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.
File without changes
@@ -43,7 +43,6 @@ module OSPFv2
43
43
  @logger = Logger.new(io)
44
44
  end
45
45
  def trace(s)
46
- "{Time.to_ts} #{s}"
47
46
  @logger << s
48
47
  end
49
48
  end
@@ -71,7 +70,7 @@ module OSPFv2
71
70
  @router_id= RouterId.new arg[:router_id] || '1.1.1.1'
72
71
  @area_id= AreaId.new arg[:aread_id] || '0.0.0.0'
73
72
  @lsa_request_list = {}
74
- @ls_db=nil
73
+ @ls_db, @ev = nil, nil
75
74
  if arg[:log_fname]
76
75
  @trace = Trace.new(arg[:log_fname])
77
76
  else
@@ -113,6 +112,9 @@ module OSPFv2
113
112
  s << "\n"
114
113
  @trace.trace s.join
115
114
  end
115
+ rescue => e
116
+ p e
117
+ raise
116
118
  end
117
119
 
118
120
  def debug(obj)
@@ -169,21 +171,34 @@ module OSPFv2
169
171
  end
170
172
 
171
173
  def update(*args)
172
- @evQ.enq *args
174
+ @evQ.enq(*args)
173
175
  end
174
176
  def send(packet, dest=OSPFv2::AllSPFRouters)
177
+ # p "about to send 111111 #{packet.class} "
178
+ # p "@output? #{@output ? true : false} #{packet.class}"
179
+ # p @output
180
+ # p "--------------"
175
181
  return unless @output
176
- [packet].flatten.each { |p|
177
- log :snd, p
178
- @output.enq [p,dest]
179
- }
182
+ case packet
183
+ when Array
184
+ # p "WE HAVE AN ARRAY OF PACKET!"
185
+ packet.each { |p|
186
+ # p "about to send p 333333 #{p.inspect}"
187
+ # log :snd, p
188
+ @output.enq [p,dest]
189
+ }
190
+ else
191
+ log :snd, packet
192
+ # p "about to send packet 333333 #{packet.inspect}"
193
+ @output.enq [packet,dest]
194
+ # p "about to send 333333 #{packet.inspect}"
195
+ end
180
196
  end
181
197
 
182
198
  # AllSPFRouters = "224.0.0.5"
183
199
  # AllDRouters = "224.0.0.6"
184
200
  def flood(lsas, dest=AllSPFRouters)
185
- # return unless @output
186
- send (LinkStateUpdate.new_lsas lsas), dest
201
+ send LinkStateUpdate.new_lsas(lsas), dest
187
202
  end
188
203
 
189
204
  def start_periodic_hellos
@@ -30,11 +30,6 @@ module OSPFv2
30
30
  debug "rescued #{e.inspect}"
31
31
  end
32
32
 
33
- def recv_link_state_request(ls_request, from, port)
34
- #TODO: check what address the LSU shoul be send to ? unicast ? AllDRouteres ? AllSpfRouters ?
35
- send ls_request.to_lsu(@ls_db, :area_id=> @aread_id, :router_id => @router_id), from
36
- end
37
-
38
33
  def recv_link_state_update(ls_update, from, port)
39
34
  ls_ack = LinkStateAck.ack_ls_update ls_update, :area_id=> @area_id, :router_id=> @router_id
40
35
  send ls_ack, OSPFv2::AllDRouters #from
@@ -34,7 +34,6 @@ module OSPFv2
34
34
  end
35
35
 
36
36
  def recv_link_state_request(ls_request, from, port)
37
- #TODO: check what address the LSU shoul be send to ? unicast ? AllDRouteres ? AllSpfRouters ?
38
37
  send ls_request.to_lsu(@ls_db, :area_id=> @aread_id, :router_id => @router_id), from
39
38
  end
40
39
 
@@ -52,7 +51,7 @@ module OSPFv2
52
51
  end
53
52
  }
54
53
  new_state Full.new, 'loading_done' if @ls_req_list.empty?
55
- end
54
+ end
56
55
  @ls_db.recv_link_state_update ls_update if @ls_db
57
56
  end
58
57
 
@@ -23,33 +23,30 @@
23
23
  require 'neighbor_sm/neighbor_state'
24
24
  module OSPFv2
