class Topology
Attributes
topology_elements[R]
Public Class Methods
new()
click to toggle source
# File lib/network_entities/topology.rb, line 11 def initialize @topology_elements = [] end
Public Instance Methods
add_flow(id, priority, path, distribution_rate, distribution_size)
click to toggle source
# File lib/network_entities/topology.rb, line 60 def add_flow(id, priority, path, distribution_rate, distribution_size) raise "ID '#{id}' already exists in topology" if get_element_by_id id distribution_rate ||= ConstantDistribution.new 0 distribution_size ||= ConstantDistribution.new 0 new_flow = Flow.new id, priority, path, distribution_rate, distribution_size @topology_elements.push new_flow new_flow end
add_full_duplex_link(id, src, src_port, dst, dst_port, bandwith = nil)
click to toggle source
# File lib/network_entities/topology.rb, line 55 def add_full_duplex_link(id, src, src_port, dst, dst_port, bandwith = nil) add_link("#{id}_up", src, src_port, dst, dst_port, bandwith) # up add_link("#{id}_down", dst, dst_port, src, src_port, bandwith) # down end
add_host(id, ips=["127.0.0.1"], mac="9A:4A:43:D4:36:45", queue_capacity=-1)
click to toggle source
# File lib/network_entities/topology.rb, line 27 def add_host(id, ips=["127.0.0.1"], mac="9A:4A:43:D4:36:45", queue_capacity=-1) raise "ID '#{id}' already exists in topology" if get_element_by_id id new_host = Host.new id, ips, mac, queue_capacity @topology_elements.push new_host new_host end
add_link(id, src, src_port, dst, dst_port, bandwith = nil)
click to toggle source
# File lib/network_entities/topology.rb, line 43 def add_link(id, src, src_port, dst, dst_port, bandwith = nil) raise "ID '#{id}' already exists in topology" if get_element_by_id id # if they sent the id of the src or dst => search the object src_node = (src.is_a? NetworkElement) ? src : (get_element_by_id src) dst_node = (dst.is_a? NetworkElement) ? dst : (get_element_by_id dst) new_link = Link.new id, src_node, src_port, dst_node, dst_port, bandwith @topology_elements.push new_link new_link end
add_router(id, priority_weights=[1], buffer=-1)
click to toggle source
# File lib/network_entities/topology.rb, line 35 def add_router(id, priority_weights=[1], buffer=-1) raise "ID '#{id}' already exists in topology" if get_element_by_id id new_router = Router.new id, priority_weights, buffer @topology_elements.push new_router new_router end
elements_of_type(type)
click to toggle source
# File lib/network_entities/topology.rb, line 19 def elements_of_type(type) @topology_elements.select { |elem| elem.is_a? type } end
get_element_by_id(element_id)
click to toggle source
# File lib/network_entities/topology.rb, line 15 def get_element_by_id(element_id) @topology_elements.find{|x| x.id == element_id } end
links()
click to toggle source
# File lib/network_entities/topology.rb, line 23 def links elements_of_type Link end