VOL-3551: Decode support for unknown managed entities
Change-Id: I3217bf1df161d9e073046e3c351c7e635ae852f8
diff --git a/VERSION b/VERSION
index 9beb74d..288adf5 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.13.2
+0.13.3
diff --git a/generated/classidmap.go b/generated/classidmap.go
index 7538d66..2fe9ea1 100644
--- a/generated/classidmap.go
+++ b/generated/classidmap.go
@@ -23,8 +23,6 @@
package generated
-import "fmt"
-
// ManagedEntityInfo provides ManagedEntity information
type ManagedEntityInfo struct {
New func(params ...ParamData) (*ManagedEntity, error)
@@ -239,12 +237,13 @@
// LoadManagedEntityDefinition returns a function to create a Managed Entity for a specific
// Managed Entity class ID
func LoadManagedEntityDefinition(classID ClassID, params ...ParamData) (*ManagedEntity, OmciErrors) {
- newFunc, ok := classToManagedEntityMap[classID]
- if ok {
+ if newFunc, ok := classToManagedEntityMap[classID]; ok {
return newFunc(params...)
}
- return nil, NewUnknownEntityError(fmt.Sprintf("managed entity %d (%#x) definition not found",
- uint16(classID), uint16(classID)))
+ if IsVendorSpecificClassID(classID) {
+ return NewUnknownVendorSpecificME(classID, params...)
+ }
+ return NewUnknownG988ME(classID, params...)
}
// GetSupportedClassIDs returns an array of Managed Entity Class IDs supported
@@ -264,3 +263,12 @@
}
return medef.GetAttributeDefinitions(), err
}
+
+// IsVendorSpecificClassID returns true if the provided class ID is reserved in ITU-T G.988
+// for vendor specific functionality
+func IsVendorSpecificClassID(classID ClassID) bool {
+ // Values below are from Table 11.2.4-1 of ITU-T G.988 (11/2017)
+ return (ClassID(240) <= classID && classID <= ClassID(255)) ||
+ (ClassID(350) <= classID && classID <= ClassID(399)) ||
+ (ClassID(65280) <= classID && classID <= ClassID(65535))
+}
\ No newline at end of file
diff --git a/generated/classsupport.go b/generated/classsupport.go
index 5edba61..9cc9dc6 100644
--- a/generated/classsupport.go
+++ b/generated/classsupport.go
@@ -26,6 +26,10 @@
Unsupported // OMCI returns error code if accessed
PartiallySupported // some aspects of ME supported
Ignored // OMCI supported, but underlying function is now
+
+ // The following two are specific unsupported Managed Entity Definitions
+ UnsupportedManagedEntity // Unsupported ITU G.988 Class ID
+ UnsupportedVendorSpecificManagedEntity // Unsupported Vendor Specific Class ID
)
func (cs ClassSupport) String() string {
diff --git a/generated/me.go b/generated/me.go
index 7e51f85..caa32bc 100644
--- a/generated/me.go
+++ b/generated/me.go
@@ -74,6 +74,11 @@
return entity.definition.GetClassID()
}
+// SetClassID assigns the 16-bit class ID of a Managed Entity
+func (entity *ManagedEntity) SetClassID(classID ClassID) {
+ entity.definition.SetClassID(classID)
+}
+
// GetMessageTypes returns the OMCI message types that a Managed Entity supports
func (entity ManagedEntity) GetMessageTypes() mapset.Set {
return entity.definition.GetMessageTypes()
diff --git a/generated/medef.go b/generated/medef.go
index a2bd2da..7cb85d2 100644
--- a/generated/medef.go
+++ b/generated/medef.go
@@ -58,6 +58,11 @@
return bme.ClassID
}
+// SetClassID assigns the 16-bit class ID of a managed entity from a ME Definition
+func (bme *ManagedEntityDefinition) SetClassID(classID ClassID) {
+ bme.ClassID = classID
+}
+
// GetMessageTypes retrieves the OMCI Message Types supporte3d by a managed entity from a ME Definition
func (bme ManagedEntityDefinition) GetMessageTypes() mapset.Set {
return bme.MessageTypes
diff --git a/generated/unknowng988me.go b/generated/unknowng988me.go
new file mode 100644
index 0000000..af68823
--- /dev/null
+++ b/generated/unknowng988me.go
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
+ * Copyright 2020-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.
+ */
+/*
+ * NOTE: This file was generated, manual edits will be overwritten!
+ *
+ * Generated by 'goCodeGenerator.py':
+ * https://github.com/cboling/OMCI-parser/README.md
+ */
+
+package generated
+
+import "github.com/deckarep/golang-set"
+
+
+var unknownG988BME *ManagedEntityDefinition
+
+type UnknownG988ME struct {
+ ManagedEntityDefinition
+ Attributes AttributeValueMap
+}
+
+func init() {
+ unknownG988BME = &ManagedEntityDefinition{
+ Name: "UnknownItuG988ManagedEntity",
+ ClassID: 0,
+ MessageTypes: mapset.NewSetWith(
+ MibUploadNext,
+ AlarmNotification,
+ AttributeValueChange,
+ ),
+ AllowedAttributeMask: 0xffff,
+ AttributeDefinitions: AttributeDefinitionMap{
+ 0: Uint16Field("ManagedEntityId", PointerAttributeType, 0x0000, 0, mapset.NewSetWith(Read), false, false, false, 0),
+ 1: MultiByteField("UnknownAttr_1", OctetsAttributeType, 0x8000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 1),
+ 2: MultiByteField("UnknownAttr_2", OctetsAttributeType, 0x4000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 2),
+ 3: MultiByteField("UnknownAttr_3", OctetsAttributeType, 0x2000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 3),
+ 4: MultiByteField("UnknownAttr_4", OctetsAttributeType, 0x1000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 4),
+ 5: MultiByteField("UnknownAttr_5", OctetsAttributeType, 0x0800, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 5),
+ 6: MultiByteField("UnknownAttr_6", OctetsAttributeType, 0x0400, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 6),
+ 7: MultiByteField("UnknownAttr_7", OctetsAttributeType, 0x0200, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 7),
+ 8: MultiByteField("UnknownAttr_8", OctetsAttributeType, 0x0100, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 8),
+ 9: MultiByteField("UnknownAttr_9", OctetsAttributeType, 0x0080, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 9),
+ 10: MultiByteField("UnknownAttr_10", OctetsAttributeType, 0x0040, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 10),
+ 11: MultiByteField("UnknownAttr_11", OctetsAttributeType, 0x0020, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 11),
+ 12: MultiByteField("UnknownAttr_12", OctetsAttributeType, 0x0010, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 12),
+ 13: MultiByteField("UnknownAttr_13", OctetsAttributeType, 0x0008, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 13),
+ 14: MultiByteField("UnknownAttr_14", OctetsAttributeType, 0x0004, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 14),
+ 15: MultiByteField("UnknownAttr_15", OctetsAttributeType, 0x0002, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 15),
+ 16: MultiByteField("UnknownAttr_16", OctetsAttributeType, 0x0001, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 16),
+ },
+ Access: UnknownAccess,
+ Support: UnsupportedManagedEntity,
+ }
+}
+
+func NewUnknownG988ME(classID ClassID, params ...ParamData) (*ManagedEntity, OmciErrors) {
+ return newUnknownManagedEntity(classID, *unknownG988BME, params...)
+}
+
+// newUnknownManagedEntity creates a ManagedEntity given an ME Definition and parameter/attribute data
+// much like NewManagedEntity but treats attributes is a special way
+func newUnknownManagedEntity(classID ClassID, definition ManagedEntityDefinition, params ...ParamData) (*ManagedEntity, OmciErrors) {
+ entity := &ManagedEntity{
+ definition: definition,
+ attributes: make(map[string]interface{}),
+ }
+ // Make this unique for the received class ID and attribute masks
+ entity.SetClassID(classID)
+
+ if params != nil {
+ if err := entity.setAttributes(params...); err.StatusCode() != Success {
+ return nil, err
+ }
+ }
+ return entity, NewOmciSuccess()
+}
diff --git a/generated/unknownvendorspecificme.go b/generated/unknownvendorspecificme.go
new file mode 100644
index 0000000..146e012
--- /dev/null
+++ b/generated/unknownvendorspecificme.go
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2018 - present. Boling Consulting Solutions (bcsw.net)
+ * Copyright 2020-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.
+ */
+ /*
+ * NOTE: This file was generated, manual edits will be overwritten!
+ *
+ * Generated by 'goCodeGenerator.py':
+ * https://github.com/cboling/OMCI-parser/README.md
+ */
+
+package generated
+
+import "github.com/deckarep/golang-set"
+
+
+var unknownVendorSpecificBME *ManagedEntityDefinition
+
+type UnknownVendorSpecific struct {
+ ManagedEntityDefinition
+ Attributes AttributeValueMap
+}
+
+func init() {
+ unknownVendorSpecificBME = &ManagedEntityDefinition{
+ Name: "UnknownVendorSpecificManagedEntity",
+ ClassID: 0,
+ MessageTypes: mapset.NewSetWith(
+ MibUploadNext,
+ AlarmNotification,
+ AttributeValueChange,
+ ),
+ AllowedAttributeMask: 0xffff,
+ AttributeDefinitions: AttributeDefinitionMap{
+ 0: Uint16Field("ManagedEntityId", PointerAttributeType, 0x0000, 0, mapset.NewSetWith(Read), false, false, false, 0),
+ 1: MultiByteField("UnknownAttr_1", OctetsAttributeType, 0x8000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 1),
+ 2: MultiByteField("UnknownAttr_2", OctetsAttributeType, 0x4000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 2),
+ 3: MultiByteField("UnknownAttr_3", OctetsAttributeType, 0x2000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 3),
+ 4: MultiByteField("UnknownAttr_4", OctetsAttributeType, 0x1000, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 4),
+ 5: MultiByteField("UnknownAttr_5", OctetsAttributeType, 0x0800, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 5),
+ 6: MultiByteField("UnknownAttr_6", OctetsAttributeType, 0x0400, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 6),
+ 7: MultiByteField("UnknownAttr_7", OctetsAttributeType, 0x0200, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 7),
+ 8: MultiByteField("UnknownAttr_8", OctetsAttributeType, 0x0100, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 8),
+ 9: MultiByteField("UnknownAttr_9", OctetsAttributeType, 0x0080, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 9),
+ 10: MultiByteField("UnknownAttr_10", OctetsAttributeType, 0x0040, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 10),
+ 11: MultiByteField("UnknownAttr_11", OctetsAttributeType, 0x0020, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 11),
+ 12: MultiByteField("UnknownAttr_12", OctetsAttributeType, 0x0010, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 12),
+ 13: MultiByteField("UnknownAttr_13", OctetsAttributeType, 0x0008, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 13),
+ 14: MultiByteField("UnknownAttr_14", OctetsAttributeType, 0x0004, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 14),
+ 15: MultiByteField("UnknownAttr_15", OctetsAttributeType, 0x0002, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 15),
+ 16: MultiByteField("UnknownAttr_16", OctetsAttributeType, 0x0001, 1, toOctets("AA=="), mapset.NewSetWith(Read), true, true, false, 16),
+ },
+ Access: UnknownAccess,
+ Support: UnsupportedVendorSpecificManagedEntity,
+ }
+}
+
+func NewUnknownVendorSpecificME(classID ClassID, params ...ParamData) (*ManagedEntity, OmciErrors) {
+ return newUnknownManagedEntity(classID, *unknownVendorSpecificBME, params...)
+}
diff --git a/omci_test.go b/omci_test.go
index 1a8105c..12575d7 100644
--- a/omci_test.go
+++ b/omci_test.go
@@ -1079,3 +1079,170 @@
// firstTid += 1
// }
//}
+
+// TestUnsupportedG988ClassIDMibUploadNextResponse tests decoding of an Unknown class ID that is
+// in the range of IDs assigned for G.988 use
+func TestUnsupportedG988ClassIDMibUploadNextResponse(t *testing.T) {
+ // The unsupported G.988 class ID below is 37 (0x0025), which is marked in the G.988
+ // (11/2017) as 'Intentionally left blank). The encoded frame is a Get-Next
+ // response with a single attribute 1 & 16 (0x8001) encoded.
+ //
+ tid := 3
+ cid := 0x25
+ eid := 1
+ mask := 0x8000
+ hdr := "00032e0a00020000002500018000"
+ trailer := "0000002828ce00e2"
+ attr := "0102030405060708090A0B0C0D0E0F101112131415161718191A"
+ msg := hdr + attr + trailer
+ data, err := stringToPacket(msg)
+ assert.NoError(t, err)
+
+ packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+ assert.NotNil(t, packet)
+
+ omciLayer := packet.Layer(LayerTypeOMCI)
+ assert.NotNil(t, packet)
+
+ omciMsg, ok := omciLayer.(*OMCI)
+ assert.True(t, ok)
+ assert.Equal(t, omciMsg.TransactionID, uint16(tid))
+ assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
+ assert.Equal(t, omciMsg.Length, uint16(40))
+
+ msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
+ assert.NotNil(t, msgLayer)
+
+ uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
+ assert.True(t, ok2)
+ assert.NotNil(t, uploadResponse)
+ assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
+ assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
+ assert.Equal(t, uploadResponse.ReportedME.GetClassID(), ClassID(cid))
+ assert.Equal(t, uploadResponse.ReportedME.GetEntityID(), uint16(eid))
+ assert.Equal(t, uploadResponse.ReportedME.GetAttributeMask(), uint16(mask))
+
+ name := "UnknownAttr_1"
+ blobAttribute, err := uploadResponse.ReportedME.GetAttribute(name)
+
+ assert.Nil(t, err)
+ assert.NotNil(t, blobAttribute)
+
+ byteValue, ok3 := blobAttribute.([]uint8)
+ assert.True(t, ok3)
+ assert.NotNil(t, byteValue)
+}
+
+
+func TestUnsupportedG988ClassIDMibUploadNextResponseAttributes(t *testing.T) {
+ // Same as previous, but try different attribute mask combinations
+ tid := 3
+ cid := 0x25
+ eid := 1
+
+ // There are a number of ranges for vendor ID use. List below picks one from
+ // each of those ranges
+ masks := []uint16{0x8001, 0x0000, 0x0001, 0x8000}
+
+ trailer := "0000002828ce00e2"
+ attr := "0102030405060708090A0B0C0D0E0F101112131415161718191A"
+
+ for _, mask := range masks {
+ hdr := fmt.Sprintf("00032e0a0002000000250001%04x", mask)
+
+ msg := hdr + attr + trailer
+ data, err := stringToPacket(msg)
+ assert.NoError(t, err)
+
+ packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+ assert.NotNil(t, packet)
+
+ omciLayer := packet.Layer(LayerTypeOMCI)
+ assert.NotNil(t, packet)
+
+ omciMsg, ok := omciLayer.(*OMCI)
+ assert.True(t, ok)
+ assert.Equal(t, omciMsg.TransactionID, uint16(tid))
+ assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
+ assert.Equal(t, omciMsg.Length, uint16(40))
+
+ msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
+ assert.NotNil(t, msgLayer)
+
+ uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
+ assert.True(t, ok2)
+ assert.NotNil(t, uploadResponse)
+ assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
+ assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
+ assert.Equal(t, uploadResponse.ReportedME.GetClassID(), ClassID(cid))
+ assert.Equal(t, uploadResponse.ReportedME.GetEntityID(), uint16(eid))
+ assert.Equal(t, uploadResponse.ReportedME.GetAttributeMask(), uint16(mask))
+
+ //name := "UnknownAttr_1"
+ //blobAttribute, err := uploadResponse.ReportedME.GetAttribute(name)
+ //
+ //assert.Nil(t, err)
+ //assert.NotNil(t, blobAttribute)
+ //
+ //byteValue, ok3 := blobAttribute.([]uint8)
+ //assert.True(t, ok3)
+ //assert.NotNil(t, byteValue)
+ }
+}
+
+// TestUnsupportedVendorClassIDMibUploadNextResponse tests decoding of an Unknown class ID that is
+// in the range of IDs assigned for vendor assignment
+func TestUnsupportedVendorClassIDMibUploadNextResponse(t *testing.T) {
+ tid := 3
+ eid := 0
+ mask := 0x8000
+
+ // There are a number of ranges for vendor ID use. List below picks one from
+ // each of those ranges
+ classIDs := []uint16{250, 355, 65500}
+
+ hdr := "00032e0a00020000"
+ attr := "0102030405060708090A0B0C0D0E0F101112131415161718191A"
+ trailer := "0000002828ce00e2"
+
+ for _, cid := range classIDs {
+ cidToMask := fmt.Sprintf("%04x%04x%04x", cid, eid, mask)
+ msg := hdr + cidToMask + attr + trailer
+ data, err := stringToPacket(msg)
+ assert.NoError(t, err)
+
+ packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+ assert.NotNil(t, packet)
+
+ omciLayer := packet.Layer(LayerTypeOMCI)
+ assert.NotNil(t, packet)
+
+ omciMsg, ok := omciLayer.(*OMCI)
+ assert.True(t, ok)
+ assert.Equal(t, omciMsg.TransactionID, uint16(tid))
+ assert.Equal(t, omciMsg.MessageType, MibUploadNextResponseType)
+ assert.Equal(t, omciMsg.Length, uint16(40))
+
+ msgLayer := packet.Layer(LayerTypeMibUploadNextResponse)
+ assert.NotNil(t, msgLayer)
+
+ uploadResponse, ok2 := msgLayer.(*MibUploadNextResponse)
+ assert.True(t, ok2)
+ assert.NotNil(t, uploadResponse)
+ assert.Equal(t, uploadResponse.EntityClass, OnuDataClassID)
+ assert.Equal(t, uploadResponse.EntityInstance, uint16(0))
+ assert.Equal(t, uploadResponse.ReportedME.GetClassID(), ClassID(cid))
+ assert.Equal(t, uploadResponse.ReportedME.GetEntityID(), uint16(eid))
+ assert.Equal(t, uploadResponse.ReportedME.GetAttributeMask(), uint16(mask))
+
+ name := "UnknownAttr_1"
+ blobAttribute, err := uploadResponse.ReportedME.GetAttribute(name)
+
+ assert.Nil(t, err)
+ assert.NotNil(t, blobAttribute)
+
+ byteValue, ok3 := blobAttribute.([]uint8)
+ assert.True(t, ok3)
+ assert.NotNil(t, byteValue)
+ }
+}
\ No newline at end of file