"Fossies" - the Fresh Open Source Software Archive

Member "netxms-3.8.166/src/server/drivers/qtech-olt/qtech-olt.cpp" (23 Feb 2021, 5767 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 "qtech-olt.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 ** Driver for Qtech OLT switches
    4 **
    5 ** Licensed under MIT lisence, as stated by the original
    6 ** author: https://dev.raden.solutions/issues/779#note-4
    7 ** 
    8 ** Copyright (C) 2015 Procyshin Dmitriy
    9 ** 
   10 ** Permission is hereby granted, free of charge, to any person obtaining a copy of
   11 ** this software and associated documentation files (the “Software”), to deal in
   12 ** the Software without restriction, including without limitation the rights to
   13 ** use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
   14 ** of the Software, and to permit persons to whom the Software is furnished to do
   15 ** so, subject to the following conditions:
   16 **
   17 ** The above copyright notice and this permission notice shall be included in all
   18 ** copies or substantial portions of the Software.
   19 **
   20 ** THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   21 ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   22 ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   23 ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   24 ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   25 ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   26 ** SOFTWARE.
   27 **
   28 ** File: qtech-olt.cpp
   29 **/
   30 
   31 #include "qtech-olt.h"
   32 #include <netxms-version.h>
   33 
   34 /**
   35  * Driver name
   36  */
   37 static TCHAR s_driverName[] = _T("QTECH-OLT");
   38 
   39 /**
   40  * Driver version
   41  */
   42 static TCHAR s_driverVersion[] = NETXMS_VERSION_STRING;
   43 
   44 /**
   45  * Get driver name
   46  */
   47 const TCHAR *QtechOLTDriver::getName()
   48 {
   49     return s_driverName;
   50 }
   51 
   52 /**
   53  * Get driver version
   54  */
   55 const TCHAR *QtechOLTDriver::getVersion()
   56 {
   57     return s_driverVersion;
   58 }
   59 
   60 /**
   61  * Check if given device can be potentially supported by driver
   62  *
   63  * @param oid Device OID
   64  */
   65 int QtechOLTDriver::isPotentialDevice(const TCHAR *oid)
   66 {
   67     return !_tcscmp(oid, _T(".1.3.6.1.4.1.27514.1.10.4.1")) ? 254 : 0;
   68 }
   69 
   70 /**
   71  * Check if given device is supported by driver
   72  *
   73  * @param snmp SNMP transport
   74  * @param oid Device OID
   75  */
   76 bool QtechOLTDriver::isDeviceSupported(SNMP_Transport *snmp, const TCHAR *oid)
   77 {
   78     return true;
   79 }
   80 
   81 /**
   82  * Handler for enumerating indexes
   83  */
   84 static UINT32 HandlerIndex(SNMP_Variable *pVar, SNMP_Transport *pTransport, void *pArg)
   85 {
   86     UINT32 slot = pVar->getName().getElement(14);
   87     InterfaceInfo *info = new InterfaceInfo(pVar->getValueAsUInt() + slot * 1000);
   88     info->location.module = slot;
   89     info->location.port = info->index - slot * 1000;
   90     info->isPhysicalPort = true;
   91     ((InterfaceList *)pArg)->add(info);
   92     return SNMP_ERR_SUCCESS;
   93 }
   94 
   95 /**
   96  * Get list of interfaces for given node
   97  *
   98  * @param snmp SNMP transport
   99  * @param node Node
  100  */
  101 InterfaceList *QtechOLTDriver::getInterfaces(SNMP_Transport *snmp, NObject *node, DriverData *driverData, int useAliases, bool useIfXTable)
  102 {
  103    UINT32 oid[MAX_OID_LEN];
  104 
  105    InterfaceList *pIfList = NetworkDeviceDriver::getInterfaces(snmp, node, driverData, 0, false);
  106    if (SnmpWalk(snmp, _T(".1.3.6.1.4.1.27514.1.11.4.1.1.1"), HandlerIndex, pIfList) == SNMP_ERR_SUCCESS)
  107    {
  108       for(int i = 0; i < pIfList->size(); i++)
  109       {
  110          InterfaceInfo *iface = pIfList->get(i);
  111          if (iface->index > 1000)
  112          {
  113             SNMPParseOID(_T(".1.3.6.1.4.1.27514.1.11.4.1.1.0.0.0.0"), oid, MAX_OID_LEN);
  114             oid[12] = 22;
  115             oid[14] = iface->location.module;
  116             oid[15] = iface->index - iface->location.module * 1000;
  117             iface->type = IFTYPE_GPON;
  118             if (SnmpGetEx(snmp, NULL, oid, 16, iface->alias, MAX_DB_STRING * sizeof(TCHAR), 0, NULL) != SNMP_ERR_SUCCESS)
  119             {
  120                StrStrip(iface->alias);
  121             }
  122             oid[12] = 13;
  123             if (SnmpGetEx(snmp, NULL, oid, 16, iface->description, MAX_DB_STRING * sizeof(TCHAR), 0, NULL) != SNMP_ERR_SUCCESS)
  124             {
  125                StrStrip(iface->description);
  126             }
  127             oid[12] = 2;
  128             if (SnmpGetEx(snmp, NULL, oid, 16, iface->name, MAX_DB_STRING * sizeof(TCHAR), 0, NULL) != SNMP_ERR_SUCCESS)
  129             {
  130                iface->type = IFTYPE_OTHER;
  131             }
  132          }
  133       }
  134    }
  135    return pIfList;
  136 }
  137 
  138 /**
  139  * Get interface status
  140  *
  141  * @param snmp SNMP transport
  142  * @param node Node
  143  * @param driverData
  144  * @param ifIndex
  145  * @param *adminState
  146  * @param *operState
  147  */
  148 void QtechOLTDriver::getInterfaceState(SNMP_Transport *snmp, NObject *node, DriverData *driverData, UINT32 ifIndex,
  149                                        int ifTableSuffixLen, UINT32 *ifTableSuffix, InterfaceAdminState *adminState, InterfaceOperState *operState)
  150 {
  151    UINT32 dwOperStatus = 0;
  152    UINT32 oid[MAX_OID_LEN];
  153 
  154    *adminState = IF_ADMIN_STATE_UP;
  155 
  156    if (ifIndex > 1000)
  157    {
  158       SNMPParseOID(_T(".1.3.6.1.4.1.27514.1.11.4.1.1.3.0.0.0"), oid, MAX_OID_LEN);
  159       oid[14] = ifIndex / 1000;
  160       oid[15] = ifIndex - oid[14] * 1000;
  161       SnmpGetEx(snmp, NULL, oid, 16, &dwOperStatus, sizeof(UINT32), 0, NULL);
  162       switch(dwOperStatus)
  163       {
  164          case 1:
  165             *operState = IF_OPER_STATE_UP;
  166             break;
  167          case 0:
  168             *operState = IF_OPER_STATE_DOWN;
  169             break;
  170          default:
  171             *operState = IF_OPER_STATE_UNKNOWN;
  172             break;
  173       }
  174    }
  175    else
  176    {
  177       NetworkDeviceDriver::getInterfaceState(snmp, node, driverData, ifIndex, ifTableSuffixLen, ifTableSuffix, adminState, operState);
  178    }
  179 }
  180 
  181 /**
  182  * Driver entry point
  183  */
  184 DECLARE_NDD_ENTRY_POINT(QtechOLTDriver);
  185 
  186 #ifdef _WIN32
  187 
  188 /**
  189  * DLL entry point
  190  */
  191 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  192 {
  193    if (dwReason == DLL_PROCESS_ATTACH)
  194       DisableThreadLibraryCalls(hInstance);
  195    return TRUE;
  196 }
  197 
  198 #endif