Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package omci |
| 18 | |
| 19 | import ( |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 20 | "testing" |
| 21 | |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 22 | "github.com/opencord/omci-lib-go/v2" |
| 23 | me "github.com/opencord/omci-lib-go/v2/generated" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 24 | "github.com/stretchr/testify/assert" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 25 | ) |
| 26 | |
| 27 | func 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 40 | func 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 | |
| 48 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 57 | func Test_GenerateMibDatabase(t *testing.T) { |
| 58 | const uniPortCount = 4 |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 59 | mibDb, err := GenerateMibDatabase(uniPortCount, 0) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 60 | |
| 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 Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 93 | |
| 94 | func 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 | } |