Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 1 | |
| 2 | from oftest import config |
| 3 | import logging |
| 4 | import oftest.base_tests as base_tests |
| 5 | import ofp |
| 6 | from oftest.testutils import * |
| 7 | from accton_util import * |
| 8 | |
Flavio Castro | cca0d98 | 2016-01-26 17:55:55 -0500 | [diff] [blame] | 9 | class McastLeaf1(base_tests.SimpleDataPlane): |
| 10 | def runTest(self): |
| 11 | """ |
| 12 | port1 (vlan 300)-> All Ports (vlan 300) |
| 13 | """ |
| 14 | if len(config["port_map"]) <2: |
| 15 | logging.info("Port count less than 2, can't run this case") |
| 16 | return |
| 17 | |
| 18 | vlan_id =300 |
| 19 | intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc] |
| 20 | intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac]) |
| 21 | dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01] |
| 22 | dst_mac_str=':'.join(['%02X' % x for x in dst_mac]) |
| 23 | port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11] |
| 24 | port1_mac_str=':'.join(['%02X' % x for x in port1_mac]) |
| 25 | src_ip=0xc0a80101 |
| 26 | src_ip_str="192.168.1.1" |
| 27 | dst_ip=0xe0010101 |
| 28 | dst_ip_str="224.1.1.1" |
| 29 | |
| 30 | port1=32 |
| 31 | port2=33 |
| 32 | |
| 33 | switch_mac = [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00] |
| 34 | |
| 35 | portlist=[32, 33, 34, 36] |
| 36 | |
| 37 | #add l2 interface group |
| 38 | l2_intf_group_list=[] |
| 39 | for port in portlist: |
| 40 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=4) |
| 41 | #if port == port2: |
| 42 | # continue |
| 43 | l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 44 | l2_intf_group_list.append(l2_intf_gid) |
| 45 | |
| 46 | #add termination flow |
| 47 | add_termination_flow(self.controller, port1, 0x0800, switch_mac, vlan_id) |
| 48 | |
| 49 | #add l3 interface group |
| 50 | mcat_group_msg=add_l3_mcast_group(self.controller, vlan_id, 2, l2_intf_group_list) |
| 51 | add_mcast4_routing_flow(self.controller, vlan_id, src_ip, 0, dst_ip, mcat_group_msg.group_id) |
| 52 | parsed_pkt = simple_udp_packet(pktlen=100, |
| 53 | dl_vlan_enable=True, |
| 54 | vlan_vid=vlan_id, |
| 55 | eth_dst=dst_mac_str, |
| 56 | eth_src=port1_mac_str, |
| 57 | ip_ttl=64, |
| 58 | ip_src=src_ip_str, |
| 59 | ip_dst=dst_ip_str) |
| 60 | pkt=str(parsed_pkt) |
| 61 | self.dataplane.send(port1, pkt) |
| 62 | for port in config["port_map"].keys(): |
| 63 | if port == port1: |
| 64 | verify_no_packet(self, pkt, port) |
| 65 | continue |
| 66 | verify_packet(self, pkt, port) |
| 67 | verify_no_other_packets(self) |
| 68 | |
| 69 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 70 | class Leaf1(base_tests.SimpleDataPlane): |
| 71 | |
| 72 | def runTest(self): |
| 73 | #Add flows correspondent to Leaf1 |
| 74 | switch_mac=[0x00, 0x00, 0x00, 0x01, 0xea, 0xf1] |
| 75 | dst_mac= [0x00, 0x00, 0x00, 0x12, 0x34, 0x01] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 76 | id=0x1eaf |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 77 | #Add L3Unicast to Host |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 78 | port, vlan_id = 33, 4093 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 79 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 80 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 81 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 82 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 83 | dst_mac=dst_mac) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 84 | add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 85 | ##add Termination Flow |
| 86 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
| 87 | ##add unicast routing flow |
| 88 | dst_ip=0x0a000001 |
| 89 | mask=0xffffff00 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 90 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, l3_msg.group_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 91 | |
| 92 | port = 32 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 93 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 94 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 95 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 96 | |
| 97 | #Add L3VPN initiation |
| 98 | dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55] |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 99 | #add MPLS interface group |
| 100 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, switch_mac, vlan_id, port) |
| 101 | ##add L3VPN interface |
| 102 | mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 103 | index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=20, set_bos=1, cpy_ttl_outward=True) |
| 104 | ecmp_msg=add_l3_ecmp_group(self.controller, port, [mpls_label_gid]) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 105 | ##add unicast routing flow |
| 106 | dst_ip=0x14000001 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 107 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, ecmp_msg.group_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 108 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 109 | do_barrier(self.controller) |
| 110 | |
| 111 | class Leaf2(base_tests.SimpleDataPlane): |
| 112 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 113 | def runTest(self): |
| 114 | #Add flows correspondent to Leaf1 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 115 | switch_mac=[0x00, 0x00, 0x00, 0x01, 0xea, 0xf2] |
| 116 | dst_mac= [0x00, 0x00, 0x00, 0x12, 0x34, 0x02] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 117 | id=0x2eaf |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 118 | #Add L3Unicast to Host |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 119 | port, vlan_id = 33, 4093 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 120 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 121 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 122 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 123 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 124 | dst_mac=dst_mac) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 125 | add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 126 | ##add Termination Flow |
| 127 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
| 128 | ##add unicast routing flow |
| 129 | dst_ip=0x14000001 |
| 130 | mask=0xffffff00 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 131 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, l3_msg.group_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 132 | |
| 133 | port = 32 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 134 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 135 | add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 136 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 137 | |
| 138 | #Add L3VPN initiation |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 139 | dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55] |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 140 | #add MPLS interface group |
| 141 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, switch_mac, vlan_id, port) |
| 142 | ##add L3VPN interface |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 143 | mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 144 | index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=20, set_bos=1, cpy_ttl_outward=True) |
| 145 | ecmp_msg=add_l3_ecmp_group(self.controller, id, [mpls_label_gid]) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 146 | ##add unicast routing flow |
| 147 | dst_ip=0x0a000001 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 148 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, ecmp_msg.group_id) |
| 149 | |
| 150 | do_barrier(self.controller) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 151 | |
| 152 | class Spine(base_tests.SimpleDataPlane): |
| 153 | |
| 154 | def runTest(self): |
| 155 | #add Spine Flows |
| 156 | switch_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55] |
| 157 | dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf1] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 158 | id = 0x55 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 159 | #Add MPLS termination |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 160 | port, vlan_id=31, 4093 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 161 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 162 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 163 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 164 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 165 | dst_mac=dst_mac) |
| 166 | ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id]) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 167 | add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 168 | add_termination_flow(self.controller, port, 0x8847, switch_mac, vlan_id, goto_table=24) |
| 169 | add_mpls_flow(self.controller, ecmp_msg.group_id, 10) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 170 | |
| 171 | dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf2] |
| 172 | #Add MPLS termination |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 173 | port=32 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 174 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 175 | add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 176 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 177 | id=id+1 |
| 178 | l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 179 | dst_mac=dst_mac) |
| 180 | ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id]) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 181 | add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 182 | add_termination_flow(self.controller, port, 0x8847, switch_mac, vlan_id, goto_table=24) |
| 183 | add_mpls_flow(self.controller, ecmp_msg.group_id, 20) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 184 | |
| 185 | class TestLeaf1(base_tests.SimpleDataPlane): |
| 186 | |
| 187 | def runTest(self): |
| 188 | host_mac='00:00:00:12:34:01' |
| 189 | ip_src='10.0.0.1' |
| 190 | ip_dst='20.0.0.2' |
| 191 | switch_mac='00:00:00:01:ea:f1' |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 192 | parsed_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 193 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=host_mac, ip_ttl=33) |
| 194 | pkt=str(parsed_pkt) |
| 195 | self.dataplane.send(33, pkt) |
| 196 | |
| 197 | #build expect packet |
| 198 | next_hop_mac='00:00:00:55:55:55' |
| 199 | switch_mac='00:00:00:01:ea:f1' |
| 200 | label = (20, 0, 1, 32) |
| 201 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=100, label=[label], |
| 202 | eth_dst=next_hop_mac, eth_src=switch_mac, ip_ttl=32, ip_src=ip_src, ip_dst=ip_dst) |
| 203 | pkt=str(exp_pkt) |
| 204 | verify_packet(self, pkt, 37) |
| 205 | |
| 206 | class TestSpine(base_tests.SimpleDataPlane): |
| 207 | |
| 208 | def runTest(self): |
| 209 | ip_src='10.0.0.1' |
| 210 | ip_dst='20.0.0.2' |
| 211 | |
| 212 | #build outgoing packet |
| 213 | spine_mac='00:00:00:55:55:55' |
| 214 | switch_mac='00:00:00:01:ea:f2' |
| 215 | leaf1= '00:00:00:01:ea:f1' |
| 216 | label = (20, 0, 1, 32) |
| 217 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=100, label=[label], |
| 218 | eth_dst=spine_mac, eth_src=leaf1, ip_ttl=32, ip_src=ip_src, ip_dst=ip_dst) |
| 219 | pkt=str(parsed_pkt) |
| 220 | self.dataplane.send(33, pkt) |
| 221 | |
| 222 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=20, ip_src=ip_src, |
| 223 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=spine_mac, ip_ttl=31) |
| 224 | pkt=str(exp_pkt) |
| 225 | verify_packet(self, pkt, 37) |
| 226 | |
| 227 | class TestLeaf2(base_tests.SimpleDataPlane): |
| 228 | |
| 229 | def runTest(self): |
| 230 | host_mac='00:00:00:55:55:55' |
| 231 | ip_src='10.0.0.1' |
| 232 | ip_dst='20.0.0.3' |
| 233 | switch_mac='00:00:00:01:ea:f1' |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 234 | parsed_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 235 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=host_mac, ip_ttl=33) |
| 236 | pkt=str(parsed_pkt) |
| 237 | self.dataplane.send(33, pkt) |
| 238 | switch_mac='00:00:00:01:ea:f2' |
| 239 | host_mac='00:00:00:12:34:02' |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 240 | exp_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 241 | ip_dst=ip_dst, eth_dst=host_mac, eth_src=switch_mac, ip_ttl=30) |
| 242 | pkt=str(exp_pkt) |
| 243 | verify_packet(self, pkt, 37) |
| 244 | |
| 245 | |
| 246 | |