ospfv2 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +674 -0
  3. data/LICENSE.txt +53 -0
  4. data/README +50 -0
  5. data/bin/ospfv2 +112 -105
  6. data/changelog.txt +7 -0
  7. data/gemspec +17 -0
  8. data/lib/ie/external_route.rb +9 -0
  9. data/lib/ie/id.rb +3 -4
  10. data/lib/ie/ie.rb +12 -0
  11. data/lib/ie/ls_age.rb +35 -5
  12. data/lib/ie/ls_type.rb +40 -37
  13. data/lib/ie/opaque_id.rb +46 -0
  14. data/lib/ie/opaque_type.rb +96 -0
  15. data/lib/ie/options.rb +5 -3
  16. data/lib/ie/router_link.rb +30 -7
  17. data/lib/ie/router_link_type.rb +116 -27
  18. data/lib/ie/sequence_number.rb +7 -3
  19. data/lib/infra/ospf_common.rb +1 -12
  20. data/lib/infra/ospf_io.rb +14 -8
  21. data/lib/infra/ospf_socket.rb +14 -14
  22. data/lib/infra/parse_options.rb +69 -25
  23. data/lib/ls_db/advertised_routers.rb +1 -1
  24. data/lib/ls_db/link_state_database.rb +74 -39
  25. data/lib/ls_db/link_state_database_build.rb +3 -3
  26. data/lib/ls_db/link_state_database_links.rb +7 -2
  27. data/lib/ls_db/lsdb_ios.rb +59 -0
  28. data/lib/lsa/external.rb +35 -2
  29. data/lib/lsa/lsa.rb +128 -35
  30. data/lib/lsa/lsa_factory.rb +20 -7
  31. data/lib/lsa/network.rb +44 -9
  32. data/lib/lsa/router.rb +14 -2
  33. data/lib/lsa/summary.rb +16 -3
  34. data/lib/lsa/tlv/color.rb +47 -0
  35. data/lib/lsa/tlv/link.rb +122 -0
  36. data/lib/lsa/tlv/link_id.rb +55 -0
  37. data/lib/lsa/tlv/link_type.rb +44 -0
  38. data/lib/lsa/tlv/local_interface.rb +56 -0
  39. data/lib/lsa/tlv/maximum_bandwidth.rb +55 -0
  40. data/lib/lsa/tlv/maximum_reservable_bandwidth.rb +52 -0
  41. data/lib/lsa/tlv/remote_interface.rb +58 -0
  42. data/lib/lsa/tlv/router_address.rb +57 -0
  43. data/lib/lsa/tlv/tlv.rb +32 -0
  44. data/lib/lsa/tlv/tlv_factory.rb +72 -0
  45. data/lib/lsa/tlv/traffic_engineering_metric.rb +52 -0
  46. data/lib/lsa/tlv/unreserved_bandwidth.rb +55 -0
  47. data/lib/lsa/traffic_engineering.rb +95 -0
  48. data/lib/neighbor/neighbor.rb +9 -9
  49. data/lib/packet/link_state_update.rb +16 -14
  50. data/lib/packet/ospf_packet.rb +13 -9
  51. data/test/unit/ie/au_type_test.rb +18 -0
  52. data/test/unit/ie/external_route_test.rb +51 -0
  53. data/test/unit/ie/id_test.rb +22 -0
  54. data/test/unit/ie/interface_mtu_test.rb +23 -0
  55. data/test/unit/ie/ls_age_test.rb +46 -0
  56. data/test/unit/ie/ls_type_test.rb +41 -0
  57. data/test/unit/ie/metric_test.rb +24 -0
  58. data/test/unit/ie/mt_metric_test.rb +27 -0
  59. data/test/unit/ie/opaque_id_test.rb +22 -0
  60. data/test/unit/ie/opaque_type_test.rb +22 -0
  61. data/test/unit/ie/options_test.rb +142 -0
  62. data/test/unit/ie/ospf_version_test.rb +0 -0
  63. data/test/unit/ie/packet_type_test.rb +33 -0
  64. data/test/unit/ie/router_link_factory_test.rb +26 -0
  65. data/test/unit/ie/router_link_test.rb +276 -0
  66. data/test/unit/ie/router_link_type_test.rb +24 -0
  67. data/test/unit/ie/sequence_number_test.rb +31 -0
  68. data/test/unit/ie/tos_metric_test.rb +27 -0
  69. data/test/unit/infra/ospf_common_test.rb +42 -0
  70. data/test/unit/infra/parse_options_test.rb +58 -0
  71. data/test/unit/infra/timer_test.rb +94 -0
  72. data/test/unit/ls_db/all +10 -0
  73. data/test/unit/ls_db/link_state_database_build_test.rb +140 -0
  74. data/test/unit/ls_db/link_state_database_links_tests.rb +74 -0
  75. data/test/unit/ls_db/link_state_database_test.rb +444 -0
  76. data/test/unit/ls_db/links_test.rb +49 -0
  77. data/test/unit/lsa/all +10 -0
  78. data/test/unit/lsa/external_test.rb +218 -0
  79. data/test/unit/lsa/lsa_factory_test.rb +314 -0
  80. data/test/unit/lsa/lsa_test.rb +191 -0
  81. data/test/unit/lsa/network_test.rb +107 -0
  82. data/test/unit/lsa/router_test.rb +614 -0
  83. data/test/unit/lsa/summary_test.rb +135 -0
  84. data/test/unit/lsa/tlv/color_test.rb +39 -0
  85. data/test/unit/lsa/tlv/link_id_test.rb +14 -0
  86. data/test/unit/lsa/tlv/link_test.rb +413 -0
  87. data/test/unit/lsa/tlv/link_type_test.rb +16 -0
  88. data/test/unit/lsa/tlv/local_interface_test.rb +15 -0
  89. data/test/unit/lsa/tlv/maximum_bandwidth_test.rb +14 -0
  90. data/test/unit/lsa/tlv/maximum_reservable_bandwidth_test.rb +13 -0
  91. data/test/unit/lsa/tlv/remote_interface_test.rb +14 -0
  92. data/test/unit/lsa/tlv/router_address_test.rb +16 -0
  93. data/test/unit/lsa/tlv/tlv_factory_test.rb +89 -0
  94. data/test/unit/lsa/tlv/traffic_engineering_metric_test.rb +15 -0
  95. data/test/unit/lsa/traffic_engineering_test.rb +65 -0
  96. data/test/unit/neighbor/neighbor_test.rb +82 -0
  97. data/test/unit/packet/all +10 -0
  98. data/test/unit/packet/database_description_test.rb +114 -0
  99. data/test/unit/packet/hello_test.rb +107 -0
  100. data/test/unit/packet/link_state_ack_test.rb +64 -0
  101. data/test/unit/packet/link_state_request_test.rb +168 -0
  102. data/test/unit/packet/link_state_update_test.rb +62 -0
  103. data/test/unit/packet/ospf_packet_test.rb +91 -0
  104. metadata +106 -51
  105. data/lib/infra/to_s.rb +0 -38
  106. data/lib/lsa/lsa_base.rb +0 -430
  107. data/lib/lsa/opaque.rb +0 -143
