import threading
import zerorpc
+import paramiko
+import ipaddress
+
logging.basicConfig(level=logging.INFO)
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,
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
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
#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
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
# 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
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):
"""
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