added driver for Cisco ESW switches
[public/netxms.git] / src / server / drivers / procurve / procurve.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Driver for HP ProCurve switches
4 ** Copyright (C) 2003-2012 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: procurve.cpp
21 **/
22
23 #include "procurve.h"
24
25
26 //
27 // Static data
28 //
29
30 static TCHAR s_driverName[] = _T("PROCURVE");
31 static TCHAR s_driverVersion[] = NETXMS_VERSION_STRING;
32
33
34 /**
35 * Get driver name
36 */
37 const TCHAR *ProCurveDriver::getName()
38 {
39 return s_driverName;
40 }
41
42 /**
43 * Get driver version
44 */
45 const TCHAR *ProCurveDriver::getVersion()
46 {
47 return s_driverVersion;
48 }
49
50 /**
51 * Check if given device can be potentially supported by driver
52 *
53 * @param oid Device OID
54 */
55 int ProCurveDriver::isPotentialDevice(const TCHAR *oid)
56 {
57 return (_tcsncmp(oid, _T(".1.3.6.1.4.1.11.2.3.7.11"), 24) == 0) ? 127 : 0;
58 }
59
60 /**
61 * Check if given device is supported by driver
62 *
63 * @param snmp SNMP transport
64 * @param oid Device OID
65 */
66 bool ProCurveDriver::isDeviceSupported(SNMP_Transport *snmp, const TCHAR *oid)
67 {
68 return true;
69 }
70
71 /**
72 * Do additional checks on the device required by driver.
73 * Driver can set device's custom attributes from within
74 * this function.
75 *
76 * @param snmp SNMP transport
77 * @param attributes Node's custom attributes
78 */
79 void ProCurveDriver::analyzeDevice(SNMP_Transport *snmp, const TCHAR *oid, StringMap *attributes)
80 {
81 int model = _tcstol(&oid[25], NULL, 10);
82
83 // modular switches
84 if ((model == 7) || (model == 9) || (model == 13) || (model == 14) || (model == 23) || (model == 27))
85 {
86 attributes->set(_T(".procurve.isModular"), _T("1"));
87 attributes->set(_T(".procurve.slotSize"), _T("24"));
88 }
89 }
90
91 /**
92 * Get list of interfaces for given node
93 *
94 * @param snmp SNMP transport
95 * @param attributes Node's custom attributes
96 */
97 InterfaceList *ProCurveDriver::getInterfaces(SNMP_Transport *snmp, StringMap *attributes, int useAliases, bool useIfXTable)
98 {
99 // Get interface list from standard MIB
100 InterfaceList *ifList = NetworkDeviceDriver::getInterfaces(snmp, attributes, useAliases, useIfXTable);
101 if (ifList == NULL)
102 return NULL;
103
104 bool isModular = attributes->getBoolean(_T(".procurve.isModular"), false);
105 DWORD slotSize = attributes->getULong(_T(".procurve.slotSize"), 24);
106
107 // Find physical ports
108 for(int i = 0; i < ifList->getSize(); i++)
109 {
110 NX_INTERFACE_INFO *iface = ifList->get(i);
111 if (iface->dwType == IFTYPE_ETHERNET_CSMACD)
112 {
113 iface->isPhysicalPort = true;
114 if (isModular)
115 {
116 iface->dwSlotNumber = (iface->dwIndex / slotSize) + 1;
117 iface->dwPortNumber = iface->dwIndex % slotSize;
118 }
119 else
120 {
121 iface->dwSlotNumber = 1;
122 iface->dwPortNumber = iface->dwIndex;
123 }
124 }
125 }
126
127 return ifList;
128 }
129
130 /**
131 * Driver entry point
132 */
133 DECLARE_NDD_ENTRY_POINT(s_driverName, ProCurveDriver);
134
135 /**
136 * DLL entry point
137 */
138 #ifdef _WIN32
139
140 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
141 {
142 if (dwReason == DLL_PROCESS_ATTACH)
143 DisableThreadLibraryCalls(hInstance);
144 return TRUE;
145 }
146
147 #endif