Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package control |
| 21 | |
| 22 | import ( |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 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" |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 26 | "os" |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 27 | "testing" |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 28 | ) |
| 29 | |
| 30 | //----------------------------------------------------------------------------- |
| 31 | // |
| 32 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 33 | func CaseBegin(desc string) *teststub.TestWrapper { |
| 34 | tent := teststub.NewTestWrapper(desc) |
| 35 | tent.Logger.Info(desc) |
| 36 | return tent |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | //----------------------------------------------------------------------------- |
| 40 | // |
| 41 | //----------------------------------------------------------------------------- |
| 42 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 43 | var xappConn1 *teststube2ap.E2Stub |
| 44 | var xappConn2 *teststube2ap.E2Stub |
Juha Hyttinen | 896c3ac | 2020-02-24 12:49:20 +0200 | [diff] [blame^] | 45 | var e2termConn1 *teststube2ap.E2Stub |
| 46 | var e2termConn2 *teststube2ap.E2Stub |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 47 | var rtmgrHttp *testingHttpRtmgrStub |
| 48 | var mainCtrl *testingSubmgrControl |
| 49 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 50 | var dummystub *teststubdummy.RmrDummyStub |
| 51 | |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 52 | func ut_test_init() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 53 | tent := CaseBegin("ut_test_init") |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 54 | |
| 55 | //--------------------------------- |
| 56 | // |
| 57 | //--------------------------------- |
| 58 | rtmgrHttp = createNewHttpRtmgrStub("RTMGRSTUB", "8989") |
| 59 | go rtmgrHttp.run() |
| 60 | |
| 61 | //--------------------------------- |
| 62 | // |
| 63 | //--------------------------------- |
| 64 | |
| 65 | // |
| 66 | //Cfg creation won't work like this as xapp-frame reads it during init. |
| 67 | // |
| 68 | /* |
| 69 | cfgstr:=`{ |
| 70 | "local": { |
| 71 | "host": ":8080" |
| 72 | }, |
| 73 | "logger": { |
| 74 | "level": 4 |
| 75 | }, |
| 76 | "rmr": { |
| 77 | "protPort": "tcp:14560", |
| 78 | "maxSize": 4096, |
| 79 | "numWorkers": 1, |
| 80 | "txMessages": ["RIC_SUB_REQ", "RIC_SUB_DEL_REQ"], |
| 81 | "rxMessages": ["RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE", "RIC_INDICATION"] |
| 82 | }, |
| 83 | "db": { |
| 84 | "host": "localhost", |
| 85 | "port": 6379, |
| 86 | "namespaces": ["sdl", "rnib"] |
| 87 | }, |
| 88 | "rtmgr" : { |
| 89 | "HostAddr" : "localhost", |
| 90 | "port" : "8989", |
| 91 | "baseUrl" : "/" |
| 92 | } |
| 93 | ` |
| 94 | |
| 95 | cfgfilename,_ := testCreateTmpFile(cfgstr) |
| 96 | defer os.Remove(cfgfilename) |
| 97 | os.Setenv("CFG_FILE", cfgfilename) |
| 98 | */ |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 99 | tent.Logger.Info("Using cfg file %s", os.Getenv("CFG_FILE")) |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 100 | |
| 101 | //--------------------------------- |
| 102 | // Static routetable for rmr |
| 103 | // |
| 104 | // NOTE: Routing table is configured so, that responses |
| 105 | // are duplicated to xapp1 and xapp2 instances. |
| 106 | // If XID is not matching xapp stub will just |
| 107 | // drop message. (Messages 12011, 12012, 12021, 12022) |
| 108 | // |
| 109 | // NOTE2: 55555 message type is for stub rmr connectivity probing |
| 110 | // |
| 111 | // NOTE3: Ports per entity: |
| 112 | // |
| 113 | // Port Entity |
| 114 | // ------------------- |
| 115 | // 14560 submgr |
Juha Hyttinen | 896c3ac | 2020-02-24 12:49:20 +0200 | [diff] [blame^] | 116 | // 15560 e2term1 stub |
| 117 | // 15660 e2term2 stub |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 118 | // 13560 xapp1 stub |
| 119 | // 13660 xapp2 stub |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 120 | // 16560 dummy stub |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 121 | // |
| 122 | //--------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 123 | rt := &teststub.RmrRouteTable{} |
Juha Hyttinen | 896c3ac | 2020-02-24 12:49:20 +0200 | [diff] [blame^] | 124 | rt.AddRoute(12010, "", -1, "localhost:14560") |
| 125 | rt.AddRoute(12010, "localhost:14560", -1, "%meid") |
| 126 | rt.AddRoute(12011, "localhost:15560", -1, "localhost:14560") |
| 127 | rt.AddRoute(12012, "localhost:15560", -1, "localhost:14560") |
| 128 | rt.AddRoute(12011, "localhost:15660", -1, "localhost:14560") |
| 129 | rt.AddRoute(12012, "localhost:15660", -1, "localhost:14560") |
| 130 | rt.AddRoute(12011, "localhost:14560", -1, "localhost:13660;localhost:13560") |
| 131 | rt.AddRoute(12012, "localhost:14560", -1, "localhost:13660;localhost:13560") |
| 132 | rt.AddRoute(12020, "", -1, "localhost:14560") |
| 133 | rt.AddRoute(12020, "localhost:14560", -1, "%meid") |
| 134 | rt.AddRoute(12021, "localhost:15560", -1, "localhost:14560") |
| 135 | rt.AddRoute(12022, "localhost:15560", -1, "localhost:14560") |
| 136 | rt.AddRoute(12021, "localhost:15660", -1, "localhost:14560") |
| 137 | rt.AddRoute(12022, "localhost:15660", -1, "localhost:14560") |
| 138 | rt.AddRoute(12021, "localhost:14560", -1, "localhost:13660;localhost:13560") |
| 139 | rt.AddRoute(12022, "localhost:14560", -1, "localhost:13660;localhost:13560") |
| 140 | rt.AddRoute(55555, "", -1, "localhost:13660;localhost:13560;localhost:15560;localhost:15660;localhost:16560") |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 141 | |
Juha Hyttinen | 896c3ac | 2020-02-24 12:49:20 +0200 | [diff] [blame^] | 142 | rt.AddMeid("localhost:15560", []string{"RAN_NAME_1", "RAN_NAME_2"}) |
| 143 | rt.AddMeid("localhost:15660", []string{"RAN_NAME_11", "RAN_NAME_12"}) |
| 144 | |
| 145 | rtfilename, _ := teststub.CreateTmpFile(rt.GetTable()) |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 146 | defer os.Remove(rtfilename) |
Juha Hyttinen | 896c3ac | 2020-02-24 12:49:20 +0200 | [diff] [blame^] | 147 | tent.Logger.Info("table[%s]", rt.GetTable()) |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 148 | //--------------------------------- |
| 149 | // |
| 150 | //--------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 151 | tent.Logger.Info("### submgr ctrl run ###") |
| 152 | mainCtrl = createSubmgrControl(rtfilename, "14560") |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 153 | |
| 154 | //--------------------------------- |
| 155 | // |
| 156 | //--------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 157 | tent.Logger.Info("### xapp1 stub run ###") |
| 158 | xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", rtfilename, "13560", "RMRXAPP1STUB", 55555) |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 159 | |
| 160 | //--------------------------------- |
| 161 | // |
| 162 | //--------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 163 | tent.Logger.Info("### xapp2 stub run ###") |
| 164 | xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", rtfilename, "13660", "RMRXAPP2STUB", 55555) |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 165 | |
| 166 | //--------------------------------- |
| 167 | // |
| 168 | //--------------------------------- |
Juha Hyttinen | 896c3ac | 2020-02-24 12:49:20 +0200 | [diff] [blame^] | 169 | tent.Logger.Info("### e2term1 stub run ###") |
| 170 | e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", rtfilename, "15560", "RMRE2TERMSTUB1", 55555) |
| 171 | |
| 172 | //--------------------------------- |
| 173 | // |
| 174 | //--------------------------------- |
| 175 | tent.Logger.Info("### e2term2 stub run ###") |
| 176 | e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", rtfilename, "15660", "RMRE2TERMSTUB2", 55555) |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 177 | |
| 178 | //--------------------------------- |
| 179 | // Just to test dummy stub |
| 180 | //--------------------------------- |
| 181 | tent.Logger.Info("### dummy stub run ###") |
| 182 | dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", rtfilename, "16560", "DUMMYSTUB", 55555) |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 183 | |
| 184 | //--------------------------------- |
| 185 | // Testing message sending |
| 186 | //--------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 187 | if teststub.RmrStubControlWaitAlive(10, 55555, mainCtrl.c) == false { |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 188 | os.Exit(1) |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | //----------------------------------------------------------------------------- |
| 193 | // |
| 194 | //----------------------------------------------------------------------------- |
| 195 | func TestMain(m *testing.M) { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 196 | CaseBegin("TestMain start") |
Juha Hyttinen | fa01566 | 2020-01-24 10:05:18 +0200 | [diff] [blame] | 197 | ut_test_init() |
| 198 | code := m.Run() |
| 199 | os.Exit(code) |
| 200 | } |