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