VOL-3985: Extended Message Set support for Alarm Notification, AVC Notification, and Test Results async message types.

Change-Id: I813b7067c6dd1c994a4e488d040c0ccf559195ab
diff --git a/README.md b/README.md
index 959990a..3308803 100644
--- a/README.md
+++ b/README.md
@@ -74,6 +74,10 @@
 
  - GetRequest
  - GetResponse
+ - DownloadSectionRequest/Response
+ - AlarmNotification
+ - AttributeValueChange
+ - TestResult
 
 ### Upcoming message types that will be supported
 
@@ -81,11 +85,6 @@
 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
@@ -93,19 +92,21 @@
  - CreateRequest/Response
  - DeleteRequest/Response
  - SetRequest/Response
-  
+
+ - GetNextRequest/Response
+ - SetTableRequest/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
diff --git a/VERSION b/VERSION
index 6085e94..f0bb29e 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.2.1
+1.3.0
diff --git a/layers.go b/layers.go
index 4a527bf..1e0b686 100644
--- a/layers.go
+++ b/layers.go
@@ -49,7 +49,7 @@
 	LayerTypeGetCurrentDataRequest        gopacket.LayerType
 	LayerTypeSetTableRequest              gopacket.LayerType
 
-	// Extended Message Types
+	// Extended Request Message Types
 	LayerTypeGetRequestExtended                 gopacket.LayerType
 	LayerTypeDownloadSectionRequestExtended     gopacket.LayerType
 	LayerTypeDownloadSectionLastRequestExtended gopacket.LayerType
@@ -80,9 +80,12 @@
 	LayerTypeGetCurrentDataResponse        gopacket.LayerType
 	LayerTypeSetTableResponse              gopacket.LayerType
 
-	// Extended Message Types
+	// Extended Response/Notification Message Types
 	LayerTypeGetResponseExtended             gopacket.LayerType
 	LayerTypeDownloadSectionResponseExtended gopacket.LayerType
