blob: c43b7aa9068142751a2c3ff560fb4ffdb89e24bb [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
9class 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]
15 #Add L3Unicast to Host
16 port, vlan_id = 33, 10
17 ##add L2 Interface Group
castroflaviodd171472015-12-08 13:55:58 -050018 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050019 ##add L3 Unicast Group
20 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=switch_mac,
21 dst_mac=dst_mac)
22 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=vlan_id, vrf=vlan_id,
23 flag=VLAN_TABLE_FLAG_ONLY_TAG)
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
29 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, l3_msg.group_id, vrf=10)
30 #add entries in the Bridging table to avoid packet-in from mac learning
31 group_id = encode_l2_interface_group_id(vlan_id, port)
32 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
33
34 port = 32
castroflaviodd171472015-12-08 13:55:58 -050035 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050036 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
37 add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id)
38 do_barrier(self.controller)
39
40 #Add L3VPN initiation
41 dst_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55]
42 vlan_id = 100
43 ##add L2 Interface Group
castroflaviodd171472015-12-08 13:55:58 -050044 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050045 #add MPLS interface group
46 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, switch_mac, vlan_id, port)
47 ##add L3VPN interface
48 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
49 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=20, set_bos=1, set_ttl=32)
50 ##add unicast routing flow
51 dst_ip=0x14000001
52 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, mpls_label_gid, vrf=10)
53
54 #add entries in the Bridging table to avoid packet-in from mac learning
55 group_id = encode_l2_interface_group_id(vlan_id, port)
56 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
57
58 do_barrier(self.controller)
59
60class Leaf2(base_tests.SimpleDataPlane):
61
62 def runTest(self):
63 #Add flows correspondent to Leaf2
64 switch_mac=[0x00, 0x00, 0x00, 0x01, 0xea, 0xf2]
65 dst_mac= [0x00, 0x00, 0x00, 0x12, 0x34, 0x02]
66 #Add L3Unicast to Host
67 port, vlan_id=33, 20
68 ##add L2 Interface Group
castroflaviodd171472015-12-08 13:55:58 -050069 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050070 ##add L3 Unicast Group
71 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=switch_mac,
72 dst_mac=dst_mac)
73 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=20, flag=VLAN_TABLE_FLAG_ONLY_TAG)
74 ##add Termination Flow
75 add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id)
76 ##add unicast routing flow
77 dst_ip=0x14000001
78 mask=0xffffff00
79 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, l3_msg.group_id, vrf=vlan_id)
80 #add entries in the Bridging table to avoid packet-in from mac learning
81 group_id = encode_l2_interface_group_id(vlan_id, port)
82 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
83
84 port = 32
castroflaviodd171472015-12-08 13:55:58 -050085 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050086 add_one_vlan_table_flow(self.controller, port, vlan_id, vrf=vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
87 add_termination_flow(self.controller, port, 0x0800, switch_mac, vlan_id)
88 do_barrier(self.controller)
89
90 #Add L3VPN initiation
91 dst_mac= [0x00, 0x00, 0x00, 0x55, 0x55, 0x55]
92 vlan_id = 100
93 ##add L2 Interface Group
castroflaviodd171472015-12-08 13:55:58 -050094 l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -050095 #add MPLS interface group
96 mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, switch_mac, vlan_id, port)
97 ##add L3VPN interface
98 mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
99 index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=10, set_bos=1, set_ttl=32)
100 ##add unicast routing flow
101 dst_ip=0x0a000001
102 add_unicast_routing_flow(self.controller, 0x0800, dst_ip, mask, mpls_label_gid, vrf=20)
103 #add entries in the Bridging table to avoid packet-in from mac learning
104 group_id = encode_l2_interface_group_id(vlan_id, port)
105 add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
106
107class Spine(base_tests.SimpleDataPlane):
108
109 def runTest(self):
110 #add Spine Flows
111 switch_mac = [0x00, 0x00, 0x00, 0x55, 0x55, 0x55]
112 dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf1]
113 #Add MPLS termination
114 port, vlan_id=31, 10
115 ##add L2 Interface Group
castroflaviodd171472015-12-08 13:55:58 -0500116 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -0500117 ##add L3 Unicast Group
118 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=switch_mac,
119 dst_mac=dst_mac)
120 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
121 vlan_id=100
122 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=100, flag=VLAN_TABLE_FLAG_ONLY_TAG)
123 add_termination_flow(self.controller, port, 0x8847, switch_mac, vlan_id, goto_table=24)
124 add_mpls_flow(self.controller, ecmp_msg.group_id, 10)
125 #add entries in the Bridging table to avoid packet-in from mac learning
126 group_id = encode_l2_interface_group_id(100, port)
127 add_bridge_flow(self.controller, dst_mac, 100, group_id, True)
128
129 dst_mac = [0x00, 0x00, 0x00, 0x01, 0xea, 0xf2]
130 #Add MPLS termination
131 port, vlan_id=32, 20
132 ##add L2 Interface Group
castroflaviodd171472015-12-08 13:55:58 -0500133 add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
Flavio Castro34352e72015-12-07 20:01:51 -0500134 ##add L3 Unicast Group
135 l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=switch_mac,
136 dst_mac=dst_mac)
137 ecmp_msg = add_l3_ecmp_group(self.controller, port, [l3_msg.group_id])
138 add_one_vlan_table_flow(self.controller, of_port=port, vlan_id=100, flag=VLAN_TABLE_FLAG_ONLY_TAG)
139 vlan_id=100
140 add_termination_flow(self.controller, port, 0x8847, switch_mac, vlan_id, goto_table=24)
141 add_mpls_flow(self.controller, ecmp_msg.group_id, 20)
142 #add entries in the Bridging table to avoid packet-in from mac learning
143 group_id = encode_l2_interface_group_id(100, port)
144 add_bridge_flow(self.controller, dst_mac, 100, group_id, True)
145
146class TestLeaf1(base_tests.SimpleDataPlane):
147
148 def runTest(self):
149 host_mac='00:00:00:12:34:01'
150 ip_src='10.0.0.1'
151 ip_dst='20.0.0.2'
152 switch_mac='00:00:00:01:ea:f1'
153 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=10, ip_src=ip_src,
154 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=host_mac, ip_ttl=33)
155 pkt=str(parsed_pkt)
156 self.dataplane.send(33, pkt)
157
158 #build expect packet
159 next_hop_mac='00:00:00:55:55:55'
160 switch_mac='00:00:00:01:ea:f1'
161 label = (20, 0, 1, 32)
162 exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=100, label=[label],
163 eth_dst=next_hop_mac, eth_src=switch_mac, ip_ttl=32, ip_src=ip_src, ip_dst=ip_dst)
164 pkt=str(exp_pkt)
165 verify_packet(self, pkt, 37)
166
167class TestSpine(base_tests.SimpleDataPlane):
168
169 def runTest(self):
170 ip_src='10.0.0.1'
171 ip_dst='20.0.0.2'
172
173 #build outgoing packet
174 spine_mac='00:00:00:55:55:55'
175 switch_mac='00:00:00:01:ea:f2'
176 leaf1= '00:00:00:01:ea:f1'
177 label = (20, 0, 1, 32)
178 parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True, vlan_vid=100, label=[label],
179 eth_dst=spine_mac, eth_src=leaf1, ip_ttl=32, ip_src=ip_src, ip_dst=ip_dst)
180 pkt=str(parsed_pkt)
181 self.dataplane.send(33, pkt)
182
183 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=20, ip_src=ip_src,
184 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=spine_mac, ip_ttl=31)
185 pkt=str(exp_pkt)
186 verify_packet(self, pkt, 37)
187
188class TestLeaf2(base_tests.SimpleDataPlane):
189
190 def runTest(self):
191 host_mac='00:00:00:55:55:55'
192 ip_src='10.0.0.1'
193 ip_dst='20.0.0.3'
194 switch_mac='00:00:00:01:ea:f1'
195 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=10, ip_src=ip_src,
196 ip_dst=ip_dst, eth_dst=switch_mac, eth_src=host_mac, ip_ttl=33)
197 pkt=str(parsed_pkt)
198 self.dataplane.send(33, pkt)
199 switch_mac='00:00:00:01:ea:f2'
200 host_mac='00:00:00:12:34:02'
201 exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=20, ip_src=ip_src,
202 ip_dst=ip_dst, eth_dst=host_mac, eth_src=switch_mac, ip_ttl=30)
203 pkt=str(exp_pkt)
204 verify_packet(self, pkt, 37)
205
206
207