some vendor-specific code moved to device drivers; dropped "node type" attribute...
[public/netxms.git] / src / server / drivers / baystack / baystack.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Driver for Avaya ERS switches (except ERS 8xxx) (former Nortel/Bay Networks BayStack)
4 ** Copyright (C) 2003-2011 Victor Kirhenshtein
5 **
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU Lesser General Public License as published by
8 ** the Free Software Foundation; either version 3 of the License, or
9 ** (at your option) any later version.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU Lesser General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 **
20 ** File: baystack.cpp
21 **/
22
23 #include <nddrv.h>
24
25
26 //
27 // Static data
28 //
29
30 static TCHAR s_driverName[] = _T("BAYSTACK");
31 static TCHAR s_driverVersion[] = NETXMS_VERSION_STRING;
32
33
34 /**
35 * Driver's class
36 */
37 class BayStackDriver : public NetworkDeviceDriver
38 {
39 public:
40 virtual const TCHAR *getName();
41 virtual const TCHAR *getVersion();
42
43 virtual bool isDeviceSupported(const TCHAR *oid);
44 virtual void analyzeDevice(SNMP_Transport *snmp, const TCHAR *oid, StringMap *attributes);
45 virtual InterfaceList *getInterfaces(SNMP_Transport *snmp, StringMap *attributes);
46 };
47
48 /**
49 * Get driver name
50 */
51 const TCHAR *BayStackDriver::getName()
52 {
53 return s_driverName;
54 }
55
56 /**
57 * Get driver version
58 */
59 const TCHAR *BayStackDriver::getVersion()
60 {
61 return s_driverVersion;
62 }
63
64 /**
65 * Check if given device is supported by driver
66 *
67 * @param oid Device OID
68 */
69 bool BayStackDriver::isDeviceSupported(const TCHAR *oid)
70 {
71 return _tcsncmp(oid, _T(".1.3.6.1.4.1.45.3"), 17) == 0;
72 }
73
74 /**
75 * Do additional checks on the device required by driver.
76 * Driver can set device's custom attributes from within
77 * this function.
78 *
79 * @param snmp SNMP transport
80 * @param attributes Node's custom attributes
81 */
82 void BayStackDriver::analyzeDevice(SNMP_Transport *snmp, const TCHAR *oid, StringMap *attributes)
83 {
84 DWORD slotSize;
85
86 if (!_tcsncmp(oid, _T(".1.3.6.1.4.1.45.3.74"), 20)) // 56xx
87 {
88 slotSize = 128;
89 }
90 else if (!_tcsncmp(oid, _T(".1.3.6.1.4.1.45.3.40"), 20)) // BPS2000
91 {
92 slotSize = 32;
93 }
94 else
95 {
96 slotSize = 64;
97 }
98
99 attributes->set(_T(".baystack.rapidCity.vlan"), slotSize);
100 }
101
102 /**
103 * Get list of interfaces for given node
104 *
105 * @param snmp SNMP transport
106 * @param attributes Node's custom attributes
107 */
108 InterfaceList *BayStackDriver::getInterfaces(SNMP_Transport *snmp, StringMap *attributes)
109 {
110 // Get interface list from standard MIB
111 InterfaceList *ifList = NetworkDeviceDriver::getInterfaces(snmp, attributes);
112 if (ifList == NULL)
113 return NULL;
114
115 // Translate interface names
116 // TODO: does it really needed?
117 for(int i = 0; i < ifList->getSize(); i++)
118 {
119 INTERFACE_INFO *iface = ifList->get(i);
120
121 const TCHAR *ptr;
122 if ((ptr = _tcsstr(iface->szName, _T("- Port"))) != NULL)
123 {
124 ptr += 2;
125 memmove(iface->szName, ptr, _tcslen(ptr) + 1);
126 }
127 else if ((ptr = _tcsstr(iface->szName, _T("- Unit"))) != NULL)
128 {
129 ptr += 2;
130 memmove(iface->szName, ptr, _tcslen(ptr) + 1);
131 }
132 else if ((_tcsstr(iface->szName, _T("BayStack")) != NULL) ||
133 (_tcsstr(iface->szName, _T("Nortel Ethernet Switch")) != NULL))
134 {
135 ptr = _tcsrchr(iface->szName, _T('-'));
136 if (ptr != NULL)
137 {
138 ptr++;
139 while(*ptr == _T(' '))
140 ptr++;
141 memmove(iface->szName, ptr, _tcslen(ptr) + 1);
142 }
143 }
144 StrStrip(iface->szName);
145 }
146
147 // Calculate slot/port pair from ifIndex
148 DWORD slotSize = attributes->getULong(_T(".baystack.rapidCity.vlan"), 64);
149 for(int i = 0; i < ifList->getSize(); i++)
150 {
151 DWORD slot = ifList->get(i)->dwIndex / slotSize + 1;
152 if ((slot > 0) && (slot <= 8))
153 {
154 ifList->get(i)->dwSlotNumber = slot;
155 ifList->get(i)->dwPortNumber = ifList->get(i)->dwIndex % slotSize;
156 }
157 }
158
159 return ifList;
160 }
161
162 /**
163 * Driver entry point
164 */
165 DECLARE_NDD_ENTRY_POINT(s_driverName, BayStackDriver);
166
167
168 /**
169 * DLL entry point
170 */
171 #ifdef _WIN32
172
173 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
174 {
175 if (dwReason == DLL_PROCESS_ATTACH)
176 DisableThreadLibraryCalls(hInstance);
177 return TRUE;
178 }
179
180 #endif