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