+	LayerTypeAlarmNotificationExtended       gopacket.LayerType
+	LayerTypeAttributeValueChangeExtended    gopacket.LayerType
+	LayerTypeTestResultExtended              gopacket.LayerType
 )
 
 func mkReqLayer(mt me.MsgType, mts string, decode gopacket.DecodeFunc) gopacket.LayerType {
@@ -158,6 +161,10 @@
 	LayerTypeDownloadSectionLastRequestExtended = mkReqLayer(me.DownloadSection|me.ExtendedOffset, "DownloadLastSectionRequest-Ext", gopacket.DecodeFunc(decodeDownloadSectionRequestExtended))
 	LayerTypeDownloadSectionResponseExtended = mkRespLayer(me.DownloadSection|me.ExtendedOffset, "DownloadSectionResponse-Ext", gopacket.DecodeFunc(decodeDownloadSectionResponseExtended))
 
+	LayerTypeAlarmNotificationExtended = mkLayer(me.AlarmNotification|me.ExtendedOffset, "AlarmNotification-Ext", gopacket.DecodeFunc(decodeAlarmNotificationExtended))
+	LayerTypeAttributeValueChangeExtended = mkLayer(me.AttributeValueChange|me.ExtendedOffset, "AttributeValueChange-Ext", gopacket.DecodeFunc(decodeAttributeValueChangeExtended))
+	LayerTypeTestResultExtended = mkLayer(me.TestResult|me.ExtendedOffset, "TestResult-Ext", gopacket.DecodeFunc(decodeTestResultExtended))
+
 	// Map message_type and action to layer
 	nextLayerMapping = make(map[MessageType]gopacket.LayerType)
 
@@ -216,6 +223,10 @@
 	nextLayerMapping[DownloadSectionRequestType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionRequestExtended
 	nextLayerMapping[DownloadSectionRequestWithResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionLastRequestExtended
 	nextLayerMapping[DownloadSectionResponseType+ExtendedTypeDecodeOffset] = LayerTypeDownloadSectionResponseExtended
+
+	nextLayerMapping[AlarmNotificationType+ExtendedTypeDecodeOffset] = LayerTypeAlarmNotificationExtended
+	nextLayerMapping[AttributeValueChangeType+ExtendedTypeDecodeOffset] = LayerTypeAttributeValueChangeExtended
+	nextLayerMapping[TestResultType+ExtendedTypeDecodeOffset] = LayerTypeTestResultExtended
 }
 
 func MsgTypeToNextLayer(mt MessageType, isExtended bool) (gopacket.LayerType, error) {
diff --git a/meframe_test.go b/meframe_test.go
index fd9d339..5a4d038 100644
--- a/meframe_test.go
+++ b/meframe_test.go
@@ -86,6 +86,10 @@
 	messageTypeTestFuncs[DownloadSectionRequestType+ExtendedTypeDecodeOffset] = testDownloadSectionRequestTypeMeFrame
 	// TODO: messageTypeTestFuncs[DownloadSectionRequestWithResponseType+ExtendedTypeDecodeOffset] = testDownloadSectionLastRequestTypeMeFrame
 	messageTypeTestFuncs[DownloadSectionResponseType+ExtendedTypeDecodeOffset] = testDownloadSectionResponseTypeMeFrame
+
+	messageTypeTestFuncs[AlarmNotificationType+ExtendedTypeDecodeOffset] = testAlarmNotificationTypeMeFrame
+	messageTypeTestFuncs[AttributeValueChangeType+ExtendedTypeDecodeOffset] = testAttributeValueChangeTypeMeFrame
+	messageTypeTestFuncs[TestResultType+ExtendedTypeDecodeOffset] = testTestResultTypeMeFrame
 }
 
 func getMEsThatSupportAMessageType(messageType MessageType) []*me.ManagedEntity {
diff --git a/messagetypes.go b/messagetypes.go
index dd908b6..4709f79 100644
--- a/messagetypes.go
+++ b/messagetypes.go
@@ -1673,7 +1673,7 @@
 type AlarmNotificationMsg struct {
 	MeBasePacket
 	AlarmBitmap         [AlarmBitmapSize / 8]byte
-	zeroPadding         [3]byte
+	zeroPadding         [3]byte // Note: This zero padding is not present in the Extended Message Set
 	AlarmSequenceNumber byte
 }
 
@@ -1795,17 +1795,28 @@
 	isUnsupported := classSupport == me.UnsupportedManagedEntity ||
 		classSupport == me.UnsupportedVendorSpecificManagedEntity
 
+	mapOffset := 4
+	if omci.Extended {
+		mapOffset = 6
+		if len(data) < 6+28+1 {
+			p.SetTruncated()
+			return errors.New("frame too small")
+		}
+	}
 	// Look for a non-nil/not empty Alarm Map to determine if this ME supports alarms
 	if alarmMap := meDefinition.GetAlarmMap(); isUnsupported || (alarmMap != nil && len(alarmMap) > 0) {
-		for index, octet := range data[4 : (AlarmBitmapSize/8)-4] {
+		for index, octet := range data[mapOffset : (AlarmBitmapSize/8)-mapOffset] {
 			omci.AlarmBitmap[index] = octet
 		}
-		padOffset := 4 + (AlarmBitmapSize / 8)
-		omci.zeroPadding[0] = data[padOffset]
-		omci.zeroPadding[1] = data[padOffset+1]
-		omci.zeroPadding[2] = data[padOffset+2]
-
-		omci.AlarmSequenceNumber = data[padOffset+3]
+		if omci.Extended {
+			omci.AlarmSequenceNumber = data[mapOffset+(AlarmBitmapSize/8)]
+		} else {
+			padOffset := mapOffset + (AlarmBitmapSize / 8)
+			omci.zeroPadding[0] = data[padOffset]
+			omci.zeroPadding[1] = data[padOffset+1]
+			omci.zeroPadding[2] = data[padOffset+2]
+			omci.AlarmSequenceNumber = data[padOffset+3]
+		}
 		return nil
 	}
 	return me.NewProcessingError("managed entity does not support alarm notifications")
@@ -1817,6 +1828,13 @@
 	return decodingLayerDecoder(omci, data, p)
 }
 
+func decodeAlarmNotificationExtended(data []byte, p gopacket.PacketBuilder) error {
+	omci := &AlarmNotificationMsg{}
+	omci.MsgLayerType = LayerTypeAlarmNotification
+	omci.Extended = true
+	return decodingLayerDecoder(omci, data, p)
+}
+
 // SerializeTo provides serialization of an Alarm Notification message
 func (omci *AlarmNotificationMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
 	// Basic (common) OMCI Header is 8 octets, 10
@@ -1824,29 +1842,40 @@
 	if err != nil {
 		return err
 	}
-	//var meDefinition me.IManagedEntityDefinition
-	//meDefinition, err = me.LoadManagedEntityDefinition(omci.EntityClass,
+	// TODO: Support of encoding AlarmNotification into supported types not yet supported
+	//meDefinition, omciErr := me.LoadManagedEntityDefinition(omci.EntityClass,
 	//	me.ParamData{EntityID: omci.EntityInstance})
-	//if err != nil {
-	//	return err
+	//if omciErr.StatusCode() != me.Success {
+	//	return omciErr.GetError()
 	//}
-	// ME needs to support Alarms
-	// TODO: Add attribute to ME to specify that alarm is allowed
-	//if !me.SupportsMsgType(meDefinition, me.MibReset) {
-	//	return me.NewProcessingError("managed entity does not support MIB Reset Message-Type")
+	//if !me.SupportsMsgType(meDefinition, me.AlarmNotification) {
+	//	return me.NewProcessingError("managed entity does not support Alarm Notification Message-Type")
 	//}
-	bytes, err := b.AppendBytes((AlarmBitmapSize / 8) + 3 + 1)
-	if err != nil {
-		return err
+	if omci.Extended {
+		bytes, err := b.AppendBytes(2 + (AlarmBitmapSize / 8) + 1)
+		if err != nil {
+			return err
+		}
+		binary.BigEndian.PutUint16(bytes, uint16((AlarmBitmapSize/8)+1))
+
+		for index, octet := range omci.AlarmBitmap {
+			bytes[2+index] = octet
+		}
+		bytes[2+(AlarmBitmapSize/8)] = omci.AlarmSequenceNumber
+	} else {
+		bytes, err := b.AppendBytes((AlarmBitmapSize / 8) + 3 + 1)
+		if err != nil {
+			return err
+		}
+		for index, octet := range omci.AlarmBitmap {
+			bytes[index] = octet
+		}
+		padOffset := AlarmBitmapSize / 8
+		bytes[padOffset] = 0
+		bytes[padOffset+1] = 0
+		bytes[padOffset+2] = 0
+		bytes[padOffset+3] = omci.AlarmSequenceNumber
 	}
-	for index, octet := range omci.AlarmBitmap {
-		bytes[index] = octet
-	}
-	padOffset := AlarmBitmapSize / 8
-	bytes[padOffset] = 0
-	bytes[padOffset+1] = 0
-	bytes[padOffset+2] = 0
-	bytes[padOffset+3] = omci.AlarmSequenceNumber
 	return nil
 }
 
@@ -1875,9 +1904,18 @@
 	if omciErr.StatusCode() != me.Success {
 		return omciErr.GetError()
 	}
-	omci.AttributeMask = binary.BigEndian.Uint16(data[4:6])
+	// TODO: Support for encoding AVC into message type support not yet supported
+	//if !me.SupportsMsgType(meDefinition, me.AlarmNotification) {
+	//	return me.NewProcessingError("managed entity does not support Alarm Notification Message-Type")
+	//}
+	maskOffset := 4
+	if omci.Extended {
+		maskOffset = 6
+	}
+	omci.AttributeMask = binary.BigEndian.Uint16(data[maskOffset:])
 	// Attribute decode
-	omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[6:40], p, byte(AttributeValueChangeType))
+	omci.Attributes, err = meDefinition.DecodeAttributes(omci.AttributeMask, data[maskOffset+2:],
+		p, byte(AttributeValueChangeType))
 	// TODO: Add support for attributes that can have an AVC associated with them and then add a check here
 	// Validate all attributes support AVC
 	//for attrName := range omci.attributes {
@@ -1899,6 +1937,13 @@
 	return decodingLayerDecoder(omci, data, p)
 }
 
+func decodeAttributeValueChangeExtended(data []byte, p gopacket.PacketBuilder) error {
+	omci := &AttributeValueChangeMsg{}
+	omci.MsgLayerType = LayerTypeAttributeValueChange
+	omci.Extended = true
+	return decodingLayerDecoder(omci, data, p)
+}
+
 // SerializeTo provides serialization of an Attribute Value Change Notification message
 func (omci *AttributeValueChangeMsg) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
 	// Basic (common) OMCI Header is 8 octets, 10
@@ -1923,18 +1968,36 @@
 	//		return me.NewProcessingError(msg)
 	//	}
 	//}
-	bytes, err := b.AppendBytes(2)
+	var maskOffset int
+	var bytesAvailable int
+	if omci.Extended {
+		maskOffset = 2
+		bytesAvailable = MaxExtendedLength - 12 - 4
+	} else {
+		maskOffset = 0
+		bytesAvailable = MaxBaselineLength - 10 - 8
+	}
+	bytes, err := b.AppendBytes(maskOffset + 2)
 	if err != nil {
 		return err
 	}
-	binary.BigEndian.PutUint16(bytes, omci.AttributeMask)
+	binary.BigEndian.PutUint16(bytes[maskOffset:], omci.AttributeMask)
 
 	// Attribute serialization
-	// TODO: Only Baseline supported at this time
-	bytesAvailable := MaxBaselineLength - 10 - 8
+	attributeBuffer := gopacket.NewSerializeBuffer()
+	if err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask,
+		attributeBuffer, byte(GetResponseType), bytesAvailable, false); err != nil {
+		return err
+	}
 
-	err, _ = meDefinition.SerializeAttributes(omci.Attributes, omci.AttributeMask, b,
-		byte(AttributeValueChangeType), bytesAvailable, false)
+	if omci.Extended {
+		binary.BigEndian.PutUint16(bytes, uint16(len(attributeBuffer.Bytes())+2))
+	}
+	bytes, err = b.AppendBytes(len(attributeBuffer.Bytes()))
+	if err != nil {
+		return err
+	}
+	copy(bytes, attributeBuffer.Bytes())
 	return err
 }
 
