blob: e3f0108bec2770863c0474c9adac02223fa1baf1 [file] [log] [blame]
Flavio Castro34352e72015-12-07 20:01:51 -05001
2from oftest import config
3import logging
4import oftest.base_tests as base_tests
5import ofp
6from oftest.testutils import *
7from accton_util import *
8
Flavio Castrocca0d982016-01-26 17:55:55 -05009class 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 Castro34352e72015-12-07 20:01:51 -050070class 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 Castro7fb6ca92015-12-16 15:50:14 -050076 id=0x1eaf
Flavio Castro34352e72015-12-07 20:01:51 -050077 #Add L3Unicast to Host
Flavio Castro7fb6ca92015-12-16 15:50:14 -050078 port, vlan_id = 33, 4093
Flavio Castro34352e72015-12-07 20:01:51 -050079 ##add L2 Interface Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -050080 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050081 ##add L3 Unicast Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -050082 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac,
Flavio Castro34352e72015-12-07 20:01:51 -050083 dst_mac=dst_mac)
Flavio Castro7fb6ca92015-12-16 15:50:14 -050084 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro34352e72015-12-07 20:01:51 -050085 ##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 Castro7fb6ca92015-12-16 15:50:14 -050090 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, l3_msg.group_id)
Flavio Castro34352e72015-12-07 20:01:51 -050091
92 port = 32
Flavio Castro7fb6ca92015-12-16 15:50:14 -050093 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 Castro34352e72015-12-07 20:01:51 -050095 add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id)
Flavio Castro34352e72015-12-07 20:01:51 -050096
97 #Add L3VPN initiation
98 dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55]
Flavio Castro34352e72015-12-07 20:01:51 -050099 #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 Castro7fb6ca92015-12-16 15:50:14 -0500103 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 Castro34352e72015-12-07 20:01:51 -0500105 ##add unicast routing flow
106 dst_ip=0x14000001
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500107 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, ecmp_msg.group_id)
Flavio Castro34352e72015-12-07 20:01:51 -0500108
Flavio Castro34352e72015-12-07 20:01:51 -0500109 do_barrier(self.controller)
110
111class Leaf2(base_tests.SimpleDataPlane):
112
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500113 def runTest(self):
114 #Add flows correspondent to Leaf1
Flavio Castro34352e72015-12-07 20:01:51 -0500115 switch_mac=[0x00, 0x00, 0x00, 0x01, 0xea, 0xf2]
116 dst_mac= [0x00, 0x00, 0x00, 0x12, 0x34, 0x02]
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500117 id=0x2eaf
Flavio Castro34352e72015-12-07 20:01:51 -0500118 #Add L3Unicast to Host
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500119 port, vlan_id = 33, 4093
Flavio Castro34352e72015-12-07 20:01:51 -0500120 ##add L2 Interface Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500121 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -0500122 ##add L3 Unicast Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500123 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac,
Flavio Castro34352e72015-12-07 20:01:51 -0500124 dst_mac=dst_mac)
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500125 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro34352e72015-12-07 20:01:51 -0500126 ##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 Castro7fb6ca92015-12-16 15:50:14 -0500131 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, l3_msg.group_id)
Flavio Castro34352e72015-12-07 20:01:51 -0500132
133 port = 32
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500134 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 Castro34352e72015-12-07 20:01:51 -0500136 add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id)
Flavio Castro34352e72015-12-07 20:01:51 -0500137
138 #Add L3VPN initiation
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500139 dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55]
Flavio Castro34352e72015-12-07 20:01:51 -0500140 #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 Castro7fb6ca92015-12-16 15:50:14 -0500143 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 Castro34352e72015-12-07 20:01:51 -0500146 ##add unicast routing flow
147 dst_ip=0x0a000001
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500148 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, ecmp_msg.group_id)
149
150 do_barrier(self.controller)
Flavio Castro34352e72015-12-07 20:01:51 -0500151
152class 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 Castro7fb6ca92015-12-16 15:50:14 -0500158 id = 0x55
Flavio Castro34352e72015-12-07 20:01:51 -0500159 #Add MPLS termination
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500160 port, vlan_id=31, 4093
Flavio Castro34352e72015-12-07 20:01:51 -0500161 ##add L2 Interface Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500162 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -0500163 ##add L3 Unicast Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500164 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac,
Flavio Castro34352e72015-12-07 20:01:51 -0500165 dst_mac=dst_mac)
166 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500167 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro34352e72015-12-07 20:01:51 -0500168 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 Castro34352e72015-12-07 20:01:51 -0500170
171 dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf2]
172 #Add MPLS termination
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500173 port=32
Flavio Castro34352e72015-12-07 20:01:51 -0500174 ##add L2 Interface Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500175 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -0500176 ##add L3 Unicast Group
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500177 id=id+1
178 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=id, src_mac=switch_mac,
Flavio Castro34352e72015-12-07 20:01:51 -0500179 dst_mac=dst_mac)
180 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
Flavio Castro7fb6ca92015-12-16 15:50:14 -0500181 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
Flavio Castro34352e72015-12-07 20:01:51 -0500182 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 Castro34352e72015-12-07 20:01:51 -0500184
185class 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 Castro7fb6ca92015-12-16 15:50:14 -0500192 parsed_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src,
Flavio Castro34352e72015-12-07 20:01:51 -0500193 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
206class 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
227class 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 Castro7fb6ca92015-12-16 15:50:14 -0500234 parsed_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src,
Flavio Castro34352e72015-12-07 20:01:51 -0500235 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 Castro7fb6ca92015-12-16 15:50:14 -0500240 exp_pkt = simple_tcp_packet(pktlen=100, ip_src=ip_src,
Flavio Castro34352e72015-12-07 20:01:51 -0500241 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