Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 1 | """ |
| 2 | Flow Test |
| 3 | Test each flow table can set entry, and packet rx correctly. |
| 4 | 1) L3UcastRoute |
| 5 | 2) QinQ |
| 6 | """ |
| 7 | |
| 8 | import logging |
| 9 | |
| 10 | from oftest import config |
| 11 | import oftest.base_tests as base_tests |
| 12 | import ofp |
| 13 | from oftest.testutils import * |
| 14 | from accton_util import * |
| 15 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 16 | class PacketInSrcMacMiss(base_tests.SimpleDataPlane): |
| 17 | """ |
| 18 | Test packet in function on a src-mac miss |
| 19 | Send a packet to each dataplane port and verify that a packet |
| 20 | in message is received from the controller for each |
| 21 | #todo verify you stop receiving after adding rule |
| 22 | """ |
| 23 | |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 24 | def runTest(self): |
| 25 | delete_all_flows(self.controller) |
| 26 | delete_all_groups(self.controller) |
| 27 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 28 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104, |
| 29 | vlan_vid=0x1001, dl_vlan_enable=True) |
| 30 | vlan_pkt = str(parsed_vlan_pkt) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 31 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 32 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 33 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 34 | # group table |
| 35 | # set up untag groups for each port |
| 36 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 37 | |
| 38 | for of_port in config["port_map"].keys(): |
| 39 | logging.info("PacketInMiss test, port %d", of_port) |
| 40 | self.dataplane.send(of_port, vlan_pkt) |
| 41 | |
| 42 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_NO_MATCH) |
| 43 | |
| 44 | verify_no_other_packets(self) |
| 45 | |
| 46 | class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane): |
| 47 | """ |
| 48 | Test L2 flood to a vlan |
| 49 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
| 50 | #todo take in account unknown src |
| 51 | """ |
| 52 | def runTest(self): |
| 53 | ports = sorted(config["port_map"].keys()) |
| 54 | delete_all_flows(self.controller) |
| 55 | delete_all_groups(self.controller) |
| 56 | |
| 57 | add_vlan_table_flow(self.controller, ports, 1) |
| 58 | |
| 59 | # set up tagged groups for each port |
| 60 | add_l2_interface_grouop(self.controller, ports, 1, True, 1) |
| 61 | |
| 62 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 63 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
| 64 | |
| 65 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a') |
| 66 | pkt = str(parsed_pkt) |
| 67 | #verify flood |
| 68 | for ofport in ports: |
| 69 | self.dataplane.send(ofport, pkt) |
| 70 | #self won't rx packet |
| 71 | verify_no_packet(self, pkt, ofport) |
| 72 | #others will rx packet |
| 73 | tmp_ports=list(ports) |
| 74 | tmp_ports.remove(ofport) |
| 75 | verify_packets(self, pkt, tmp_ports) |
| 76 | |
| 77 | verify_no_other_packets(self) |
| 78 | |
| 79 | |
| 80 | class L2UnicastTagged(base_tests.SimpleDataPlane): |
| 81 | """ |
| 82 | Test output function for an exact-match flow |
| 83 | |
| 84 | For each port A, adds a flow directing matching packets to that port. |
| 85 | Then, for all other ports B != A, verifies that sending a matching packet |
| 86 | to B results in an output to A. |
| 87 | """ |
| 88 | def runTest(self): |
| 89 | ports = sorted(config["port_map"].keys()) |
| 90 | |
| 91 | delete_all_flows(self.controller) |
| 92 | delete_all_groups(self.controller) |
| 93 | |
| 94 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 95 | |
| 96 | # set up tag groups for each port |
| 97 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 98 | |
| 99 | for port in ports: |
| 100 | group_id = encode_l2_interface_group_id(1, port) |
| 101 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 102 | do_barrier(self.controller) |
| 103 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 104 | for out_port in ports: |
| 105 | # change dest based on port number |
| 106 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 107 | for in_port in ports: |
| 108 | if in_port == out_port: |
| 109 | continue |
| 110 | # change source based on port number to avoid packet-ins from learning |
| 111 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 112 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 113 | pkt = str(parsed_pkt) |
| 114 | self.dataplane.send(in_port, pkt) |
| 115 | |
| 116 | for ofport in ports: |
| 117 | if ofport in [out_port]: |
| 118 | verify_packet(self, pkt, ofport) |
| 119 | else: |
| 120 | verify_no_packet(self, pkt, ofport) |
| 121 | |
| 122 | verify_no_other_packets(self) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 123 | |
| 124 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 125 | |
| 126 | class L3UcastTagged(base_tests.SimpleDataPlane): |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 127 | """ |
| 128 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) , |
| 129 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1) |
| 130 | """ |
| 131 | def runTest(self): |
| 132 | delete_all_flows(self.controller) |
| 133 | delete_all_groups(self.controller) |
| 134 | |
| 135 | if len(config["port_map"]) <2: |
| 136 | logging.info("Port count less than 2, can't run this case") |
| 137 | return |
| 138 | |
| 139 | vlan_id=1 |
| 140 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 141 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 142 | dip=0xc0a80001 |
| 143 | for port in config["port_map"].keys(): |
| 144 | #add l2 interface group |
| 145 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
| 146 | dst_mac[5]=vlan_id |
| 147 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 148 | #add vlan flow table |
| 149 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 150 | #add termination flow |
| 151 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 152 | #add unicast routing flow |
| 153 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 154 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id) |
| 155 | |
| 156 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 157 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 158 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 159 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 160 | vlan_id += 1 |
| 161 | |
| 162 | do_barrier(self.controller) |
| 163 | |
| 164 | port1=config["port_map"].keys()[0] |
| 165 | port2=config["port_map"].keys()[1] |
| 166 | #port 1 to port 2 |
| 167 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 168 | dst_mac[5]=1 |
| 169 | port1_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 170 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame^] | 171 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 172 | vlan_vid=1, |
| 173 | eth_dst=switch_mac, |
| 174 | eth_src=port1_mac, |
| 175 | ip_ttl=64, |
| 176 | ip_src="192.168.1.1", |
| 177 | ip_dst='192.168.2.1') |
| 178 | pkt=str(parsed_pkt) |
| 179 | self.dataplane.send(port1, pkt) |
| 180 | #build expect packet |
| 181 | dst_mac[5]=2 |
| 182 | port2_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 183 | exp_pkt = simple_tcp_packet(pktlen=100, |
| 184 | dl_vlan_enable=True, |
| 185 | vlan_vid=2, |
| 186 | eth_dst=port2_mac, |
| 187 | eth_src=switch_mac, |
| 188 | ip_ttl=63, |
| 189 | ip_src="192.168.1.1", |
| 190 | ip_dst='192.168.2.1') |
| 191 | pkt=str(exp_pkt) |
| 192 | verify_packet(self, pkt, port2) |
| 193 | verify_no_other_packets(self) |
| 194 | |
| 195 | #port 2 to port 1 |
| 196 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 197 | dst_mac[5]=2 |
| 198 | port2_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 199 | |
| 200 | parsed_pkt = simple_tcp_packet(pktlen=100, |
| 201 | dl_vlan_enable=True, |
| 202 | vlan_vid=2, |
| 203 | eth_dst=switch_mac, |
| 204 | eth_src=port2_mac, |
| 205 | ip_ttl=64, |
| 206 | ip_src="192.168.2.1", |
| 207 | ip_dst='192.168.1.1') |
| 208 | pkt=str(parsed_pkt) |
| 209 | self.dataplane.send(port2, pkt) |
| 210 | #build expect packet |
| 211 | dst_mac[5]=1 |
| 212 | port1_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 213 | exp_pkt = simple_tcp_packet(pktlen=100, |
| 214 | dl_vlan_enable=True, |
| 215 | vlan_vid=1, |
| 216 | eth_dst=port1_mac, |
| 217 | eth_src=switch_mac, |
| 218 | ip_ttl=63, |
| 219 | ip_src="192.168.2.1", |
| 220 | ip_dst='192.168.1.1') |
| 221 | pkt=str(exp_pkt) |
| 222 | verify_packet(self, pkt, port1) |
| 223 | verify_no_other_packets(self) |
| 224 | |