module OutputConcreteBuilder
Constants
- NUMBER_OF_PDM_MODELS_IN_STRUCTURE
- OUTPUT_CPP_FILE_NAME
- OUTPUT_FLOWS_SCILAB_FILE_NAME
- OUTPUT_HOSTS_SCILAB_FILE_NAME
- OUTPUT_LINKS_SCILAB_FILE_NAME
- OUTPUT_PDM_FILE_NAME
- OUTPUT_ROUTERS_SCILAB_FILE_NAME
- OUTPUT_RUBY_FILE_NAME
- OUTPUT_SCILAB_FILE_NAME
Public Instance Methods
add_elements_of_type(graph_elements, type)
click to toggle source
# File lib/builders_examples/ruby_builders/output_concrete_builder.rb, line 45 def add_elements_of_type(graph_elements, type) elements_to_add = graph_elements.select { |elem| elem.is_a? type } elements_def = '' elements_to_add.each do |element| elements_def += " #{element.transform_to_output_representation @directory_concrete_builders} \n" end elements_def = replace_ids_host_router_for_index graph_elements, elements_def if type == Link elements_def += "\n" elements_def end
build_cplusplus_output(cplusplus_flows_defined)
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 75 def build_cplusplus_output(cplusplus_flows_defined) cplusplus_flows_definition = "#include \"FlowDefinitions.h\" \n" cplusplus_flows_definition += "\n" cplusplus_flows_definition += "std::multimap<std::string, std::shared_ptr<Flow>> FlowDefinitions::Flows; \n" cplusplus_flows_definition += "\n" cplusplus_flows_definition += "void FlowDefinitions::defineFlows(){ \n" cplusplus_flows_definition += "\n" cplusplus_flows_definition += cplusplus_flows_defined cplusplus_flows_definition += '}' cplusplus_flows_definition end
build_flow_output()
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 55 def build_flow_output graph_elements = topology_provider.get_topology flows = graph_elements.select { |elem| elem.is_a? Flow } scilab_flows_definition = '' cplusplus_flows_defined = '' flows.each do |flow| flow_output = flow.transform_to_output_representation @directory_concrete_builders scilab_flows_definition += flow_output['scilab'] cplusplus_flows_defined += flow_output['cplusplus'] end write_file "#{@output_directory}/#{OUTPUT_SCILAB_FILE_NAME}", scilab_flows_definition write_file "#{@output_directory}/#{OUTPUT_CPP_FILE_NAME}", (build_cplusplus_output cplusplus_flows_defined) end
build_host_link_router_output()
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/output_concrete_builder.rb, line 23 def build_host_link_router_output graph_elements = topology_provider.get_topology pdm_topology = pmd_initial_struture router_scilab_params = '' link_scilab_params = '' host_scilab_params = '' elements_which_are_not_flows = graph_elements.select{ |elem| [Host,Router,Link].include? elem.class } elements_which_are_not_flows.each do |element| output_representation = element.transform_to_output_representation @directory_concrete_builders pdm_topology += output_representation['pdm'] router_scilab_params += output_representation['scilab'] if element.is_a? Router link_scilab_params += output_representation['scilab'] if element.is_a? Link host_scilab_params += output_representation['scilab'] if element.is_a? Host end pdm_topology += create_lines_between_graph_elements graph_elements pdm_topology += pdm_final_structure write_file "#{@output_directory}/#{OUTPUT_PDM_FILE_NAME}", pdm_topology write_file "#{@output_directory}/#{OUTPUT_ROUTERS_SCILAB_FILE_NAME}", router_scilab_params write_file "#{@output_directory}/#{OUTPUT_LINKS_SCILAB_FILE_NAME}", link_scilab_params write_file "#{@output_directory}/#{OUTPUT_HOSTS_SCILAB_FILE_NAME}", host_scilab_params end
build_output_content()
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 12 def build_output_content build_pdm_output build_flow_output end
build_pdm_output()
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 18 def build_pdm_output graph_elements = topology_provider.get_topology graph_elements = graph_elements.select { |elem| [Host,Link,Router].include? elem.class } pdm_topology = PDM_INITIAL_STRUCTURE graph_elements.each do |element| pdm_topology += element.transform_to_output_representation @directory_concrete_builders end pdm_topology += create_lines_between_graph_elements graph_elements pdm_topology += PDM_FINAL_STRUCTURE write_file "#{@output_directory}/#{OUTPUT_PDM_FILE_NAME}", pdm_topology end
create_lines_between_graph_elements(graph_elements)
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 37 def create_lines_between_graph_elements(graph_elements) links = graph_elements.select { |node| node.is_a? Link } lines = '' links.each do |link| src_pdm_pos = get_pdm_position link.src_element dst_pdm_pos = get_pdm_position link.dst_element link_pdm_pos = get_pdm_position link lines += link.create_pdm_line_between_src_and_dst src_pdm_pos, dst_pdm_pos, link_pdm_pos end lines end
get_pdm_position(network_elem)
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 49 def get_pdm_position(network_elem) #Here links have a modeled representation, so we have to count the link as well. #We have routers, hosts and links as either atomic or compunded models NUMBER_OF_PDM_MODELS_IN_STRUCTURE + network_elem.my_number end
initialize_concrete_builder(topology_provider, directory_concrete_builders, output_directory)
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseI/output_concrete_builder.rb, line 6 def initialize_concrete_builder(topology_provider, directory_concrete_builders, output_directory) @topology_provider = topology_provider @directory_concrete_builders = directory_concrete_builders # make's sense? @output_directory = output_directory end
pdm_final_structure()
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/output_concrete_builder.rb, line 202 def pdm_final_structure "Atomic { Name = FinalizationCommands Ports = 0 ; 0 Path = sinks/multipleSimulationCommands.h 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 Graphic { Position = -6270 ; -14220 Dimension = 540 ; 540 Direction = Right Color = 15 Icon = %datanetworks%scilab.bmp } Parameters { initSimulationCommandName = Str; ../examples/PhaseI_topologies/lar_with_hlt/firstSimulation.sce ; eachSimulationCommandName = Str; ../examples/PhaseI_topologies/lar_with_hlt/eachSimulation.sce ; lastSimulationCommandName = Str; ../examples/PhaseI_topologies/lar_with_hlt/lastSimulation.sce ; } } } }" end
pmd_initial_struture()
click to toggle source
# File lib/builders_examples/pdm_builders/PhaseIWithPriorityQueues/output_concrete_builder.rb, line 114 def pmd_initial_struture "Coupled { Type = Root Name = MyTopology Ports = 0; 0 Description = Testing the creation of a topology by getting the info from the controller Graphic { Position = 0; 0 Dimension = 600; 600 Direction = Right Color = 15 Icon = Window = 5000; 5000; 5000; 5000 } Parameters { } System { Atomic { Name = LoadScilabParams Ports = 1 ; 0 Path = sinks/RunScilabJob.h Description = If Scilab is configured as backed in the cmd line options, this model runs Scilab commands at Init, Exit and when receive events. Graphic { Position = -13845 ; -14220 Dimension = 540 ; 540 Direction = Right Color = 15 Icon = %sinks%scilab.ico } Parameters { Run at Init = Str; exec('../examples/PhaseI_topologies/lar_with_hlt/model.scilabParams', 0) ; Scilab Job at Init Run at External = Str; ; Scilab Job when receive event Run at Exit = Str; ; Scilab Job at Exit } } Atomic { Name = ExperimenetTracker Ports = 0 ; 0 Path = sinks/SimulationExperimentTracker.h 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!! Graphic { Position = -11220 ; -14220 Dimension = 540 ; 540 Direction = Right Color = 15 Icon = %realtime%lcd.svg } Parameters { ScilabSimulationSetID = Str; SimulationName ; indicates the simulation set ID ScilabSimulationCounterVariableName = Str; ExperimentNumber ; Name of the Scilab variable that indicates the simulation number. ScilabParametersVariableName = Str; ParameterValues ; Name of the Scilab variable that contains the parameter values for each simulation ScilabParametersValuesVariableName = Str; ParameterNames ; Name of the Scilab variable that contains the parameter names for each simulation } } Atomic { Name = UpdateScilabParams Ports = 1 ; 0 Path = sinks/RunScilabJob.h Description = If Scilab is configured as backed in the cmd line options, this model runs Scilab commands at Init, Exit and when receive events. Graphic { Position = -8670 ; -14220 Dimension = 540 ; 540 Direction = Right Color = 15 Icon = %sinks%scilab.ico } Parameters { Run at Init = Str; ; Scilab Job at Init Run at External = Str; ; Scilab Job when receive event Run at Exit = Str; ; Scilab Job at Exit } } " end
replace_ids_host_router_for_index(graph_elements, links_definition)
click to toggle source
# File lib/builders_examples/ruby_builders/output_concrete_builder.rb, line 60 def replace_ids_host_router_for_index(graph_elements, links_definition) # Links have a dst and a src. These elements are in one of either hosts or routers array, # however the index is unkown for the Link!, Instead of serializing the src/dst, the link # prints it's element id. We now have to find this id (which is a string), and replace it by the # corresponding element of the array. hosts = graph_elements.select { |elem| elem.is_a? Host } routers = graph_elements.select { |elem| elem.is_a? Router } hosts.each_with_index do |host,index| links_definition.gsub! host.id, "hosts[#{index}]" end routers.each_with_index do |router,index| links_definition.gsub! router.id, "routers[#{index}]" end links_definition end