topologygenerator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +49 -0
  6. data/Gemfile +10 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +35 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/behaviors/serialize_behavior.rb +14 -0
  13. data/lib/builders_examples/pdm_builders/PhaseI/Flow_concrete_builder.rb +82 -0
  14. data/lib/builders_examples/pdm_builders/PhaseI/Host_concrete_builder.rb +24 -0
  15. data/lib/builders_examples/pdm_builders/PhaseI/Link_concrete_builder.rb +150 -0
  16. data/lib/builders_examples/pdm_builders/PhaseI/Router_concrete_builder.rb +24 -0
  17. data/lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb +86 -0
  18. data/lib/builders_examples/pdm_builders/PhaseI/pdm_constants.rb +111 -0
  19. data/lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/Flow_concrete_builder.rb +82 -0
  20. data/lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/Host_concrete_builder.rb +335 -0
  21. data/lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/Link_concrete_builder.rb +25 -0
  22. data/lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/Router_concrete_builder.rb +449 -0
  23. data/lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/output_concrete_builder.rb +229 -0
  24. data/lib/builders_examples/ruby_builders/Flow_concrete_builder.rb +5 -0
  25. data/lib/builders_examples/ruby_builders/Host_concrete_builder.rb +5 -0
  26. data/lib/builders_examples/ruby_builders/Link_concrete_builder.rb +5 -0
  27. data/lib/builders_examples/ruby_builders/Router_concrete_builder.rb +5 -0
  28. data/lib/builders_examples/ruby_builders/output_concrete_builder.rb +78 -0
  29. data/lib/command_line/command_line_arguments.rb +59 -0
  30. data/lib/createTopology.rb +10 -0
  31. data/lib/flows_distributions/constant_distribution.rb +7 -0
  32. data/lib/flows_distributions/exponential_distribution.rb +7 -0
  33. data/lib/flows_distributions/normal_distribution.rb +8 -0
  34. data/lib/flows_distributions/pareto_distribution.rb +9 -0
  35. data/lib/flows_distributions/split_distribution.rb +8 -0
  36. data/lib/network_entities/abstracts/flow.rb +27 -0
  37. data/lib/network_entities/abstracts/network_element.rb +19 -0
  38. data/lib/network_entities/abstracts/path.rb +16 -0
  39. data/lib/network_entities/physical/host.rb +10 -0
  40. data/lib/network_entities/physical/link.rb +36 -0
  41. data/lib/network_entities/physical/router.rb +12 -0
  42. data/lib/network_entities/topology.rb +69 -0
  43. data/lib/network_topologies_examples/PhaseI_onlyLAr_1FelixTo1SWROD.rb +93 -0
  44. data/lib/network_topologies_examples/octopus_topology.rb +66 -0
  45. data/lib/network_topologies_examples/phase1_topology_mininet/tdaq +4 -0
  46. data/lib/network_topologies_examples/phase1_topology_mininet/tdaq.py +99 -0
  47. data/lib/network_topologies_examples/sofisticated_octopus_topology.rb +121 -0
  48. data/lib/network_topologies_examples/tdaq_network_topology.rb +76 -0
  49. data/lib/network_topologies_examples/tdaq_topology_example.rb +119 -0
  50. data/lib/network_topologies_examples/tree_topology.rb +102 -0
  51. data/lib/output/FlowDefinitions.cpp +109 -0
  52. data/lib/output/copy_files.sh +8 -0
  53. data/lib/output/flows_definition.scilabParams +30 -0
  54. data/lib/output/hosts_definition.scilabParams +5 -0
  55. data/lib/output/links_definition.scilabParams +48 -0
  56. data/lib/output/routers_definition.scilabParams +24 -0
  57. data/lib/output/ruby_network_topology.rb +76 -0
  58. data/lib/output/topology.pdm +5321 -0
  59. data/lib/output_builder.rb +39 -0
  60. data/lib/providers/apis/onos_topology_provider.rb +146 -0
  61. data/lib/providers/customs/custom_topology_provider.rb +14 -0
  62. data/lib/providers/interface_topology_provider.rb +11 -0
  63. data/lib/topologygenerator/version.rb +3 -0
  64. data/lib/topologygenerator.rb +34 -0
  65. data/lib/utils/custom_files_utils.rb +16 -0
  66. data/topologygenerator.gemspec +45 -0
  67. metadata +188 -0
