blob: 2794aa46cf9f4c3ba798547c21b68916ed88b941 [file] [log] [blame]
Matteo Scandoloef4e8f82021-05-17 11:20:49 -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 omci
18
19import (
Elia Battistonac63b112022-01-12 18:40:49 +010020 "testing"
21
Elia Battistonb7bea222022-02-18 16:25:00 +010022 "github.com/opencord/bbsim/internal/common"
Andrea Campanella10426e22021-10-15 17:58:04 +020023 "github.com/opencord/omci-lib-go/v2"
24 me "github.com/opencord/omci-lib-go/v2/generated"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070025 "github.com/stretchr/testify/assert"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070026)
27
28func TestEntityID_ToUint16(t *testing.T) {
29 var id EntityID
30 var res uint16
31
32 id = EntityID{0x01, 0x01}
33 res = id.ToUint16()
34 assert.Equal(t, uint16(257), res)
35
36 id = EntityID{0x00, 0x00}
37 res = id.ToUint16()
38 assert.Equal(t, uint16(0), res)
39}
40
Matteo Scandolo8a574812021-05-20 15:18:53 -070041func TestEntityID_FromUint16(t *testing.T) {
42 id := uint16(257)
43 e := EntityID{}.FromUint16(id)
44
45 assert.Equal(t, e.ToString(), "0101")
46 assert.Equal(t, e.ToUint16(), id)
47}
48
49func TestEntityID_Equals(t *testing.T) {
50 a := EntityID{0x01, 0x01}
51 b := EntityID{0x01, 0x01}
52 c := EntityID{0x01, 0x02}
53
54 assert.True(t, a.Equals(b))
55 assert.False(t, a.Equals(c))
56}
57
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070058func Test_GenerateMibDatabase(t *testing.T) {
59 const uniPortCount = 4
Elia Battistonb7bea222022-02-18 16:25:00 +010060 mibDb, err := GenerateMibDatabase(uniPortCount, 0, common.XGSPON)
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070061
62 expectedItems := 9 //ONU-G + 2 Circuit Packs (4 messages each)
63 expectedItems += 2 * uniPortCount // 1 PPTP and 1 UniG per UNI
64 expectedItems += 1 // ANI-G
65 expectedItems += 2 * tconts // T-CONT and traffic schedulers
66 expectedItems += 1 // ONU-2g
67 expectedItems += 2 * 8 * tconts // 8 upstream queues for each T-CONT, and we report each queue twice
68 expectedItems += 2 * 16 * uniPortCount // 16 downstream queues for each T-CONT, and we report each queue twice
69
70 assert.NoError(t, err)
71 assert.NotNil(t, mibDb)
72 assert.Equal(t, expectedItems, int(mibDb.NumberOfCommands))
73
74 // now try to serialize all messages to check on the attributes
75 for _, entry := range mibDb.items {
76 reportedMe, meErr := me.LoadManagedEntityDefinition(entry.classId, me.ParamData{
77 EntityID: entry.entityId.ToUint16(),
78 Attributes: entry.params,
79 })
80 assert.NoError(t, meErr.GetError())
81
82 response := &omci.MibUploadNextResponse{
83 MeBasePacket: omci.MeBasePacket{
84 EntityClass: me.OnuDataClassID,
85 },
86 ReportedME: *reportedMe,
87 }
88
89 _, err := Serialize(omci.MibUploadNextResponseType, response, uint16(10))
90 assert.NoError(t, err)
91 }
92
93}
Elia Battistonac63b112022-01-12 18:40:49 +010094
95func Test_GenerateMibDatabase_withPots(t *testing.T) {
96 const uniPortCount = 4
97 const potsPortCount = 1
Elia Battistonb7bea222022-02-18 16:25:00 +010098 mibDb, err := GenerateMibDatabase(uniPortCount, potsPortCount, common.XGSPON)
Elia Battistonac63b112022-01-12 18:40:49 +010099
100 expectedItems := 13 //ONU-G + 3 Circuit Packs (4 messages each)
101 expectedItems += 2 * (uniPortCount + potsPortCount) // 1 PPTP and 1 UniG per UNI
102 expectedItems += 1 // ANI-G
103 expectedItems += 2 * tconts // T-CONT and traffic schedulers
104 expectedItems += 1 // ONU-2g
105 expectedItems += 2 * 8 * tconts // 8 upstream queues for each T-CONT, and we report each queue twice
106 expectedItems += 2 * 16 * (uniPortCount + potsPortCount) // 16 downstream queues for each T-CONT, and we report each queue twice
107
108 assert.NoError(t, err)
109 assert.NotNil(t, mibDb)
110 assert.Equal(t, expectedItems, int(mibDb.NumberOfCommands))
111
112 // now try to serialize all messages to check on the attributes
113 for _, entry := range mibDb.items {
114 reportedMe, meErr := me.LoadManagedEntityDefinition(entry.classId, me.ParamData{
115 EntityID: entry.entityId.ToUint16(),
116 Attributes: entry.params,
117 })
118 assert.NoError(t, meErr.GetError())
119
120 response := &omci.MibUploadNextResponse{
121 MeBasePacket: omci.MeBasePacket{
122 EntityClass: me.OnuDataClassID,
123 },
124 ReportedME: *reportedMe,
125 }
126
127 _, err := Serialize(omci.MibUploadNextResponseType, response, uint16(10))
128 assert.NoError(t, err)
129 }
130
131}