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 | |
| 9 | class Leaf1(base_tests.SimpleDataPlane): |
| 10 | |
| 11 | def runTest(self): |
| 12 | #Add flows correspondent to Leaf1 |
| 13 | switch_mac=[0x00, 0x00, 0x00, 0x01, 0xea, 0xf1] |
| 14 | dst_mac= [0x00, 0x00, 0x00, 0x12, 0x34, 0x01] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 15 | id=0x1eaf |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 16 | #Add L3Unicast to Host |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 17 | port, vlan_id = 33, 4093 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 18 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 19 | 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] | 20 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 21 | 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] | 22 | dst_mac=dst_mac) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 23 | 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] | 24 | ##add Termination Flow |
| 25 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
| 26 | ##add unicast routing flow |
| 27 | dst_ip=0x0a000001 |
| 28 | mask=0xffffff00 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 29 | 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] | 30 | |
| 31 | port = 32 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 32 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 33 | 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] | 34 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 35 | |
| 36 | #Add L3VPN initiation |
| 37 | dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55] |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 38 | #add MPLS interface group |
| 39 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, switch_mac, vlan_id, port) |
| 40 | ##add L3VPN interface |
| 41 | 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] | 42 | index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=20, set_bos=1, cpy_ttl_outward=True) |
| 43 | ecmp_msg=add_l3_ecmp_group(self.controller, port, [mpls_label_gid]) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 44 | ##add unicast routing flow |
| 45 | dst_ip=0x14000001 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 46 | 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] | 47 | |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 48 | do_barrier(self.controller) |
| 49 | |
| 50 | class Leaf2(base_tests.SimpleDataPlane): |
| 51 | |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 52 | def runTest(self): |
| 53 | #Add flows correspondent to Leaf1 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 54 | switch_mac=[0x00, 0x00, 0x00, 0x01, 0xea, 0xf2] |
| 55 | dst_mac= [0x00, 0x00, 0x00, 0x12, 0x34, 0x02] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 56 | id=0x2eaf |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 57 | #Add L3Unicast to Host |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 58 | port, vlan_id = 33, 4093 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 59 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 60 | 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] | 61 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 62 | 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] | 63 | dst_mac=dst_mac) |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 64 | 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] | 65 | ##add Termination Flow |
| 66 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
| 67 | ##add unicast routing flow |
| 68 | dst_ip=0x14000001 |
| 69 | mask=0xffffff00 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 70 | 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] | 71 | |
| 72 | port = 32 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 73 | l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False) |
| 74 | 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] | 75 | add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 76 | |
| 77 | #Add L3VPN initiation |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 78 | dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55] |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 79 | #add MPLS interface group |
| 80 | mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, switch_mac, vlan_id, port) |
| 81 | ##add L3VPN interface |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 82 | mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, |
| 83 | index=id, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=20, set_bos=1, cpy_ttl_outward=True) |
| 84 | ecmp_msg=add_l3_ecmp_group(self.controller, id, [mpls_label_gid]) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 85 | ##add unicast routing flow |
| 86 | dst_ip=0x0a000001 |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 87 | add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, ecmp_msg.group_id) |
| 88 | |
| 89 | do_barrier(self.controller) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 90 | |
| 91 | class Spine(base_tests.SimpleDataPlane): |
| 92 | |
| 93 | def runTest(self): |
| 94 | #add Spine Flows |
| 95 | switch_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55] |
| 96 | dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf1] |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 97 | id = 0x55 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 98 | #Add MPLS termination |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 99 | port, vlan_id=31, 4093 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 100 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 101 | 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] | 102 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 103 | 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] | 104 | dst_mac=dst_mac) |
| 105 | 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] | 106 | 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] | 107 | add_termination_flow(self.controller, port, 0x8847, switch_mac, vlan_id, goto_table=24) |
| 108 | add_mpls_flow(self.controller, ecmp_msg.group_id, 10) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 109 | |
| 110 | dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf2] |
| 111 | #Add MPLS termination |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 112 | port=32 |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 113 | ##add L2 Interface Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 114 | 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] | 115 | ##add L3 Unicast Group |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 116 | id=id+1 |
| 117 | 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] | 118 | dst_mac=dst_mac) |
| 119 | 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] | 120 | 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] | 121 | add_termination_flow(self.controller, port, 0x8847, switch_mac, vlan_id, goto_table=24) |
| 122 | add_mpls_flow(self.controller, ecmp_msg.group_id, 20) |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 123 | |
| 124 | class TestLeaf1(base_tests.SimpleDataPlane): |
| 125 | |
| 126 | def runTest(self): |
| 127 | host_mac='00:00:00:12:34:01' |
| 128 | ip_src='10.0.0.1' |
| 129 | ip_dst='20.0.0.2' |
| 130 | switch_mac='00:00:00:01:ea:f1' |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 131 | parsed_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 132 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=host_mac, ip_ttl=33) |
| 133 | pkt=str(parsed_pkt) |
| 134 | self.dataplane.send(33, pkt) |
| 135 | |
| 136 | #build expect packet |
| 137 | next_hop_mac='00:00:00:55:55:55' |
| 138 | switch_mac='00:00:00:01:ea:f1' |
| 139 | label = (20, 0, 1, 32) |
| 140 | exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=100, label=[label], |
| 141 | eth_dst=next_hop_mac, eth_src=switch_mac, ip_ttl=32, ip_src=ip_src, ip_dst=ip_dst) |
| 142 | pkt=str(exp_pkt) |
| 143 | verify_packet(self, pkt, 37) |
| 144 | |
| 145 | class TestSpine(base_tests.SimpleDataPlane): |
| 146 | |
| 147 | def runTest(self): |
| 148 | ip_src='10.0.0.1' |
| 149 | ip_dst='20.0.0.2' |
| 150 | |
| 151 | #build outgoing packet |
| 152 | spine_mac='00:00:00:55:55:55' |
| 153 | switch_mac='00:00:00:01:ea:f2' |
| 154 | leaf1= '00:00:00:01:ea:f1' |
| 155 | label = (20, 0, 1, 32) |
| 156 | parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=100, label=[label], |
| 157 | eth_dst=spine_mac, eth_src=leaf1, ip_ttl=32, ip_src=ip_src, ip_dst=ip_dst) |
| 158 | pkt=str(parsed_pkt) |
| 159 | self.dataplane.send(33, pkt) |
| 160 | |
| 161 | exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=20, ip_src=ip_src, |
| 162 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=spine_mac, ip_ttl=31) |
| 163 | pkt=str(exp_pkt) |
| 164 | verify_packet(self, pkt, 37) |
| 165 | |
| 166 | class TestLeaf2(base_tests.SimpleDataPlane): |
| 167 | |
| 168 | def runTest(self): |
| 169 | host_mac='00:00:00:55:55:55' |
| 170 | ip_src='10.0.0.1' |
| 171 | ip_dst='20.0.0.3' |
| 172 | switch_mac='00:00:00:01:ea:f1' |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 173 | parsed_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 174 | ip_dst=ip_dst, eth_dst=switch_mac, eth_src=host_mac, ip_ttl=33) |
| 175 | pkt=str(parsed_pkt) |
| 176 | self.dataplane.send(33, pkt) |
| 177 | switch_mac='00:00:00:01:ea:f2' |
| 178 | host_mac='00:00:00:12:34:02' |
Flavio Castro | 7fb6ca9 | 2015-12-16 15:50:14 -0500 | [diff] [blame] | 179 | exp_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src, |
Flavio Castro | 34352e7 | 2015-12-07 20:01:51 -0500 | [diff] [blame] | 180 | ip_dst=ip_dst, eth_dst=host_mac, eth_src=switch_mac, ip_ttl=30) |
| 181 | pkt=str(exp_pkt) |
| 182 | verify_packet(self, pkt, 37) |
| 183 | |
| 184 | |
| 185 | |