SEBA-400 Add omci_defs file for standard OMCI msg definitions and parsing.

Change-Id: I9b5612b5d8966ecd8547ff25ff7f25c7565821c7
diff --git a/core/omci.go b/core/omci.go
index c9860c2..6a55416 100644
--- a/core/omci.go
+++ b/core/omci.go
@@ -17,77 +17,17 @@
 package core
 
 import (
-	"bytes"
 	"encoding/binary"
+	"time"
 
 	"context"
 	"errors"
-	"time"
 
 	"gerrit.opencord.org/voltha-bbsim/common/logger"
 	"gerrit.opencord.org/voltha-bbsim/device"
 	"gerrit.opencord.org/voltha-bbsim/protos"
 )
 
-//
-// OMCI definitions
-//
-
-// OmciMsgType represents a OMCI message-type
-type OmciMsgType byte
-
-const (
-	// Message Types
-	_                                 = iota
-	Create                OmciMsgType = 4
-	Delete                OmciMsgType = 6
-	Set                   OmciMsgType = 8
-	Get                   OmciMsgType = 9
-	GetAllAlarms          OmciMsgType = 11
-	GetAllAlarmsNext      OmciMsgType = 12
-	MibUpload             OmciMsgType = 13
-	MibUploadNext         OmciMsgType = 14
-	MibReset              OmciMsgType = 15
-	AlarmNotification     OmciMsgType = 16
-	AttributeValueChange  OmciMsgType = 17
-	Test                  OmciMsgType = 18
-	StartSoftwareDownload OmciMsgType = 19
-	DownloadSection       OmciMsgType = 20
-	EndSoftwareDownload   OmciMsgType = 21
-	ActivateSoftware      OmciMsgType = 22
-	CommitSoftware        OmciMsgType = 23
-	SynchronizeTime       OmciMsgType = 24
-	Reboot                OmciMsgType = 25
-	GetNext               OmciMsgType = 26
-	TestResult            OmciMsgType = 27
-	GetCurrentData        OmciMsgType = 28
-	SetTable              OmciMsgType = 29 // Defined in Extended Message Set Only
-)
-
-const (
-	// Managed Entity Class values
-	GEMPortNetworkCTP OmciClass = 268
-)
-
-// OMCI Managed Entity Class
-type OmciClass uint16
-
-// OMCI Message Identifier
-type OmciMessageIdentifier struct {
-	Class    OmciClass
-	Instance uint16
-}
-
-type OmciContent [32]byte
-
-type OmciMessage struct {
-	TransactionId uint16
-	MessageType   OmciMsgType
-	DeviceId      uint8
-	MessageId     OmciMessageIdentifier
-	Content       OmciContent
-}
-
 const NumMibUploads byte = 26
 
 type OnuKey struct {
@@ -150,7 +90,7 @@
 			var resp openolt.OmciIndication
 			select {
 			case m := <-omciOut:
-				transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(m.Pkt)
+				transactionId, deviceId, msgType, class, instance, content, err := ParsePkt(HexDecode(m.Pkt))
 				if err != nil {
 					errch <- err
 					return
@@ -188,20 +128,6 @@
 	}()
 }
 
-func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) {
-	var m OmciMessage
-
-	r := bytes.NewReader(HexDecode(pkt))
-
-	if err := binary.Read(r, binary.BigEndian, &m); err != nil {
-		logger.Error("binary.Read failed: %s", err)
-		return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
-	}
-	logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
-		m.TransactionId, m.MessageType&0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content)
-	return m.TransactionId, m.DeviceId, m.MessageType & 0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil
-}
-
 func HexDecode(pkt []byte) []byte {
 	// Convert the hex encoding to binary
 	// TODO - Change openolt adapter to send raw binary instead of hex encoded
diff --git a/core/omci_defs.go b/core/omci_defs.go
new file mode 100644
index 0000000..1de2f41
--- /dev/null
+++ b/core/omci_defs.go
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package core
+
+import (
+	"bytes"
+	"encoding/binary"
+	"errors"
+
+	"gerrit.opencord.org/voltha-bbsim/common/logger"
+)
+
+//
+// OMCI definitions
+//
+
+// OmciMsgType represents a OMCI message-type
+type OmciMsgType byte
+
+const (
+	// Message Types
+	_                                 = iota
+	Create                OmciMsgType = 4
+	Delete                OmciMsgType = 6
+	Set                   OmciMsgType = 8
+	Get                   OmciMsgType = 9
+	GetAllAlarms          OmciMsgType = 11
+	GetAllAlarmsNext      OmciMsgType = 12
+	MibUpload             OmciMsgType = 13
+	MibUploadNext         OmciMsgType = 14
+	MibReset              OmciMsgType = 15
+	AlarmNotification     OmciMsgType = 16
+	AttributeValueChange  OmciMsgType = 17
+	Test                  OmciMsgType = 18
+	StartSoftwareDownload OmciMsgType = 19
+	DownloadSection       OmciMsgType = 20
+	EndSoftwareDownload   OmciMsgType = 21
+	ActivateSoftware      OmciMsgType = 22
+	CommitSoftware        OmciMsgType = 23
+	SynchronizeTime       OmciMsgType = 24
+	Reboot                OmciMsgType = 25
+	GetNext               OmciMsgType = 26
+	TestResult            OmciMsgType = 27
+	GetCurrentData        OmciMsgType = 28
+	SetTable              OmciMsgType = 29 // Defined in Extended Message Set Only
+)
+
+const (
+	// Managed Entity Class values
+	GEMPortNetworkCTP OmciClass = 268
+)
+
+// OMCI Managed Entity Class
+type OmciClass uint16
+
+// OMCI Message Identifier
+type OmciMessageIdentifier struct {
+	Class    OmciClass
+	Instance uint16
+}
+
+type OmciContent [32]byte
+
+type OmciMessage struct {
+	TransactionId uint16
+	MessageType   OmciMsgType
+	DeviceId      uint8
+	MessageId     OmciMessageIdentifier
+	Content       OmciContent
+}
+
+func ParsePkt(pkt []byte) (uint16, uint8, OmciMsgType, OmciClass, uint16, OmciContent, error) {
+	var m OmciMessage
+
+	r := bytes.NewReader(pkt)
+
+	if err := binary.Read(r, binary.BigEndian, &m); err != nil {
+		logger.Error("binary.Read failed: %s", err)
+		return 0, 0, 0, 0, 0, OmciContent{}, errors.New("binary.Read failed")
+	}
+	logger.Debug("OmciRun - TransactionId: %d MessageType: %d, ME Class: %d, ME Instance: %d, Content: %x",
+		m.TransactionId, m.MessageType&0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content)
+	return m.TransactionId, m.DeviceId, m.MessageType & 0x0F, m.MessageId.Class, m.MessageId.Instance, m.Content, nil
+}