25
25
  module NeighborState
26
-
26
+
27
27
  class ExStart < State
28
28
  def initialize(n)
29
29
  @neighbor = n
30
- n.instance_eval do
30
+ n.instance_eval do
31
31
  @last_dd_seqn = n.dd_sequence_number
32
-
32
+
33
33
  #-- could be a State#reset method inherited ?
34
34
  @ls_db.reset if @ls_db
35
35
  @ls_req_list={}
36
36
  @periodic_refresh.cancel
37
37
  @periodic_rxmt.cancel
38
38
  #--
39
-
39
+
40
40
  @last_dd_seqn = dd_sequence_number
41
41
  raise unless @last_dd_seqn>0
42
-
43
- p "***"
44
- p @last_dd_seqn
45
-
42
+
46
43
  dd = DatabaseDescription.new :router_id=> @router_id, :area_id=> @area_id,
47
- :imms=>7, :dd_sequence_number => @last_dd_seqn
44
+ :imms=>7, :dd_sequence_number => @last_dd_seqn
48
45
  send_dd dd, true
49
46
  end
50
-
47
+
51
48
  end
52
-
49
+
53
50
  def negotiation_done
54
51
  @neighbor.instance_eval do
55
52
  dd_rxmt_interval.cancel
@@ -58,7 +55,7 @@ module OSPFv2
58
55
  end
59
56
 
60
57
  def adj_ok?
61
- if ! ok
58
+ if ! ok
62
59
  change_state(@neighbor, Two_way.new)
63
60
  end
64
61
 
@@ -23,21 +23,19 @@
23
23
  require 'neighbor_sm/neighbor_state'
24
24
  module OSPFv2
25
25
  module NeighborState
26
-
26
+
27
27
  class Init < State
28
28
 
29
- # recv_hello inherited
30
-
31
29
  def recv_hello(neighbor, hello, *args)
32
- super
33
- two_way_received(neighbor) if hello.has_neighbor?(neighbor.router_id)
34
- end
30
+ super
31
+ two_way_received(neighbor) if hello.has_neighbor?(neighbor.router_id)
32
+ end
35
33
 
36
34
  def two_way_received(neighbor, *args)
37
35
  change_state(neighbor, ExStart.new(neighbor), 'two_way_received' )
38
36
  end
39
37
  end
40
-
38
+
41
39
  end
42
40
  end
43
41
 
@@ -120,8 +120,6 @@ require 'ls_db/link_state_database'
120
120
 
121
121
  module OSPFv2
122
122
 
123
-
124
-
125
123
  class DatabaseDescription < OspfPacket
126
124
 
127
125
  class << self
@@ -149,6 +147,7 @@ module OSPFv2
149
147
  @interface_mtu = InterfaceMtu.new
150
148
  @options = Options.new
151
149
  @imms, @dd_sequence_number, @number_of_lsa=0, nil, nil
150
+ @lsas=[]
152
151
 
153
152
  if arg.is_a?(Hash)
154
153
  arg.merge!({:packet_type=>:dd})
@@ -168,7 +167,7 @@ module OSPFv2
168
167
  s << super(:brief)
169
168
  s << "MTU #{interface_mtu.to_i}, Options 0x#{options.to_i.to_s(16)}, #{imms_to_s}, DD_SEQ: 0x#{dd_sequence_number_to_shex}"
170
169
  s << "Age Options Type Link-State ID Advr Router Sequence Checksum Length" if @lsas
171
- s <<((@lsas.collect { |x| x.to_s_dd })).join("\n ") if @lsas
170
+ s << ((@lsas.collect { |x| x.to_s_dd })).join("\n ") if @lsas
172
171
  s.join("\n ")
173
172
  end
174
173
 
@@ -268,8 +267,10 @@ module OSPFv2
268
267
  dd_sequence_number.to_s(16)
269
268
  end
270
269
 
271
- def parse(s)
272
- interface_mtu, options, @imms, @dd_sequence_number, headers = super(s).unpack('nCCNa*')
270
+ def parse(_s)
271
+ s = super(_s)
272
+ db, _ = s.unpack("a#{@_packet_len-24}a*")
273
+ interface_mtu, options, @imms, @dd_sequence_number, headers = db.unpack('nCCNa*')
273
274
  self.options = Options.new options
