fix bug in chaining command
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 6 May 2016 08:35:15 +0000 (10:35 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 6 May 2016 08:35:15 +0000 (10:35 +0200)
src/emuvim/api/zerorpc/compute.py
src/emuvim/cli/network.py
src/emuvim/dcemulator/monitoring.py
src/emuvim/dcemulator/net.py
src/emuvim/dcemulator/node.py
src/emuvim/examples/monitoring_demo_topology.py

index 9d59183..4815fa7 100644 (file)
@@ -7,6 +7,9 @@ import logging
 import threading
 import zerorpc
 
+import paramiko
+import ipaddress
+
 logging.basicConfig(level=logging.INFO)
 
 
@@ -122,7 +125,7 @@ class MultiDatacenterApi(object):
                                   kwargs.get('network'),
                                   kwargs.get('command'))
         # start traffic source (with fixed ip addres, no use for now...)
-        self.compute_action_start( dc_label, 'psrc', 'profile_source', [{'id':'output'}], None)
+        psrc_status = self.compute_action_start( dc_label, 'psrc', 'profile_source', [{'id':'output'}], None)
         # link vnf to traffic source
         DCNetwork = self.dcs.get(dc_label).net
         DCNetwork.setChain('psrc', compute_name,
@@ -131,6 +134,32 @@ class MultiDatacenterApi(object):
                            cmd='add-flow', weight=None)
 
         ## SSM/SP tasks:
+        # start traffic generation
+        for nw in psrc_status.get('network'):
+            if nw.get('intf_name') == 'output':
+                psrc_output_ip = unicode(nw['ip'])
+                break
+        dummy_iperf_server_ip = ipaddress.IPv4Address(psrc_output_ip) + 1
+        iperf_cmd = 'iperf -c {0} -u -l18 -b10M -t1000 &'.format(dummy_iperf_server_ip)
+
+        psrc_mgmt_ip = psrc_status['docker_network']
+        psrc_user='root'
+        psrc_passw='root'
+
+        # use ssh login when starting command externally
+        ret = self.dcs.get(dc_label).containers.get('psrc').pexec(iperf_cmd)
+        logging.info(ret)
+        self.dcs.get(dc_label).containers.get('psrc').monitor()
+
+        #ssh does not work when exectuted via zerorpc command
+        #psrc_mgmt_ip = '172.17.0.3'
+        #ssh = paramiko.SSHClient()
+        #ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+        #ssh.connect(psrc_mgmt_ip, username='steven', password='test')
+        #ssh.connect(psrc_mgmt_ip, username='root', password='root')
+
+        #iperf_cmd = 'iperf -c {0} -u -l18 -b10M -t1000'.format(dummy_iperf_server_ip)
+        #stdin, stdout, stderr = ssh.exec_command(iperf_cmd)
         # get monitor data and analyze
 
         # create table
index 6b196a3..c524226 100755 (executable)
@@ -33,13 +33,14 @@ class ZeroRpcClient(object):
         vnf_dst_name = self._parse_vnf_name(args.get("destination"))\r
         vnf_dst_interface = self._parse_vnf_interface(args.get("destination"))\r
         weight = args.get("weight")\r
+        # note zerorpc does not support named arguments\r
         r = self.c.network_action_start(\r
             #args.get("datacenter"),\r
             vnf_src_name,\r
             vnf_dst_name,\r
-            vnf_src_interface=vnf_src_interface,\r
-            vnf_dst_interface=vnf_dst_interface,\r
-            weight=weight)\r
+            vnf_src_interface,\r
+            vnf_dst_interface,\r
+            weight)\r
         pp.pprint(r)\r
 \r
     def remove(self, args):\r
@@ -52,9 +53,9 @@ class ZeroRpcClient(object):
             #args.get("datacenter"),\r
             vnf_src_name,\r
             vnf_dst_name,\r
-            vnf_src_interface=vnf_src_interface,\r
-            vnf_dst_interface=vnf_dst_interface,\r
-            weight=weight)\r
+            vnf_src_interface,\r
+            vnf_dst_interface,\r
+            weight)\r
         pp.pprint(r)\r
 \r
     def _parse_vnf_name(self, vnf_name_str):\r
index b3ec7ee..6531beb 100755 (executable)
@@ -91,7 +91,7 @@ class DCNetworkMonitor():
                 if link_dict[link]['src_port_id'] == vnf_interface:\r
                     # found the right link and connected switch\r
                     # logging.info("{0},{1}".format(link_dict[link]['src_port_id'], vnf_source_interface))\r
-                    network_metric['mon_port'] = link_dict[link]['dst_port']\r
+                    network_metric['mon_port'] = link_dict[link]['dst_port_nr']\r
                     break\r
 \r
         if 'mon_port' not in network_metric:\r
index 633ec6b..ac44d57 100755 (executable)
@@ -223,6 +223,7 @@ class DCNetwork(Dockernet):
     # to remove chain do setChain( src, dst, cmd='del-flows')
     def setChain(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None, cmd='add-flow', weight=None):
 
+        logging.info('vnf_src_if: {0}'.format(vnf_src_interface))
         #check if port is specified (vnf:port)
         if vnf_src_interface is None:
             # take first interface by default
index d533f97..ad33adf 100755 (executable)
@@ -39,7 +39,7 @@ class EmulatorCompute(Docker):
         this compute instance is connected to.
         """
         # format list of tuples (name, Ip, MAC, isUp, status)
-        return [(str(i), i.IP(), i.MAC(), i.isUp(), i.status())
+        return [{'intf_name':str(i), 'ip':i.IP(), 'mac':i.MAC(), 'up':i.isUp(), 'status':i.status()}
                 for i in self.intfList()]
 
     def getStatus(self):
index fc515a8..8592d62 100755 (executable)
@@ -29,7 +29,7 @@ def create_topology1():
     """
     1. Create a data center network object (DCNetwork) with monitoring enabled
     """
-    net = DCNetwork(monitor=False)
+    net = DCNetwork(monitor=True)
 
     """
     1b. add a monitoring agent to the DCNetwork