@@ -3635,6 +3698,31 @@
 	}
 }
 
+func decodeTestResultExtended(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
+		omci.Extended = true
+		return decodingLayerDecoder(omci, data, p)
+
+	case me.AniGClassID, me.ReAniGClassID, me.PhysicalPathTerminationPointReUniClassID,
+		me.ReUpstreamAmplifierClassID, me.ReDownstreamAmplifierClassID:
+		omci := &OpticalLineSupervisionTestResult{}
+		omci.MsgLayerType = LayerTypeTestResult
+		omci.Extended = true
+		return decodingLayerDecoder(omci, data, p)
+	}
+}
+
 type TestResultNotification struct {
 	MeBasePacket
 	Payload []byte
@@ -3651,7 +3739,11 @@
 // DecodeFromBytes decodes the given bytes of a Test Result Notification into this layer
 func (omci *TestResultNotification) DecodeFromBytes(data []byte, p gopacket.PacketBuilder) error {
 	// Common ClassID/EntityID decode in msgBase
-	err := omci.MeBasePacket.DecodeFromBytes(data, p, 4)
+	payloadOffset := 4
+	if omci.Extended {
+		payloadOffset = 6
+	}
+	err := omci.MeBasePacket.DecodeFromBytes(data, p, payloadOffset)
 	if err != nil {
 		return err
 	}
@@ -3666,8 +3758,22 @@
 	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)
+	if omci.Extended {
+		if len(data) < 6 {
+			p.SetTruncated()
+			return errors.New("frame too small")
+		}
+		length := binary.BigEndian.Uint16(data[4:])
+		if len(data) < 6+int(length) {
+			p.SetTruncated()
+			return errors.New("frame too small")
+		}
+		omci.Payload = make([]byte, length)
+		copy(omci.Payload, data[6:])
+	} else {
+		omci.Payload = make([]byte, MaxTestResultsLength)
+		copy(omci.Payload, omci.MeBasePacket.Payload)
+	}
 	return nil
 }
 