@@ -0,0 +1,53 @@
1
+ OSPFv2 is copyrighted free software by Jean-Michel Esnault.
2
+
3
+ You can redistribute it and/or modify it under either the terms of the GPL
4
+ (see the COPYING file), or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) rename any non-standard executables so the names do not conflict
22
+ with standard executables, which must also be provided.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or executable
27
+ form, provided that you do at least ONE of the following:
28
+
29
+ a) distribute the executables and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c) give non-standard executables non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial).
43
+
44
+ 5. The scripts and library files supplied as input to or produced as
45
+ output from the software do not automatically fall under the
46
+ copyright of the software, but belong to whomever generated them,
47
+ and may be sold commercially, and may be aggregated with this
48
+ software.
49
+
50
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
51
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
52
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53
+ PURPOSE.
data/README ADDED
@@ -0,0 +1,50 @@
1
+ Supported LSA:
2
+ Router, Network, Summary, AsbrSummary, AsExternal
3
+
4
+ TODO: NSSA, TE, LLC
5
+
6
+ Supported Ospf Packets:
7
+
8
+ Link State Update
9
+ Link State Request
10
+ Link State Ack
11
+ Database Description
12
+ Hello
13
+
14
+ Supported RouterType:
15
+
16
+ Intra-area
17
+ ABR -> generate Summary and set B bit
18
+ ASBR -> generate AsExternal and set E bit
19
+
20
+ Network Types Supported
21
+ Broadcast (DROTHER)
22
+ point-to-point
23
+
24
+ Authentication:
25
+ no auth
26
+ TODO: MD5, Password
27
+
28
+ Learned LSA Functionality
29
+
30
+ display of the Link State Database
31
+ summary
32
+ detailed
33
+
34
+ Scalability:
35
+
36
+ calculate large Area:
37
+ A Grid 50x50 Intra-area routers
38
+ Summary x N
39
+ AsExternal x N
40
+
41
+ Automation:
42
+
43
+ Using ruby language and the set of OSPF ruby classes provided by this library
44
+ All OSPF constructs can be described in simple ruby statements
45
+
46
+
47
+ RFCs:
48
+
49
+ RFC 2328
50
+ RFC 4915
data/bin/ospfv2 CHANGED
@@ -1,6 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'timeout'
2
3
 
