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_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_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