@@ -3692,17 +3798,27 @@
 	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)
+
+	payloadOffset := 0
+	maxSize := MaxTestResultsLength
+
+	if omci.Extended {
+		payloadOffset = 2
+		maxSize = MaxExtendedLength - 10 - 4
+	}
+	if len(omci.Payload) > maxSize {
+		msg := fmt.Sprintf("Invalid Test Results payload size. Received %v bytes, max expected %v",
+			len(omci.Payload), maxSize)
 		return errors.New(msg)
 	}
-	bytes, err := b.AppendBytes(len(omci.Payload))
+	bytes, err := b.AppendBytes(len(omci.Payload) + payloadOffset)
 	if err != nil {
 		return err
 	}
-
-	copy(bytes, omci.Payload)
+	if omci.Extended {
+		binary.BigEndian.PutUint16(bytes, uint16(len(omci.Payload)))
+	}
+	copy(bytes[payloadOffset:], omci.Payload)
 	return nil
 }
 
@@ -3735,7 +3851,11 @@
 // 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)
+	payloadOffset := 4
+	if omci.Extended {
+		payloadOffset = 6
+	}
+	err := omci.MeBasePacket.DecodeFromBytes(data, p, payloadOffset+17)
 	if err != nil {
 		return err
 	}
@@ -3753,26 +3873,26 @@
 	// 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:])
