Class: Link

Inherits:
NetworkElement show all
Defined in:
lib/network_entities/physical/link.rb

Instance Attribute Summary collapse

Attributes inherited from NetworkElement

#id, #in_elements, #my_number, #out_elements

Instance Method Summary collapse

Methods inherited from NetworkElement

#increase_quantity_in_one

Methods included from SerializeBehavior

#transform_to_output_representation, #validate_concrete_builder

Constructor Details

#initialize(id, src_element, src_port, dst_element, dst_port, bandwith = 500*1000*1000, delay = 0) ⇒ Link

Returns a new instance of Link.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/network_entities/physical/link.rb', line 8

def initialize(id, src_element, src_port, dst_element, dst_port, bandwith = 500*1000*1000, delay = 0)
  
  bandwith ||= 500*1000*1000 # 500 Mb/s
  delay ||= 0
  
  raise "Attempted to create an invalid Link. Invalid source #{src_element.id}" if (!src_element.is_a? Router) && (!src_element.is_a? Host)  
  raise "Attempted to create an invalid Link. Invalid destination '#{dst_element.id}'" if (!dst_element.is_a? Router) && (!dst_element.is_a? Host)
  raise "Attempted to create an invalid Link. Invalid source port '#{src_port}' must be an integer" if (!src_port.is_a? Integer)
  raise "Attempted to create an invalid Link. Invalid destination port '#{dst_port}' must be an integer" if (!dst_port.is_a? Integer)
  raise "Invalid Source port. Port '#{src_port}' already in use for '#{src_element.id}'" if src_element.out_elements[src_port]
  raise "Invalid Destination port. Port '#{dst_port}' already in use for '#{dst_element.id}'" if dst_element.in_elements[dst_port]
  raise "Bandwith must be a number, #{bandwith} was recieved" unless bandwith.is_a? Integer

  @src_element = src_element
  @src_port = src_port
  @dst_element = dst_element
  @dst_port = dst_port
  @bandwith = bandwith # Expressed in bits per second (bit/s)
  @delay = delay

  # add each other
  @src_element.out_elements[src_port] = @dst_element
  @dst_element.in_elements[dst_port] = @src_element 

  super id
end

Instance Attribute Details

#bandwithObject (readonly)

Returns the value of attribute bandwith.



5
6
7
# File 'lib/network_entities/physical/link.rb', line 5

def bandwith
  @bandwith
end

#delayObject (readonly)

Returns the value of attribute delay.



5
6
7
# File 'lib/network_entities/physical/link.rb', line 5

def delay
  @delay
end

#dst_elementObject (readonly)

Returns the value of attribute dst_element.



5
6
7
# File 'lib/network_entities/physical/link.rb', line 5

def dst_element
  @dst_element
end

#dst_portObject (readonly)

Returns the value of attribute dst_port.



5
6
7
# File 'lib/network_entities/physical/link.rb', line 5

def dst_port
  @dst_port
end

#src_elementObject (readonly)

Returns the value of attribute src_element.



5
6
7
# File 'lib/network_entities/physical/link.rb', line 5

def src_element
  @src_element
end

#src_portObject (readonly)

Returns the value of attribute src_port.



5
6
7
# File 'lib/network_entities/physical/link.rb', line 5

def src_port
  @src_port
end