+
+ 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'
+ # ryu expects the field to be masked
+ action['value'] = vlan | 0x1000
+ 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')
+