VOL-2841: Remove old backward compatible omci message checking code

New onu and openomci library now sends a proper byte array for the
message, so no need to check.

Note, openolt agent still expects the hex string.  Once that
is fixed and both adapter and agent released then the final TODO
can go away.

Also make omci message tracing through openolt a bit easier by
adding the omci transaction id

Change-Id: I79d3519365d3f03d668e4fdc2e5ae9e0d323a96e
diff --git a/internal/pkg/core/device_handler.go b/internal/pkg/core/device_handler.go
index 1390e1d..3d7a5ad 100644
--- a/internal/pkg/core/device_handler.go
+++ b/internal/pkg/core/device_handler.go
@@ -19,6 +19,7 @@
 
 import (
 	"context"
+	"encoding/binary"
 	"encoding/hex"
 	"fmt"
 	"github.com/opencord/voltha-lib-go/v3/pkg/flows"
@@ -502,7 +503,7 @@
 		}()
 	case *oop.Indication_OmciInd:
 		omciInd := indication.GetOmciInd()
-		logger.Debugw("Received Omci indication ", log.Fields{"IntfId": omciInd.IntfId, "OnuId": omciInd.OnuId, "pkt": hex.EncodeToString(omciInd.Pkt)})
+		logger.Debugw("Received Omci indication ", log.Fields{"IntfId": omciInd.IntfId, "OnuId": omciInd.OnuId})
 		go func() {
 			if err := dh.omciIndication(omciInd); err != nil {
 				olterrors.NewErrAdapter("handle-indication-error", log.Fields{"type": "omci"}, err).Log()
@@ -839,6 +840,10 @@
 	var deviceID string
 	var proxyDeviceID string
 
+	transid := extractOmciTransactionID(omciInd.Pkt)
+	logger.Debugw("recv-omci-msg", log.Fields{"intfID": omciInd.IntfId, "onuID": omciInd.OnuId,
+		"omciTransactionID": transid, "omciMsg": hex.EncodeToString(omciInd.Pkt)})
+
 	onuKey := dh.formOnuKey(omciInd.IntfId, omciInd.OnuId)
 
 	if onuInCache, ok := dh.onus.Load(onuKey); !ok {
@@ -951,22 +956,18 @@
 			"onu-id":       onuID}, nil)
 	}
 
-	// TODO: Once we are sure openonu/openomci is sending only binary in omciMsg.Message, we can remove this check
-	isHexString := false
-	_, decodeerr := hex.DecodeString(string(omciMsg.Message))
-	if decodeerr == nil {
-		isHexString = true
-	}
-
-	// TODO: OpenOLT Agent expects a hex string for OMCI packets rather than binary.  Fix this in the agent and then we can pass binary Pkt: omciMsg.Message.
+	// TODO: OpenOLT Agent oop.OmciMsg expects a hex encoded string for OMCI packets rather than the actual bytes.
+	//  Fix this in the agent and then we can pass byte array as Pkt: omciMsg.Message.
 	var omciMessage *oop.OmciMsg
-	if isHexString {
-		omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: omciMsg.Message}
-	} else {
-		hexPkt := make([]byte, hex.EncodedLen(len(omciMsg.Message)))
-		hex.Encode(hexPkt, omciMsg.Message)
-		omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt}
-	}
+	hexPkt := make([]byte, hex.EncodedLen(len(omciMsg.Message)))
+	hex.Encode(hexPkt, omciMsg.Message)
+	omciMessage = &oop.OmciMsg{IntfId: intfID, OnuId: onuID, Pkt: hexPkt}
+
+	// TODO: Below logging illustrates the "stringify" of the omci Pkt.
+	//  once above is fixed this log line can change to just use hex.EncodeToString(omciMessage.Pkt)
+	transid := extractOmciTransactionID(omciMsg.Message)
+	logger.Debugw("sent-omci-msg", log.Fields{"intfID": intfID, "onuID": onuID,
+		"omciTransactionID": transid, "omciMsg": string(omciMessage.Pkt)})
 
 	_, err := dh.Client.OmciMsgOut(context.Background(), omciMessage)
 	if err != nil {
@@ -975,7 +976,6 @@
 			"onu-id":       onuID,
 			"message":      omciMessage}, err)
 	}
-	logger.Debugw("Sent Omci message", log.Fields{"intfID": intfID, "onuID": onuID, "omciMsg": hex.EncodeToString(omciMsg.Message)})
 	return nil
 }
 
@@ -2124,3 +2124,12 @@
 
 	return InvalidPort, InvalidPort
 }
+
+func extractOmciTransactionID(omciPkt []byte) uint16 {
+	if len(omciPkt) > 3 {
+		d := omciPkt[0:2]
+		transid := binary.BigEndian.Uint16(d)
+		return transid
+	}
+	return 0
+}