blob: 38bd322be2043d8b3e9592a1c32b6b5db3c2a061 [file] [log] [blame]
Juha Hyttinenfa015662020-01-24 10:05:18 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
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==================================================================================
18*/
19
20package control
21
22import (
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020023 "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"
Juha Hyttinenfa015662020-01-24 10:05:18 +020026 "os"
Juha Hyttinenfa015662020-01-24 10:05:18 +020027 "testing"
Juha Hyttinenfa015662020-01-24 10:05:18 +020028)
29
30//-----------------------------------------------------------------------------
31//
32//-----------------------------------------------------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020033func CaseBegin(desc string) *teststub.TestWrapper {
34 tent := teststub.NewTestWrapper(desc)
35 tent.Logger.Info(desc)
36 return tent
Juha Hyttinenfa015662020-01-24 10:05:18 +020037}
38
39//-----------------------------------------------------------------------------
40//
41//-----------------------------------------------------------------------------
42
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020043var xappConn1 *teststube2ap.E2Stub
44var xappConn2 *teststube2ap.E2Stub
45var e2termConn *teststube2ap.E2Stub
Juha Hyttinenfa015662020-01-24 10:05:18 +020046var rtmgrHttp *testingHttpRtmgrStub
47var mainCtrl *testingSubmgrControl
48
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020049var dummystub *teststubdummy.RmrDummyStub
50
Juha Hyttinenfa015662020-01-24 10:05:18 +020051func ut_test_init() {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020052 tent := CaseBegin("ut_test_init")
Juha Hyttinenfa015662020-01-24 10:05:18 +020053
54 //---------------------------------
55 //
56 //---------------------------------
57 rtmgrHttp = createNewHttpRtmgrStub("RTMGRSTUB", "8989")
58 go rtmgrHttp.run()
59
60 //---------------------------------
61 //
62 //---------------------------------
63
64 //
65 //Cfg creation won't work like this as xapp-frame reads it during init.
66 //
67 /*
68 cfgstr:=`{
69 "local": {
70 "host": ":8080"
71 },
72 "logger": {
73 "level": 4
74 },
75 "rmr": {
76 "protPort": "tcp:14560",
77 "maxSize": 4096,
78 "numWorkers": 1,
79 "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ"],
80 "rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION"]
81 },
82 "db": {
83 "host": "localhost",
84 "port": 6379,
85 "namespaces": ["sdl", "rnib"]
86 },
87 "rtmgr" : {
88 "HostAddr" : "localhost",
89 "port" : "8989",
90 "baseUrl" : "/"
91 }
92 `
93
94 cfgfilename,_ := testCreateTmpFile(cfgstr)
95 defer os.Remove(cfgfilename)
96 os.Setenv("CFG_FILE", cfgfilename)
97 */
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020098 tent.Logger.Info("Using cfg file %s", os.Getenv("CFG_FILE"))
Juha Hyttinenfa015662020-01-24 10:05:18 +020099
100 //---------------------------------
101 // Static routetable for rmr
102 //
103 // NOTE: Routing table is configured so, that responses
104 // are duplicated to xapp1 and xapp2 instances.
105 // If XID is not matching xapp stub will just
106 // drop message. (Messages 12011, 12012, 12021, 12022)
107 //
108 // NOTE2: 55555 message type is for stub rmr connectivity probing
109 //
110 // NOTE3: Ports per entity:
111 //
112 // Port Entity
113 // -------------------
114 // 14560 submgr
115 // 15560 e2term stub
116 // 13560 xapp1 stub
117 // 13660 xapp2 stub
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200118 // 16560 dummy stub
Juha Hyttinenfa015662020-01-24 10:05:18 +0200119 //
120 //---------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200121 rt := &teststub.RmrRouteTable{}
122 rt.AddEntry(12010, "", -1, "localhost:14560")
123 rt.AddEntry(12010, "localhost:14560", -1, "localhost:15560")
124 rt.AddEntry(12011, "localhost:15560", -1, "localhost:14560")
125 rt.AddEntry(12012, "localhost:15560", -1, "localhost:14560")
126 rt.AddEntry(12011, "localhost:14560", -1, "localhost:13660;localhost:13560")
127 rt.AddEntry(12012, "localhost:14560", -1, "localhost:13660;localhost:13560")
128 rt.AddEntry(12020, "", -1, "localhost:14560")
129 rt.AddEntry(12020, "localhost:14560", -1, "localhost:15560")
130 rt.AddEntry(12021, "localhost:15560", -1, "localhost:14560")
131 rt.AddEntry(12022, "localhost:15560", -1, "localhost:14560")
132 rt.AddEntry(12021, "localhost:14560", -1, "localhost:13660;localhost:13560")
133 rt.AddEntry(12022, "localhost:14560", -1, "localhost:13660;localhost:13560")
134 rt.AddEntry(55555, "", -1, "localhost:13660;localhost:13560;localhost:15560;localhost:16560")
Juha Hyttinenfa015662020-01-24 10:05:18 +0200135
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200136 rtfilename, _ := teststub.CreateTmpFile(rt.GetRt())
137 defer os.Remove(rtfilename)
Juha Hyttinenfa015662020-01-24 10:05:18 +0200138
139 //---------------------------------
140 //
141 //---------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200142 tent.Logger.Info("### submgr ctrl run ###")
143 mainCtrl = createSubmgrControl(rtfilename, "14560")
Juha Hyttinenfa015662020-01-24 10:05:18 +0200144
145 //---------------------------------
146 //
147 //---------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200148 tent.Logger.Info("### xapp1 stub run ###")
149 xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", rtfilename, "13560", "RMRXAPP1STUB", 55555)
Juha Hyttinenfa015662020-01-24 10:05:18 +0200150
151 //---------------------------------
152 //
153 //---------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200154 tent.Logger.Info("### xapp2 stub run ###")
155 xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", rtfilename, "13660", "RMRXAPP2STUB", 55555)
Juha Hyttinenfa015662020-01-24 10:05:18 +0200156
157 //---------------------------------
158 //
159 //---------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200160 tent.Logger.Info("### e2term stub run ###")
161 e2termConn = teststube2ap.CreateNewE2termStub("e2termstub", rtfilename, "15560", "RMRE2TERMSTUB", 55555)
162
163 //---------------------------------
164 // Just to test dummy stub
165 //---------------------------------
166 tent.Logger.Info("### dummy stub run ###")
167 dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", rtfilename, "16560", "DUMMYSTUB", 55555)
Juha Hyttinenfa015662020-01-24 10:05:18 +0200168
169 //---------------------------------
170 // Testing message sending
171 //---------------------------------
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200172 if teststub.RmrStubControlWaitAlive(10, 55555, mainCtrl.c) == false {
Juha Hyttinenfa015662020-01-24 10:05:18 +0200173 os.Exit(1)
174 }
175}
176
177//-----------------------------------------------------------------------------
178//
179//-----------------------------------------------------------------------------
180func TestMain(m *testing.M) {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200181 CaseBegin("TestMain start")
Juha Hyttinenfa015662020-01-24 10:05:18 +0200182 ut_test_init()
183 code := m.Run()
184 os.Exit(code)
185}