- Added osgi cmds to enable/disable LLDP snooping on each individual node connector 19/319/1
authorJason Ye <yisye@cisco.com>
Wed, 8 May 2013 06:12:01 +0000 (23:12 -0700)
committerJason Ye <yisye@cisco.com>
Wed, 8 May 2013 06:12:01 +0000 (23:12 -0700)
- Fixed TopologyManager nodeConnectorsDB which should only contain ISL ports

Signed-off-by: Jason Ye <yisye@cisco.com>
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/DiscoveryService.java
opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java

index ef74774..8c41624 100644 (file)
@@ -97,8 +97,8 @@ public class DiscoveryService implements IInventoryShimExternalListener,
     private int discoveryConsistencyCheckCorrected = 0; // # of cases CC corrected
     private boolean discoveryConsistencyCheckEnabled = true;// enable or disable CC
     private boolean discoveryAgingEnabled = true; // enable or disable aging
-    private boolean discoverySpoofingEnabled = true; // enable or disable spoofing neighbor of a production network
-
+    private boolean discoverySnoopingEnabled = true; // global flag to enable or disable LLDP snooping
+    private List<NodeConnector> discoverySnoopingDisableList; // the list of ports that will not do LLDP snooping
     private BlockingQueue<NodeConnector> transmitQ;
     private Thread transmitThread;
     private Boolean throttling = false; // if true, no more batching.
@@ -263,8 +263,8 @@ public class DiscoveryService implements IInventoryShimExternalListener,
         if (ethPkt.getPayload() instanceof LLDP) {
             NodeConnector dst = inPkt.getIncomingNodeConnector();
             if (!processDiscoveryPacket(dst, ethPkt)) {
-                /* Spoof the discovery pkt if not generated from us */
-                spoofDiscoveryPacket(dst, ethPkt);
+                /* Snoop the discovery pkt if not generated from us */
+                snoopDiscoveryPacket(dst, ethPkt);
             }
             return PacketResult.CONSUME;
         }
@@ -272,16 +272,20 @@ public class DiscoveryService implements IInventoryShimExternalListener,
     }
 
     /*
-     * Spoof incoming discovery frames generated by the production network neighbor switch
+     * Snoop incoming discovery frames generated by the production network neighbor switch
      */
