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
/*
* 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 (
"encoding/json"
"fmt"
"testing"
ceModel "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-ctrl-engine-model"
log "github.com/InterDigitalInc/AdvantEDGE/go-packages/meep-logger"
)
func TestNodeMapDomains(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
fmt.Println("Create a scenario structure")
scenario := new(ceModel.Scenario)
err := json.Unmarshal([]byte(testScenario), scenario)
if err != nil {
t.Errorf("Unable to unmarshall scenario")
}
fmt.Println("Create nodeMap")
nm := NewNodeMap()
if nm == nil {
t.Errorf("Unable to allocate nodeMap")
}
fmt.Println("Test Deployment")
if scenario.Deployment == nil {
t.Errorf("nil deployment")
}
fmt.Println("Test Domains")
////fmt.Printf(" Scenario has %d domains\n", len(scenario.Deployment.Domains))
for i := range scenario.Deployment.Domains {
domain := &scenario.Deployment.Domains[i]
context := make(map[string]string)
context["pl"] = "phyLoc"
context["nl"] = "netLoc"
nm.AddNode(NewNode(domain.Name, domain.Type_, domain, &domain.Zones, scenario.Deployment, context))
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
////fmt.Printf(" domain%d: object @ %p\n%+v\n", i, &scenario.Deployment.Domains[i], domain)
////fmt.Printf(" domain%d: child @ %p\n%+v\n", i, &domain.Zones, domain.Zones)
////fmt.Printf(" domain%d: parent @ %p\n%+v\n", i, scenario.Deployment, *scenario.Deployment)
}
n := nm.FindByName("PUBLIC")
////fmt.Printf("%+v\n", n)
if n.object != &scenario.Deployment.Domains[0] {
t.Errorf("Domain[0] wrong object reference ")
}
if n.child != &scenario.Deployment.Domains[0].Zones {
t.Errorf("Domain[0] wrong child reference ")
}
if n.parent != scenario.Deployment {
t.Errorf("Domain[0] wrong parent reference ")
}
n = nm.FindByName("operator1")
////fmt.Printf("%+v\n", n)
if n.object != &scenario.Deployment.Domains[1] {
t.Errorf("Domain[1] wrong object reference ")
}
if n.child != &scenario.Deployment.Domains[1].Zones {
t.Errorf("Domain[1] wrong child reference ")
}
if n.parent != scenario.Deployment {
t.Errorf("Domain[1] wrong parent reference ")
}
// Change an object field via the node
testID := "new-test-id"
objPtr := n.object.(*ceModel.Domain)
////fmt.Printf(" node.object ptr %p\n%+v\n", objPtr, *objPtr)
objPtr.Id = testID
if scenario.Deployment.Domains[1].Id != testID {
t.Errorf("Failed changing domain id")
}
// Change a child field via the node
childPtr := n.child.(*[]ceModel.Zone)
//fmt.Printf(" node.child ptr %p\n%+v\n", childPtr, *childPtr)
(*childPtr)[0].Id = testID
if scenario.Deployment.Domains[1].Zones[0].Id != testID {
t.Errorf("Failed changing zone[0] id")
}
// Change a parent field via the node
parentPtr := n.parent.(*ceModel.Deployment)
//fmt.Printf(" node.parent ptr %p\n%+v\n", parentPtr, *parentPtr)
parentPtr.InterDomainLatency = 500
if scenario.Deployment.InterDomainLatency != 500 {
t.Errorf("Failed changing Deployment InterDomainLatency")
}
// Verify Node context
context := n.context.(map[string]string)
if context["pl"] != "phyLoc" || context["nl"] != "netLoc" {
t.Errorf("Failed to set context entries")
}
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
}
func TestNodeMapZone(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
fmt.Println("Create a scenario structure")
scenario := new(ceModel.Scenario)
err := json.Unmarshal([]byte(testScenario), scenario)
if err != nil {
t.Errorf("Unable to unmarshall scenario")
}
fmt.Println("Create nodeMap")
nm := NewNodeMap()
if nm == nil {
t.Errorf("Unable to allocate nodeMap")
}
fmt.Println("Test Deployment")
if scenario.Deployment == nil {
t.Errorf("nil deployment")
}
fmt.Println("Test Zones")
domain := &scenario.Deployment.Domains[1]
//fmt.Printf(" scenario.Deployment.Domains[1] has %d zones\n", len(scenario.Deployment.Domains[1].Zones))
for i := range domain.Zones {
zone := &domain.Zones[i]
context := make(map[string]string)
context["pl"] = "phyLoc"
context["nl"] = "netLoc"
nm.AddNode(NewNode(zone.Name, zone.Type_, zone, &zone.NetworkLocations, domain, context))
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
//fmt.Printf(" zone%d: object @ %p\n%+v\n", i, zone, *zone)
//fmt.Printf(" zone%d: child @ %p\n%+v\n", i, &zone.NetworkLocations, zone.NetworkLocations)
//fmt.Printf(" zone%d: parent @ %p\n%+v\n", i, domain, *domain)
}
n := nm.FindByName("zone1")
//fmt.Printf("%+v\n", n)
if n.object != &domain.Zones[1] {
t.Errorf("Zone[1] wrong object reference ")
}
if n.child != &domain.Zones[1].NetworkLocations {
t.Errorf("Zone[1] wrong child reference ")
}
if n.parent != domain {
t.Errorf("Zone[1] wrong parent reference ")
}
// Change an object field via the node
testID := "new-test-id"
objPtr := n.object.(*ceModel.Zone)
//fmt.Printf(" node.object ptr %p\n%+v\n", objPtr, *objPtr)
objPtr.Id = testID
if domain.Zones[1].Id != testID {
t.Errorf("Failed changing zone id")
}
// Change a child field via the node
childPtr := n.child.(*[]ceModel.NetworkLocation)
//fmt.Printf(" node.child ptr %p\n%+v\n", childPtr, *childPtr)
(*childPtr)[0].Id = testID
if domain.Zones[1].NetworkLocations[0].Id != testID {
t.Errorf("Failed changing NetworkLocation[0] id")
}
// Change a parent field via the node
parentPtr := n.parent.(*ceModel.Domain)
//fmt.Printf(" node.parent ptr %p\n%+v\n", parentPtr, *parentPtr)
parentPtr.Id = testID
if domain.Id != testID {
t.Errorf("Failed changing Deployment InterDomainLatency")
}
// Verify Node context
context := n.context.(map[string]string)
if context["pl"] != "phyLoc" || context["nl"] != "netLoc" {
t.Errorf("Failed to set context entries")
}
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
}
func TestNodeMapNetworkLocation(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
fmt.Println("Create a scenario structure")
scenario := new(ceModel.Scenario)
err := json.Unmarshal([]byte(testScenario), scenario)
if err != nil {
t.Errorf("Unable to unmarshall scenario")
}
fmt.Println("Create nodeMap")
nm := NewNodeMap()
if nm == nil {
t.Errorf("Unable to allocate nodeMap")
}
fmt.Println("Test Deployment")
if scenario.Deployment == nil {
t.Errorf("nil deployment")
}
fmt.Println("Test Network Locations")
zone := &scenario.Deployment.Domains[1].Zones[1]
//fmt.Printf(" scenario.Deployment.Domains[1].Zones[1] has %d NL\n", len(zone.NetworkLocations))
for i := range zone.NetworkLocations {
nl := &zone.NetworkLocations[i]
context := make(map[string]string)
context["pl"] = "phyLoc"
context["nl"] = "netLoc"
nm.AddNode(NewNode(nl.Name, nl.Type_, nl, &nl.PhysicalLocations, zone, context))
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
//fmt.Printf(" nl%d: object @ %p\n%+v\n", i, nl, *nl)
//fmt.Printf(" nl%d: child @ %p\n%+v\n", i, &nl.PhysicalLocations, nl.PhysicalLocations)
//fmt.Printf(" nl%d: parent @ %p\n%+v\n", i, zone, *zone)
}
n := nm.FindByName("zone1-poa1")
//fmt.Printf("%+v\n", n)
if n.object != &zone.NetworkLocations[1] {
t.Errorf("NL[1] wrong object reference ")
}
if n.child != &zone.NetworkLocations[1].PhysicalLocations {
t.Errorf("NL[1] wrong child reference ")
}
if n.parent != zone {
t.Errorf("NL[1] wrong parent reference ")
}
// Change an object field via the node
testID := "new-test-id"
objPtr := n.object.(*ceModel.NetworkLocation)
//fmt.Printf(" node.object ptr %p\n%+v\n", objPtr, *objPtr)
objPtr.Id = testID
if zone.NetworkLocations[1].Id != testID {
t.Errorf("Failed changing NL id")
}
// Change a child field via the node
childPtr := n.child.(*[]ceModel.PhysicalLocation)
//fmt.Printf(" node.child ptr %p\n%+v\n", childPtr, *childPtr)
(*childPtr)[0].Id = testID
if zone.NetworkLocations[1].PhysicalLocations[0].Id != testID {
t.Errorf("Failed changing PL[0] id")
}
// Change a parent field via the node
parentPtr := n.parent.(*ceModel.Zone)
//fmt.Printf(" node.parent ptr %p\n%+v\n", parentPtr, *parentPtr)
parentPtr.Id = testID
if zone.Id != testID {
t.Errorf("Failed changing Zone id")
}
// Verify Node context
context := n.context.(map[string]string)
if context["pl"] != "phyLoc" || context["nl"] != "netLoc" {
t.Errorf("Failed to set context entries")
}
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
}
func TestNodeMapPhysicalLocation(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
fmt.Println("Create a scenario structure")
scenario := new(ceModel.Scenario)
err := json.Unmarshal([]byte(testScenario), scenario)
if err != nil {
t.Errorf("Unable to unmarshall scenario")
}
fmt.Println("Create nodeMap")
nm := NewNodeMap()
if nm == nil {
t.Errorf("Unable to allocate nodeMap")
}
fmt.Println("Test Deployment")
if scenario.Deployment == nil {
t.Errorf("nil deployment")
}
fmt.Println("Test Physical Locations")
nl := &scenario.Deployment.Domains[1].Zones[1].NetworkLocations[1]
//fmt.Printf(" scenario.Deployment.Domains[1].Zones[1].NetworkLocations[1] has %d PL\n", len(nl.PhysicalLocations))
for i := range nl.PhysicalLocations {
pl := &nl.PhysicalLocations[i]
context := make(map[string]string)
context["pl"] = "phyLoc"
context["nl"] = "netLoc"
nm.AddNode(NewNode(pl.Name, pl.Type_, pl, &pl.Processes, nl, context))
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
//fmt.Printf(" nl%d: object @ %p\n%+v\n", i, pl, *pl)
//fmt.Printf(" nl%d: child @ %p\n%+v\n", i, &pl.Processes, pl.Processes)
//fmt.Printf(" nl%d: parent @ %p\n%+v\n", i, nl, *nl)
}
n := nm.FindByName("ue1")
//fmt.Printf("%+v\n", n)
if n.object != &nl.PhysicalLocations[1] {
t.Errorf("PL[1] wrong object reference ")
}
if n.child != &nl.PhysicalLocations[1].Processes {
t.Errorf("PL[1] wrong child reference ")
}
if n.parent != nl {
t.Errorf("PL[1] wrong parent reference ")
}
// Change an object field via the node
testID := "new-test-id"
objPtr := n.object.(*ceModel.PhysicalLocation)
//fmt.Printf(" node.object ptr %p\n%+v\n", objPtr, *objPtr)
objPtr.Id = testID
if nl.PhysicalLocations[1].Id != testID {
t.Errorf("Failed changing PL id")
}
// Change a child field via the node
childPtr := n.child.(*[]ceModel.Process)
//fmt.Printf(" node.child ptr %p\n%+v\n", childPtr, *childPtr)
(*childPtr)[0].Id = testID
if nl.PhysicalLocations[1].Processes[0].Id != testID {
t.Errorf("Failed changing Process[0] id")
}
// Change a parent field via the node
parentPtr := n.parent.(*ceModel.NetworkLocation)
//fmt.Printf(" node.parent ptr %p\n%+v\n", parentPtr, *parentPtr)
parentPtr.Id = testID
if nl.Id != testID {
t.Errorf("Failed changing NL id")
}
// Verify Node context
context := n.context.(map[string]string)
if context["pl"] != "phyLoc" || context["nl"] != "netLoc" {
t.Errorf("Failed to set context entries")
}
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
}
func TestNodeMapProcess(t *testing.T) {
fmt.Println("--- ", t.Name())
log.MeepTextLogInit(t.Name())
fmt.Println("Create a scenario structure")
scenario := new(ceModel.Scenario)
err := json.Unmarshal([]byte(testScenario), scenario)
if err != nil {
t.Errorf("Unable to unmarshall scenario")
}
fmt.Println("Create nodeMap")
nm := NewNodeMap()
if nm == nil {
t.Errorf("Unable to allocate nodeMap")
}
fmt.Println("Test Deployment")
if scenario.Deployment == nil {
t.Errorf("nil deployment")
}
fmt.Println("Test Process")
pl := &scenario.Deployment.Domains[1].Zones[1].NetworkLocations[1].PhysicalLocations[0]
//fmt.Printf(" scenario.Deployment.Domains[1].Zones[1].NetworkLocations[1].PhysicalLocation[0] has %d processes\n", len(pl.Processes))
for i := range pl.Processes {
proc := &pl.Processes[i]
context := make(map[string]string)
context["pl"] = "phyLoc"
context["nl"] = "netLoc"
nm.AddNode(NewNode(proc.Name, proc.Type_, proc, nil, pl, context))
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
//fmt.Printf(" nl%d: object @ %p\n%+v\n", i, proc, *proc)
//fmt.Printf(" nl%d: child @ nil\n%+v\n", i, nil)
//fmt.Printf(" nl%d: parent @ %p\n%+v\n", i, pl, *pl)
}
n := nm.FindByName("zone1-fog1-svc")
//fmt.Printf("%+v\n", n)
if n.object != &pl.Processes[1] {
t.Errorf("Process[1] wrong object reference ")
}
if n.child != nil {
t.Errorf("Process[1] wrong child reference ")
}
if n.parent != pl {
t.Errorf("PL[1] wrong parent reference ")
}
// Change an object field via the node
testID := "new-test-id"
objPtr := n.object.(*ceModel.Process)
//fmt.Printf(" node.object ptr %p\n%+v\n", objPtr, *objPtr)
objPtr.Id = testID
if pl.Processes[1].Id != testID {
t.Errorf("Failed changing Process id")
}
// Change a parent field via the node
parentPtr := n.parent.(*ceModel.PhysicalLocation)
//fmt.Printf(" node.parent ptr %p\n%+v\n", parentPtr, *parentPtr)
parentPtr.Id = testID
if pl.Id != testID {
t.Errorf("Failed changing PL id")
}
// Verify Node context
context := n.context.(map[string]string)
if context["pl"] != "phyLoc" || context["nl"] != "netLoc" {
t.Errorf("Failed to set context entries")
}