+	omci.PowerFeedVoltageType = data[payloadOffset]
+	omci.PowerFeedVoltage = binary.BigEndian.Uint16(data[payloadOffset+1:])
 
 	// Type = 3
-	omci.ReceivedOpticalPowerType = data[7]
-	omci.ReceivedOpticalPower = binary.BigEndian.Uint16(data[8:])
+	omci.ReceivedOpticalPowerType = data[payloadOffset+3]
+	omci.ReceivedOpticalPower = binary.BigEndian.Uint16(data[payloadOffset+4:])
 
 	// Type = 5
-	omci.MeanOpticalLaunchType = data[10]
-	omci.MeanOpticalLaunch = binary.BigEndian.Uint16(data[11:])
+	omci.MeanOpticalLaunchType = data[payloadOffset+6]
+	omci.MeanOpticalLaunch = binary.BigEndian.Uint16(data[payloadOffset+7:])
 
 	// Type = 9
-	omci.LaserBiasCurrentType = data[13]
-	omci.LaserBiasCurrent = binary.BigEndian.Uint16(data[14:])
+	omci.LaserBiasCurrentType = data[payloadOffset+9]
+	omci.LaserBiasCurrent = binary.BigEndian.Uint16(data[payloadOffset+10:])
 
 	// Type = 12
-	omci.TemperatureType = data[16]
-	omci.Temperature = binary.BigEndian.Uint16(data[17:])
+	omci.TemperatureType = data[payloadOffset+12]
+	omci.Temperature = binary.BigEndian.Uint16(data[payloadOffset+13:])
 
-	omci.GeneralPurposeBuffer = binary.BigEndian.Uint16(data[19:])
+	omci.GeneralPurposeBuffer = binary.BigEndian.Uint16(data[payloadOffset+15:])
 	return nil
 }
 
@@ -3793,22 +3913,30 @@
 	if !me.SupportsMsgType(meDefinition, me.Test) {
 		return me.NewProcessingError("managed entity does not support Test Message-Type")
 	}