-    private void spoofDiscoveryPacket(NodeConnector dstNodeConnector,
+    private void snoopDiscoveryPacket(NodeConnector dstNodeConnector,
             Ethernet ethPkt) {
-        if (!this.discoverySpoofingEnabled) {
+        if (!this.discoverySnoopingEnabled
+                || discoverySnoopingDisableList.contains(dstNodeConnector)) {
+            logger.trace(
+                    "Discarded received discovery packet on {} since snooping is turned off",
+                    dstNodeConnector);
             return;
         }
 
         if ((dstNodeConnector == null) || (ethPkt == null)) {
-            logger.trace("Quit spoofing discovery packet: Null node connector or packet");
+            logger.trace("Quit snooping discovery packet: Null node connector or packet");
             return;
         }
 
@@ -880,31 +884,34 @@ public class DiscoveryService implements IInventoryShimExternalListener,
     public String getHelp() {
         StringBuffer help = new StringBuffer();
         help.append("---Topology Discovery---\n");
-        help.append("\t prlh                   - Print readyListHi entries\n");
-        help.append("\t prll                   - Print readyListLo entries\n");
-        help.append("\t pwl                    - Print waitingList entries\n");
-        help.append("\t ppl                    - Print pendingList entries\n");
-        help.append("\t ptick                  - Print tick time in msec\n");
-        help.append("\t pcc                    - Print CC info\n");
-        help.append("\t psize                  - Print sizes of all the lists\n");
-        help.append("\t ptm                    - Print timeout info\n");
-        help.append("\t ecc                       - Enable CC\n");
-        help.append("\t dcc                       - Disable CC\n");
-        help.append("\t scc [multiple]         - Set/show CC multiple and interval\n");
-        help.append("\t sports [ports]                    - Set/show max ports per batch\n");
-        help.append("\t spause [ticks]         - Set/show pause period\n");
-        help.append("\t sdi [ticks]               - Set/show discovery interval in ticks\n");
-        help.append("\t stm [ticks]            - Set/show per timeout ticks\n");
-        help.append("\t sretry [count]                    - Set/show num of retries\n");
-        help.append("\t addsw <swid>              - Add a switch\n");
-        help.append("\t remsw <swid>              - Remove a switch\n");
-        help.append("\t page                   - Print aging info\n");
-        help.append("\t sage                   - Set/Show aging time limit\n");
-        help.append("\t eage                      - Enable aging\n");
-        help.append("\t dage                      - Disable aging\n");
-        help.append("\t pthrot                 - Print throttling\n");
-        help.append("\t ethrot                    - Enable throttling\n");
-        help.append("\t dthrot                 - Disable throttling\n");
+        help.append("\t prlh                            - Print readyListHi entries\n");
+        help.append("\t prll                            - Print readyListLo entries\n");
+        help.append("\t pwl                             - Print waitingList entries\n");
+        help.append("\t ppl                             - Print pendingList entries\n");
+        help.append("\t ptick                           - Print tick time in msec\n");
+        help.append("\t pcc                             - Print CC info\n");
+        help.append("\t psize                           - Print sizes of all the lists\n");
+        help.append("\t ptm                             - Print timeout info\n");
+        help.append("\t ecc                            - Enable CC\n");
+        help.append("\t dcc                            - Disable CC\n");
+        help.append("\t scc [multiple]                  - Set/show CC multiple and interval\n");
+        help.append("\t sports [ports]                         - Set/show max ports per batch\n");
+        help.append("\t spause [ticks]                  - Set/show pause period\n");
+        help.append("\t sdi [ticks]                            - Set/show discovery interval in ticks\n");
+        help.append("\t stm [ticks]                     - Set/show per timeout ticks\n");
+        help.append("\t sretry [count]                         - Set/show num of retries\n");
+        help.append("\t addsw <swid>                   - Add a switch\n");
+        help.append("\t remsw <swid>                   - Remove a switch\n");
+        help.append("\t page                            - Print aging info\n");
+        help.append("\t sage                            - Set/Show aging time limit\n");
+        help.append("\t eage                           - Enable aging\n");
+        help.append("\t dage                           - Disable aging\n");
+        help.append("\t pthrot                          - Print throttling\n");
+        help.append("\t ethrot                          - Enable throttling\n");
+        help.append("\t dthrot                          - Disable throttling\n");
+        help.append("\t psnp                            - Print LLDP snooping\n");
+        help.append("\t esnp <all|nodeConnector>        - Enable LLDP snooping\n");
+        help.append("\t dsnp <all|nodeConnector>        - Disable LLDP snooping\n");
         return help.toString();
     }
 
@@ -1068,24 +1075,59 @@ public class DiscoveryService implements IInventoryShimExternalListener,
         return;
     }
 
-    public void _pspf(CommandInterpreter ci) {
-        if (this.discoverySpoofingEnabled) {
-            ci.println("Discovery spoofing is enabled");
+    public void _psnp(CommandInterpreter ci) {
+        if (this.discoverySnoopingEnabled) {
+            ci.println("Discovery snooping is globally enabled");
         } else {
-            ci.println("Discovery spoofing is disabled");
+            ci.println("Discovery snooping is globally disabled");
+        }
+        
+        ci.println("\nDiscovery snooping is locally disabled on these ports");
+        for (NodeConnector nodeConnector : discoverySnoopingDisableList) {
+            ci.println(nodeConnector);
         }
         return;
     }
 
-    public void _espf(CommandInterpreter ci) {
-        this.discoverySpoofingEnabled = true;
-        ci.println("Discovery spoofing is enabled");
+    public void _esnp(CommandInterpreter ci) {
+        String val = ci.nextArgument();
+        
+        if (val == null) {
+            ci.println("Usage: esnp <all|nodeConnector>");            
+        } else if (val.equalsIgnoreCase("all")) {
+            this.discoverySnoopingEnabled = true;
+            ci.println("Discovery snooping is globally enabled");
+        } else {
+            NodeConnector nodeConnector = NodeConnector.fromString(val);
+            if (nodeConnector != null) {
+                discoverySnoopingDisableList.remove(nodeConnector); 
+                ci.println("Discovery snooping is locally enabled on port "
+                        + nodeConnector);
+            } else {
+                ci.println("Entered invalid NodeConnector " + val);                
+            }
+        }
         return;
     }
 
-    public void _dspf(CommandInterpreter ci) {
-        this.discoverySpoofingEnabled = false;
-        ci.println("Discovery spoofing is disabled");
+    public void _dsnp(CommandInterpreter ci) {
+        String val = ci.nextArgument();
+        
+        if (val == null) {
+            ci.println("Usage: dsnp <all|nodeConnector>");            
+        } else if (val.equalsIgnoreCase("all")) {
+            this.discoverySnoopingEnabled = false;
+            ci.println("Discovery snooping is globally disabled");
+        } else {
+            NodeConnector nodeConnector = NodeConnector.fromString(val);
+            if (nodeConnector != null) {
+                discoverySnoopingDisableList.add(nodeConnector);
+                ci.println("Discovery snooping is locally disabled on port "
+                        + nodeConnector);
+            } else {
+                ci.println("Entered invalid NodeConnector " + val);                
+            }
+        }
         return;
     }
 
@@ -1374,6 +1416,7 @@ public class DiscoveryService implements IInventoryShimExternalListener,
         edgeMap = new ConcurrentHashMap<NodeConnector, Edge>();
         agingMap = new ConcurrentHashMap<NodeConnector, Integer>();
         prodMap = new ConcurrentHashMap<NodeConnector, Edge>();
+        discoverySnoopingDisableList = new CopyOnWriteArrayList<NodeConnector>();
 
         discoveryTimer = new Timer("DiscoveryService");
         discoveryTimerTask = new DiscoveryTimerTask();
index e8d0d41..2002158 100644 (file)
@@ -74,8 +74,9 @@ public class TopologyManagerImpl implements ITopologyManager,
     private IClusterContainerServices clusterContainerService = null;
     // DB of all the Edges with properties which constitute our topology
     private ConcurrentMap<Edge, Set<Property>> edgesDB = null;
-    // DB of all NodeConnector which are part of Edges, meaning they
-    // are connected to another NodeConnector on the other side
+    // DB of all NodeConnector which are part of ISL Edges, meaning they
+    // are connected to another NodeConnector on the other side of an ISL link.
+    // NodeConnector of a Production Edge is not part of this DB.
     private ConcurrentMap<NodeConnector, Set<Property>> nodeConnectorsDB = null;
     // DB of all the NodeConnectors with an Host attached to it
     private ConcurrentMap<NodeConnector, ImmutablePair<Host, Set<Property>>> hostsDB = null;
@@ -324,6 +325,31 @@ public class TopologyManagerImpl implements ITopologyManager,
         return (this.nodeConnectorsDB.get(p) != null);
     }
 
+    /**
+     * This method returns true if the edge is an ISL link.
+     * 
+     * @param e
+     *            The edge
+     * @return true if it is an ISL link
+     */
+    public boolean isISLink(Edge e) {
+        return (!isProductionLink(e));
+    }
+
+    /**
+     * This method returns true if the edge is a production link.
+     * 
+     * @param e
+     *            The edge
+     * @return true if it is a production link
+     */
+    public boolean isProductionLink(Edge e) {
+        return (e.getHeadNodeConnector().getType()
+                .equals(NodeConnector.NodeConnectorIDType.PRODUCTION) || e
+                .getTailNodeConnector().getType()
+                .equals(NodeConnector.NodeConnectorIDType.PRODUCTION));
+    }
+
     /**
      * The Map returned is a copy of the current topology hence if the topology
      * changes the copy doesn't
@@ -469,12 +495,15 @@ public class TopologyManagerImpl implements ITopologyManager,
             this.edgesDB.put(e, props);
 
             // Now populate the DB of NodeConnectors
-            // NOTE WELL: properties are empy sets, not really needed
+            // NOTE WELL: properties are empty sets, not really needed
             // for now.
-            this.nodeConnectorsDB.put(e.getHeadNodeConnector(),
-                    new HashSet<Property>());
-            this.nodeConnectorsDB.put(e.getTailNodeConnector(),
-                    new HashSet<Property>());
+            // The DB only contains ISL ports
+            if (isISLink(e)) {
+                this.nodeConnectorsDB.put(e.getHeadNodeConnector(),
+                        new HashSet<Property>());
+                this.nodeConnectorsDB.put(e.getTailNodeConnector(),
+                        new HashSet<Property>());
+            }
             log.trace("Edge {}  {}", e.toString(), type.name());
             break;
         case REMOVED: