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")
49 logger, err := logger.InitLogger(logLevel)
51 fmt.Printf("#app.main - failed to initialize logger, error: %s", err)
55 var rmrContext *rmr.Context
56 var rmrConfig = rmr.Config{Port: RMR_PORT_DEFAULT, MaxMsgSize: rmr.RMR_MAX_MSG_SIZE, MaxRetries: 10, Flags: 0}
58 if port, err := strconv.ParseUint(os.Getenv(ENV_RMR_PORT), 10, 16); err == nil {
59 rmrConfig.Port = int(port)
61 logger.Infof("#main - %s: %s, using default (%d).", ENV_RMR_PORT, err, RMR_PORT_DEFAULT)
64 rmrService = rmr.NewService(rmrConfig, rmrContext)
65 jsonSender := sender.NewJsonSender(logger)
66 dispatcherDesc := dispatcher.New(logger, rmrService, jsonSender)
68 /* Load configuration file*/
69 err = frontend.ProcessConfigurationFile("resources", "conf", ".json",
70 func(data []byte) error {
71 return frontend.JsonCommandsDecoder(data, dispatcherDesc.JsonCommandsDecoderCB)
75 logger.Errorf("#main - processing error: %s", err)
79 logger.Infof("#main - xApp Mock is up and running...")
82 cmd := flag.Arg(0) /*first remaining argument after flags have been processed*/
84 command, err := frontend.DecodeJsonCommand([]byte(cmd))
87 logger.Errorf("#main - command decoding error: %s", err)
88 rmrService.CloseContext()
89 logger.Infof("#main - xApp Mock is down")
93 c := make(chan os.Signal, 1)
94 signal.Notify(c, os.Interrupt)
95 ctx, cancel := context.WithCancel(context.Background())
99 logger.Infof("system call:%+v", oscall)
101 rmrService.CloseContext()
104 dispatcherDesc.ProcessJsonCommand(ctx, command)
105 pr := dispatcherDesc.GetProcessResult()
108 logger.Errorf("#main - command processing Error: %s", pr.Err)
111 if pr.StartTime != nil {
112 processElapsedTimeInMs := float64(time.Since(*pr.StartTime)) / float64(time.Millisecond)
113 logger.Infof("#main - processing (sending/receiving) messages took %.2f ms", processElapsedTimeInMs)
116 logger.Infof("#main - process stats: %s", pr.Stats)
118 rmrService.CloseContext() // TODO: called twice
119 logger.Infof("#main - xApp Mock is down")