VOL-4028: Support ANI-G test message at openonu-go adapter
Change-Id: Ibcdcf67e3f80fc30d673c1d8cc657bff654e9ee6
diff --git a/vendor/github.com/opencord/omci-lib-go/README.md b/vendor/github.com/opencord/omci-lib-go/README.md
index fa5499f..959990a 100644
--- a/vendor/github.com/opencord/omci-lib-go/README.md
+++ b/vendor/github.com/opencord/omci-lib-go/README.md
@@ -1,7 +1,8 @@
# OMCI
OMCI gopacket library supports the encoding and decoding of ITU G.988 OMCI
-messages.
+messages. Support for the Baseline Message Set has been completed and work
+is underway to support the Extended Message Set format.
## Message Types supported and under unit test
The following OMCI message types currently have been coded and are covered
@@ -22,6 +23,13 @@
- MibResetRequest
- MibResetResponse
- SynchronizeTimeRequest
+ - DownloadSectionRequest
+ - DownloadSectionResponse
+ - EndSoftwareDownloadRequest
+ - EndSoftwareDownloadResponse
+ - CommitSoftwareRequest
+ - CommitSoftwareResponse
+ - AlarmNotification
## Message Types supported but lacking full unit test
The following OMCI message types currently have been coded and are partially covered
@@ -38,46 +46,80 @@
- StartSoftwareDownloadRequest
- GetNextRequest
- GetNextResponse
+ - TestResult
+ - TestRequest
+ - TestResponse
## Message Types supported but lacking any unit test
The following OMCI message types currently have been coded but do not
have any unit test coverage.
- StartSoftwareDownloadResponse
- - DownloadSectionRequest
- - DownloadSectionResponse
- - EndSoftwareDownloadRequest
- - EndSoftwareDownloadResponse
- ActivateSoftwareRequest
- ActivateSoftwareResponse
- - CommitSoftwareRequest
- - CommitSoftwareResponse
- GetCurrentDataRequest
- GetCurrentDataResponse
- - AlarmNotification
## Message Types not yet supported
The following OMCI message types currently have not been coded.
- - TestResult
- - TestRequest
- - TestResponse
- SetTableRequest
- SetTableResponse
+## Extended Message Set Support
+
+As mentioned earlier, support for the Extended Message Set is underway. Currently,
+the following Message Types have this support and are covered by unit tests:
+
+ - GetRequest
+ - GetResponse
+
+### Upcoming message types that will be supported
+
+The following provides a list of message types that will eventually support the _Extended Message Set_
+in the expected order of implementation. The priority was chosen based on speed improvement requests
+of operations and ease of implementation.
+
+ - DownloadSectionRequest/Response
+ - AlarmNotification
+ - AttributeValueChange
+ - TestResult
+
+ - GetCurrentDataRequest/Response
+ - MibResetRequest/Response
+ - RebootRequest/Response
+ - SynchronizeTimeRequest/Response
+ - CreateRequest/Response
+ - DeleteRequest/Response
+ - SetRequest/Response
+
+ - MibUploadRequest/Response
+ - MibUploadNextRequest/Response
+ - GetAllAlarmsRequest/Response
+ - GetAllAlarmsNextRequest/Response
+ - GetNextRequest/Response
+
+ - StartSoftwareDownloadRequest/Response
+ - EndSoftwareDownloadRequest/Response
+ - CommitSoftwareRequest/Response
+ - ActivateSoftwareRequest/Response
+
+ - SetTableRequest/Response
+ - TestRequest/Response
+
## Current user-test coverage
-The _coverage.sh_ and _coverage.cmd_ scripts can be used to create code coverage support for the
-library. The current coverage (as of 2/11/2020) is:
+The _**make** test_ command can be used to create code coverage support for the
+library. The current coverage for version 1.0.0 (as of 4/21/2021) is:
| File | Statement Coverage |
| --------------: | :---: |
| layers.go | 100% |
-| mebase.go | 87.5% |
-| meframe.go | 54.8% |
-| messagetypes.go | 48.1% |
-| omci.go | 81.6% |
+| mebase.go | 91.7% |
+| meframe.go | 50.8% |
+| messagetypes.go | 59.1% |
+| omci.go | 79.0% |
## Other outstanding items
@@ -85,26 +127,12 @@
would be needed or useful in a first official release of this library. Some changes are
to be done in the generated OMCI ME code as well.
- - Specific examples of how to use this library (expand upon DecodeEncode.go examples)
- Include unknown ME examples and how to catch various common or expected errors. Until
- this is available, please take a look at how this library is used in my
- [onumock](https://github.com/cboling/onumock/README.md). There is a utilities subdirectory
- in the _onumock_ project that has some examples. One is a **very** crude OLT simulator that
- I wrote to help test the ONU Mock.
- - Support optional msg-types. (This was very recently fixed in the code generator).
- Constraint checking (these are not yet fully parsed/provided by the OMCI code generated
structs). This feature will hopefully be available in the near future.
- - Add Alarm Table Support (generated MEs also)
- Add AVC flag for appropriate attributes
- - Support of the extended message format
- - For serialization, check early for message size exceeded
- Add some type of logging support
-The following would be 'nice' to have but are not necessary for initial code release
- - Extended message support
- - MIC Encode/Decode support
-
-Also searching through the code for _TODO_ statements will also yeild additional areas of
+Also searching through the code for _TODO_ statements will also yield additional areas of
work to be performed.
## What is not provided by this library
@@ -114,7 +142,7 @@
the creation of OMCI frames and handling decoded frames from the PON.
For an OLT-side OMCI stack, you would still need to write:
- - OMCI CC sender & receiver with appropriate timeout support
+ - OMCI CC sender & receiver (stop & wait protocol) with appropriate timeout support
- OLT State machines to support
- MIB Uploads/Audits/Resynchronization (and a MIB database implemention),
- More sophisticated get & get-next support to make handle of MEs with
@@ -123,7 +151,7 @@
- OMCI ME/Msg-Type capabilities inquiry,
- Performance Monitoring collection (and initial time synchronization),
- Service implementation
-
+
For an ONU-side OMCI stack, you would still need to write:
- OMCC implementation,
- MIB Database,
diff --git a/vendor/github.com/opencord/omci-lib-go/VERSION b/vendor/github.com/opencord/omci-lib-go/VERSION
index c5523bd..9084fa2 100644
--- a/vendor/github.com/opencord/omci-lib-go/VERSION
+++ b/vendor/github.com/opencord/omci-lib-go/VERSION
@@ -1 +1 @@
-0.17.0
+1.1.0
diff --git a/vendor/github.com/opencord/omci-lib-go/generated/medef.go b/vendor/github.com/opencord/omci-lib-go/generated/medef.go
index 767e27b..4e91db6 100644
--- a/vendor/github.com/opencord/omci-lib-go/generated/medef.go
+++ b/vendor/github.com/opencord/omci-lib-go/generated/medef.go
@@ -141,7 +141,7 @@
data = data[len(valueBuffer):]
case byte(Set) | AR: // Set Request
- fmt.Println("TODO")
+ // TODO: No support at this time
case byte(SetTable) | AR: // Set Table Request
// TODO: Only baseline supported at this time
diff --git a/vendor/github.com/opencord/omci-lib-go/generated/omcidefs.go b/vendor/github.com/opencord/omci-lib-go/generated/omcidefs.go
index 8924e7d..5e845ff2 100644
--- a/vendor/github.com/opencord/omci-lib-go/generated/omcidefs.go
+++ b/vendor/github.com/opencord/omci-lib-go/generated/omcidefs.go
@@ -105,6 +105,7 @@
TestResult MsgType = 27
GetCurrentData MsgType = 28
SetTable MsgType = 29 // Defined in Extended Message Set Only
+ ExtendedOffset MsgType = 0x80
)
func (mt MsgType) String() string {
diff --git a/vendor/github.com/opencord/omci-lib-go/layers.go b/vendor/github.com/opencord/omci-lib-go/layers.go
index 1bac6b3..aa49e8c 100644
--- a/vendor/github.com/opencord/omci-lib-go/layers.go
+++ b/vendor/github.com/opencord/omci-lib-go/layers.go
@@ -26,6 +26,7 @@
var nextLayerMapping map[MessageType]gopacket.LayerType
var (
+ // Baseline Message Types
LayerTypeCreateRequest gopacket.LayerType
LayerTypeDeleteRequest gopacket.LayerType
LayerTypeSetRequest gopacket.LayerType
@@ -47,8 +48,12 @@
LayerTypeGetNextRequest gopacket.LayerType
LayerTypeGetCurrentDataRequest gopacket.LayerType
LayerTypeSetTableRequest gopacket.LayerType
+
+ // Extended Message Types
+ LayerTypeGetRequestExtended gopacket.LayerType
)
var (
+ // Baseline Message Types
LayerTypeCreateResponse gopacket.LayerType
LayerTypeDeleteResponse gopacket.LayerType
LayerTypeSetResponse gopacket.LayerType
@@ -72,6 +77,9 @@
LayerTypeTestResult gopacket.LayerType
LayerTypeGetCurrentDataResponse gopacket.LayerType
LayerTypeSetTableResponse gopacket.LayerType
+
+ // Extended Message Types
+ LayerTypeGetResponseExtended gopacket.LayerType
)
func mkReqLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
@@ -139,6 +147,11 @@
LayerTypeGetCurrentDataResponse = mkRespLayer(me.GetCurrentData, "GetCurrentDataResponse", gopacket.DecodeFunc(decodeGetCurrentDataResponse))
LayerTypeSetTableResponse = mkRespLayer(me.SetTable, "SetTableResponse", gopacket.DecodeFunc(decodeSetTableResponse))
+ // Extended message set support
+
+ LayerTypeGetRequestExtended = mkReqLayer(me.Get|me.ExtendedOffset, "GetRequest-Ext", gopacket.DecodeFunc(decodeGetRequestExtended))
+ LayerTypeGetResponseExtended = mkRespLayer(me.Get|me.ExtendedOffset, "GetResponse-Ext", gopacket.DecodeFunc(decodeGetResponseExtended))
+
// Map message_type and action to layer
nextLayerMapping = make(map[MessageType]gopacket.LayerType)
@@ -188,12 +201,19 @@
nextLayerMapping[AttributeValueChangeType] = LayerTypeAttributeValueChange
nextLayerMapping[AlarmNotificationType] = LayerTypeAlarmNotification
nextLayerMapping[TestResultType] = LayerTypeTestResult
+
+ // Extended message support
+ nextLayerMapping[GetRequestType+ExtendedTypeDecodeOffset] = LayerTypeGetRequestExtended
+ nextLayerMapping[GetResponseType+ExtendedTypeDecodeOffset] = LayerTypeGetResponseExtended
}
-func MsgTypeToNextLayer(mt MessageType) (gopacket.LayerType, error) {
+func MsgTypeToNextLayer(mt MessageType, isExtended bool) (gopacket.LayerType, error) {
+ if isExtended {
+ mt |= ExtendedTypeDecodeOffset
+ }
nextLayer, ok := nextLayerMapping[mt]
if ok {
return nextLayer, nil
}
- return gopacket.LayerTypeZero, errors.New("unknown message type")
+ return gopacket.LayerTypeZero, errors.New("unknown/unsupported message type")
}
diff --git a/vendor/github.com/opencord/omci-lib-go/mebase.go b/vendor/github.com/opencord/omci-lib-go/mebase.go
index 955e610..41f7a1f 100644
--- a/vendor/github.com/opencord/omci-lib-go/mebase.go
+++ b/vendor/github.com/opencord/omci-lib-go/mebase.go
@@ -32,6 +32,7 @@
gopacket.Layer
layers.BaseLayer
MsgLayerType gopacket.LayerType
+ Extended bool
}
func (msg *MeBasePacket) String() string {
diff --git a/vendor/github.com/opencord/omci-lib-go/meframe.go b/vendor/github.com/opencord/omci-lib-go/meframe.go
index 3c5ab53..c13554c 100644
--- a/vendor/github.com/opencord/omci-lib-go/meframe.go
+++ b/vendor/github.com/opencord/omci-lib-go/meframe.go
@@ -43,7 +43,7 @@
encoderMap[MibUploadRequestType] = MibUploadRequestFrame
encoderMap[MibUploadNextRequestType] = MibUploadNextRequestFrame
encoderMap[MibResetRequestType] = MibResetRequestFrame
- encoderMap[TestRequestType] = TestRequestFrame
+ //encoderMap[TestRequestType] = TestRequestFrame
encoderMap[StartSoftwareDownloadRequestType] = StartSoftwareDownloadRequestFrame
encoderMap[DownloadSectionRequestType] = DownloadSectionRequestFrame
encoderMap[EndSoftwareDownloadRequestType] = EndSoftwareDownloadRequestFrame
@@ -63,7 +63,7 @@
encoderMap[MibUploadResponseType] = MibUploadResponseFrame
encoderMap[MibUploadNextResponseType] = MibUploadNextResponseFrame
encoderMap[MibResetResponseType] = MibResetResponseFrame
- encoderMap[TestResponseType] = TestResponseFrame
+ //encoderMap[TestResponseType] = TestResponseFrame
encoderMap[StartSoftwareDownloadResponseType] = StartSoftwareDownloadResponseFrame
encoderMap[DownloadSectionResponseType] = DownloadSectionResponseFrame
encoderMap[EndSoftwareDownloadResponseType] = EndSoftwareDownloadResponseFrame
@@ -76,7 +76,7 @@
encoderMap[SetTableResponseType] = SetTableResponseFrame
encoderMap[AlarmNotificationType] = AlarmNotificationFrame
encoderMap[AttributeValueChangeType] = AttributeValueChangeFrame
- encoderMap[TestResultType] = TestResultFrame
+ //encoderMap[TestResultType] = TestResultFrame
}
type options struct {
@@ -414,6 +414,9 @@
}
func CreateRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// NOTE: The OMCI parser does not extract the default values of set-by-create attributes
// and are the zero 'default' (or nil) at this time. For this reason, make sure
// you specify all non-zero default values and pass them in appropriate
@@ -421,6 +424,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Attributes: m.GetAttributeValueMap(),
}
@@ -443,10 +447,14 @@
}
func CreateResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
meLayer := &CreateResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
}
@@ -457,20 +465,28 @@
}
func DeleteRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
meLayer := &DeleteRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
return meLayer, nil
}
func DeleteResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
meLayer := &DeleteResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
}
@@ -493,11 +509,15 @@
// Get payload space available
maxPayload := maxPacketAvailable(m, opt)
payloadAvailable := int(maxPayload) - 2 // Less attribute mask
-
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ // payloadAvailable -= 2 // Less length
+ }
meLayer := &SetRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
AttributeMask: 0,
Attributes: make(me.AttributeValueMap),
@@ -546,10 +566,14 @@
}
func SetResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
meLayer := &SetResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
}
@@ -582,6 +606,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
AttributeMask: mask,
}
@@ -601,6 +626,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
AttributeMask: 0,
@@ -666,11 +692,15 @@
}
func GetAllAlarmsRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &GetAllAlarmsRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
AlarmRetrievalMode: opt.mode,
}
@@ -678,11 +708,15 @@
}
func GetAllAlarmsResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &GetAllAlarmsResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
NumberOfCommands: opt.sequenceNumberCountOrSize,
}
@@ -690,11 +724,15 @@
}
func GetAllAlarmsNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &GetAllAlarmsNextRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
CommandSequenceNumber: opt.sequenceNumberCountOrSize,
}
@@ -702,11 +740,15 @@
}
func GetAllAlarmsNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &GetAllAlarmsNextResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
AlarmEntityClass: opt.alarm.AlarmClassID,
AlarmEntityInstance: opt.alarm.AlarmInstance,
@@ -724,22 +766,30 @@
}
func MibUploadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &MibUploadRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: 0,
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
return meLayer, nil
}
func MibUploadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &MibUploadResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: 0,
+ Extended: opt.frameFormat == ExtendedIdent,
},
NumberOfCommands: opt.sequenceNumberCountOrSize,
}
@@ -747,11 +797,15 @@
}
func MibUploadNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &MibUploadNextRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: 0,
+ Extended: opt.frameFormat == ExtendedIdent,
},
CommandSequenceNumber: opt.sequenceNumberCountOrSize,
}
@@ -759,11 +813,15 @@
}
func MibUploadNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &MibUploadNextResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
if opt.payload == nil {
@@ -792,22 +850,30 @@
}
func MibResetRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &MibResetRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
return meLayer, nil
}
func MibResetResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &MibResetResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
}
@@ -815,6 +881,9 @@
}
func AlarmNotificationFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -824,6 +893,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -837,6 +907,9 @@
}
func AttributeValueChangeFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -846,6 +919,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
AttributeMask: 0,
Attributes: make(me.AttributeValueMap),
@@ -860,54 +934,66 @@
return meLayer, errors.New("todo: Not implemented")
}
-func TestRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
- mask, err := checkAttributeMask(m, opt.attributeMask)
- if err != nil {
- return nil, err
- }
- // Common for all MEs
- meLayer := &TestRequest{
- MeBasePacket: MeBasePacket{
- EntityClass: m.GetClassID(),
- EntityInstance: m.GetEntityID(),
- },
- }
- // Get payload space available
- maxPayload := maxPacketAvailable(m, opt)
+//func TestRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+// if opt.frameFormat == ExtendedIdent {
+// return nil, errors.New("Extended message set for this message type is not supported")
+// }
+// mask, err := checkAttributeMask(m, opt.attributeMask)
+// if err != nil {
+// return nil, err
+// }
+// // Common for all MEs
+// meLayer := &TestRequest{
+// MeBasePacket: MeBasePacket{
+// EntityClass: m.GetClassID(),
+// EntityInstance: m.GetEntityID(),
+// Extended: opt.frameFormat == ExtendedIdent,
+// },
+// }
+// // Get payload space available
+// maxPayload := maxPacketAvailable(m, opt)
+//
+// // TODO: Lots of work to do
+//
+// fmt.Println(mask, maxPayload)
+// return meLayer, errors.New("todo: Not implemented")
+//}
- // TODO: Lots of work to do
-
- fmt.Println(mask, maxPayload)
- return meLayer, errors.New("todo: Not implemented")
-}
-
-func TestResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
- mask, err := checkAttributeMask(m, opt.attributeMask)
- if err != nil {
- return nil, err
- }
- // Common for all MEs
- meLayer := &TestResponse{
- MeBasePacket: MeBasePacket{
- EntityClass: m.GetClassID(),
- EntityInstance: m.GetEntityID(),
- },
- }
- // Get payload space available
- maxPayload := maxPacketAvailable(m, opt)
-
- // TODO: Lots of work to do
-
- fmt.Println(mask, maxPayload)
- return meLayer, errors.New("todo: Not implemented")
-}
+//func TestResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+// if opt.frameFormat == ExtendedIdent {
+// return nil, errors.New("Extended message set for this message type is not supported")
+// }
+// mask, err := checkAttributeMask(m, opt.attributeMask)
+// if err != nil {
+// return nil, err
+// }
+// // Common for all MEs
+// meLayer := &TestResponse{
+// MeBasePacket: MeBasePacket{
+// EntityClass: m.GetClassID(),
+// EntityInstance: m.GetEntityID(),
+// Extended: opt.frameFormat == ExtendedIdent,
+// },
+// }
+// // Get payload space available
+// maxPayload := maxPacketAvailable(m, opt)
+//
+// // TODO: Lots of work to do
+//
+// fmt.Println(mask, maxPayload)
+// return meLayer, errors.New("todo: Not implemented")
+//}
func StartSoftwareDownloadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &StartSoftwareDownloadRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
WindowSize: opt.software.WindowSize,
ImageSize: opt.software.ImageSize,
@@ -927,11 +1013,15 @@
}
func StartSoftwareDownloadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &StartSoftwareDownloadResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
WindowSize: opt.software.WindowSize,
NumberOfInstances: byte(len(opt.software.CircuitPacks)),
@@ -950,6 +1040,9 @@
}
func DownloadSectionRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -959,6 +1052,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -971,6 +1065,9 @@
}
func DownloadSectionResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -980,6 +1077,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -992,6 +1090,9 @@
}
func EndSoftwareDownloadRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1001,6 +1102,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1013,6 +1115,9 @@
}
func EndSoftwareDownloadResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1022,6 +1127,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1034,6 +1140,9 @@
}
func ActivateSoftwareRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1043,6 +1152,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1055,6 +1165,9 @@
}
func ActivateSoftwareResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1064,6 +1177,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1076,6 +1190,9 @@
}
func CommitSoftwareRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1085,6 +1202,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1097,6 +1215,9 @@
}
func CommitSoftwareResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1106,6 +1227,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1118,11 +1240,15 @@
}
func SynchronizeTimeRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &SynchronizeTimeRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Decode payload option. If nil, no timestamp provided
@@ -1139,11 +1265,15 @@
}
func SynchronizeTimeResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &SynchronizeTimeResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
SuccessResults: opt.mode,
@@ -1152,11 +1282,15 @@
}
func RebootRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &RebootRequest{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
RebootCondition: opt.mode,
}
@@ -1164,11 +1298,15 @@
}
func RebootResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Common for all MEs
meLayer := &RebootResponse{
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
}
@@ -1176,6 +1314,9 @@
}
func GetNextRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Validate attribute mask
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
@@ -1195,6 +1336,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
AttributeMask: mask,
SequenceNumber: opt.sequenceNumberCountOrSize,
@@ -1203,6 +1345,9 @@
}
func GetNextResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
// Validate attribute mask
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
@@ -1218,6 +1363,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
Result: opt.result,
AttributeMask: 0,
@@ -1273,28 +1419,35 @@
return meLayer, nil
}
-func TestResultFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
- mask, err := checkAttributeMask(m, opt.attributeMask)
- if err != nil {
- return nil, err
- }
- // Common for all MEs
- meLayer := &TestResultMsg{
- MeBasePacket: MeBasePacket{
- EntityClass: m.GetClassID(),
- EntityInstance: m.GetEntityID(),
- },
- }
- // Get payload space available
- maxPayload := maxPacketAvailable(m, opt)
-
- // TODO: Lots of work to do
-
- fmt.Println(mask, maxPayload)
- return meLayer, errors.New("todo: Not implemented")
-}
+//func TestResultFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+// if opt.frameFormat == ExtendedIdent {
+// return nil, errors.New("Extended message set for this message type is not supported")
+// }
+// mask, err := checkAttributeMask(m, opt.attributeMask)
+// if err != nil {
+// return nil, err
+// }
+// // Common for all MEs
+// meLayer := &TestResultNotification{
+// MeBasePacket: MeBasePacket{
+// EntityClass: m.GetClassID(),
+// EntityInstance: m.GetEntityID(),
+// Extended: opt.frameFormat == ExtendedIdent,
+// },
+// }
+// // Get payload space available
+// maxPayload := maxPacketAvailable(m, opt)
+//
+// // TODO: Lots of work to do
+//
+// fmt.Println(mask, maxPayload)
+// return meLayer, errors.New("todo: Not implemented")
+//}
func GetCurrentDataRequestFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1304,6 +1457,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1316,6 +1470,9 @@
}
func GetCurrentDataResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1325,6 +1482,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1340,6 +1498,9 @@
if opt.frameFormat != ExtendedIdent {
return nil, errors.New("SetTable message type only supported with Extended OMCI Messaging")
}
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
+ }
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
return nil, err
@@ -1349,6 +1510,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: opt.frameFormat == ExtendedIdent,
},
}
// Get payload space available
@@ -1362,7 +1524,10 @@
func SetTableResponseFrame(m *me.ManagedEntity, opt options) (gopacket.SerializableLayer, error) {
if opt.frameFormat != ExtendedIdent {
- return nil, errors.New("SetTable message type only supported with Extended OMCI Messaging")
+ return nil, errors.New("SetTable message type only supported with Extended OMCI Message Set")
+ }
+ if opt.frameFormat == ExtendedIdent {
+ return nil, errors.New("Extended message set for this message type is not supported")
}
mask, err := checkAttributeMask(m, opt.attributeMask)
if err != nil {
@@ -1373,6 +1538,7 @@
MeBasePacket: MeBasePacket{
EntityClass: m.GetClassID(),
EntityInstance: m.GetEntityID(),
+ Extended: true,
},
}
// Get payload space available
diff --git a/vendor/github.com/opencord/omci-lib-go/messagetypes.go b/vendor/github.com/opencord/omci-lib-go/messagetypes.go
index f0ff447..456bef8 100644
--- a/vendor/github.com/opencord/omci-lib-go/messagetypes.go
+++ b/vendor/github.com/opencord/omci-lib-go/messagetypes.go
@@ -70,10 +70,14 @@
GetCurrentDataResponseType = MessageType(byte(me.GetCurrentData) | me.AK)
SetTableRequestType = MessageType(byte(me.SetTable) | me.AR)
SetTableResponseType = MessageType(byte(me.SetTable) | me.AK)
+
// Autonomous ONU messages
AlarmNotificationType = MessageType(byte(me.AlarmNotification))
AttributeValueChangeType = MessageType(byte(me.AttributeValueChange))
TestResultType = MessageType(byte(me.TestResult))
+
+ // Support mapping of extended format types (use MSB reserved bit)
+ ExtendedTypeDecodeOffset = MessageType(byte(0x80))
)
func (mt MessageType) String() string {
@@ -125,7 +129,7 @@
return "Start Software Download Request"
case StartSoftwareDownloadResponseType:
return "Start Software Download Response"
- case DownloadSectionRequestType:
+ case DownloadSectionRequestType, DownloadSectionRequestWithResponseType:
return "Download Section Request"
case DownloadSectionResponseType:
return "Download Section Response"
@@ -649,7 +653,15 @@
if !me.SupportsMsgType(meDefinition, me.Get) {
return me.NewProcessingError("managed entity does not support Get Message-Type")
}
- omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
+ if omci.Extended {
+ if len(data) < 8 {
+ p.SetTruncated()
+ return errors.New("frame too small")
+ }
+ omci.AttributeMask = binary.BigEndian.Uint16(data[6:])
+ } else {
+ omci.AttributeMask = binary.BigEndian.Uint16(data[4:])
+ }
return nil
}
@@ -659,6 +671,13 @@
return decodingLayerDecoder(omci, data, p)
}
+func decodeGetRequestExtended(data []byte, p gopacket.PacketBuilder) error {
+ omci := &GetRequest{}
+ omci.MsgLayerType = LayerTypeGetRequest
+ omci.Extended = true
+ return decodingLayerDecoder(omci, data, p)
+}
+
// SerializeTo provides serialization of an Get Request message
func (omci *GetRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
// Basic (common) OMCI Header is 8 octets, 10
@@ -675,11 +694,22 @@
if !me.SupportsMsgType(meDefinition, me.Get) {
return me.NewProcessingError("managed entity does not support Get Message-Type")
}
- bytes, err := b.AppendBytes(2)
+ maskOffset := 0
+ if omci.Extended {
+ maskOffset = 2
+ }
+ bytes, err := b.AppendBytes(2 + maskOffset)
if err != nil {
return err
}
- binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
+ if omci.Extended {
+ binary.BigEndian.PutUint16(bytes, uint16(2))
+ }
+ binary.BigEndian.PutUint16(bytes[maskOffset:], omci.AttributeMask)
+ return nil
+}
+
+func (omci *GetRequest) SerializeToExtended(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
return nil
}
@@ -716,33 +746,56 @@
if !me.SupportsMsgType(meDefinition, me.Get) {
return me.NewProcessingError("managed entity does not support Get Message-Type")
}
- omci.Result = me.Results(data[4])
- omci.AttributeMask = binary.BigEndian.Uint16(data[5:7])
+ if omci.Extended {
+ if len(data) < 13 {
+ p.SetTruncated()
+ return errors.New("frame too small")
+ }
+ omci.Result = me.Results(data[6])
+ omci.AttributeMask = binary.BigEndian.Uint16(data[7:])
+ // If Attribute failed or Unknown, decode optional attribute mask
+ if omci.Result == me.AttributeFailure {
+ omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[9:])
+ omci.FailedAttributeMask = binary.BigEndian.Uint16(data[11:])
+ }
+ } else {
+ omci.Result = me.Results(data[4])
+ omci.AttributeMask = binary.BigEndian.Uint16(data[5:])
+
+ // If Attribute failed or Unknown, decode optional attribute mask
+ if omci.Result == me.AttributeFailure {
+ omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[32:34])
+ omci.FailedAttributeMask = binary.BigEndian.Uint16(data[34:36])
+ }
+ }
// Attribute decode. Note that the ITU-T G.988 specification states that the
// Unsupported and Failed attribute masks are always present
// but only valid if the status code== 9. However some XGS
// ONUs (T&W and Alpha, perhaps more) will use these last 4
// octets for data if the status code == 0. So accommodate
// this behaviour in favor of greater interoperability.
+ firstOctet := 7
lastOctet := 36
+ if omci.Extended {
+ firstOctet = 13
+ lastOctet = len(data)
+ }
switch omci.Result {
case me.ProcessingError, me.NotSupported, me.UnknownEntity, me.UnknownInstance, me.DeviceBusy:
return nil // Done (do not try and decode attributes)
case me.AttributeFailure:
- lastOctet = 32
+ if !omci.Extended {
+ lastOctet = 32
+ }
}
- omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[7:lastOctet], p, byte(GetResponseType))
+ omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask,
+ data[firstOctet:lastOctet], p, byte(GetResponseType))
if err != nil {
return err
}
- // If Attribute failed or Unknown, decode optional attribute mask
- if omci.Result == me.AttributeFailure {
- omci.UnsupportedAttributeMask = binary.BigEndian.Uint16(data[32:34])
- omci.FailedAttributeMask = binary.BigEndian.Uint16(data[34:36])
- }
// Validate all attributes support read
for attrName := range omci.Attributes {
attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
@@ -767,6 +820,13 @@
return decodingLayerDecoder(omci, data, p)
}
+func decodeGetResponseExtended(data []byte, p gopacket.PacketBuilder) error {
+ omci := &GetResponse{}
+ omci.MsgLayerType = LayerTypeGetResponse
+ omci.Extended = true
+ return decodingLayerDecoder(omci, data, p)
+}
+
// SerializeTo provides serialization of an Get Response message
func (omci *GetResponse) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
// Basic (common) OMCI Header is 8 octets, 10
@@ -783,16 +843,27 @@
if !me.SupportsMsgType(meDefinition, me.Get) {
return me.NewProcessingError("managed entity does not support the Get Message-Type")
}
- bytes, err := b.AppendBytes(3)
+ resultOffset := 0
+ attributeErrExtra := 0
+
+ if omci.Extended {
+ resultOffset = 2
+ attributeErrExtra = 4 // Attribute mask + attribute error masks
+ }
+ // Space for result + mask (both types) + (len & error masks if extended)
+ buffer, err := b.AppendBytes(3 + resultOffset + attributeErrExtra)
if err != nil {
return err
}
- bytes[0] = byte(omci.Result)
- binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask)
+ // Save result and initial mask. Other header fields updated after
+ // attribute copy
+ buffer[resultOffset] = byte(omci.Result)
+ binary.BigEndian.PutUint16(buffer[resultOffset+1:], omci.AttributeMask)
// Validate all attributes support read
for attrName := range omci.Attributes {
- attr, err := me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
+ var attr *me.AttributeDefinition
+ attr, err = me.GetAttributeDefinitionByName(meDefinition.GetAttributeDefinitions(), attrName)
if err != nil {
return err
}
@@ -804,52 +875,77 @@
// Attribute serialization
switch omci.Result {
default:
+ if omci.Extended {
+ // Minimum length is 7 for extended an need to write error masks
+ binary.BigEndian.PutUint16(buffer, uint16(7))
+ binary.BigEndian.PutUint32(buffer[resultOffset+3:], 0)
+ }
break
case me.Success, me.AttributeFailure:
// TODO: Baseline only supported at this time)
- available := MaxBaselineLength - 11 - 4 - 8
-
+ var available int
+ if omci.Extended {
+ available = MaxExtendedLength - 18 - 4 // Less: header, mic
+ } else {
+ available = MaxBaselineLength - 11 - 4 - 8 // Less: header, failed attributes, length, mic
+ }
// Serialize to temporary buffer if we may need to reset values due to
// recoverable truncation errors
- origBuffer := b
- b := gopacket.NewSerializeBuffer()
+ attributeBuffer := gopacket.NewSerializeBuffer()
+ var failedMask uint16
+ err, failedMask = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask,
+ attributeBuffer, byte(GetResponseType), available, opts.FixLengths)
- err, failedMask := meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b, byte(GetResponseType),
- available, opts.FixLengths)
-
- if err == nil && failedMask != 0 && opts.FixLengths {
+ if err != nil {
+ return err
+ }
+ if failedMask != 0 {
// Not all attributes would fit
omci.FailedAttributeMask |= failedMask
omci.AttributeMask &= ^failedMask
omci.Result = me.AttributeFailure
// Adjust already recorded values
- bytes[0] = byte(omci.Result)
- binary.BigEndian.PutUint16(bytes[1:3], omci.AttributeMask)
- } else if err != nil {
- return err
+ buffer[resultOffset] = byte(omci.Result)
+ binary.BigEndian.PutUint16(buffer[resultOffset+1:], omci.AttributeMask)
+ }
+ if omci.Extended {
+ // Set length and any failure masks
+ binary.BigEndian.PutUint16(buffer, uint16(len(attributeBuffer.Bytes())+7))
+
+ if omci.Result == me.AttributeFailure {
+ binary.BigEndian.PutUint16(buffer[resultOffset+3:], omci.UnsupportedAttributeMask)
+ binary.BigEndian.PutUint16(buffer[resultOffset+5:], omci.FailedAttributeMask)
+ } else {
+ binary.BigEndian.PutUint32(buffer[resultOffset+3:], 0)
+ }
}
// Copy over attributes to the original serialization buffer
- newSpace, err := origBuffer.AppendBytes(len(b.Bytes()))
+ var newSpace []byte
+
+ newSpace, err = b.AppendBytes(len(attributeBuffer.Bytes()))
if err != nil {
return err
}
- copy(newSpace, b.Bytes())
- b = origBuffer
+ copy(newSpace, attributeBuffer.Bytes())
- // Calculate space left. Max - msgType header - OMCI trailer - spacedUsedSoFar
- bytesLeft := MaxBaselineLength - 4 - 8 - len(b.Bytes())
+ if !omci.Extended {
+ // Calculate space left. Max - msgType header - OMCI trailer - spacedUsedSoFar
+ bytesLeft := MaxBaselineLength - 4 - 8 - len(b.Bytes())
- remainingBytes, err := b.AppendBytes(bytesLeft + 4)
- if err != nil {
- return me.NewMessageTruncatedError(err.Error())
- }
- copy(remainingBytes, lotsOfZeros[:])
+ var remainingBytes []byte
+ remainingBytes, err = b.AppendBytes(bytesLeft + 4)
- if omci.Result == me.AttributeFailure {
- binary.BigEndian.PutUint16(remainingBytes[bytesLeft-4:bytesLeft-2], omci.UnsupportedAttributeMask)
- binary.BigEndian.PutUint16(remainingBytes[bytesLeft-2:bytesLeft], omci.FailedAttributeMask)
+ if err != nil {
+ return me.NewMessageTruncatedError(err.Error())
+ }
+ copy(remainingBytes, lotsOfZeros[:])
+
+ if omci.Result == me.AttributeFailure {
+ binary.BigEndian.PutUint16(remainingBytes[bytesLeft-4:bytesLeft-2], omci.UnsupportedAttributeMask)
+ binary.BigEndian.PutUint16(remainingBytes[bytesLeft-2:bytesLeft], omci.FailedAttributeMask)
+ }
}
}
return nil
@@ -1534,7 +1630,7 @@
}
omci.Result = me.Results(data[4])
if omci.Result > me.DeviceBusy {
- msg := fmt.Sprintf("invalid results code: %v, must be 0..8", omci.Result)
+ msg := fmt.Sprintf("invalid results code: %v, must be 0..6", omci.Result)
return errors.New(msg)
}
return nil
@@ -1842,30 +1938,54 @@
return err
}
-/////////////////////////////////////////////////////////////////////////////
-// TestRequest: TODO: Not yet implemented
+func decodeTestRequest(data []byte, p gopacket.PacketBuilder) error {
+ // Peek at Managed Entity Type
+ if len(data) < 8 {
+ p.SetTruncated()
+ return errors.New("frame too small")
+ }
+ classID := binary.BigEndian.Uint16(data)
+
+ // Is it a Managed Entity class we support customized decode of?
+ switch me.ClassID(classID) {
+ default:
+ omci := &TestRequest{}
+ omci.MsgLayerType = LayerTypeTestResult
+ return decodingLayerDecoder(omci, data, p)
+
+ case me.AniGClassID, me.ReAniGClassID, me.PhysicalPathTerminationPointReUniClassID,
+ me.ReUpstreamAmplifierClassID, me.ReDownstreamAmplifierClassID:
+ omci := &OpticalLineSupervisionTestRequest{}
+ omci.MsgLayerType = LayerTypeTestResult
+ return decodingLayerDecoder(omci, data, p)
+ }
+}
+
+// TestRequest message
type TestRequest struct {
MeBasePacket
+ Payload []byte
}
func (omci *TestRequest) String() string {
- return fmt.Sprintf("%v", omci.MeBasePacket.String())
+ return fmt.Sprintf("%v, Request: %v octets", omci.MeBasePacket.String(), len(omci.Payload))
+}
+
+func (omci *TestRequest) TestRequest() []byte {
+ return omci.Payload
}
// DecodeFromBytes decodes the given bytes of a Test Request into this layer
func (omci *TestRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
// Common ClassID/EntityID decode in msgBase
- err := omci.MeBasePacket.DecodeFromBytes(data, p, 4+5)
+ err := omci.MeBasePacket.DecodeFromBytes(data, p, 4)
if err != nil {
return err
}
- return errors.New("need to implement") // TODO: Fix me) // return nil
-}
-func decodeTestRequest(data []byte, p gopacket.PacketBuilder) error {
- omci := &TestRequest{}
- omci.MsgLayerType = LayerTypeTestRequest
- return decodingLayerDecoder(omci, data, p)
+ omci.Payload = make([]byte, MaxTestRequestLength)
+ copy(omci.Payload, omci.MeBasePacket.Payload)
+ return nil
}
// SerializeTo provides serialization of an Test Request message
@@ -1875,17 +1995,81 @@
if err != nil {
return err
}
- return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b)
+ if omci.Payload == nil {
+ return errors.New("Test Results payload is missing")
+ }
+
+ if len(omci.Payload) > MaxTestRequestLength {
+ msg := fmt.Sprintf("Invalid Test Request payload size. Received %v bytes, expected %v",
+ len(omci.Payload), MaxTestRequestLength)
+ return errors.New(msg)
+ }
+ bytes, err := b.AppendBytes(len(omci.Payload))
+ if err != nil {
+ return err
+ }
+
+ copy(bytes, omci.Payload)
+ return nil
}
-/////////////////////////////////////////////////////////////////////////////
-// TestResponse: TODO: Not yet implemented
+type OpticalLineSupervisionTestRequest struct {
+ MeBasePacket
+ SelectTest uint8 // Bitfield
+ GeneralPurposeBuffer uint16 // Pointer to General Purpose Buffer ME
+ VendorSpecificParameters uint16 // Pointer to Octet String ME
+}
+
+func (omci *OpticalLineSupervisionTestRequest) String() string {
+ return fmt.Sprintf("Optical Line Supervision Test Result: SelectTest: %#x, Buffer: %#x, Params: %#x",
+ omci.SelectTest, omci.GeneralPurposeBuffer, omci.VendorSpecificParameters)
+}
+
+func (omci *OpticalLineSupervisionTestRequest) TestRequest() []byte {
+ return omci.Payload
+}
+
+// DecodeFromBytes decodes the given bytes of a Test Result Notification into this layer
+func (omci *OpticalLineSupervisionTestRequest) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
+ // Common ClassID/EntityID decode in msgBase
+ err := omci.MeBasePacket.DecodeFromBytes(data, p, 4+5)
+ if err != nil {
+ return err
+ }
+
+ omci.SelectTest = data[4]
+ omci.GeneralPurposeBuffer = binary.BigEndian.Uint16(data[5:])
+ omci.VendorSpecificParameters = binary.BigEndian.Uint16(data[7:])
+ return nil
+}
+
+// SerializeTo provides serialization of an Test Result notification message
+func (omci *OpticalLineSupervisionTestRequest) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
+ // Basic (common) OMCI Header is 8 octets, 10
+ err := omci.MeBasePacket.SerializeTo(b)
+ if err != nil {
+ return err
+ }
+
+ bytes, err := b.AppendBytes(8)
+ if err != nil {
+ return err
+ }
+
+ bytes[0] = omci.SelectTest
+ binary.BigEndian.PutUint16(bytes[1:], omci.GeneralPurposeBuffer)
+ binary.BigEndian.PutUint16(bytes[3:], omci.VendorSpecificParameters)
+ return nil
+}
+
+// TestResponse message
type TestResponse struct {
MeBasePacket
+ Result me.Results
}
func (omci *TestResponse) String() string {
- return fmt.Sprintf("%v", omci.MeBasePacket.String())
+ return fmt.Sprintf("%v, Results: %d (%v)", omci.MeBasePacket.String(), omci.Result, omci.Result)
}
// DecodeFromBytes decodes the given bytes of a Test Response into this layer
@@ -1895,7 +2079,18 @@
if err != nil {
return err
}
- return errors.New("need to implement") // TODO: Fix me) // return nil
+ meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
+ me.ParamData{EntityID: omci.EntityInstance})
+ if omciErr.StatusCode() != me.Success {
+ return omciErr.GetError()
+ }
+
+ // ME needs to support Test requests
+ if !me.SupportsMsgType(meDefinition, me.Test) {
+ return me.NewProcessingError("managed entity does not support Test Message-Type")
+ }
+ omci.Result = me.Results(data[4])
+ return nil
}
func decodeTestResponse(data []byte, p gopacket.PacketBuilder) error {
@@ -1911,7 +2106,26 @@
if err != nil {
return err
}
- return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b)
+ entity, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
+ me.ParamData{EntityID: omci.EntityInstance})
+ if omciErr.StatusCode() != me.Success {
+ return omciErr.GetError()
+ }
+ // ME needs to support Set
+ if !me.SupportsMsgType(entity, me.Test) {
+ return me.NewProcessingError("managed entity does not support the Test Message-Type")
+ }
+ bytes, err := b.AppendBytes(1)
+ if err != nil {
+ return err
+ }
+ bytes[0] = byte(omci.Result)
+
+ if omci.Result > me.DeviceBusy {
+ msg := fmt.Sprintf("invalid results code: %v, must be 0..6", omci.Result)
+ return errors.New(msg)
+ }
+ return nil
}
/////////////////////////////////////////////////////////////////////////////
@@ -2932,7 +3146,7 @@
}
omci.Result = me.Results(data[4])
if omci.Result > me.DeviceBusy {
- msg := fmt.Sprintf("invalid results code: %v, must be 0..8", omci.Result)
+ msg := fmt.Sprintf("invalid results code: %v, must be 0..6", omci.Result)
return errors.New(msg)
}
omci.SuccessResults = data[5]
@@ -3316,40 +3530,204 @@
return nil
}
-/////////////////////////////////////////////////////////////////////////////
-//
-type TestResultMsg struct {
- MeBasePacket
+func decodeTestResult(data []byte, p gopacket.PacketBuilder) error {
+ // Peek at Managed Entity Type
+ if len(data) < 8 {
+ p.SetTruncated()
+ return errors.New("frame too small")
+ }
+ classID := binary.BigEndian.Uint16(data)
+
+ // Is it a Managed Entity class we support customized decode of?
+ switch me.ClassID(classID) {
+ default:
+ omci := &TestResultNotification{}
+ omci.MsgLayerType = LayerTypeTestResult
+ return decodingLayerDecoder(omci, data, p)
+
+ case me.AniGClassID, me.ReAniGClassID, me.PhysicalPathTerminationPointReUniClassID,
+ me.ReUpstreamAmplifierClassID, me.ReDownstreamAmplifierClassID:
+ omci := &OpticalLineSupervisionTestResult{}
+ omci.MsgLayerType = LayerTypeTestResult
+ return decodingLayerDecoder(omci, data, p)
+ }
}
-func (omci *TestResultMsg) String() string {
- return fmt.Sprintf("%v", omci.MeBasePacket.String())
+type TestResultNotification struct {
+ MeBasePacket
+ Payload []byte
+}
+
+func (omci *TestResultNotification) TestResults() []byte {
+ return omci.Payload
+}
+
+func (omci *TestResultNotification) String() string {
+ return fmt.Sprintf("%v, Payload: %v octets", omci.MeBasePacket.String(), len(omci.Payload))
}
// DecodeFromBytes decodes the given bytes of a Test Result Notification into this layer
-func (omci *TestResultMsg) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
+func (omci *TestResultNotification) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
// Common ClassID/EntityID decode in msgBase
err := omci.MeBasePacket.DecodeFromBytes(data, p, 4)
if err != nil {
return err
}
- return errors.New("need to implement") // TODO: Fix me) // return nil
-}
-func decodeTestResult(data []byte, p gopacket.PacketBuilder) error {
- omci := &TestResultMsg{}
- omci.MsgLayerType = LayerTypeTestResult
- return decodingLayerDecoder(omci, data, p)
+ meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
+ me.ParamData{EntityID: omci.EntityInstance})
+ if omciErr.StatusCode() != me.Success {
+ return omciErr.GetError()
+ }
+
+ // ME needs to support Test requests
+ if !me.SupportsMsgType(meDefinition, me.Test) {
+ return me.NewProcessingError("managed entity does not support Test Message-Type")
+ }
+ omci.Payload = make([]byte, MaxTestResultsLength)
+ copy(omci.Payload, omci.MeBasePacket.Payload)
+ return nil
}
// SerializeTo provides serialization of an Test Result notification message
-func (omci *TestResultMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
+func (omci *TestResultNotification) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
+ // Basic (common) OMCI Header is 8 octets
+ err := omci.MeBasePacket.SerializeTo(b)
+ if err != nil {
+ return err
+ }
+
+ meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
+ me.ParamData{EntityID: omci.EntityInstance})
+ if omciErr.StatusCode() != me.Success {
+ return omciErr.GetError()
+ }
+
+ // ME needs to support Test requests
+ if !me.SupportsMsgType(meDefinition, me.Test) {
+ return me.NewProcessingError("managed entity does not support Test Message-Type")
+ }
+ if omci.Payload == nil {
+ return errors.New("Test Results payload is missing")
+ }
+ if len(omci.Payload) > MaxTestResultsLength {
+ msg := fmt.Sprintf("Invalid Test Results payload size. Received %v bytes, expected %v",
+ len(omci.Payload), MaxTestResultsLength)
+ return errors.New(msg)
+ }
+ bytes, err := b.AppendBytes(len(omci.Payload))
+ if err != nil {
+ return err
+ }
+
+ copy(bytes, omci.Payload)
+ return nil
+}
+
+// OpticalLineSupervisionTestResult provides a Optical Specific test results
+// message decode for the associated Managed Entities
+type OpticalLineSupervisionTestResult struct {
+ MeBasePacket
+ PowerFeedVoltageType uint8 // Type = 1
+ PowerFeedVoltage uint16 // value
+ ReceivedOpticalPowerType uint8 // Type = 3
+ ReceivedOpticalPower uint16 // value
+ MeanOpticalLaunchType uint8 // Type = 5
+ MeanOpticalLaunch uint16 // value
+ LaserBiasCurrentType uint8 // Type = 9
+ LaserBiasCurrent uint16 // value
+ TemperatureType uint8 // Type = 12
+ Temperature uint16 // value
+
+ GeneralPurposeBuffer uint16 // Pointer to General Purpose Buffer ME
+}
+
+func (omci *OpticalLineSupervisionTestResult) String() string {
+ return fmt.Sprintf("Optical Line Supervision Test Result")
+}
+
+func (omci *OpticalLineSupervisionTestResult) TestResults() []byte {
+ return omci.MeBasePacket.Payload
+}
+
+// DecodeFromBytes decodes the given bytes of a Test Result Notification into this layer
+func (omci *OpticalLineSupervisionTestResult) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
+ // Common ClassID/EntityID decode in msgBase
+ err := omci.MeBasePacket.DecodeFromBytes(data, p, 4+17)
+ if err != nil {
+ return err
+ }
+
+ meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
+ me.ParamData{EntityID: omci.EntityInstance})
+ if omciErr.StatusCode() != me.Success {
+ return omciErr.GetError()
+ }
+
+ // ME needs to support Test requests
+ if !me.SupportsMsgType(meDefinition, me.Test) {
+ return me.NewProcessingError("managed entity does not support Test Message-Type")
+ }
+ // Note: Unsupported tests will have a type = 0 and the value should be zero
+ // as well, but that constraint is not enforced at this time.
+ // Type = 1
+ omci.PowerFeedVoltageType = data[4]
+ omci.PowerFeedVoltage = binary.BigEndian.Uint16(data[5:])
+
+ // Type = 3
+ omci.ReceivedOpticalPowerType = data[7]
+ omci.ReceivedOpticalPower = binary.BigEndian.Uint16(data[8:])
+
+ // Type = 5
+ omci.MeanOpticalLaunchType = data[10]
+ omci.MeanOpticalLaunch = binary.BigEndian.Uint16(data[11:])
+
+ // Type = 9
+ omci.LaserBiasCurrentType = data[13]
+ omci.LaserBiasCurrent = binary.BigEndian.Uint16(data[14:])
+
+ // Type = 12
+ omci.TemperatureType = data[16]
+ omci.Temperature = binary.BigEndian.Uint16(data[17:])
+
+ omci.GeneralPurposeBuffer = binary.BigEndian.Uint16(data[19:])
+ return nil
+}
+
+// SerializeTo provides serialization of an Test Result notification message
+func (omci *OpticalLineSupervisionTestResult) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
// Basic (common) OMCI Header is 8 octets, 10
err := omci.MeBasePacket.SerializeTo(b)
if err != nil {
return err
}
- return errors.New("need to implement") // TODO: Fix me) // omci.cachedME.SerializeTo(mask, b)
+ meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
+ me.ParamData{EntityID: omci.EntityInstance})
+ if omciErr.StatusCode() != me.Success {
+ return omciErr.GetError()
+ }
+
+ // ME needs to support Test requests
+ if !me.SupportsMsgType(meDefinition, me.Test) {
+ return me.NewProcessingError("managed entity does not support Test Message-Type")
+ }
+ bytes, err := b.AppendBytes(17)
+ if err != nil {
+ return err
+ }
+
+ bytes[0] = omci.PowerFeedVoltageType
+ binary.BigEndian.PutUint16(bytes[1:], omci.PowerFeedVoltage)
+ bytes[3] = omci.ReceivedOpticalPowerType
+ binary.BigEndian.PutUint16(bytes[4:], omci.ReceivedOpticalPower)
+ bytes[6] = omci.MeanOpticalLaunchType
+ binary.BigEndian.PutUint16(bytes[7:], omci.MeanOpticalLaunch)
+ bytes[9] = omci.LaserBiasCurrentType
+ binary.BigEndian.PutUint16(bytes[10:], omci.LaserBiasCurrent)
+ bytes[12] = omci.TemperatureType
+ binary.BigEndian.PutUint16(bytes[13:], omci.Temperature)
+ binary.BigEndian.PutUint16(bytes[15:], omci.GeneralPurposeBuffer)
+ return nil
}
/////////////////////////////////////////////////////////////////////////////
diff --git a/vendor/github.com/opencord/omci-lib-go/omci.go b/vendor/github.com/opencord/omci-lib-go/omci.go
index 9b7f881..b2995d0 100644
--- a/vendor/github.com/opencord/omci-lib-go/omci.go
+++ b/vendor/github.com/opencord/omci-lib-go/omci.go
@@ -86,10 +86,18 @@
const MaxAttributeMibUploadNextBaselineLength = MaxBaselineLength - 14 - 8
// MaxAttributeGetNextBaselineLength is the maximum payload size for attributes for
-// a Baseline MIB Get Next message. This is just the attribute portion of the
-// message contents and does not include the Result Code & Attribute Mask.
+// a Baseline MIB Get Next message for the baseline message set. This is just the
+// attribute portion of the message contents and does not include the Result Code & Attribute Mask.
const MaxAttributeGetNextBaselineLength = MaxBaselineLength - 11 - 8
+// MaxTestRequestLength is the maximum payload size for test request message
+// for the baseline message set.
+const MaxTestRequestLength = MaxBaselineLength - 8 - 8
+
+// MaxTestResultsLength is the maximum payload size for test results message
+// for the baseline message set.
+const MaxTestResultsLength = MaxBaselineLength - 8 - 8
+
// MaxManagedEntityMibUploadNextExtendedLength is the maximum payload size for ME
// entries for an Extended MIB Upload Next message. Extended messages differ from
// the baseline as multiple MEs can be reported in a single frame, just not multiple
@@ -115,7 +123,6 @@
DeviceIdentifier DeviceIdent
ResponseExpected bool // Significant for Download Section Request only
Payload []byte // TODO: Deprecated. Use layers.BaseLayer.Payload
- padding []byte // TODO: Deprecated. Never Used
Length uint16
MIC uint32
}
@@ -157,21 +164,24 @@
func decodeOMCI(data []byte, p gopacket.PacketBuilder) error {
// Allow baseline messages without Length & MIC, but no less
- if len(data) < MaxBaselineLength-8 {
+ if len(data) < 10 {
+ p.SetTruncated()
return errors.New("frame header too small")
}
+ omci := &OMCI{}
+
switch DeviceIdent(data[3]) {
default:
- return errors.New("unsupported message type")
+ return errors.New("unsupported message set/device identifier")
case BaselineIdent:
- //omci := &BaselineMessage{}
- omci := &OMCI{}
+ if len(data) < MaxBaselineLength-8 {
+ p.SetTruncated()
+ return errors.New("frame too small")
+ }
return omci.DecodeFromBytes(data, p)
case ExtendedIdent:
- //omci := &ExtendedMessage{}
- omci := &OMCI{}
return omci.DecodeFromBytes(data, p)
}
}
@@ -217,10 +227,12 @@
// Decode length
var payloadOffset int
var micOffset int
+ var eomOffset int
if omci.DeviceIdentifier == BaselineIdent {
omci.Length = MaxBaselineLength - 8
payloadOffset = 8
micOffset = MaxBaselineLength - 4
+ eomOffset = MaxBaselineLength - 8
if len(data) >= micOffset {
length := binary.BigEndian.Uint32(data[micOffset-4:])
@@ -232,14 +244,13 @@
payloadOffset = 10
omci.Length = binary.BigEndian.Uint16(data[8:10])
micOffset = int(omci.Length) + payloadOffset
+ eomOffset = micOffset
- if omci.Length > MaxExtendedLength {
+ if omci.Length > uint16(MaxExtendedLength-payloadOffset) {
return me.NewProcessingError("extended frame exceeds maximum allowed")
}
- if int(omci.Length) != micOffset {
- if int(omci.Length) < micOffset {
- p.SetTruncated()
- }
+ if len(data) < micOffset {
+ p.SetTruncated()
return me.NewProcessingError("extended frame too small")
}
}
@@ -253,9 +264,9 @@
//return errors.New(msg)
}
}
- omci.BaseLayer = layers.BaseLayer{Contents: data[:4], Payload: data[4:omci.Length]}
+ omci.BaseLayer = layers.BaseLayer{data[:4], data[4:eomOffset]}
p.AddLayer(omci)
- nextLayer, err := MsgTypeToNextLayer(omci.MessageType)
+ nextLayer, err := MsgTypeToNextLayer(omci.MessageType, omci.DeviceIdentifier == ExtendedIdent)
if err != nil {
return err
}
@@ -266,8 +277,6 @@
// SerializationBuffer, implementing gopacket.SerializableLayer.
// See the docs for gopacket.SerializableLayer for more info.
func (omci *OMCI) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
- // TODO: Hardcoded for baseline message format for now. Will eventually need to support
- // the extended message format.
bytes, err := b.PrependBytes(4)
if err != nil {
return err
@@ -288,11 +297,11 @@
return errors.New(msg)
}
} else if omci.DeviceIdentifier == ExtendedIdent {
- if omci.Length == 0 {
- omci.Length = uint16(len(bytes) - 10) // Allow uninitialized length
- }
- if omci.Length > MaxExtendedLength {
- msg := fmt.Sprintf("invalid Baseline message length: %v", omci.Length)
+ omci.Length = uint16(len(b.Bytes()) - 10)
+
+ // Is length larger than maximum packet (less header and trailing MIC)
+ if omci.Length > MaxExtendedLength-10-4 {
+ msg := fmt.Sprintf("invalid Extended message length: %v", omci.Length)
return errors.New(msg)
}
} else {
@@ -311,17 +320,20 @@
bytes[3] = byte(omci.DeviceIdentifier)
b.PushLayer(LayerTypeOMCI)
- bufLen := len(b.Bytes())
- padSize := int(omci.Length) - bufLen + 4
- if padSize < 0 {
- msg := fmt.Sprintf("invalid OMCI Message Type length, exceeded allowed frame size by %d bytes",
- -padSize)
- return errors.New(msg)
- }
- padding, err := b.AppendBytes(padSize)
- copy(padding, lotsOfZeros[:])
-
if omci.DeviceIdentifier == BaselineIdent {
+ bufLen := len(b.Bytes())
+ padSize := int(omci.Length) - bufLen + 4
+ if padSize < 0 {
+ msg := fmt.Sprintf("invalid OMCI Message Type length, exceeded allowed frame size by %d bytes",
+ -padSize)
+ return errors.New(msg)
+ }
+ padding, err := b.AppendBytes(padSize)
+ if err != nil {
+ return err
+ }
+ copy(padding, lotsOfZeros[:])
+
// For baseline, always provide the length
binary.BigEndian.PutUint32(b.Bytes()[MaxBaselineLength-8:], 40)
}