Flavio Castro | 96646c6 | 2015-11-16 15:05:43 -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 | |
| 16 | class L3UcastRoute(base_tests.SimpleDataPlane): |
| 17 | """ |
| 18 | Port1(vlan1, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 192.168.1.1) , |
| 19 | Port2(vlan2, 0x00, 0x00, 0x00, 0x22, 0x22, 0x02, 19.168.2.1) |
| 20 | """ |
| 21 | def runTest(self): |
| 22 | delete_all_flows(self.controller) |
| 23 | delete_all_groups(self.controller) |
| 24 | |
| 25 | if len(config["port_map"]) <2: |
| 26 | logging.info("Port count less than 2, can't run this case") |
| 27 | return |
| 28 | |
| 29 | vlan_id=1 |
| 30 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 31 | dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00] |
| 32 | dip=0xc0a80001 |
| 33 | for port in config["port_map"].keys(): |
| 34 | #add l2 interface group |
| 35 | add_one_l2_interface_grouop(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False) |
| 36 | dst_mac[5]=vlan_id |
| 37 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac) |
| 38 | #add vlan flow table |
| 39 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
| 40 | #add termination flow |
| 41 | add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id) |
| 42 | #add unicast routing flow |
| 43 | dst_ip = dip + (vlan_id<<8) |
| 44 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id) |
| 45 | vlan_id += 1 |
| 46 | |
| 47 | do_barrier(self.controller) |
| 48 | |
| 49 | port1=config["port_map"].keys()[0] |
| 50 | port2=config["port_map"].keys()[1] |
| 51 | #port 1 to port 2 |
| 52 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 53 | dst_mac[5]=1 |
| 54 | port1_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 55 | |
| 56 | parsed_pkt = simple_tcp_packet(pktlen=100, |
| 57 | dl_vlan_enable=True, |
| 58 | vlan_vid=1, |
| 59 | eth_dst=switch_mac, |
| 60 | eth_src=port1_mac, |
| 61 | ip_ttl=64, |
| 62 | ip_src="192.168.1.1", |
| 63 | ip_dst='192.168.2.1') |
| 64 | pkt=str(parsed_pkt) |
| 65 | self.dataplane.send(port1, pkt) |
| 66 | #build expect packet |
| 67 | dst_mac[5]=2 |
| 68 | port2_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 69 | exp_pkt = simple_tcp_packet(pktlen=100, |
| 70 | dl_vlan_enable=True, |
| 71 | vlan_vid=2, |
| 72 | eth_dst=port2_mac, |
| 73 | eth_src=switch_mac, |
| 74 | ip_ttl=63, |
| 75 | ip_src="192.168.1.1", |
| 76 | ip_dst='192.168.2.1') |
| 77 | pkt=str(exp_pkt) |
| 78 | verify_packet(self, pkt, port2) |
| 79 | verify_no_other_packets(self) |
| 80 | |
| 81 | #port 2 to port 1 |
| 82 | switch_mac = ':'.join(['%02X' % x for x in intf_src_mac]) |
| 83 | dst_mac[5]=2 |
| 84 | port2_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 85 | |
| 86 | parsed_pkt = simple_tcp_packet(pktlen=100, |
| 87 | dl_vlan_enable=True, |
| 88 | vlan_vid=2, |
| 89 | eth_dst=switch_mac, |
| 90 | eth_src=port2_mac, |
| 91 | ip_ttl=64, |
| 92 | ip_src="192.168.2.1", |
| 93 | ip_dst='192.168.1.1') |
| 94 | pkt=str(parsed_pkt) |
| 95 | self.dataplane.send(port2, pkt) |
| 96 | #build expect packet |
| 97 | dst_mac[5]=1 |
| 98 | port1_mac=':'.join(['%02X' % x for x in dst_mac]) |
| 99 | exp_pkt = simple_tcp_packet(pktlen=100, |
| 100 | dl_vlan_enable=True, |
| 101 | vlan_vid=1, |
| 102 | eth_dst=port1_mac, |
| 103 | eth_src=switch_mac, |
| 104 | ip_ttl=63, |
| 105 | ip_src="192.168.2.1", |
| 106 | ip_dst='192.168.1.1') |
| 107 | pkt=str(exp_pkt) |
| 108 | verify_packet(self, pkt, port1) |
| 109 | verify_no_other_packets(self) |
| 110 | |
| 111 | |
| 112 | class qinq(base_tests.SimpleDataPlane): |
| 113 | def runTest(self): |
| 114 | delete_all_flows(self.controller) |
| 115 | delete_all_groups(self.controller) |
| 116 | |
| 117 | in_port = config["port_map"].keys()[0] |
| 118 | out_port = config["port_map"].keys()[1] |
| 119 | out_vlan=10 |
| 120 | #add_vlan_table_flow_pvid(self.controller, in_port, None, out_vlan, False) |
| 121 | add_vlan_table_flow_pvid(self.controller, in_port, 1,out_vlan, False) |
| 122 | group_id, msg=add_one_l2_interface_grouop(self.controller, out_port, out_vlan, True, False) |
| 123 | #add acl |
| 124 | match = ofp.match() |
| 125 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 126 | request = ofp.message.flow_add( |
| 127 | table_id=60, |
| 128 | cookie=42, |
| 129 | match=match, |
| 130 | instructions=[ |
| 131 | ofp.instruction.write_actions( |
| 132 | actions=[ |
| 133 | ofp.action.group(msg.group_id)]) |
| 134 | ], |
| 135 | buffer_id=ofp.OFP_NO_BUFFER, |
| 136 | priority=1000) |
| 137 | self.controller.message_send(request) |
| 138 | |
| 139 | #input tag packet |
| 140 | parsed_pkt = simple_tcp_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=1) |
| 141 | pkt = str(parsed_pkt) |
| 142 | self.dataplane.send(in_port, pkt) |
| 143 | |
| 144 | parsed_pkt = simple_tcp_packet_two_vlan(pktlen=108, out_dl_vlan_enable=True, out_vlan_vid=10, |
| 145 | in_dl_vlan_enable=True, in_vlan_vid=1) |
| 146 | verify_packet(self, str(parsed_pkt), out_port) |
| 147 | |
| 148 | |
| 149 | class FlowStats(base_tests.SimpleProtocol): |
| 150 | """ |
| 151 | Flow stats multipart transaction |
| 152 | Only verifies we get a reply. |
| 153 | """ |
| 154 | def runTest(self): |
| 155 | logging.info("Sending flow stats request") |
| 156 | stats = get_flow_stats(self, ofp.match()) |
| 157 | logging.info("Received %d flow stats entries", len(stats)) |
| 158 | for entry in stats: |
| 159 | logging.info(entry.show()) |
| 160 | |
| 161 | |
| 162 | class ACLStats(base_tests.SimpleProtocol): |
| 163 | """ |
| 164 | Flow stats multipart transaction |
| 165 | Only verifies we get a reply. |
| 166 | """ |
| 167 | def runTest(self): |
| 168 | logging.info("Installing ACL rule") |
| 169 | #delete_all_flows(self.controller) |
| 170 | #delete_all_groups(self.controller) |
| 171 | |
| 172 | in_port = config["port_map"].keys()[0] |
| 173 | out_port=config["port_map"].keys()[1] |
| 174 | out_vlan=10 |
| 175 | #add_vlan_table_flow_pvid(self.controller, in_port, None, out_vlan, False) |
| 176 | #add_vlan_table_flow_pvid(self.controller, in_port, 1,out_vlan, False) |
| 177 | group_id, msg=add_one_l2_interface_grouop(self.controller, out_port, out_vlan, True, False) |
| 178 | inst=[ofp.instruction.write_actions( |
| 179 | actions=[ |
| 180 | ofp.action.group(msg.group_id)]) |
| 181 | ], |
| 182 | |
| 183 | #add acl |
| 184 | match = ofp.match() |
| 185 | match.oxm_list.append(ofp.oxm.in_port(in_port)) |
| 186 | request = ofp.message.flow_add( |
| 187 | table_id=60, |
| 188 | cookie=42, |
| 189 | match=match, |
| 190 | instructions=inst, |
| 191 | buffer_id=ofp.OFP_NO_BUFFER, |
| 192 | priority=1000) |
| 193 | #self.controller.message_send(request) |
| 194 | |
| 195 | logging.info("Sending flow stats request") |
| 196 | stats = get_flow_stats(self, match) |
| 197 | logging.info("Received %d flow stats entries", len(stats)) |
| 198 | verify_flow_stats=[ofp.flow_stats_entry( |
| 199 | table_id=60 |
| 200 | #cookie=42, |
| 201 | #match=match, |
| 202 | #instructions=inst, |
| 203 | #priority=1000 |
| 204 | )] |
| 205 | self.assertEquals(stats, verify_flow_stats) |
| 206 | |