added "flags" field to interface objects; added "isPhysicalPort" flag
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 12 Apr 2011 20:55:08 +0000 (20:55 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 12 Apr 2011 20:55:08 +0000 (20:55 +0000)
15 files changed:
doc/internal/db_format_change.txt
include/netxmsdb.h
include/nxclapi.h
sql/schema.in
src/java/netxms-client/src/main/java/org/netxms/client/objects/Interface.java
src/java/netxms-eclipse/ObjectView/src/org/netxms/ui/eclipse/objectview/objecttabs/elements/GeneralInfo.java
src/libnxcl/libnxcl.h
src/libnxcl/objects.cpp
src/server/core/interface.cpp
src/server/core/node.cpp
src/server/drivers/baystack/baystack.cpp
src/server/drivers/ers8000/ers8000.cpp
src/server/include/nms_objects.h
src/server/include/nxsrvapi.h
src/server/tools/nxdbmgr/upgrade.cpp

index bad2303..06dc1d9 100644 (file)
@@ -1,4 +1,12 @@
 ***************
+* 225 ==> 226 *
+***************
+
+- Column "synthetic_mask" removed from table "interfaces"
+- Columns "flags" added to table "interfaces"
+
+
+***************
 * 224 ==> 225 *
 ***************
 
index c47c7ff..2dae165 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   225
+#define DB_FORMAT_VERSION   226
 
 #endif
index c94be60..dfde5ba 100644 (file)
@@ -239,6 +239,14 @@ typedef void * NXC_SESSION;
 
 
 //
+// Interface flags
+//
+
+#define IF_SYNTHETIC_MASK        0x00000001
+#define IF_PHYSICAL_PORT         0x00000002
+
+
+//
 // Node ifXTable usage mode
 //
 
@@ -1049,6 +1057,7 @@ typedef struct
 
 struct __nxc_object_iface
 {
+       DWORD dwFlags;
    DWORD dwIpNetMask;   // Ip netmask.
    DWORD dwIfIndex;     // Interface index.
    DWORD dwIfType;      // Interface type
index f92cda3..bf7edbf 100644 (file)
@@ -298,6 +298,7 @@ CREATE TABLE interfaces
 (
        id integer not null,
        node_id integer not null,
+       flags integer not null,
        ip_addr varchar(15) not null,
        ip_netmask varchar(15) not null,
        if_type integer not null,
@@ -308,7 +309,6 @@ CREATE TABLE interfaces
        peer_node_id integer not null,
        peer_if_id integer not null,
        mac_addr varchar(15) not null,
-       synthetic_mask integer not null,
        required_polls integer not null,
        description varchar(255),
        PRIMARY KEY(id)
index 2c8d39f..0930dff 100644 (file)
@@ -28,6 +28,11 @@ import org.netxms.client.NXCSession;
  */\r
 public class Interface extends GenericObject\r
 {\r
+       // Interface flags\r
+       public static final int IF_SYNTHETIC_MASK = 0x00000001;\r
+       public static final int IF_PHYSICAL_PORT  = 0x00000002;\r
+       \r
+       private int flags;\r
        private InetAddress subnetMask;\r
        private int ifIndex;\r
        private int ifType;\r
@@ -47,6 +52,7 @@ public class Interface extends GenericObject
        {\r
                super(msg, session);\r
                \r
+               flags = msg.getVariableAsInteger(NXCPCodes.VID_FLAGS);\r
                subnetMask = msg.getVariableAsInetAddress(NXCPCodes.VID_IP_NETMASK);\r
                ifIndex = msg.getVariableAsInteger(NXCPCodes.VID_IF_INDEX);\r
                ifType = msg.getVariableAsInteger(NXCPCodes.VID_IF_TYPE);\r
@@ -156,4 +162,12 @@ public class Interface extends GenericObject
        {\r
                return description;\r
        }\r
+\r
+       /**\r
+        * @return the flags\r
+        */\r
+       public int getFlags()\r
+       {\r
+               return flags;\r
+       }\r
 }\r
index 96674a3..9b905af 100644 (file)
@@ -56,7 +56,7 @@ public class GeneralInfo extends TableElement
                                addPair("Interface Type", Integer.toString(iface.getIfType()));\r
                                addPair("Description", iface.getDescription());\r
                                addPair("MAC Address", iface.getMacAddress().toString());\r
-                               if ((iface.getSlot() != 0) && (iface.getPort() != 0))\r
+                               if ((iface.getFlags() & Interface.IF_PHYSICAL_PORT) != 0)\r
                                        addPair("Slot/Port", Integer.toString(iface.getSlot()) + "/" + Integer.toString(iface.getPort()));\r
                                if (!iface.getPrimaryIP().isAnyLocalAddress())\r
                                {\r
index c46f1c7..257637d 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** NetXMS - Network Management System
 ** Client Library
-** Copyright (C) 2003-2010 Victor Kirhenshtein
+** Copyright (C) 2003-2011 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -38,7 +38,7 @@
 // Constants
 //
 
-#define OBJECT_CACHE_MAGIC 0x20110124
+#define OBJECT_CACHE_MAGIC 0x20110412
 
 #define MAX_SERVER_NAME    64
 #define MAX_LOGIN_NAME     64
index 182d81c..bb27bcc 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 ** NetXMS - Network Management System
 ** Client Library
-** Copyright (C) 2003-2010 Victor Kirhenshtein
+** Copyright (C) 2003-2011 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU Lesser General Public License as published by
@@ -269,6 +269,7 @@ static NXC_OBJECT *NewObjectFromMsg(CSCPMessage *pMsg)
    switch(pObject->iClass)
    {
       case OBJECT_INTERFACE:
+                       pObject->iface.dwFlags = pMsg->GetVariableLong(VID_FLAGS);
          pObject->iface.dwIpNetMask = pMsg->GetVariableLong(VID_IP_NETMASK);
          pObject->iface.dwIfIndex = pMsg->GetVariableLong(VID_IF_INDEX);
          pObject->iface.dwIfType = pMsg->GetVariableLong(VID_IF_TYPE);
index cafbd48..e010ed2 100644 (file)
@@ -30,6 +30,7 @@
 Interface::Interface()
           : NetObj()
 {
+       m_flags = 0;
        nx_strncpy(m_description, m_szName, MAX_DB_STRING);
    m_dwIpNetMask = 0;
    m_dwIfIndex = 0;
@@ -42,7 +43,6 @@ Interface::Interface()
        m_dot1xPaeAuthState = 0;
        m_dot1xBackendAuthState = 0;
    m_qwLastDownEventId = 0;
-       m_bSyntheticMask = false;
        m_iPendingStatus = -1;
        m_iPollCount = 0;
        m_iRequiredPollCount = 0;       // Use system default
@@ -56,6 +56,7 @@ Interface::Interface()
 Interface::Interface(DWORD dwAddr, DWORD dwNetMask, bool bSyntheticMask)
           : NetObj()
 {
+       m_flags = bSyntheticMask ? IF_SYNTHETIC_MASK : 0;
    _tcscpy(m_szName, _T("unknown"));
    _tcscpy(m_description, _T("unknown"));
    m_dwIpAddr = dwAddr;
@@ -71,7 +72,6 @@ Interface::Interface(DWORD dwAddr, DWORD dwNetMask, bool bSyntheticMask)
        m_dot1xBackendAuthState = 0;
    memset(m_bMacAddr, 0, MAC_ADDR_LENGTH);
    m_qwLastDownEventId = 0;
-       m_bSyntheticMask = bSyntheticMask;
        m_iPendingStatus = -1;
        m_iPollCount = 0;
        m_iRequiredPollCount = 0;       // Use system default
@@ -86,6 +86,7 @@ Interface::Interface(DWORD dwAddr, DWORD dwNetMask, bool bSyntheticMask)
 Interface::Interface(const TCHAR *name, const TCHAR *descr, DWORD index, DWORD ipAddr, DWORD ipNetMask, DWORD ifType)
           : NetObj()
 {
+       m_flags = 0;
    nx_strncpy(m_szName, name, MAX_OBJECT_NAME);
    nx_strncpy(m_description, descr, MAX_DB_STRING);
    m_dwIfIndex = index;
@@ -101,7 +102,6 @@ Interface::Interface(const TCHAR *name, const TCHAR *descr, DWORD index, DWORD i
        m_dot1xBackendAuthState = 0;
    memset(m_bMacAddr, 0, MAC_ADDR_LENGTH);
    m_qwLastDownEventId = 0;
-       m_bSyntheticMask = false;
        m_iPendingStatus = -1;
        m_iPollCount = 0;
        m_iRequiredPollCount = 0;       // Use system default
@@ -136,7 +136,7 @@ BOOL Interface::CreateFromDB(DWORD dwId)
       return FALSE;
 
    _sntprintf(szQuery, 256, _T("SELECT ip_addr,ip_netmask,if_type,if_index,node_id,")
-                            _T("mac_addr,synthetic_mask,required_polls,bridge_port,phy_slot,")
+                            _T("mac_addr,flags,required_polls,bridge_port,phy_slot,")
                                                                         _T("phy_port,peer_node_id,peer_if_id,description FROM interfaces WHERE id=%d"), dwId);
    hResult = DBSelect(g_hCoreDB, szQuery);
    if (hResult == NULL)
@@ -150,7 +150,7 @@ BOOL Interface::CreateFromDB(DWORD dwId)
       m_dwIfIndex = DBGetFieldULong(hResult, 0, 3);
       dwNodeId = DBGetFieldULong(hResult, 0, 4);
       StrToBin(DBGetField(hResult, 0, 5, szBuffer, MAX_DB_STRING), m_bMacAddr, MAC_ADDR_LENGTH);
-               m_bSyntheticMask = DBGetFieldLong(hResult, 0, 6) ? true : false;
+               m_flags = DBGetFieldULong(hResult, 0, 6);
       m_iRequiredPollCount = DBGetFieldLong(hResult, 0, 7);
                m_bridgePortNumber = DBGetFieldULong(hResult, 0, 8);
                m_slotNumber = DBGetFieldULong(hResult, 0, 9);
@@ -231,24 +231,24 @@ BOOL Interface::SaveToDB(DB_HANDLE hdb)
    BinToStr(m_bMacAddr, MAC_ADDR_LENGTH, szMacStr);
    if (bNewObject)
       _sntprintf(szQuery, 2048, _T("INSERT INTO interfaces (id,ip_addr,")
-                       _T("ip_netmask,node_id,if_type,if_index,mac_addr,synthetic_mask,required_polls,")
+                       _T("ip_netmask,node_id,if_type,if_index,mac_addr,flags,required_polls,")
                                                          _T("bridge_port,phy_slot,phy_port,peer_node_id,peer_if_id,description) ")
                        _T("VALUES (%d,'%s','%s',%d,%d,%d,'%s',%d,%d,%d,%d,%d,%d,%d,%s)"),
               m_dwId, IpToStr(m_dwIpAddr, szIpAddr),
               IpToStr(m_dwIpNetMask, szNetMask), dwNodeId,
-                                 m_dwIfType, m_dwIfIndex, szMacStr, m_bSyntheticMask ? 1 : 0,
+                                 m_dwIfType, m_dwIfIndex, szMacStr, (int)m_flags,
                                  m_iRequiredPollCount, (int)m_bridgePortNumber, (int)m_slotNumber,
                                  (int)m_portNumber, (int)m_peerNodeId, (int)m_peerInterfaceId,
                                  (const TCHAR *)DBPrepareString(hdb, m_description));
    else
       _sntprintf(szQuery, 2048, _T("UPDATE interfaces SET ip_addr='%s',ip_netmask='%s',")
                        _T("node_id=%d,if_type=%d,if_index=%d,")
-                       _T("mac_addr='%s',synthetic_mask=%d,")
+                       _T("mac_addr='%s',flags=%d,")
                                                          _T("required_polls=%d,bridge_port=%d,phy_slot=%d,phy_port=%d,")
                                                          _T("peer_node_id=%d,peer_if_id=%d,description=%s WHERE id=%d"),
               IpToStr(m_dwIpAddr, szIpAddr),
               IpToStr(m_dwIpNetMask, szNetMask), dwNodeId,
-                                 m_dwIfType, m_dwIfIndex, szMacStr, m_bSyntheticMask ? 1 : 0,
+                                 m_dwIfType, m_dwIfIndex, szMacStr, (int)m_flags,
                                  m_iRequiredPollCount, (int)m_bridgePortNumber, (int)m_slotNumber,
                                  (int)m_portNumber, (int)m_peerNodeId, (int)m_peerInterfaceId,
                                  (const TCHAR *)DBPrepareString(hdb, m_description), m_dwId);
@@ -441,7 +441,7 @@ void Interface::CreateMessage(CSCPMessage *pMsg)
    pMsg->SetVariable(VID_IF_PORT, m_portNumber);
    pMsg->SetVariable(VID_IP_NETMASK, m_dwIpNetMask);
    pMsg->SetVariable(VID_MAC_ADDR, m_bMacAddr, MAC_ADDR_LENGTH);
-       pMsg->SetVariable(VID_SYNTHETIC_MASK, (WORD)(m_bSyntheticMask ? 1 : 0));
+       pMsg->SetVariable(VID_FLAGS, m_flags);
        pMsg->SetVariable(VID_REQUIRED_POLLS, (WORD)m_iRequiredPollCount);
        pMsg->SetVariable(VID_PEER_NODE_ID, m_peerNodeId);
        pMsg->SetVariable(VID_PEER_INTERFACE_ID, m_peerInterfaceId);
index c73cf33..df639ac 100644 (file)
@@ -648,15 +648,12 @@ Interface *Node::findInterfaceBySlotAndPort(DWORD slot, DWORD port)
    DWORD i;
    Interface *pInterface;
 
-       if ((slot == 0) || (port == 0))
-               return NULL;
-
    LockChildList(FALSE);
    for(i = 0; i < m_dwChildCount; i++)
       if (m_pChildList[i]->Type() == OBJECT_INTERFACE)
       {
          pInterface = (Interface *)m_pChildList[i];
-                       if ((pInterface->getSlotNumber() == slot) && (pInterface->getPortNumber() == port))
+                       if (pInterface->isPhysicalPort() && (pInterface->getSlotNumber() == slot) && (pInterface->getPortNumber() == port))
          {
             UnlockChildList();
             return pInterface;
@@ -801,7 +798,7 @@ BOOL Node::isMyIP(DWORD dwIpAddr)
 
 void Node::createNewInterface(DWORD dwIpAddr, DWORD dwNetMask, const TCHAR *name, const TCHAR *descr,
                               DWORD dwIndex, DWORD dwType, BYTE *pbMacAddr, DWORD bridgePort, 
-                                                                               DWORD slot, DWORD port)
+                                                                               DWORD slot, DWORD port, bool physPort)
 {
    Interface *pInterface;
    Subnet *pSubnet = NULL;
@@ -873,6 +870,7 @@ void Node::createNewInterface(DWORD dwIpAddr, DWORD dwNetMask, const TCHAR *name
        pInterface->setBridgePortNumber(bridgePort);
        pInterface->setSlotNumber(slot);
        pInterface->setPortNumber(port);
+       pInterface->setPhysicalPortFlag(physPort);
 
    // Insert to objects' list and generate event
    NetObjInsert(pInterface, TRUE);
@@ -1935,6 +1933,10 @@ BOOL Node::updateInterfaceConfiguration(DWORD dwRqId, DWORD dwNetMask)
                                                {
                                                        pInterface->setPortNumber(ifInfo->dwPortNumber);
                                                }
+                                               if (ifInfo->isPhysicalPort != pInterface->isPhysicalPort())
+                                               {
+                                                       pInterface->setPhysicalPortFlag(ifInfo->isPhysicalPort);
+                                               }
                                                if ((ifInfo->dwIpNetMask != 0) && (ifInfo->dwIpNetMask != pInterface->getIpNetMask()))
                                                {
                                                        pInterface->setIpNetMask(ifInfo->dwIpNetMask);
@@ -1959,7 +1961,8 @@ BOOL Node::updateInterfaceConfiguration(DWORD dwRqId, DWORD dwNetMask)
                                ifInfo->bMacAddr,
                                                                                 ifInfo->dwBridgePortNumber,
                                                                                 ifInfo->dwSlotNumber,
-                                                                                ifInfo->dwPortNumber);
+                                                                                ifInfo->dwPortNumber,
+                                                                                ifInfo->isPhysicalPort);
             hasChanges = TRUE;
          }
       }
index 4941560..a34b109 100644 (file)
@@ -145,6 +145,7 @@ InterfaceList *BayStackDriver::getInterfaces(SNMP_Transport *snmp, StringMap *at
                {
                        ifList->get(i)->dwSlotNumber = slot;
                        ifList->get(i)->dwPortNumber = ifList->get(i)->dwIndex % slotSize;
+                       ifList->get(i)->isPhysicalPort = true;
                }
        }
 
index 27c4ccb..6e082d8 100644 (file)
@@ -78,6 +78,7 @@ InterfaceList *PassportDriver::getInterfaces(SNMP_Transport *snmp, StringMap *at
                {\r
                        ifList->get(i)->dwSlotNumber = slot;\r
                        ifList->get(i)->dwPortNumber = ifList->get(i)->dwIndex % 64 + 1;\r
+                       ifList->get(i)->isPhysicalPort = true;\r
                }\r
        }\r
 \r
index 4974237..a606c37 100644 (file)
@@ -488,6 +488,7 @@ public:
 class NXCORE_EXPORTABLE Interface : public NetObj
 {
 protected:
+       DWORD m_flags;
        TCHAR m_description[MAX_DB_STRING];     // Interface description - value of ifDescr for SNMP, equals to name for NetXMS agent
    DWORD m_dwIfIndex;
    DWORD m_dwIfType;
@@ -501,7 +502,6 @@ protected:
        WORD m_dot1xPaeAuthState;               // 802.1x port auth state
        WORD m_dot1xBackendAuthState;   // 802.1x backend auth state
    QWORD m_qwLastDownEventId;
-       bool m_bSyntheticMask;
        int m_iPendingStatus;
        int m_iPollCount;
        int m_iRequiredPollCount;
@@ -529,7 +529,8 @@ public:
        DWORD getPeerInterfaceId() { return m_peerInterfaceId; }
        const TCHAR *getDescription() { return m_description; }
    const BYTE *getMacAddr() { return m_bMacAddr; }
-       bool isSyntheticMask() { return m_bSyntheticMask; }
+       bool isSyntheticMask() { return (m_flags & IF_SYNTHETIC_MASK) ? true : false; }
+       bool isPhysicalPort() { return (m_flags & IF_PHYSICAL_PORT) ? true : false; }
    bool isFake() { return (m_dwIfIndex == 1) && 
                           (m_dwIfType == IFTYPE_OTHER) &&
                           (!_tcscmp(m_szName, _T("lan0")) || !_tcscmp(m_szName, _T("unknown"))) &&
@@ -544,6 +545,7 @@ public:
    void setBridgePortNumber(DWORD bpn) { m_bridgePortNumber = bpn; Modify(); }
    void setSlotNumber(DWORD slot) { m_slotNumber = slot; Modify(); }
    void setPortNumber(DWORD port) { m_portNumber = port; Modify(); }
+       void setPhysicalPortFlag(bool isPhysical) { if (isPhysical) m_flags |= IF_PHYSICAL_PORT; else m_flags &= ~IF_PHYSICAL_PORT; Modify(); }
        void setPeer(DWORD nodeId, DWORD ifId) { m_peerNodeId = nodeId; m_peerInterfaceId = ifId; Modify(); }
    void setDescription(const TCHAR *descr) { nx_strncpy(m_description, descr, MAX_DB_STRING); Modify(); }
 
@@ -759,7 +761,7 @@ public:
    void addInterface(Interface *pInterface) { AddChild(pInterface); pInterface->AddParent(this); }
    void createNewInterface(DWORD dwAddr, DWORD dwNetMask, const TCHAR *name = NULL, const TCHAR *descr = NULL,
                            DWORD dwIndex = 0, DWORD dwType = 0, BYTE *pbMacAddr = NULL, DWORD bridgePort = 0,
-                                                                       DWORD slot = 0, DWORD port = 0);
+                                                                       DWORD slot = 0, DWORD port = 0, bool physPort = false);
    void deleteInterface(Interface *pInterface);
 
    void changeIPAddress(DWORD dwIpAddr);
index c8ab126..93d826c 100644 (file)
@@ -214,6 +214,7 @@ typedef struct
    DWORD dwIpNetMask;
    BYTE bMacAddr[MAC_ADDR_LENGTH];
    int iNumSecondary;      // Number of secondary IP's on this interface
+       bool isPhysicalPort;
 } NX_INTERFACE_INFO;
 
 
index 6b4e117..ba083c9 100644 (file)
@@ -249,6 +249,26 @@ static BOOL SetColumnNullable(const TCHAR *table, const TCHAR *column, const TCH
 
 
 //
+// Upgrade from V225 to V226
+//
+
+static BOOL H_UpgradeFromV225(int currVersion, int newVersion)
+{
+       static TCHAR batch[] = 
+               _T("ALTER TABLE interfaces ADD flags integer\n")
+               _T("UPDATE interfaces SET flags=0\n")
+               _T("UPDATE interfaces SET flags=1 WHERE synthetic_mask<>0\n")
+               _T("ALTER TABLE interfaces DROP COLUMN synthetic_mask\n")
+               _T("<END>");
+
+       CHK_EXEC(SQLBatch(batch));
+
+       CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='226' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
+
+//
 // Upgrade from V224 to V225
 //
 
@@ -5160,6 +5180,7 @@ static struct
        { 222, 223, H_UpgradeFromV222 },
        { 223, 224, H_UpgradeFromV223 },
        { 224, 225, H_UpgradeFromV224 },
+       { 225, 226, H_UpgradeFromV225 },
    { 0, NULL }
 };