3
- raise "Not working with 1.9, use ruby 1.8.7" if RUBY_VERSION.split('.')[0..1].join > '18'
4
+ if Object.const_defined? :Encoding
5
+ Encoding.default_internal="BINARY"
6
+ Encoding.default_external="BINARY"
7
+ end
4
8
 
5
9
  require 'neighbor/neighbor'
6
10
  require 'packet/ospf_packet'
@@ -11,123 +15,126 @@ require 'pp'
11
15
 
12
16
  include OSPFv2
13
17
 
14
- Thread.current["name"] = "#{self}"
18
+ # Parse command line
19
+ begin
20
+ options = OptParse.parse(ARGV)
21
+ rescue OptionParser::InvalidOption => e
22
+ STDERR.puts e.to_s.gsub(/at\s*$/,'')
23
+ exit(1)
24
+ end
15
25
 
16
- cli = Thread.new do
17
- Thread.current["name"] = "CLI"
18
-
19
- # Parse command line
20
- begin
21
- options = OptParse.parse(ARGV)
22
- rescue OptionParser::InvalidOption => e
23
- STDERR.puts e.to_s.gsub(/at\s*$/,'')
24
- exit(1)
25
- end
26
-
27
- ls_db = OSPFv2::LSDB::LinkStateDatabase.create :columns=> options.grid[0],
28
- :rows=> options.grid[1],
29
- :base_prefix => options.base_link_addr,
30
- :base_router_id=> options.base_router_id
26
+ ls_db = OSPFv2::LSDB::LinkStateDatabase.create :columns=> options.grid[0],
27
+ :rows=> options.grid[1],
28
+ :base_prefix => options.base_link_addr,
29
+ :base_router_id=> options.base_router_id
31
30
 
32
- # Up all links
33
- OSPFv2::LSDB::Link.all.each { |id,lnk| ls_db.link lnk, :up }
31
+ # Up all links
32
+ LSDB::Link.all.each { |id,lnk| ls_db.link lnk, :up }
34
33
 