274
275
  @interface_mtu = InterfaceMtu.new interface_mtu
275
276
  @lsas ||=[]
@@ -280,8 +281,7 @@ module OSPFv2
280
281
  end
281
282
 
282
283
  def number_of_lsa
283
- #FIXME: rename interface mtu method...
284
- @number_of_lsa ||=interface_mtu.n0flsa
284
+ @number_of_lsa ||=interface_mtu.number_of_lsa
285
285
  end
286
286
 
287
287
  def set(arg)
data/lib/packet/hello.rb CHANGED
@@ -189,7 +189,7 @@ module OSPFv2
189
189
 
190
190
  attr_reader :netmask, :designated_router_id, :backup_designated_router_id
191
191
  attr_reader :hello_interval, :options, :rtr_pri, :router_dead_interval, :neighbors
192
- attr_writer_delegate :designated_router_id, :backup_designated_router_id, :neighbors
192
+ attr_writer_delegate :designated_router_id, :backup_designated_router_id
193
193
 
194
194
  class Neighbors
195
195
  Neighbor = Class.new(OSPFv2::Id)
@@ -241,7 +241,6 @@ module OSPFv2
241
241
  @neighbors = nil
242
242
  @hello_interval, @router_dead_interval = 10, 40
243
243
  set arg
244
-
245
244
  elsif arg.is_a?(String)
246
245
  parse arg
247
246
  elsif arg.is_a?(Hello)
@@ -268,10 +267,6 @@ module OSPFv2
268
267
  self.neighbors = hello.router_id.to_hash
269
268
  end
270
269
 
271
- def to_s
272
- super
273
- end
274
-
275
270
  def to_s_verbose
276
271
  super +
277
272
  [@netmask, @options, rtr_pri_to_s, @designated_router_id, @backup_designated_router_id, neighbors_to_s].collect { |x| x.to_s }.join("\n ")
@@ -300,7 +295,6 @@ module OSPFv2
300
295
 
301
296
  private
302
297
 
303
-
304
298
  def neighbors_to_s
305
299
  ["Neighbors:", neighbors.collect { |x| x.to_s(nil) } ].join("\n ")
306
300
  end
@@ -308,15 +302,17 @@ module OSPFv2
308
302
  ["Neighbors:", neighbors.collect { |x| x.to_s(nil) } ].join("\n ")
309
303
  end
310
304
 
311
- def parse(s)
312
- netmask, @hello_interval, options, @rtr_pri, @router_dead_interval, dr, bdr, neighbors = super(s).unpack('NnCCNNNa*')
305
+ def parse(_s)
306
+ s = super(_s)
307
+ hello, _ = s.unpack("a#{@_packet_len-24}a*")
308
+ netmask, @hello_interval, options, @rtr_pri, @router_dead_interval, dr, bdr = hello.slice!(0,20).unpack('NnCCNNN')
313
309
  @netmask = Netmask.new netmask
314
310
  @options = Options.new options
315
311
  @designated_router_id = DesignatedRouterId.new dr
316
312
  @backup_designated_router_id = BackupDesignatedRouterId.new bdr
317
- @neighbors ||=Hello::Neighbors.new
318
- while neighbors.size>0
319
- self.neighbors= neighbors.slice!(0,4).unpack('N')[0]
313
+ @neighbors ||=Hello::Neighbors.new
314
+ while hello.size>0
315
+ self.neighbors= hello.slice!(0,4).unpack('N')[0]
320
316
  end
321
317
  end
322
318
 
@@ -325,3 +321,89 @@ module OSPFv2
325
321
  end
326
322
 
327
323
  load "../../../test/ospfv2/packet/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
