blob: 6ff4bc45c7efe9473323e2301134a0c5940939ab [file] [log] [blame]
alshabibd6be76e2016-03-01 22:21:00 -08001import oftest.base_tests as base_tests
alshabibcde318b2016-03-01 22:49:13 -08002from oftest import config
alshabibd6be76e2016-03-01 22:21:00 -08003import ofp
Admin4ebddb82016-03-01 22:36:30 -08004from oftest.testutils import *
alshabibcde318b2016-03-01 22:49:13 -08005from oltconstants import *
6import copy
Admin44f754e2016-03-01 23:00:46 -08007import logging
alshabibd6be76e2016-03-01 22:21:00 -08008
alshabibcde318b2016-03-01 22:49:13 -08009
alshabibd6be76e2016-03-01 22:21:00 -080010class OltBaseTest(base_tests.SimpleDataPlane):
11
Zsolt Harasztif5c6aba2016-03-02 11:41:22 -080012 next_cookie_block = 40
13
14 def getCookieBlock(self):
15 """Returns the starting value of the next 100 cookies"""
16 c = self.next_cookie_block
17 OltBaseTest.next_cookie_block += 100
18 return c
19
20 def resetOlt(self):
21 """Reset the OLT into a clean healthy state"""
22 delete_all_flows(self.controller)
23 do_barrier(self.controller)
24 verify_no_errors(self.controller)
25
alshabibcde318b2016-03-01 22:49:13 -080026 def testPacketIn(self, match, parsed_pkt):
27 delete_all_flows(self.controller)
28
29 pkt = str(parsed_pkt)
30
31 for of_port in config["port_map"]:
32 m = copy.deepcopy(match)
33 m.oxm_list.append(ofp.oxm.in_port(of_port))
34 request = ofp.message.flow_add(
35 table_id=test_param_get("table", 0),
36 cookie=42,
37 match=m,
38 instructions=[
39 ofp.instruction.apply_actions(
40 actions=[
41 ofp.action.output(
42 port=ofp.OFPP_CONTROLLER,
43 max_len=ofp.OFPCML_NO_BUFFER)])],
44 buffer_id=ofp.OFP_NO_BUFFER,
45 priority=1000)
46 logging.info("Inserting flow sending matching packets to controller")
47 self.controller.message_send(request)
48 do_barrier(self.controller)
49
alshabib5339b7d2016-03-01 23:14:57 -080050 for of_port in config["port_map"]:
51 logging.info("PacketInExact test, port %d", of_port)
52 self.dataplane.send(of_port, pkt)
53 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
54 verify_packets(self, pkt, [])
alshabibcde318b2016-03-01 22:49:13 -080055
56 def processEapolRule(self, in_port, install = True):
57 match = ofp.match()
58 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
59 match.oxm_list.append(ofp.oxm.in_port(in_port))
60 if install:
61 request = ofp.message.flow_add(
62 table_id=test_param_get("table", 0),
63 cookie=42,
64 match=match,
65 instructions=[
66 ofp.instruction.apply_actions(
67 actions=[
68 ofp.action.output(
69 port=ofp.OFPP_CONTROLLER,
70 max_len=ofp.OFPCML_NO_BUFFER)])],
71 buffer_id=ofp.OFP_NO_BUFFER,
72 priority=1000)
73 else:
74 request = ofp.message.flow_delete(
75 table_id=test_param_get("table", 0),
76 cookie=42,
77 match=match,
78 instructions=[
79 ofp.instruction.apply_actions(
80 actions=[
81 ofp.action.output(
82 port=ofp.OFPP_CONTROLLER,
83 max_len=ofp.OFPCML_NO_BUFFER)])],
84 buffer_id=ofp.OFP_NO_BUFFER,
85 priority=1000)
86 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
87 self.controller.message_send(request)
88 do_barrier(self.controller)
89
Zsolt Harasztif5c6aba2016-03-02 11:41:22 -080090 def testPacketFlow(self,
91 s_vlan_id,
92 c_vlan_id,
93 onu=None,
94 verify_blocked_flows=True,
95 pktlen=96):
alshabibcde318b2016-03-01 22:49:13 -080096
Zsolt Harasztif5c6aba2016-03-02 11:41:22 -080097 incorrectTagPkt = simple_udp_packet(
98 pktlen=pktlen+4, dl_vlan_enable=True, vlan_vid=s_vlan_id, vlan_pcp=1)
99 zeroTaggedPkt = simple_udp_packet(
100 pktlen=pktlen+4, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
101 untaggedPkt = simple_udp_packet(pktlen=pktlen)
102 upstreamDoubleTaggedPkt = double_vlan_udp_packet(
103 pktlen=pktlen+8, dl_vlan_enable=True, c_vlan_vid=c_vlan_id, s_vlan_vid=s_vlan_id,
104 c_vlan_pcp=0, s_vlan_pcp=0)
alshabibcde318b2016-03-01 22:49:13 -0800105
alshabib5339b7d2016-03-01 23:14:57 -0800106 inport = onu_port if onu is None else onu
107
alshabibcde318b2016-03-01 22:49:13 -0800108 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
109
110 # test upstream untagged packet got double tag at OLT
alshabib5339b7d2016-03-01 23:14:57 -0800111 self.dataplane.send(inport, str(zeroTaggedPkt))
Admin44f754e2016-03-01 23:00:46 -0800112 verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
alshabibcde318b2016-03-01 22:49:13 -0800113
114 # test downstream doubletagged packet got untagged at ONU
115 self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
116 if device_type == "pmc":
alshabib5339b7d2016-03-01 23:14:57 -0800117 verify_packet(self, zeroTaggedPkt, inport)
alshabibcde318b2016-03-01 22:49:13 -0800118 else:
alshabib5339b7d2016-03-01 23:14:57 -0800119 verify_packet(self, untaggedPkt, inport)
alshabibcde318b2016-03-01 22:49:13 -0800120
Zsolt Harasztif5c6aba2016-03-02 11:41:22 -0800121 if verify_blocked_flows:
122 # test upstream doubletagged packet got dropped
123 self.dataplane.send(inport, str(upstreamDoubleTaggedPkt))
124 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
alshabibcde318b2016-03-01 22:49:13 -0800125
Zsolt Harasztif5c6aba2016-03-02 11:41:22 -0800126 # test downstream untagged packet got dropped at ONU
127 self.dataplane.send(olt_port, str(untaggedPkt))
128 verify_no_packet(self, untaggedPkt, inport)
alshabibcde318b2016-03-01 22:49:13 -0800129
Zsolt Harasztif5c6aba2016-03-02 11:41:22 -0800130 # test upstream icorrectly tagged packet; should get dropped
131 self.dataplane.send(inport, str(incorrectTagPkt))
132 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
133
134 def testSustainedPacketFlow(self, s_vlan_id, c_vlan_id, number_of_roundtrips=10, onu=None):
135 for i in xrange(number_of_roundtrips):
136 print "loop %d" % i
137 self.testPacketFlow(s_vlan_id, c_vlan_id, onu=onu, verify_blocked_flows=False)
alshabibcde318b2016-03-01 22:49:13 -0800138
alshabib5339b7d2016-03-01 23:14:57 -0800139 def installDoubleTaggingRules(self, s_vlan_id, c_vlan_id, cookie=42, onu = None):
140
141 inport = onu_port if onu is None else onu
alshabibd6be76e2016-03-01 22:21:00 -0800142
143 # upstream flow rule
144 match = ofp.match()
alshabib5339b7d2016-03-01 23:14:57 -0800145 match.oxm_list.append(ofp.oxm.in_port(inport))
alshabibd6be76e2016-03-01 22:21:00 -0800146 if device_type == "cpqd":
147 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
148 actions = [
149 ofp.action.push_vlan(ethertype=0x8100),
150 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)),
151 ofp.action.set_field(ofp.oxm.vlan_pcp(0))
152 ]
153 else: # "pmc", "normal"
154 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
155 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
156 actions = [
157 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
158 ]
159 cookie += 1
160
161 # push inner vlan (c-vlan) for upstream
162 request = ofp.message.flow_add(
163 table_id=test_param_get("table", 0),
164 cookie=cookie,
165 match=match,
166 instructions=[
167 ofp.instruction.apply_actions(actions=actions),
168 ofp.instruction.goto_table(1)],
169 buffer_id=ofp.OFP_NO_BUFFER,
170 priority=1000)
171
172 self.controller.message_send(request)
173 do_barrier(self.controller)
174 verify_no_errors(self.controller)
175
176 # push outer vlan (s-vlan) for upstream
177 match = ofp.match()
alshabib5339b7d2016-03-01 23:14:57 -0800178 match.oxm_list.append(ofp.oxm.in_port(inport))
alshabibd6be76e2016-03-01 22:21:00 -0800179 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
180 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
181 cookie += 1
182
183 request = ofp.message.flow_add(
184 table_id=test_param_get("table", 1),
185 cookie=cookie,
186 match=match,
187 instructions=[
188 ofp.instruction.apply_actions(
189 actions=[
190 ofp.action.push_vlan(ethertype=0x8100),
191 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
192 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
193 ofp.action.output(port=olt_port)]),
194 ],
195 buffer_id=ofp.OFP_NO_BUFFER,
196 priority=1000)
197
198 self.controller.message_send(request)
199 do_barrier(self.controller)
200 verify_no_errors(self.controller)
201 cookie += 1
202
203 # strip outer vlan (s-vlan) for downstream
204 match = ofp.match()
205 match.oxm_list.append(ofp.oxm.in_port(olt_port))
206 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
207 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
208 request = ofp.message.flow_add(
209 table_id=test_param_get("table", 0),
210 cookie=cookie,
211 match=match,
212 instructions=[
213 ofp.instruction.apply_actions(
214 actions=[ofp.action.pop_vlan()]),
215 ofp.instruction.goto_table(1)],
216 buffer_id=ofp.OFP_NO_BUFFER,
217 priority=1000)
218
219 self.controller.message_send(request)
220 do_barrier(self.controller)
221 verify_no_errors(self.controller)
222
223 # rewrite inner vlan (c-vlan) to default (0) for downstream
224 match = ofp.match()
225 match.oxm_list.append(ofp.oxm.in_port(olt_port))
226 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
227 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
228 cookie += 1
229
230 request = ofp.message.flow_add(
231 table_id=test_param_get("table", 1),
232 cookie=cookie,
233 match=match,
234 instructions=[
235 ofp.instruction.apply_actions(
236 actions=[
237 ofp.action.pop_vlan(),
alshabib5339b7d2016-03-01 23:14:57 -0800238 ofp.action.output(port=inport)])
alshabibd6be76e2016-03-01 22:21:00 -0800239 ],
240 buffer_id=ofp.OFP_NO_BUFFER,
241 priority=1000)
242
243 self.controller.message_send(request)
244 do_barrier(self.controller)
245 verify_no_errors(self.controller)