[VOL-4111] Dinamically generating the MibDB during ONU creation and use
that to drive the MibUploadNextResponse generation
Change-Id: I67dbbe0700a7fbec802516fc6b2a9aff496022de
diff --git a/internal/common/omci/mib_test.go b/internal/common/omci/mib_test.go
index a4ffbb7..139e3e1 100644
--- a/internal/common/omci/mib_test.go
+++ b/internal/common/omci/mib_test.go
@@ -71,27 +71,99 @@
func TestCreateMibUploadNextResponse(t *testing.T) {
+ const uniPortCount = 4
+
+ var (
+ onuDataEntityId = EntityID{0x00, 0x00}
+ onu2gEntityId = EntityID{0x00, 0x00}
+ anigEntityId = EntityID{tcontSlotId, aniGId}
+ )
+
+ // create a fake mibDb, we only need to test that given a CommandSequenceNumber
+ // we return the corresponding entry
+ // the only exception is for OnuData in which we need to replace the MibDataSync attribute with the current value
+ mibDb := MibDb{
+ NumberOfCommands: 4,
+ items: []MibDbEntry{},
+ }
+
+ mibDb.items = append(mibDb.items, MibDbEntry{
+ me.OnuDataClassID,
+ onuDataEntityId,
+ me.AttributeValueMap{"MibDataSync": 0},
+ })
+
+ mibDb.items = append(mibDb.items, MibDbEntry{
+ me.CircuitPackClassID,
+ circuitPackEntityID,
+ me.AttributeValueMap{
+ "Type": ethernetUnitType,
+ "NumberOfPorts": uniPortCount,
+ "SerialNumber": ToOctets("BBSM-Circuit-Pack", 20),
+ "Version": ToOctets("v0.0.1", 20),
+ },
+ })
+
+ mibDb.items = append(mibDb.items, MibDbEntry{
+ me.AniGClassID,
+ anigEntityId,
+ me.AttributeValueMap{
+ "Arc": 0,
+ "ArcInterval": 0,
+ "Deprecated": 0,
+ "GemBlockLength": 48,
+ "LowerOpticalThreshold": 255,
+ "LowerTransmitPowerThreshold": 129,
+ "OnuResponseTime": 0,
+ "OpticalSignalLevel": 57428,
+ "PiggybackDbaReporting": 0,
+ "SignalDegradeThreshold": 9,
+ "SignalFailThreshold": 5,
+ "SrIndication": 1,
+ "TotalTcontNumber": 8,
+ "TransmitOpticalLevel": 3171,
+ "UpperOpticalThreshold": 255,
+ "UpperTransmitPowerThreshold": 129,
+ },
+ })
+
+ mibDb.items = append(mibDb.items, MibDbEntry{
+ me.Onu2GClassID,
+ onu2gEntityId,
+ me.AttributeValueMap{
+ "ConnectivityCapability": 127,
+ "CurrentConnectivityMode": 0,
+ "Deprecated": 1,
+ "PriorityQueueScaleFactor": 1,
+ "QualityOfServiceQosConfigurationFlexibility": 63,
+ "Sysuptime": 0,
+ "TotalGemPortIdNumber": 8,
+ "TotalPriorityQueueNumber": 64,
+ "TotalTrafficSchedulerNumber": 8,
+ },
+ })
+
tests := []struct {
name string
args mibArgs
want mibExpected
}{
{"mibUploadNext-0", createTestMibUploadNextArgs(t, 1, 0),
-
- mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 1, entityID: 0, entityClass: me.OnuDataClassID, attributes: map[string]interface{}{"MibDataSync": MDS}}},
+ mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 1, entityID: onuDataEntityId.ToUint16(), entityClass: me.OnuDataClassID, attributes: map[string]interface{}{"MibDataSync": MDS}}},
{"mibUploadNext-1", createTestMibUploadNextArgs(t, 2, 1),
- mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 2, entityID: 257, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"Type": uint8(47), "NumberOfPorts": uint8(4)}}},
- {"mibUploadNext-4", createTestMibUploadNextArgs(t, 3, 4),
- mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 3, entityID: 257, entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"PowerShedOverride": uint32(0)}}},
- {"mibUploadNext-10", createTestMibUploadNextArgs(t, 4, 10),
- mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 4, entityID: 258, entityClass: me.PhysicalPathTerminationPointEthernetUniClassID, attributes: map[string]interface{}{"SensedType": uint8(47)}}},
+ mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 2, entityID: circuitPackEntityID.ToUint16(), entityClass: me.CircuitPackClassID, attributes: map[string]interface{}{"Type": uint8(47), "NumberOfPorts": uint8(4)}}},
+ {"mibUploadNext-2", createTestMibUploadNextArgs(t, 3, 2),
+ mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 3, entityID: anigEntityId.ToUint16(), entityClass: me.AniGClassID, attributes: map[string]interface{}{"GemBlockLength": uint16(48)}}},
+ {"mibUploadNext-3", createTestMibUploadNextArgs(t, 4, 3),
+ mibExpected{messageType: omci.MibUploadNextResponseType, transactionId: 4, entityID: onuDataEntityId.ToUint16(), entityClass: me.Onu2GClassID, attributes: map[string]interface{}{"TotalPriorityQueueNumber": uint16(64)}}},
}
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)
+ data, err := CreateMibUploadNextResponse(tt.args.omciPkt, tt.args.omciMsg, MDS, &mibDb)
+ assert.NilError(t, err)
omciMsg, omciPkt := omciBytesToMsg(t, data)
assert.Equal(t, omciMsg.MessageType, tt.want.messageType)
@@ -107,65 +179,15 @@
assert.Equal(t, msgObj.ReportedME.GetEntityID(), tt.want.entityID)
for k, v := range tt.want.attributes {
- attr, _ := msgObj.ReportedME.GetAttribute(k)
+ attr, err := msgObj.ReportedME.GetAttribute(k)
+ assert.NilError(t, err)
assert.Equal(t, attr, v)
}
})
}
-}
-type pqueueExpected struct {
- entityId uint16
- relatedPort uint32
-}
-
-func TestGeneratePriorityQueueMe(t *testing.T) {
-
- tests := []struct {
- name string
- sequence uint16
- want pqueueExpected
- }{
- {"generate-pq-downstream-1", 26,
- pqueueExpected{entityId: 1, relatedPort: 16842752}},
- {"generate-pq-downstream-2", 30,
- pqueueExpected{entityId: 2, relatedPort: 16842753}},
- {"generate-pq-downstream-3", 58,
- pqueueExpected{entityId: 9, relatedPort: 16842760}},
- {"generate-pq-upstream-1", 28,
- pqueueExpected{entityId: 32769, relatedPort: 2147549184}},
- {"generate-pq-upstream-2", 32,
- pqueueExpected{entityId: 32770, relatedPort: 2147549185}},
- {"generate-pq-upstream-3", 60,
- pqueueExpected{entityId: 32777, relatedPort: 2147614720}},
- }
-
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- reportedMe, meErr := GeneratePriorityQueueMe(tt.sequence)
- if meErr.GetError() != nil {
- t.Fatal(meErr.Error())
- }
-
- assert.Equal(t, reportedMe.GetEntityID(), tt.want.entityId)
-
- relatedPort, _ := reportedMe.GetAttribute("RelatedPort")
- assert.Equal(t, relatedPort, tt.want.relatedPort)
- })
- }
-
- // test that the related ports are unique
- allRelatedPorts := make(map[uint32]struct{})
- for v := 26; v <= 281; v++ {
- reportedMe, meErr := GeneratePriorityQueueMe(uint16(v))
- if meErr.GetError() != nil {
- t.Fatal(meErr.Error())
- }
- relatedPort, _ := reportedMe.GetAttribute("RelatedPort")
- allRelatedPorts[relatedPort.(uint32)] = struct{}{}
- }
-
- // we report 128 queues total, but each of them is comprised of 2 messages
- // that's why the 256 iterations
- assert.Equal(t, len(allRelatedPorts), 128)
+ // now try to get a non existing command from the DB anche expect an error
+ args := createTestMibUploadNextArgs(t, 1, 20)
+ _, err := CreateMibUploadNextResponse(args.omciPkt, args.omciMsg, MDS, &mibDb)
+ assert.Error(t, err, "mibdb-does-not-contain-item")
}