Class: OSPFv2::RouterLink
- Includes:
- Common, CommonMetric
- Defined in:
- lib/ie/router_link.rb,
lib/ie/router_link_factory.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#link_data ⇒ Object
readonly
Returns the value of attribute link_data.
-
#link_id ⇒ Object
readonly
Returns the value of attribute link_id.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#mt_metrics ⇒ Object
readonly
Returns the value of attribute mt_metrics.
-
#router_link_type ⇒ Object
readonly
Returns the value of attribute router_link_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#encode ⇒ Object
-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | Link ID |-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | Link Data |-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | Type | # TOS | metric |-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | … -
#initialize(arg = {}) ⇒ RouterLink
constructor
A new instance of RouterLink.
- #parse(s) ⇒ Object
- #to_s(ident = 2) ⇒ Object
- #to_s_junos ⇒ Object
- #to_s_junos_style ⇒ Object
Methods included from CommonMetric
Methods included from Common
#ivar_to_klassname, #ivars, #set, #to_hash
Constructor Details
#initialize(arg = {}) ⇒ RouterLink
Returns a new instance of RouterLink.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ie/router_link.rb', line 44 def initialize(arg={}) arg = arg.dup if arg.is_a?(Hash) @link_id, @link_data, @router_link_type, @metric = nil, nil, nil, nil @mt_metrics = [] set arg elsif arg.is_a?(String) parse arg elsif arg.is_a?(self.class) parse arg.encode else raise ArgumentError, "Invalid Argument: #{arg.inspect}" end end |
Instance Attribute Details
#link_data ⇒ Object (readonly)
Returns the value of attribute link_data.
40 41 42 |
# File 'lib/ie/router_link.rb', line 40 def link_data @link_data end |
#link_id ⇒ Object (readonly)
Returns the value of attribute link_id.
40 41 42 |
# File 'lib/ie/router_link.rb', line 40 def link_id @link_id end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
40 41 42 |
# File 'lib/ie/router_link.rb', line 40 def metric @metric end |
#mt_metrics ⇒ Object (readonly)
Returns the value of attribute mt_metrics.
40 41 42 |
# File 'lib/ie/router_link.rb', line 40 def mt_metrics @mt_metrics end |
#router_link_type ⇒ Object (readonly)
Returns the value of attribute router_link_type.
40 41 42 |
# File 'lib/ie/router_link.rb', line 40 def router_link_type @router_link_type end |
Class Method Details
.factory(arg) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ie/router_link_factory.rb', line 28 def self.factory(arg) if arg.is_a?(Hash) raise ArgumentError, "no link type specified" unless arg[:router_link_type] case arg[:router_link_type] when 1,:point_to_point ; PointToPoint.new(arg) when 2,:transit_network ; TransitNetwork.new(arg) when 3,:stub_network ; StubNetwork.new(arg) when 4,:virtual_link ; VirtualLink.new(arg) end elsif arg.is_a?(String) case arg[8,1].unpack('C')[0] when 1 ; PointToPoint.new(arg) when 2 ; TransitNetwork.new(arg) when 3 ; StubNetwork.new(arg) when 4 ; VirtualLink.new(arg) else raise ArgumentError, "Invalid Argument: #{arg[8,1].unpack('C')[0]} #{arg.inspect}/#{arg.unpack('H*')}" end elsif arg.is_a?(RouterLink) factory(arg.encode) end end |
Instance Method Details
#encode ⇒ Object
-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | Link ID | -
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | Link Data | -
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | Type | # TOS | metric | -
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | … | -
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+ | TOS | 0 | TOS metric | -
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-+
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ie/router_link.rb', line 70 def encode @link_id ||= LinkId.new @link_data ||= LinkData.new @router_link_type ||= RouterLinkType.new @metric ||= Metric.new rlink =[] rlink << link_id.encode rlink << link_data.encode rlink << router_link_type.encode rlink << [mt_metrics.size].pack('C') rlink << metric.encode('n') rlink << mt_metrics.collect { |x| x.encode } rlink.join end |
#parse(s) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ie/router_link.rb', line 129 def parse(s) @mt_metrics ||=[] link_id, link_data, router_link_type, ntos, metric, mt_metrics = s.unpack('NNCCna*') @link_id = LinkId.new link_id @link_data = LinkData.new link_data @router_link_type = RouterLinkType.new router_link_type @metric = Metric.new metric while mt_metrics.size>0 self << MtMetric.new(mt_metrics.slice!(0,4)) end end |
#to_s(ident = 2) ⇒ Object
85 86 87 88 89 |
# File 'lib/ie/router_link.rb', line 85 def to_s(ident=2) encode unless @router_link_type self.class.to_s.split('::').last + ":" + ['',link_id, link_data, router_link_type, metric, *mt_metrics].compact.collect { |x| x.to_s }.join("\n"+" "*ident) end |
#to_s_junos ⇒ Object
98 99 100 101 102 103 |
# File 'lib/ie/router_link.rb', line 98 def to_s_junos s = " id #{link_id.to_ip}, data #{link_data.to_ip}, Type #{RouterLinkType.to_junos(router_link_type.to_i)} (#{router_link_type.to_i})" s +="\n Topology count: #{@mt_metrics.size}, Default metric: #{metric.to_i}" s += @mt_metrics.collect { |mt| "\n #{mt.to_s}" }.join end |
#to_s_junos_style ⇒ Object
91 92 93 94 95 96 |
# File 'lib/ie/router_link.rb', line 91 def to_s_junos_style s = " id #{id}, data #{data}, Type #{RouterLink.type_to_s_junos_style[@type]} (#{@type})" s +="\n Topology count: #{@mt_id.size}, Default metric: #{@metric}" s += @mt_id.collect { |mt| "\n #{mt.to_s_junos_style}" }.join s end |