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 | |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame^] | 22 | "github.com/opencord/bbsim/internal/common" |
Andrea Campanella | 10426e2 | 2021-10-15 17:58:04 +0200 | [diff] [blame] | 23 | "github.com/opencord/omci-lib-go/v2" |
| 24 | me "github.com/opencord/omci-lib-go/v2/generated" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 25 | "github.com/stretchr/testify/assert" |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func 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 Scandolo | 8a57481 | 2021-05-20 15:18:53 -0700 | [diff] [blame] | 41 | func 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 | |
| 49 | func 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 Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 58 | func Test_GenerateMibDatabase(t *testing.T) { |
| 59 | const uniPortCount = 4 |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame^] | 60 | mibDb, err := GenerateMibDatabase(uniPortCount, 0, common.XGSPON) |
Matteo Scandolo | ef4e8f8 | 2021-05-17 11:20:49 -0700 | [diff] [blame] | 61 | |
| 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 Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 94 | |
| 95 | func Test_GenerateMibDatabase_withPots(t *testing.T) { |
| 96 | const uniPortCount = 4 |
| 97 | const potsPortCount = 1 |
Elia Battiston | b7bea22 | 2022-02-18 16:25:00 +0100 | [diff] [blame^] | 98 | mibDb, err := GenerateMibDatabase(uniPortCount, potsPortCount, common.XGSPON) |
Elia Battiston | ac63b11 | 2022-01-12 18:40:49 +0100 | [diff] [blame] | 99 | |
| 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 | } |