ospfv2 0.0.1 → 0.0.2

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.
data/bin/ospfv2 CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ raise "Not working with 1.9, use ruby 1.8.7" if RUBY_VERSION.split('.')[0..1].join > '18'
4
+
3
5
  require 'neighbor/neighbor'
4
6
  require 'packet/ospf_packet'
5
7
  require 'ls_db/link_state_database'
@@ -89,7 +91,6 @@ cli = Thread.new do
89
91
  stop
90
92
  puts ls_db
91
93
  puts ls_db.to_js_unos
92
- aging :on | :off
93
94
  end;
94
95
 
95
96
  def prompt() ; ">> " ; end
@@ -107,10 +108,6 @@ cli = Thread.new do
107
108
  puts "% error: #{e}\n"
108
109
  end
109
110
 
110
- def aging(arg)
111
- OSPFv2::Lsa::LsAge.aging arg
112
- end
113
-
114
111
  loop do
115
112
  print prompt() ; $stdout.flush
116
113
  cmd = STDIN.gets
@@ -118,7 +115,7 @@ cli = Thread.new do
118
115
  next if cmd.size == 0
119
116
  ary = cmd.downcase.split(' ')
120
117
  case ary[0]
121
- when 'start' ; aging :on ; neighbor.start
118
+ when 'start' ; neighbor.start
122
119
  when 'stop' ; neighbor.stop
123
120
  when 'help', '?'
124
121
  print help
data/changelog.txt ADDED
@@ -0,0 +1,8 @@
1
+ === 0.0.2 Fri Apr 15 18:22:26 PDT 2011
2
+
3
+ * Work with Cisco Routers that enable LLS by default
4
+
5
+ === 0.0.1
6
+
7
+ * Initial release
8
+
data/lib/ie/au_type.rb CHANGED
@@ -20,8 +20,8 @@
20
20
  # along with OSPFv2. If not, see <http://www.gnu.org/licenses/>.
21
21
  #++
22
22
 
23
-
24
23
  # 0 Null authentication 1 Simple password 2 Cryptographic authentication
24
+
25
25
  module OSPFv2
26
26
  class AuType
27
27
  def initialize(au_type=0)
@@ -64,7 +64,9 @@ module OSPFv2
64
64
  class ExternalRoute_Base
65
65
  include Common
66
66
 
67
- ForwardingAddress = Class.new(OSPFv2::Id)
67
+ unless const_defined?(:ForwardingAddress)
68
+ ForwardingAddress = Class.new(OSPFv2::Id)
69
+ end
68
70
 
69
71
  attr_reader :metric, :type, :forwarding_address, :tag, :mt_id
70
72
  attr_checked :metric do |x|
@@ -161,7 +163,7 @@ module OSPFv2
161
163
  def initialize(arg={})
162
164
  if arg.is_a?(Hash)
163
165
  @forwarding_address = ForwardingAddress.new
164
- raise ArgumentError, "MT-ID not set!" unless arg[:mt_id]
166
+ raise ArgumentError, "MT-ID not set!" unless arg.has_key?(:mt_id)
165
167
  raise ArgumentError, "MT-ID should not be 0!" if arg[:mt_id]==0
166
168
  end
167
169
  super
@@ -169,7 +171,8 @@ module OSPFv2
169
171
  end
170
172
 
171
173
  def ExternalRoute_Base.new_hash(h)
172
- if h[:mt_metrics]
174
+ raise unless h.is_a?(Hash)
175
+ if h.has_key? :mt_metrics
173
176
  MtExternalRoute.new(h)
174
177
  else
175
178
  ExternalRoute.new(h)
@@ -43,7 +43,6 @@ class InterfaceMtu
43
43
  def number_of_lsa
44
44
  @noh ||= ((to_i - OSPFv2::PACKET_HEADER_LEN) / OSPFv2::LSA_HEADER_LEN) - 1
45
45
  end
46
- alias :n0flsa :number_of_lsa
47
46
 
48
47
  def to_s
49
48
  self.class.to_s.split('::').last + ": #{to_i}"
data/lib/ie/ls_age.rb CHANGED
@@ -26,24 +26,10 @@ module OSPFv2
26
26
  class LsAge
27
27
  include Comparable
28
28
 
29
- class << self
30
- def aging(state=:off)
31
- case state
32
- when :on ; @aging = true
33
- when :off ; @aging = false
34
- else
35
- raise ArgumentError, "Invalid Argument"
36
- end
37
- end
38
- def aging?
39
- @aging
40
- end
41
- end
42
-
43
29
  def initialize(age=0)
