blob: 994902e930815b0f9b9d373b5de4b8e097a591d1 [file] [log] [blame]
Matteo Scandolo10f965c2019-09-24 10:40:46 -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 Scandolob5913142021-03-19 16:10:18 -070020 "context"
21 "github.com/looplab/fsm"
Matteo Scandolof9d43412021-01-12 11:11:34 -080022 "github.com/opencord/bbsim/internal/bbsim/types"
Matteo Scandolob5913142021-03-19 16:10:18 -070023 bbsim "github.com/opencord/bbsim/internal/bbsim/types"
Matteo Scandolo4a036262020-08-17 15:56:13 -070024 "github.com/opencord/bbsim/internal/common"
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070025 "net"
Matteo Scandolo10f965c2019-09-24 10:40:46 -070026 "testing"
Shrey Baid688b4242020-07-10 20:40:10 +053027
Matteo Scandolo4f4ac792020-10-01 16:33:21 -070028 "github.com/opencord/voltha-protos/v4/go/openolt"
Shrey Baid688b4242020-07-10 20:40:10 +053029 "gotest.tools/assert"
Matteo Scandolo10f965c2019-09-24 10:40:46 -070030)
31
Matteo Scandolo4a036262020-08-17 15:56:13 -070032func createMockOlt(numPon int, numOnu int, services []ServiceIf) *OltDevice {
Shrey Baid688b4242020-07-10 20:40:10 +053033 olt := &OltDevice{
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080034 ID: 0,
35 AllocIDs: make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool),
36 GemPortIDs: make(map[uint32]map[uint32]map[uint32]map[int32]map[uint64]bool),
Matteo Scandolo10f965c2019-09-24 10:40:46 -070037 }
38
39 for i := 0; i < numPon; i++ {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080040
41 // initialize the resource maps for every PON Ports
42 olt.AllocIDs[uint32(i)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool)
43 olt.GemPortIDs[uint32(i)] = make(map[uint32]map[uint32]map[int32]map[uint64]bool)
44
Matteo Scandolo10f965c2019-09-24 10:40:46 -070045 pon := PonPort{
46 ID: uint32(i),
47 }
48
49 for j := 0; j < numOnu; j++ {
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080050
51 // initialize the resource maps for every ONU and the first UNI
52 olt.AllocIDs[uint32(i)][uint32(j)] = make(map[uint32]map[int32]map[uint64]bool)
53 olt.GemPortIDs[uint32(i)][uint32(j)] = make(map[uint32]map[int32]map[uint64]bool)
54
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070055 onuId := uint32(i + j)
Matteo Scandolo10f965c2019-09-24 10:40:46 -070056 onu := Onu{
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070057 ID: onuId,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -070058 PonPort: &pon,
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -070059 PonPortID: pon.ID,
Matteo Scandolob5913142021-03-19 16:10:18 -070060 InternalState: fsm.NewFSM(
61 OnuStateCreated,
62 // this is fake state machine, we don't care about transition in the OLT
63 // unit tests, we'll use SetState to emulate cases
64 fsm.Events{
65 {Name: OnuTxEnable, Src: []string{}, Dst: OnuStateEnabled},
66 {Name: OnuTxDisable, Src: []string{}, Dst: OnuStateDisabled},
67 },
68 fsm.Callbacks{},
69 ),
70 Channel: make(chan bbsim.Message, 2048),
Matteo Scandolo10f965c2019-09-24 10:40:46 -070071 }
Matteo Scandolo4a036262020-08-17 15:56:13 -070072
73 for k, s := range services {
74 service := s.(*Service)
75 service.HwAddress = net.HardwareAddr{0x2e, 0x60, byte(olt.ID), byte(pon.ID), byte(onuId), byte(k)}
76 service.Onu = &onu
77 onu.Services = append(onu.Services, service)
78 }
79
Matteo Scandolo4b077aa2021-02-16 17:33:37 -080080 onu.SerialNumber = NewSN(olt.ID, pon.ID, onu.ID)
Matteo Scandolo27428702019-10-11 16:21:16 -070081 pon.Onus = append(pon.Onus, &onu)
Matteo Scandolo10f965c2019-09-24 10:40:46 -070082 }
Matteo Scandolo27428702019-10-11 16:21:16 -070083 olt.Pons = append(olt.Pons, &pon)
Matteo Scandolo10f965c2019-09-24 10:40:46 -070084 }
85 return olt
86}
87
Matteo Scandolo4a036262020-08-17 15:56:13 -070088// check the creation of an OLT with a single Service
89func TestCreateOLT(t *testing.T) {
90
91 common.Services = []common.ServiceYaml{
92 {Name: "hsia", CTag: 900, CTagAllocation: common.TagAllocationUnique.String(), STag: 900, STagAllocation: common.TagAllocationShared.String(), NeedsEapol: true, NeedsDchp: true, NeedsIgmp: true},
93 }
94
95 common.Config = &common.GlobalConfig{
96 Olt: common.OltConfig{
97 ID: 1,
98 PonPorts: 2,
99 OnusPonPort: 2,
100 },
101 }
102
103 olt := CreateOLT(*common.Config, common.Services, true)
104
105 assert.Equal(t, len(olt.Pons), int(common.Config.Olt.PonPorts))
106
107 // count the ONUs
108 onus := 0
109 for _, p := range olt.Pons {
110 onus = onus + len(p.Onus)
111 }
112
113 assert.Equal(t, onus, int(common.Config.Olt.PonPorts*common.Config.Olt.OnusPonPort))
114
115 // count the services
116 services := 0
117 for _, p := range olt.Pons {
118 for _, o := range p.Onus {
119 services = services + len(o.Services)
120 }
121 }
122
123 assert.Equal(t, services, int(common.Config.Olt.PonPorts)*int(common.Config.Olt.OnusPonPort)*len(common.Services))
124
125 s1 := olt.Pons[0].Onus[0].Services[0].(*Service)
126
127 assert.Equal(t, s1.Name, "hsia")
128 assert.Equal(t, s1.CTag, 900)
129 assert.Equal(t, s1.STag, 900)
130 assert.Equal(t, s1.HwAddress.String(), "2e:60:01:00:01:00")
131 assert.Equal(t, olt.Pons[0].Onus[0].ID, uint32(1))
132
133 s2 := olt.Pons[0].Onus[1].Services[0].(*Service)
134 assert.Equal(t, s2.CTag, 901)
135 assert.Equal(t, s2.STag, 900)
136 assert.Equal(t, s2.HwAddress.String(), "2e:60:01:00:02:00")
137 assert.Equal(t, olt.Pons[0].Onus[1].ID, uint32(2))
138
139 s3 := olt.Pons[1].Onus[0].Services[0].(*Service)
140 assert.Equal(t, s3.CTag, 902)
141 assert.Equal(t, s3.STag, 900)
142 assert.Equal(t, s3.HwAddress.String(), "2e:60:01:01:01:00")
143 assert.Equal(t, olt.Pons[1].Onus[0].ID, uint32(1))
144
145 s4 := olt.Pons[1].Onus[1].Services[0].(*Service)
146 assert.Equal(t, s4.CTag, 903)
147 assert.Equal(t, s4.STag, 900)
148 assert.Equal(t, s4.HwAddress.String(), "2e:60:01:01:02:00")
149 assert.Equal(t, olt.Pons[1].Onus[1].ID, uint32(2))
150}
151
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700152func Test_Olt_FindOnuBySn_Success(t *testing.T) {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700153
154 numPon := 4
155 numOnu := 4
156
Matteo Scandolo4a036262020-08-17 15:56:13 -0700157 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700158
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700159 onu, err := olt.FindOnuBySn("BBSM00000303")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700160
161 assert.Equal(t, err, nil)
162 assert.Equal(t, onu.Sn(), "BBSM00000303")
163 assert.Equal(t, onu.ID, uint32(3))
164 assert.Equal(t, onu.PonPortID, uint32(3))
165}
166
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700167func Test_Olt_FindOnuBySn_Error(t *testing.T) {
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700168
169 numPon := 1
170 numOnu := 4
171
Matteo Scandolo4a036262020-08-17 15:56:13 -0700172 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700173
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700174 _, err := olt.FindOnuBySn("BBSM00000303")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700175
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700176 assert.Equal(t, err.Error(), "cannot-find-onu-by-serial-number-BBSM00000303")
177}
178
179func Test_Olt_FindOnuByMacAddress_Success(t *testing.T) {
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700180 numPon := 4
181 numOnu := 4
182
Matteo Scandolo4a036262020-08-17 15:56:13 -0700183 services := []ServiceIf{
184 &Service{Name: "hsia"},
185 &Service{Name: "voip"},
186 &Service{Name: "vod"},
187 }
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700188
Matteo Scandolo4a036262020-08-17 15:56:13 -0700189 olt := createMockOlt(numPon, numOnu, services)
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700190
Matteo Scandolo4a036262020-08-17 15:56:13 -0700191 mac := net.HardwareAddr{0x2e, 0x60, byte(olt.ID), byte(3), byte(6), byte(1)}
192 s, err := olt.FindServiceByMacAddress(mac)
193
194 assert.NilError(t, err)
195
196 service := s.(*Service)
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700197
198 assert.Equal(t, err, nil)
Matteo Scandolo4a036262020-08-17 15:56:13 -0700199 assert.Equal(t, service.Onu.Sn(), "BBSM00000306")
200 assert.Equal(t, service.Onu.ID, uint32(6))
201 assert.Equal(t, service.Onu.PonPortID, uint32(3))
202
203 assert.Equal(t, service.Name, "voip")
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700204}
205
206func Test_Olt_FindOnuByMacAddress_Error(t *testing.T) {
207
208 numPon := 1
209 numOnu := 4
210
Matteo Scandolo4a036262020-08-17 15:56:13 -0700211 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700212
213 mac := net.HardwareAddr{0x2e, 0x60, 0x70, 0x13, byte(3), byte(3)}
214
Matteo Scandolo4a036262020-08-17 15:56:13 -0700215 _, err := olt.FindServiceByMacAddress(mac)
Matteo Scandolof6f3a7f2019-10-11 11:19:29 -0700216
Matteo Scandolo4a036262020-08-17 15:56:13 -0700217 assert.Equal(t, err.Error(), "cannot-find-service-by-mac-address-2e:60:70:13:03:03")
Matteo Scandolo10f965c2019-09-24 10:40:46 -0700218}
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700219
220func Test_Olt_GetOnuByFlowId(t *testing.T) {
221 numPon := 4
222 numOnu := 4
223
Matteo Scandolo4a036262020-08-17 15:56:13 -0700224 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700225
226 // Add the flows to onus (to be found)
227 onu1, _ := olt.FindOnuBySn("BBSM00000303")
228 flow1 := openolt.Flow{
Shrey Baid688b4242020-07-10 20:40:10 +0530229 FlowId: 64,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700230 Classifier: &openolt.Classifier{},
231 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800232 msg1 := types.OnuFlowUpdateMessage{
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700233 OnuID: onu1.ID,
234 PonPortID: onu1.PonPortID,
235 Flow: &flow1,
236 }
237 onu1.handleFlowAdd(msg1)
238
239 onu2, _ := olt.FindOnuBySn("BBSM00000103")
240 flow2 := openolt.Flow{
Shrey Baid688b4242020-07-10 20:40:10 +0530241 FlowId: 72,
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700242 Classifier: &openolt.Classifier{},
243 }
Matteo Scandolof9d43412021-01-12 11:11:34 -0800244 msg2 := types.OnuFlowUpdateMessage{
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700245 OnuID: onu2.ID,
246 PonPortID: onu2.PonPortID,
247 Flow: &flow2,
248 }
249 onu2.handleFlowAdd(msg2)
250
Matteo Scandoloeb6b5af2020-06-24 16:23:58 -0700251 found, err := olt.GetOnuByFlowId(flow1.FlowId)
252
253 assert.Equal(t, err, nil)
254 assert.Equal(t, found.Sn(), onu1.Sn())
Shrey Baid688b4242020-07-10 20:40:10 +0530255}
Matteo Scandolo4b077aa2021-02-16 17:33:37 -0800256
257func Test_Olt_storeGemPortId(t *testing.T) {
258
259 const (
260 pon = 1
261 onu = 1
262 uni = 16
263 gem1 = 1024
264 gem2 = 1025
265 )
266
267 numPon := 2
268 numOnu := 2
269
270 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
271
272 // add a first flow on the ONU
273 flow1 := &openolt.Flow{
274 AccessIntfId: pon,
275 OnuId: onu,
276 PortNo: uni,
277 FlowId: 1,
278 GemportId: gem1,
279 }
280
281 olt.storeGemPortId(flow1)
282 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni]), 1) // we have 1 gem port
283 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni][gem1]), 1) // and one flow referencing it
284
285 // add a second flow on the ONU (same gem)
286 flow2 := &openolt.Flow{
287 AccessIntfId: pon,
288 OnuId: onu,
289 PortNo: uni,
290 FlowId: 2,
291 GemportId: gem1,
292 }
293
294 olt.storeGemPortId(flow2)
295 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni]), 1) // we have 1 gem port
296 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni][gem1]), 2) // and two flows referencing it
297
298 // add a third flow on the ONU (different gem)
299 flow3 := &openolt.Flow{
300 AccessIntfId: pon,
301 OnuId: onu,
302 PortNo: uni,
303 FlowId: 2,
304 GemportId: 1025,
305 }
306
307 olt.storeGemPortId(flow3)
308 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni]), 2) // we have 2 gem ports
309 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni][gem1]), 2) // two flows referencing the first one
310 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni][gem2]), 1) // and one flow referencing the second one
311}
312
313func Test_Olt_freeGemPortId(t *testing.T) {
314 const (
315 pon = 1
316 onu = 1
317 uni = 16
318 gem1 = 1024
319 gem2 = 1025
320 flow1 = 1
321 flow2 = 2
322 flow3 = 3
323 )
324
325 numPon := 2
326 numOnu := 2
327
328 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
329
330 olt.GemPortIDs[pon][onu][uni] = make(map[int32]map[uint64]bool)
331 olt.GemPortIDs[pon][onu][uni][gem1] = make(map[uint64]bool)
332 olt.GemPortIDs[pon][onu][uni][gem1][flow1] = true
333 olt.GemPortIDs[pon][onu][uni][gem1][flow2] = true
334 olt.GemPortIDs[pon][onu][uni][gem2] = make(map[uint64]bool)
335 olt.GemPortIDs[pon][onu][uni][gem2][flow3] = true
336
337 // remove one flow on the first gem, check that the gem is still allocated as there is still a flow referencing it
338 // NOTE that the flow remove only carries the flow ID, no other information
339 flowGem1 := &openolt.Flow{
340 FlowId: flow1,
341 }
342
343 olt.freeGemPortId(flowGem1)
344 // we still have two unis in the map
345 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni]), 2)
346
347 // we should now have a single gem referenced on this UNI
348 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni][gem1]), 1, "gemport-not-removed")
349
350 // the gem should still reference flow 2
351 assert.Equal(t, olt.GemPortIDs[pon][onu][uni][gem1][flow2], true)
352 // but should not reference flow1
353 _, flow1Exists := olt.GemPortIDs[pon][onu][uni][gem1][flow1]
354 assert.Equal(t, flow1Exists, false)
355
356 // this is the only flow remaining on this gem, the gem should be removed
357 flowGem2 := &openolt.Flow{
358 FlowId: flow2,
359 }
360 olt.freeGemPortId(flowGem2)
361
362 // we should now have a single gem referenced on this UNI
363 assert.Equal(t, len(olt.GemPortIDs[pon][onu][uni]), 1, "gemport-not-removed")
364
365 // and it should be gem2
366 _, gem1exists := olt.GemPortIDs[pon][onu][uni][gem1]
367 assert.Equal(t, gem1exists, false)
368 _, gem2exists := olt.GemPortIDs[pon][onu][uni][gem2]
369 assert.Equal(t, gem2exists, true)
370}
371
372func Test_Olt_validateFlow(t *testing.T) {
373
374 const (
375 pon0 = 0
376 pon1 = 1
377 onu0 = 0
378 onu1 = 1
379 uniPort = 0
380 usedGemIdPon0 = 1024
381 usedGemIdPon1 = 1025
382 usedAllocIdPon0 = 1
383 usedAllocIdPon1 = 2
384 flowId = 1
385 )
386
387 numPon := 2
388 numOnu := 2
389
390 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
391
392 olt.GemPortIDs[pon0][onu0][uniPort] = make(map[int32]map[uint64]bool)
393 olt.GemPortIDs[pon1][onu0][uniPort] = make(map[int32]map[uint64]bool)
394
395 olt.GemPortIDs[pon0][onu0][uniPort][usedGemIdPon0] = make(map[uint64]bool)
396 olt.GemPortIDs[pon0][onu0][uniPort][usedGemIdPon0][flowId] = true
397 olt.GemPortIDs[pon1][onu0][uniPort][usedGemIdPon1] = make(map[uint64]bool)
398 olt.GemPortIDs[pon1][onu0][uniPort][usedGemIdPon1][flowId] = true
399
400 olt.AllocIDs[pon0][onu0][uniPort] = make(map[int32]map[uint64]bool)
401 olt.AllocIDs[pon1][onu0][uniPort] = make(map[int32]map[uint64]bool)
402 olt.AllocIDs[pon0][onu0][uniPort][usedAllocIdPon0] = make(map[uint64]bool)
403 olt.AllocIDs[pon0][onu0][uniPort][usedAllocIdPon0][flowId] = true
404 olt.AllocIDs[pon1][onu0][uniPort][usedAllocIdPon1] = make(map[uint64]bool)
405 olt.AllocIDs[pon1][onu0][uniPort][usedAllocIdPon1][flowId] = true
406
407 // a GemPortID can be referenced across multiple flows on the same ONU
408 validGemFlow := &openolt.Flow{
409 AccessIntfId: pon0,
410 OnuId: onu0,
411 GemportId: usedGemIdPon0,
412 }
413
414 err := olt.validateFlow(validGemFlow)
415 assert.NilError(t, err)
416
417 // a GemPortID can NOT be referenced across different ONUs on the same PON
418 invalidGemFlow := &openolt.Flow{
419 AccessIntfId: pon0,
420 OnuId: onu1,
421 GemportId: usedGemIdPon0,
422 }
423 err = olt.validateFlow(invalidGemFlow)
424 assert.Error(t, err, "gem-1024-already-in-use-on-uni-0-onu-0")
425
426 // if a flow reference the same GEM on a different PON it's a valid flow
427 invalidGemDifferentPonFlow := &openolt.Flow{
428 AccessIntfId: pon1,
429 OnuId: onu1,
430 GemportId: usedGemIdPon0,
431 }
432 err = olt.validateFlow(invalidGemDifferentPonFlow)
433 assert.NilError(t, err)
434
435 // an allocId can be referenced across multiple flows on the same ONU
436 validAllocFlow := &openolt.Flow{
437 AccessIntfId: pon0,
438 OnuId: onu0,
439 AllocId: usedAllocIdPon0,
440 }
441 err = olt.validateFlow(validAllocFlow)
442 assert.NilError(t, err)
443
444 // an allocId can NOT be referenced across different ONUs on the same PON
445 invalidAllocFlow := &openolt.Flow{
446 AccessIntfId: pon0,
447 OnuId: onu1,
448 AllocId: usedAllocIdPon0,
449 }
450 err = olt.validateFlow(invalidAllocFlow)
451 assert.Error(t, err, "allocId-1-already-in-use-on-uni-0-onu-0")
452
453 // if a flow reference the same AllocId on a different PON it's a valid flow
454 invalidAllocDifferentPonFlow := &openolt.Flow{
455 AccessIntfId: pon1,
456 OnuId: onu1,
457 AllocId: usedAllocIdPon0,
458 }
459 err = olt.validateFlow(invalidAllocDifferentPonFlow)
460 assert.NilError(t, err)
461}
Matteo Scandolob5913142021-03-19 16:10:18 -0700462
463func Test_Olt_OmciMsgOut(t *testing.T) {
464 numPon := 4
465 numOnu := 4
466
467 olt := createMockOlt(numPon, numOnu, []ServiceIf{})
468
469 // a malformed packet should return an error
470 msg := &openolt.OmciMsg{
471 IntfId: 1,
472 OnuId: 1,
473 Pkt: []byte{},
474 }
475 ctx := context.TODO()
476 _, err := olt.OmciMsgOut(ctx, msg)
477 assert.Error(t, err, "olt-received-malformed-omci-packet")
478
479 // a correct packet for a non exiting ONU should throw an error
480 msg = &openolt.OmciMsg{
481 IntfId: 10,
482 OnuId: 25,
483 Pkt: makeOmciSetRequest(t),
484 }
485 _, err = olt.OmciMsgOut(ctx, msg)
486 assert.Error(t, err, "Cannot find PonPort with id 10 in OLT 0")
487
488 // a correct packet for a disabled ONU should be dropped
489 // note that an error is not returned, this is valid in BBsim
490 const (
491 ponId = 1
492 onuId = 1
493 )
494 pon, _ := olt.GetPonById(ponId)
495 onu, _ := pon.GetOnuById(onuId)
496 onu.InternalState.SetState(OnuStateDisabled)
497 msg = &openolt.OmciMsg{
498 IntfId: ponId,
499 OnuId: onuId,
500 Pkt: makeOmciSetRequest(t),
501 }
502 _, err = olt.OmciMsgOut(ctx, msg)
503 assert.NilError(t, err)
504 assert.Equal(t, len(onu.Channel), 0) // check that no messages have been sent
505
506 // test that the ONU receives a valid packet
507 onu.InternalState.SetState(OnuStateEnabled)
508 _, err = olt.OmciMsgOut(ctx, msg)
509 assert.NilError(t, err)
510 assert.Equal(t, len(onu.Channel), 1) // check that one message have been sent
511
512}