macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 1 | """
|
| 2 | Flow Test
|
| 3 |
|
| 4 | Test each flow table can set entry, and packet rx correctly.
|
| 5 | """
|
| 6 |
|
| 7 | import logging
|
| 8 |
|
| 9 | from oftest import config
|
| 10 | import oftest.base_tests as base_tests
|
| 11 | import ofp
|
| 12 | from oftest.testutils import *
|
| 13 | from accton_util import *
|
| 14 |
|
| 15 | class L2McastFlow(base_tests.SimpleDataPlane):
|
| 16 | """
|
| 17 | Test output function for an exact-match flow
|
| 18 |
|
| 19 | Add some multicast flows
|
| 20 | Then, for all ports, verifies that sending a matching packet
|
| 21 | to a multicast match results in an output to all ports.
|
| 22 | """
|
| 23 | def runTest(self):
|
| 24 | ports = sorted(config["port_map"].keys())
|
| 25 |
|
| 26 | delete_all_flows(self.controller)
|
| 27 | delete_all_groups(self.controller)
|
| 28 |
|
| 29 | # table 10: vlan
|
| 30 | # send to table 20
|
| 31 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 32 |
|
| 33 | # group table
|
| 34 | # set up untag groups for each port
|
| 35 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, False)
|
| 36 |
|
| 37 | # set up multicast group
|
| 38 | add_l2_mcast_group(self.controller, config["port_map"].keys(), 1, 1)
|
| 39 |
|
| 40 | test_macs = [[0x01, 0x00, 0x5e, 0xff, 0xff, 0xff]]
|
| 41 |
|
| 42 | for test_mac in test_macs:
|
| 43 | group_id = encode_l2_mcast_group_id(1, 1)
|
| 44 | add_bridge_flow(self.controller, test_mac, 1, group_id, True)
|
| 45 |
|
| 46 | for test_mac in test_macs:
|
| 47 | mactest = ':'.join(['%02X' % x for x in test_mac])
|
| 48 |
|
| 49 | for in_port in ports:
|
| 50 | # change dest based on port number
|
| 51 | parsed_pkt = simple_tcp_packet(eth_dst=mactest)
|
| 52 | pkt = str(parsed_pkt)
|
| 53 | logging.info("OutputExact test, from port %d to mac %s", in_port, mactest)
|
| 54 | self.dataplane.send(in_port, pkt)
|
| 55 |
|
| 56 | for ofport in ports:
|
| 57 | if ofport == in_port: #tx port won't rx packet, unless L3 mcast routing
|
| 58 | continue
|
| 59 | verify_packet(self, pkt, ofport)
|
| 60 | verify_no_other_packets(self)
|
| 61 |
|
| 62 | class L2UnicastFlow(base_tests.SimpleDataPlane):
|
| 63 | """
|
| 64 | Test output function for an exact-match flow
|
| 65 |
|
| 66 | For each port A, adds a flow directing matching packets to that port.
|
| 67 | Then, for all other ports B != A, verifies that sending a matching packet
|
| 68 | to B results in an output to A.
|
| 69 | """
|
| 70 | def runTest(self):
|
| 71 | ports = sorted(config["port_map"].keys())
|
| 72 |
|
| 73 | delete_all_flows(self.controller)
|
| 74 | delete_all_groups(self.controller)
|
| 75 | # table 10: vlan
|
| 76 | # send to table 20
|
| 77 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 78 |
|
| 79 | # group table
|
| 80 | # set up untag groups for each port
|
| 81 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
|
| 82 |
|
| 83 | for out_port in ports:
|
| 84 | group_id = encode_l2_interface_group_id(1, out_port)
|
| 85 | add_bridge_flow(self.controller, [0x00, 0x12, 0x34, 0x56, 0x78, out_port], 1, group_id, True)
|
| 86 |
|
| 87 | for in_port in ports:
|
| 88 | if in_port == out_port:
|
| 89 | continue
|
| 90 | # change dest based on port number
|
| 91 | parsed_pkt = simple_tcp_packet(eth_dst='00:12:34:56:78:%02X' % out_port)
|
| 92 | pkt = str(parsed_pkt)
|
| 93 | logging.info("OutputExact test, ports %d to %d", in_port, out_port)
|
| 94 | self.dataplane.send(in_port, pkt)
|
| 95 |
|
| 96 | for ofport in ports:
|
| 97 | if ofport in [out_port]:
|
| 98 | verify_packet(self, pkt, ofport)
|
| 99 | else:
|
| 100 | verify_no_packet(self, pkt, ofport)
|
| 101 |
|
| 102 | verify_no_other_packets(self)
|
| 103 |
|
| 104 | class PacketInMiss(base_tests.SimpleDataPlane):
|
| 105 | """
|
| 106 | Test packet in function for a table-miss flow
|
| 107 |
|
| 108 | Send a packet to each dataplane port and verify that a packet
|
| 109 | in message is received from the controller for each
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 110 |
|
| 111 | NOTE: Verify This case the oft option shall not use --switch-ip
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 112 | """
|
| 113 |
|
| 114 | def runTest(self):
|
| 115 | delete_all_flows(self.controller)
|
| 116 | delete_all_groups(self.controller)
|
| 117 |
|
| 118 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 119 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 120 | vlan_vid=0x1001, dl_vlan_enable=True)
|
| 121 | pkt = str(parsed_pkt)
|
| 122 | vlan_pkt = str(parsed_vlan_pkt)
|
| 123 | # table 10: vlan
|
| 124 | # send to table 20
|
| 125 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 126 |
|
| 127 | # group table
|
| 128 | # set up untag groups for each port
|
| 129 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
|
| 130 |
|
| 131 | # create match
|
| 132 | match = ofp.match()
|
| 133 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
|
| 134 | request = ofp.message.flow_add(
|
| 135 | table_id=60,
|
| 136 | cookie=42,
|
| 137 | match=match,
|
| 138 | instructions=[
|
| 139 | ofp.instruction.apply_actions(
|
| 140 | actions=[
|
| 141 | ofp.action.output(
|
| 142 | port=ofp.OFPP_CONTROLLER,
|
| 143 | max_len=ofp.OFPCML_NO_BUFFER)]),
|
| 144 | ],
|
| 145 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 146 | priority=1)
|
| 147 |
|
| 148 | logging.info("Inserting packet in flow to controller")
|
| 149 | self.controller.message_send(request)
|
| 150 | do_barrier(self.controller)
|
| 151 |
|
| 152 | for of_port in config["port_map"].keys():
|
| 153 | logging.info("PacketInMiss test, port %d", of_port)
|
| 154 | self.dataplane.send(of_port, pkt)
|
| 155 |
|
| 156 | #AOS current packet in will not have vlan tag
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 157 | if config["cicada_poject"]:
|
| 158 | verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
|
| 159 | else:
|
| 160 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
|
| 161 |
|
macauley | 1e26c5b | 2015-07-16 17:27:32 +0800 | [diff] [blame] | 162 | verify_no_other_packets(self)
|
| 163 |
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 164 | class PacketOut(base_tests.SimpleDataPlane):
|
| 165 | """
|
| 166 | Verify action Flood, ALL, in port
|
| 167 | """
|
| 168 |
|
| 169 | def runTest(self):
|
| 170 | if config["cicada_poject"]:
|
| 171 | pass
|
| 172 |
|
| 173 | delete_all_flows(self.controller)
|
| 174 | delete_all_groups(self.controller)
|
| 175 |
|
| 176 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 177 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 178 | vlan_vid=0x1002, dl_vlan_enable=True)
|
| 179 |
|
| 180 | pkt = str(parsed_pkt)
|
| 181 | vlan_pkt = str(parsed_vlan_pkt)
|
| 182 |
|
| 183 |
|
| 184 | #packet out flood, untag packet
|
| 185 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 186 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 187 | actions=[ofp.action.output(
|
| 188 | port=ofp.OFPP_FLOOD)],
|
| 189 | data=pkt))
|
| 190 |
|
| 191 | for of_port in config["port_map"].keys():
|
| 192 | verify_packet(self, pkt, of_port)
|
| 193 |
|
| 194 | verify_no_other_packets(self)
|
| 195 |
|
| 196 | #packet out flood, tag packet, because it can't identify vlan has which port
|
| 197 | #so we do as all action.
|
| 198 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 199 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 200 | actions=[ofp.action.output(
|
| 201 | port=ofp.OFPP_FLOOD)],
|
| 202 | data=vlan_pkt))
|
| 203 |
|
| 204 | for of_port in config["port_map"].keys():
|
| 205 | verify_packet(self, vlan_pkt, of_port)
|
| 206 |
|
| 207 | verify_no_other_packets(self)
|
| 208 |
|
| 209 | #packet out all
|
| 210 | self.controller.message_send(ofp.message.packet_out(in_port=ofp.OFPP_CONTROLLER,
|
| 211 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 212 | actions=[ofp.action.output(
|
| 213 | port=ofp.OFPP_FLOOD)],
|
| 214 | data=pkt))
|
| 215 |
|
| 216 | for of_port in config["port_map"].keys():
|
| 217 | verify_packet(self, pkt, of_port)
|
| 218 |
|
| 219 | verify_no_other_packets(self)
|
| 220 |
|
| 221 | #packet out to in port
|
| 222 | in_port = config["port_map"].keys()[0]
|
| 223 | self.controller.message_send(ofp.message.packet_out(in_port=in_port,
|
| 224 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 225 | actions=[ofp.action.output(
|
| 226 | port=in_port)],
|
| 227 | data=pkt))
|
| 228 |
|
| 229 | verify_packet(self, pkt, in_port)
|
| 230 | verify_no_other_packets(self)
|
| 231 |
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame^] | 232 | class L3UcastRout(base_tests.SimpleDataPlane):
|
| 233 | """
|
| 234 | P1(vlan1, 192.168.1.1) , port2(vlan2, 19.168.2.1)
|
| 235 | """
|
| 236 | def runTest(self):
|
| 237 | delete_all_flows(self.controller)
|
| 238 | delete_all_groups(self.controller)
|
| 239 |
|
| 240 | vlan_id=1
|
| 241 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
|
| 242 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
|
| 243 | dip=0xc0a80001
|
| 244 | for port in config["port_map"].keys():
|
| 245 | #add l2 interface group
|
| 246 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
|
| 247 | dst_mac[5]=vlan_id
|
| 248 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
|
| 249 | #add vlan flow table
|
| 250 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
|
| 251 | #add termination flow
|
| 252 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
|
| 253 | #add unicast routing flow
|
| 254 | dst_ip = dip + (vlan_id<<8)
|
| 255 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, l3_msg.group_id)
|
| 256 | vlan_id += 1
|
| 257 |
|
| 258 | do_barrier(ctrl)
|
| 259 |
|
| 260 | port1=config["port_map"].keys()[0]
|
| 261 | port2=config["port_map"].keys()[1]
|
| 262 | #port 1 to port 2
|
| 263 | eth_dst = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 264 | dst_mac[5]=1
|
| 265 | eth_src=':'.join(['%02X' % x for x in dst_mac])
|
| 266 |
|
| 267 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 268 | eth_dst=eth_dst,
|
| 269 | eth_src=eth_src,
|
| 270 | ip_src="192.168.1.1",
|
| 271 | ip_dst='192.168.2.1')
|
| 272 | pkt=str(parsed_pkt)
|
| 273 | self.dataplane.send(port1, pkt)
|
| 274 | verify_packet(self, pkt, port2)
|
| 275 | verify_no_other_packets(self)
|
| 276 |
|
| 277 | #port 2 to port 1
|
| 278 | eth_dst = ':'.join(['%02X' % x for x in intf_src_mac])
|
| 279 | dst_mac[5]=2
|
| 280 | eth_src=':'.join(['%02X' % x for x in dst_mac])
|
| 281 |
|
| 282 | parsed_pkt = simple_tcp_packet(pktlen=100,
|
| 283 | eth_dst=eth_dst,
|
| 284 | eth_src=eth_src,
|
| 285 | ip_src="192.168.2.1",
|
| 286 | ip_dst='192.168.1.1')
|
| 287 | pkt=str(parsed_pkt)
|
| 288 | self.dataplane.send(port2, pkt)
|
| 289 | #verify_packet(self, pkt, port1)
|
| 290 | #verify_no_other_packets(self)
|
| 291 |
|
| 292 | class L3McastRoute(base_tests.SimpleDataPlane):
|
| 293 | def runTest(self):
|
| 294 | delete_all_flows(self.controller)
|
| 295 | delete_all_groups(self.controller)
|
| 296 |
|
macauley | 5295038 | 2015-07-17 15:59:01 +0800 | [diff] [blame] | 297 |
|
| 298 |
|
macauley | 0c54d3f | 2015-07-17 18:10:03 +0800 | [diff] [blame^] | 299 | |