44
- raise ArgumentError, "Invalid Argument #{age}" unless age.is_a?(Integer)
45
30
  @age=age
46
31
  @time = Time.now
32
+ raise ArgumentError, "Invalid Argument #{age}" unless age.is_a?(Integer)
47
33
  end
48
34
 
49
35
  def to_i
@@ -51,7 +37,7 @@ class LsAge
51
37
  end
52
38
 
53
39
  def aging?
54
- self.class.aging?
40
+ true
55
41
  end
56
42
 
57
43
  def maxage
data/lib/ie/ls_type.rb CHANGED
@@ -20,77 +20,114 @@
20
20
  # along with OSPFv2. If not, see <http://www.gnu.org/licenses/>.
21
21
  #++
22
22
 
23
- #
24
- # LS Type Description
25
- # ___________________________________
26
- # 1 Router-LSAs
27
- # 2 Network-LSAs
28
- # 3 Summary-LSAs (IP network)
29
- # 4 Summary-LSAs (ASBR)
30
- # 5 AS-external-LSAs
31
- #
32
23
  module OSPFv2
33
24
  class LsType
25
+
26
+ @ls_type_junos = {
27
+ 1 => 'Router' ,
28
+ 2 => 'Network' ,
29
+ 3 => 'Summary' ,
30
+ 4 => 'ASBRSum' ,
31
+ 5 => 'Extern' ,
32
+ 9 => 'OpaqLoca',
33
+ 10=> 'OpaqArea',
34
+ 11=> 'OpaqAS' ,
35
+ }
36
+
37
+ @ls_type_short = {
38
+ 1=>'router' ,
39
+ 2=>'network' ,
40
+ 3=>'summary' ,
41
+ 4=>'asbrSum' ,
42
+ 5=>'external' ,
43
+ 7=>'nssa' ,
44
+ 9=>'opaqLnk' ,
45
+ 10=>'opaqArea',
46
+ 11=>'opaqAs' ,
47
+ }
48
+
49
+ @ls_type_sym = {
50
+ 1 => :router_lsa ,
51
+ 2 => :network_lsa ,
52
+ 3 => :summary_lsa ,
53
+ 4 => :asbr_summary_lsa,
54
+ 5 => :as_external_lsa ,
55
+ 7 => :as_external7_lsa,
56
+ 9 => :link_local_lsa ,
57
+ 10 => :area_lsa ,
58
+ 11 => :domain_lsa ,
59
+ }
34
60
 
35
- def self.all
36
- [:router, :network, :summary, :asbr_summary, :as_external]
37
- end
61
+ @ls_type_sym_to_i = @ls_type_sym.invert
38
62
 
39
- def self.to_i(arg)
40
- return arg unless arg.is_a?(Symbol)
41
- case arg.to_s
42
- when /^router(_lsa|)$/ ; @ls_type=1
43
- when /^network(_lsa|)$/ ; @ls_type=2
44
- when /^summary(_lsa|)$/ ; @ls_type=3
45
- when /^asbr_summary(_lsa|)$/ ; @ls_type=4
46
- when /^as_external(_lsa|)$/ ; @ls_type=5
47
- #FIXME: finish and unit-test
48
- # when :as_external7_lsa ; @ls_type=7
49
- # when :opaque_link ; @ls_type=9
50
- # when :opaque_area ; @ls_type=10
51
- # when :opaque_as ; @ls_type=11
52
- end
63
+ def is_opaque?
64
+ (9..11) === @ls_type
53
65
  end
54
-
55
- def self.to_sym(arg)
56
- return arg unless arg.is_a?(Fixnum)
57
- case arg
58
- when 1 ; :router_lsa
59
- when 2 ; :network_lsa
60
- when 3 ; :summary_lsa
61
- when 4 ; :asbr_summary_lsa
62
- when 5 ; :as_external_lsa
63
- when 7 ; :as_external7_lsa
64
- when 9 ; :opaque_link
65
- when 10 ; :opaque_area
66
- when 11 ; :opaque_as
66
+
67
+ class << self
68
+ def all
69
+ [:router, :network, :summary, :asbr_summary, :as_external]
67
70
  end
68
- end
69
71
 
