blob: dd760cddd07f71f90f2ba8b3040152872fe9eabc [file] [log] [blame]
Matteo Scandolo813402b2019-10-23 19:24:52 -07001/*
Joey Armstrong2c039362024-02-04 18:51:52 -05002 * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors
Matteo Scandolo813402b2019-10-23 19:24:52 -07003
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 (
Elia Battiston560e9552022-01-31 10:44:15 +010020 "testing"
21
Matteo Scandolo813402b2019-10-23 19:24:52 -070022 "github.com/google/gopacket/layers"
23 "github.com/looplab/fsm"
Matteo Scandolof9d43412021-01-12 11:11:34 -080024 "github.com/opencord/bbsim/internal/bbsim/types"
David K. Bainbridgec415efe2021-08-19 13:05:21 +000025 "github.com/opencord/voltha-protos/v5/go/openolt"
Matteo Scandolo813402b2019-10-23 19:24:52 -070026 "gotest.tools/assert"
Matteo Scandolo813402b2019-10-23 19:24:52 -070027)
28
Matteo Scandolo4a036262020-08-17 15:56:13 -070029// test that BBR correctly sends the EAPOL Flow
Matteo Scandolo813402b2019-10-23 19:24:52 -070030func Test_Onu_SendEapolFlow(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070031 onu := createMockOnu(1, 1)
Matteo Scandolo813402b2019-10-23 19:24:52 -070032
33 client := &mockClient{
34 FlowAddSpy: FlowAddSpy{
35 Calls: make(map[int]*openolt.Flow),
36 },
37 fail: false,
38 }
39
40 onu.sendEapolFlow(client)
41 assert.Equal(t, client.FlowAddSpy.CallCount, 1)
42
43 assert.Equal(t, client.FlowAddSpy.Calls[1].AccessIntfId, int32(onu.PonPortID))
44 assert.Equal(t, client.FlowAddSpy.Calls[1].OnuId, int32(onu.ID))
45 assert.Equal(t, client.FlowAddSpy.Calls[1].UniId, int32(0))
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070046 assert.Equal(t, client.FlowAddSpy.Calls[1].FlowId, uint64(onu.ID))
Elia Battiston560e9552022-01-31 10:44:15 +010047 assert.Equal(t, client.FlowAddSpy.Calls[1].FlowType, flowTypeDownstream)
Matteo Scandolo813402b2019-10-23 19:24:52 -070048 assert.Equal(t, client.FlowAddSpy.Calls[1].PortNo, onu.ID)
49}
50
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070051// checks that the FlowId is added to the list
52func Test_HandleFlowAddFlowId(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -070053 onu := createMockOnu(1, 1)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070054
Matteo Scandolo8a574812021-05-20 15:18:53 -070055 // add flow on the first UNI
56 flow1 := openolt.Flow{
Shrey Baid688b4242020-07-10 20:40:10 +053057 FlowId: 64,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070058 Classifier: &openolt.Classifier{},
Matteo Scandolo8a574812021-05-20 15:18:53 -070059 PortNo: onu.UniPorts[0].(*UniPort).PortNo,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070060 }
Matteo Scandolo8a574812021-05-20 15:18:53 -070061 msg1 := types.OnuFlowUpdateMessage{
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070062 OnuID: onu.ID,
63 PonPortID: onu.PonPortID,
Matteo Scandolo8a574812021-05-20 15:18:53 -070064 Flow: &flow1,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070065 }
Matteo Scandolo8a574812021-05-20 15:18:53 -070066 onu.handleFlowAdd(msg1)
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070067 assert.Equal(t, len(onu.FlowIds), 1)
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070068 assert.Equal(t, onu.FlowIds[0], uint64(64))
Matteo Scandolo8a574812021-05-20 15:18:53 -070069
70 // add flow on the second UNI
71 flow2 := openolt.Flow{
72 FlowId: 65,
73 Classifier: &openolt.Classifier{},
74 PortNo: onu.UniPorts[1].(*UniPort).PortNo,
75 }
76 msg2 := types.OnuFlowUpdateMessage{
77 OnuID: onu.ID,
78 PonPortID: onu.PonPortID,
79 Flow: &flow2,
80 }
81 onu.handleFlowAdd(msg2)
82 assert.Equal(t, len(onu.FlowIds), 2)
83 assert.Equal(t, onu.FlowIds[1], uint64(65))
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070084}
85
Matteo Scandolo4a036262020-08-17 15:56:13 -070086// checks that we only remove the correct flow
87func Test_HandleFlowRemoveFlowId(t *testing.T) {
88 onu := createMockOnu(1, 1)
89
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070090 onu.FlowIds = []uint64{1, 2, 34, 64, 92}
Matteo Scandolo4a036262020-08-17 15:56:13 -070091
92 flow := openolt.Flow{
93 FlowId: 64,
94 Classifier: &openolt.Classifier{},
95 }
Matteo Scandolof9d43412021-01-12 11:11:34 -080096 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -070097 OnuID: onu.ID,
98 PonPortID: onu.PonPortID,
99 Flow: &flow,
100 }
101 onu.handleFlowRemove(msg)
102 assert.Equal(t, len(onu.FlowIds), 4)
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700103 assert.Equal(t, onu.FlowIds[0], uint64(1))
104 assert.Equal(t, onu.FlowIds[1], uint64(2))
105 assert.Equal(t, onu.FlowIds[2], uint64(34))
106 assert.Equal(t, onu.FlowIds[3], uint64(92))
Matteo Scandolo4a036262020-08-17 15:56:13 -0700107}
108
109// checks that when the last flow is removed we reset the stored flags in the ONU
110func Test_HandleFlowRemoveFlowId_LastFlow(t *testing.T) {
111 onu := createMockOnu(1, 1)
112
113 onu.InternalState = fsm.NewFSM(
114 "enabled",
115 fsm.Events{
116 {Name: "disable", Src: []string{"enabled"}, Dst: "disabled"},
117 },
118 fsm.Callbacks{},
119 )
120
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700121 onu.FlowIds = []uint64{64}
Matteo Scandolo4a036262020-08-17 15:56:13 -0700122
123 flow := openolt.Flow{
124 FlowId: 64,
125 Classifier: &openolt.Classifier{},
126 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800127 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -0700128 OnuID: onu.ID,
129 PonPortID: onu.PonPortID,
130 Flow: &flow,
131 }
132 onu.handleFlowRemove(msg)
133 assert.Equal(t, len(onu.FlowIds), 0)
Matteo Scandolo4a036262020-08-17 15:56:13 -0700134}
135
136func TestOnu_HhandleEAPOLStart(t *testing.T) {
Matteo Scandolo8a574812021-05-20 15:18:53 -0700137 // FIXME
138 t.Skip("move in the UNI")
Matteo Scandolo4a036262020-08-17 15:56:13 -0700139 onu := createMockOnu(1, 1)
140 hsia := mockService{Name: "hsia"}
141 voip := mockService{Name: "voip"}
142
Matteo Scandolo8a574812021-05-20 15:18:53 -0700143 //onu.Services = []ServiceIf{&hsia, &voip}
Matteo Scandolo4a036262020-08-17 15:56:13 -0700144
145 stream := mockStream{
146 Calls: make(map[int]*openolt.Indication),
147 }
148
149 onu.PonPort.Olt.OpenoltStream = &stream
150
151 flow := openolt.Flow{
152 AccessIntfId: int32(onu.PonPortID),
153 OnuId: int32(onu.ID),
154 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700155 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100156 FlowType: flowTypeDownstream,
Matteo Scandolo4a036262020-08-17 15:56:13 -0700157 AllocId: int32(0),
158 NetworkIntfId: int32(0),
159 Classifier: &openolt.Classifier{
160 EthType: uint32(layers.EthernetTypeEAPOL),
161 OVid: 4091,
162 },
163 Action: &openolt.Action{},
164 Priority: int32(100),
165 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
166 }
167
Matteo Scandolof9d43412021-01-12 11:11:34 -0800168 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo4a036262020-08-17 15:56:13 -0700169 PonPortID: 1,
170 OnuID: 1,
171 Flow: &flow,
172 }
173
174 onu.handleFlowAdd(msg)
175
176 // check that we call HandleAuth on all the services
177 assert.Equal(t, hsia.HandleAuthCallCount, 1)
178 assert.Equal(t, voip.HandleAuthCallCount, 1)
179}
180
181// TODO all the following tests needs to be moved in the Service model
182
Matteo Scandolo813402b2019-10-23 19:24:52 -0700183// validates that when an ONU receives an EAPOL flow for UNI 0
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800184// and the GemPort has already been configured
Matteo Scandolo813402b2019-10-23 19:24:52 -0700185// it transition to auth_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700186func Test_HandleFlowAddEapolWithGem(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700187 t.Skip("Needs to be moved in the Service struct")
188 onu := createMockOnu(1, 1)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700189
190 onu.InternalState = fsm.NewFSM(
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800191 "enabled",
Matteo Scandolo813402b2019-10-23 19:24:52 -0700192 fsm.Events{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800193 {Name: "start_auth", Src: []string{"enabled"}, Dst: "auth_started"},
Matteo Scandolo813402b2019-10-23 19:24:52 -0700194 },
195 fsm.Callbacks{},
196 )
197
198 flow := openolt.Flow{
199 AccessIntfId: int32(onu.PonPortID),
200 OnuId: int32(onu.ID),
201 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700202 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100203 FlowType: flowTypeDownstream,
Matteo Scandolo813402b2019-10-23 19:24:52 -0700204 AllocId: int32(0),
205 NetworkIntfId: int32(0),
206 Classifier: &openolt.Classifier{
207 EthType: uint32(layers.EthernetTypeEAPOL),
208 OVid: 4091,
209 },
210 Action: &openolt.Action{},
211 Priority: int32(100),
212 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
213 }
214
Matteo Scandolof9d43412021-01-12 11:11:34 -0800215 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo813402b2019-10-23 19:24:52 -0700216 PonPortID: 1,
217 OnuID: 1,
218 Flow: &flow,
219 }
220
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700221 onu.handleFlowAdd(msg)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700222 assert.Equal(t, onu.InternalState.Current(), "auth_started")
223}
224
225// validates that when an ONU receives an EAPOL flow for UNI that is not 0
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800226// no action is taken (this is independent of GemPort status
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700227func Test_HandleFlowAddEapolWrongUNI(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700228 t.Skip("Needs to be moved in the Service struct")
229 onu := createMockOnu(1, 1)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700230
231 onu.InternalState = fsm.NewFSM(
232 "enabled",
233 fsm.Events{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800234 {Name: "start_auth", Src: []string{"enabled"}, Dst: "auth_started"},
Matteo Scandolo813402b2019-10-23 19:24:52 -0700235 },
236 fsm.Callbacks{},
237 )
238
239 flow := openolt.Flow{
240 AccessIntfId: int32(onu.PonPortID),
241 OnuId: int32(onu.ID),
242 UniId: int32(1),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700243 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100244 FlowType: flowTypeDownstream,
Matteo Scandolo813402b2019-10-23 19:24:52 -0700245 AllocId: int32(0),
246 NetworkIntfId: int32(0),
247 Classifier: &openolt.Classifier{
248 EthType: uint32(layers.EthernetTypeEAPOL),
249 OVid: 4091,
250 },
251 Action: &openolt.Action{},
252 Priority: int32(100),
253 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
254 }
255
Matteo Scandolof9d43412021-01-12 11:11:34 -0800256 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo813402b2019-10-23 19:24:52 -0700257 PonPortID: 1,
258 OnuID: 1,
259 Flow: &flow,
260 }
261
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700262 onu.handleFlowAdd(msg)
Matteo Scandolo813402b2019-10-23 19:24:52 -0700263 assert.Equal(t, onu.InternalState.Current(), "enabled")
264}
265
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800266// validates that when an ONU receives a DHCP flow for UNI 0 and pbit 0
267// and the GemPort has already been configured
268// it transition to dhcp_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700269func Test_HandleFlowAddDhcp(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700270 t.Skip("Needs to be moved in the Service struct")
271 onu := createMockOnu(1, 1)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700272
273 onu.InternalState = fsm.NewFSM(
274 "eap_response_success_received",
275 fsm.Events{
276 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
277 },
278 fsm.Callbacks{},
279 )
280
281 flow := openolt.Flow{
282 AccessIntfId: int32(onu.PonPortID),
283 OnuId: int32(onu.ID),
284 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700285 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100286 FlowType: flowTypeDownstream,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700287 AllocId: int32(0),
288 NetworkIntfId: int32(0),
289 Classifier: &openolt.Classifier{
290 EthType: uint32(layers.EthernetTypeIPv4),
291 SrcPort: uint32(68),
292 DstPort: uint32(67),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800293 OPbits: 0,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700294 },
295 Action: &openolt.Action{},
296 Priority: int32(100),
297 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
298 }
299
Matteo Scandolof9d43412021-01-12 11:11:34 -0800300 msg := types.OnuFlowUpdateMessage{
Matteo Scandoloc1147092019-10-29 09:38:33 -0700301 PonPortID: 1,
302 OnuID: 1,
303 Flow: &flow,
304 }
305
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700306 onu.handleFlowAdd(msg)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700307 assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
Matteo Scandoloc1147092019-10-29 09:38:33 -0700308}
309
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800310// validates that when an ONU receives a DHCP flow for UNI 0 and pbit 255
311// and the GemPort has already been configured
312// it transition to dhcp_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700313func Test_HandleFlowAddDhcpPBit255(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700314 t.Skip("Needs to be moved in the Service struct")
315 onu := createMockOnu(1, 1)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700316
317 onu.InternalState = fsm.NewFSM(
318 "eap_response_success_received",
319 fsm.Events{
320 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
321 },
322 fsm.Callbacks{},
323 )
324
325 flow := openolt.Flow{
326 AccessIntfId: int32(onu.PonPortID),
327 OnuId: int32(onu.ID),
328 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700329 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100330 FlowType: flowTypeDownstream,
Matteo Scandolod74abba2020-04-16 16:36:44 -0700331 AllocId: int32(0),
332 NetworkIntfId: int32(0),
333 Classifier: &openolt.Classifier{
334 EthType: uint32(layers.EthernetTypeIPv4),
335 SrcPort: uint32(68),
336 DstPort: uint32(67),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800337 OPbits: 255,
Matteo Scandolod74abba2020-04-16 16:36:44 -0700338 },
339 Action: &openolt.Action{},
340 Priority: int32(100),
341 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
342 }
343
Matteo Scandolof9d43412021-01-12 11:11:34 -0800344 msg := types.OnuFlowUpdateMessage{
Matteo Scandolod74abba2020-04-16 16:36:44 -0700345 PonPortID: 1,
346 OnuID: 1,
347 Flow: &flow,
348 }
349
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700350 onu.handleFlowAdd(msg)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700351 assert.Equal(t, onu.InternalState.Current(), "dhcp_started")
Matteo Scandolod74abba2020-04-16 16:36:44 -0700352}
353
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800354// validates that when an ONU receives a DHCP flow for UNI 0 and pbit not 0 or 255
355// and the GemPort has already been configured
356// it ignores the message
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700357func Test_HandleFlowAddDhcpIgnoreByPbit(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700358 t.Skip("Needs to be moved in the Service struct")
359 onu := createMockOnu(1, 1)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700360
361 onu.InternalState = fsm.NewFSM(
362 "eap_response_success_received",
363 fsm.Events{
364 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
365 },
366 fsm.Callbacks{},
367 )
368
369 flow := openolt.Flow{
370 AccessIntfId: int32(onu.PonPortID),
371 OnuId: int32(onu.ID),
372 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700373 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100374 FlowType: flowTypeDownstream,
Matteo Scandolod74abba2020-04-16 16:36:44 -0700375 AllocId: int32(0),
376 NetworkIntfId: int32(0),
377 Classifier: &openolt.Classifier{
378 EthType: uint32(layers.EthernetTypeIPv4),
379 SrcPort: uint32(68),
380 DstPort: uint32(67),
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800381 OPbits: 1,
Matteo Scandolod74abba2020-04-16 16:36:44 -0700382 },
383 Action: &openolt.Action{},
384 Priority: int32(100),
385 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
386 }
387
Matteo Scandolof9d43412021-01-12 11:11:34 -0800388 msg := types.OnuFlowUpdateMessage{
Matteo Scandolod74abba2020-04-16 16:36:44 -0700389 PonPortID: 1,
390 OnuID: 1,
391 Flow: &flow,
392 }
393
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700394 onu.handleFlowAdd(msg)
Matteo Scandolod74abba2020-04-16 16:36:44 -0700395 assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
Matteo Scandolod74abba2020-04-16 16:36:44 -0700396}
397
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800398// validates that when an ONU receives a DHCP flow for UNI 0
399// but the noDchp bit is set no action is taken
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700400func Test_HandleFlowAddDhcpNoDhcp(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700401 t.Skip("Needs to be moved in the Service struct")
402 onu := createMockOnu(1, 1)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700403
404 onu.InternalState = fsm.NewFSM(
405 "eap_response_success_received",
406 fsm.Events{
407 {Name: "start_dhcp", Src: []string{"eap_response_success_received"}, Dst: "dhcp_started"},
408 },
409 fsm.Callbacks{},
410 )
411
412 flow := openolt.Flow{
413 AccessIntfId: int32(onu.PonPortID),
414 OnuId: int32(onu.ID),
415 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700416 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100417 FlowType: flowTypeDownstream,
Matteo Scandoloc1147092019-10-29 09:38:33 -0700418 AllocId: int32(0),
419 NetworkIntfId: int32(0),
420 Classifier: &openolt.Classifier{
421 EthType: uint32(layers.EthernetTypeIPv4),
422 SrcPort: uint32(68),
423 DstPort: uint32(67),
424 },
425 Action: &openolt.Action{},
426 Priority: int32(100),
427 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
428 }
429
Matteo Scandolof9d43412021-01-12 11:11:34 -0800430 msg := types.OnuFlowUpdateMessage{
Matteo Scandoloc1147092019-10-29 09:38:33 -0700431 PonPortID: 1,
432 OnuID: 1,
433 Flow: &flow,
434 }
435
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700436 onu.handleFlowAdd(msg)
Matteo Scandoloc1147092019-10-29 09:38:33 -0700437 assert.Equal(t, onu.InternalState.Current(), "eap_response_success_received")
Matteo Scandoloc1147092019-10-29 09:38:33 -0700438}
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800439
440// validates that when an ONU receives a DHCP flow for UNI 0 and pbit not 0 or 255
441// and the GemPort has not already been configured
442// it transition to dhcp_started state
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700443func Test_HandleFlowAddDhcpWithoutGem(t *testing.T) {
Matteo Scandolo4a036262020-08-17 15:56:13 -0700444 t.Skip("Needs to be moved in the Service struct")
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700445 // NOTE that this feature is required as there is no guarantee that the gemport is the same
446 // one we received with the EAPOL flow
Matteo Scandolo4a036262020-08-17 15:56:13 -0700447 onu := createMockOnu(1, 1)
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800448
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800449 onu.InternalState = fsm.NewFSM(
450 "enabled",
451 fsm.Events{
452 {Name: "start_dhcp", Src: []string{"enabled"}, Dst: "dhcp_started"},
453 },
454 fsm.Callbacks{},
455 )
456
457 flow := openolt.Flow{
458 AccessIntfId: int32(onu.PonPortID),
459 OnuId: int32(onu.ID),
460 UniId: int32(0),
Matteo Scandolo4f4ac792020-10-01 16:33:21 -0700461 FlowId: uint64(onu.ID),
Elia Battiston560e9552022-01-31 10:44:15 +0100462 FlowType: flowTypeDownstream,
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800463 AllocId: int32(0),
464 NetworkIntfId: int32(0),
465 Classifier: &openolt.Classifier{
466 EthType: uint32(layers.EthernetTypeIPv4),
467 SrcPort: uint32(68),
468 DstPort: uint32(67),
469 OPbits: 0,
470 },
471 Action: &openolt.Action{},
472 Priority: int32(100),
473 PortNo: uint32(onu.ID), // NOTE we are using this to map an incoming packetIndication to an ONU
474 }
475
Matteo Scandolof9d43412021-01-12 11:11:34 -0800476 msg := types.OnuFlowUpdateMessage{
Matteo Scandolo5ff80082019-12-20 13:20:57 -0800477 PonPortID: 1,
478 OnuID: 1,
479 Flow: &flow,
480 }
481
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700482 onu.handleFlowAdd(msg)
Hardik Windlass7b3405b2020-07-08 15:10:05 +0530483}