2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub"
24 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststubdummy"
25 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststube2ap"
26 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
35 func CaseBegin(desc string) *teststub.TestWrapper {
36 tent := teststub.NewTestWrapper(desc)
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 const teststubPortSeed int = 55555
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 var xappConn1 *teststube2ap.E2Stub
51 var xappConn2 *teststube2ap.E2Stub
52 var e2termConn1 *teststube2ap.E2Stub
53 var e2termConn2 *teststube2ap.E2Stub
54 var rtmgrHttp *testingHttpRtmgrStub
55 var mainCtrl *testingSubmgrControl
57 var dummystub *teststubdummy.RmrDummyStub
59 func ut_test_init() func() {
60 tent := CaseBegin("ut_test_init")
62 //---------------------------------
64 //---------------------------------
65 rtmgrHttp = createNewHttpRtmgrStub("RTMGRSTUB", "8989")
68 //---------------------------------
70 //---------------------------------
73 //Cfg creation won't work like this as xapp-frame reads it during init.
84 "protPort": "tcp:14560",
87 "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ"],
88 "rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION"]
93 "namespaces": ["sdl", "rnib"]
96 "HostAddr" : "localhost",
102 cfgfilename,_ := testCreateTmpFile(cfgstr)
103 defer os.Remove(cfgfilename)
104 os.Setenv("CFG_FILE", cfgfilename)
106 tent.Info("Using cfg file %s", os.Getenv("CFG_FILE"))
108 //---------------------------------
109 // Static routetable for rmr
111 // NOTE: Routing table is configured so, that responses
112 // are duplicated to xapp1 and xapp2 instances.
113 // If XID is not matching xapp stub will just
114 // drop message. (Messages 12011, 12012, 12021, 12022)
116 // NOTE2: teststubPortSeed message type is for stub rmr connectivity probing
118 // NOTE3: Ports per entity:
121 // -------------------
123 mainsrc := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 14560}}
124 xapp1src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 13560}}
125 xapp2src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 13660}}
126 e2term1src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 15560}}
127 e2term2src := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 15660}}
128 dummysrc := teststub.RmrSrcId{xapp.RmrEndpoint{"localhost", 16560}}
130 //---------------------------------
131 rt := &teststub.RmrRouteTable{}
132 rt.AddRoute(12010, "", -1, mainsrc.String())
133 rt.AddRoute(12010, mainsrc.String(), -1, "%meid")
134 rt.AddRoute(12011, e2term1src.String(), -1, mainsrc.String())
135 rt.AddRoute(12012, e2term1src.String(), -1, mainsrc.String())
136 rt.AddRoute(12011, e2term2src.String(), -1, mainsrc.String())
137 rt.AddRoute(12012, e2term2src.String(), -1, mainsrc.String())
138 rt.AddRoute(12011, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String())
139 rt.AddRoute(12012, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String())
140 rt.AddRoute(12020, "", -1, mainsrc.String())
141 rt.AddRoute(12020, mainsrc.String(), -1, "%meid")
142 rt.AddRoute(12021, e2term1src.String(), -1, mainsrc.String())
143 rt.AddRoute(12022, e2term1src.String(), -1, mainsrc.String())
144 rt.AddRoute(12021, e2term2src.String(), -1, mainsrc.String())
145 rt.AddRoute(12022, e2term2src.String(), -1, mainsrc.String())
146 rt.AddRoute(12021, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String())
147 rt.AddRoute(12022, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String())
148 rt.AddRoute(teststubPortSeed, "", -1, xapp2src.String()+";"+xapp1src.String()+";"+e2term1src.String()+";"+e2term2src.String()+";"+dummysrc.String())
150 rt.AddMeid(e2term1src.String(), []string{"RAN_NAME_1", "RAN_NAME_2"})
151 rt.AddMeid(e2term2src.String(), []string{"RAN_NAME_11", "RAN_NAME_12"})
154 tent.Info("rttable[%s]", rt.Table())
156 //---------------------------------
158 //---------------------------------
159 tent.Info("### submgr ctrl run ###")
160 mainCtrl = createSubmgrControl(mainsrc, teststub.RmrRtgSvc{})
163 // Tweak to get around with fact that alarm package alternates RMR_SEED_RT environment variable
165 //xapp-frame inits alarms when readycb is coming from xapps rmr
166 //alarm will make new rmr instance and overrides RMR_SEED_RT and RMR_RTG_SVC
167 //env variables. Re-create rt info.
168 for i := 0; i < int(10)*2; i++ {
169 if os.Getenv("RMR_SEED_RT") == rt.FileName() {
170 tent.Info("Waiting that alarm alternates RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT"))
171 time.Sleep(500 * time.Millisecond)
173 tent.Info("Alarm has alternated RMR_SEED_RT=%s, so waiting 0.5 secs before restoring it", os.Getenv("RMR_SEED_RT"))
174 time.Sleep(500 * time.Millisecond)
176 tent.Info("rttable[%s]", rt.Table())
181 if os.Getenv("RMR_SEED_RT") != rt.FileName() {
182 tent.Error("Unittest timing issue with alarm RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT"))
186 //---------------------------------
188 //---------------------------------
189 tent.Info("### xapp1 stub run ###")
190 xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", xapp1src, teststub.RmrRtgSvc{}, "RMRXAPP1STUB", teststubPortSeed)
192 //---------------------------------
194 //---------------------------------
195 tent.Info("### xapp2 stub run ###")
196 xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", xapp2src, teststub.RmrRtgSvc{}, "RMRXAPP2STUB", teststubPortSeed)
198 //---------------------------------
200 //---------------------------------
201 tent.Info("### e2term1 stub run ###")
202 e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", e2term1src, teststub.RmrRtgSvc{}, "RMRE2TERMSTUB1", teststubPortSeed)
204 //---------------------------------
206 //---------------------------------
207 tent.Info("### e2term2 stub run ###")
208 e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", e2term2src, teststub.RmrRtgSvc{}, "RMRE2TERMSTUB2", teststubPortSeed)
210 //---------------------------------
211 // Just to test dummy stub
212 //---------------------------------
213 tent.Info("### dummy stub run ###")
214 dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", dummysrc, teststub.RmrRtgSvc{}, "DUMMYSTUB", teststubPortSeed)
216 //---------------------------------
217 // Testing message sending
218 //---------------------------------
219 if teststub.RmrStubControlWaitAlive(10, teststubPortSeed, mainCtrl.c.RMRClient, tent) == false {
223 if os.Getenv("RMR_SEED_RT") != rt.FileName() {
224 tent.Error("Unittest timing issue with alarm RMR_SEED_RT=%s", os.Getenv("RMR_SEED_RT"))
228 return func() { rt.Disable() }
231 //-----------------------------------------------------------------------------
233 //-----------------------------------------------------------------------------
234 func TestMain(m *testing.M) {
235 CaseBegin("TestMain start")
236 cleanfn := ut_test_init()