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.
- #link_data_to_s(link_type) ⇒ Object
- #link_id_to_s(link_type) ⇒ Object
- #parse(s) ⇒ Object
- #to_s(ident = 4) ⇒ Object
-
#to_s_ios ⇒ Object
(also: #to_s_ios_verbose)
Link connected to: another Router (point-to-point) (Link ID) Neighboring Router ID: 1.1.1.1 (Link Data) Router Interface address: 192.168.158.1 Number of TOS metrics: 0 TOS 0 Metrics: 1.
- #to_s_junos ⇒ 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 |
#link_data_to_s(link_type) ⇒ Object
95 96 97 |
# File 'lib/ie/router_link.rb', line 95 def link_data_to_s(link_type) RouterLinkType.link_data_to_s(link_type) end |
#link_id_to_s(link_type) ⇒ Object
91 92 93 |
# File 'lib/ie/router_link.rb', line 91 def link_id_to_s(link_type) RouterLinkType.link_id_to_s(link_type) end |
#parse(s) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ie/router_link.rb', line 150 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 = 4) ⇒ Object
85 86 87 88 89 |
# File 'lib/ie/router_link.rb', line 85 def to_s(ident=4) 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_ios ⇒ Object Also known as: to_s_ios_verbose
Link connected to: another Router (point-to-point)
(Link ID) Neighboring Router ID: 1.1.1.1
(Link Data) Router Interface address: 192.168.158.1
Number of TOS metrics: 0
TOS 0 Metrics: 1
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ie/router_link.rb', line 104 def to_s_ios s = [] s << '' s << "Link connected to: #{router_link_type.to_s_ios}" s << " (Link ID) #{link_id_to_s(router_link_type.to_i)}: #{link_id.to_ip}" s << " (Link Data) #{link_data_to_s(router_link_type.to_i)}: #{link_data.to_ip}" s << " Number of TOS metrics: #{@mt_metrics.size}" s << " TOS 0 Metrics: #{metric.to_i}" s << @mt_metrics.collect { |mt| "\n #{mt.to_s}" }.join unless @mt_metrics.empty? s << '' s.join("\n ") end |
#to_s_junos ⇒ Object
119 120 121 122 123 124 |
# File 'lib/ie/router_link.rb', line 119 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 |