34
+
35
+ rlsa = Router.new :ls_id=> options.router_id, :advertising_router=>options.router_id, :options=>0x22
36
+ if options.network_type == :broadcast
37
+ #
38
+ # o If the state of the interface is Waiting, add a Type
39
+ # 3 link (stub network) with Link ID set to the IP
40
+ # network number of the attached network, Link Data
41
+ # set to the attached network's address mask, and cost
42
+ # equal to the interface's configured output cost.
43
+ #
44
+ # o Else, there has been a Designated Router elected for
45
+ # the attached network. If the router is fully
46
+ # adjacent to the Designated Router, or if the router
47
+ # itself is Designated Router and is fully adjacent to
48
+ # at least one other router, add a single Type 2 link
49
+ # (transit network) with Link ID set to the IP
50
+ # interface address of the attached network's
51
+ # Designated Router (which may be the router itself),
52
+ # Link Data set to the router's own IP interface
53
+ # address, and cost equal to the interface's
54
+ # configured output cost. Otherwise, add a link as if
55
+ # the interface state were Waiting (see above).
56
+ #
57
+ #
58
+ rlsa << RouterLink.new_stub_network(:link_id=>options.network, :link_data=>options.netmask, :metric=>20)
59
+
60
+ else
61
+ # Assume p2p:
62
+ # add p2p link and a stub link
63
+ rlsa << RouterLink.new_point_to_point(:link_id=>options.neighbor_id, :link_data=> options.ipaddr, :metric=>1)
64
+ rlsa << RouterLink.new_stub_network(:link_id=>options.network, :link_data=>options.netmask, :metric=>1)
65
+ rlsa << RouterLink.new_stub_network(:link_id=>'0.0.0.0', :link_data=>'0.0.0.0', :metric=>1)
35
66
 
36
- # Describe the connection to our neighbor
37
- # It's a p2p connection
38
- # we need to describe a p2p link and a stub link
39
- rlsa = Router.new :ls_id=> options.router_id,
40
- :advertising_router=>options.router_id,
41
- :options=>0x22
42
- rlsa << RouterLink.new_point_to_point(:link_id=>options.neighbor_id,
43
- :link_data=> options.ipaddr,
44
- :metric=>1)
45
- rlsa << RouterLink.new_stub_network(:link_id=>options.network,
46
- :link_data=>options.netmask,
47
- :metric=>1)
48
- ls_db << rlsa
49
-
50
-
51
- rid1 = OSPFv2::LSDB::LinkStateDatabase.router_id(1,1,options.base_router_id)
52
- rid2 = OSPFv2::LSDB::LinkStateDatabase.router_id(2,1,options.base_router_id)
53
- rid3 = OSPFv2::LSDB::LinkStateDatabase.router_id(1,1,options.base_router_id)
67
+ end
68
+
69
+ # ls_db << rlsa
54
70
 
71
+ rid1 = OSPFv2::LSDB::LinkStateDatabase.router_id(1,1,options.base_router_id)
72
+ rid2 = OSPFv2::LSDB::LinkStateDatabase.router_id(2,1,options.base_router_id)
73
+ rid3 = OSPFv2::LSDB::LinkStateDatabase.router_id(1,1,options.base_router_id)
74
+
75
+ unless options.grid == [0,0]
55
76
  # add a a p2p link between router_id and rid1
56
- ls_db.new_link :router_id=> options.router_id, :neighbor_id=>rid1
77
+ ls_db.new_link :router_id=> options.router_id, :neighbor_id=>rid1
78
+ end
57
79
 
58
- # Link.all.values.each { |lnk| @ls_db.link lnk, :down }
59
-
60
- # Add some Summary LSAs
80
+
81
+ # Add some Summary LSAs
82
+ if options.num_sum>0
61
83
  [rid1,rid2].each do |rid|
62
84
  ls_db.lookup(1,rid).set_abr
63
85
  (options.num_sum/2).times { ls_db << OSPFv2::Summary.new_lsdb( :advertising_router=> rid ) }
64
86
  end
65
-
66
- # Add some External LSAs
67
- ls_db.find_router_lsa(rid3).set_asbr
68
- options.num_ext.times { \
69
- ls_db << OSPFv2::AsExternal.new_lsdb(:advertising_router=> rid3,
70
- :mt_metrics=>[{:mt_id=>10, :metric=>20,
71
- :tag=>10}])}
72
-
73
87
  ls_db << AsbrSummary.new(:advertising_router=> rid3, :ls_id=> rid3)