@@ -0,0 +1,449 @@
1
+ module RouterConcreteBuilder
2
+ def build_output_representation
3
+ template =
4
+ " Coupled
5
+ {
6
+ Type = Coordinator
7
+ Name = #{id}
8
+ Ports = #{@in_elements.size}; #{@out_elements.size}
9
+ Description = Coupled DEVS model
10
+ Graphic
11
+ {
12
+ Position = #{-13455 + 2000 * (my_number - 2)} ; #{-9510 + 1600 * (my_number - 2)}
13
+ Dimension = 660; 1470
14
+ Direction = Down
15
+ Color = 15
16
+ Icon = %datanetworks%switch.jpg
17
+ Window = 5000; 5000; 5000; 5000
18
+ }
19
+ Parameters
20
+ {
21
+ }
22
+ System
23
+ {
24
+ "
25
+
26
+ @in_elements.each_with_index do |in_elem, index|
27
+ template += buildInPort index
28
+ end
29
+
30
+ @out_elements.each_with_index do |out_elem, index|
31
+ template += buildOutPort index
32
+ end
33
+
34
+ template += buildRouting @in_elements.size, @out_elements.size
35
+
36
+ scilab_router_definition = ''
37
+ scilab_router_definition += "\n"
38
+ scilab_router_definition += "#{id}.numberOfQueues = #{priority_weights.size} ;\n"
39
+ scilab_router_definition += "#{id}.queueCapacity = #{buffer}; \n"
40
+ @out_elements.each_with_index do |out_elem, index|
41
+ template += buildEgressPort index
42
+ scilab_router_definition += "#{id}.egressPort#{index}.PriorityQueue.WRRScheduler.weights = #{priority_weights}; \n"
43
+ end
44
+
45
+ template += buildLines @in_elements.size, @out_elements.size
46
+
47
+ template += " }
48
+ }
49
+ "
50
+
51
+ {'scilab'=>scilab_router_definition, 'pdm'=>template}
52
+ end
53
+
54
+ def buildInPort (portNumber)
55
+ " Inport
56
+ {
57
+ Name = Inport#{portNumber}
58
+ CoupledPort = #{portNumber+1}
59
+ Description =
60
+ Graphic
61
+ {
62
+ Position = #{-5000 + 1000* portNumber+1} ; -6525
63
+ Dimension = 600
64
+ Direction = Right
65
+ }
66
+ }
67
+ "
68
+ end
69
+
70
+ def buildOutPort (portNumber)
71
+ " Outport
72
+ {
73
+ Name = Outport#{portNumber+1}
74
+ CoupledPort = #{portNumber+1}
75
+ Description =
76
+ Graphic
77
+ {
78
+ Position = #{-5000 + 1000* portNumber} ; 2175
79
+ Dimension = 600
80
+ Direction = Right
81
+ }
82
+ }
83
+ "
84
+ end
85
+
86
+ def buildRouting (nInports, nOutports)
87
+ " Atomic
88
+ {
89
+ Name = Routing
90
+ Ports = #{nInports} ; #{nOutports}
91
+ Path = PhaseI/Router.h
92
+ Description = InN: Incomming packets\\nInN: Outgoing packets \\n This model routes incoming packets to outports. The decision is based on the global table GlobalFlowBasedRoutingTable(flowId, routerName). If there are more than one possible outport, the model uses a routingPolicy (currently hardcoded to Round-Robin) to decide.
93
+ Graphic
94
+ {
95
+ Position = -3600 ; -4155
96
+ Dimension = 615 ; 1785
97
+ Direction = Down
98
+ Color = 15
99
+ Icon = %datanetworks%router.jpg
100
+ }
101
+ Parameters
102
+ {
103
+ }
104
+ }
105
+ "
106
+ end
107
+
108
+ def buildEgressPort (portNumber)
109
+ " Coupled
110
+ {
111
+ Type = Coordinator
112
+ Name = egressPort#{portNumber}
113
+ Ports = 1; 1
114
+ Description = Coupled DEVS model
115
+ Graphic
116
+ {
117
+ Position = #{-4710 + 1200 * portNumber}; -1860
118
+ Dimension = 1170; 870
119
+ Direction = Down
120
+ Color = 15
121
+ Icon = %datanetworks%priorityegressport.jpg
122
+ Window = 5000; 5000; 5000; 5000
123
+ }
124
+ Parameters
125
+ {
126
+ }
127
+ System
128
+ {
129
+ Inport
130
+ {
131
+ Name = Inport0
132
+ CoupledPort = 1
133
+ Description =
134
+ Graphic
135
+ {
136
+ Position = -4695 ; -3525
137
+ Dimension = 390
138
+ Direction = Right
139
+ }
140
+ }
141
+ Outport
142
+ {
143
+ Name = Outport0
144
+ CoupledPort = 1
145
+ Description =
146
+ Graphic
147
+ {
148
+ Position = -1785 ; 600
149
+ Dimension = 435
150
+ Direction = Right
151
+ }
152
+ }
153
+ Atomic
154
+ {
155
+ Name = Link
156
+ Ports = 1 ; 1
157
+ Path = PhaseI/Link.h
158
+ Description = Vector to scalar signal
159
+ Graphic
160
+ {
161
+ Position = -3990 ; -915
162
+ Dimension = 630 ; 630
163
+ Direction = Down
164
+ Color = 15
165
+ Icon = %vectors%vec2scalar.svg
166
+ }
167
+ Parameters
168
+ {
169
+ link.capacity = Str; #{id}.egressPort#{portNumber}.link.capacity ; Signal Index
170
+ link.delay = Str; #{id}.egressPort#{portNumber}.link.delay ;
171
+ }
172
+ }
173
+ Coupled
174
+ {
175
+ Type = Coordinator
176
+ Name = PriorityQueue
177
+ Ports = 2; 1
178
+ Description = Coupled DEVS model
179
+ Graphic
180
+ {
181
+ Position = -4080; -2895
182
+ Dimension = 810; 990
183
+ Direction = Down
184
+ Color = 15
185
+ Icon = %datanetworks%priorityqueue.jpg
186
+ Window = 5000; 5000; 5000; 5000
187
+ }
188
+ Parameters
189
+ {
190
+ }
191
+ System
192
+ {
193
+ Inport
194
+ {
195
+ Name = inPackets
196
+ CoupledPort = 1
197
+ Description =
198
+ Graphic
199
+ {
200
+ Position = -10710 ; -2625
201
+ Dimension = 570
202
+ Direction = Right
203
+ }
204
+ }
205
+ Outport
206
+ {
207
+ Name = outPackets
208
+ CoupledPort = 1
209
+ Description =
210
+ Graphic
211
+ {
212
+ Position = -3990 ; -3750
213
+ Dimension = 630
214
+ Direction = Right
215
+ }
216
+ }
217
+ Inport
218
+ {
219
+ Name = inDequeReq
220
+ CoupledPort = 2
221
+ Description =
222
+ Graphic
223
+ {
224
+ Position = -5880 ; -525
225
+ Dimension = 525
226
+ Direction = Right
227
+ }
228
+ }
229
+ Atomic
230
+ {
231
+ Name = prioritySelect
232
+ Ports = 1 ; 1
233
+ Path = PhaseI/PacketPrioritySelect.h
234
+ Description = Receives packets, and based on their flowId it selects which output port to send it through
235
+ Graphic
236
+ {
237
+ Position = -8805 ; -2985
238
+ Dimension = 675 ; 720
239
+ Direction = Right
240
+ Color = 15
241
+ Icon = None
242
+ }
243
+ Parameters
244
+ {
245
+ }
246
+ }
247
+ Atomic
248
+ {
249
+ Name = VQueues
250
+ Ports = 2 ; 2
251
+ Path = PhaseI/Vector_NetworkQueueWithSizeOutput.h
252
+ Description = In0 Incomming packets to queue\\nIn1 Incoming signal to request dequeue\\nOut0 Outgoing dequeued packets\\nOut1 Outgoing queue lenght information\\n\\nQueues incoming packets and enqueues them as required by a\\nexternal entity. FIFO Policy (FirstInFirstOut). Provides information\\nits internal state.
253
+ Graphic
254
+ {
255
+ Position = -7200 ; -2805
256
+ Dimension = 600 ; 675
257
+ Direction = Right
258
+ Color = 15
259
+ Icon = %datanetworks%queue_vec.png
260
+ }
261
+ Parameters
262
+ {
263
+ MaxCapacity = Str; #{id}.queueCapacity ; Queue Capacity in Bytes. (Use -1 for INF capacity)
264
+ ForcedPeriod = Str; -1 ; Force minimum period to transition. Use -1 for INF
265
+ Instances = Str; #{id}.numberOfQueues ;
266
+ }
267
+ }
268
+ Atomic
269
+ {
270
+ Name = WRRScheduler
271
+ Ports = 2 ; 1
272
+ Path = PhaseI/WRRScheduler.h
273
+ Description = Atomic DEVS model
274
+ Graphic
275
+ {
276
+ Position = -4530 ; -2505
277
+ Dimension = 675 ; 675
278
+ Direction = Right
279
+ Color = 15
280
+ Icon = None
281
+ }
282
+ Parameters
283
+ {
284
+ numberOfQueues = Str; #{id}.numberOfQueues ;
285
+ weights = Str; #{id}.egressPort#{portNumber}.PriorityQueue.WRRScheduler.weights; vector<double> with the weights for each queue
286
+ }
287
+ }
288
+ Atomic
289
+ {
290
+ Name = Vect2Scal
291
+ Ports = 1 ; 1
292
+ Path = vector/Vector2Scalar.h
293
+ Description = Vector to scalar signal
294
+ Graphic
295
+ {
296
+ Position = -5505 ; -4080
297
+ Dimension = 675 ; 675
298
+ Direction = Right
299
+ Color = 15
300
+ Icon = %vectors%vec2scalar.svg
301
+ }
302
+ Parameters
303
+ {
304
+ Index = Str; -1 ; Signal Index
305
+ }
306
+ }
307
+ Line
308
+ {
309
+ Source = Cmp ; 1 ; 1 ; 0
310
+ Sink = Cmp ; 2 ; 1 ; -1
311
+ PointX = -8025 ; -8025 ; -7365
312
+ PointY = -2625 ; -2625 ; -2625
313
+ }
314
+ Line
315
+ {
316
+ Source = Prt ; 1 ; 1 ; 0
317
+ Sink = Cmp ; 1 ; 1 ; -1
318
+ PointX = -9975 ; -9975 ; -8940
319
+ PointY = -2625 ; -2625 ; -2625
320
+ }
321
+ Line
322
+ {
323
+ Source = Cmp ; 2 ; 2 ; 0
324
+ Sink = Cmp ; 3 ; 1 ; -1
325
+ PointX = -6450 ; -6450 ; -4665
326
+ PointY = -2325 ; -2325 ; -2325
327
+ }
328
+ Line
329
+ {
330
+ Source = Prt ; 3 ; 1 ; 0
331
+ Sink = Cmp ; 3 ; 2 ; -1
332
+ PointX = -5250 ; -5025 ; -5025 ; -4665
333
+ PointY = -525 ; -525 ; -2025 ; -2025
334
+ }
335
+ Line
336
+ {
337
+ Source = Cmp ; 3 ; 1 ; 0
338
+ Sink = Cmp ; 2 ; 2 ; -1
339
+ PointX = -3750 ; -3300 ; -3300 ; -7500 ; -7500 ; -7365
340
+ PointY = -2175 ; -2175 ; -1275 ; -1275 ; -2325 ; -2325
341
+ }
342
+ Line
343
+ {
344
+ Source = Cmp ; 4 ; 1 ; 0
345
+ Sink = Prt ; 2 ; 1 ; -1
346
+ PointX = -4725 ; -4725 ; -4140
347
+ PointY = -3750 ; -3750 ; -3750
348
+ }
349
+ Line
350
+ {
351
+ Source = Cmp ; 4 ; 1 ; -1
352
+ Sink = Cmp ; 2 ; 1 ; 0
353
+ PointX = -5640 ; -6075 ; -6075 ; -6450
354
+ PointY = -3750 ; -3750 ; -2625 ; -2625
355
+ }
356
+ }
357
+ }
358
+ Point
359
+ {
360
+ ConectedLines = 1 ; 4 ; 5
361
+ ConectedExtrems = Org ; Org ; Org
362
+ Position = -3675 ; 150
363
+ }
364
+ Line
365
+ {
366
+ Source = Cmp ; 1 ; 1 ; 0
367
+ Sink = Pnt ; 1 ; -1 ; 0
368
+ PointX = -3675 ; -3675 ; -3675
369
+ PointY = -150 ; -150 ; 150
370
+ }
371
+ Line
372
+ {
373
+ Source = Prt ; 1 ; 1 ; 0
374
+ Sink = Cmp ; 2 ; 1 ; -1
375
+ PointX = -4200 ; -3900 ; -3900
376
+ PointY = -3525 ; -3525 ; -2940
377
+ }
378
+ Line
379
+ {
380
+ Source = Cmp ; 2 ; 1 ; 0
381
+ Sink = Cmp ; 1 ; 1 ; -1
382
+ PointX = -3675 ; -3675 ; -3675
383
+ PointY = -1875 ; -1875 ; -1065
384
+ }
385
+ Line
386
+ {
387
+ Source = Cmp ; 2 ; 2 ; -1
388
+ Sink = Pnt ; 1 ; -1 ; 0
389
+ PointX = -3450 ; -3450 ; -2775 ; -2775 ; -3675
390
+ PointY = -2940 ; -3300 ; -3300 ; 150 ; 150
391
+ }
392
+ Line
393
+ {
394
+ Source = Pnt ; 1 ; -1 ; 0
395
+ Sink = Prt ; 2 ; 1 ; -1
396
+ PointX = -3675 ; -3675 ; -1965
397
+ PointY = 150 ; 600 ; 600
398
+ }
399
+ }
400
+ }
401
+ "
402
+ end
403
+
404
+ def buildLines(in_elements_quantity, out_elements_quantity)
405
+ routing_position = 1 #Because is the first component after ports
406
+ first_egress_port_position = routing_position
407
+ first_output_port_position = in_elements_quantity # Because I have as many inputs_ports as in_elements
408
+
409
+ lines = ''
410
+ #from inports to Routing
411
+ (1..in_elements_quantity).each do |i|
412
+ lines += "Line
413
+ {
414
+ Source = Prt ; #{i} ; 1 ; 0
415
+ Sink = Cmp ; #{routing_position} ; #{i} ; -1
416
+ PointX = -11325 ; -11325 ; -9840
417
+ PointY = -2625 ; -2625 ; -2625
418
+ }
419
+ "
420
+ end
421
+
422
+ # from Routing to egressPorts
423
+ (1..out_elements_quantity).each do |i|
424
+ lines += "Line
425
+ {
426
+ Source = Cmp ; #{routing_position} ; #{i} ; 0
427
+ Sink = Cmp ; #{first_egress_port_position + i} ; 1 ; -1
428
+ PointX = -11325 ; -11325 ; -9840
429
+ PointY = -2625 ; -2625 ; -2625
430
+ }
431
+ "
432
+ end
433
+
434
+ # from egressPorts to outports
435
+ (1..out_elements_quantity).each do |i|
436
+ lines += "Line
437
+ {
438
+ Source = Cmp ; #{first_egress_port_position + i} ; 1 ; 0
439
+ Sink = Prt ; #{first_output_port_position + i} ; 1 ; -1
440
+ PointX = -11325 ; -11325 ; -9840
441
+ PointY = -2625 ; -2625 ; -2625
442
+ }
443
+ "
444
+ end
445
+
446
+ lines
447
+ end
448
+
449
+ end
@@ -0,0 +1,229 @@
1
+ module OutputConcreteBuilder
2
+ NUMBER_OF_PDM_MODELS_IN_STRUCTURE = 3
3
+
4
+ OUTPUT_PDM_FILE_NAME = 'topology.pdm'
5
+ OUTPUT_CPP_FILE_NAME = 'FlowDefinitions.cpp'
6
+ OUTPUT_FLOWS_SCILAB_FILE_NAME = 'flows_definition.scilabParams'
7
+ OUTPUT_ROUTERS_SCILAB_FILE_NAME = 'routers_definition.scilabParams'
8
+ OUTPUT_LINKS_SCILAB_FILE_NAME = 'links_definition.scilabParams'
9
+ OUTPUT_HOSTS_SCILAB_FILE_NAME = 'hosts_definition.scilabParams'
10
+
11
+ def initialize_concrete_builder(topology_provider, directory_concrete_builders, output_directory)
12
+ @topology_provider = topology_provider
13
+ @directory_concrete_builders = directory_concrete_builders
14
+ @output_directory = output_directory
15
+ end
16
+
17
+ def build_output_content
18
+ build_host_link_router_output
19
+
20
+ build_flow_output
21
+ end
22
+
23
+ def build_host_link_router_output
24
+ graph_elements = topology_provider.get_topology
25
+ pdm_topology = pmd_initial_struture
26
+
27
+ router_scilab_params = ''
28
+ link_scilab_params = ''
29
+ host_scilab_params = ''
30
+
31
+ elements_which_are_not_flows = graph_elements.select{ |elem| [Host,Router,Link].include? elem.class }
32
+
33
+ elements_which_are_not_flows.each do |element|
34
+ output_representation = element.transform_to_output_representation @directory_concrete_builders
35
+ pdm_topology += output_representation['pdm']
36
+ router_scilab_params += output_representation['scilab'] if element.is_a? Router
37
+ link_scilab_params += output_representation['scilab'] if element.is_a? Link
38
+ host_scilab_params += output_representation['scilab'] if element.is_a? Host
39
+ end
40
+
41
+ pdm_topology += create_lines_between_graph_elements graph_elements
42
+
43
+ pdm_topology += pdm_final_structure
44
+
45
+ write_file "#{@output_directory}/#{OUTPUT_PDM_FILE_NAME}",
46
+ pdm_topology
47
+
48
+ write_file "#{@output_directory}/#{OUTPUT_ROUTERS_SCILAB_FILE_NAME}",
49
+ router_scilab_params
50
+
51
+ write_file "#{@output_directory}/#{OUTPUT_LINKS_SCILAB_FILE_NAME}",
52
+ link_scilab_params
53
+
54
+ write_file "#{@output_directory}/#{OUTPUT_HOSTS_SCILAB_FILE_NAME}",
55
+ host_scilab_params
56
+ end
57
+
58
+ def create_lines_between_graph_elements(graph_elements)
59
+ links = graph_elements.select { |node| node.is_a? Link }
60
+ lines = ''
61
+ links.each do |link|
62
+ src_pdm_pos = get_pdm_position link.src_element, graph_elements
63
+ dst_pdm_pos = get_pdm_position link.dst_element, graph_elements
64
+ link_pdm_pos = get_pdm_position link, graph_elements
65
+ lines += link.create_pdm_line_between_src_and_dst src_pdm_pos, dst_pdm_pos, link_pdm_pos
66
+ end
67
+ lines
68
+ end
69
+
70
+ def get_pdm_position(network_elem, graph_elements)
71
+ #Here links DONT have a modeled representation, so we just have to count routers and hosts
72
+ return -1 if network_elem.is_a? Link
73
+
74
+ network_elem_index = graph_elements.index { |elem| elem.id == network_elem.id }
75
+ my_pdm_position = 0
76
+ (0..network_elem_index).each do |i|
77
+ my_pdm_position += 1 unless graph_elements[i].is_a? Link
78
+ end
79
+ NUMBER_OF_PDM_MODELS_IN_STRUCTURE + my_pdm_position
80
+ end
81
+
82
+ def build_flow_output
83
+ graph_elements = topology_provider.get_topology
84
+
85
+ flows = graph_elements.select { |elem| elem.is_a? Flow }
86
+
87
+ scilab_flows_definition = ''
88
+ cplusplus_flows_defined = ''
89
+ flows.each do |flow|
90
+ flow_output = flow.transform_to_output_representation @directory_concrete_builders
91
+ scilab_flows_definition += flow_output['scilab']
92
+ cplusplus_flows_defined += flow_output['cplusplus']
93
+ end
94
+
95
+ write_file "#{@output_directory}/#{OUTPUT_FLOWS_SCILAB_FILE_NAME}",
96
+ scilab_flows_definition
97
+
98
+ write_file "#{@output_directory}/#{OUTPUT_CPP_FILE_NAME}",
99
+ (build_cplusplus_output cplusplus_flows_defined)
100
+ end
101
+
102
+ def build_cplusplus_output(cplusplus_flows_defined)
103
+ cplusplus_flows_definition = "#include \"FlowDefinitions.h\" \n"
104
+ cplusplus_flows_definition += "\n"
105
+ cplusplus_flows_definition += "std::multimap<std::string, std::shared_ptr<Flow>> FlowDefinitions::Flows; \n"
106
+ cplusplus_flows_definition += "\n"
107
+ cplusplus_flows_definition += "void FlowDefinitions::defineFlows(){ \n"
108
+ cplusplus_flows_definition += "\n"
109
+ cplusplus_flows_definition += cplusplus_flows_defined
110
+ cplusplus_flows_definition += '}'
111
+ cplusplus_flows_definition
112
+ end
113
+
114
+ def pmd_initial_struture
115
+ "Coupled
116
+ {
117
+ Type = Root
118
+ Name = MyTopology
119
+ Ports = 0; 0
120
+ Description = Testing the creation of a topology by getting the info from the controller
121
+ Graphic
122
+ {
123
+ Position = 0; 0
124
+ Dimension = 600; 600
125
+ Direction = Right
126
+ Color = 15
127
+ Icon =
128
+ Window = 5000; 5000; 5000; 5000
129
+ }
130
+ Parameters
131
+ {
132
+ }
133
+ System
134
+ {
135
+ Atomic
136
+ {
137
+ Name = LoadScilabParams
138
+ Ports = 1 ; 0
139
+ Path = sinks/RunScilabJob.h
140
+ Description = If Scilab is configured as backed in the cmd line options, this model runs Scilab commands at Init, Exit and when receive events.
141
+ Graphic
142
+ {
143
+ Position = -13845 ; -14220
144
+ Dimension = 540 ; 540
145
+ Direction = Right
146
+ Color = 15
147
+ Icon = %sinks%scilab.ico
148
+ }
149
+ Parameters
150
+ {
151
+ Run at Init = Str; exec('#{File.absolute_path(@output_directory)}/Scilab/model.scilabParams', 0) ; Scilab Job at Init
152
+ Run at External = Str; ; Scilab Job when receive event
153
+ Run at Exit = Str; ; Scilab Job at Exit
154
+ }
155
+ }
156
+ Atomic
157
+ {
158
+ Name = ExperimenetTracker
159
+ Ports = 0 ; 0
160
+ Path = sinks/SimulationExperimentTracker.h
161
+ Description = Allows to use multiple simulation runs setting new parameter values in each run. It configures Scilab variables according to the current simunation number. This model should run with 1st priority!!
162
+ Graphic
163
+ {
164
+ Position = -11220 ; -14220
165
+ Dimension = 540 ; 540
166
+ Direction = Right
167
+ Color = 15
168
+ Icon = %realtime%lcd.svg
169
+ }
170
+ Parameters
171
+ {
172
+ ScilabSimulationSetID = Str; SimulationName ; indicates the simulation set ID
173
+ ScilabSimulationCounterVariableName = Str; ExperimentNumber ; Name of the Scilab variable that indicates the simulation number.
174
+ ScilabParametersVariableName = Str; ParameterValues ; Name of the Scilab variable that contains the parameter values for each simulation
175
+ ScilabParametersValuesVariableName = Str; ParameterNames ; Name of the Scilab variable that contains the parameter names for each simulation
176
+ }
177
+ }
178
+ Atomic
179
+ {
180
+ Name = UpdateScilabParams
181
+ Ports = 1 ; 0
182
+ Path = sinks/RunScilabJob.h
183
+ Description = If Scilab is configured as backed in the cmd line options, this model runs Scilab commands at Init, Exit and when receive events.
184
+ Graphic
185
+ {
186
+ Position = -8670 ; -14220
187
+ Dimension = 540 ; 540
188
+ Direction = Right
189
+ Color = 15
190
+ Icon = %sinks%scilab.ico
191
+ }
192
+ Parameters
193
+ {
194
+ Run at Init = Str; ; Scilab Job at Init
195
+ Run at External = Str; ; Scilab Job when receive event
196
+ Run at Exit = Str; ; Scilab Job at Exit
197
+ }
198
+ }
199
+ "
200
+ end
201
+
202
+ def pdm_final_structure
203
+ "Atomic
204
+ {
205
+ Name = FinalizationCommands
206
+ Ports = 0 ; 0
207
+ Path = sinks/multipleSimulationCommands.h
208
+ Description = Executes Scilab commands when using multiple simulation runs (at the end of each simulation, and at the end of ALL simulations).\\nThis model should run with LAST priority
209
+ Graphic
210
+ {
211
+ Position = -6270 ; -14220
212
+ Dimension = 540 ; 540
213
+ Direction = Right
214
+ Color = 15
215
+ Icon = %datanetworks%scilab.bmp
216
+ }
217
+ Parameters
218
+ {
219
+ initSimulationCommandName = Str; #{File.absolute_path(@output_directory)}/Scilab/firstSimulation.sce ;
220
+ eachSimulationCommandName = Str; #{File.absolute_path(@output_directory)}/Scilab/eachSimulation.sce ;
221
+ lastSimulationCommandName = Str; #{File.absolute_path(@output_directory)}/Scilab/lastSimulation.sce ;
222
+ }
223
+ }
224
+ }
225
+ }"
226
+ end
227
+
228
+
229
+ end
@@ -0,0 +1,5 @@
1
+ module FlowConcreteBuilder
2
+ def build_output_representation
3
+ ""
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module HostConcreteBuilder
2
+ def build_output_representation
3
+ "hosts.push @topology.add_host \"#{id}\""
4
+ end
5
+ end