Fixed Unit Test Cases
[ric-plt/rtmgr.git] / pkg / rtmgr / rtmgr.go
index 9dd956e..3c4f4e5 100644 (file)
    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).
+
 ==================================================================================
 */
 /*
   Mnemonic:    rtmgr/rtmgr.go
-  Abstract:    Containes RTMGR (Routing Manager) module's generic variables and functions
+  Abstract:    Contains RTMGR (Routing Manager) module's generic variables and functions
   Date:                26 March 2019
 */
 
 package rtmgr
 
 import (
-       "github.com/jcelliott/lumber"
+       "encoding/json"
+       "errors"
+       "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+       "github.com/ghodss/yaml"
+       "io/ioutil"
+       "os"
+       "strings"
 )
 
 var (
-       //TODO: temporary solution
-       // CamelCase Message Types are for being able to test with old fashioned admin controll xApps
-       MESSAGETYPES = map[string]string{
-               "HandoverPreparation":              "0",
-               "HandoverCancel":                   "1",
-               "LoadIndication":                   "2",
-               "ErrorIndication":                  "3",
-               "SNStatusTransfer":                 "4",
-               "UEContextRelease":                 "5",
-               "X2Setup":                          "6",
-               "Reset":                            "7",
-               "RIC_X2_SETUP":                     "10000",
-               "RIC_X2_RESPONSE":                  "10001",
-               "RIC_X2_RESOURCE_STATUS_REQUEST":   "10002",
-               "RIC_X2_RESOURCE_STATUS_RESPONSE":  "10003",
-               "RIC_X2_LOAD_INFORMATION":          "10004",
-               "RIC_E2_TERMINATION_HC_REQUEST":    "10005",
-               "RIC_E2_TERMINATION_HC_RESPONSE":   "10006",
-               "RIC_E2_MANAGER_HC_REQUEST":        "10007",
-               "RIC_E2_MANAGER_HC_RESPONSE":       "10008",
-               "RIC_CONTROL_XAPP_CONFIG_REQUEST":  "100000",
-               "RIC_CONTROL_XAPP_CONFIG_RESPONSE": "100001",
-       }
-       Logger = lumber.NewConsoleLogger(lumber.INFO)
-       Eps Endpoints
+       Eps              Endpoints
+       Subs             SubscriptionList
+       PrsCfg           *PlatformRoutes
+       Mtype            MessageTypeList
+       DynamicRouteList []string
+       RMRConnStatus    map[string]bool
 )
 
-func SetLogLevel(loglevel string) {
-       switch loglevel {
-       case "INFO":
-               Logger.Level(lumber.INFO)
-       case "WARN":
-               Logger.Level(lumber.WARN)
-       case "ERROR":
-               Logger.Level(lumber.ERROR)
-       case "DEBUG":
-               Logger.Info("debugmode")
-               Logger.Level(lumber.DEBUG)
+func GetPlatformComponents(configfile string) (*PlatformComponents, error) {
+       xapp.Logger.Debug("Invoked rtmgr.GetPlatformComponents(" + configfile + ")")
+       var rcfg ConfigRtmgr
+       var rtroutes RtmgrRoutes
+       var mtypes MessageTypeIdentifier
+       yamlFile, err := os.Open(configfile)
+       if err != nil {
+               return nil, errors.New("cannot open the file due to: " + err.Error())
        }
-}
+       defer yamlFile.Close()
+       byteValue, err := ioutil.ReadAll(yamlFile)
+       if err != nil {
+               return nil, errors.New("cannot read the file due to: " + err.Error())
+       }
+       jsonByteValue, err := yaml.YAMLToJSON(byteValue)
+       if err != nil {
+               return nil, errors.New("cannot read the file due to: " + err.Error())
+       }
+       err = json.Unmarshal(jsonByteValue, &rtroutes)
+       if err != nil {
+               return nil, errors.New("cannot parse data due to: " + err.Error())
+       }
+       PrsCfg = &(rtroutes.Prs)
 
+       err = json.Unmarshal(jsonByteValue, &mtypes)
+       if err != nil {
+               return nil, errors.New("cannot parse data due to: " + err.Error())
+       } else {
+               xapp.Logger.Debug("Messgaetypes = %v", mtypes)
+               for _, m := range mtypes.Mit {
+                       splitstr := strings.Split(m, "=")
+                       Mtype[splitstr[0]] = splitstr[1]
+               }
+       }
+       err = json.Unmarshal(jsonByteValue, &rcfg)
+       if err != nil {
+               return nil, errors.New("cannot parse data due to: " + err.Error())
+       }
+       xapp.Logger.Debug("Platform components read from the configfile:  %v", rcfg.Pcs)
+       return &(rcfg.Pcs), nil
+}