-	bytes, err := b.AppendBytes(17)
+	payloadOffset := 0
+
+	if omci.Extended {
+		payloadOffset = 2
+	}
+	bytes, err := b.AppendBytes(payloadOffset + 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)
+	if omci.Extended {
+		binary.BigEndian.PutUint16(bytes, 17)
+	}
+	bytes[payloadOffset] = omci.PowerFeedVoltageType
+	binary.BigEndian.PutUint16(bytes[payloadOffset+1:], omci.PowerFeedVoltage)
+	bytes[payloadOffset+3] = omci.ReceivedOpticalPowerType
+	binary.BigEndian.PutUint16(bytes[payloadOffset+4:], omci.ReceivedOpticalPower)
+	bytes[payloadOffset+6] = omci.MeanOpticalLaunchType
+	binary.BigEndian.PutUint16(bytes[payloadOffset+7:], omci.MeanOpticalLaunch)
+	bytes[payloadOffset+9] = omci.LaserBiasCurrentType
+	binary.BigEndian.PutUint16(bytes[payloadOffset+10:], omci.LaserBiasCurrent)
+	bytes[payloadOffset+12] = omci.TemperatureType
+	binary.BigEndian.PutUint16(bytes[payloadOffset+13:], omci.Temperature)
+	binary.BigEndian.PutUint16(bytes[payloadOffset+15:], omci.GeneralPurposeBuffer)
 	return nil
 }
 
diff --git a/messagetypes_test.go b/messagetypes_test.go
index 399fc34..5420e99 100644
--- a/messagetypes_test.go
+++ b/messagetypes_test.go
@@ -4049,5 +4049,360 @@
 	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
 }
 
