def runTest(self): """ Add flow entries: First Table; Match IP Src A; set ToS = tos1, goto Second Table First Table; Match IP Src B; set ToS = tos2, goto Second Table Second Table; Match IP Src A; send to 1 Second Table; Match IP Src B; send to 1 Then send packets: IP A; expect port 1 with DSCP = dscp1 IP B; expect port 1 with DSCP = dscp2 @param self object instance @param EX_ACL_TABLE first table @param WC_ACL_TABLE second table @param dscp1 DSCP value to be set for first flow @param dscp2 DSCP value to be set for second flow """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up flow match in table A: set ToS #t_act = action.action_set_nw_tos() #t_act.nw_tos = tos1 dscp1 = 4 dscp2 = 8 t_act = action.action_set_field() t_act.field = match.ip_dscp(dscp1) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.10') t_act.field = match.ip_dscp(dscp2) #t_act.field = match.ip_ecn(3) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.30',clear_tag=False) # Set up flow matches in table B: routing testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.10") testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.30") # Generate packets and check them exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=1234, ip_dscp=dscp1) testutils.reply_check_dp(self, ip_src='192.168.1.10', tcp_sport=1234, exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])
def packet_to_flow_match(packet): """ Create a flow match that matches packet with the given wildcards @param packet The packet to use as a flow template @param pkt_format Currently only L2 is supported. Will indicate the overall packet type for parsing @return An ofp_match object if successful. None if format is not recognized. The wildcards of the match will be cleared for the values extracted from the packet. @todo check min length of packet @todo Check if packet is other than L2 format @todo implement other fields covered by OpenFlow 1.2 """ match_ls = match_list() if Ether in packet: ether = packet[Ether] eth_type = match.eth_type(ether.type) eth_dst = match.eth_dst(parse_mac(ether.dst)) eth_src = match.eth_src(parse_mac(ether.src)) match_ls.add(eth_type) match_ls.add(eth_dst) match_ls.add(eth_src) else: return match_ls if Dot1Q in packet: #TODO: nicer way to get last vlan tag? vlan = packet[Dot1Q:0] vlan_vid = match.vlan_vid(vlan.vlan) vlan_pcp = match.vlan_pcp(vlan.prio) match_ls.add(vlan_vid) match_ls.add(vlan_pcp) vlan_pl = vlan.payload while vlan_pl is not None and vlan_pl.name == Dot1Q.name: vlan = vlan_pl vlan_pl = vlan.payload #We need to overwrite the already # inserted eth_type eth_index = match.tlvs.index() eth_type = match.eth_type(vlan.type) match_ls.tlvs.insert(vlan.type, eth_index) #TODO ARP if MPLS in packet: mpls = packet[MPLS:0] mpls_label = match.mpls_label(mpls.label) mpls_tc = match.mpls_tc(mpls.cos) match_ls.add(mpls_label) match_ls.add(mpls_tc) return match_ls if IP in packet: ip = packet[IP] ipv4_src = match.ipv4_src(parse_ip(ip.src)) ipv4_dst = match.ipv4_dst(parse_ip(ip.dst)) ip_dscp = match.ip_dscp(ip.tos >> 2) ip_ecn = match.ip_ecn(ip.tos & 0x03) match_ls.add(ipv4_src) match_ls.add(ipv4_dst) match_ls.add(ip_dscp) match_ls.add(ip_ecn) else: return match_ls if TCP in packet: tcp = packet[TCP] ip_proto = match.ip_proto(6) tcp_src = match.tcp_src(tcp.sport) tcp_dst = match.tcp_dst(tcp.dport) match_ls.add(ip_proto) match_ls.add(tcp_src) match_ls.add(tcp_dst) return match_ls if UDP in packet: udp = packet[UDP] ip_proto = match.ip_proto(17) udp_src = match.tcp_src(udp.sport) udp_dst = match.tcp_dst(udp.dport) match_ls.add(ip_proto) match_ls.add(udp_src) match_ls.add(udp_dst) returnmatch_ls if ICMP in packet: icmp = packet[ICMP] ip_proto = match.ip_proto(1) icmp_type = match.icmp_type(icmp.type) icmp_code = match.icmp_code(icmp.code) match_ls.add(icmp_type) match_ls.add(icmp_code) return match_ls return match_ls
def packet_to_flow_match(packet): """ Create a flow match that matches packet with the given wildcards @param packet The packet to use as a flow template @param pkt_format Currently only L2 is supported. Will indicate the overall packet type for parsing @return An ofp_match object if successful. None if format is not recognized. The wildcards of the match will be cleared for the values extracted from the packet. @todo check min length of packet @todo Check if packet is other than L2 format @todo implement other fields covered by OpenFlow 1.2 """ match_ls = match_list() if Ether in packet: ether = packet[Ether] eth_type = match.eth_type(ether.type) eth_dst = match.eth_dst(parse_mac(ether.dst)) eth_src = match.eth_src(parse_mac(ether.src)) match_ls.add(eth_type) match_ls.add(eth_dst) match_ls.add(eth_src) else: return match_ls if Dot1Q in packet: #TODO: nicer way to get last vlan tag? vlan = packet[Dot1Q:0] vlan_vid = match.vlan_vid(vlan.vlan) vlan_pcp = match.vlan_pcp(vlan.prio) match_ls.add(vlan_vid) match_ls.add(vlan_pcp) vlan_pl = vlan.payload while vlan_pl is not None and vlan_pl.name == Dot1Q.name: vlan = vlan_pl vlan_pl = vlan.payload #We need to overwrite the already # inserted eth_type eth_index = match.tlvs.index() eth_type = match.eth_type(vlan.type) match_ls.tlvs.insert(vlan.type,eth_index) #TODO ARP if MPLS in packet: mpls = packet[MPLS:0] mpls_label = match.mpls_label(mpls.label) mpls_tc = match.mpls_tc(mpls.cos) match_ls.add(mpls_label) match_ls.add(mpls_tc) return match_ls if IP in packet: ip = packet[IP] ipv4_src = match.ipv4_src(parse_ip(ip.src)) ipv4_dst = match.ipv4_dst(parse_ip(ip.dst)) ip_dscp = match.ip_dscp(ip.tos >> 2) ip_ecn = match.ip_ecn(ip.tos & 0x03) match_ls.add(ipv4_src) match_ls.add(ipv4_dst) match_ls.add(ip_dscp) match_ls.add(ip_ecn) else: return match_ls if TCP in packet: tcp = packet[TCP] ip_proto = match.ip_proto(6) tcp_src = match.tcp_src(tcp.sport) tcp_dst = match.tcp_dst(tcp.dport) match_ls.add(ip_proto) match_ls.add(tcp_src) match_ls.add(tcp_dst) return match_ls if UDP in packet: udp = packet[UDP] ip_proto = match.ip_proto(17) udp_src = match.tcp_src(udp.sport) udp_dst = match.tcp_dst(udp.dport) match_ls.add(ip_proto) match_ls.add(udp_src) match_ls.add(udp_dst) returnmatch_ls if ICMP in packet: icmp = packet[ICMP] ip_proto = match.ip_proto(1) icmp_type = match.icmp_type(icmp.type) icmp_code = match.icmp_code(icmp.code) match_ls.add(icmp_type) match_ls.add(icmp_code) return match_ls return match_ls
def runTest(self): """ Add flow entries: First Table; Match IP Src A; set ToS = tos1, goto Second Table First Table; Match IP Src B; set ToS = tos2, goto Second Table Second Table; Match IP Src A; send to 1 Second Table; Match IP Src B; send to 1 Then send packets: IP A; expect port 1 with DSCP = dscp1 IP B; expect port 1 with DSCP = dscp2 @param self object instance @param EX_ACL_TABLE first table @param WC_ACL_TABLE second table @param dscp1 DSCP value to be set for first flow @param dscp2 DSCP value to be set for second flow """ of_ports = testutils.clear_switch(self, pa_port_map.keys(), pa_logger) # Set up flow match in table A: set ToS #t_act = action.action_set_nw_tos() #t_act.nw_tos = tos1 dscp1 = 4 dscp2 = 8 t_act = action.action_set_field() t_act.field = match.ip_dscp(dscp1) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.10') t_act.field = match.ip_dscp(dscp2) #t_act.field = match.ip_ecn(3) testutils.write_goto_action(self, testutils.WC_ACL_TABLE, testutils.WC_ALL_TABLE, t_act, ip_src='192.168.1.30', clear_tag=False) # Set up flow matches in table B: routing testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.10") testutils.write_output(self, testutils.WC_ALL_TABLE, of_ports[1], of_ports[2], ip_src="192.168.1.30") # Generate packets and check them exp_pkt = testutils.simple_tcp_packet(ip_src='192.168.1.10', tcp_sport=1234, ip_dscp=dscp1) testutils.reply_check_dp(self, ip_src='192.168.1.10', tcp_sport=1234, exp_pkt=exp_pkt, ing_port=of_ports[2], egr_port=of_ports[1])