def output_port(port_num, max_len=0): """Return OpenFlow action to output to a port. Args: port_num (int): port to output to. max_len (int): maximum length of packet to output (default no maximum). Returns: ryu.ofproto.ofproto_v1_3_parser.OFPActionOutput: output to port action. """ return parser.OFPActionOutput(port_num, max_len=max_len)
def switch_features_handler(self, event): """ switch sent his features, check if Beba supported """ msg = event.msg datapath = msg.datapath LOG.info("Configuring switch %d..." % datapath.id) """ Set table 0 as stateful """ req = bebaparser.OFPExpMsgConfigureStatefulTable( datapath=datapath, table_id=0, stateful=1) datapath.send_msg(req) """ Set lookup extractor = {eth_dst} """ req = bebaparser.OFPExpMsgKeyExtract(datapath=datapath, command=bebaproto.OFPSC_EXP_SET_L_EXTRACTOR, fields=[ofproto.OXM_OF_ETH_SRC], table_id=0) datapath.send_msg(req) """ Set update extractor = {eth_dst} """ req = bebaparser.OFPExpMsgKeyExtract(datapath=datapath, command=bebaproto.OFPSC_EXP_SET_U_EXTRACTOR, fields=[ofproto.OXM_OF_ETH_SRC], table_id=0) datapath.send_msg(req) ########################################################################################### """ Set HF[1]=PKT_LEN [byte]""" req = bebaparser.OFPExpMsgHeaderFieldExtract( datapath=datapath, table_id=0, extractor_id=1, field=bebaproto.OXM_EXP_PKT_LEN ) datapath.send_msg(req) """ Update function: var( [count] , [value_to_be_varianced] , [avg_value] , [var_value]) = (IO1 , IN1 , IO2, IO3) has 4 inputs and 3 outputs OUT1 = FDV[0] = count OUT2 = FDV[1] = avg(IN1)*1000 OUT3 = FDV[2] = var(IN1) """ match = ofparser.OFPMatch() actions = [ofparser.OFPActionOutput(ofproto.OFPP_FLOOD), bebaparser.OFPExpActionSetDataVariable(table_id=0, opcode=bebaproto.OPCODE_VAR, output_fd_id=0, operand_1_hf_id=1, operand_2_fd_id=1, operand_3_fd_id=2)] self.add_flow(datapath=datapath, table_id=0, priority=0, match=match, actions=actions) """ $ sudo watch --color -n1 dpctl tcp:127.0.0.1:6634 stats-state -c
def _switch_features_handler(self, ev): datapath = ev.msg.datapath self.datapaths[datapath.id] = datapath self.statistics.append({}) # All packets with a destination address in the IP address range 22.0.0.0/8 are expected to arrive at host H2 match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP, ipv4_src=('11.0.0.0', '255.0.0.0'), ipv4_dst=('22.0.0.0', '255.0.0.0')) actions = [parser.OFPActionOutput(2)] self.program_flow(datapath, match, actions, priority=20, hard_timeout=0, idle_timeout=0) # All packets with a destination address in the IP address range 33.0.0.0/8 are expected to arrive at host H3 match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP, ipv4_src=('11.0.0.0', '255.0.0.0'), ipv4_dst=('33.0.0.0', '255.0.0.0')) actions = [parser.OFPActionOutput(3)] self.program_flow(datapath, match, actions, priority=20, hard_timeout=0, idle_timeout=0) # traffic destined to 44.0.0.0/8 should be forwarded in such a way that the overall traffic is evenly distributed among the two hosts H2 and H3 # set group table self.send_group_mod(datapath) match = parser.OFPMatch(eth_type=ether_types.ETH_TYPE_IP, ipv4_src=('11.0.0.0', '255.0.0.0'), ipv4_dst=('44.0.0.0', '255.0.0.0')) actions = [parser.OFPActionGroup(group_id=1)] self.program_flow(datapath, match, actions, priority=10, hard_timeout=0, idle_timeout=0)
def send_midpoint_flows_for_path(self, in_path): """ Gets list of link and then based on them it sends flows only to the switches in the midpoints. That is the switch in the middle of path not at the endpoints Note that it only takes care of nodes in the middle very well. :type in_path: list :param in_path: list of link objects which collectively is called a path. """ u_dpids = self.find_unique_dpid_inlinklist(in_path) for temp_dpid in u_dpids: ports = self.find_ports_for_dpid(temp_dpid, in_path) if len(ports) == 2: match = ofproto_v1_3_parser.OFPMatch(in_port=ports[0]) actions = [ofproto_v1_3_parser.OFPActionOutput(port=ports[1])] self.add_flow(self.get_dp_switch_with_id(temp_dpid), 1, match, actions) match = ofproto_v1_3_parser.OFPMatch(in_port=ports[1]) actions = [ofproto_v1_3_parser.OFPActionOutput(port=ports[0])] self.add_flow(self.get_dp_switch_with_id(temp_dpid), 1, match, actions) elif len(ports) > 2: print("Need to be implemented.")
def install_rule(self, **kwargs): ofproto = self.datapath.ofproto match = parser.OFPMatch(**kwargs.get('match')) action = parser.OFPActionOutput(kwargs.get('action').get('output')) self.wrapper.set_flow(self.datapath, match, [action], priority=priority)
def load_arp_icmp(self): """ Enable ARP and ICMP protocol """ match = ofparser.OFPMatch(eth_type=0x0806) actions = [ofparser.OFPActionOutput(ofp.OFPP_FLOOD)] self.add_flow(datapath=self.datapath, table_id=0, priority=100, match=match, actions=actions) # ICMP packets flooding - simple, TEMPORARY and dull solution. match = ofparser.OFPMatch(eth_type=0x0800, ip_proto=1) actions = [ofparser.OFPActionOutput(ofp.OFPP_FLOOD)] self.add_flow(datapath=self.datapath, table_id=0, priority=1, match=match, actions=actions)
def common_reply_actions(self): # pylint: disable=no-member return [ parser.NXActionRegMove(src_field='eth_src', dst_field='eth_dst', n_bits=48, src_ofs=0, dst_ofs=0), parser.OFPActionSetField(eth_src=FAKECLIENTMAC), parser.OFPActionOutput(ofp.OFPP_IN_PORT) ]
def send_pkt(self, dp, data, port=ofproto.OFPP_FLOOD): """ Convenience method that instructs a switch to forward a packet from the controller. """ out = parser.OFPPacketOut(datapath=dp, actions=[parser.OFPActionOutput(port)], in_port=dp.ofproto.OFPP_CONTROLLER, data=data, buffer_id=ofproto.OFP_NO_BUFFER) dp.send_msg(out)
def _parse_action(self, actions): ret = False for action in actions: if "OFPActionOutput" in action: out_port = action.get("OFPActionOutput").get("out_port") if out_port == "FLOOD": ret = [ ofproto_v1_3_parser.OFPActionOutput( ofproto_v1_3.OFPP_FLOOD, 0) ] elif out_port == "OFPP_CONTROLLER": ret = [ ofproto_v1_3_parser.OFPActionOutput( ofproto_v1_3.OFPP_CONTROLLER, ofproto_v1_3.OFPCML_NO_BUFFER) ] else: ret = [ofproto_v1_3_parser.OFPActionOutput(int(out_port))] return ret
def send_flows_for_path(self, in_link_path): """ Gets list of back up link and then based on them it sends flows to the switch. Note that it takes care of nodes in the middle very well. But for the endpoints, it assumes that the host is connected to port 1. :param in_link_path: List of link objects (a path) """ u_dpids = self.find_unique_dpid_inlinklist(in_link_path) visited_dpids = [] for temp_dpid in u_dpids: ports = self.find_ports_for_dpid(temp_dpid, in_link_path) if len(ports) == 2: visited_dpids.append(temp_dpid) match = ofproto_v1_3_parser.OFPMatch(in_port=ports[0]) actions = [ofproto_v1_3_parser.OFPActionOutput(port=ports[1])] self.add_flow(self.get_dp_switch_with_id(temp_dpid), 1, match, actions) match = ofproto_v1_3_parser.OFPMatch(in_port=ports[1]) actions = [ofproto_v1_3_parser.OFPActionOutput(port=ports[0])] self.add_flow(self.get_dp_switch_with_id(temp_dpid), 1, match, actions) elif len(ports) > 2: visited_dpids.append(temp_dpid) print("Need to be implemented.") end_points = [x for x in u_dpids if x not in visited_dpids] if len(end_points) > 2: print( "There is something wrong. There is two endpoints for a link") for temp_dpid_endpoint in end_points: other_port = self.find_ports_for_dpid(temp_dpid_endpoint, in_link_path) match = ofproto_v1_3_parser.OFPMatch(in_port=1) actions = [ofproto_v1_3_parser.OFPActionOutput(port=other_port[0])] self.add_flow(self.get_dp_switch_with_id(temp_dpid_endpoint), 1, match, actions) match = ofproto_v1_3_parser.OFPMatch() actions = [ofproto_v1_3_parser.OFPActionOutput(port=1)] self.add_flow(self.get_dp_switch_with_id(temp_dpid_endpoint), 1, match, actions)
def getReturnAndTagActions(self, switchID, numberOfFlowEntries): ''' Get the return and tag actions (only return actions in 3 flow entries case or the first return action for 4 flow entries case) :param switchID: ID of current switch :param numberOfFlowEntries: 3 or 4 flow entries mode :return: return and tag flow entries to be installed ''' #initialize the actions set to be empty actions = [] #3 flow entries case if (3 == numberOfFlowEntries): #transfer to "parent" port as is (the packet already contains the switch ID's tagging) actions.append( ofproto_v1_3_parser.OFPActionOutput( (self.switch_to_parent_port[switchID]))) #4 flow entries case else: #In 4 flow entries, the packet contains only tagging on last switch ID (inner tagging) need to add #the first switch ID (outer tagging) and change the ethertype to be dirReturnNoTag. # Pop vlan actions.append(ofproto_v1_3_parser.OFPActionPopVlan()) #set the DirectionReturn field to be dirReturnNoTag actions.append( ofproto_v1_3_parser.OFPActionSetField( eth_type=ExtraLayers.dirReturnNoTag)) # push a new VLAN with ethertype of vlan actions.append( ofproto_v1_3_parser.OFPActionPushVlan( ethertype=ExtraLayers.VLAN_ID_ETHERTYPE_QINQ)) # set vlan ID to be current switch (last switch field) actions.append( ofproto_v1_3_parser.OFPActionSetField( vlan_vid=retMaskedVlanID(switchID))) #transfer to "parent" port actions.append( ofproto_v1_3_parser.OFPActionOutput( (self.switch_to_parent_port[switchID]))) #return the actions list return actions
def send_group_mod(self, datapath): fproto = datapath.ofproto parser = datapath.ofproto_parser # H1 sends packets with IP destination addresses in the range 44.0.0.0/8 to either one of host H2 or H3 actions_1 = [parser.OFPActionOutput(2)] actions_2 = [parser.OFPActionOutput(3)] weight1 = 100 weight2 = 100 # Add buckets buckets = [ # for network destination H2 parser.OFPBucket(weight1, actions=actions_1), # for network destination H3 parser.OFPBucket(weight2, actions=actions_2) ] group_id = 1 req = parser.OFPGroupMod(datapath, ofproto.OFPGC_ADD, ofproto.OFPGT_SELECT, group_id, buckets) datapath.send_msg(req)
def install_stateless(self, datapath): ################################ TAB 0: FWD ################################### match = ofparser.OFPMatch(eth_type=0x800, in_port=HOST_PORT) self.add_flow(datapath=datapath, priority=0, table_id=0, match=match, actions=[]) match = ofparser.OFPMatch(eth_type=0x800, ip_dscp=0) actions = [ofparser.OFPActionOutput(1 if datapath.id != 8 else 2)] self.add_flow(datapath=datapath, priority=100, table_id=0, match=match, actions=actions) # If: sw[i] is connected to the host -> deliver the packet match = ofparser.OFPMatch(eth_type=0x800, ipv4_dst=server_dict[datapath.id]) actions = [ofparser.OFPActionOutput(HOST_PORT)] self.add_flow(datapath=datapath, priority=10, table_id=0, match=match, actions=actions) # Else: forward it to the other ports for p in CORE_PORTS: # If ip_dst does not belong to the host directly connected to me, # drop the packet because it is already been forwarded match = ofparser.OFPMatch(in_port=p, eth_type=0x800) actions = [ofparser.OFPActionOutput(1 if p == 2 else 2)] self.add_flow(datapath=datapath, priority=0, table_id=0, match=match, actions=actions)
def switch_features_handler(self, ev): datapath = ev.msg.datapath ofproto = datapath.ofproto parser = datapath.ofproto_parser # install the table-miss flow entry. match = parser.OFPMatch() actions = [ parser.OFPActionOutput(ofproto.OFPP_CONTROLLER, ofproto.OFPCML_NO_BUFFER) ] self.add_flow(datapath, 0, match, actions)
def send_group_mod(self, datapath): ofproto = datapath.ofproto parser = datapath.ofproto_parser actions_1 = [parser.OFPActionOutput(2)] actions_2 = [parser.OFPActionOutput(3)] weight1 = 100 weight2 = 100 # Add buckets buckets = [ # for network destination H2 parser.OFPBucket(weight1, actions = actions_1), # for network destination H3 parser.OFPBucket(weight2, actions = actions_2) ] group_id = 1 req = parser.OFPGroupMod(datapath, ofproto.OFPGC_ADD, ofproto.OFPGT_SELECT, group_id, buckets) datapath.send_msg(req)
def _switch_features_handler(self, ev): # to make sure host H2 and H3 receive an equal share of the overall traffic # N2_address_range = IPNetwork("22.0.0.0/9") # N3_address_range = IPNetwork("22.128.0.0/9") datapath = ev.msg.datapath match = parser.OFPMatch( # from N1 to N2 eth_type = ether_types.ETH_TYPE_IP, ipv4_src = ('11.0.0.0', '255.0.0.0'), ipv4_dst = ('22.0.0.0', '255.128.0.0') ) actions = [parser.OFPActionOutput(2)] self.program_flow(datapath, match, actions, priority = 10, hard_timeout = 0, idle_timeout = 0) match = parser.OFPMatch( # from N1 to N3 eth_type = ether_types.ETH_TYPE_IP, ipv4_src = ('11.0.0.0', '255.0.0.0'), ipv4_dst = ('22.128.0.0', '255.128.0.0') ) actions = [parser.OFPActionOutput(3)] self.program_flow(datapath, match, actions, priority = 10, hard_timeout = 0, idle_timeout = 0)
def _switch_features_handler(self, ev): dp = ev.msg.datapath # r: src, dst, sid, in_port, out_port rules = [r for r in ROUTING_TABLE if r[2] == dp.id] for r in rules: match = parser.OFPMatch( eth_type = ether_types.ETH_TYPE_IP, ipv4_src = r[0], ipv4_dst = r[1] ) actions = [parser.OFPActionOutput(r[4])] self.program_flow(dp, match, actions, priority=10, hard_timeout=0, idle_timeout=0)
def packet_in(self, event): msg = event.msg path = msg.datapath inpt = msg.match['in_port'] pckt = packet.Packet(msg.data) eth = pckt.get_protocols(ethernet.ethernet)[0] arpp = pckt.get_protocols(arp.arp)[0] acts = [parser.OFPActionOutput(inpt)] mtch = parser.OFPMatch(in_port=inpt, ipv4_dst=arpp.src_ip, ip_proto=0, eth_type=ether_types.ETH_TYPE_IP) self.send_flow(path, 1, mtch, acts) dest = eth.dst sorc = eth.src dpid = path.id self.mac_tab.setdefault(dpid, {}) self.mac_tab[dpid][sorc] = inpt outp = self.get_port(dest, dpid) acts = [parser.OFPActionOutput(outp)] if outp != proto.OFPP_FLOOD: mtch = parser.OFPMatch(in_port=outp, eth_dst=dest) self.send_flow(path, 1, mtch, acts) data = None if msg.buffer_id == proto.OFP_NO_BUFFER: data = msg.data out = parser.OFPPacketOut(datapath=path, buffer_id=msg.buffer_id, in_port=inpt, actions=acts, data=data) path.send_msg(out)
def execute_rule(self, rule): print(">> install new rule in switch %d: match=%s, action=%s" % (self.id, str(rule.matches), str(rule.actions))) actions = [] #action = parser.OFPActionOutput(kwargs.get('action').get('output')) match_dict = {} for k, v in rule.matches.items(): if k == '*': match_dict = {} break if k in MATCHES: match_dict[MATCHES[k]] = v # add eth_type match in case of ip if 'IP_DST' in rule.matches or 'IP_SRC' in rule.matches: match_dict['eth_type'] = ether_types.ETH_TYPE_IP for k, v in rule.actions.items(): if k == 'OUTPUT': # output flood if v == 'flood' or v == 'FLOOD': actions.append(parser.OFPActionOutput(ofproto.OFPP_FLOOD)) # output to a specific port if isinstance(v, int): actions.append(parser.OFPActionOutput(v)) if k == 'DROP': actions = [] break if k == 'CONTROLLER': actions.append(parser.OFPActionOutput(ofproto.OFPP_CONTROLLER)) match = parser.OFPMatch(**match_dict) self.wrapper.set_flow(self.datapath, match, actions, priority=rule.prio)
def install_edges(self, datapath): # Static routes configuration if datapath.id == 5: match = ofparser.OFPMatch(in_port=HOST_PORT) actions = [ofparser.OFPActionOutput(2)] self.add_flow(datapath=datapath, priority=0, table_id=0, match=match, actions=actions) match = ofparser.OFPMatch(in_port=HOST_PORT, eth_type=0x800, ipv4_dst=addrs[0]) actions = [ofparser.OFPActionOutput(1)] self.add_flow(datapath=datapath, priority=10, table_id=0, match=match, actions=actions) else: match = ofparser.OFPMatch(in_port=HOST_PORT) actions = [ofparser.OFPActionOutput(1)] self.add_flow(datapath=datapath, priority=0, table_id=0, match=match, actions=actions) if datapath.id == 1 or datapath.id == 3: match = ofparser.OFPMatch(in_port=HOST_PORT, eth_type=0x800, ipv4_dst=addrs[1]) actions = [ofparser.OFPActionOutput(2)] self.add_flow(datapath=datapath, priority=10, table_id=0, match=match, actions=actions) elif datapath.id == 7: match = ofparser.OFPMatch(in_port=HOST_PORT, eth_type=0x800, ipv4_dst=addrs[0]) actions = [ofparser.OFPActionOutput(2)] self.add_flow(datapath=datapath, priority=10, table_id=0, match=match, actions=actions) # Dumbly forward ALL for p in CORE_PORTS: match = ofparser.OFPMatch(in_port=p) actions = [ofparser.OFPActionOutput(1 if p == 2 else 2)] self.add_flow(datapath=datapath, priority=5, table_id=0, match=match, actions=actions)
def _send_packet(self, datapath, port, pkt): ofproto = datapath.ofproto parser = datapath.ofproto_parser pkt.serialize() self.logger.info("packet-out %s" % (pkt, )) data = pkt.data actions = [parser.OFPActionOutput(port=port)] out = parser.OFPPacketOut(datapath=datapath, buffer_id=ofproto.OFP_NO_BUFFER, in_port=ofproto.OFPP_CONTROLLER, actions=actions, data=data) datapath.send_msg(out)
def new_contstructorFlowMod(self, datapath, cookie=0, cookie_mask=0, table_id=0, command=ofproto_v1_3.OFPFC_ADD, idle_timeout=0, hard_timeout=0, priority=ofproto_v1_3.OFP_DEFAULT_PRIORITY, buffer_id=ofproto_v1_3.OFP_NO_BUFFER, out_port=0, out_group=0, flags=0, match=None, instructions=None): if instructions is not None and datapath.id == sw_snort: for instruction in instructions: if (instruction.type == 4 or instruction.type == 3): if (instruction.actions is not None): for action in instruction.actions: if action.type == 0: if action.port == snort_port: return old_constructorFlowMod( self, datapath, cookie, cookie_mask, table_id, command, idle_timeout, hard_timeout, priority, buffer_id, out_port, out_group, flags, match, instructions) else: instruction.actions.append( parser.OFPActionOutput(snort_port)) return old_constructorFlowMod( self, datapath, cookie, cookie_mask, table_id, command, idle_timeout, hard_timeout, priority, buffer_id, out_port, out_group, flags, match, instructions) return old_constructorFlowMod(self, datapath, cookie, cookie_mask, table_id, command, idle_timeout, hard_timeout, priority, buffer_id, out_port, out_group, flags, match, instructions)
def switch_features_handler(self, event): """ Switche sent his features, check if Beba supported """ msg = event.msg datapath = msg.datapath devices.append(datapath) LOG.info("Configuring switch %d..." % datapath.id) """ Set table 0 as stateful """ req = bebaparser.OFPExpMsgConfigureStatefulTable(datapath=datapath, table_id=0, stateful=1) datapath.send_msg(req) """ Set lookup extractor = {eth_dst} """ req = bebaparser.OFPExpMsgKeyExtract( datapath=datapath, command=bebaproto.OFPSC_EXP_SET_L_EXTRACTOR, fields=[ofp.OXM_OF_ETH_DST], table_id=0) datapath.send_msg(req) """ Set update extractor = {eth_src} """ req = bebaparser.OFPExpMsgKeyExtract( datapath=datapath, command=bebaproto.OFPSC_EXP_SET_U_EXTRACTOR, fields=[ofp.OXM_OF_ETH_SRC], table_id=0) datapath.send_msg(req) # for each input port, for each state for i in range(1, N + 1): for s in range(N + 1): match = ofparser.OFPMatch(in_port=i, state=s) if s == 0: out_port = ofp.OFPP_FLOOD else: out_port = s actions = [ bebaparser.OFPExpActionSetState(state=i, table_id=0, hard_timeout=10), ofparser.OFPActionOutput(out_port) #,ofparser.OFPActionOutput(ofp.OFPP_CONTROLLER, #ofp.OFPCML_NO_BUFFER) ] # Triggers flow mod self.add_flow(datapath=datapath, table_id=0, priority=0, match=match, actions=actions)
def flow_example(self, dp): # a flow to correctly forward all traffic to m1 match = parser.OFPMatch( # if you want to match on any part of the IP header, you always have # to match on the IP type in the ethernet header as well. eth_type=ether_types.ETH_TYPE_IP, ipv4_dst='44.0.0.0/8') action = [parser.OFPActionOutput(4)] self.program_flow(dp, match, action, priority=1, idle_timeout=0, hard_timeout=0)
def test13(self, datapath): self.send_table_mod(datapath) (global_state, global_state_mask ) = osparser.masked_global_state_from_str("*1*1*1*1*0*0*1*1*1*1*1*1*") actions = [ofparser.OFPActionOutput(6, 0)] match = ofparser.OFPMatch( in_port=5, eth_type=0x800, ip_proto=1, global_state=osparser.masked_global_state_from_str( "*1*1*1*1*0*0*1*1*1*1*1*1*")) self.add_flow(datapath, 200, match, actions) actions = [ osparser.OFPExpActionSetGlobalState( global_state=global_state, global_state_mask=global_state_mask) ] match = ofparser.OFPMatch(in_port=5, eth_type=0x800, ip_proto=1) self.add_flow(datapath, 100, match, actions) actions = [ofparser.OFPActionOutput(5, 0)] match = ofparser.OFPMatch(in_port=6, eth_type=0x800, ip_proto=1) self.add_flow(datapath, 200, match, actions)
def install_forward(self, datapath): match = ofparser.OFPMatch() actions = [ofparser.OFPActionOutput(ofproto.OFPP_FLOOD)] inst = [ ofparser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS, actions) ] mod = ofparser.OFPFlowMod(datapath=datapath, table_id=0, priority=10, match=match, instructions=inst) datapath.send_msg(mod)
def _state_change(self, ev): dp = ev.datapath print("OFPStateChange {ip}:{port}".format(ip=ev.datapath.address[0], port=ev.datapath.address[1])) actions = [ofp_parser.OFPActionOutput(ofp.OFPP_FLOOD)] # out = ofp_parser.OFPPacketOut(datapath=dp, in_port=1, actions=actions) data = json.dumps({"cumprimento": "Bom dia", "hora": 10, "minuto": 34}) data = data + bytearray(1398 - len(data)) out = ofp_parser.OFPExperimenter(datapath=dp, experimenter=0x00000005, exp_type=20, data=bytearray(data)) dp.send_msg(out) time.sleep(.3)
def test1(self, datapath): LOG.info("Configuring switch %d..." % datapath.id) LOG.info("Creating ARP triggers...") match = ofparser.OFPMatch(in_port=1) actions = [ ofparser.OFPActionOutput(ofproto.OFPP_CONTROLLER, ofproto.OFPCML_NO_BUFFER) ] self.add_flow(datapath=datapath, table_id=0, priority=0, match=match, actions=actions)
def _switch_features_handler(self, ev): datapath = ev.msg.datapath self.datapaths[datapath.id] = datapath self.statistics.append({}) rules = [r for r in ROUTING_complete if r[3] == datapath.id] for r in rules: match = parser.OFPMatch( in_port = r[2], eth_type = ether_types.ETH_TYPE_IP, ipv4_src = r[0], ipv4_dst = r[1] ) actions = [parser.OFPActionOutput(r[4])] self.program_flow(datapath, match, actions, priority=10)
def test11(self, datapath): self.send_table_mod(datapath) (global_state, global_state_mask) = bebaparser.masked_global_state_from_str( "1*1*1*1*1*1*1*1*0*0*1*1*1*1*1*1*") actions = [ofparser.OFPActionOutput(6, 0)] match = ofparser.OFPMatch( in_port=5, eth_type=0x800, ip_proto=1, global_state=bebaparser.masked_global_state_from_str( "1*1*1*1*1*1*1*1*0*0*1*1*1*1*1*1*")) self.add_flow(datapath, 150, match, actions) msg = bebaparser.OFPExpSetGlobalState( datapath=datapath, global_state=global_state, global_state_mask=global_state_mask) datapath.send_msg(msg) actions = [ofparser.OFPActionOutput(5, 0)] match = ofparser.OFPMatch(in_port=6, ip_proto=1, eth_type=0x800) self.add_flow(datapath, 200, match, actions)