"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/src/server/drivers/avaya/avaya.cpp" (23 Feb 2021, 3842 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "avaya.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.6.300_vs_3.7.95.

    1 /* 
    2 ** NetXMS - Network Management System
    3 ** Generic driver for Avaya ERS switches (former Nortel)
    4 ** Copyright (C) 2003-2018 Victor Kirhenshtein
    5 **
    6 ** This program is free software; you can redistribute it and/or modify
    7 ** it under the terms of the GNU General Public License as published by
    8 ** the Free Software Foundation; either version 2 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 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: avaya.cpp
   21 **
   22 **/
   23 
   24 #include "avaya.h"
   25 #include <netxms-version.h>
   26 
   27 /**
   28  * Get driver version
   29  */
   30 const TCHAR *AvayaERSDriver::getVersion()
   31 {
   32    return NETXMS_VERSION_STRING;
   33 }
   34 
   35 /**
   36  * Get slot size from object's custom attributes. Default implementation always return constant value 64.
   37  *
   38  * @param attributes object's custom attributes
   39  * @return slot size
   40  */
   41 UINT32 AvayaERSDriver::getSlotSize(NObject *node)
   42 {
   43    return 64;
   44 }
   45 
   46 /**
   47  * Handler for VLAN enumeration on Avaya ERS
   48  */
   49 static UINT32 HandlerVlanList(SNMP_Variable *pVar, SNMP_Transport *pTransport, void *pArg)
   50 {
   51    UINT32 oidName[MAX_OID_LEN], dwResult;
   52    VlanList *vlanList = (VlanList *)pArg;
   53 
   54    size_t nameLen = pVar->getName().length();
   55     VlanInfo *vlan = new VlanInfo(pVar->getValueAsInt(), VLAN_PRM_IFINDEX);
   56 
   57    // Get VLAN name
   58    memcpy(oidName, pVar->getName().value(), nameLen * sizeof(UINT32));
   59    oidName[nameLen - 2] = 2;
   60    TCHAR buffer[256];
   61     dwResult = SnmpGetEx(pTransport, NULL, oidName, nameLen, buffer, sizeof(buffer), SG_STRING_RESULT, NULL);
   62    if (dwResult != SNMP_ERR_SUCCESS)
   63     {
   64         delete vlan;
   65       return dwResult;
   66     }
   67     vlan->setName(buffer);
   68 
   69    // Get member ports
   70     // From RapidCity MIB:
   71     //   The string is 32 octets long, for a total of 256 bits. Each bit 
   72     //   corresponds to a port, as represented by its ifIndex value . When a 
   73     //   bit has the value one(1), the corresponding port is a member of the 
   74     //   set. When a bit has the value zero(0), the corresponding port is not 
   75     //   a member of the set. The encoding is such that the most significant 
   76     //   bit of octet #1 corresponds to ifIndex 0, while the least significant 
   77     //   bit of octet #32 corresponds to ifIndex 255." 
   78     // Note: on newer devices port list can be longer
   79    oidName[nameLen - 2] = 12;
   80     BYTE portMask[256];
   81     memset(portMask, 0, sizeof(portMask));
   82    dwResult = SnmpGetEx(pTransport, NULL, oidName, nameLen, portMask, sizeof(portMask), SG_RAW_RESULT, NULL);
   83    if (dwResult != SNMP_ERR_SUCCESS)
   84     {
   85         delete vlan;
   86       return dwResult;
   87     }
   88 
   89     UINT32 ifIndex = 0;
   90     for(int i = 0; i < 256; i++)
   91     {
   92         BYTE mask = 0x80;
   93         while(mask > 0)
   94         {
   95             if (portMask[i] & mask)
   96             {
   97                 vlan->add(ifIndex);
   98             }
   99             mask >>= 1;
  100             ifIndex++;
  101         }
  102     }
  103 
  104     vlanList->add(vlan);
  105    return SNMP_ERR_SUCCESS;
  106 }
  107 
  108 /**
  109  * Get VLANs 
  110  */
  111 VlanList *AvayaERSDriver::getVlans(SNMP_Transport *snmp, NObject *node, DriverData *driverData)
  112 {
  113     VlanList *list = new VlanList();
  114     if (SnmpWalk(snmp, _T(".1.3.6.1.4.1.2272.1.3.2.1.1"), HandlerVlanList, list, FALSE) != SNMP_ERR_SUCCESS)
  115     {
  116         delete_and_null(list);
  117     }
  118     return list;
  119 }
  120 
  121 /**
  122  * Driver module entry point
  123  */
  124 NDD_BEGIN_DRIVER_LIST
  125 NDD_DRIVER(BayStackDriver)
  126 NDD_DRIVER(NtwsDriver)
  127 NDD_DRIVER(PassportDriver)
  128 NDD_END_DRIVER_LIST
  129 DECLARE_NDD_MODULE_ENTRY_POINT
  130 
  131 /**
  132  * DLL entry point
  133  */
  134 #ifdef _WIN32
  135 
  136 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  137 {
  138     if (dwReason == DLL_PROCESS_ATTACH)
  139         DisableThreadLibraryCalls(hInstance);
  140     return TRUE;
  141 }
  142 
  143 #endif