74
-
75
-
76
- neighbor = OSPFv2::Neighbor.new :src_addr => options.ipaddr,
77
- :router_id => options.router_id,
78
- :area_id=>options.area_id,
79
- :log_fname => options.log_fname
80
-
81
- neighbor.hello_int
82
- neighbor.dead_int
83
- neighbor.ls_db = ls_db
84
-
85
- # Add option to parse
86
- ls_db.ls_refresh_time=2000
87
- ls_db.ls_refresh_interval=10
88
-
89
- help= <<-"end;"
90
- start
91
- stop
92
- puts ls_db
93
- puts ls_db.to_js_unos
94
- end;
95
-
96
- def prompt() ; ">> " ; end
97
-
98
- sleep(1)
99
- ue=nil
100
-
101
- def eval_cmd(cmd,binding)
102
- s = eval(cmd,binding)
103
- print "=> #{s.inspect}" if s
104
- puts
105
- rescue SyntaxError, NameError => e
106
- puts "% syntax error\n"
107
- rescue => e
108
- puts "% error: #{e}\n"
109
- end
110
-
111
- loop do
112
- print prompt() ; $stdout.flush
113
- cmd = STDIN.gets
114
- break unless cmd
115
- next if cmd.size == 0
116
- ary = cmd.downcase.split(' ')
117
- case ary[0]
118
- when 'start' ; neighbor.start
119
- when 'stop' ; neighbor.stop
120
- when 'help', '?'
121
- print help
122
- when nil
123
- when /^(exit|quit|x|q|fin|end)$/ ; exit
124
- else
125
- eval_cmd cmd, binding()
126
- end
127
- end
88
+ end
128
89
 
90
+ # Add some External LSAs
91
+ ls_db.find_router_lsa(rid3).set_asbr if options.num_ext>0
92
+ options.num_ext.times do
93
+ ls_db << OSPFv2::AsExternal.new_lsdb(:advertising_router=> rid3,
94
+ :mt_metrics=>[{:mt_id=>10, :metric=>20,:tag=>10}])
129
95
  end
130
96
 
131
- cli.join
132
97
 
133
- exit
98
+ neighbor = OSPFv2::Neighbor.new :src_addr => options.ipaddr,
99
+ :router_id => options.router_id,
100
+ :area_id=>options.area_id,
101
+ :log_fname => options.log_fname
102
+
103
+ neighbor.hello_int
104
+ neighbor.dead_int
105
+ neighbor.ls_db = ls_db
106
+
107
+ ls_db.ls_refresh_time= options.ls_refresh_time
108
+ ls_db.ls_refresh_interval=options.ls_refresh_interval
109
+
110
+ def ls_db.aging(arg=nil)
111
+ Lsa::LsAge.aging(arg)
112
+ all.collect { |l| l.ls_age.to_i }
113
+ aging?
114
+ end
115
+ def ls_db.aging?
116
+ Lsa::LsAge.aging? ? :on : :off
117
+ end
118
+ def ls_db.age_reset(age=nil)
119
+ all.each { |l| l.ls_age.reset(age) }
120
+ ''
121
+ end
122
+
123
+ case options.console
124
+ when :pry
125
+ require 'pry'
126
+ binding.pry
127
+ when :irb
128
+ require 'irb'
129
+ puts "*** cb $binding ***"
130
+ puts "Once in irb> enter \"cb $binding\" to access local variables: ls_db, neighbor, options"
131
+ puts "Use ls_db object to access generated link state database."
132
+ puts "Use neighbor object to start or stop ospfv2 neighboring."
133
+ puts ""
134
+ $binding = binding
135
+ IRB.start(__FILE__)
136
+ else
137
+ ls_db.aging(:on); neighbor.start
138
+ sleep 30_000
139
+ end
140
+
@@ -1,3 +1,10 @@
1
+ === 0.0.3
2
+
3
+ * Opaque LSA
4
+ + Traffic Engineering TLVs
5
+
6
+
7
+
1
8
  === 0.0.2 Fri Apr 15 18:22:26 PDT 2011
2
9
 
3
10
  * Work with Cisco Routers that enable LLS by default
