blob: a55eeebc2088db34939414ed1f0227d5bc477558 [file] [log] [blame]
/*
* Copyright 2018-present Open Networking Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package omci
import (
"github.com/google/gopacket"
"github.com/opencord/omci-lib-go"
me "github.com/opencord/omci-lib-go/generated"
"gotest.tools/assert"
"testing"
)
// used to verify that the first message in the MIB Sync (OnuData)
// reports the correct MDS
const MDS = uint8(128)
func TestCreateMibResetResponse(t *testing.T) {
data, _ := CreateMibResetResponse(1)
omciMsg, omciPkt := omciBytesToMsg(t, data)
assert.Equal(t, omciMsg.MessageType, omci.MibResetResponseType)
msgLayer := (*omciPkt).Layer(omci.LayerTypeMibResetResponse)
msgObj, msgOk := msgLayer.(*omci.MibResetResponse)
if !msgOk {
t.Fail()
}
assert.Equal(t, msgObj.Result, me.Success)
}
// types for TestCreateMibUploadNextResponse test
type mibArgs struct {
omciPkt gopacket.Packet
omciMsg *omci.OMCI
}
type mibExpected struct {
messageType omci.MessageType
transactionId uint16
entityClass me.ClassID
entityID uint16
attributes map[string]interface{}
}
func createTestMibUploadNextArgs(t *testing.T, tid uint16, seqNumber uint16) mibArgs {
mibUploadNext, _ := CreateMibUploadNextRequest(tid, seqNumber)
mibUploadNext = hexDecode(mibUploadNext)
mibUploadNextMsg, mibUploadNextPkt := omciBytesToMsg(t, mibUploadNext)
return mibArgs{
omciPkt: *mibUploadNextPkt,
omciMsg: mibUploadNextMsg,
}
}
func TestCreateMibUploadNextResponse(t *testing.T) {
tests := []struct {
name string
args mibArgs
want mibExpected
}{
{"mibUploadNext-0", createTestMibUploadNextArgs(t, 1, 0),
mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 0, transactionId: 1, entityClass: me.OnuDataClassID, attributes: map[string]interface{}{"MibDataSync": MDS}}},
{"mibUploadNext-1", createTestMibUploadNextArgs(t, 2, 1),
mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 0, transactionId: 2, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"Type": uint8(47), "NumberOfPorts": uint8(4)}}},
{"mibUploadNext-4", createTestMibUploadNextArgs(t, 3, 4),
mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 0, transactionId: 3, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"PowerShedOverride": uint32(0)}}},
{"mibUploadNext-10", createTestMibUploadNextArgs(t, 4, 10),
mibExpected{messageType: omci.MibUploadNextResponseType, entityID: 258, transactionId: 4, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"SensedType": uint8(47)}}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// create the packet starting from the mibUploadNextRequest
data, _ := CreateMibUploadNextResponse(tt.args.omciPkt, tt.args.omciMsg, MDS)
omciMsg, omciPkt := omciBytesToMsg(t, data)
assert.Equal(t, omciMsg.MessageType, tt.want.messageType)
msgLayer := (*omciPkt).Layer(omci.LayerTypeMibUploadNextResponse)
msgObj, msgOk := msgLayer.(*omci.MibUploadNextResponse)
if !msgOk {
t.Fail()
}
assert.Equal(t, omciMsg.TransactionID, tt.want.transactionId) // tid
assert.Equal(t, msgObj.ReportedME.GetEntityID(), tt.want.entityID)
for k, v := range tt.want.attributes {
attr, _ := msgObj.ReportedME.GetAttribute(k)
assert.Equal(t, attr, v)
}
})
}
}