client size API for reading routing table; protocol changes
authorVictor Kirhenshtein <victor@netxms.org>
Mon, 14 Jul 2014 11:50:35 +0000 (14:50 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Mon, 14 Jul 2014 11:50:35 +0000 (14:50 +0300)
16 files changed:
include/netxms-version.h
include/nms_cscp.h
include/nxclapi.h
src/java/netxms-base/src/main/java/org/netxms/base/NXCPCodes.java
src/java/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/netxms-client/src/main/java/org/netxms/client/constants/RCC.java
src/java/netxms-client/src/main/java/org/netxms/client/topology/RadioInterface.java
src/java/netxms-client/src/main/java/org/netxms/client/topology/Route.java [new file with mode: 0644]
src/java/netxms-client/src/main/resources/messages.properties
src/java/netxms-client/src/main/resources/messages_es.properties
src/java/netxms-client/src/main/resources/messages_ru.properties
src/java/netxms-client/src/test/java/org/netxms/client/TopologyTest.java
src/libnetxms/nxcp.cpp
src/libnxcl/main.cpp
src/server/core/session.cpp
src/server/include/nms_core.h

index a14a9c8..f0f2702 100644 (file)
@@ -43,7 +43,7 @@
 /**
  * Current client-server protocol version
  */
-#define CLIENT_PROTOCOL_VERSION           43
+#define CLIENT_PROTOCOL_VERSION           44
 
 /**
  * Current mobile device protocol version
index e121ada..e134d18 100644 (file)
@@ -491,7 +491,8 @@ typedef struct
 #define CMD_FILEMGR_DELETE_FILE        0x0127
 #define CMD_FILEMGR_RENAME_FILE        0x0128
 #define CMD_FILEMGR_MOVE_FILE          0x0129
-#define CMD_FILEMGR_UPLOAD             0x0130
+#define CMD_FILEMGR_UPLOAD             0x012A
+#define CMD_GET_SWITCH_FDB             0x012B
 
 #define CMD_RS_LIST_REPORTS            0x1100
 #define CMD_RS_GET_REPORT              0x1101
index 7c49c23..6f2aa4d 100644 (file)
@@ -535,6 +535,7 @@ enum
 #define RCC_HDLINK_ACCESS_DENIED     ((UINT32)110)
 #define RCC_HDLINK_INTERNAL_ERROR    ((UINT32)111)
 #define RCC_NO_LDAP_CONNECTION       ((UINT32)112)
+#define RCC_NO_ROUTING_TABLE         ((UINT32)113)
 
 /**
  * Mask bits for NXCModifyEventTemplate()
index 7e44f3e..75cdd20 100644 (file)
@@ -317,7 +317,8 @@ public class NXCPCodes
    public static final int CMD_FILEMGR_DELETE_FILE = 0x0127;
    public static final int CMD_FILEMGR_RENAME_FILE = 0x0128;
    public static final int CMD_FILEMGR_MOVE_FILE = 0x0129;
-   public static final int CMD_FILEMGR_UPLOAD = 0x0130;
+   public static final int CMD_FILEMGR_UPLOAD = 0x012A;
+   public static final int CMD_GET_SWITCH_FDB = 0x012B;
        
        // CMD_RS_ - Reporting Server related codes
        public static final int CMD_RS_LIST_REPORTS = 0x1100;
index 3b334b1..cfc7272 100644 (file)
@@ -164,6 +164,7 @@ import org.netxms.client.snmp.SnmpValue;
 import org.netxms.client.snmp.SnmpWalkListener;
 import org.netxms.client.topology.ConnectionPoint;
 import org.netxms.client.topology.NetworkPath;
+import org.netxms.client.topology.Route;
 import org.netxms.client.topology.VlanInfo;
 import org.netxms.client.topology.WirelessStation;
 
@@ -174,7 +175,7 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
 {
    // Various public constants
    public static final int DEFAULT_CONN_PORT = 4701;
-   public static final int CLIENT_PROTOCOL_VERSION = 43;
+   public static final int CLIENT_PROTOCOL_VERSION = 44;
 
    // Authentication types
    public static final int AUTH_TYPE_PASSWORD = 0;
@@ -6760,6 +6761,31 @@ public class NXCSession implements Session, ScriptLibraryManager, UserManager, S
       final NXCPMessage response = waitForRCC(msg.getMessageId());
       return new NetworkPath(response);
    }
+   
+   /**
+    * Get routing table from node
+    * 
+    * @param nodeId
+    * @return
+    * @throws IOException
+    * @throws NXCException
+    */
+   public List<Route> getRoutingTable(long nodeId) throws IOException, NXCException
+   {
+      final NXCPMessage msg = newMessage(NXCPCodes.CMD_GET_ROUTING_TABLE);
+      msg.setVariableInt32(NXCPCodes.VID_OBJECT_ID, (int) nodeId);
+      sendMessage(msg);
+      final NXCPMessage response = waitForRCC(msg.getMessageId());
+      int count = response.getVariableAsInteger(NXCPCodes.VID_NUM_ELEMENTS);
+      List<Route> rt = new ArrayList<Route>(count);
+      long varId = NXCPCodes.VID_ELEMENT_LIST_BASE;
+      for(int i = 0; i < count; i++)
+      {
+         rt.add(new Route(response, varId));
+         varId += 10;
+      }
+      return rt;
+   }
 
    /**
     * Get list of wireless stations registered at given wireless controller.
index 91097a2..1aabd62 100644 (file)
@@ -96,6 +96,12 @@ public final class RCC extends CommonRCC
        public static final int NO_SOFTWARE_PACKAGE_DATA = 100;
        public static final int INVALID_SUMMARY_TABLE_ID = 101;
        public static final int USER_LOGGED_IN = 102;
+   public static final int NO_HDLINK = 108;
+   public static final int HDLINK_COMM_FAILURE = 109;
+   public static final int HDLINK_ACCESS_DENIED = 110;
+   public static final int HDLINK_INTERNAL_ERROR = 111;
+   public static final int NO_LDAP_CONNECTION = 112;
+   public static final int NO_ROUTING_TABLE = 113;
        
        // SNMP-specific, has no corresponding RCC_xxx constants in C library
        public static final int BAD_MIB_FILE_HEADER = 1001;
index 26c0127..47d70f9 100644 (file)
@@ -1,5 +1,20 @@
 /**
- * 
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2014 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 package org.netxms.client.topology;
 
diff --git a/src/java/netxms-client/src/main/java/org/netxms/client/topology/Route.java b/src/java/netxms-client/src/main/java/org/netxms/client/topology/Route.java
new file mode 100644 (file)
index 0000000..b51e373
--- /dev/null
@@ -0,0 +1,98 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2014 Victor Kirhenshtein
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.netxms.client.topology;
+
+import java.net.InetAddress;
+import org.netxms.base.NXCPMessage;
+
+/**
+ * IP route
+ */
+public class Route
+{
+   private InetAddress destination;
+   private int prefixLength;
+   private InetAddress nextHop;
+   private int ifIndex;
+   private int type;
+   
+   /**
+    * Create route object from NXCP message
+    * 
+    * @param msg
+    * @param baseId
+    */
+   public Route(NXCPMessage msg, long baseId)
+   {
+      destination = msg.getVariableAsInetAddress(baseId);
+      prefixLength = msg.getVariableAsInteger(baseId + 1);
+      nextHop = msg.getVariableAsInetAddress(baseId + 2);
+      ifIndex = msg.getVariableAsInteger(baseId + 3);
+      type = msg.getVariableAsInteger(baseId + 4);
+   }
+
+   /**
+    * @return the destination
+    */
+   public InetAddress getDestination()
+   {
+      return destination;
+   }
+
+   /**
+    * @return the prefixLength
+    */
+   public int getPrefixLength()
+   {
+      return prefixLength;
+   }
+
+   /**
+    * @return the nextHop
+    */
+   public InetAddress getNextHop()
+   {
+      return nextHop;
+   }
+
+   /**
+    * @return the ifIndex
+    */
+   public int getIfIndex()
+   {
+      return ifIndex;
+   }
+
+   /**
+    * @return the type
+    */
+   public int getType()
+   {
+      return type;
+   }
+
+   /* (non-Javadoc)
+    * @see java.lang.Object#toString()
+    */
+   @Override
+   public String toString()
+   {
+      return "Route [" + destination.getHostAddress() + "/" + prefixLength + " gw=" + nextHop.getHostAddress() + " iface=" + ifIndex + " type=" + type + "]";
+   }
+}
index 43a8d30..2e569e9 100644 (file)
@@ -111,6 +111,7 @@ RCC_0109 = Helpdesk link communication failure
 RCC_0110 = Helpdesk link access denied
 RCC_0111 = Helpdesk link internal error
 RCC_0112 = LDAP connection error
+RCC_0113 = Routing table unavailable
 RCC_1001 = Bad MIB file header
 RCC_1002 = Bad MIB file data
 RCC_UNKNOWN = Error %d
index 6b4d0f7..53f786f 100644 (file)
@@ -110,6 +110,8 @@ RCC_0108 = Helpdesk link unavailable
 RCC_0109 = Helpdesk link communication failure
 RCC_0110 = Helpdesk link access denied
 RCC_0111 = Helpdesk link internal error
+RCC_0112 = LDAP connection error
+RCC_0113 = Routing table unavailable
 RCC_1001 = Error en la cabecera del fichero MIB
 RCC_1002 = Error en los datos del fichero MIB
 RCC_UNKNOWN = Error %d
index 66727e2..32ea154 100644 (file)
@@ -110,6 +110,8 @@ RCC_0108 = \u0421\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0441\u
 RCC_0109 = \u041e\u0448\u0438\u0431\u043a\u0430 \u0441\u0432\u044f\u0437\u0438 \u043f\u0440\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0441\u043e \u0441\u043b\u0443\u0436\u0431\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438
 RCC_0110 = \u041e\u0442\u043a\u0430\u0437 \u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043f\u0440\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0441\u043e \u0441\u043b\u0443\u0436\u0431\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438
 RCC_0111 = \u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0438 \u0441\u043e \u0441\u043b\u0443\u0436\u0431\u043e\u0439 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438
+RCC_0112 = \u041d\u0435\u0442 \u0441\u0432\u044f\u0437\u0438 \u0441 LDAP \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u043c
+RCC_0113 = \u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430
 RCC_1001 = \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0444\u0430\u0439\u043b\u0430 MIB
 RCC_1002 = \u041d\u0435\u0432\u0435\u0440\u043d\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 MIB
 RCC_UNKNOWN = \u041e\u0448\u0438\u0431\u043a\u0430 %d
index b354975..58d4ce1 100644 (file)
  */
 package org.netxms.client;
 
+import java.util.List;
 import org.netxms.client.maps.NetworkMapLink;
 import org.netxms.client.maps.NetworkMapPage;
 import org.netxms.client.maps.elements.NetworkMapElement;
+import org.netxms.client.topology.Route;
 
 
 /**
@@ -29,7 +31,7 @@ import org.netxms.client.maps.elements.NetworkMapElement;
 public class TopologyTest extends SessionTest
 {
    private static final long SUBNET_ID = 796;
-   private static final long NODE_ID = 603;
+   private static final long NODE_ID = 100;
    
    public void testAddressMap() throws Exception
    {
@@ -54,4 +56,15 @@ public class TopologyTest extends SessionTest
       
       session.disconnect();
    }
+
+   public void testRoutingTable() throws Exception
+   {
+      final NXCSession session = connect();
+
+      List<Route> rt = session.getRoutingTable(NODE_ID);
+      for(Route r : rt)
+         System.out.println(r.toString());
+      
+      session.disconnect();
+   }
 }
index 6b25754..c226660 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ** NetXMS - Network Management System
 ** NetXMS Foundation Library
-** Copyright (C) 2003-2013 Victor Kirhenshtein
+** Copyright (C) 2003-2014 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
@@ -333,10 +333,11 @@ TCHAR LIBNETXMS_EXPORTABLE *NXCPMessageCodeName(WORD wCode, TCHAR *pszBuffer)
       _T("CMD_FILEMGR_DELETE_FILE"),
       _T("CMD_FILEMGR_RENAME_FILE"),
       _T("CMD_FILEMGR_MOVE_FILE"),
-      _T("CMD_FILEMGR_UPLOAD")
+      _T("CMD_FILEMGR_UPLOAD"),
+      _T("CMD_GET_SWITCH_FDB")
    };
 
-   if ((wCode >= CMD_LOGIN) && (wCode <= CMD_FILEMGR_UPLOAD))
+   if ((wCode >= CMD_LOGIN) && (wCode <= CMD_GET_SWITCH_FDB))
       _tcscpy(pszBuffer, pszMsgNames[wCode - CMD_LOGIN]);
    else
       _sntprintf(pszBuffer, 64, _T("CMD_0x%04X"), wCode);
index be4cc4a..77b3304 100644 (file)
@@ -388,9 +388,10 @@ const TCHAR LIBNXCL_EXPORTABLE *NXCGetErrorText(UINT32 dwError)
       _T("Helpdesk link communication failure"),
       _T("Helpdesk link access denied"),
       _T("Helpdesk link internal error"),
-      _T("LDAP connection error")
+      _T("LDAP connection error"),
+      _T("Routing table unavailable")
    };
-       return (dwError <= RCC_NO_LDAP_CONNECTION) ? pszErrorText[dwError] : _T("No text message for this error");
+       return (dwError <= RCC_NO_ROUTING_TABLE) ? pszErrorText[dwError] : _T("No text message for this error");
 }
 
 #if defined(_WIN32) && !defined(UNDER_CE)
index 6d5aebb..e436d7c 100644 (file)
@@ -169,6 +169,8 @@ DEFINE_THREAD_STARTER(openHelpdeskIssue)
 DEFINE_THREAD_STARTER(forwardToReportingServer)
 DEFINE_THREAD_STARTER(fileManagerControl)
 DEFINE_THREAD_STARTER(uploadUserFileToAgent)
+DEFINE_THREAD_STARTER(getSwitchForwardingDatabase)
+DEFINE_THREAD_STARTER(getRoutingTable)
 
 /**
  * Client communication read thread starter
@@ -1438,6 +1440,12 @@ void ClientSession::processingThread()
          case CMD_FILEMGR_UPLOAD:
             CALL_IN_NEW_THREAD(uploadUserFileToAgent, pMsg);
             break;
+         case CMD_GET_SWITCH_FDB:
+            CALL_IN_NEW_THREAD(getSwitchForwardingDatabase, pMsg);
+            break;
+         case CMD_GET_ROUTING_TABLE:
+            CALL_IN_NEW_THREAD(getRoutingTable, pMsg);
+            break;
          default:
             if ((m_wCurrentCmd >> 8) == 0x11)
             {
@@ -13246,3 +13254,88 @@ void ClientSession::uploadUserFileToAgent(CSCPMessage *request)
       delete response;
 }
 
+/**
+ * Get switch forwarding database
+ */
+void ClientSession::getSwitchForwardingDatabase(CSCPMessage *request)
+{
+   CSCPMessage msg;
+
+   // Prepare response message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(request->GetId());
+
+   // Get node id and check object class and access rights
+   Node *node = (Node *)FindObjectById(request->GetVariableLong(VID_OBJECT_ID), OBJECT_NODE);
+   if (node != NULL)
+   {
+      if (node->checkAccessRights(m_dwUserId, OBJECT_ACCESS_READ))
+      {
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+         WriteAuditLog(AUDIT_OBJECTS, FALSE, m_dwUserId, m_workstation, node->Id(), _T("Access denied on reading FDB"));
+      }
+   }
+   else  // No object with given ID
+   {
+      msg.SetVariable(VID_RCC, RCC_INVALID_OBJECT_ID);
+   }
+
+   // Send response
+   sendMessage(&msg);
+}
+
+/**
+ * Get switch forwarding database
+ */
+void ClientSession::getRoutingTable(CSCPMessage *request)
+{
+   CSCPMessage msg;
+
+   // Prepare response message
+   msg.SetCode(CMD_REQUEST_COMPLETED);
+   msg.SetId(request->GetId());
+
+   // Get node id and check object class and access rights
+   Node *node = (Node *)FindObjectById(request->GetVariableLong(VID_OBJECT_ID), OBJECT_NODE);
+   if (node != NULL)
+   {
+      if (node->checkAccessRights(m_dwUserId, OBJECT_ACCESS_READ))
+      {
+         ROUTING_TABLE *rt = node->getRoutingTable();
+         if (rt != NULL)
+         {
+            msg.SetVariable(VID_RCC, RCC_SUCCESS);
+            msg.SetVariable(VID_NUM_ELEMENTS, (UINT32)rt->iNumEntries);
+            UINT32 id = VID_ELEMENT_LIST_BASE;
+            for(int i = 0; i < rt->iNumEntries; i++)
+            {
+               msg.SetVariable(id++, rt->pRoutes[i].dwDestAddr);
+               msg.SetVariable(id++, (UINT32)BitsInMask(rt->pRoutes[i].dwDestMask));
+               msg.SetVariable(id++, rt->pRoutes[i].dwNextHop);
+               msg.SetVariable(id++, rt->pRoutes[i].dwIfIndex);
+               msg.SetVariable(id++, rt->pRoutes[i].dwRouteType);
+               id += 5;
+            }
+         }
+         else
+         {
+            msg.SetVariable(VID_RCC, RCC_NO_ROUTING_TABLE);
+         }
+      }
+      else
+      {
+         msg.SetVariable(VID_RCC, RCC_ACCESS_DENIED);
+         WriteAuditLog(AUDIT_OBJECTS, FALSE, m_dwUserId, m_workstation, node->Id(), _T("Access denied on reading routing table"));
+      }
+   }
+   else  // No object with given ID
+   {
+      msg.SetVariable(VID_RCC, RCC_INVALID_OBJECT_ID);
+   }
+
+   // Send response
+   sendMessage(&msg);
+}
index b96fdd2..5288647 100644 (file)
@@ -465,6 +465,8 @@ private:
        DECLARE_THREAD_STARTER(forwardToReportingServer)
    DECLARE_THREAD_STARTER(fileManagerControl)
    DECLARE_THREAD_STARTER(uploadUserFileToAgent)
+   DECLARE_THREAD_STARTER(getSwitchForwardingDatabase)
+   DECLARE_THREAD_STARTER(getRoutingTable)
 
    void readThread();
    void writeThread();
@@ -672,6 +674,8 @@ private:
    void getEffectiveRights(CSCPMessage *request);
    void fileManagerControl(CSCPMessage *request);
    void uploadUserFileToAgent(CSCPMessage *request);
+   void getSwitchForwardingDatabase(CSCPMessage *request);
+   void getRoutingTable(CSCPMessage *request);
 
 public:
    ClientSession(SOCKET hSocket, struct sockaddr *addr);