+func TestExtendedAlarmNotificationDecode(t *testing.T) {
+	//                                   1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+	goodMessage := "0000100b000b0104001d8000000000000000000000000000000000000000000000000000000005"
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, omciLayer)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
+	assert.Equal(t, AlarmNotificationType, omciMsg.MessageType)
+	assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, uint16(29), omciMsg.Length)
+
+	msgLayer := packet.Layer(LayerTypeAlarmNotification)
+	assert.NotNil(t, msgLayer)
+
+	request, ok2 := msgLayer.(*AlarmNotificationMsg)
+	assert.True(t, ok2)
+	assert.NotNil(t, request)
+	assert.Equal(t, me.PhysicalPathTerminationPointEthernetUniClassID, request.EntityClass)
+	assert.Equal(t, uint16(0x104), request.EntityInstance)
+	assert.Equal(t, [28]byte{
+		0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	}, request.AlarmBitmap)
+	assert.Equal(t, byte(5), request.AlarmSequenceNumber)
+
+	// Active/Clear tests
+	active, err2 := request.IsAlarmActive(0)
+	clear, err3 := request.IsAlarmClear(0)
+	assert.Nil(t, err2)
+	assert.Nil(t, err3)
+	assert.True(t, active)
+	assert.False(t, clear)
+
+	// Active/Clear for undefined alarm bits
+	active, err2 = request.IsAlarmActive(1)
+	clear, err3 = request.IsAlarmClear(1)
+	assert.NotNil(t, err2)
+	assert.NotNil(t, err3)
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
+}
+
+func TestExtendedAlarmNotificationSerialize(t *testing.T) {
+	//                                   1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8
+	goodMessage := "0000100b000b0104001d8000000000000000000000000000000000000000000000000000000005"
+
+	omciLayer := &OMCI{
+		TransactionID:    0,
+		MessageType:      AlarmNotificationType,
+		DeviceIdentifier: ExtendedIdent,
+		// Length parameter is optional for Extended message format serialization
+		// and if present it will be overwritten during the serialization with the
+		// actual value.
+	}
+	request := &AlarmNotificationMsg{
+		MeBasePacket: MeBasePacket{
+			EntityClass:    me.PhysicalPathTerminationPointEthernetUniClassID,
+			EntityInstance: uint16(0x104),
+			Extended:       true,
+		},
+		AlarmBitmap: [28]byte{
+			0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+		},
+		AlarmSequenceNumber: byte(5),
+	}
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+}
+
+func TestExtendedAttributeValueChangeDecode(t *testing.T) {
+	// Software Image Version (14 bytes) AVC
+	goodMessage := "0000110b00070000001080004d4c2d3336323600000000000000"
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, omciLayer)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0), omciMsg.TransactionID)
+	assert.Equal(t, AttributeValueChangeType, omciMsg.MessageType)
+	assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, uint16(2+14), omciMsg.Length)
+
+	msgLayer := packet.Layer(LayerTypeAttributeValueChange)
+	assert.NotNil(t, msgLayer)
+
+	request, ok2 := msgLayer.(*AttributeValueChangeMsg)
+	assert.True(t, ok2)
+	assert.NotNil(t, request)
+	assert.Equal(t, uint16(0x8000), request.AttributeMask)
+	assert.Equal(t, me.SoftwareImageClassID, request.EntityClass)
+	assert.Equal(t, uint16(0), request.EntityInstance)
+	assert.Equal(t, []byte{
+		0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36,
+		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, request.Attributes["Version"])
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
+}
+
+func TestExtendedAttributeValueChangeSerialize(t *testing.T) {
+	goodMessage := "0000110b00070000001080004d4c2d3336323600000000000000"
+
+	omciLayer := &OMCI{
+		TransactionID:    0,
+		MessageType:      AttributeValueChangeType,
+		DeviceIdentifier: ExtendedIdent,
+		// Length parameter is optional for Extended message format serialization
+		// and if present it will be overwritten during the serialization with the
+		// actual value.
+	}
+	request := &AttributeValueChangeMsg{
+		MeBasePacket: MeBasePacket{
+			EntityClass:    me.SoftwareImageClassID,
+			EntityInstance: uint16(0),
+			Extended:       true,
+		},
+		AttributeMask: uint16(0x8000),
+		Attributes: me.AttributeValueMap{
+			"Version": []byte{
+				0x4d, 0x4c, 0x2d, 0x33, 0x36, 0x32, 0x36,
+				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			},
+		},
+	}
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+}
+
+func TestExtendedGenericTestResultDecode(t *testing.T) {
+	// ONU-G ME for this test with just made up data
+	payload := "1234567890123456789012345678901234567890"
+	resultLen := len(payload) / 2
+	goodMessage := "00001b0b01000000" + fmt.Sprintf("%04x", resultLen) + payload
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, omciLayer)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0000), omciMsg.TransactionID)
+	assert.Equal(t, TestResultType, omciMsg.MessageType)
+	assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, omciMsg.Length, uint16(resultLen))
+
+	msgLayer := packet.Layer(LayerTypeTestResult)
+	assert.NotNil(t, msgLayer)
+
+	// This is a generic struct since we do not do detailed decode
+	generic, ok2 := msgLayer.(*TestResultNotification)
+	assert.True(t, ok2)
+	assert.NotNil(t, generic)
+	assert.NotNil(t, generic.MeBasePacket.Payload) // Next three all same data
+	assert.NotNil(t, generic.Payload)
+	assert.NotNil(t, generic.TestResults())
+
+	base := generic.MeBasePacket
+	assert.Equal(t, me.OnuGClassID, base.EntityClass)
+	assert.Equal(t, uint16(0), base.EntityInstance)
+
+	// For the generic Test Result, get the payload data which is all the data in
+	// the test notification past the Entity Instance value.
+	payloadData, payloadErr := stringToPacket(payload)
+	assert.NotNil(t, payloadData)
+	assert.NoError(t, payloadErr)
+	assert.Equal(t, payloadData, base.Payload)
+	assert.Equal(t, payloadData, generic.Payload)
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
+}
+
+func TestExtendedOpticalLineSupervisionTestResultDecode(t *testing.T) {
+	// ANI-G ME for this test with just made up data
+	payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901"
+	resultLen := len(payload) / 2
+	goodMessage := "00001b0b01078001" + fmt.Sprintf("%04x", resultLen) + payload
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, omciLayer)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0000), omciMsg.TransactionID)
+	assert.Equal(t, TestResultType, omciMsg.MessageType)
+	assert.Equal(t, ExtendedIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, uint16(resultLen), omciMsg.Length)
+
+	msgLayer := packet.Layer(LayerTypeTestResult)
+	assert.NotNil(t, msgLayer)
+
+	// This is a optical line test results
+	optical, ok2 := msgLayer.(*OpticalLineSupervisionTestResult)
+	assert.True(t, ok2)
+	assert.NotNil(t, optical)
+
+	// Get the Managed Entity class ID and instance ID from the base packet
+	base := optical.MeBasePacket
+	assert.Equal(t, me.AniGClassID, base.EntityClass)
+	assert.Equal(t, uint16(0x8001), base.EntityInstance)
+
+	assert.Equal(t, uint8(1), optical.PowerFeedVoltageType)
+	assert.Equal(t, uint16(0x34), optical.PowerFeedVoltage)
+
+	assert.Equal(t, uint8(3), optical.ReceivedOpticalPowerType)
+	assert.Equal(t, uint16(0x67), optical.ReceivedOpticalPower)
+
+	assert.Equal(t, uint8(5), optical.MeanOpticalLaunchType)
+	assert.Equal(t, uint16(0x91), optical.MeanOpticalLaunch)
+
+	assert.Equal(t, uint8(9), optical.LaserBiasCurrentType)
+	assert.Equal(t, uint16(0x34), optical.LaserBiasCurrent)
+
+	assert.Equal(t, uint8(12), optical.TemperatureType)
+	assert.Equal(t, uint16(0x67), optical.Temperature)
+
+	assert.Equal(t, uint16(0x8901), optical.GeneralPurposeBuffer)
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
+}
+
+func TestExtendedGenericTestResultSerialize(t *testing.T) {
+	payload := "12345678901234567890"
+	resultLen := len(payload) / 2
+	goodMessage := "00001b0b01000000" + fmt.Sprintf("%04x", resultLen) + payload
+
+	omciLayer := &OMCI{
+		// TransactionID: 0x0c,						// Optional for notifications since TID always 0x0000
+		MessageType:      TestResultType,
+		DeviceIdentifier: ExtendedIdent,
+		// Length parameter is optional for Extended message format serialization
+		// and if present it will be overwritten during the serialization with the
+		// actual value.
+	}
+	data, derr := stringToPacket(payload)
+	assert.NoError(t, derr)
+
+	request := &TestResultNotification{
+		MeBasePacket: MeBasePacket{
+			EntityClass:    me.OnuGClassID,
+			EntityInstance: uint16(0),
+			Extended:       true,
+		},
+		Payload: data,
+	}
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+}
+
+func TestExtendedOpticalLineSupervisionTestResultSerialize(t *testing.T) {
+	// ANI-G ME for this test with just made up data
+	payload := "010034" + "030067" + "050091" + "090034" + "0c0067" + "8901"
+	resultLen := len(payload) / 2
+	goodMessage := "00001b0b01078001" + fmt.Sprintf("%04x", resultLen) + payload
+
+	omciLayer := &OMCI{
+		// TransactionID: 0x0c,						// Optional for notifications since TID always 0x0000
+		MessageType:      TestResultType,
+		DeviceIdentifier: ExtendedIdent,
+		// Length parameter is optional for Extended message format serialization
+		// and if present it will be overwritten during the serialization with the
+		// actual value.
+	}
+	request := &OpticalLineSupervisionTestResult{
+		MeBasePacket: MeBasePacket{
+			EntityClass:    me.AniGClassID,
+			EntityInstance: uint16(0x8001),
+			Extended:       true,
+		},
+		PowerFeedVoltageType:     uint8(1),
+		PowerFeedVoltage:         uint16(0x34),
+		ReceivedOpticalPowerType: uint8(3),
+		ReceivedOpticalPower:     uint16(0x67),
+		MeanOpticalLaunchType:    uint8(5),
+		MeanOpticalLaunch:        uint16(0x91),
+		LaserBiasCurrentType:     uint8(9),
+		LaserBiasCurrent:         uint16(0x34),
+		TemperatureType:          uint8(12),
+		Temperature:              uint16(0x67),
+		GeneralPurposeBuffer:     uint16(0x8901),
+	}
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+}
+
 // TODO: Also remember to add extended message tests to the meframe_test.go
 //       unit tests as more message types are supported