+ CLI(self)
+
+ # to remove chain do setChain( src, dst, cmd='del-flows')
+ def setChain(self, vnf_src_name, vnf_dst_name, cmd='add-flow'):
+ # get shortest path
+ path = nx.shortest_path(self.DCNetwork_graph, vnf_src_name, vnf_dst_name)
+ logging.info("Path between {0} and {1}: {2}".format(vnf_src_name, vnf_dst_name, path))
+
+ current_hop = vnf_src_name
+ for i in range(0,len(path)):
+ next_hop = path[path.index(current_hop)+1]
+ next_node = self.getNodeByName(next_hop)
+
+ if next_hop == vnf_dst_name:
+ return "path added between {0} and {1}".format(vnf_src_name, vnf_dst_name)
+ elif not isinstance( next_node, OVSSwitch ):
+ logging.info("Next node: {0} is not a switch".format(next_hop))
+ return "Next node: {0} is not a switch".format(next_hop)
+
+
+ switch_inport = self.DCNetwork_graph[current_hop][next_hop]['dst_port']
+ next2_hop = path[path.index(current_hop)+2]
+ switch_outport = self.DCNetwork_graph[next_hop][next2_hop]['src_port']
+
+ logging.info("add flow in switch: {0} in_port: {1} out_port: {2}".format(next_node.name, switch_inport, switch_outport))
+ # set of entry via ovs-ofctl
+ # TODO use rest API of ryu to set flow entries to correct witch dpid
+ if isinstance( next_node, OVSSwitch ):
+ match = 'in_port=%s' % switch_inport
+
+ if cmd=='add-flow':
+ action = 'action=%s' % switch_outport
+ s = ','
+ ofcmd = s.join([match,action])
+ elif cmd=='del-flows':
+ ofcmd = match
+ else:
+ ofcmd=''
+
+ next_node.dpctl(cmd, ofcmd)
+
+ current_hop = next_hop
+
+ return "destination node: {0} not reached".format(vnf_dst_name)
+
+ # start Ryu Openflow controller as Remote Controller for the DCNetwork
+ def startRyu(self):
+ # start Ryu controller with rest-API
+ python_install_path = site.getsitepackages()[0]
+ ryu_path = python_install_path + '/ryu/app/simple_switch_13.py'
+ ryu_path2 = python_install_path + '/ryu/app/ofctl_rest.py'
+ # change the default Openflow controller port to 6653 (official IANA-assigned port number), as used by Mininet
+ # Ryu still uses 6633 as default
+ ryu_option = '--ofp-tcp-listen-port'
+ ryu_of_port = '6653'
+ ryu_cmd = 'ryu-manager'
+ FNULL = open(os.devnull, 'w')
+ self.ryu_process = Popen([ryu_cmd, ryu_path, ryu_path2, ryu_option, ryu_of_port], stdout=FNULL, stderr=FNULL)
\ No newline at end of file