2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 // platform project (RICP).
39 ENV_RMR_PORT = "RMR_PORT"
40 RMR_PORT_DEFAULT = 5001
43 var rmrService *rmr.Service
47 logLevel, _ := logger.LogLevelTokenToLevel("info")
48 logger, err := logger.InitLogger(logLevel)
50 fmt.Printf("#app.main - failed to initialize logger, error: %s", err)
54 var rmrContext *rmr.Context
55 var rmrConfig = rmr.Config{Port: RMR_PORT_DEFAULT, MaxMsgSize: rmr.RMR_MAX_MSG_SIZE, MaxRetries: 10, Flags: 0}
57 if port, err := strconv.ParseUint(os.Getenv(ENV_RMR_PORT), 10, 16); err == nil {
58 rmrConfig.Port = int(port)
60 logger.Infof("#main - %s: %s, using default (%d).", ENV_RMR_PORT, err, RMR_PORT_DEFAULT)
63 rmrService = rmr.NewService(rmrConfig, rmrContext)
64 jsonSender := sender.NewJsonSender(logger)
65 dispatcherDesc := dispatcher.New(logger, rmrService, jsonSender)
67 /* Load configuration file*/
68 err = frontend.ProcessConfigurationFile("resources", "conf", ".json",
69 func(data []byte) error {
70 return frontend.JsonCommandsDecoder(data, dispatcherDesc.JsonCommandsDecoderCB)
74 logger.Errorf("#main - processing error: %s", err)
78 logger.Infof("#main - xApp Mock is up and running...")
81 cmd := flag.Arg(0) /*first remaining argument after flags have been processed*/
83 command, err := frontend.DecodeJsonCommand([]byte(cmd))
86 logger.Errorf("#main - command decoding error: %s", err)
87 rmrService.CloseContext()
88 logger.Infof("#main - xApp Mock is down")
92 c := make(chan os.Signal, 1)
93 signal.Notify(c, os.Interrupt)
94 ctx, cancel := context.WithCancel(context.Background())
98 logger.Infof("system call:%+v", oscall)
100 rmrService.CloseContext()
103 dispatcherDesc.ProcessJsonCommand(ctx, command)
104 pr := dispatcherDesc.GetProcessResult()
107 logger.Errorf("#main - command processing Error: %s", pr.Err)
110 if pr.StartTime != nil {
111 processElapsedTimeInMs := float64(time.Since(*pr.StartTime)) / float64(time.Millisecond)
112 logger.Infof("#main - processing (sending/receiving) messages took %.2f ms", processElapsedTimeInMs)
115 logger.Infof("#main - process stats: %s", pr.Stats)
117 rmrService.CloseContext() // TODO: called twice
118 logger.Infof("#main - xApp Mock is down")