+ # take first link between switches by default
+ if isinstance( next_node, OVSSwitch ):
+ switch_inport_nr = self.DCNetwork_graph[current_hop][next_hop][0]['dst_port_nr']
+ current_hop = next_hop
+
+ return "path {2} between {0} and {1}".format(vnf_src_name, vnf_dst_name, cmd)
+
+ def _set_flow_entry_ryu_rest(self, node, switch_inport_nr, switch_outport_nr, **kwargs):
+ match = 'in_port=%s' % switch_inport_nr
+
+ cookie = kwargs.get('cookie')
+ match_input = kwargs.get('match')
+ cmd = kwargs.get('cmd')
+ path = kwargs.get('path')
+ current_hop = kwargs.get('current_hop')
+ vlan = kwargs.get('vlan')
+ priority = kwargs.get('priority')
+
+ s = ','
+ if match_input:
+ match = s.join([match, match_input])
+
+ flow = {}
+ flow['dpid'] = int(node.dpid, 16)
+
+ if cookie:
+ flow['cookie'] = int(cookie)
+ if priority:
+ flow['priority'] = int(priority)
+
+ flow['actions'] = []
+
+ # possible Ryu actions, match fields:
+ # http://ryu.readthedocs.io/en/latest/app/ofctl_rest.html#add-a-flow-entry
+ if cmd == 'add-flow':
+ prefix = 'stats/flowentry/add'
+ if vlan != None:
+ if path.index(current_hop) == 0: # first node
+ action = {}
+ action['type'] = 'PUSH_VLAN' # Push a new VLAN tag if a input frame is non-VLAN-tagged
+ action['ethertype'] = 33024 # Ethertype 0x8100(=33024): IEEE 802.1Q VLAN-tagged frame
+ flow['actions'].append(action)
+ action = {}
+ action['type'] = 'SET_FIELD'
+ action['field'] = 'vlan_vid'
+ action['value'] = vlan
+ flow['actions'].append(action)
+ elif path.index(current_hop) == len(path) - 1: # last node
+ match += ',dl_vlan=%s' % vlan
+ action = {}
+ action['type'] = 'POP_VLAN'
+ flow['actions'].append(action)
+ else: # middle nodes
+ match += ',dl_vlan=%s' % vlan
+ # output action must come last
+ action = {}
+ action['type'] = 'OUTPUT'
+ action['port'] = switch_outport_nr
+ flow['actions'].append(action)
+
+ elif cmd == 'del-flows':
+ prefix = 'stats/flowentry/delete'
+
+ if cookie:
+ # TODO: add cookie_mask as argument
+ flow['cookie_mask'] = int('0xffffffffffffffff', 16) # need full mask to match complete cookie
+
+ action = {}
+ action['type'] = 'OUTPUT'
+ action['port'] = switch_outport_nr
+ flow['actions'].append(action)
+
+ flow['match'] = self._parse_match(match)
+ self.ryu_REST(prefix, data=flow)
+
+ def _set_flow_entry_dpctl(self, node, switch_inport_nr, switch_outport_nr, **kwargs):
+ match = 'in_port=%s' % switch_inport_nr
+
+ cookie = kwargs.get('cookie')
+ match_input = kwargs.get('match')
+ cmd = kwargs.get('cmd')
+ path = kwargs.get('path')
+ current_hop = kwargs.get('current_hop')
+ vlan = kwargs.get('vlan')
+
+ s = ','
+ if cookie:
+ cookie = 'cookie=%s' % cookie
+ match = s.join([cookie, match])
+ if match_input:
+ match = s.join([match, match_input])
+ if cmd == 'add-flow':
+ action = 'action=%s' % switch_outport_nr
+ if vlan != None:
+ if path.index(current_hop) == 0: # first node
+ action = ('action=mod_vlan_vid:%s' % vlan) + (',output=%s' % switch_outport_nr)
+ match = '-O OpenFlow13 ' + match
+ elif path.index(current_hop) == len(path) - 1: # last node
+ match += ',dl_vlan=%s' % vlan
+ action = 'action=strip_vlan,output=%s' % switch_outport_nr
+ else: # middle nodes
+ match += ',dl_vlan=%s' % vlan
+ ofcmd = s.join([match, action])
+ elif cmd == 'del-flows':
+ ofcmd = match
+ else:
+ ofcmd = ''
+
+ node.dpctl(cmd, ofcmd)
+ LOG.info("{3} in switch: {0} in_port: {1} out_port: {2}".format(node.name, switch_inport_nr,
+ switch_outport_nr, cmd))