Newer
Older
/*
* Copyright (c) 2019 InterDigital Communications, Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package model
import (
"fmt"
"testing"
ceModel "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-ctrl-engine-model"
log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
)
Kevin Di Lallo
committed
const modelRedisAddr string = "localhost:30380"
const modelRedisTestTable = 0
const modelName string = "test-model"
const moduleName string = "test-module"
const testScenario string = `
{"_id":"demo1","_rev":"5-905df5009b54170401d47031711afff7","name":"demo1","deployment":{"interDomainLatency":50,"interDomainLatencyVariation":5,"interDomainThroughput":1000,"domains":[{"id":"PUBLIC","name":"PUBLIC","type":"PUBLIC","interZoneLatency":6,"interZoneLatencyVariation":2,"interZoneThroughput":1000000,"zones":[{"id":"PUBLIC-COMMON","name":"PUBLIC-COMMON","type":"COMMON","interFogLatency":2,"interFogLatencyVariation":1,"interFogThroughput":1000000,"interEdgeLatency":3,"interEdgeLatencyVariation":1,"interEdgeThroughput":1000000,"edgeFogLatency":5,"edgeFogLatencyVariation":1,"edgeFogThroughput":1000000,"networkLocations":[{"id":"PUBLIC-COMMON-DEFAULT","name":"PUBLIC-COMMON-DEFAULT","type":"DEFAULT","terminalLinkLatency":1,"terminalLinkLatencyVariation":1,"terminalLinkThroughput":50000,"terminalLinkPacketLoss":1,"physicalLocations":[{"id":"cloud1","name":"cloud1","type":"DC","processes":[{"id":"cloud1-iperf","name":"cloud1-iperf","type":"CLOUD-APP","image":"gophernet/iperf-server","commandArguments":"-c, export; iperf -s -p $IPERF_SERVICE_PORT","commandExe":"/bin/bash","serviceConfig":{"name":"cloud1-iperf","ports":[{"protocol":"UDP","port":80}]}},{"id":"cloud1-svc","name":"cloud1-svc","type":"CLOUD-APP","image":"meep-docker-registry:30001/demo-server","environment":"MGM_GROUP_NAME=cloud1-svc, MGM_APP_ID=cloud1-svc, MGM_APP_PORT=80","serviceConfig":{"name":"cloud1-svc","ports":[{"protocol":"TCP","port":80}]}}]}]}]}]},{"id":"operator1","name":"operator1","type":"OPERATOR","interZoneLatency":15,"interZoneLatencyVariation":3,"interZoneThroughput":1000,"zones":[{"id":"operator1-COMMON","name":"operator1-COMMON","type":"COMMON","interFogLatency":2,"interFogLatencyVariation":1,"interFogThroughput":1000000,"interEdgeLatency":3,"interEdgeLatencyVariation":1,"interEdgeThroughput":1000000,"edgeFogLatency":5,"edgeFogLatencyVariation":1,"edgeFogThroughput":1000000,"networkLocations":[{"id":"operator1-COMMON-DEFAULT","name":"operator1-COMMON-DEFAULT","type":"DEFAULT","terminalLinkLatency":1,"terminalLinkLatencyVariation":1,"terminalLinkThroughput":50000,"terminalLinkPacketLoss":1}]},{"id":"zone1","name":"zone1","type":"ZONE","interFogLatency":10,"interFogLatencyVariation":2,"interFogThroughput":1000,"interEdgeLatency":12,"interEdgeLatencyVariation":2,"interEdgeThroughput":1000,"edgeFogLatency":5,"edgeFogLatencyVariation":1,"edgeFogThroughput":1000,"networkLocations":[{"id":"zone1-DEFAULT","name":"zone1-DEFAULT","type":"DEFAULT","terminalLinkLatency":1,"terminalLinkLatencyVariation":1,"terminalLinkThroughput":50000,"terminalLinkPacketLoss":1,"physicalLocations":[{"id":"zone1-edge1","name":"zone1-edge1","type":"EDGE","processes":[{"id":"zone1-edge1-iperf","name":"zone1-edge1-iperf","type":"EDGE-APP","image":"gophernet/iperf-server","commandArguments":"-c, export; iperf -s -p $IPERF_SERVICE_PORT","commandExe":"/bin/bash","serviceConfig":{"name":"zone1-edge1-iperf","meSvcName":"iperf","ports":[{"protocol":"UDP","port":80}]}},{"id":"zone1-edge1-svc","name":"zone1-edge1-svc","type":"EDGE-APP","image":"meep-docker-registry:30001/demo-server","environment":"MGM_GROUP_NAME=svc, MGM_APP_ID=zone1-edge1-svc, MGM_APP_PORT=80","serviceConfig":{"name":"zone1-edge1-svc","meSvcName":"svc","ports":[{"protocol":"TCP","port":80}]}}]}]},{"id":"zone1-poa1","name":"zone1-poa1","type":"POA","terminalLinkLatency":1,"terminalLinkLatencyVariation":1,"terminalLinkThroughput":1000,"physicalLocations":[{"id":"zone1-fog1","name":"zone1-fog1","type":"FOG","processes":[{"id":"zone1-fog1-iperf","name":"zone1-fog1-iperf","type":"EDGE-APP","image":"gophernet/iperf-server","commandArguments":"-c, export; iperf -s -p $IPERF_SERVICE_PORT;","commandExe":"/bin/bash","serviceConfig":{"name":"zone1-fog1-iperf","meSvcName":"iperf","ports":[{"protocol":"UDP","port":80}]}},{"id":"zone1-fog1-svc","name":"zone1-fog1-svc","type":"EDGE-APP","image":"meep-docker-registry:30001/demo-server","environment":"MGM_GROUP_NAME=svc, MGM_APP_ID=zone1-fog1-svc, MGM_APP_PORT=80","serviceConfig":{"name":"zone1-fog1-svc","meSvcName":"svc","ports":[{"protocol":"TCP","port":80}]}}]},{"id":"ue1","name":"ue1","type":"UE","processes":[{"id":"ue1-iperf","name":"ue1-iperf","type":"UE-APP","image":"gophernet/iperf-client","commandArguments":"-c, export; iperf -u -c $IPERF_SERVICE_HOST -p $IPERF_SERVICE_PORT -t 3600 -b 50M;","commandExe":"/bin/bash"}]},{"id":"ue2-ext","name":"ue2-ext","type":"UE","isExternal":true,"processes":[{"id":"ue2-svc","name":"ue2-svc","type":"UE-APP","isExternal":true,"externalConfig":{"ingressServiceMap":[{"name":"svc","port":80,"externalPort":31111,"protocol":"TCP"},{"name":"iperf","port":80,"externalPort":31222,"protocol":"UDP"},{"name":"cloud1-svc","port":80,"externalPort":31112,"protocol":"TCP"},{"name":"cloud1-iperf","port":80,"externalPort":31223,"protocol":"UDP"}]}}]}]},{"id":"zone1-poa2","name":"zone1-poa2","type":"POA","terminalLinkLatency":10,"terminalLinkLatencyVariation":2,"terminalLinkThroughput":50}]},{"id":"zone2","name":"zone2","type":"ZONE","interFogLatency":10,"interFogLatencyVariation":2,"interFogThroughput":1000,"interEdgeLatency":12,"interEdgeLatencyVariation":2,"interEdgeThroughput":1000,"edgeFogLatency":5,"edgeFogLatencyVariation":1,"edgeFogThroughput":1000,"networkLocations":[{"id":"zone2-DEFAULT","name":"zone2-DEFAULT","type":"DEFAULT","terminalLinkLatency":1,"terminalLinkLatencyVariation":1,"terminalLinkThroughput":50000,"terminalLinkPacketLoss":1,"physicalLocations":[{"id":"zone2-edge1","name":"zone2-edge1","type":"EDGE","processes":[{"id":"zone2-edge1-iperf","name":"zone2-edge1-iperf","type":"EDGE-APP","image":"gophernet/iperf-server","commandArguments":"-c, export; iperf -s -p $IPERF_SERVICE_PORT;","commandExe":"/bin/bash","serviceConfig":{"name":"zone2-edge1-iperf","meSvcName":"iperf","ports":[{"protocol":"UDP","port":80}]}},{"id":"zone2-edge1-svc","name":"zone2-edge1-svc","type":"EDGE-APP","image":"meep-docker-registry:30001/demo-server","environment":"MGM_GROUP_NAME=svc, MGM_APP_ID=zone2-edge1-svc, MGM_APP_PORT=80","serviceConfig":{"name":"zone2-edge1-svc","meSvcName":"svc","ports":[{"protocol":"TCP","port":80}]}}]}]},{"id":"zone2-poa1","name":"zone2-poa1","type":"POA","terminalLinkLatency":1,"terminalLinkLatencyVariation":1,"terminalLinkThroughput":20}]}]}]}}
`
func TestNewModel(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
// Keep this one first...
fmt.Println("Invalid Redis DB address")
_, err := NewModel("ExpectedFailure-InvalidDbLocation", "test-mod", modelName)
if err == nil {
t.Errorf("Should report error on invalid Redis db")
}
fmt.Println("Invalid module")
_, err = NewModel(modelRedisAddr, "", modelName)
if err == nil {
t.Errorf("Should report error on invalid module")
}
fmt.Println("Create normal")
_, err = NewModel(modelRedisAddr, "test-mod", modelName)
if err != nil {
t.Errorf("Unable to create model")
}
fmt.Println("Create no name")
_, err = NewModel(modelRedisAddr, "test-mod", "")
if err == nil {
t.Errorf("Should not allow creating model without a name")
}
}
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
m, err := NewModel(modelRedisAddr, "test-mod", modelName)
if err != nil {
t.Errorf("Unable to create model")
}
t.Errorf("Service map unexpected")
}
fmt.Println("Set Model")
if err != nil {
t.Errorf("Error setting model")
}
if m.scenario.Name != "demo1" {
s, err := m.GetScenario()
if err != nil {
t.Errorf("Error getting scenario")
if s == nil {
t.Errorf("Error getting scenario")
// if s.Name != "demo1" {
// t.Errorf("GetModel failed")
// }
fmt.Println("GetSvcMap - existing")
svcMap = m.GetServiceMaps()
if svcMap == nil {
t.Errorf("Service map expected")
}
}
func TestActivateDeactivate(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
m, err := NewModel(modelRedisAddr, "test-mod", modelName)
if err != nil {
t.Errorf("Unable to create model")
}
if err != nil {
t.Errorf("Error setting model")
}
if m.scenario.Name != "demo1" {
}
fmt.Println("Activate model")
err = m.Activate()
if err != nil {
t.Errorf("Error activating model")
}
if err != nil {
t.Errorf("Error updating model")
}
fmt.Println("Deactivate model")
err = m.Deactivate()
if err != nil {
t.Errorf("Error deactivating model")
}
}
func TestMoveNode(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
m, err := NewModel(modelRedisAddr, "test-mod", modelName)
if err != nil {
t.Errorf("Unable to create model")
}
fmt.Println("Set Model")
if err != nil {
t.Errorf("Error setting model")
}
if m.scenario.Name != "demo1" {
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
}
fmt.Println("Move ue1")
old, new, err := m.MoveNode("ue1", "zone2-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone1-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone2-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move ue2-ext")
old, new, err = m.MoveNode("ue2-ext", "zone2-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone1-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone2-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move ue1 back")
old, new, err = m.MoveNode("ue1", "zone1-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone2-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone1-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move ue2-ext back")
old, new, err = m.MoveNode("ue2-ext", "zone1-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone2-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone1-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move ue2-ext again")
old, new, err = m.MoveNode("ue2-ext", "zone2-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone1-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone2-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move ue1")
old, new, err = m.MoveNode("ue1", "zone2-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone1-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone2-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move ue1 back again")
old, new, err = m.MoveNode("ue1", "zone1-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone2-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone1-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move zone1-edge1-iperf")
_, _, err = m.MoveNode("zone1-edge1-iperf", "zone2-edge2")
if err == nil {
t.Errorf("Moving Edge-App part of mobility group should not be allowed")
}
fmt.Println("Move zone1-edge1-iperf")
// Remove mobility group
node := m.nodeMap.FindByName("zone1-edge1-iperf")
if node == nil {
t.Errorf("unable to find node")
}
proc := node.object.(*ceModel.Process)
proc.ServiceConfig.MeSvcName = ""
old, new, err = m.MoveNode("zone1-edge1-iperf", "zone2-edge1")
if err != nil {
t.Errorf("Error moving Edge-App")
}
if old != "zone1-edge1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone2-edge1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
fmt.Println("Move Node - not a UE")
_, _, err = m.MoveNode("Not-a-UE", "zone1-poa1")
if err == nil {
t.Errorf("Error moving UE - inexisting UE")
}
fmt.Println("Move Node - not a PoA")
_, _, err = m.MoveNode("ue1", "Not-a-poa")
if err == nil {
t.Errorf("Error moving UE - inexisting PoA")
}
}
func TestUpdateNetChar(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
m, err := NewModel(modelRedisAddr, "test-mod", modelName)
if err != nil {
t.Errorf("Unable to create model")
}
fmt.Println("Set Model")
if err != nil {
t.Errorf("Error setting model")
}
if m.scenario.Name != "demo1" {
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
}
var nc ceModel.EventNetworkCharacteristicsUpdate
nc.ElementName = "demo1"
nc.ElementType = "SCENARIO"
nc.Latency = 1
nc.LatencyVariation = 2
nc.Throughput = 3
nc.PacketLoss = 4
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
if m.scenario.Deployment.InterDomainLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if m.scenario.Deployment.InterDomainLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if m.scenario.Deployment.InterDomainThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if m.scenario.Deployment.InterDomainPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "operator1"
nc.ElementType = "OPERATOR"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n := m.nodeMap.FindByName(nc.ElementName)
d := n.object.(*ceModel.Domain)
if d.InterZoneLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if d.InterZoneLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if d.InterZoneThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if d.InterZonePacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "zone1"
nc.ElementType = "ZONE-INTER-EDGE"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
z := n.object.(*ceModel.Zone)
if z.InterEdgeLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if z.InterEdgeLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if z.InterEdgeThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if z.InterEdgePacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementType = "ZONE-INTER-FOG"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
if z.InterFogLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if z.InterFogLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if z.InterFogThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if z.InterFogPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementType = "ZONE-EDGE-FOG"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
if z.EdgeFogLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if z.EdgeFogLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if z.EdgeFogThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if z.EdgeFogPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "zone1-poa1"
nc.ElementType = "POA"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
nl := n.object.(*ceModel.NetworkLocation)
if nl.TerminalLinkLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if nl.TerminalLinkLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if nl.TerminalLinkThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if nl.TerminalLinkPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "zone1-fog1"
nc.ElementType = "FOG"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
pl := n.object.(*ceModel.PhysicalLocation)
if pl.LinkLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if pl.LinkLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if pl.LinkThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if pl.LinkPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "zone1-edge1"
nc.ElementType = "EDGE"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
pl = n.object.(*ceModel.PhysicalLocation)
if pl.LinkLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if pl.LinkLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if pl.LinkThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if pl.LinkPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "ue1"
nc.ElementType = "UE"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
pl = n.object.(*ceModel.PhysicalLocation)
if pl.LinkLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if pl.LinkLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if pl.LinkThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if pl.LinkPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "cloud1"
nc.ElementType = "DISTANT CLOUD"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
pl = n.object.(*ceModel.PhysicalLocation)
if pl.LinkLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if pl.LinkLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if pl.LinkThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if pl.LinkPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "zone1-edge1-iperf"
nc.ElementType = "EDGE APPLICATION"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
proc := n.object.(*ceModel.Process)
if proc.AppLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if proc.AppLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if proc.AppThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if proc.AppPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "ue1-iperf"
nc.ElementType = "UE APPLICATION"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
proc = n.object.(*ceModel.Process)
if proc.AppLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if proc.AppLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if proc.AppThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if proc.AppPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "cloud1-iperf"
nc.ElementType = "CLOUD APPLICATION"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
n = m.nodeMap.FindByName(nc.ElementName)
proc = n.object.(*ceModel.Process)
if proc.AppLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if proc.AppLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if proc.AppThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if proc.AppPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
nc.ElementName = "Not-a-Name"
nc.ElementType = "POA"
err = m.UpdateNetChar(&nc)
if err == nil {
t.Errorf("Update " + nc.ElementType + " should fail")
}
nc.ElementName = "ue1"
nc.ElementType = "Not-a-Type"
err = m.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Unsupported type should not fail")
}
}
func TestListenModel(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
fmt.Println("Create Publisher")
mPub, err := NewModel(modelRedisAddr, moduleName+"-Pub", modelName)
if err != nil {
t.Errorf("Unable to create model")
}
if mPub.GetScenarioName() != "" {
t.Errorf("Scenario name should be empty")
}
Kevin Di Lallo
committed
err = mPub.Activate()
if err != nil {
t.Errorf("Failed to activate model")
}
time.Sleep(50 * time.Millisecond)
fmt.Println("Set Model")
err = mPub.SetScenario([]byte(testScenario))
time.Sleep(50 * time.Millisecond)
if err != nil {
t.Errorf("Error setting model")
}
if mPub.GetScenarioName() != "demo1" {
t.Errorf("Scenario name should be demo1")
}
// create listener after model has been published to test initialization
fmt.Println("Create Listener")
mLis, err := NewModel(modelRedisAddr, moduleName+"-Lis", "Active")
if err != nil {
t.Errorf("Unable to create model")
}
if mLis.GetScenarioName() != "" {
t.Errorf("Scenario name should be empty")
}
fmt.Println("Register listener (no handler)")
err = mLis.Listen(nil)
if err == nil {
t.Errorf("Should not allow registering without a handler")
}
var testCount = 0
eventCount = 0
lis, _ := mLis.GetScenario()
pub, _ := mPub.GetScenario()
if string(lis) != string(pub) {
t.Errorf("Published model different than received one")
}
if mLis.GetScenarioName() != "demo1" {
t.Errorf("Scenario name should be demo1")
}
// MoveNode
fmt.Println("Move ue1")
testCount++
old, new, err := mPub.MoveNode("ue1", "zone2-poa1")
if err != nil {
t.Errorf("Error moving UE")
}
if old != "zone1-poa1" {
t.Errorf("Move Node - wrong origin Location " + old)
}
if new != "zone2-poa1" {
t.Errorf("Move Node - wrong destination Location " + new)
}
if eventCount != testCount {
t.Errorf("No event received for MoveUE")
}
n := mLis.nodeMap.FindByName("ue1")
parent := n.parent.(*ceModel.NetworkLocation)
if parent.Name != "zone2-poa1" {
t.Errorf("Published model not as expected")
}
//UpdateNetChar
fmt.Println("Update net-char")
testCount++
var nc ceModel.EventNetworkCharacteristicsUpdate
nc.ElementName = "demo1"
nc.ElementType = "SCENARIO"
nc.Latency = 1
nc.LatencyVariation = 2
nc.Throughput = 3
nc.PacketLoss = 4
err = mPub.UpdateNetChar(&nc)
if err != nil {
t.Errorf("Update " + nc.ElementType + " failed")
}
if eventCount != testCount {
t.Errorf("No event received for UpdateNetChar")
}
if mLis.scenario.Deployment.InterDomainLatency != 1 {
t.Errorf("Update " + nc.ElementType + " latency failed")
}
if mLis.scenario.Deployment.InterDomainLatencyVariation != 2 {
t.Errorf("Update " + nc.ElementType + " jitter failed")
}
if mLis.scenario.Deployment.InterDomainThroughput != 3 {
t.Errorf("Update " + nc.ElementType + " throughput failed")
}
if mLis.scenario.Deployment.InterDomainPacketLoss != 4 {
t.Errorf("Update " + nc.ElementType + " packet loss failed")
}
fmt.Println("Dectivate")
testCount++
Kevin Di Lallo
committed
err = mPub.Deactivate()
if err != nil {
t.Errorf("Failed to deactivate")
}
if eventCount != testCount {
t.Errorf("No event received for Activate")
}
lis, _ = mLis.GetScenario()
if string(lis) != "{}" {
if mPub.GetScenarioName() != "demo1" {
t.Errorf("Scenario name should be demo1")
}
if mLis.GetScenarioName() != "" {
t.Errorf("Scenario name should be empty")
}
fmt.Println("Re-Activate")
testCount++
Kevin Di Lallo
committed
err = mPub.Activate()
if err != nil {
t.Errorf("Failed to activate")
}
time.Sleep(50 * time.Millisecond)
if eventCount != testCount {
t.Errorf("No event received for Activate")
}
if mPub.GetScenarioName() != "demo1" {
t.Errorf("Scenario name should be demo1")
}
if mLis.GetScenarioName() != "demo1" {
t.Errorf("Scenario name should be demo1")
}
}
var eventChannel string
var eventPayload string
var eventCount int
func eventHandler(channel string, payload string) {
eventChannel = channel
eventPayload = payload
eventCount++
fmt.Println("Event#", eventCount, " ch:", channel)
}
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
func TestGetters(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
// Switch to a different table for testing
redisTable = modelRedisTestTable
fmt.Println("Create Model")
m, err := NewModel(modelRedisAddr, moduleName, modelName)
if err != nil {
t.Errorf("Unable to create model")
}
fmt.Println("Get Node Names (empty)")
l := m.GetNodeNames("")
if len(l) != 0 {
t.Errorf("Node name list should be empty")
}
fmt.Println("Set Model")
err = m.SetScenario([]byte(testScenario))
if err != nil {
t.Errorf("Error setting model")
}
fmt.Println("Get Node Names")
l = m.GetNodeNames("ANY")
if len(l) != 30 {
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
t.Errorf("Node name list should not be empty")
}
fmt.Println(l)
fmt.Println(len(l))
fmt.Println("Get UE Node Names")
l = m.GetNodeNames("UE")
if len(l) != 2 {
t.Errorf("UE node name list should be 2")
}
fmt.Println(l)
fmt.Println(len(l))
fmt.Println("Get POA Node Names")
l = m.GetNodeNames("POA")
if len(l) != 3 {
t.Errorf("POA node name list should be 3")
}
fmt.Println(l)
fmt.Println(len(l))
fmt.Println("Get Zone Node Names")
l = m.GetNodeNames("ZONE")
if len(l) != 2 {
t.Errorf("Zone node name list should be 2")
}
fmt.Println(l)
fmt.Println(len(l))
fmt.Println("Get UE + POA Node Names")
l = m.GetNodeNames("UE", "POA")
if len(l) != 5 {
t.Errorf("UE + POA node name list should be 5")
}
fmt.Println(l)
fmt.Println(len(l))
fmt.Println("Get UE + POA + ZONE Node Names")
l = m.GetNodeNames("UE", "POA", "ZONE")
if len(l) != 7 {
t.Errorf("UE + POA + ZONE node name list should be 10")
}
fmt.Println(l)
fmt.Println(len(l))
fmt.Println("Get invalid node")
n := m.GetNode("NOT-A-NODE")
if n != nil {
t.Errorf("Node should not exist")
}
fmt.Println("Get ue1 node")
n = m.GetNode("ue1")
if n == nil {
t.Errorf("Failed getting ue1 node")
}
pl, ok := n.(*ceModel.PhysicalLocation)
if !ok {
t.Errorf("ue1 has wrong type %T -- expected *model.PhysicalLocation", n)
}
if pl.Name != "ue1" {
t.Errorf("Could not find ue1")
}
fmt.Println("Get edges")
edges := m.GetEdges()
if len(edges) != 28 {
t.Errorf("Missing edges - expected 28")
}
if edges["ue1"] != "zone1-poa1" {
t.Errorf("UE1 edge - expected zone1-poa1 -- got %s", edges["ue1"])
}
if edges["zone1"] != "operator1" {
t.Errorf("Zone1 edge - expected operator1 -- got %s", edges["zone1"])
}
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
// Node Type
fmt.Println("Get node type for invalid node")
nodeType := m.GetNodeType("NOT-A-NODE")
if nodeType != "" {
t.Errorf("Node type should be empty")
}
fmt.Println("Get node type for OPERATOR")
nodeType = m.GetNodeType("operator1")
if nodeType != "OPERATOR" {
t.Errorf("Invalid node type")
}
fmt.Println("Get node type for ZONE")
nodeType = m.GetNodeType("zone1")
if nodeType != "ZONE" {
t.Errorf("Invalid node type")
}
fmt.Println("Get node type for POA")
nodeType = m.GetNodeType("zone1-poa1")
if nodeType != "POA" {
t.Errorf("Invalid node type")
}
fmt.Println("Get node type for FOG")
nodeType = m.GetNodeType("zone1-fog1")
if nodeType != "FOG" {
t.Errorf("Invalid node type")
}
fmt.Println("Get node type for UE")
nodeType = m.GetNodeType("ue1")
if nodeType != "UE" {
t.Errorf("Invalid node type")
}
fmt.Println("Get node type for UE-APP")
nodeType = m.GetNodeType("ue1-iperf")
if nodeType != "UE-APP" {
t.Errorf("Invalid node type")
}
fmt.Println("Get node type for EDGE-APP")
nodeType = m.GetNodeType("zone1-edge1-svc")
if nodeType != "EDGE-APP" {
t.Errorf("Invalid node type")
}
// Node Context
fmt.Println("Get context for invalid node")
ctx := m.GetNodeContext("NOT-A-NODE")
if ctx != nil {
t.Errorf("Node context should not exist")
}
fmt.Println("Get Deployment context")
ctx = m.GetNodeContext("demo1")
if ctx == nil {
t.Errorf("Node context should exist")
}
Kevin Di Lallo
committed
nodeCtx, ok := ctx.(*NodeContext)
if !ok || !validateNodeContext(nodeCtx, "demo1", "", "", "", "") {
t.Errorf("Invalid Deployment context")
}
fmt.Println("Get Operator context")
ctx = m.GetNodeContext("operator1")
if ctx == nil {
t.Errorf("Node context should exist")
Kevin Di Lallo
committed
nodeCtx, ok = ctx.(*NodeContext)
if !ok || !validateNodeContext(nodeCtx, "demo1", "operator1", "", "", "") {
t.Errorf("Invalid Operator context")
}
fmt.Println("Get Zone context")
ctx = m.GetNodeContext("zone1")
if ctx == nil {
t.Errorf("Node context should exist")
Kevin Di Lallo
committed
nodeCtx, ok = ctx.(*NodeContext)
if !ok || !validateNodeContext(nodeCtx, "demo1", "operator1", "zone1", "", "") {
t.Errorf("Invalid Operator context")
}
fmt.Println("Get Net Location context")
ctx = m.GetNodeContext("zone1-poa1")
if ctx == nil {
t.Errorf("Node context should exist")
Kevin Di Lallo
committed
nodeCtx, ok = ctx.(*NodeContext)
if !ok || !validateNodeContext(nodeCtx, "demo1", "operator1", "zone1", "zone1-poa1", "") {
t.Errorf("Invalid Operator context")
}
fmt.Println("Get Phy Location context")
ctx = m.GetNodeContext("zone1-fog1")
if ctx == nil {
t.Errorf("Node context should exist")
Kevin Di Lallo
committed
nodeCtx, ok = ctx.(*NodeContext)
if !ok || !validateNodeContext(nodeCtx, "demo1", "operator1", "zone1", "zone1-poa1", "zone1-fog1") {
t.Errorf("Invalid Operator context")
}
fmt.Println("Get App context")
ctx = m.GetNodeContext("ue1-iperf")
if ctx == nil {
t.Errorf("Node context should exist")
Kevin Di Lallo
committed
nodeCtx, ok = ctx.(*NodeContext)
if !ok || !validateNodeContext(nodeCtx, "demo1", "operator1", "zone1", "zone1-poa1", "ue1") {
Kevin Di Lallo
committed
// Network Graph
graph := m.GetNetworkGraph()
if len(graph.Verticies) != 29 {
t.Errorf("Invalid Network Graph")
}
}
func validateNodeContext(nodeCtx *NodeContext, deployment, domain, zone, netLoc, phyLoc string) bool {
if nodeCtx.Parents[Deployment] != deployment ||
nodeCtx.Parents[Domain] != domain ||
nodeCtx.Parents[Zone] != zone ||
nodeCtx.Parents[NetLoc] != netLoc ||
nodeCtx.Parents[PhyLoc] != phyLoc {
return false
}
return true