data/gemspec ADDED
@@ -0,0 +1,17 @@
1
+
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "ospfv2"
4
+ spec.date = "2014-10-17"
5
+ spec.version = "0.0.3"
6
+ spec.author = "Jean Michel Esnault"
7
+ spec.email = "ospfv2@esnault.org"
8
+ spec.summary = "Playing with OSPF version 2 using ruby."
9
+ spec.description = "Playing with OSPF version 2 using ruby."
10
+ spec.homepage = "https://github.com/jesnault/ospfv2"
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.rdoc_options = ["--quiet", "--title", "ospfv2", "--line-numbers"]
13
+ spec.require_paths = ["lib"]
14
+ spec.bindir = 'bin'
15
+ spec.executables = ['ospfv2']
16
+ spec.extra_rdoc_files = ["LICENSE.txt","README"]
17
+ end
@@ -118,6 +118,15 @@ module OSPFv2
118
118
  def to_s
119
119
  "#{type.to_s.upcase} (ID #{mt_id}) Metric: #{metric.to_i} Forwarding: #{forwarding_address.to_ip} Tag: #{tag}"
120
120
  end
121
+
122
+ def to_s_ios
123
+ # Metric Type: 1 (Comparable directly to link state metric)
124
+ # TOS: 0
125
+ # Metric: 0
126
+ # Forward Address: 0.0.0.0
127
+ # External Route Tag: 0
128
+ #TODO: implement...
129
+ end
121
130
 
122
131
  private
123
132
 
@@ -22,10 +22,12 @@
22
22
 
23
23
 
24
24
  require 'ipaddr'
25
- require 'infra/ospf_common'
25
+ require_relative '../infra/ospf_common'
26
+ require_relative 'ie'
26
27
 
27
28
  module OSPFv2
28
29
  class Id
30
+ include IE
29
31
 
30
32
  def self.new_ntoh(s)
31
33
  return unless s.is_a?(String)
@@ -92,6 +94,3 @@ class Id
92
94
  end
93
95
 
94
96
  end
95
-
96
- load "../../../test/ospfv2/ie/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
97
-
@@ -0,0 +1,12 @@
1
+ module OSPFv2
2
+ module IE
3
+ def method_missing(name, *args, &block)
4
+ if name.to_s =~ /^to_s_(ios|junos)$/
5
+ __send__ :to_s, *args, &block
6
+ else
7
+ p "#{name} is missing...."
8
+ raise
9
+ end
10
+ end
11
+ end
12
+ end
@@ -20,24 +20,51 @@
20
20
  # along with OSPFv2. If not, see <http://www.gnu.org/licenses/>.
21
21
  #++
22
22
 
23
- require 'infra/ospf_constants'
23
+ require_relative '../infra/ospf_constants'
24
24
 
25
25
  module OSPFv2
26
26
  class LsAge
27
+
28
+ class << self
29
+ attr_accessor :_aging
30
+ def aging?
31
+ _aging
32
+ end
33
+ def aging(arg=nil)
34
+ if arg
35
+ case arg
36
+ when :on ; self._aging = true
37
+ when :off ; self._aging = false
38
+ end
39
+ else
40
+ self._aging = ! _aging
41
+ end
42
+ end
43
+ end
44
+
27
45
  include Comparable
28
46
 
29
47
  def initialize(age=0)
30
48
  @age=age
31
- @time = Time.now
32
49
  raise ArgumentError, "Invalid Argument #{age}" unless age.is_a?(Integer)
33
50
  end
34
51
 
35
52
  def to_i
36
- aging? ? (Time.new - @time + @age).to_int : @age
53
+ if aging?
54
+ @time ||= Time.now
55
+ (Time.new - @time + @age).to_int
56
+ else
57
+ @age
58
+ end
59
+ end
60
+
61
+ def reset(age=nil)
62
+ @age = age if age
63
+ @time=nil
37
64
  end
38
65
 
39
66
  def aging?
40
- true
67
+ self.class.aging?
41
68
  end
42
69
 
43
70
  def maxage
@@ -60,6 +87,10 @@ class LsAge
60
87
  self.class.to_s.split('::').last + ": #{to_i}"
61
88
  end
62
89
 
90
+ def to_s_ios
91
+ "LS age: #{to_i}"
92
+ end
93
+
63
94
  def encode
64
95
  [@age].pack('n')
65
96
  end
@@ -72,4 +103,3 @@ class LsAge
72
103
  end
73
104
  end
74
105
 
75
- load "../../../test/ospfv2/ie/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0