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
|
| 110 | """
|
| 111 |
|
| 112 | def runTest(self):
|
| 113 | delete_all_flows(self.controller)
|
| 114 | delete_all_groups(self.controller)
|
| 115 |
|
| 116 | parsed_pkt = simple_tcp_packet(pktlen=100)
|
| 117 | parsed_vlan_pkt = simple_tcp_packet(pktlen=104,
|
| 118 | vlan_vid=0x1001, dl_vlan_enable=True)
|
| 119 | pkt = str(parsed_pkt)
|
| 120 | vlan_pkt = str(parsed_vlan_pkt)
|
| 121 | # table 10: vlan
|
| 122 | # send to table 20
|
| 123 | add_vlan_table_flow(self.controller, config["port_map"].keys(), 1)
|
| 124 |
|
| 125 | # group table
|
| 126 | # set up untag groups for each port
|
| 127 | add_l2_interface_grouop(self.controller, config["port_map"].keys(), 1, False, 1)
|
| 128 |
|
| 129 | # create match
|
| 130 | match = ofp.match()
|
| 131 | match.oxm_list.append(ofp.oxm.vlan_vid(0x1001))
|
| 132 | request = ofp.message.flow_add(
|
| 133 | table_id=60,
|
| 134 | cookie=42,
|
| 135 | match=match,
|
| 136 | instructions=[
|
| 137 | ofp.instruction.apply_actions(
|
| 138 | actions=[
|
| 139 | ofp.action.output(
|
| 140 | port=ofp.OFPP_CONTROLLER,
|
| 141 | max_len=ofp.OFPCML_NO_BUFFER)]),
|
| 142 | ],
|
| 143 | buffer_id=ofp.OFP_NO_BUFFER,
|
| 144 | priority=1)
|
| 145 |
|
| 146 | logging.info("Inserting packet in flow to controller")
|
| 147 | self.controller.message_send(request)
|
| 148 | do_barrier(self.controller)
|
| 149 |
|
| 150 | for of_port in config["port_map"].keys():
|
| 151 | logging.info("PacketInMiss test, port %d", of_port)
|
| 152 | self.dataplane.send(of_port, pkt)
|
| 153 |
|
| 154 | #AOS current packet in will not have vlan tag
|
| 155 | #verify_packet_in(self, vlan_pkt, of_port, ofp.OFPR_ACTION)
|
| 156 | verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
|
| 157 | verify_no_other_packets(self)
|
| 158 |
|