Class: Topology

Inherits:
Object
  • Object
show all
Defined in:
lib/network_entities/topology.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTopology

Returns a new instance of Topology.



11
12
13
# File 'lib/network_entities/topology.rb', line 11

def initialize
  @topology_elements = []
end

Instance Attribute Details

#topology_elementsObject (readonly)

Returns the value of attribute topology_elements.



9
10
11
# File 'lib/network_entities/topology.rb', line 9

def topology_elements
  @topology_elements
end

Instance Method Details

#add_flow(id, priority, path, distribution_rate, distribution_size) ⇒ Object



60
61
62
63
64
65
66
67
68
# 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


55
56
57
58
# 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)) ⇒ Object



27
28
29
30
31
32
33
# 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


43
44
45
46
47
48
49
50
51
52
53
# 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)) ⇒ Object



35
36
37
38
39
40
41
# 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) ⇒ Object



19
20
21
# 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) ⇒ Object



15
16
17
# File 'lib/network_entities/topology.rb', line 15

def get_element_by_id(element_id)
  @topology_elements.find{|x| x.id == element_id }
end


23
24
25
# File 'lib/network_entities/topology.rb', line 23

def links
  elements_of_type Link
end