70
- def self.to_junos(arg)
71
- return arg.to_i unless arg.is_a?(Fixnum)
72
- case arg
73
- when 1 ; 'Router'
74
- when 2 ; 'Network'
75
- when 3 ; 'Summary'
76
- when 4 ; 'ASBRSum'
77
- when 5 ; 'Extern'
78
- else
79
- 'TBD'
72
+ def to_i(arg)
73
+ return arg unless arg.is_a?(Symbol)
74
+ case arg.to_s
75
+ when /^router(_lsa|)$/ ; @ls_type=1
76
+ when /^network(_lsa|)$/ ; @ls_type=2
77
+ when /^summary(_lsa|)$/ ; @ls_type=3
78
+ when /^asbr_summary(_lsa|)$/ ; @ls_type=4
79
+ when /^as_external(_lsa|)$/ ; @ls_type=5
80
+ #FIXME: finish and unit-test
81
+ # when :as_external7_lsa ; @ls_type=7
82
+ # when :opaque_link ; @ls_type=9
83
+ # when :opaque_area ; @ls_type=10
84
+ # when :opaque_as ; @ls_type=11
85
+ end
86
+ end
87
+
88
+ def to_sym(arg)
89
+ return arg unless arg.is_a?(Fixnum)
90
+ if @ls_type_sym.has_key?(arg)
91
+ @ls_type_sym[arg]
92
+ else
93
+ raise
94
+ end
95
+ end
96
+
97
+ def ls_type_sym_to_i(arg)
98
+ return arg if arg.is_a?(Fixnum)
99
+ if @ls_type_sym_to_i.has_key?(arg)
100
+ @ls_type_sym_to_i[arg]
101
+ else
102
+ raise
103
+ end
104
+ end
105
+
106
+ def to_junos(arg)
107
+ return arg unless arg.is_a?(Fixnum)
108
+ if @ls_type_junos.has_key?(arg)
109
+ @ls_type_junos[arg]
110
+ else
111
+ raise
112
+ end
113
+ end
114
+
115
+ def to_short(arg)
116
+ return arg unless arg.is_a?(Fixnum)
117
+ if @ls_type_short.has_key?(arg)
118
+ @ls_type_short[arg]
119
+ else
120
+ raise
121
+ end
80
122
  end
81
123
  end
82
124
 
83
125
  def initialize(ls_type=1)
84
- case ls_type
85
- when 1,:router_lsa ; @ls_type=1
86
- when 2,:network_lsa ; @ls_type=2
87
- when 3,:summary_lsa ; @ls_type=3
88
- when 4,:asbr_summary_lsa ; @ls_type=4
89
- when 5,:as_external_lsa ; @ls_type=5
90
- when 7,:as_external7_lsa ; @ls_type=7
91
- when 9,:opaque_link ; @ls_type=9
92
- when 10,:opaque_area ; @ls_type=10
93
- when 11,:opaque_as ; @ls_type=11
126
+ @ls_type = case ls_type
127
+ when Symbol
128
+ LsType.ls_type_sym_to_i(ls_type)
129
+ when Fixnum
130
+ ls_type
94
131
  else
95
132
  raise ArgumentError, "Invalid LsType #{ls_type}"
96
133
  end
@@ -101,19 +138,7 @@ class LsType
101
138
  def to_s
102
139
  self.class.to_s.split('::').last + ": #{to_sym}"
103
140
  end
104
- def to_s_short
105
- case to_i
106
- when 1; 'router'
107
- when 2; 'network'
108
- when 3; 'summary'
109
- when 4; 'asbrSum'
110
- when 5; 'external'
111
- when 7; 'nssa'
112
- when 9; 'opaqLnk'
113
- when 10; 'opaqArea'
114
- when 11; 'opaqAs'
115
- end
116
- end
141
+
117
142
  def to_sym
118
143
  LsType.to_sym @ls_type
119
144
  end
@@ -127,6 +152,14 @@ class LsType
127
152
  to_sym
128
153
  end
129
154
 
155
+ def to_s_short
156
+ LsType.to_short(to_i)
157
+ end
158
+
159
+ def to_junos
160
+ LsType.to_junos(to_i)
161
+ end
162
+
130
163
  end
131
164
  end
132
165
 
data/lib/ie/metric.rb CHANGED
@@ -58,6 +58,19 @@ class Metric
58
58
  end
59
59
 
60
60
  end
61
+
62
+ module CommonMetric
63
+ def mt_metrics=(val)
64
+ [val].flatten.each { |x| self << x }
65
+ end
66
+
67
+ def <<(metric)
68
+ @mt_metrics ||=[]
69
+ @mt_metrics << MtMetric.new(metric)
70
+ self
71
+ end
72
+ end
73
+
61
74
  end
