Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
package main
import (
"net/http"
"os"
"os/signal"
"syscall"
"time"
"errors"
"context"
"net/url"
"strings"
"io/ioutil"
log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
platformCtrlClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-platform-ctrl-client"
sandboxCtrlClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-sandbox-ctrl-client"
rnisClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-rnis-client"
waisClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-wais-client"
gisClient "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-gis-engine-client"
)
var httpReqBody []string
var platformCtrlAppClient *platformCtrlClient.APIClient
var sandboxCtrlAppClient *sandboxCtrlClient.APIClient
var rnisAppClient *rnisClient.APIClient
var waisAppClient *waisClient.APIClient
var gisAppClient *gisClient.APIClient
var sandboxName = "sandbox-system-test"
var scenarioName = "scenario-system-test"
var hostUrlStr = ""
var httpListenerPort = "3333"
var run = false
const PASS = true
const FAIL = false
func resetHttpReqBody() {
httpReqBody = []string{}
}
func initialiseVars() {
hostUrl, _ := url.Parse(strings.TrimSpace(os.Getenv("MEEP_HOST_TEST_URL")))
hostUrlStr = hostUrl.String()
}
func createClients() error {
// Create & store client for App REST API
platformCtrlAppClientCfg := platformCtrlClient.NewConfiguration()
if hostUrlStr == "" {
platformCtrlAppClientCfg.BasePath = "http://localhost/platform-ctrl/v1"
} else {
platformCtrlAppClientCfg.BasePath = hostUrlStr + "/platform-ctrl/v1"
}
platformCtrlAppClient = platformCtrlClient.NewAPIClient(platformCtrlAppClientCfg)
if platformCtrlAppClient == nil {
log.Error("Failed to create Platform App REST API client: ", platformCtrlAppClientCfg.BasePath)
err := errors.New("Failed to create Platform App REST API client")
return err
}
return nil
}
func createSandboxClients(sandboxName string) error {
// Create & store client for App REST API
sandboxCtrlAppClientCfg := sandboxCtrlClient.NewConfiguration()
if hostUrlStr == "" {
sandboxCtrlAppClientCfg.BasePath = "http://localhost/" + sandboxName + "/sandbox-ctrl/v1"
} else {
sandboxCtrlAppClientCfg.BasePath = hostUrlStr + "/" + sandboxName + "/sandbox-ctrl/v1"
}
sandboxCtrlAppClient = sandboxCtrlClient.NewAPIClient(sandboxCtrlAppClientCfg)
if sandboxCtrlAppClient == nil {
log.Error("Failed to create Sandbox App REST API client: ", sandboxCtrlAppClientCfg.BasePath)
err := errors.New("Failed to create Sandbox App REST API client")
return err
}
rnisAppClientCfg := rnisClient.NewConfiguration()
if hostUrlStr == "" {
rnisAppClientCfg.BasePath = "http://localhost/" + sandboxName + "/rni/v2"
} else {
rnisAppClientCfg.BasePath = hostUrlStr + "/" + sandboxName + "/rni/v2"
}
rnisAppClient = rnisClient.NewAPIClient(rnisAppClientCfg)
if rnisAppClient == nil {
log.Error("Failed to create RNI App REST API client: ", rnisAppClientCfg.BasePath)
err := errors.New("Failed to create RNI App REST API client")
return err
}
waisAppClientCfg := waisClient.NewConfiguration()
if hostUrlStr == "" {
waisAppClientCfg.BasePath = "http://localhost/" + sandboxName + "/wai/v2"
} else {
waisAppClientCfg.BasePath = hostUrlStr + "/" + sandboxName + "/wai/v2"
}
waisAppClient = waisClient.NewAPIClient(waisAppClientCfg)
if waisAppClient == nil {
log.Error("Failed to create WAI App REST API client: ", waisAppClientCfg.BasePath)
err := errors.New("Failed to create WAI App REST API client")
return err
}
gisAppClientCfg := gisClient.NewConfiguration()
if hostUrlStr == "" {
gisAppClientCfg.BasePath = "http://localhost/" + sandboxName + "/gis/v1"
} else {
gisAppClientCfg.BasePath = hostUrlStr + "/" + sandboxName + "/gis/v1"
}
gisAppClient = gisClient.NewAPIClient(gisAppClientCfg)
if gisAppClient == nil {
log.Error("Failed to create GIS App REST API client: ", gisAppClientCfg.BasePath)
err := errors.New("Failed to create GIS App REST API client")
return err
}
return nil
}
func createSandbox(name string) error {
config := platformCtrlClient.SandboxConfig{""}
_, err := platformCtrlAppClient.SandboxControlApi.CreateSandboxWithName(context.TODO(), name, config)
if err != nil {
log.Error("Failed to create sandbox: ", err)
return err
}
return nil
}
func deleteSandbox(name string) error {
_, err := platformCtrlAppClient.SandboxControlApi.DeleteSandbox(context.TODO(), name)
if err != nil {
log.Error("Failed to delete sandbox: ", err)
return err
}
return nil
}
func createScenario(name string) error {
var scenario platformCtrlClient.Scenario
_, err := platformCtrlAppClient.ScenarioConfigurationApi.SetScenario(context.TODO(), name, scenario)
if err != nil {
log.Error("Failed to create scenario: ", err)
return err
}
return nil
}
func deleteScenario(name string) error {
_, err := platformCtrlAppClient.ScenarioConfigurationApi.DeleteScenario(context.TODO(), name)
if err != nil {
log.Error("Failed to delete scenario: ", err)
return err
}
return nil
}
func activateScenario(name string) error {
_, err := sandboxCtrlAppClient.ActiveScenarioApi.ActivateScenario(context.TODO(), name, nil)
if err != nil {
log.Error("Failed to activate scenario: ", err)
return err
}
//reinitialisation of http msg queue
resetHttpReqBody()
return nil
}
func terminateScenario() error {
_, err := sandboxCtrlAppClient.ActiveScenarioApi.TerminateScenario(context.TODO())
if err != nil {
log.Error("Failed to terminate scenario: ", err)
return err
}
return nil
}
func createBasics() {
initialiseVars()
log.Info("creating Clients")
createClients()
log.Info("creating Sandbox")
err := createSandbox(sandboxName)
if err == nil {
time.Sleep(20000 * time.Millisecond)
}
log.Info("creating Sandbox Clients")
createSandboxClients(sandboxName)
}
func clearBasics() {
log.Info("deleting Sandbox")
deleteSandbox(sandboxName)
}
func startSystemTest() {
if !run {
go main()
createBasics()
}
}
func stopSystemTest() {
if run {
clearBasics()
}
}
func main() {
//create default route handler
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
log.Info("http message received!")
defer req.Body.Close()
body, _ := ioutil.ReadAll(req.Body)
httpReqBody = append(httpReqBody, string(body))
})
log.Info(os.Args)
log.Info("Starting System Test")
run = true
go func() {
sigchan := make(chan os.Signal, 10)
signal.Notify(sigchan, syscall.SIGINT, syscall.SIGTERM)
<-sigchan
log.Info("Program killed !")
// do last actions and wait for all write operations to end
run = false
}()
go func() {
// Initialize RNIS
/*err := server.Init()
if err != nil {
log.Error("Failed to initialize RNI Service")
run = false
return
}
// Start RNIS Event Handler thread
err = server.Run()
if err != nil {
log.Error("Failed to start RNI Service")
run = false
return
}
*/
//create default route handler
log.Fatal(http.ListenAndServe(":" + httpListenerPort, nil))
run = false
}()
//createBasics()
count := 0
for {
if !run {
log.Info("Ran for ", count, " seconds")
clearBasics()
break
}
time.Sleep(time.Second)
count++
}
}
func geAutomationUpdate(mobility bool, movement bool, poasInRange bool, netCharUpd bool) error {
_, err := gisAppClient.AutomationApi.SetAutomationStateByName(context.TODO(), "MOBILITY", mobility)
if err != nil {
log.Error("Failed to communicatie with gis engine: ", err)
return err
}
_, err = gisAppClient.AutomationApi.SetAutomationStateByName(context.TODO(), "MOVEMENT", movement)
if err != nil {
log.Error("Failed to communicatie with gis engine: ", err)
return err
}
_, err = gisAppClient.AutomationApi.SetAutomationStateByName(context.TODO(), "POAS-IN-RANGE", poasInRange)
if err != nil {
log.Error("Failed to communicatie with gis engine: ", err)
return err
}
_, err = gisAppClient.AutomationApi.SetAutomationStateByName(context.TODO(), "NETWORK-CHARACTERISTICS-UPDATE", netCharUpd)
if err != nil {
log.Error("Failed to communicatie with gis engine: ", err)
return err
}
return nil
}
func geMoveAssetCoordinates(assetName string, long float32, lat float32) error {
var geoData gisClient.GeoDataAsset
point := gisClient.Point{"Point", []float32{long, lat}}
geoData.Location = &point
geoData.AssetName = assetName
geoData.AssetType = "UE"
geoData.SubType = "UE"
err := geMoveAsset(assetName, geoData)
if err != nil {
log.Error("Failed to move asset: ", err)
return err
}
return nil
}
func geMoveAsset(assetName string, geoData gisClient.GeoDataAsset) error {
_, err := gisAppClient.GeospatialDataApi.UpdateGeoDataByName(context.TODO(), assetName, geoData)
if err != nil {
log.Error("Failed to communicatie with gis engine: ", err)
return err
}
return nil
}