update dashboard, to display placement, colored by node type
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Wed, 3 May 2017 22:01:52 +0000 (00:01 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Wed, 3 May 2017 22:01:52 +0000 (00:01 +0200)
src/emuvim/api/rest/network.py
src/emuvim/api/sonata/dummygatekeeper.py
src/emuvim/dashboard/index_upb.html
src/emuvim/dashboard/js/d3.v3.min.js [changed mode: 0644->0755]
src/emuvim/dashboard/js/graph.js [changed mode: 0644->0755]
src/emuvim/dcemulator/net.py

index 65dddc4..84db87e 100755 (executable)
@@ -36,6 +36,7 @@ import logging
 from flask_restful import Resource
 from flask import request
 import json
+import networkx
 
 logging.basicConfig(level=logging.INFO)
 
@@ -132,11 +133,12 @@ class DrawD3jsgraph(Resource):
         nodes2 = list()
         links = list()
         # add all DCs
-        #for dc in net.dcs:
+        node_attr = networkx.get_node_attributes(net.DCNetwork_graph, 'type')
         for node_name in net.DCNetwork_graph.nodes():
             nodes2.append(node_name)
             node_index = nodes2.index(node_name)
-            node_dict = {"name":node_name,"group":node_index}
+            type = node_attr[node_name]
+            node_dict = {"name":node_name,"group":type}
             nodes.append(node_dict)
 
         # add links between other DCs
index a7f0a6c..a57a6b9 100755 (executable)
@@ -259,7 +259,7 @@ class Service(object):
         # last step: remove the instance from the list of all instances
         del self.instances[instance_uuid]
 
-    def _start_vnfd(self, vnfd, vnf_id):
+    def _start_vnfd(self, vnfd, vnf_id, **kwargs):
         """
         Start a single VNFD of this service
         :param vnfd: vnfd descriptor dict
@@ -352,7 +352,8 @@ class Service(object):
                     cpu_period=cpu_period,
                     cpuset=cpu_list,
                     mem_limit=mem_lim,
-                    volumes=volumes)
+                    volumes=volumes,
+                    type=kwargs.get('type','docker'))
 
             # rename the docker0 interfaces (eth0) to the management port name defined in the VNFD
             if USE_DOCKER_MGMT:
@@ -546,7 +547,7 @@ class Service(object):
         if sap["type"] == "internal":
             vnfi = None
             if not GK_STANDALONE_MODE:
-                vnfi = self._start_vnfd(sap, sap['name'])
+                vnfi = self._start_vnfd(sap, sap['name'], type='sap_int')
             self.instances[instance_uuid]["vnf_instances"].append(vnfi)
 
         elif sap["type"] == "external":
index c5224bf..485a6b1 100755 (executable)
   </table>
 </div>
 
-<div>
-<script src="//d3js.org/d3.v3.min.js"></script>
-<script src="js/graph.js" type="text/javascript"></script>
-</div>
-
 
 </div>
 
old mode 100644 (file)
new mode 100755 (executable)
old mode 100644 (file)
new mode 100755 (executable)
index bc10d39..9b28e11
@@ -1,6 +1,6 @@
 var width = 960,
     height = 500,
-    color = d3.scale.category20c();
+    color = d3.scale.category10();
 
 var svg = d3.select("#table_graph").append("svg")
     .attr("width", width)
@@ -40,7 +40,7 @@ d3.json("http://127.0.0.1:5001/restapi/network/d3jsgraph", function(error, json)
   //    .attr("height", 16);
   node.append("circle")
     .attr("r", 10)
-    .style("fill", function(d) { return color(d.name); });
+    .style("fill", function(d) { return color(d.group); });
 
   node.append("text")
       .attr("dx", 12)
index 418ab20..faae0e3 100755 (executable)
@@ -240,16 +240,33 @@ class DCNetwork(Containernet):
         """
         Wrapper for addDocker method to use custom container class.
         """
-        self.DCNetwork_graph.add_node(label)
+        self.DCNetwork_graph.add_node(label, type=params.get('type', 'docker'))
         return Containernet.addDocker(self, label, cls=EmulatorCompute, **params)
 
-    def removeDocker( self, label, **params ):
+    def removeDocker( self, label, **params):
         """
         Wrapper for removeDocker method to update graph.
         """
         self.DCNetwork_graph.remove_node(label)
         return Containernet.removeDocker(self, label, **params)
 
+    def addExtSAP(self, sap_name, sap_ip, **params):
+        """
+        Wrapper for addExtSAP method to store SAP  also in graph.
+        """
+        # make sure that 'type' is set
+        params['type'] = params.get('type','sap_ext')
+        self.DCNetwork_graph.add_node(sap_name, type=params['type'])
+        LOG.info('add ext sap: {0}'.format(sap_name))
+        return Containernet.addExtSAP(self, sap_name, sap_ip, **params)
+
+    def removeExtSAP(self, sap_name, **params):
+        """
+        Wrapper for removeExtSAP method to remove SAP  also from graph.
+        """
+        self.DCNetwork_graph.remove_node(sap_name)
+        return Containernet.removeExtSAP(self, sap_name)
+
     def addSwitch( self, name, add_to_graph=True, **params ):
         """
         Wrapper for addSwitch method to store switch also in graph.
@@ -257,7 +274,8 @@ class DCNetwork(Containernet):
 
         # add this switch to the global topology overview
         if add_to_graph:
-            self.DCNetwork_graph.add_node(name)
+            self.DCNetwork_graph.add_node(name, type=params.get('type','switch'))
+            LOG.info('*** **** *** add switch: {0} type: {1}'.format(name, params.get('type')))
 
         # set the learning switch behavior
         if 'failMode' in params :
@@ -267,12 +285,6 @@ class DCNetwork(Containernet):
 
         s = Containernet.addSwitch(self, name, protocols='OpenFlow10,OpenFlow12,OpenFlow13', failMode=failMode, **params)
 
-        # set flow entry that enables learning switch behavior (needed to enable E-LAN functionality)
-        #LOG.info('failmode {0}'.format(failMode))
-        #if failMode == 'standalone' :
-        #    LOG.info('add NORMAL')
-        #    s.dpctl('add-flow', 'actions=NORMAL')
-
         return s
 
     def getAllContainers(self):