Merge "Adding configuration for rmr"
diff --git a/config/configuration.go b/config/configuration.go
new file mode 100644
index 0000000..e67083a
--- /dev/null
+++ b/config/configuration.go
@@ -0,0 +1,69 @@
+/*
+==================================================================================
+  Copyright (c) 2023 Samsung
+
+   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.
+
+   This source code is part of the near-RT RIC (RAN Intelligent Controller)
+   platform project (RICP).
+==================================================================================
+*/
+package config
+
+import (
+	"os"
+
+	"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
+	"github.com/spf13/viper"
+)
+
+type Configuration struct {
+	LogLevel          string
+	Name              string
+	MaxSize           int
+	ThreadType        int
+	LowLatency        bool
+	FastAck           bool
+	MaxRetryOnFailure int
+	Port              int
+}
+
+func ParseConfiguration() *Configuration {
+	viper.SetConfigType("yaml")
+	viper.SetConfigName("configuration")
+	configFile := os.Getenv("A1_CONFIG_FILE")
+	viper.SetConfigFile(configFile)
+	err := viper.ReadInConfig()
+	if err != nil {
+		a1.Logger.Info("#configuration.ParseConfiguration - failed to read configuration file: %s\n", err)
+	}
+
+	config := Configuration{}
+	config.LogLevel = viper.GetString("log-level")
+	viper.SetDefault("log-level", "info")
+	config.Name = viper.GetString("NAME")
+	viper.SetDefault("NAME", "")
+	config.MaxSize = viper.GetInt("MAX_SIZE")
+	viper.SetDefault("MAX_SIZE", 65534)
+	config.ThreadType = viper.GetInt("THREAD_TYPE")
+	viper.SetDefault("THREAD_TYPE", 0)
+	config.LowLatency = viper.GetBool("LOW_LATENCY")
+	viper.SetDefault("LOW_LATENCY", false)
+	config.FastAck = viper.GetBool("FAST_ACK")
+	viper.SetDefault("FAST_ACK", false)
+	config.MaxRetryOnFailure = viper.GetInt("MAX_RETRY_ON_FAILURE")
+	viper.SetDefault("MAX_RETRY_ON_FAILURE", 1)
+	config.Port = viper.GetInt("PORT")
+	viper.SetDefault("PORT", 4561)
+	return &config
+}
diff --git a/go.mod b/go.mod
index a78b02b..1f58f26 100644
--- a/go.mod
+++ b/go.mod
@@ -44,6 +44,7 @@
 	github.com/stretchr/testify v1.6.1
 	golang.org/x/net v0.0.0-20210428140749-89ef3d95e781
 	gopkg.in/yaml.v2 v2.4.0
+	github.com/spf13/viper v1.7.0
 )
 
 require (
diff --git a/pkg/resthooks/resthooks.go b/pkg/resthooks/resthooks.go
index 49df6f4..79e52fa 100644
--- a/pkg/resthooks/resthooks.go
+++ b/pkg/resthooks/resthooks.go
@@ -396,7 +396,7 @@
 			a1.Logger.Error("error : %v", err)
 			return err
 		}
-		isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1PolicyRequest)
+		isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1PolicyRequest, int(policyTypeId))
 		if isSent {
 			a1.Logger.Debug("rmrSendToXapp : message sent")
 		} else {
@@ -713,7 +713,7 @@
 		a1.Logger.Error("error : %v", err1)
 		return err1
 	}
-	isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1PolicyRequest)
+	isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1PolicyRequest, int(policyTypeId))
 	if isSent {
 		a1.Logger.Debug("rmrSendToXapp : message sent")
 	} else {
@@ -734,7 +734,7 @@
 		return err
 	}
 	a1.Logger.Debug("rmrSendToXapp :rmrMessage %+v", rmrMessage)
-	isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1EIDataDelivery)
+	isSent := rh.iRmrSenderInst.RmrSendToXapp(rmrMessage, a1EIDataDelivery, rmr.DefaultSubId)
 	if isSent {
 		a1.Logger.Debug("rmrSendToXapp : message sent")
 	} else {
diff --git a/pkg/resthooks/resthooks_test.go b/pkg/resthooks/resthooks_test.go
index 01d11e7..11afe47 100644
--- a/pkg/resthooks/resthooks_test.go
+++ b/pkg/resthooks/resthooks_test.go
@@ -155,7 +155,7 @@
 	a1.Logger.Debug("metadatainstancekey   : %+v", metadatainstancekey)
 	metadatainstancearr := []interface{}{metadatainstancekey, string(metadata)}
 	sdlInst.On("Set", "A1m_ns", metadatainstancearr).Return(nil)
-	rmrSenderInst.On("RmrSendToXapp", "httpBodyString", 20010).Return(true)
+	rmrSenderInst.On("RmrSendToXapp", "httpBodyString", 20010, int(policyTypeId)).Return(true)
 
 	errresp := rh.CreatePolicyInstance(policyTypeId, policyInstanceID, instancedata)
 
@@ -303,7 +303,7 @@
 
 	httpBodyString := `{"operation":"DELETE","payload":"","policy_instance_id":"123456","policy_type_id":"20001"}`
 
-	rmrSenderInst.On("RmrSendToXapp", httpBodyString, 20010).Return(true)
+	rmrSenderInst.On("RmrSendToXapp", httpBodyString, 20010, int(policyTypeId)).Return(true)
 
 	errresp := rh.DeletePolicyInstance(policyTypeId, policyInstanceID)
 
@@ -322,7 +322,7 @@
 	json.Unmarshal([]byte(httpBody), &instancedata)
 	a1.Logger.Debug("Marshaled data : %+v", (instancedata))
 	httpBodyString := `{"ei_job_id":"1","payload":"payload"}`
-	rmrSenderInst.On("RmrSendToXapp", httpBodyString, 20017).Return(true)
+	rmrSenderInst.On("RmrSendToXapp", httpBodyString, 20017, -1).Return(true)
 	errresp := rh.DataDelivery(instancedata)
 
 	assert.Nil(t, errresp)
@@ -412,12 +412,12 @@
 	return args.Bool(0), args.Error(1)
 }
 
