blob: be7f0af5319d959b1a98200d1964a59e37c374ab [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
alshabibcde318b2016-03-01 22:49:13 -080012 def testPacketIn(self, match, parsed_pkt):
13 delete_all_flows(self.controller)
14
15 pkt = str(parsed_pkt)
16
17 for of_port in config["port_map"]:
18 m = copy.deepcopy(match)
19 m.oxm_list.append(ofp.oxm.in_port(of_port))
20 request = ofp.message.flow_add(
21 table_id=test_param_get("table", 0),
22 cookie=42,
23 match=m,
24 instructions=[
25 ofp.instruction.apply_actions(
26 actions=[
27 ofp.action.output(
28 port=ofp.OFPP_CONTROLLER,
29 max_len=ofp.OFPCML_NO_BUFFER)])],
30 buffer_id=ofp.OFP_NO_BUFFER,
31 priority=1000)
32 logging.info("Inserting flow sending matching packets to controller")
33 self.controller.message_send(request)
34 do_barrier(self.controller)
35
alshabib5339b7d2016-03-01 23:14:57 -080036 for of_port in config["port_map"]:
37 logging.info("PacketInExact test, port %d", of_port)
38 self.dataplane.send(of_port, pkt)
39 verify_packet_in(self, pkt, of_port, ofp.OFPR_ACTION)
40 verify_packets(self, pkt, [])
alshabibcde318b2016-03-01 22:49:13 -080041
42 def processEapolRule(self, in_port, install = True):
43 match = ofp.match()
44 match.oxm_list.append(ofp.oxm.eth_type(0x888e))
45 match.oxm_list.append(ofp.oxm.in_port(in_port))
46 if install:
47 request = ofp.message.flow_add(
48 table_id=test_param_get("table", 0),
49 cookie=42,
50 match=match,
51 instructions=[
52 ofp.instruction.apply_actions(
53 actions=[
54 ofp.action.output(
55 port=ofp.OFPP_CONTROLLER,
56 max_len=ofp.OFPCML_NO_BUFFER)])],
57 buffer_id=ofp.OFP_NO_BUFFER,
58 priority=1000)
59 else:
60 request = ofp.message.flow_delete(
61 table_id=test_param_get("table", 0),
62 cookie=42,
63 match=match,
64 instructions=[
65 ofp.instruction.apply_actions(
66 actions=[
67 ofp.action.output(
68 port=ofp.OFPP_CONTROLLER,
69 max_len=ofp.OFPCML_NO_BUFFER)])],
70 buffer_id=ofp.OFP_NO_BUFFER,
71 priority=1000)
72 logging.info("%s flow sending matching packets to controller" % "Install" if install else "Remove")
73 self.controller.message_send(request)
74 do_barrier(self.controller)
75
alshabib5339b7d2016-03-01 23:14:57 -080076 def testPacketFlow(self, c_vlan_id, s_vlan_id, onu = None):
alshabibcde318b2016-03-01 22:49:13 -080077
78 incorrectTagPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=100, vlan_pcp=1)
79 zeroTaggedPkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=0, vlan_pcp=0)
80 untaggedPkt = simple_udp_packet(pktlen=96)
81
82 upstreamDoubleTaggedPkt = double_vlan_udp_packet(pktlen=104, dl_vlan_enable=True,
83 c_vlan_vid=c_vlan_id,
84 s_vlan_vid=s_vlan_id,
85 c_vlan_pcp=0, s_vlan_pcp=0)
86
alshabib5339b7d2016-03-01 23:14:57 -080087 inport = onu_port if onu is None else onu
88
alshabibcde318b2016-03-01 22:49:13 -080089 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
90
91 # test upstream untagged packet got double tag at OLT
alshabib5339b7d2016-03-01 23:14:57 -080092 self.dataplane.send(inport, str(zeroTaggedPkt))
Admin44f754e2016-03-01 23:00:46 -080093 verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
alshabibcde318b2016-03-01 22:49:13 -080094
95 # test downstream doubletagged packet got untagged at ONU
96 self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
97 if device_type == "pmc":
alshabib5339b7d2016-03-01 23:14:57 -080098 verify_packet(self, zeroTaggedPkt, inport)
alshabibcde318b2016-03-01 22:49:13 -080099 else:
alshabib5339b7d2016-03-01 23:14:57 -0800100 verify_packet(self, untaggedPkt, inport)
alshabibcde318b2016-03-01 22:49:13 -0800101
102 # test upstream doubletagged packet got dropped
alshabib5339b7d2016-03-01 23:14:57 -0800103 self.dataplane.send(inport, str(upstreamDoubleTaggedPkt))
alshabibcde318b2016-03-01 22:49:13 -0800104 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
105
106 # test downstream untagged packet got dropped at ONU
107 self.dataplane.send(olt_port, str(untaggedPkt))
alshabib5339b7d2016-03-01 23:14:57 -0800108 verify_no_packet(self, untaggedPkt, inport)
alshabibcde318b2016-03-01 22:49:13 -0800109
110 # test upstream icorrectly tagged packet; should get dropped
alshabib5339b7d2016-03-01 23:14:57 -0800111 self.dataplane.send(inport, str(incorrectTagPkt))
alshabibcde318b2016-03-01 22:49:13 -0800112 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
113
alshabib5339b7d2016-03-01 23:14:57 -0800114 def installDoubleTaggingRules(self, s_vlan_id, c_vlan_id, cookie=42, onu = None):
115
116 inport = onu_port if onu is None else onu
alshabibd6be76e2016-03-01 22:21:00 -0800117
118 # upstream flow rule
119 match = ofp.match()
alshabib5339b7d2016-03-01 23:14:57 -0800120 match.oxm_list.append(ofp.oxm.in_port(inport))
alshabibd6be76e2016-03-01 22:21:00 -0800121 if device_type == "cpqd":
122 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
123 actions = [
124 ofp.action.push_vlan(ethertype=0x8100),
125 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)),
126 ofp.action.set_field(ofp.oxm.vlan_pcp(0))
127 ]
128 else: # "pmc", "normal"
129 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
130 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
131 actions = [
132 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
133 ]
134 cookie += 1
135
136 # push inner vlan (c-vlan) for upstream
137 request = ofp.message.flow_add(
138 table_id=test_param_get("table", 0),
139 cookie=cookie,
140 match=match,
141 instructions=[
142 ofp.instruction.apply_actions(actions=actions),
143 ofp.instruction.goto_table(1)],
144 buffer_id=ofp.OFP_NO_BUFFER,
145 priority=1000)
146
147 self.controller.message_send(request)
148 do_barrier(self.controller)
149 verify_no_errors(self.controller)
150
151 # push outer vlan (s-vlan) for upstream
152 match = ofp.match()
alshabib5339b7d2016-03-01 23:14:57 -0800153 match.oxm_list.append(ofp.oxm.in_port(inport))
alshabibd6be76e2016-03-01 22:21:00 -0800154 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
155 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
156 cookie += 1
157
158 request = ofp.message.flow_add(
159 table_id=test_param_get("table", 1),
160 cookie=cookie,
161 match=match,
162 instructions=[
163 ofp.instruction.apply_actions(
164 actions=[
165 ofp.action.push_vlan(ethertype=0x8100),
166 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
167 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
168 ofp.action.output(port=olt_port)]),
169 ],
170 buffer_id=ofp.OFP_NO_BUFFER,
171 priority=1000)
172
173 self.controller.message_send(request)
174 do_barrier(self.controller)
175 verify_no_errors(self.controller)
176 cookie += 1
177
178 # strip outer vlan (s-vlan) for downstream
179 match = ofp.match()
180 match.oxm_list.append(ofp.oxm.in_port(olt_port))
181 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
182 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
183 request = ofp.message.flow_add(
184 table_id=test_param_get("table", 0),
185 cookie=cookie,
186 match=match,
187 instructions=[
188 ofp.instruction.apply_actions(
189 actions=[ofp.action.pop_vlan()]),
190 ofp.instruction.goto_table(1)],
191 buffer_id=ofp.OFP_NO_BUFFER,
192 priority=1000)
193
194 self.controller.message_send(request)
195 do_barrier(self.controller)
196 verify_no_errors(self.controller)
197
198 # rewrite inner vlan (c-vlan) to default (0) for downstream
199 match = ofp.match()
200 match.oxm_list.append(ofp.oxm.in_port(olt_port))
201 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
202 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
203 cookie += 1
204
205 request = ofp.message.flow_add(
206 table_id=test_param_get("table", 1),
207 cookie=cookie,
208 match=match,
209 instructions=[
210 ofp.instruction.apply_actions(
211 actions=[
212 ofp.action.pop_vlan(),
alshabib5339b7d2016-03-01 23:14:57 -0800213 ofp.action.output(port=inport)])
alshabibd6be76e2016-03-01 22:21:00 -0800214 ],
215 buffer_id=ofp.OFP_NO_BUFFER,
216 priority=1000)
217
218 self.controller.message_send(request)
219 do_barrier(self.controller)
220 verify_no_errors(self.controller)