fix bugs in monitor commands
authorstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 26 Aug 2016 14:22:21 +0000 (16:22 +0200)
committerstevenvanrossem <steven.vanrossem@intec.ugent.be>
Fri, 26 Aug 2016 14:22:21 +0000 (16:22 +0200)
src/emuvim/dcemulator/monitoring.py

index 875913f..b5f0204 100755 (executable)
@@ -48,6 +48,8 @@ PUSHGATEWAY_PORT = 9091
 # we cannot use port 8080 because ryu-ofrest api  is already using that one\r
 CADVISOR_PORT = 8081\r
 \r
+COOKIE_MASK = 0xffffffff\r
+\r
 class DCNetworkMonitor():\r
     def __init__(self, net):\r
         self.net = net\r
@@ -344,7 +346,7 @@ class DCNetworkMonitor():
                 data = {}\r
 \r
                 data['cookie'] = flow_dict['cookie']\r
-                data['cookie_mask'] = flow_dict['cookie']\r
+                data['cookie_mask'] = COOKIE_MASK\r
 \r
                 if 'tx' in flow_dict['metric_key']:\r
                     data['match'] = {'in_port':flow_dict['mon_port']}\r
@@ -381,7 +383,12 @@ class DCNetworkMonitor():
 \r
                 # query Ryu\r
                 ret = self.net.ryu_REST('stats/port', dpid=dpid)\r
-                port_stat_dict = ast.literal_eval(ret)\r
+                if isinstance(ret, dict):\r
+                    port_stat_dict = ret\r
+                elif isinstance(ret, basestring):\r
+                    port_stat_dict = ast.literal_eval(ret.rstrip())\r
+                else:\r
+                    port_stat_dict = None\r
 \r
                 metric_list = [metric_dict for metric_dict in self.network_metrics\r
                                if int(metric_dict['switch_dpid'])==int(dpid)]\r