blob: a55eeebc2088db34939414ed1f0227d5bc477558 [file] [log] [blame]
Matteo Scandolof9d43412021-01-12 11:11:34 -08001/*
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 (
Matteo Scandolof9d43412021-01-12 11:11:34 -080020 "github.com/google/gopacket"
21 "github.com/opencord/omci-lib-go"
22 me "github.com/opencord/omci-lib-go/generated"
23 "gotest.tools/assert"
24 "testing"
25)
26
Matteo Scandolo992a23e2021-02-04 15:35:04 -080027// used to verify that the first message in the MIB Sync (OnuData)
28// reports the correct MDS
29const MDS = uint8(128)
30
Matteo Scandolof9d43412021-01-12 11:11:34 -080031func TestCreateMibResetResponse(t *testing.T) {
32 data, _ := CreateMibResetResponse(1)
33
34 omciMsg, omciPkt := omciBytesToMsg(t, data)
35
36 assert.Equal(t, omciMsg.MessageType, omci.MibResetResponseType)
37
38 msgLayer := (*omciPkt).Layer(omci.LayerTypeMibResetResponse)
39 msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
40 if !msgOk {
41 t.Fail()
42 }
43
44 assert.Equal(t, msgObj.Result, me.Success)
45}
46
47// types for TestCreateMibUploadNextResponse test
48type mibArgs struct {
49 omciPkt gopacket.Packet
50 omciMsg *omci.OMCI
51}
52
53type mibExpected struct {
54 messageType omci.MessageType
55 transactionId uint16
56 entityClass me.ClassID
Matteo Scandolo992a23e2021-02-04 15:35:04 -080057 entityID uint16
Matteo Scandolof9d43412021-01-12 11:11:34 -080058 attributes map[string]interface{}
59}
60
61func createTestMibUploadNextArgs(t *testing.T, tid uint16, seqNumber uint16) mibArgs {
62 mibUploadNext, _ := CreateMibUploadNextRequest(tid, seqNumber)
63 mibUploadNext = hexDecode(mibUploadNext)
64 mibUploadNextMsg, mibUploadNextPkt := omciBytesToMsg(t, mibUploadNext)
65
66 return mibArgs{
67 omciPkt: *mibUploadNextPkt,
68 omciMsg: mibUploadNextMsg,
69 }
70}
71
72func TestCreateMibUploadNextResponse(t *testing.T) {
73
74 tests := []struct {
75 name string
76 args mibArgs
77 want mibExpected
78 }{
79 {"mibUploadNext-0", createTestMibUploadNextArgs(t, 1, 0),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080080 mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 0, transactionId: 1, entityClass: me.OnuDataClassID, attributes: map[string]interface{}{"MibDataSync": MDS}}},
Matteo Scandolof9d43412021-01-12 11:11:34 -080081 {"mibUploadNext-1", createTestMibUploadNextArgs(t, 2, 1),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080082 mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 0, transactionId: 2, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"Type": uint8(47), "NumberOfPorts": uint8(4)}}},
Matteo Scandolof9d43412021-01-12 11:11:34 -080083 {"mibUploadNext-4", createTestMibUploadNextArgs(t, 3, 4),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080084 mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 0, transactionId: 3, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"PowerShedOverride": uint32(0)}}},
Matteo Scandolof9d43412021-01-12 11:11:34 -080085 {"mibUploadNext-10", createTestMibUploadNextArgs(t, 4, 10),
Matteo Scandolo992a23e2021-02-04 15:35:04 -080086 mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 258, transactionId: 4, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"SensedType": uint8(47)}}},
Matteo Scandolof9d43412021-01-12 11:11:34 -080087 }
88
89 for _, tt := range tests {
90 t.Run(tt.name, func(t *testing.T) {
91
92 // create the packet starting from the mibUploadNextRequest
Matteo Scandolo992a23e2021-02-04 15:35:04 -080093 data, _ := CreateMibUploadNextResponse(tt.args.omciPkt, tt.args.omciMsg, MDS)
Matteo Scandolof9d43412021-01-12 11:11:34 -080094 omciMsg, omciPkt := omciBytesToMsg(t, data)
95
96 assert.Equal(t, omciMsg.MessageType, tt.want.messageType)
97
98 msgLayer := (*omciPkt).Layer(omci.LayerTypeMibUploadNextResponse)
99 msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
100 if !msgOk {
101 t.Fail()
102 }
103
104 assert.Equal(t, omciMsg.TransactionID, tt.want.transactionId) // tid
Matteo Scandolof9d43412021-01-12 11:11:34 -0800105
Matteo Scandolo992a23e2021-02-04 15:35:04 -0800106 assert.Equal(t, msgObj.ReportedME.GetEntityID(), tt.want.entityID)
Matteo Scandolof9d43412021-01-12 11:11:34 -0800107
108 for k, v := range tt.want.attributes {
109 attr, _ := msgObj.ReportedME.GetAttribute(k)
110 assert.Equal(t, attr, v)
111 }
112 })
113 }
114
115}