fixed issue 35: Use dot1qTpFdbTable instead of dot1dTpFdbTable for FDB retrieval...
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 19 Jul 2012 16:32:53 +0000 (16:32 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 19 Jul 2012 16:32:53 +0000 (16:32 +0000)
src/agent/subagents/oracle/oracle.vcproj
src/server/core/fdb.cpp

index f616133..d86d6a7 100644 (file)
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Release|Win32"\r
-                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
-                       IntermediateDirectory="$(ConfigurationName)"\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
                        ConfigurationType="2"\r
                        CharacterSet="2"\r
-                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\..\..\include"\r
-                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;ORACLE_EXPORTS"\r
-                               RuntimeLibrary="2"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;ORACLE_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
                                Detect64BitPortabilityProblems="false"\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                OutputFile="$(OutDir)\$(ProjectName).nsm"\r
-                               LinkIncremental="1"\r
+                               LinkIncremental="2"\r
                                AdditionalLibraryDirectories="..\..\..\..\..\..\$(ConfigurationName);..\..\..\..\..\$(ConfigurationName)"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               OptimizeReferences="2"\r
-                               EnableCOMDATFolding="2"\r
-                               TargetMachine="1"\r
+                               TargetMachine="17"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
                        />\r
                </Configuration>\r
                <Configuration\r
-                       Name="Debug|x64"\r
-                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
-                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
                        ConfigurationType="2"\r
                        CharacterSet="2"\r
+                       WholeProgramOptimization="1"\r
                        >\r
                        <Tool\r
                                Name="VCPreBuildEventTool"\r
                        />\r
                        <Tool\r
                                Name="VCMIDLTool"\r
-                               TargetEnvironment="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               Optimization="0"\r
                                AdditionalIncludeDirectories="..\..\..\..\include"\r
-                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;ORACLE_EXPORTS"\r
-                               MinimalRebuild="true"\r
-                               BasicRuntimeChecks="3"\r
-                               RuntimeLibrary="3"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;ORACLE_EXPORTS"\r
+                               RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                                WarningLevel="3"\r
                                Detect64BitPortabilityProblems="false"\r
                        <Tool\r
                                Name="VCLinkerTool"\r
                                OutputFile="$(OutDir)\$(ProjectName).nsm"\r
-                               LinkIncremental="2"\r
+                               LinkIncremental="1"\r
                                AdditionalLibraryDirectories="..\..\..\..\..\..\$(ConfigurationName);..\..\..\..\..\$(ConfigurationName)"\r
                                GenerateDebugInformation="true"\r
                                SubSystem="2"\r
-                               TargetMachine="17"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
                        />\r
                        <Tool\r
                                Name="VCALinkTool"\r
index 4d083ce..aecd434 100644 (file)
@@ -85,6 +85,15 @@ DWORD ForwardingDatabase::ifIndexFromPort(DWORD port)
 \r
 void ForwardingDatabase::addEntry(FDB_ENTRY *entry)\r
 {\r
+       // Check for duplicate\r
+       for(int i = 0; i < m_fdbSize; i++)\r
+               if (!memcmp(m_fdb[i].macAddr, entry->macAddr, MAC_ADDR_LENGTH))\r
+               {\r
+                       memcpy(&m_fdb[i], entry, sizeof(FDB_ENTRY));\r
+                       m_fdb[i].ifIndex = ifIndexFromPort(entry->port);\r
+                       return;\r
+               }\r
+\r
        if (m_fdbSize == m_fdbAllocated)\r
        {\r
                m_fdbAllocated += 32;\r
@@ -212,21 +221,25 @@ static DWORD FDBHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transport *pT
 \r
 \r
 //\r
-// dot1dBasePortTable walker's callback\r
+// dot1qTpFdbEntry walker's callback\r
 //\r
 \r
-static DWORD Dot1dPortTableHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transport *pTransport, void *arg)\r
+static DWORD Dot1qTpFdbHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transport *pTransport, void *arg)\r
 {\r
+       int port = pVar->GetValueAsInt();\r
+       if (port == 0)\r
+               return SNMP_ERR_SUCCESS;\r
+\r
    SNMP_ObjectId *pOid = pVar->GetName();\r
-   TCHAR szOid[MAX_OID_LEN * 4], szSuffix[MAX_OID_LEN * 4];\r
-   SNMPConvertOIDToText(pOid->getLength() - 11, (DWORD *)&(pOid->getValue())[11], szSuffix, MAX_OID_LEN * 4);\r
+       DWORD oidLen = pOid->getLength();\r
+       DWORD oid[MAX_OID_LEN];\r
+       memcpy(oid, pOid->getValue(), oidLen * sizeof(DWORD));\r
 \r
-       // Get interface index\r
+       // Get port number and status\r
    SNMP_PDU *pRqPDU = new SNMP_PDU(SNMP_GET_REQUEST, SnmpNewRequestId(), dwVersion);\r
 \r
-       _tcscpy(szOid, _T(".1.3.6.1.2.1.17.1.4.1.2"));  // Interface index\r
-   _tcscat(szOid, szSuffix);\r
-       pRqPDU->bindVariable(new SNMP_Variable(szOid));\r
+       oid[12] = 3;    // .1.3.6.1.2.1.17.7.1.2.2.1.3 - status\r
+       pRqPDU->bindVariable(new SNMP_Variable(oid, oidLen));\r
 \r
    SNMP_PDU *pRespPDU;\r
    DWORD rcc = pTransport->doRequest(pRqPDU, &pRespPDU, g_dwSNMPTimeout, 3);\r
@@ -234,11 +247,19 @@ static DWORD Dot1dPortTableHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Tr
 \r
        if (rcc == SNMP_ERR_SUCCESS)\r
    {\r
-               PORT_MAPPING_ENTRY pm;\r
+               int status = pRespPDU->getVariable(0)->GetValueAsInt();\r
+               if (status == 3)        // status 3 == learned\r
+               {\r
+                       FDB_ENTRY entry;\r
 \r
-               pm.port = pVar->GetValueAsUInt();\r
-               pm.ifIndex = pRespPDU->getVariable(0)->GetValueAsInt();\r
-               ((ForwardingDatabase *)arg)->addPortMapping(&pm);\r
+                       memset(&entry, 0, sizeof(FDB_ENTRY));\r
+                       entry.port = (DWORD)port;\r
+                       for(DWORD i = oidLen - MAC_ADDR_LENGTH, j = 0; i < oidLen; i++)\r
+                               entry.macAddr[j++] = (BYTE)oid[i];\r
+                       Node *node = FindNodeByMAC(entry.macAddr);\r
+                       entry.nodeObject = (node != NULL) ? node->Id() : 0;\r
+                       ((ForwardingDatabase *)arg)->addEntry(&entry);\r
+               }\r
       delete pRespPDU;\r
        }\r
 \r
@@ -246,6 +267,21 @@ static DWORD Dot1dPortTableHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Tr
 }\r
 \r
 \r
+//\r
+// dot1dBasePortTable walker's callback\r
+//\r
+\r
+static DWORD Dot1dPortTableHandler(DWORD dwVersion, SNMP_Variable *pVar, SNMP_Transport *pTransport, void *arg)\r
+{\r
+   SNMP_ObjectId *pOid = pVar->GetName();\r
+       PORT_MAPPING_ENTRY pm;\r
+       pm.port = pOid->getValue()[pOid->getLength() - 1];\r
+       pm.ifIndex = pVar->GetValueAsUInt();\r
+       ((ForwardingDatabase *)arg)->addPortMapping(&pm);\r
+       return SNMP_ERR_SUCCESS;\r
+}\r
+\r
+\r
 //\r
 // Get switch forwarding database from node\r
 //\r
@@ -256,8 +292,11 @@ ForwardingDatabase *GetSwitchForwardingDatabase(Node *node)
                return NULL;\r
 \r
        ForwardingDatabase *fdb = new ForwardingDatabase();\r
-       node->CallSnmpEnumerate(_T(".1.3.6.1.2.1.17.1.4.1.1"), Dot1dPortTableHandler, fdb);\r
+       node->CallSnmpEnumerate(_T(".1.3.6.1.2.1.17.1.4.1.2"), Dot1dPortTableHandler, fdb);\r
+       node->CallSnmpEnumerate(_T(".1.3.6.1.2.1.17.7.1.2.2.1.2"), Dot1qTpFdbHandler, fdb);\r
+       DbgPrintf(5, _T("FDB: %d entries read from dot1qTpFdbTable"), fdb->getSize());\r
        node->CallSnmpEnumerate(_T(".1.3.6.1.2.1.17.4.3.1.1"), FDBHandler, fdb);\r
+       DbgPrintf(5, _T("FDB: %d entries read from dot1dTpFdbTable"), fdb->getSize());\r
        fdb->sort();\r
        return fdb;\r
 }\r