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 ( |
| 20 | "github.com/opencord/omci-lib-go" |
| 21 | me "github.com/opencord/omci-lib-go/generated" |
| 22 | "github.com/stretchr/testify/assert" |
| 23 | "testing" |
| 24 | ) |
| 25 | |
| 26 | func 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 | |
| 39 | func Test_GenerateMibDatabase(t *testing.T) { |
| 40 | const uniPortCount = 4 |
| 41 | mibDb, err := GenerateMibDatabase(uniPortCount) |
| 42 | |
| 43 | expectedItems := 9 //ONU-G + 2 Circuit Packs (4 messages each) |
| 44 | expectedItems += 2 * uniPortCount // 1 PPTP and 1 UniG per UNI |
| 45 | expectedItems += 1 // ANI-G |
| 46 | expectedItems += 2 * tconts // T-CONT and traffic schedulers |
| 47 | expectedItems += 1 // ONU-2g |
| 48 | expectedItems += 2 * 8 * tconts // 8 upstream queues for each T-CONT, and we report each queue twice |
| 49 | expectedItems += 2 * 16 * uniPortCount // 16 downstream queues for each T-CONT, and we report each queue twice |
| 50 | |
| 51 | assert.NoError(t, err) |
| 52 | assert.NotNil(t, mibDb) |
| 53 | assert.Equal(t, expectedItems, int(mibDb.NumberOfCommands)) |
| 54 | |
| 55 | // now try to serialize all messages to check on the attributes |
| 56 | for _, entry := range mibDb.items { |
| 57 | reportedMe, meErr := me.LoadManagedEntityDefinition(entry.classId, me.ParamData{ |
| 58 | EntityID: entry.entityId.ToUint16(), |
| 59 | Attributes: entry.params, |
| 60 | }) |
| 61 | assert.NoError(t, meErr.GetError()) |
| 62 | |
| 63 | response := &omci.MibUploadNextResponse{ |
| 64 | MeBasePacket: omci.MeBasePacket{ |
| 65 | EntityClass: me.OnuDataClassID, |
| 66 | }, |
| 67 | ReportedME: *reportedMe, |
| 68 | } |
| 69 | |
| 70 | _, err := Serialize(omci.MibUploadNextResponseType, response, uint16(10)) |
| 71 | assert.NoError(t, err) |
| 72 | } |
| 73 | |
| 74 | } |