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.
33 ENV_RMR_PORT = "RMR_PORT"
34 RMR_PORT_DEFAULT = 5001
37 var rmrService *rmr.Service
40 var rmrContext *rmr.Context
41 var rmrConfig = rmr.Config{Port: RMR_PORT_DEFAULT, MaxMsgSize: rmr.RMR_MAX_MSG_SIZE, MaxRetries: 10, Flags: 0}
43 if port, err := strconv.ParseUint(os.Getenv(ENV_RMR_PORT), 10, 16); err == nil {
44 rmrConfig.Port = int(port)
46 log.Printf("#main - %s: %s, using default (%d).", ENV_RMR_PORT, err, RMR_PORT_DEFAULT)
49 rmrService = rmr.NewService(rmrConfig, rmrContext)
50 dispatcherDesc := dispatcher.New(rmrService)
52 /* Load configuration file*/
53 err := frontend.ProcessConfigurationFile("resources", "conf", ".json",
54 func(data []byte) error {
55 return frontend.JsonCommandsDecoder(data, dispatcherDesc.JsonCommandsDecoderCB)
59 log.Fatalf("#main - processing error: %s", err)
62 log.Print("#main - xApp Mock is up and running...")
65 cmd := flag.Arg(0) /*first remaining argument after flags have been processed*/
67 command, err := frontend.DecodeJsonCommand([]byte(cmd))
70 log.Printf("#main - command decoding error: %s", err)
71 rmrService.CloseContext()
72 log.Print("#main - xApp Mock is down")
76 c := make(chan os.Signal, 1)
77 signal.Notify(c, os.Interrupt)
78 ctx, cancel := context.WithCancel(context.Background())
82 log.Printf("system call:%+v", oscall)
84 rmrService.CloseContext()
87 processStartTime := time.Now()
88 dispatcherDesc.ProcessJsonCommand(ctx, command)
89 pr := dispatcherDesc.GetProcessResult()
92 log.Printf("#main - command processing Error: %s", err)
95 processElapsedTimeInMs := float64(time.Since(processStartTime)) / float64(time.Millisecond)
97 log.Printf("#main - processing (sending/receiving) messages took %.2f ms", processElapsedTimeInMs)
98 log.Printf("#main - process result: %s", pr)
100 rmrService.CloseContext() // TODO: called twice
101 log.Print("#main - xApp Mock is down")