324
+
325
+
326
+ __END__
327
+
328
+ 0201002c
329
+ 01010101
330
+ 00000000
331
+ 8be60000
332
+ 00000000
333
+ 00000000
334
+
335
+ ffffff00
336
+ 000a1201
337
+ 00000028
338
+ c0a89e0d
339
+ 00000000
340
+
341
+
342
+ fff600030001000400000001
343
+
344
+ >> ["0201002c01010101000000008be600000000000000000000ffffff00000a120100000028c0a89e0d00000000fff600030001000400000001"]
345
+ ["ffffff00000a120100000028c0a89e0d00000000fff600030001000400000001"]
346
+ 44
347
+ ["0001000400000001"]
348
+ [""]
349
+
350
+
351
+ Source: 192.168.158.13 (192.168.158.13)
352
+ Destination: 224.0.0.5 (224.0.0.5)
353
+ Open Shortest Path First
354
+ OSPF Header
355
+ OSPF Version: 2
356
+ Message Type: Hello Packet (1)
357
+ Packet Length: 44
358
+ Source OSPF Router: 1.1.1.1 (1.1.1.1)
359
+ Area ID: 0.0.0.0 (Backbone)
360
+ Packet Checksum: 0x8be6 [correct]
361
+ Auth Type: Null
362
+ Auth Data (none)
363
+ OSPF Hello Packet
364
+ Network Mask: 255.255.255.0
365
+ Hello Interval: 10 seconds
366
+ Options: 0x12 (L, E)
367
+ 0... .... = DN: DN-bit is NOT set
368
+ .0.. .... = O: O-bit is NOT set
369
+ ..0. .... = DC: Demand circuits are NOT supported
370
+ ...1 .... = L: The packet contains LLS data block
371
+ .... 0... = NP: Nssa is NOT supported
372
+ .... .0.. = MC: NOT multicast capable
373
+ .... ..1. = E: ExternalRoutingCapability
374
+ Router Priority: 1
375
+ Router Dead Interval: 40 seconds
376
+ Designated Router: 192.168.158.13
377
+ Backup Designated Router: 0.0.0.0
378
+ OSPF LLS Data Block
379
+ Checksum: 0xfff6
380
+ LLS Data Length: 12 bytes
381
+ Extended options TLV
382
+ Type: 1
383
+ Length: 4
384
+ Options: 0x00000001 (LR)
385
+ .... .... .... .... .... .... .... ..0. = RS: Restart Signal (RS-bit) is NOT set
386
+ .... .... .... .... .... .... .... ...1 = LR: LSDB Resynchronization (LR-bit) is SET
387
+
388
+
389
+ 0000 01 00 5e 00 00 05 cc 00 09 41 00 10 08 00 45 c0 ..^......A....E.
390
+ 0010 00 4c 1b 86 00 00 01 59 5e 58 c0 a8 9e 0d e0 00 .L.....Y^X......
391
+ 0020 00 05 02 01 00 2c 01 01 01 01 00 00 00 00 8b e6 .....,..........
392
+ 0030 00 00 00 00 00 00 00 00 00 00 ff ff ff 00 00 0a ................
393
+ 0040 12 01 00 00 00 28 c0 a8 9e 0d 00 00 00 00 ff f6 .....(..........
394
+ 0050 00 03 00 01 00 04 00 00 00 01 ..........
395
+
396
+
397
+ 2c
398
+
399
+
400
+ 02 01 00 2c 01 01 01 01 00 00 00 00 8b e6 14
401
+ 00 00 00 00 00 00 00 00 00 00 ff ff ff 00 00 0a 16 30
402
+ 12 01 00 00 00 28 c0 a8 9e 0d 00 00 00 00 ff f6 16 46
403
+ 00 03 00 01 00 04 00 00 00 01 10 56
404
+
405
+
406
+
407
+
408
+
409
+
@@ -79,7 +79,7 @@ module OSPFv2
79
79
  attr_accessor :lsa_headers
80
80
 
81
81
  def self.ack_ls_update(lsu, *args)
82
- ls_ack = new *args
82
+ ls_ack = new(*args)
83
83
  ls_ack.lsa_headers = lsu.lsas
84
84
  ls_ack
85
85
  end
@@ -125,7 +125,7 @@ module OSPFv2
125
125
  headers = super(s)
126
126
  while headers.size>0
127
127
  lsa = Lsa.new headers.slice!(0,20)
128
- @lsa_headers <<lsa
128
+ @lsa_headers << lsa
129
129
  end
130
130
  end
131
131
 
@@ -167,7 +167,7 @@ module OSPFv2
167
167
  lsas = arg[:lsas]
168
168
  arg.delete(:lsas)
169
169
  lsu = new(arg)
170
- lsas.flatten.compact.each do |lsa|
170
+ [lsas].flatten.compact.each do |lsa|
171
171
  lsa_len = lsa.encode.size
172
172
  if (len + lsa_len) > (1476-56-20)
173
173
  lsus << lsu
@@ -147,6 +147,7 @@ module OSPFv2
147
147
  else
148
148
  raise ArgumentError, "Invalid argument", caller
149
149
  end
150
+ @_len=nil
150
151
  end
151
152
 
152
153
  def encode(payload='',router_id=@router_id)
@@ -167,7 +168,7 @@ module OSPFv2
167
168
  # Version 2, RouterId 0.0.0.1, AreaId 0.0.0.0, AuType 0, Checksum 0x9580, len 9999
168
169
 
169
170
  def to_s_brief
170
- encode unless @_len
171
+ encode
171
172
  "Version #{ospf_version.to_i}, RouterId #{router_id.to_ip}, AreaId #{area_id.to_ip}, Checksum #{0}, len #{@_len}"
172
173
  end
173
174
 
@@ -202,8 +203,6 @@ module OSPFv2
202
203
  end
203
204
 
204
205
  def method_missing(method, *args, &block)
205
- puts "Method missing in #{self.class}: method: #{method}"
206
-
207
206
  if method == :to_s_junos
208
207
  to_s_default(*args)
209
208
  else
@@ -212,8 +211,7 @@ module OSPFv2
212
211
  end
213
212
 
214
213
  def to_hash(verbose=false)
215
- #FIXME: verbose not working, i.e. always false
216
- encode if verbose
214
+ encode
217
215
  h = super()
218
216
  h.delete(:authentication) if @authentication==''
219
217
  h.delete(:csum) unless verbose
@@ -234,6 +232,7 @@ module OSPFv2
234
232
  @router_id = RouterId.new(rid)
235
233
  @area_id = AreaId.new(aid)
236
234
  @au_type = AuType.new(au_type)
235
+ @_packet_len = len
237
236
  packet
238
237
  end
239
238
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ospfv2
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 27
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jean Michel Esnault
@@ -14,12 +15,11 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-05-16 00:00:00 -07:00
18
- default_executable:
18
+ date: 2011-04-16 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description:
22
- email: jme@spidercloud.com
22
+ email: ospfv2@esnault.org
23
23
  executables:
24
24
  - ospfv2
25
25
  extensions: []
@@ -58,10 +58,13 @@ files:
58
58
  - lib/ls_db/links.rb
59
59
  - lib/lsa/external.rb
60
60
  - lib/lsa/lsa.rb
61
+ - lib/lsa/lsa_base.rb
61
62
  - lib/lsa/lsa_factory.rb
62
63
  - lib/lsa/network.rb
64
+ - lib/lsa/opaque.rb
63
65
  - lib/lsa/router.rb
64
66
  - lib/lsa/summary.rb
67
+ - lib/lsa/tlv/tlv.rb
65
68
  - lib/neighbor/neighbor.rb
66
69
  - lib/neighbor/neighbor_event_handler.rb
67
70
  - lib/neighbor/recv_database_description.rb
@@ -81,7 +84,8 @@ files:
81
84
  - lib/packet/link_state_request.rb
82
85
  - lib/packet/link_state_update.rb
83
86
  - lib/packet/ospf_packet.rb
84
- has_rdoc: true
87
+ - changelog.txt
88
+ - bin/ospfv2
85
89
  homepage:
86
90
  licenses: []
87
91
 
@@ -92,23 +96,27 @@ require_paths:
92
96
  - lib
93
97
  - lib
94
98
  required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
95
100
  requirements:
96
101
  - - ">="
97
102
  - !ruby/object:Gem::Version
103
+ hash: 3
98
104
  segments:
99
105
  - 0
100
106
  version: "0"
101
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
102
109
  requirements:
103
110
  - - ">="
104
111
  - !ruby/object:Gem::Version
112
+ hash: 3
105
113
  segments:
106
114
  - 0
107
115
  version: "0"
108
116
  requirements: []
109
117
 
110
118
  rubyforge_project:
111
- rubygems_version: 1.3.6
119
+ rubygems_version: 1.7.2
112
120
  signing_key:
113
121
  specification_version: 3
114
122
  summary: An OSPFv2 Emulator.