blob: ba72e8e9a04f84082aebd0c54cad5e784916cdc6 [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
36 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, [])
41
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
76 def testPacketFlow(self, c_vlan_id, s_vlan_id):
77
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
87 logging.info("Testing s-tag %d, c-tag %d" % (s_vlan_id, c_vlan_id))
88
89 # test upstream untagged packet got double tag at OLT
90 self.dataplane.send(onu_port, str(zeroTaggedPkt))
Admin44f754e2016-03-01 23:00:46 -080091 verify_packet(self, upstreamDoubleTaggedPkt, olt_port)
alshabibcde318b2016-03-01 22:49:13 -080092
93 # test downstream doubletagged packet got untagged at ONU
94 self.dataplane.send(olt_port, str(upstreamDoubleTaggedPkt))
95 if device_type == "pmc":
96 verify_packet(self, zeroTaggedPkt, onu_port)
97 else:
98 verify_packet(self, untaggedPkt, onu_port)
99
100 # test upstream doubletagged packet got dropped
101 self.dataplane.send(onu_port, str(upstreamDoubleTaggedPkt))
102 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
103
104 # test downstream untagged packet got dropped at ONU
105 self.dataplane.send(olt_port, str(untaggedPkt))
106 verify_no_packet(self, untaggedPkt, onu_port)
107
108 # test upstream icorrectly tagged packet; should get dropped
109 self.dataplane.send(onu_port, str(incorrectTagPkt))
110 verify_no_packet(self, upstreamDoubleTaggedPkt, olt_port)
111
Admin4ebddb82016-03-01 22:36:30 -0800112 def installDoubleTaggingRules(self, s_vlan_id, c_vlan_id, cookie=42):
alshabibd6be76e2016-03-01 22:21:00 -0800113
114 # upstream flow rule
115 match = ofp.match()
116 match.oxm_list.append(ofp.oxm.in_port(onu_port))
117 if device_type == "cpqd":
118 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_NONE))
119 actions = [
120 ofp.action.push_vlan(ethertype=0x8100),
121 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id)),
122 ofp.action.set_field(ofp.oxm.vlan_pcp(0))
123 ]
124 else: # "pmc", "normal"
125 match.oxm_list.append(ofp.oxm.vlan_vid(value=ofp.OFPVID_PRESENT))
126 match.oxm_list.append(ofp.oxm.vlan_pcp(value=0))
127 actions = [
128 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
129 ]
130 cookie += 1
131
132 # push inner vlan (c-vlan) for upstream
133 request = ofp.message.flow_add(
134 table_id=test_param_get("table", 0),
135 cookie=cookie,
136 match=match,
137 instructions=[
138 ofp.instruction.apply_actions(actions=actions),
139 ofp.instruction.goto_table(1)],
140 buffer_id=ofp.OFP_NO_BUFFER,
141 priority=1000)
142
143 self.controller.message_send(request)
144 do_barrier(self.controller)
145 verify_no_errors(self.controller)
146
147 # push outer vlan (s-vlan) for upstream
148 match = ofp.match()
149 match.oxm_list.append(ofp.oxm.in_port(onu_port))
150 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
151 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
152 cookie += 1
153
154 request = ofp.message.flow_add(
155 table_id=test_param_get("table", 1),
156 cookie=cookie,
157 match=match,
158 instructions=[
159 ofp.instruction.apply_actions(
160 actions=[
161 ofp.action.push_vlan(ethertype=0x8100),
162 ofp.action.set_field(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id)),
163 ofp.action.set_field(ofp.oxm.vlan_pcp(0)),
164 ofp.action.output(port=olt_port)]),
165 ],
166 buffer_id=ofp.OFP_NO_BUFFER,
167 priority=1000)
168
169 self.controller.message_send(request)
170 do_barrier(self.controller)
171 verify_no_errors(self.controller)
172 cookie += 1
173
174 # strip outer vlan (s-vlan) for downstream
175 match = ofp.match()
176 match.oxm_list.append(ofp.oxm.in_port(olt_port))
177 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | s_vlan_id))
178 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
179 request = ofp.message.flow_add(
180 table_id=test_param_get("table", 0),
181 cookie=cookie,
182 match=match,
183 instructions=[
184 ofp.instruction.apply_actions(
185 actions=[ofp.action.pop_vlan()]),
186 ofp.instruction.goto_table(1)],
187 buffer_id=ofp.OFP_NO_BUFFER,
188 priority=1000)
189
190 self.controller.message_send(request)
191 do_barrier(self.controller)
192 verify_no_errors(self.controller)
193
194 # rewrite inner vlan (c-vlan) to default (0) for downstream
195 match = ofp.match()
196 match.oxm_list.append(ofp.oxm.in_port(olt_port))
197 match.oxm_list.append(ofp.oxm.vlan_vid(ofp.OFPVID_PRESENT | c_vlan_id))
198 match.oxm_list.append(ofp.oxm.vlan_pcp(0))
199 cookie += 1
200
201 request = ofp.message.flow_add(
202 table_id=test_param_get("table", 1),
203 cookie=cookie,
204 match=match,
205 instructions=[
206 ofp.instruction.apply_actions(
207 actions=[
208 ofp.action.pop_vlan(),
209 ofp.action.output(port=onu_port)])
210 ],
211 buffer_id=ofp.OFP_NO_BUFFER,
212 priority=1000)
213
214 self.controller.message_send(request)
215 do_barrier(self.controller)
216 verify_no_errors(self.controller)