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