Added topology support to SAL Compatibility 05/1905/2
authorTony Tkacik <ttkacik@cisco.com>
Tue, 15 Oct 2013 14:23:42 +0000 (16:23 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Tue, 15 Oct 2013 14:51:53 +0000 (16:51 +0200)
Change-Id: I6bdb967313a3a2a78f3734de18ce92da5b8bf9ea
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
opendaylight/md-sal/model/model-flow-service/src/main/yang/flow-topology-notification.yang [new file with mode: 0644]
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/ComponentActivator.xtend
opendaylight/md-sal/sal-compability/src/main/java/org/opendaylight/controller/sal/compability/InventoryAndReadAdapter.xtend

diff --git a/opendaylight/md-sal/model/model-flow-service/src/main/yang/flow-topology-notification.yang b/opendaylight/md-sal/model/model-flow-service/src/main/yang/flow-topology-notification.yang
new file mode 100644 (file)
index 0000000..2dd5f9f
--- /dev/null
@@ -0,0 +1,47 @@
+module flow-topology-discovery {
+    namespace "urn:opendaylight:flow:topology:discovery";
+    prefix flow-node-topo;
+
+    import yang-ext {prefix ext;}
+    import ietf-inet-types {prefix inet;}
+    import ietf-yang-types {prefix yang;}
+    import opendaylight-port-types {prefix port;}
+    import opendaylight-inventory {prefix inv;}
+    import flow-node-inventory {prefix flowinv;}
+    
+    revision "2013-08-19" {
+        description "Flow Capable Node extensions to the Inventory model";
+    }
+    
+
+    grouping link {
+        leaf source {
+            type inv:node-connector-ref;
+        }
+        leaf destination {
+            type inv:node-connector-ref;
+        }
+    }
+
+
+    notification link-discovered {
+        uses link;
+    }
+    
+    notification link-overutilized {
+        uses link;
+    }
+    
+    notification link-removed {
+        uses link;
+    }
+    
+    notification link-utilization-normal {
+        uses link;
+    }
+
+    rpc solicit-refresh {
+    
+    }
+
+}
\ No newline at end of file
index 0ef349ce2cbe86ed78bded00f2738bb268b881c3..5c1723ec7e4fcddde4b468703d96b7c0ec541e50 100644 (file)
@@ -27,6 +27,9 @@ import org.opendaylight.controller.sal.packet.IPluginOutDataPacketService
 import org.osgi.framework.BundleContext
 import org.opendaylight.controller.sal.reader.IPluginOutReadService
 import org.opendaylight.controller.sal.inventory.IPluginOutInventoryService
+import org.opendaylight.controller.sal.discovery.IDiscoveryService
+import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
 
 class ComponentActivator extends ComponentActivatorAbstractBase implements BindingAwareConsumer {
 
@@ -68,6 +71,7 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
         // Inventory Service
         inventory.dataService = session.getSALService(DataBrokerService);
         inventory.flowStatisticsService = session.getRpcService(OpendaylightFlowStatisticsService);
+        inventory.topologyDiscovery = session.getRpcService(FlowTopologyDiscoveryService);
 
         subscribe.registerNotificationListener(dataPacket)
 
@@ -93,7 +97,7 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
             createServiceDependency() //
             .setService(IPluginOutDataPacketService) //
             .setCallbacks("setDataPacketPublisher", "setDataPacketPublisher") //
-            .setRequired(true))
+            .setRequired(false))
     }
 
     private def dispatch configure(FlowProgrammerAdapter imp, Component it) {
@@ -102,7 +106,7 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
             createServiceDependency() //
             .setService(IPluginOutFlowProgrammerService) //
             .setCallbacks("setFlowProgrammerPublisher", "setFlowProgrammerPublisher") //
-            .setRequired(true))
+            .setRequired(false))
     }
 
     private def dispatch configure(InventoryAndReadAdapter imp, Component it) {
@@ -111,12 +115,23 @@ class ComponentActivator extends ComponentActivatorAbstractBase implements Bindi
             createServiceDependency() //
             .setService(IPluginOutReadService) //
             .setCallbacks("setReadPublisher", "setReadPublisher") //
-            .setRequired(true))
+            .setRequired(false))
         add(
             createServiceDependency() //
             .setService(IPluginOutInventoryService) //
             .setCallbacks("setInventoryPublisher", "setInventoryPublisher") //
-            .setRequired(true))
+            .setRequired(false))
+        add(
+            createServiceDependency() //
+            .setService(IPluginOutTopologyService) //
+            .setCallbacks("setTopologyPublisher", "setTopologyPublisher") //
+            .setRequired(false))
+        add(
+            createServiceDependency() //
+            .setService(IDiscoveryService) //
+            .setCallbacks("setDiscoveryPublisher", "setDiscoveryPublisher") //
+            .setRequired(false))
+        
     }
 
     private def Dictionary<String, Object> properties() {
index 367e64c8934a6d0c45d83b100fc1a240d0a8657b..c9c60e21411138c746621c6c40e2c46a42a349d7 100644 (file)
@@ -10,7 +10,7 @@ import org.opendaylight.controller.sal.binding.api.data.DataBrokerService
 import static extension org.opendaylight.controller.sal.common.util.Arguments.*
 import static extension org.opendaylight.controller.sal.compability.NodeMapping.*
 import static org.opendaylight.controller.sal.compability.MDFlowMapping.*
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow   .inventory.rev130819.FlowCapableNode
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef
@@ -33,8 +33,20 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRem
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
 import org.opendaylight.yangtools.yang.binding.DataObject
-
-class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventoryService,OpendaylightInventoryListener {
+import org.opendaylight.controller.sal.topology.IPluginOutTopologyService
+import org.opendaylight.controller.sal.topology.IPluginInTopologyService
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryService
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.FlowTopologyDiscoveryListener
+import org.opendaylight.controller.sal.core.Edge
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.Link
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkDiscovered
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkOverutilized
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkRemoved
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.topology.discovery.rev130819.LinkUtilizationNormal
+import org.opendaylight.controller.sal.topology.TopoEdgeUpdate
+import org.opendaylight.controller.sal.discovery.IDiscoveryService
+
+class InventoryAndReadAdapter implements IPluginInTopologyService, IPluginInReadService, IPluginInInventoryService, OpendaylightInventoryListener, FlowTopologyDiscoveryListener {
 
     private static val LOG = LoggerFactory.getLogger(InventoryAndReadAdapter);
 
@@ -43,10 +55,18 @@ class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventor
 
     @Property
     OpendaylightFlowStatisticsService flowStatisticsService;
-    
+
     @Property
-    IPluginOutInventoryService adInventoryPublisher;
+    IPluginOutInventoryService inventoryPublisher;
+
+    @Property
+    IPluginOutTopologyService topologyPublisher;
     
+    @Property
+    IDiscoveryService discoveryPublisher;
+
+    @Property
+    FlowTopologyDiscoveryService topologyDiscovery;
 
     override getTransmitRate(NodeConnector connector) {
         val nodeConnector = readFlowCapableNodeConnector(connector.toNodeConnectorRef);
@@ -57,10 +77,10 @@ class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventor
         val input = new GetAllFlowStatisticsInputBuilder;
         input.setNode(node.toNodeRef);
         val result = flowStatisticsService.getAllFlowStatistics(input.build)
-        
+
         val statistics = result.get.result;
         val output = new ArrayList<FlowOnNode>();
-        for(stat : statistics.flowStatistics) {
+        for (stat : statistics.flowStatistics) {
             // FIXME: Create FlowOnNode
         }
         return output;
@@ -72,7 +92,7 @@ class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventor
         val result = flowStatisticsService.getAllNodeConnectorStatistics(input.build());
         val statistics = result.get.result.nodeConnectorStatistics;
         val ret = new ArrayList<NodeConnectorStatistics>();
-        for(stat : statistics) {
+        for (stat : statistics) {
             ret.add(stat.toNodeConnectorStatistics())
         }
         return ret;
@@ -109,7 +129,7 @@ class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventor
                 return it;
             }
         } catch (Exception e) {
-             LOG.error("Read flow not processed", e);
+            LOG.error("Read flow not processed", e);
         }
         return null;
     }
@@ -137,31 +157,31 @@ class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventor
     }
 
     override onNodeRemoved(NodeRemoved notification) {
-        
         // NOOP
     }
 
     override onNodeConnectorUpdated(NodeConnectorUpdated update) {
         val properties = Collections.<org.opendaylight.controller.sal.core.Property>emptySet();
-        adInventoryPublisher.updateNodeConnector(update.nodeConnectorRef.toADNodeConnector,UpdateType.CHANGED,properties);
+        inventoryPublisher.updateNodeConnector(update.nodeConnectorRef.toADNodeConnector, UpdateType.CHANGED, properties);
     }
 
     override onNodeUpdated(NodeUpdated notification) {
         val properties = Collections.<org.opendaylight.controller.sal.core.Property>emptySet();
-        adInventoryPublisher.updateNode(notification.nodeRef.toADNode,UpdateType.CHANGED,properties);
+        inventoryPublisher.updateNode(notification.nodeRef.toADNode, UpdateType.CHANGED, properties);
     }
 
-    override  getNodeProps() {
+    override getNodeProps() {
+
         // FIXME: Read from MD-SAL inventory service
         return null;
     }
 
-    override  getNodeConnectorProps(Boolean refresh) {
+    override getNodeConnectorProps(Boolean refresh) {
+
         // FIXME: Read from MD-SAL Invcentory Service
         return null;
     }
 
-
     override readNodeTable(NodeTable table, boolean cached) {
         throw new UnsupportedOperationException("TODO: auto-generated method stub")
     }
@@ -200,4 +220,33 @@ class InventoryAndReadAdapter implements IPluginInReadService, IPluginInInventor
         transmitByteCount = output.getBytes().getTransmitted().longValue();
         return it;
     }
+
+    override sollicitRefresh() {
+        topologyDiscovery.solicitRefresh
+    }
+    
+    override onLinkDiscovered(LinkDiscovered notification) {
+        val update = new TopoEdgeUpdate(notification.toADEdge,Collections.emptySet(),UpdateType.ADDED);
+        discoveryPublisher.notifyEdge(notification.toADEdge,UpdateType.ADDED,Collections.emptySet());
+        topologyPublisher.edgeUpdate(Collections.singletonList(update))
+    }
+    
+    override onLinkOverutilized(LinkOverutilized notification) {
+        topologyPublisher.edgeOverUtilized(notification.toADEdge)
+    }
+    
+    override onLinkRemoved(LinkRemoved notification) {
+        val update = new TopoEdgeUpdate(notification.toADEdge,Collections.emptySet(),UpdateType.REMOVED);
+        topologyPublisher.edgeUpdate(Collections.singletonList(update))
+    }
+    
+    override onLinkUtilizationNormal(LinkUtilizationNormal notification) {
+        topologyPublisher.edgeUtilBackToNormal(notification.toADEdge)
+    }
+    
+    
+    def Edge toADEdge(Link link) {
+        new Edge(link.source.toADNodeConnector,link.destination.toADNodeConnector)
+    }
+
 }