blob: aefbae5cd4bd2b73acac29f4853b58484806c78a [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 (
Andrea Campanella10426e22021-10-15 17:58:04 +020020 "github.com/opencord/omci-lib-go/v2"
21 me "github.com/opencord/omci-lib-go/v2/generated"
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070022 "github.com/stretchr/testify/assert"
23 "testing"
24)
25
26func TestEntityID_ToUint16(t *testing.T) {
27 var id EntityID
28 var res uint16
29
30 id = EntityID{0x01, 0x01}
31 res = id.ToUint16()
32 assert.Equal(t, uint16(257), res)
33
34 id = EntityID{0x00, 0x00}
35 res = id.ToUint16()
36 assert.Equal(t, uint16(0), res)
37}
38
Matteo Scandolo8a574812021-05-20 15:18:53 -070039func TestEntityID_FromUint16(t *testing.T) {
40 id := uint16(257)
41 e := EntityID{}.FromUint16(id)
42
43 assert.Equal(t, e.ToString(), "0101")
44 assert.Equal(t, e.ToUint16(), id)
45}
46
47func TestEntityID_Equals(t *testing.T) {
48 a := EntityID{0x01, 0x01}
49 b := EntityID{0x01, 0x01}
50 c := EntityID{0x01, 0x02}
51
52 assert.True(t, a.Equals(b))
53 assert.False(t, a.Equals(c))
54}
55
Matteo Scandoloef4e8f82021-05-17 11:20:49 -070056func Test_GenerateMibDatabase(t *testing.T) {
57 const uniPortCount = 4
58 mibDb, err := GenerateMibDatabase(uniPortCount)
59
60 expectedItems := 9 //ONU-G + 2 Circuit Packs (4 messages each)
61 expectedItems += 2 * uniPortCount // 1 PPTP and 1 UniG per UNI
62 expectedItems += 1 // ANI-G
63 expectedItems += 2 * tconts // T-CONT and traffic schedulers
64 expectedItems += 1 // ONU-2g
65 expectedItems += 2 * 8 * tconts // 8 upstream queues for each T-CONT, and we report each queue twice
66 expectedItems += 2 * 16 * uniPortCount // 16 downstream queues for each T-CONT, and we report each queue twice
67
68 assert.NoError(t, err)
69 assert.NotNil(t, mibDb)
70 assert.Equal(t, expectedItems, int(mibDb.NumberOfCommands))
71
72 // now try to serialize all messages to check on the attributes
73 for _, entry := range mibDb.items {
74 reportedMe, meErr := me.LoadManagedEntityDefinition(entry.classId, me.ParamData{
75 EntityID: entry.entityId.ToUint16(),
76 Attributes: entry.params,
77 })
78 assert.NoError(t, meErr.GetError())
79
80 response := &omci.MibUploadNextResponse{
81 MeBasePacket: omci.MeBasePacket{
82 EntityClass: me.OnuDataClassID,
83 },
84 ReportedME: *reportedMe,
85 }
86
87 _, err := Serialize(omci.MibUploadNextResponseType, response, uint16(10))
88 assert.NoError(t, err)
89 }
90
91}