-func (rmr *RmrSenderMock) RmrSendToXapp(httpBodyString string, mtype int) bool {
+func (rmr *RmrSenderMock) RmrSendToXapp(httpBodyString string, mtype int, subid int) bool {
 	if httpBodyString == `{"blocking_rate":20,"enforce":true,"trigger_threshold":10,"window_length":20}` {
-		args := rmr.MethodCalled("RmrSendToXapp", httpBodyString, mtype)
+		args := rmr.MethodCalled("RmrSendToXapp", httpBodyString, mtype, subid)
 		return args.Bool(0)
 	} else if httpBodyString == `{"ei_job_id":"1","payload":"payload"}` {
-		args := rmr.MethodCalled("RmrSendToXapp", httpBodyString, mtype)
+		args := rmr.MethodCalled("RmrSendToXapp", httpBodyString, mtype, subid)
 		return args.Bool(0)
 	}
 	return true
diff --git a/pkg/rmr/rmr.go b/pkg/rmr/rmr.go
index c0366af..d9ec0f0 100644
--- a/pkg/rmr/rmr.go
+++ b/pkg/rmr/rmr.go
@@ -29,6 +29,7 @@
 	"net/http"
 	"strconv"
 
+	"gerrit.o-ran-sc.org/r/ric-plt/a1/config"
 	"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/a1"
 	"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/models"
 	"gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/policy"
@@ -44,6 +45,7 @@
 	a1EiQueryAllResp  = 20014
 	a1EiCreateJobResp = 20016
 	jobCreationData   = `{"ei_job_id": %s.}`
+	DefaultSubId      = -1
 )
 
 type RmrSender struct {
@@ -52,21 +54,22 @@
 }
 
 type IRmrSender interface {
-	RmrSendToXapp(httpBodyString string, messagetype int) bool
+	RmrSendToXapp(httpBodyString string, messagetype int, subid int) bool
 }
 
 func NewRMRSender(policyManager *policy.PolicyManager) IRmrSender {
+	config := config.ParseConfiguration()
 	RMRclient := xapp.NewRMRClientWithParams(&xapp.RMRClientParams{
 		StatDesc: "",
 		RmrData: xapp.PortData{
-			//TODO: Read configuration from config file
-			Name:              "",
-			MaxSize:           65534,
-			ThreadType:        0,
-			LowLatency:        false,
-			FastAck:           false,
-			MaxRetryOnFailure: 1,
-			Port:              4561,
+
+			Name:              config.Name,
+			MaxSize:           config.MaxSize,
+			ThreadType:        config.ThreadType,
+			LowLatency:        config.LowLatency,
+			FastAck:           config.FastAck,
+			MaxRetryOnFailure: config.MaxRetryOnFailure,
+			Port:              config.Port,
 		},
 	})
 
@@ -99,11 +102,11 @@
 	return
 }
 
-func (rmr *RmrSender) RmrSendToXapp(httpBodyString string, messagetype int) bool {
+func (rmr *RmrSender) RmrSendToXapp(httpBodyString string, messagetype int, subid int) bool {
 
 	params := &xapp.RMRParams{}
 	params.Mtype = messagetype
-	params.SubId = -1
+	params.SubId = subid
 	params.Xid = ""
 	params.Meid = &xapp.RMRMeid{}
 	params.Src = a1SourceName
@@ -164,7 +167,7 @@
 				return err1
 			}
 			a1.Logger.Debug("rmrMessage ", rmrMessage)
-			isSent := rmr.RmrSendToXapp(rmrMessage, a1PolicyRequest)
+			isSent := rmr.RmrSendToXapp(rmrMessage, a1PolicyRequest, int(policytypeid))
 			if isSent {
 				a1.Logger.Debug("rmrSendToXapp : message sent")
 			} else {
@@ -192,7 +195,7 @@
 
 		a1.Logger.Debug("response : %+v", string(respByte))
 
-		isSent := rmr.RmrSendToXapp(string(respByte), a1EiQueryAllResp)
+		isSent := rmr.RmrSendToXapp(string(respByte), a1EiQueryAllResp, DefaultSubId)
 		if isSent {
 			a1.Logger.Debug("rmrSendToXapp : message sent")
 		} else {
@@ -241,7 +244,7 @@
 			rmrData := fmt.Sprintf(jobCreationData, jobIdStr)
 			a1.Logger.Debug("rmr_Data to send: ", rmrData)
 
-			isSent := rmr.RmrSendToXapp(rmrData, a1EiCreateJobResp)
+			isSent := rmr.RmrSendToXapp(rmrData, a1EiCreateJobResp, DefaultSubId)
 			if isSent {
 				a1.Logger.Debug("rmrSendToXapp : message sent")
 			} else {