62
75
 
63
76
  load "../../../test/ospfv2/ie/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
data/lib/ie/options.rb CHANGED
@@ -90,6 +90,23 @@ A.2 The Options field
90
90
  This bit describes the router's handling of demand circuits, as
91
91
  specified in [Ref10].
92
92
 
93
+
94
+ 2.1. L-bit in Options Field
95
+
96
+ A new L bit (L stands for LLS) is introduced into the OSPF Options
97
+ field (see Figure 2a/2b). Routers set the L bit in Hello and DD
98
+ packets to indicate that the packet contains an LLS data block. In
99
+ other words, the LLS data block is only examined if the L bit is set.
100
+
101
+ +---+---+---+---+---+---+---+---+
102
+ | * | O | DC| L |N/P| MC| E | * |
103
+ +---+---+---+---+---+---+---+-+-+
104
+
105
+ Figure 2a: OSPFv2 Options field
106
+
107
+
108
+
109
+
93
110
  =end
94
111
 
95
112
  require 'infra/ospf_common'
@@ -98,7 +115,7 @@ module OSPFv2
98
115
 
99
116
  class Options
100
117
 
101
- attr :options, true
118
+ attr_accessor :options
102
119
 
103
120
  def initialize(arg={})
104
121
  @options=0
@@ -146,17 +163,17 @@ module OSPFv2
146
163
  end
147
164
  end
148
165
  end
149
- unless arg[:R].nil? and arg[:r].nil?
150
- _flag = arg[:R] ||= arg[:r]
166
+ unless arg[:L].nil? and arg[:l].nil?
167
+ _flag = arg[:L] ||= arg[:l]
151
168
  if _flag.is_a?(TrueClass)
152
- setR
169
+ setL
153
170
  elsif _flag.is_a?(FalseClass)
154
- unsetR
171
+ unsetL
155
172
  elsif _flag.is_a?(Fixnum)
156
173
  if _flag == 0
157
- unsetR
174
+ unsetL
158
175
  else
159
- setR
176
+ setL
160
177
  end
161
178
  end
162
179
  end
@@ -189,19 +206,19 @@ module OSPFv2
189
206
  end
190
207
  end
191
208
  unless arg[:MC].nil? and arg[:mc].nil?
192
- _flag = arg[:MC] ||= arg[:mc]
193
- if _flag.is_a?(TrueClass)
194
- setMC
195
- elsif _flag.is_a?(FalseClass)
209
+ _flag = arg[:MC] ||= arg[:mc]
210
+ if _flag.is_a?(TrueClass)
211
+ setMC
212
+ elsif _flag.is_a?(FalseClass)
213
+ unsetMC
214
+ elsif _flag.is_a?(Fixnum)
215
+ if _flag == 0
196
216
  unsetMC
197
- elsif _flag.is_a?(Fixnum)
198
- if _flag == 0
199
- unsetMC
200
- else
201
- setMC
202
- end
217
+ else
218
+ setMC
203
219
  end
204
220
  end
221
+ end
205
222
  unless arg[:E].nil? and arg[:e].nil?
206
223
  _flag = arg[:E] ||= arg[:e]
207
224
  if _flag.is_a?(TrueClass)
@@ -254,9 +271,13 @@ module OSPFv2
254
271
  def unsetDC ; __unsetBit(6) ; end
255
272
  def dc? ; __isSet(6) ; end
256
273
 
257
- def setR ; __setBit(5) ; end
258
- def unsetR ; __unsetBit(5) ; end
259
- def r? ; __isSet(5) ; end
274
+ # A new L-bit (L stands for LLS) is introduced into the OSPF Options
275
+ # field (see Figures 2a and 2b). Routers set the L-bit in Hello and DD
276
+ # packets to indicate that the packet contains an LLS data block. In
277
+ # other words, the LLS data block is only examined if the L-bit is set.
278
+ def setL ; __setBit(5) ; end
279
+ def unsetL ; __unsetBit(5) ; end
280
+ def l? ; __isSet(5) ; end
260
281
 
261
282
  # N-bit is used in Hello packets only.
262
283
  # It signals the area is an NSSA area.
@@ -340,7 +361,7 @@ module OSPFv2
340
361
  def _to_s_
341
362
  s = []
342
363
  s << 'O' if o?
343
- s << 'R' if r?
364
+ s << 'L' if l?
344
365
  s << 'DC' if dc?
345
366
  s << 'N' if n?
346
367
  s << 'MC' if mc?