updated SDN chaining commands
diff --git a/src/emuvim/api/zerorpc/network.py b/src/emuvim/api/zerorpc/network.py
index f232166..a64b09e 100644
--- a/src/emuvim/api/zerorpc/network.py
+++ b/src/emuvim/api/zerorpc/network.py
@@ -64,37 +64,47 @@
def __init__(self, net):
self.net = net
- def network_action_start(self, vnf_src_name, vnf_dst_name):
+ def network_action_start(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None):
# call DCNetwork method, not really datacenter specific API for now...
# provided dc name needs to be part of API endpoint
# no check if vnfs are really connected to this datacenter...
logging.debug("RPC CALL: network chain start")
try:
c = self.net.setChain(
- vnf_src_name, vnf_dst_name)
+ vnf_src_name, vnf_dst_name, vnf_src_interface, vnf_dst_interface)
return str(c)
except Exception as ex:
logging.exception("RPC error.")
return ex.message
- def network_action_stop(self, vnf_src_name, vnf_dst_name):
+ def network_action_stop(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None):
# call DCNetwork method, not really datacenter specific API for now...
# provided dc name needs to be part of API endpoint
# no check if vnfs are really connected to this datacenter...
logging.debug("RPC CALL: network chain stop")
try:
c = self.net.setChain(
- vnf_src_name, vnf_dst_name, cmd='del-flows')
+ vnf_src_name, vnf_dst_name, vnf_src_interface, vnf_dst_interface, cmd='del-flows')
+ return c
+ except Exception as ex:
+ logging.exception("RPC error.")
+ return ex.message
+
+ # setup the rate measurement for a vnf interface
+ def monitor_setup_rate_measurement(self, vnf_name, vnf_interface, direction, metric):
+ logging.debug("RPC CALL: get rate")
+ try:
+ c = self.net.monitor_agent.setup_rate_measurement(vnf_name, vnf_interface, direction, metric)
return c
except Exception as ex:
logging.exception("RPC error.")
return ex.message
# get egress(default) or ingress rate of a vnf
- def monitor_get_rate(self, vnf_name, direction):
+ def monitor_get_rate(self, vnf_name, vnf_interface, direction, metric):
logging.debug("RPC CALL: get rate")
try:
- c = self.net.monitor_agent.get_rate(vnf_name, direction)
+ c = self.net.monitor_agent.get_rate(vnf_name, vnf_interface, direction, metric)
return c
except Exception as ex:
logging.exception("RPC error.")
diff --git a/src/emuvim/cli/monitor.py b/src/emuvim/cli/monitor.py
index 2caca2c..0c3c515 100755
--- a/src/emuvim/cli/monitor.py
+++ b/src/emuvim/cli/monitor.py
@@ -29,13 +29,33 @@
print "Command not implemented."
def get_rate(self, args):
+ vnf_name = self._parse_vnf_name(args.get("vnf_name"))
+ vnf_interface = self._parse_vnf_interface(args.get("vnf_name"))
+ self.c.monitor_setup_rate_measurement(
+ vnf_name,
+ vnf_interface,
+ args.get("direction"),
+ args.get("metric"))
while True:
r = self.c.monitor_get_rate(
- args.get("vnf_name"),
- args.get("direction"))
+ vnf_name,
+ vnf_interface,
+ args.get("direction"),
+ args.get("metric"))
pp.pprint(r)
time.sleep(1)
+ def _parse_vnf_name(self, vnf_name_str):
+ vnf_name = vnf_name_str.split(':')[0]
+ return vnf_name
+
+ def _parse_vnf_interface(self, vnf_name_str):
+ try:
+ vnf_interface = vnf_name_str.split(':')[1]
+ except:
+ vnf_interface = None
+
+ return vnf_interface
parser = argparse.ArgumentParser(description='son-emu network')
parser.add_argument(
@@ -46,7 +66,10 @@
help="vnf name to be monitored")
parser.add_argument(
"--direction", "-d", dest="direction",
- help="in (ingress rate) or out (egress rate)")
+ help="rx (ingress rate) or tx (egress rate)")
+parser.add_argument(
+ "--metric", "-m", dest="metric",
+ help="bytes (byte rate), packets (packet rate)")
def main(argv):
print "This is the son-emu monitor CLI."
diff --git a/src/emuvim/cli/network.py b/src/emuvim/cli/network.py
index 8d4219b..c27da59 100755
--- a/src/emuvim/cli/network.py
+++ b/src/emuvim/cli/network.py
@@ -28,19 +28,43 @@
print "Command not implemented."
def add(self, args):
+ vnf_src_name = self._parse_vnf_name(args.get("source"))
+ vnf_src_interface = self._parse_vnf_interface(args.get("source"))
+ vnf_dst_name = self._parse_vnf_name(args.get("destination"))
+ vnf_dst_interface = self._parse_vnf_interface(args.get("destination"))
r = self.c.network_action_start(
#args.get("datacenter"),
- args.get("source"),
- args.get("destination"))
+ vnf_src_name,
+ vnf_dst_name,
+ vnf_src_interface,
+ vnf_dst_interface)
pp.pprint(r)
def remove(self, args):
+ vnf_src_name = self._parse_vnf_name(args.get("source"))
+ vnf_src_interface = self._parse_vnf_interface(args.get("source"))
+ vnf_dst_name = self._parse_vnf_name(args.get("destination"))
+ vnf_dst_interface = self._parse_vnf_interface(args.get("destination"))
r = self.c.network_action_stop(
#args.get("datacenter"),
- args.get("source"),
- args.get("destination"))
+ vnf_src_name,
+ vnf_dst_name,
+ vnf_src_interface,
+ vnf_dst_interface)
pp.pprint(r)
+ def _parse_vnf_name(self, vnf_name_str):
+ vnf_name = vnf_name_str.split(':')[0]
+ return vnf_name
+
+ def _parse_vnf_interface(self, vnf_name_str):
+ try:
+ vnf_interface = vnf_name_str.split(':')[1]
+ except:
+ vnf_interface = None
+
+ return vnf_interface
+
parser = argparse.ArgumentParser(description='son-emu network')
parser.add_argument(
diff --git a/src/emuvim/dcemulator/monitoring.py b/src/emuvim/dcemulator/monitoring.py
index f5da2a1..50393ea 100755
--- a/src/emuvim/dcemulator/monitoring.py
+++ b/src/emuvim/dcemulator/monitoring.py
@@ -21,38 +21,35 @@
self.previous_measurement = 0
self.previous_monitor_time = 0
+ self.switch_dpid = 0
+ self.metric_key = None
+ self.mon_port = None
- def get_rate(self, vnf_name, direction='tx', metric='packets'):
+ # first set some parameters, before measurement can start
+ def setup_rate_measurement(self, vnf_name, vnf_interface=None, direction='tx', metric='packets'):
# check if port is specified (vnf:port)
- try:
- vnf_interface = vnf_name.split(':')[1]
- except:
+ if vnf_interface is None:
# take first interface by default
connected_sw = self.net.DCNetwork_graph.neighbors(vnf_name)[0]
link_dict = self.net.DCNetwork_graph[vnf_name][connected_sw]
vnf_interface = link_dict[0]['src_port_id']
- # vnf_source_interface = 0
-
- vnf_name = vnf_name.split(':')[0]
- # take into account that this is a MultiGraph
- #mon_port = self.net.DCNetwork_graph[vnf_name][connected_sw][0]['dst_port']
for connected_sw in self.net.DCNetwork_graph.neighbors(vnf_name):
link_dict = self.net.DCNetwork_graph[vnf_name][connected_sw]
for link in link_dict:
- # logging.info("{0},{1}".format(link_dict[link],vnf_source_interface))
+ # logging.info("{0},{1}".format(link_dict[link],vnf_interface))
if link_dict[link]['src_port_id'] == vnf_interface:
# found the right link and connected switch
# logging.info("{0},{1}".format(link_dict[link]['src_port_id'], vnf_source_interface))
- #src_sw = connected_sw
-
- mon_port = link_dict[link]['dst_port']
+ self.mon_port = link_dict[link]['dst_port']
break
try:
# default port direction to monitor
if direction is None:
direction = 'tx'
+ if metric is None:
+ metric = 'packets'
vnf_switch = self.net.DCNetwork_graph.neighbors(str(vnf_name))
@@ -66,21 +63,31 @@
vnf_switch = vnf_switch[0]
next_node = self.net.getNodeByName(vnf_switch)
- if not isinstance( next_node, OVSSwitch ):
+ if not isinstance(next_node, OVSSwitch):
logging.info("vnf: {0} is not connected to switch".format(vnf_name))
return
+ self.previous_measurement = 0
+ self.previous_monitor_time = 0
- switch_dpid = x = int(str(next_node.dpid),16)
+ #self.switch_dpid = x = int(str(next_node.dpid), 16)
+ self.switch_dpid = int(str(next_node.dpid), 16)
+ self.metric_key = '{0}_{1}'.format(direction, metric)
- # TODO get metric name from arg
- key = '{0}_{1}'.format(direction, metric)
+ except Exception as ex:
+ logging.exception("get_txrate error.")
+ return ex.message
- ret = self.REST_cmd('stats/port', switch_dpid)
+ # call this function repeatedly for streaming measurements
+ def get_rate(self, vnf_name, vnf_interface=None, direction='tx', metric='packets'):
+
+ key = self.metric_key
+
+ ret = self.REST_cmd('stats/port', self.switch_dpid)
port_stat_dict = ast.literal_eval(ret)
- for port_stat in port_stat_dict[str(switch_dpid)]:
- if port_stat['port_no'] == mon_port:
+ for port_stat in port_stat_dict[str(self.switch_dpid)]:
+ if port_stat['port_no'] == self.mon_port:
port_uptime = port_stat['duration_sec'] + port_stat['duration_nsec'] * 10 ** (-9)
this_measurement = port_stat[key]
@@ -89,13 +96,12 @@
self.previous_monitor_time = port_uptime
# do first measurement
time.sleep(1)
- byte_rate = self.get_rate(vnf_name,direction)
+ byte_rate = self.get_rate(vnf_name, vnf_interface, direction, metric)
return byte_rate
else:
time_delta = (port_uptime - self.previous_monitor_time)
byte_rate = (this_measurement - self.previous_measurement) / float(time_delta)
#logging.info('uptime:{2} delta:{0} rate:{1}'.format(time_delta,byte_rate,port_uptime))
- #return byte_rate
self.previous_measurement = this_measurement
self.previous_monitor_time = port_uptime
@@ -103,12 +109,6 @@
return ret
- except Exception as ex:
- logging.exception("get_txrate error.")
- return ex.message
-
-
-
def REST_cmd(self, prefix, dpid):
url = self.REST_api + '/' + str(prefix) + '/' + str(dpid)
req = urllib2.Request(url)
diff --git a/src/emuvim/dcemulator/net.py b/src/emuvim/dcemulator/net.py
index 47b4a7e..d6bb5bb 100755
--- a/src/emuvim/dcemulator/net.py
+++ b/src/emuvim/dcemulator/net.py
@@ -184,24 +184,21 @@
CLI(self)
# to remove chain do setChain( src, dst, cmd='del-flows')
- def setChain(self, vnf_src_name, vnf_dst_name, cmd='add-flow'):
+ def setChain(self, vnf_src_name, vnf_dst_name, vnf_src_interface=None, vnf_dst_interface=None, cmd='add-flow'):
#check if port is specified (vnf:port)
- try:
- vnf_source_interface = vnf_src_name.split(':')[1]
- except:
+ if vnf_src_interface is None:
# take first interface by default
connected_sw = self.DCNetwork_graph.neighbors(vnf_src_name)[0]
link_dict = self.DCNetwork_graph[vnf_src_name][connected_sw]
- vnf_source_interface = link_dict[0]['src_port_id']
+ vnf_src_interface = link_dict[0]['src_port_id']
#vnf_source_interface = 0
- vnf_src_name = vnf_src_name.split(':')[0]
for connected_sw in self.DCNetwork_graph.neighbors(vnf_src_name):
link_dict = self.DCNetwork_graph[vnf_src_name][connected_sw]
for link in link_dict:
#logging.info("{0},{1}".format(link_dict[link],vnf_source_interface))
- if link_dict[link]['src_port_id'] == vnf_source_interface:
+ if link_dict[link]['src_port_id'] == vnf_src_interface:
# found the right link and connected switch
#logging.info("{0},{1}".format(link_dict[link]['src_port_id'], vnf_source_interface))
src_sw = connected_sw
@@ -209,20 +206,18 @@
src_sw_inport = link_dict[link]['dst_port']
break
- try:
- vnf_dest_interface = vnf_dst_name.split(':')[1]
- except:
+ if vnf_dst_interface is None:
# take first interface by default
connected_sw = self.DCNetwork_graph.neighbors(vnf_dst_name)[0]
link_dict = self.DCNetwork_graph[connected_sw][vnf_dst_name]
- vnf_dest_interface = link_dict[0]['dst_port_id']
+ vnf_dst_interface = link_dict[0]['dst_port_id']
#vnf_dest_interface = 0
vnf_dst_name = vnf_dst_name.split(':')[0]
for connected_sw in self.DCNetwork_graph.neighbors(vnf_dst_name):
link_dict = self.DCNetwork_graph[connected_sw][vnf_dst_name]
for link in link_dict:
- if link_dict[link]['dst_port_id'] == vnf_dest_interface:
+ if link_dict[link]['dst_port_id'] == vnf_dst_interface:
# found the right link and connected switch
dst_sw = connected_sw
dst_sw_outport = link_dict[link]['src_port']
@@ -260,6 +255,7 @@
logging.info("Next node: {0} is not a switch".format(next_hop))
return "Next node: {0} is not a switch".format(next_hop)
else:
+ # take first link between switches by default
index_edge_out = 0
switch_outport = self.DCNetwork_graph[current_hop][next_hop][index_edge_out]['src_port']
@@ -292,9 +288,10 @@
current_node.dpctl(cmd, ofcmd)
logging.info("add flow in switch: {0} in_port: {1} out_port: {2}".format(current_node.name, switch_inport,
switch_outport))
-
- switch_inport = self.DCNetwork_graph[current_hop][next_hop][index_edge_out]['dst_port']
- current_hop = next_hop
+ # take first link between switches by default
+ if isinstance( next_node, OVSSwitch ):
+ switch_inport = self.DCNetwork_graph[current_hop][next_hop][0]['dst_port']
+ current_hop = next_hop
return "path added between {0} and {1}".format(vnf_src_name, vnf_dst_name)
#return "destination node: {0} not reached".format(vnf_dst_name)
@@ -311,9 +308,9 @@
ryu_of_port = '6653'
ryu_cmd = 'ryu-manager'
FNULL = open("/tmp/ryu.log", 'w')
- self.ryu_process = Popen([ryu_cmd, ryu_path, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL)
+ #self.ryu_process = Popen([ryu_cmd, ryu_path, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL)
# no learning switch
- #self.ryu_process = Popen([ryu_cmd, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL)
+ self.ryu_process = Popen([ryu_cmd, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL)
time.sleep(1)
def stopRyu(self):