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 | |
Flavio Castro | 184cefe | 2015-11-19 20:52:49 -0500 | [diff] [blame^] | 46 | class L2FloodTagged(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 | # Installing flows to avoid packet-in |
| 65 | for port in ports: |
| 66 | group_id = encode_l2_interface_group_id(1, port) |
| 67 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, port], 1, group_id, True) |
| 68 | do_barrier(self.controller) |
| 69 | |
| 70 | #verify flood |
| 71 | for ofport in ports: |
| 72 | # change dest based on port number |
| 73 | mac_src= '00:12:34:56:78:%02X' % ofport |
| 74 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a', eth_src=mac_src) |
| 75 | pkt = str(parsed_pkt) |
| 76 | self.dataplane.send(ofport, pkt) |
| 77 | #self won't rx packet |
| 78 | verify_no_packet(self, pkt, ofport) |
| 79 | #others will rx packet |
| 80 | tmp_ports=list(ports) |
| 81 | tmp_ports.remove(ofport) |
| 82 | verify_packets(self, pkt, tmp_ports) |
| 83 | |
| 84 | verify_no_other_packets(self) |
| 85 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 86 | class L2FloodTaggedUnknownSrc(base_tests.SimpleDataPlane): |
| 87 | """ |
| 88 | Test L2 flood to a vlan |
| 89 | Send a packet with unknown dst_mac and check if the packet is flooded to all ports except inport |
| 90 | #todo take in account unknown src |
| 91 | """ |
| 92 | def runTest(self): |
| 93 | ports = sorted(config["port_map"].keys()) |
| 94 | delete_all_flows(self.controller) |
| 95 | delete_all_groups(self.controller) |
| 96 | |
| 97 | add_vlan_table_flow(self.controller, ports, 1) |
| 98 | |
| 99 | # set up tagged groups for each port |
| 100 | add_l2_interface_grouop(self.controller, ports, 1, True, 1) |
| 101 | |
| 102 | msg=add_l2_flood_group(self.controller, ports, 1, 1) |
| 103 | add_bridge_flow(self.controller, None, 1, msg.group_id, True) |
| 104 | |
| 105 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst='00:12:34:56:78:9a') |
| 106 | pkt = str(parsed_pkt) |
| 107 | #verify flood |
| 108 | for ofport in ports: |
| 109 | self.dataplane.send(ofport, pkt) |
| 110 | #self won't rx packet |
| 111 | verify_no_packet(self, pkt, ofport) |
| 112 | #others will rx packet |
| 113 | tmp_ports=list(ports) |
| 114 | tmp_ports.remove(ofport) |
| 115 | verify_packets(self, pkt, tmp_ports) |
| 116 | |
| 117 | verify_no_other_packets(self) |
| 118 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 119 | class L2UnicastTagged(base_tests.SimpleDataPlane): |
| 120 | """ |
| 121 | Test output function for an exact-match flow |
| 122 | |
| 123 | For each port A, adds a flow directing matching packets to that port. |
| 124 | Then, for all other ports B != A, verifies that sending a matching packet |
| 125 | to B results in an output to A. |
| 126 | """ |
| 127 | def runTest(self): |
| 128 | ports = sorted(config["port_map"].keys()) |
| 129 | |
| 130 | delete_all_flows(self.controller) |
| 131 | delete_all_groups(self.controller) |
| 132 | |
| 133 | add_vlan_table_flow(self.controller, config["port_map"].keys()) |
| 134 | |
| 135 | # set up tag groups for each port |
| 136 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, True, 1) |
| 137 | |
| 138 | for port in ports: |
| 139 | group_id = encode_l2_interface_group_id(1, port) |
| 140 | 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] | 141 | do_barrier(self.controller) |
| 142 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 143 | for out_port in ports: |
| 144 | # change dest based on port number |
| 145 | mac_dst= '00:12:34:56:78:%02X' % out_port |
| 146 | for in_port in ports: |
| 147 | if in_port == out_port: |
| 148 | continue |
| 149 | # change source based on port number to avoid packet-ins from learning |
| 150 | mac_src= '00:12:34:56:78:%02X' % in_port |
| 151 | parsed_pkt = simple_tcp_packet(dl_vlan_enable=True, vlan_vid=1, eth_dst=mac_dst, eth_src=mac_src) |
| 152 | pkt = str(parsed_pkt) |
| 153 | self.dataplane.send(in_port, pkt) |
| 154 | |
| 155 | for ofport in ports: |
| 156 | if ofport in [out_port]: |
| 157 | verify_packet(self, pkt, ofport) |
| 158 | else: |
| 159 | verify_no_packet(self, pkt, ofport) |
| 160 | |
| 161 | verify_no_other_packets(self) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 162 | |
| 163 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 164 | |
| 165 | class L3UcastTagged(base_tests.SimpleDataPlane): |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 166 | """ |
| 167 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) , |
| 168 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1) |
| 169 | """ |
| 170 | def runTest(self): |
| 171 | delete_all_flows(self.controller) |
| 172 | delete_all_groups(self.controller) |
| 173 | |
| 174 | if len(config["port_map"]) <2: |
| 175 | logging.info("Port count less than 2, can't run this case") |
| 176 | return |
| 177 | |
| 178 | vlan_id=1 |
| 179 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 180 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 181 | dip=0xc0a80001 |
| 182 | for port in config["port_map"].keys(): |
| 183 | #add l2 interface group |
| 184 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
| 185 | dst_mac[5]=vlan_id |
| 186 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 187 | #add vlan flow table |
| 188 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 189 | #add termination flow |
| 190 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 191 | #add unicast routing flow |
| 192 | dst_ip = dip + (vlan_id<<8) |
Flavio Castro | 6efe186 | 2015-11-18 16:28:06 -0500 | [diff] [blame] | 193 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id) |
| 194 | |
| 195 | #add entries in the Bridging table to avoid packet-in from mac learning |
| 196 | group_id = encode_l2_interface_group_id(vlan_id, port) |
| 197 | add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True) |
| 198 | |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 199 | vlan_id += 1 |
| 200 | |
| 201 | do_barrier(self.controller) |
| 202 | |
| 203 | port1=config["port_map"].keys()[0] |
| 204 | port2=config["port_map"].keys()[1] |
| 205 | #port 1 to port 2 |
| 206 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 207 | dst_mac[5]=1 |
| 208 | port1_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 209 | |
Flavio Castro | aabb579 | 2015-11-18 19:03:50 -0500 | [diff] [blame] | 210 | parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, |
Flavio Castro | 05d20bc | 2015-11-16 15:06:14 -0500 | [diff] [blame] | 211 | vlan_vid=1, |
| 212 | eth_dst=switch_mac, |
| 213 | eth_src=port1_mac, |
| 214 | ip_ttl=64, |
| 215 | ip_src="192.168.1.1", |
| 216 | ip_dst='192.168.2.1') |
| 217 | pkt=str(parsed_pkt) |
| 218 | self.dataplane.send(port1, pkt) |
| 219 | #build expect packet |
| 220 | dst_mac[5]=2 |
| 221 | port2_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 222 | exp_pkt = simple_tcp_packet(pktlen=100, |
| 223 | dl_vlan_enable=True, |
| 224 | vlan_vid=2, |
| 225 | eth_dst=port2_mac, |
| 226 | eth_src=switch_mac, |
| 227 | ip_ttl=63, |
| 228 | ip_src="192.168.1.1", |
| 229 | ip_dst='192.168.2.1') |
| 230 | pkt=str(exp_pkt) |
| 231 | verify_packet(self, pkt, port2) |
| 232 | verify_no_other_packets(self) |
| 233 | |
| 234 | #port 2 to port 1 |
| 235 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 236 | dst_mac[5]=2 |
| 237 | port2_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 238 | |
| 239 | parsed_pkt = simple_tcp_packet(pktlen=100, |
| 240 | dl_vlan_enable=True, |
| 241 | vlan_vid=2, |
| 242 | eth_dst=switch_mac, |
| 243 | eth_src=port2_mac, |
| 244 | ip_ttl=64, |
| 245 | ip_src="192.168.2.1", |
| 246 | ip_dst='192.168.1.1') |
| 247 | pkt=str(parsed_pkt) |
| 248 | self.dataplane.send(port2, pkt) |
| 249 | #build expect packet |
| 250 | dst_mac[5]=1 |
| 251 | port1_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 252 | exp_pkt = simple_tcp_packet(pktlen=100, |
| 253 | dl_vlan_enable=True, |
| 254 | vlan_vid=1, |
| 255 | eth_dst=port1_mac, |
| 256 | eth_src=switch_mac, |
| 257 | ip_ttl=63, |
| 258 | ip_src="192.168.2.1", |
| 259 | ip_dst='192.168.1.1') |
| 260 | pkt=str(exp_pkt) |
| 261 | verify_packet(self, pkt, port1) |
| 262 | verify_no_other_packets(self) |
| 263 | |