blob: 66a775fbd76c4d8c29de6663f21d48fb50da4f2c [file] [log] [blame]
Matteo Scandolo813402b2019-10-23 19:24:52 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package devices
18
19import (
Matteo Scandolo813402b2019-10-23 19:24:52 -070020 "github.com/google/gopacket/layers"
21 "github.com/looplab/fsm"
Matteo Scandolof9d43412021-01-12 11:11:34 -080022 "github.com/opencord/bbsim/internal/bbsim/types"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000023 "github.com/opencord/voltha-protos/v5/go/openolt"
Matteo Scandolo813402b2019-10-23 19:24:52 -070024 "gotest.tools/assert"
Matteo Scandolo813402b2019-10-23 19:24:52 -070025 "testing"
26)
27
Matteo Scandolo4a036262020-08-17 15:56:13 -070028// test that BBR correctly sends the EAPOL Flow
Matteo Scandolo813402b2019-10-23 19:24:52 -070029func Test_Onu_SendEapolFlow(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070030 onu := createMockOnu(1, 1)
Matteo Scandolo813402b2019-10-23 19:24:52 -070031
32 client := &mockClient{
33 FlowAddSpy: FlowAddSpy{
34 Calls: make(map[int]*openolt.Flow),
35 },
36 fail: false,
37 }
38
39 onu.sendEapolFlow(client)
40 assert.Equal(t, client.FlowAddSpy.CallCount, 1)
41
42 assert.Equal(t, client.FlowAddSpy.Calls[1].AccessIntfId, int32(onu.PonPortID))
43 assert.Equal(t, client.FlowAddSpy.Calls[1].OnuId, int32(onu.ID))
44 assert.Equal(t, client.FlowAddSpy.Calls[1].UniId, int32(0))
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070045 assert.Equal(t, client.FlowAddSpy.Calls[1].FlowId, uint64(onu.ID))
Matteo Scandolo813402b2019-10-23 19:24:52 -070046 assert.Equal(t, client.FlowAddSpy.Calls[1].FlowType, "downstream")
47 assert.Equal(t, client.FlowAddSpy.Calls[1].PortNo, onu.ID)
48}
49
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070050// checks that the FlowId is added to the list
51func Test_HandleFlowAddFlowId(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070052 onu := createMockOnu(1, 1)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070053
Matteo Scandolo8a574812021-05-20 15:18:53 -070054 // add flow on the first UNI
55 flow1 := openolt.Flow{
Shrey Baid688b4242020-07-10 20:40:10 +053056 FlowId: 64,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070057 Classifier: &openolt.Classifier{},
Matteo Scandolo8a574812021-05-20 15:18:53 -070058 PortNo: onu.UniPorts[0].(*UniPort).PortNo,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070059 }
Matteo Scandolo8a574812021-05-20 15:18:53 -070060 msg1 := types.OnuFlowUpdateMessage{
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070061 OnuID: onu.ID,
62 PonPortID: onu.PonPortID,
Matteo Scandolo8a574812021-05-20 15:18:53 -070063 Flow: &flow1,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070064 }
Matteo Scandolo8a574812021-05-20 15:18:53 -070065 onu.handleFlowAdd(msg1)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070066 assert.Equal(t, len(onu.FlowIds), 1)
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070067 assert.Equal(t, onu.FlowIds[0], uint64(64))
Matteo Scandolo8a574812021-05-20 15:18:53 -070068
69 // add flow on the second UNI
70 flow2 := openolt.Flow{
71 FlowId: 65,
72 Classifier: &openolt.Classifier{},
73 PortNo: onu.UniPorts[1].(*UniPort).PortNo,
74 }
75 msg2 := types.OnuFlowUpdateMessage{
76 OnuID: onu.ID,
77 PonPortID: onu.PonPortID,
78 Flow: &flow2,
79 }
80 onu.handleFlowAdd(msg2)
81 assert.Equal(t, len(onu.FlowIds), 2)
82 assert.Equal(t, onu.FlowIds[1], uint64(65))
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070083}
84
Matteo Scandolo4a036262020-08-17 15:56:13 -070085// checks that we only remove the correct flow
86func Test_HandleFlowRemoveFlowId(t *testing.T) {
87 onu := createMockOnu(1, 1)
88
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070089 onu.FlowIds = []uint64{1, 2, 34, 64, 92}
Matteo Scandolo4a036262020-08-17 15:56:13 -070090
91 flow := openolt.Flow{
92 FlowId: 64,
93 Classifier: &openolt.Classifier{},
94 }
Matteo Scandolof9d43412021-01-12 11:11:34 -080095 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -070096 OnuID: onu.ID,
97 PonPortID: onu.PonPortID,
98 Flow: &flow,
99 }
100 onu.handleFlowRemove(msg)
101 assert.Equal(t, len(onu.FlowIds), 4)
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700102 assert.Equal(t, onu.FlowIds[0], uint64(1))
103 assert.Equal(t, onu.FlowIds[1], uint64(2))
104 assert.Equal(t, onu.FlowIds[2], uint64(34))
105 assert.Equal(t, onu.FlowIds[3], uint64(92))
Matteo Scandolo4a036262020-08-17 15:56:13 -0700106}
107
108// checks that when the last flow is removed we reset the stored flags in the ONU
109func Test_HandleFlowRemoveFlowId_LastFlow(t *testing.T) {
110 onu := createMockOnu(1, 1)
111
112 onu.InternalState = fsm.NewFSM(
113 "enabled",
114 fsm.Events{
115 {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"},
116 },
117 fsm.Callbacks{},
118 )
119
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700120 onu.FlowIds = []uint64{64}
Matteo Scandolo4a036262020-08-17 15:56:13 -0700121
122 flow := openolt.Flow{
123 FlowId: 64,
124 Classifier: &openolt.Classifier{},
125 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800126 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -0700127 OnuID: onu.ID,
128 PonPortID: onu.PonPortID,
129 Flow: &flow,
130 }
131 onu.handleFlowRemove(msg)
132 assert.Equal(t, len(onu.FlowIds), 0)
Matteo Scandolo4a036262020-08-17 15:56:13 -0700133}
134
135func TestOnu_HhandleEAPOLStart(t *testing.T) {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700136 // FIXME
137 t.Skip("move in the UNI")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700138 onu := createMockOnu(1, 1)
139 hsia := mockService{Name: "hsia"}
140 voip := mockService{Name: "voip"}
141
Matteo Scandolo8a574812021-05-20 15:18:53 -0700142 //onu.Services = []ServiceIf{&hsia, &voip}
Matteo Scandolo4a036262020-08-17 15:56:13 -0700143
144 stream := mockStream{
145 Calls: make(map[int]*openolt.Indication),
146 }
147
148 onu.PonPort.Olt.OpenoltStream = &stream
149
150 flow := openolt.Flow{
151 AccessIntfId: int32(onu.PonPortID),
152 OnuId: int32(onu.ID),
153 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700154 FlowId: uint64(onu.ID),
Matteo Scandolo4a036262020-08-17 15:56:13 -0700155 FlowType: "downstream",
156 AllocId: int32(0),
157 NetworkIntfId: int32(0),
158 Classifier: &openolt.Classifier{
159 EthType: uint32(layers.EthernetTypeEAPOL),
160 OVid: 4091,
161 },
162 Action: &openolt.Action{},
163 Priority: int32(100),
164 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
165 }
166
Matteo Scandolof9d43412021-01-12 11:11:34 -0800167 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -0700168 PonPortID: 1,
169 OnuID: 1,
170 Flow: &flow,
171 }
172
173 onu.handleFlowAdd(msg)
174
175 // check that we call HandleAuth on all the services
176 assert.Equal(t, hsia.HandleAuthCallCount, 1)
177 assert.Equal(t, voip.HandleAuthCallCount, 1)
178}
179
180// TODO all the following tests needs to be moved in the Service model
181
Matteo Scandolo813402b2019-10-23 19:24:52 -0700182// validates that when an ONU receives an EAPOL flow for UNI 0
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800183// and the GemPort has already been configured
Matteo Scandolo813402b2019-10-23 19:24:52 -0700184// it transition to auth_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700185func Test_HandleFlowAddEapolWithGem(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700186 t.Skip("Needs to be moved in the Service struct")
187 onu := createMockOnu(1, 1)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700188
189 onu.InternalState = fsm.NewFSM(
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800190 "enabled",
Matteo Scandolo813402b2019-10-23 19:24:52 -0700191 fsm.Events{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800192 {Name: "start_auth", Src: []string{"enabled"}, Dst: "auth_started"},
Matteo Scandolo813402b2019-10-23 19:24:52 -0700193 },
194 fsm.Callbacks{},
195 )
196
197 flow := openolt.Flow{
198 AccessIntfId: int32(onu.PonPortID),
199 OnuId: int32(onu.ID),
200 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700201 FlowId: uint64(onu.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700202 FlowType: "downstream",
203 AllocId: int32(0),
204 NetworkIntfId: int32(0),
205 Classifier: &openolt.Classifier{
206 EthType: uint32(layers.EthernetTypeEAPOL),
207 OVid: 4091,
208 },
209 Action: &openolt.Action{},
210 Priority: int32(100),
211 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
212 }
213
Matteo Scandolof9d43412021-01-12 11:11:34 -0800214 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo813402b2019-10-23 19:24:52 -0700215 PonPortID: 1,
216 OnuID: 1,
217 Flow: &flow,
218 }
219
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700220 onu.handleFlowAdd(msg)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700221 assert.Equal(t, onu.InternalState.Current(), "auth_started")
222}
223
224// validates that when an ONU receives an EAPOL flow for UNI that is not 0
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800225// no action is taken (this is independent of GemPort status
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700226func Test_HandleFlowAddEapolWrongUNI(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700227 t.Skip("Needs to be moved in the Service struct")
228 onu := createMockOnu(1, 1)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700229
230 onu.InternalState = fsm.NewFSM(
231 "enabled",
232 fsm.Events{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800233 {Name: "start_auth", Src: []string{"enabled"}, Dst: "auth_started"},
Matteo Scandolo813402b2019-10-23 19:24:52 -0700234 },
235 fsm.Callbacks{},
236 )
237
238 flow := openolt.Flow{
239 AccessIntfId: int32(onu.PonPortID),
240 OnuId: int32(onu.ID),
241 UniId: int32(1),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700242 FlowId: uint64(onu.ID),
Matteo Scandolo813402b2019-10-23 19:24:52 -0700243 FlowType: "downstream",
244 AllocId: int32(0),
245 NetworkIntfId: int32(0),
246 Classifier: &openolt.Classifier{
247 EthType: uint32(layers.EthernetTypeEAPOL),
248 OVid: 4091,
249 },
250 Action: &openolt.Action{},
251 Priority: int32(100),
252 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
253 }
254
Matteo Scandolof9d43412021-01-12 11:11:34 -0800255 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo813402b2019-10-23 19:24:52 -0700256 PonPortID: 1,
257 OnuID: 1,
258 Flow: &flow,
259 }
260
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700261 onu.handleFlowAdd(msg)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700262 assert.Equal(t, onu.InternalState.Current(), "enabled")
263}
264
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800265// validates that when an ONU receives a DHCP flow for UNI 0 and pbit 0
266// and the GemPort has already been configured
267// it transition to dhcp_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700268func Test_HandleFlowAddDhcp(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700269 t.Skip("Needs to be moved in the Service struct")
270 onu := createMockOnu(1, 1)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700271
272 onu.InternalState = fsm.NewFSM(
273 "eap_response_success_received",
274 fsm.Events{
275 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
276 },
277 fsm.Callbacks{},
278 )
279
280 flow := openolt.Flow{
281 AccessIntfId: int32(onu.PonPortID),
282 OnuId: int32(onu.ID),
283 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700284 FlowId: uint64(onu.ID),
Matteo Scandoloc1147092019-10-29 09:38:33 -0700285 FlowType: "downstream",
286 AllocId: int32(0),
287 NetworkIntfId: int32(0),
288 Classifier: &openolt.Classifier{
289 EthType: uint32(layers.EthernetTypeIPv4),
290 SrcPort: uint32(68),
291 DstPort: uint32(67),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800292 OPbits: 0,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700293 },
294 Action: &openolt.Action{},
295 Priority: int32(100),
296 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
297 }
298
Matteo Scandolof9d43412021-01-12 11:11:34 -0800299 msg := types.OnuFlowUpdateMessage{
Matteo Scandoloc1147092019-10-29 09:38:33 -0700300 PonPortID: 1,
301 OnuID: 1,
302 Flow: &flow,
303 }
304
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700305 onu.handleFlowAdd(msg)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700306 assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
Matteo Scandoloc1147092019-10-29 09:38:33 -0700307}
308
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800309// validates that when an ONU receives a DHCP flow for UNI 0 and pbit 255
310// and the GemPort has already been configured
311// it transition to dhcp_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700312func Test_HandleFlowAddDhcpPBit255(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700313 t.Skip("Needs to be moved in the Service struct")
314 onu := createMockOnu(1, 1)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700315
316 onu.InternalState = fsm.NewFSM(
317 "eap_response_success_received",
318 fsm.Events{
319 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
320 },
321 fsm.Callbacks{},
322 )
323
324 flow := openolt.Flow{
325 AccessIntfId: int32(onu.PonPortID),
326 OnuId: int32(onu.ID),
327 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700328 FlowId: uint64(onu.ID),
Matteo Scandolod74abba2020-04-16 16:36:44 -0700329 FlowType: "downstream",
330 AllocId: int32(0),
331 NetworkIntfId: int32(0),
332 Classifier: &openolt.Classifier{
333 EthType: uint32(layers.EthernetTypeIPv4),
334 SrcPort: uint32(68),
335 DstPort: uint32(67),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800336 OPbits: 255,
Matteo Scandolod74abba2020-04-16 16:36:44 -0700337 },
338 Action: &openolt.Action{},
339 Priority: int32(100),
340 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
341 }
342
Matteo Scandolof9d43412021-01-12 11:11:34 -0800343 msg := types.OnuFlowUpdateMessage{
Matteo Scandolod74abba2020-04-16 16:36:44 -0700344 PonPortID: 1,
345 OnuID: 1,
346 Flow: &flow,
347 }
348
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700349 onu.handleFlowAdd(msg)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700350 assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
Matteo Scandolod74abba2020-04-16 16:36:44 -0700351}
352
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800353// validates that when an ONU receives a DHCP flow for UNI 0 and pbit not 0 or 255
354// and the GemPort has already been configured
355// it ignores the message
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700356func Test_HandleFlowAddDhcpIgnoreByPbit(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700357 t.Skip("Needs to be moved in the Service struct")
358 onu := createMockOnu(1, 1)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700359
360 onu.InternalState = fsm.NewFSM(
361 "eap_response_success_received",
362 fsm.Events{
363 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
364 },
365 fsm.Callbacks{},
366 )
367
368 flow := openolt.Flow{
369 AccessIntfId: int32(onu.PonPortID),
370 OnuId: int32(onu.ID),
371 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700372 FlowId: uint64(onu.ID),
Matteo Scandolod74abba2020-04-16 16:36:44 -0700373 FlowType: "downstream",
374 AllocId: int32(0),
375 NetworkIntfId: int32(0),
376 Classifier: &openolt.Classifier{
377 EthType: uint32(layers.EthernetTypeIPv4),
378 SrcPort: uint32(68),
379 DstPort: uint32(67),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800380 OPbits: 1,
Matteo Scandolod74abba2020-04-16 16:36:44 -0700381 },
382 Action: &openolt.Action{},
383 Priority: int32(100),
384 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
385 }
386
Matteo Scandolof9d43412021-01-12 11:11:34 -0800387 msg := types.OnuFlowUpdateMessage{
Matteo Scandolod74abba2020-04-16 16:36:44 -0700388 PonPortID: 1,
389 OnuID: 1,
390 Flow: &flow,
391 }
392
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700393 onu.handleFlowAdd(msg)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700394 assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
Matteo Scandolod74abba2020-04-16 16:36:44 -0700395}
396
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800397// validates that when an ONU receives a DHCP flow for UNI 0
398// but the noDchp bit is set no action is taken
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700399func Test_HandleFlowAddDhcpNoDhcp(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700400 t.Skip("Needs to be moved in the Service struct")
401 onu := createMockOnu(1, 1)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700402
403 onu.InternalState = fsm.NewFSM(
404 "eap_response_success_received",
405 fsm.Events{
406 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
407 },
408 fsm.Callbacks{},
409 )
410
411 flow := openolt.Flow{
412 AccessIntfId: int32(onu.PonPortID),
413 OnuId: int32(onu.ID),
414 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700415 FlowId: uint64(onu.ID),
Matteo Scandoloc1147092019-10-29 09:38:33 -0700416 FlowType: "downstream",
417 AllocId: int32(0),
418 NetworkIntfId: int32(0),
419 Classifier: &openolt.Classifier{
420 EthType: uint32(layers.EthernetTypeIPv4),
421 SrcPort: uint32(68),
422 DstPort: uint32(67),
423 },
424 Action: &openolt.Action{},
425 Priority: int32(100),
426 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
427 }
428
Matteo Scandolof9d43412021-01-12 11:11:34 -0800429 msg := types.OnuFlowUpdateMessage{
Matteo Scandoloc1147092019-10-29 09:38:33 -0700430 PonPortID: 1,
431 OnuID: 1,
432 Flow: &flow,
433 }
434
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700435 onu.handleFlowAdd(msg)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700436 assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
Matteo Scandoloc1147092019-10-29 09:38:33 -0700437}
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800438
439// validates that when an ONU receives a DHCP flow for UNI 0 and pbit not 0 or 255
440// and the GemPort has not already been configured
441// it transition to dhcp_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700442func Test_HandleFlowAddDhcpWithoutGem(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700443 t.Skip("Needs to be moved in the Service struct")
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700444 // NOTE that this feature is required as there is no guarantee that the gemport is the same
445 // one we received with the EAPOL flow
Matteo Scandolo4a036262020-08-17 15:56:13 -0700446 onu := createMockOnu(1, 1)
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800447
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800448 onu.InternalState = fsm.NewFSM(
449 "enabled",
450 fsm.Events{
451 {Name: "start_dhcp", Src: []string{"enabled"}, Dst: "dhcp_started"},
452 },
453 fsm.Callbacks{},
454 )
455
456 flow := openolt.Flow{
457 AccessIntfId: int32(onu.PonPortID),
458 OnuId: int32(onu.ID),
459 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700460 FlowId: uint64(onu.ID),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800461 FlowType: "downstream",
462 AllocId: int32(0),
463 NetworkIntfId: int32(0),
464 Classifier: &openolt.Classifier{
465 EthType: uint32(layers.EthernetTypeIPv4),
466 SrcPort: uint32(68),
467 DstPort: uint32(67),
468 OPbits: 0,
469 },
470 Action: &openolt.Action{},
471 Priority: int32(100),
472 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
473 }
474
Matteo Scandolof9d43412021-01-12 11:11:34 -0800475 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800476 PonPortID: 1,
477 OnuID: 1,
478 Flow: &flow,
479 }
480
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700481 onu.handleFlowAdd(msg)
Hardik Windlass7b3405b2020-07-08 15:10:05 +0530482}