RICPLT-3007 Replace msg Mtype numbers with variables defined in xapp frame

Change-Id: Ibc35c4d82ce7fb126c1949b1a304fdd04be2e923
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
diff --git a/pkg/control/control.go b/pkg/control/control.go
index b189071..52571aa 100755
--- a/pkg/control/control.go
+++ b/pkg/control/control.go
@@ -22,7 +22,6 @@
 import (
 	"fmt"
 	"gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
-	"gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer"
 	rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
 	rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle"
 	"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
@@ -135,29 +134,29 @@
 	return
 }
 
-func (c *Control) rmrSend(desc string, subs *Subscription, trans *Transaction, payload *packer.PackedData) (err error) {
+func (c *Control) rmrSend(desc string, subs *Subscription, trans *Transaction) (err error) {
 	params := &RMRParams{&xapp.RMRParams{}}
 	params.Mtype = trans.GetMtype()
 	params.SubId = int(subs.GetSubId())
 	params.Xid = ""
 	params.Meid = subs.GetMeid()
 	params.Src = ""
-	params.PayloadLen = len(payload.Buf)
-	params.Payload = payload.Buf
+	params.PayloadLen = len(trans.Payload.Buf)
+	params.Payload = trans.Payload.Buf
 	params.Mbuf = nil
 
 	return c.rmrSendRaw(desc, params)
 }
 
-func (c *Control) rmrReplyToSender(desc string, subs *Subscription, trans *Transaction, mType int, payload *packer.PackedData) (err error) {
+func (c *Control) rmrReplyToSender(desc string, subs *Subscription, trans *Transaction) (err error) {
 	params := &RMRParams{&xapp.RMRParams{}}
-	params.Mtype = mType
+	params.Mtype = trans.GetMtype()
 	params.SubId = int(subs.GetSubId())
 	params.Xid = trans.GetXid()
 	params.Meid = trans.GetMeid()
 	params.Src = ""
-	params.PayloadLen = len(payload.Buf)
-	params.Payload = payload.Buf
+	params.PayloadLen = len(trans.Payload.Buf)
+	params.Payload = trans.Payload.Buf
 	params.Mbuf = nil
 
 	return c.rmrSendRaw(desc, params)
@@ -195,7 +194,6 @@
 	//
 	//
 	trans, err := c.tracker.TrackTransaction(NewRmrEndpoint(params.Src),
-		params.Mtype,
 		params.Xid,
 		params.Meid,
 		false,
@@ -244,7 +242,7 @@
 	//
 	//       This is intermediate solution while improving message handling
 	//
-	trans.Payload, err = c.e2ap.PackSubscriptionRequest(trans.SubReqMsg)
+	trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(trans.SubReqMsg)
 	if err != nil {
 		xapp.Logger.Error("SubReq: %s for trans %s", err.Error(), trans)
 		subs.Release()
@@ -252,7 +250,7 @@
 		return
 	}
 
-	c.rmrSend("SubReq: SubReq to E2T", subs, trans, trans.Payload)
+	c.rmrSend("SubReq: SubReq to E2T", subs, trans)
 
 	c.timerMap.StartTimer("RIC_SUB_REQ", int(subs.GetSubId()), subReqTime, FirstTry, c.handleSubscriptionRequestTimer)
 	xapp.Logger.Debug("SubReq: Debugging trans table = %v", c.tracker.transactionXappTable)
@@ -307,7 +305,7 @@
 		return
 	}
 
-	trans.Payload, err = c.e2ap.PackSubscriptionResponse(trans.SubRespMsg)
+	trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(trans.SubRespMsg)
 	if err != nil {
 		xapp.Logger.Error("SubResp: %s for trans %s", err.Error(), trans)
 		trans.Release()
@@ -316,7 +314,7 @@
 
 	subs.Confirmed()
 	trans.Release()
-	c.rmrReplyToSender("SubResp: SubResp to xapp", subs, trans, 12011, trans.Payload)
+	c.rmrReplyToSender("SubResp: SubResp to xapp", subs, trans)
 	return
 }
 
@@ -371,9 +369,9 @@
 		return
 	}
 
-	trans.Payload, err = c.e2ap.PackSubscriptionFailure(trans.SubFailMsg)
+	trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(trans.SubFailMsg)
 	if err == nil {
-		c.rmrReplyToSender("SubFail: SubFail to xapp", subs, trans, 12012, trans.Payload)
+		c.rmrReplyToSender("SubFail: SubFail to xapp", subs, trans)
 		time.Sleep(3 * time.Second)
 	} else {
 		//TODO error handling improvement
@@ -408,11 +406,11 @@
 	}
 
 	if tryCount < maxSubReqTryCount {
-		xapp.Logger.Info("SubReq timeout: Resending SubReq to E2T: Mtype: %v, SubId: %v, Xid %s, Meid %v", trans.GetMtype(), subs.GetSubId(), trans.GetXid(), trans.GetMeid())
+		xapp.Logger.Info("SubReq timeout: subs: %s trans: %s", subs, trans)
 
 		trans.RetryTransaction()
 
-		c.rmrSend("SubReq timeout: SubReq to E2T", subs, trans, trans.Payload)
+		c.rmrSend("SubReq timeout: SubReq to E2T", subs, trans)
 
 		tryCount++
 		c.timerMap.StartTimer("RIC_SUB_REQ", int(subs.GetSubId()), subReqTime, tryCount, c.handleSubscriptionRequestTimer)
@@ -424,7 +422,6 @@
 
 	// Create DELETE transaction (internal and no messages toward xapp)
 	deltrans, err := c.tracker.TrackTransaction(&trans.RmrEndpoint,
-		12020, // RIC SUBSCRIPTION DELETE
 		trans.GetXid(),
 		trans.GetMeid(),
 		false,
@@ -441,7 +438,7 @@
 	deltrans.SubDelReqMsg.RequestId.Id = trans.SubReqMsg.RequestId.Id
 	deltrans.SubDelReqMsg.RequestId.Seq = uint32(subs.GetSubId())
 	deltrans.SubDelReqMsg.FunctionId = trans.SubReqMsg.FunctionId
-	deltrans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(deltrans.SubDelReqMsg)
+	deltrans.Mtype, deltrans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(deltrans.SubDelReqMsg)
 	if err != nil {
 		xapp.Logger.Error("SubReq timeout: Packing SubDelReq failed. Err: %v", err)
 		//TODO improve error handling. Important at least in merge
@@ -458,7 +455,7 @@
 		return
 	}
 
-	c.rmrSend("SubReq timer: SubDelReq to E2T", subs, deltrans, deltrans.Payload)
+	c.rmrSend("SubReq timer: SubDelReq to E2T", subs, deltrans)
 	c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer)
 	return
 }
@@ -470,7 +467,6 @@
 	//
 	//
 	trans, err := c.tracker.TrackTransaction(NewRmrEndpoint(params.Src),
-		params.Mtype,
 		params.Xid,
 		params.Meid,
 		false,
@@ -521,7 +517,7 @@
 	//
 	//       This is intermediate solution while improving message handling
 	//
-	trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(trans.SubDelReqMsg)
+	trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(trans.SubDelReqMsg)
 	if err != nil {
 		xapp.Logger.Error("SubDelReq: %s for trans %s", err.Error(), trans)
 		trans.Release()
@@ -530,7 +526,7 @@
 
 	subs.UnConfirmed()
 
-	c.rmrSend("SubDelReq: SubDelReq to E2T", subs, trans, trans.Payload)
+	c.rmrSend("SubDelReq: SubDelReq to E2T", subs, trans)
 
 	c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer)
 	return
@@ -663,7 +659,7 @@
 	if tryCount < maxSubDelReqTryCount {
 		// Set possible to handle new response for the subId
 		trans.RetryTransaction()
-		c.rmrSend("SubDelReq timeout: SubDelReq to E2T", subs, trans, trans.Payload)
+		c.rmrSend("SubDelReq timeout: SubDelReq to E2T", subs, trans)
 		tryCount++
 		c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subReqTime, tryCount, c.handleSubscriptionDeleteRequestTimer)
 		return
@@ -683,9 +679,9 @@
 		trans.SubDelRespMsg.FunctionId = trans.SubDelReqMsg.FunctionId
 
 		var err error
-		trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(trans.SubDelRespMsg)
+		trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(trans.SubDelRespMsg)
 		if err == nil {
-			c.rmrReplyToSender(desc+": SubDelResp to xapp", subs, trans, 12021, trans.Payload)
+			c.rmrReplyToSender(desc+": SubDelResp to xapp", subs, trans)
 			time.Sleep(3 * time.Second)
 		} else {
 			//TODO error handling improvement