Class: Link
- Inherits:
-
NetworkElement
- Object
- NetworkElement
- Link
- Defined in:
- lib/network_entities/physical/link.rb
Instance Attribute Summary collapse
-
#bandwith ⇒ Object
readonly
Returns the value of attribute bandwith.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#dst_element ⇒ Object
readonly
Returns the value of attribute dst_element.
-
#dst_port ⇒ Object
readonly
Returns the value of attribute dst_port.
-
#src_element ⇒ Object
readonly
Returns the value of attribute src_element.
-
#src_port ⇒ Object
readonly
Returns the value of attribute src_port.
Attributes inherited from NetworkElement
#id, #in_elements, #my_number, #out_elements
Instance Method Summary collapse
-
#initialize(id, src_element, src_port, dst_element, dst_port, bandwith = 500*1000*1000, delay = 0) ⇒ Link
constructor
A new instance of Link.
Methods inherited from NetworkElement
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
#bandwith ⇒ Object (readonly)
Returns the value of attribute bandwith.
5 6 7 |
# File 'lib/network_entities/physical/link.rb', line 5 def bandwith @bandwith end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
5 6 7 |
# File 'lib/network_entities/physical/link.rb', line 5 def delay @delay end |
#dst_element ⇒ Object (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_port ⇒ Object (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_element ⇒ Object (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_port ⇒ Object (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 |