ospfv2 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/ospfv2 +136 -0
- data/lib/ie/au_type.rb +79 -0
- data/lib/ie/external_route.rb +181 -0
- data/lib/ie/id.rb +97 -0
- data/lib/ie/interface_mtu.rb +64 -0
- data/lib/ie/ls_age.rb +89 -0
- data/lib/ie/ls_type.rb +148 -0
- data/lib/ie/metric.rb +63 -0
- data/lib/ie/mt_metric.rb +119 -0
- data/lib/ie/options.rb +356 -0
- data/lib/ie/ospf_version.rb +67 -0
- data/lib/ie/packet_type.rb +65 -0
- data/lib/ie/router_link.rb +167 -0
- data/lib/ie/router_link_factory.rb +53 -0
- data/lib/ie/router_link_type.rb +86 -0
- data/lib/ie/sequence_number.rb +144 -0
- data/lib/ie/tos_metric.rb +102 -0
- data/lib/infra/ospf_common.rb +291 -0
- data/lib/infra/ospf_constants.rb +73 -0
- data/lib/infra/ospf_io.rb +133 -0
- data/lib/infra/ospf_socket.rb +126 -0
- data/lib/infra/parse_options.rb +135 -0
- data/lib/infra/timer.rb +104 -0
- data/lib/infra/to_s.rb +38 -0
- data/lib/ls_db/advertised_routers.rb +78 -0
- data/lib/ls_db/common.rb +31 -0
- data/lib/ls_db/link_state_database.rb +376 -0
- data/lib/ls_db/link_state_database_build.rb +181 -0
- data/lib/ls_db/link_state_database_links.rb +178 -0
- data/lib/ls_db/links.rb +160 -0
- data/lib/lsa/external.rb +347 -0
- data/lib/lsa/lsa.rb +438 -0
- data/lib/lsa/lsa_factory.rb +59 -0
- data/lib/lsa/network.rb +166 -0
- data/lib/lsa/router.rb +336 -0
- data/lib/lsa/summary.rb +393 -0
- data/lib/neighbor/neighbor.rb +298 -0
- data/lib/neighbor/neighbor_event_handler.rb +61 -0
- data/lib/neighbor/recv_database_description.rb +153 -0
- data/lib/neighbor/recv_hello.rb +53 -0
- data/lib/neighbor/recv_ospf_packet.rb +68 -0
- data/lib/neighbor_sm/attempt_state.rb +44 -0
- data/lib/neighbor_sm/down_state.rb +46 -0
- data/lib/neighbor_sm/exchange_state.rb +32 -0
- data/lib/neighbor_sm/exstart_state.rb +69 -0
- data/lib/neighbor_sm/full_state.rb +36 -0
- data/lib/neighbor_sm/init_state.rb +43 -0
- data/lib/neighbor_sm/loading_state.rb +33 -0
- data/lib/neighbor_sm/neighbor_state.rb +87 -0
- data/lib/packet/database_description.rb +300 -0
- data/lib/packet/hello.rb +327 -0
- data/lib/packet/link_state_ack.rb +144 -0
- data/lib/packet/link_state_request.rb +153 -0
- data/lib/packet/link_state_update.rb +189 -0
- data/lib/packet/ospf_packet.rb +306 -0
- metadata +116 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 Jean-Michel Esnault.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# This file is part of OSPFv2.
|
8
|
+
#
|
9
|
+
# OSPFv2 is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# OSPFv2 is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with OSPFv2. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
=begin rdoc
|
25
|
+
|
26
|
+
A.3.5 The Link State Update packet
|
27
|
+
|
28
|
+
Link State Update packets are OSPF packet type 4. These packets
|
29
|
+
implement the flooding of LSAs. Each Link State Update packet
|
30
|
+
carries a collection of LSAs one hop further from their origin.
|
31
|
+
Several LSAs may be included in a single packet.
|
32
|
+
|
33
|
+
Link State Update packets are multicast on those physical networks
|
34
|
+
that support multicast/broadcast. In order to make the flooding
|
35
|
+
procedure reliable, flooded LSAs are acknowledged in Link State
|
36
|
+
Acknowledgment packets. If retransmission of certain LSAs is
|
37
|
+
necessary, the retransmitted LSAs are always sent directly to the
|
38
|
+
neighbor. For more information on the reliable flooding of LSAs,
|
39
|
+
consult Section 13.
|
40
|
+
|
41
|
+
0 1 2 3
|
42
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
43
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
44
|
+
| Version # | 4 | Packet length |
|
45
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
46
|
+
| Router ID |
|
47
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
48
|
+
| Area ID |
|
49
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
50
|
+
| Checksum | AuType |
|
51
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
52
|
+
| Authentication |
|
53
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
54
|
+
| Authentication |
|
55
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
56
|
+
| # LSAs |
|
57
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
58
|
+
| |
|
59
|
+
+- +-+
|
60
|
+
| LSAs |
|
61
|
+
+- +-+
|
62
|
+
| ... |
|
63
|
+
|
64
|
+
|
65
|
+
# LSAs
|
66
|
+
The number of LSAs included in this update.
|
67
|
+
|
68
|
+
|
69
|
+
The body of the Link State Update packet consists of a list of LSAs.
|
70
|
+
Each LSA begins with a common 20 byte header, described in Section
|
71
|
+
A.4.1. Detailed formats of the different types of LSAs are described
|
72
|
+
in Section A.4.
|
73
|
+
|
74
|
+
|
75
|
+
=end
|
76
|
+
|
77
|
+
require 'packet/ospf_packet'
|
78
|
+
require 'lsa/lsa'
|
79
|
+
require 'lsa/lsa_factory'
|
80
|
+
require 'packet/link_state_ack'
|
81
|
+
module OSPFv2
|
82
|
+
|
83
|
+
class LinkStateUpdate < OspfPacket
|
84
|
+
|
85
|
+
attr_reader :lsas
|
86
|
+
|
87
|
+
def initialize(_arg={})
|
88
|
+
arg = _arg.dup
|
89
|
+
@lsas=[]
|
90
|
+
if arg.is_a?(Hash)
|
91
|
+
arg.merge!({:packet_type=>4})
|
92
|
+
super arg
|
93
|
+
elsif arg.is_a?(String)
|
94
|
+
parse arg
|
95
|
+
elsif arg.is_a?(self)
|
96
|
+
parse arg.encode
|
97
|
+
else
|
98
|
+
raise ArgumentError, "Invalid argument", caller
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def number_of_lsa
|
103
|
+
lsas.size
|
104
|
+
end
|
105
|
+
|
106
|
+
def encode
|
107
|
+
headers = []
|
108
|
+
headers << [lsas.size].pack('N')
|
109
|
+
headers << lsas.collect { |x| x.encode }.join
|
110
|
+
super headers.join
|
111
|
+
end
|
112
|
+
|
113
|
+
def parse(s)
|
114
|
+
n, lsas = super(s).unpack('Na*')
|
115
|
+
while lsas.size>0
|
116
|
+
len = lsas[18..19].unpack('n')[0]
|
117
|
+
lsa = lsas.slice!(0,len)
|
118
|
+
lsa = Lsa.factory lsa
|
119
|
+
if lsa
|
120
|
+
@lsas << lsa
|
121
|
+
else
|
122
|
+
puts "COULD NOT BUILD LSA OUT OF #{lsa.unpack('H*')}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def [](val)
|
128
|
+
lsas[val]
|
129
|
+
end
|
130
|
+
|
131
|
+
# def to_s
|
132
|
+
# s = []
|
133
|
+
# s << super
|
134
|
+
# s << lsas.collect { |x| x.to_s_junos }.join("\n ")
|
135
|
+
# s.join("\n ")
|
136
|
+
# end
|
137
|
+
|
138
|
+
def to_s
|
139
|
+
s = []
|
140
|
+
s << super(:brief)
|
141
|
+
s << "\# LSAs #{@lsas.size}"
|
142
|
+
s << "Age Options Type Link-State ID Advr Router Sequence Checksum Length"
|
143
|
+
s << @lsas.collect { |x| x.to_s }.join("\n ")
|
144
|
+
s.join("\n ")
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
def each
|
149
|
+
lsas.each { |ls| yield ls }
|
150
|
+
end
|
151
|
+
|
152
|
+
def keys
|
153
|
+
lsas.collect { |ls| ls.key }
|
154
|
+
end
|
155
|
+
|
156
|
+
def ack_lsu(router_id)
|
157
|
+
ls_ack = LinkStateAck.new(:router_id => router_id, :area => area = @aread_id)
|
158
|
+
each { |lsa| ls_ack.lsa_headers << lsa }
|
159
|
+
ls_ack
|
160
|
+
end
|
161
|
+
|
162
|
+
class << self
|
163
|
+
|
164
|
+
def new_lsas(arg={})
|
165
|
+
lsus=[]
|
166
|
+
len=0
|
167
|
+
lsas = arg[:lsas]
|
168
|
+
arg.delete(:lsas)
|
169
|
+
lsu = new(arg)
|
170
|
+
lsas.flatten.compact.each do |lsa|
|
171
|
+
lsa_len = lsa.encode.size
|
172
|
+
if (len + lsa_len) > (1476-56-20)
|
173
|
+
lsus << lsu
|
174
|
+
lsu = new(arg)
|
175
|
+
len = 0
|
176
|
+
end
|
177
|
+
lsu.lsas << lsa
|
178
|
+
len += lsa_len
|
179
|
+
end
|
180
|
+
lsus << lsu
|
181
|
+
lsus
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
load "../../../test/ospfv2/packet/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
@@ -0,0 +1,306 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright 2010 Jean-Michel Esnault.
|
3
|
+
# All rights reserved.
|
4
|
+
# See LICENSE.txt for permissions.
|
5
|
+
#
|
6
|
+
#
|
7
|
+
# This file is part of OSPFv2.
|
8
|
+
#
|
9
|
+
# OSPFv2 is free software: you can redistribute it and/or modify
|
10
|
+
# it under the terms of the GNU General Public License as published by
|
11
|
+
# the Free Software Foundation, either version 3 of the License, or
|
12
|
+
# (at your option) any later version.
|
13
|
+
#
|
14
|
+
# OSPFv2 is distributed in the hope that it will be useful,
|
15
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17
|
+
# GNU General Public License for more details.
|
18
|
+
#
|
19
|
+
# You should have received a copy of the GNU General Public License
|
20
|
+
# along with OSPFv2. If not, see <http://www.gnu.org/licenses/>.
|
21
|
+
#++
|
22
|
+
|
23
|
+
|
24
|
+
=begin rdoc
|
25
|
+
|
26
|
+
http://www.ietf.org/rfc/rfc2328.txt
|
27
|
+
|
28
|
+
A.3.1 The OSPF packet header
|
29
|
+
|
30
|
+
Every OSPF packet starts with a standard 24 byte header. This
|
31
|
+
header contains all the information necessary to determine whether
|
32
|
+
the packet should be accepted for further processing. This
|
33
|
+
determination is described in Section 8.2 of the specification.
|
34
|
+
|
35
|
+
|
36
|
+
0 1 2 3
|
37
|
+
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
38
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
39
|
+
| Version # | Type | Packet length |
|
40
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
41
|
+
| Router ID |
|
42
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
43
|
+
| Area ID |
|
44
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
45
|
+
| Checksum | AuType |
|
46
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
47
|
+
| Authentication |
|
48
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
49
|
+
| Authentication |
|
50
|
+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
51
|
+
|
52
|
+
|
53
|
+
Version #
|
54
|
+
The OSPF version number. This specification documents version 2
|
55
|
+
of the protocol.
|
56
|
+
|
57
|
+
Type
|
58
|
+
The OSPF packet types are as follows. See Sections A.3.2 through
|
59
|
+
A.3.6 for details.
|
60
|
+
|
61
|
+
|
62
|
+
Type Description
|
63
|
+
________________________________
|
64
|
+
1 Hello
|
65
|
+
2 Database Description
|
66
|
+
3 Link State Request
|
67
|
+
4 Link State Update
|
68
|
+
5 Link State Acknowledgment
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Packet length
|
74
|
+
The length of the OSPF protocol packet in bytes. This length
|
75
|
+
includes the standard OSPF header.
|
76
|
+
|
77
|
+
Router ID
|
78
|
+
The Router ID of the packet's source.
|
79
|
+
|
80
|
+
Area ID
|
81
|
+
A 32 bit number identifying the area that this packet belongs
|
82
|
+
to. All OSPF packets are associated with a single area. Most
|
83
|
+
travel a single hop only. Packets travelling over a virtual
|
84
|
+
link are labelled with the backbone Area ID of 0.0.0.0.
|
85
|
+
|
86
|
+
Checksum
|
87
|
+
The standard IP checksum of the entire contents of the packet,
|
88
|
+
starting with the OSPF packet header but excluding the 64-bit
|
89
|
+
authentication field. This checksum is calculated as the 16-bit
|
90
|
+
one's complement of the one's complement sum of all the 16-bit
|
91
|
+
words in the packet, excepting the authentication field. If the
|
92
|
+
packet's length is not an integral number of 16-bit words, the
|
93
|
+
packet is padded with a byte of zero before checksumming. The
|
94
|
+
checksum is considered to be part of the packet authentication
|
95
|
+
procedure; for some authentication types the checksum
|
96
|
+
calculation is omitted.
|
97
|
+
|
98
|
+
AuType
|
99
|
+
Identifies the authentication procedure to be used for the
|
100
|
+
packet. Authentication is discussed in Appendix D of the
|
101
|
+
specification. Consult Appendix D for a list of the currently
|
102
|
+
defined authentication types.
|
103
|
+
|
104
|
+
|
105
|
+
Authentication
|
106
|
+
A 64-bit field for use by the authentication scheme. See
|
107
|
+
Appendix D for details.
|
108
|
+
|
109
|
+
=end
|
110
|
+
|
111
|
+
|
112
|
+
require 'infra/ospf_common'
|
113
|
+
require 'ie/id'
|
114
|
+
require 'ie/ospf_version'
|
115
|
+
require 'ie/packet_type'
|
116
|
+
require 'ie/au_type'
|
117
|
+
|
118
|
+
module OSPFv2
|
119
|
+
|
120
|
+
RouterId = Class.new(Id)
|
121
|
+
AreaId = Class.new(Id)
|
122
|
+
|
123
|
+
class OspfPacket
|
124
|
+
include OSPFv2
|
125
|
+
include OSPFv2::Common
|
126
|
+
|
127
|
+
attr_reader :area_id, :router_id, :version, :ospf_version, :packet_type, :au_type
|
128
|
+
attr_writer_delegate :area_id, :router_id, :packet_type, :au_type
|
129
|
+
|
130
|
+
def packet_name
|
131
|
+
self.class.to_s.split('::').last.to_underscore
|
132
|
+
end
|
133
|
+
alias :name :packet_name
|
134
|
+
|
135
|
+
def initialize(arg={})
|
136
|
+
|
137
|
+
if arg.is_a?(Hash)
|
138
|
+
@ospf_version = OspfVersion.new
|
139
|
+
@packet_type = PacketType.new
|
140
|
+
@area_id = AreaId.new
|
141
|
+
@router_id = RouterId.new
|
142
|
+
@au_type = AuType.new
|
143
|
+
@authentication=''
|
144
|
+
set(arg)
|
145
|
+
elsif arg.is_a?(String)
|
146
|
+
parse(arg)
|
147
|
+
else
|
148
|
+
raise ArgumentError, "Invalid argument", caller
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def encode(payload='',router_id=@router_id)
|
153
|
+
@_len = 24 + payload.size
|
154
|
+
packet = @ospf_version.encode
|
155
|
+
packet << @packet_type.encode
|
156
|
+
packet << [24 + payload.size].pack('n')
|
157
|
+
packet << router_id.encode
|
158
|
+
packet << area_id.encode
|
159
|
+
packet << [0].pack('n')
|
160
|
+
packet << @au_type.encode
|
161
|
+
packet << [''].pack('a8')
|
162
|
+
packet << payload
|
163
|
+
packet[12..13]= self.csum = [checksum(packet)].pack('n')
|
164
|
+
packet
|
165
|
+
end
|
166
|
+
|
167
|
+
# Version 2, RouterId 0.0.0.1, AreaId 0.0.0.0, AuType 0, Checksum 0x9580, len 9999
|
168
|
+
|
169
|
+
def to_s_brief
|
170
|
+
encode unless @_len
|
171
|
+
"Version #{ospf_version.to_i}, RouterId #{router_id.to_ip}, AreaId #{area_id.to_ip}, Checksum #{0}, len #{@_len}"
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_s_default(verbosity=:brief)
|
175
|
+
case verbosity
|
176
|
+
when :brief
|
177
|
+
to_s_brief
|
178
|
+
else
|
179
|
+
s=[]
|
180
|
+
s << self.class.to_s.split('::').last + ":"
|
181
|
+
s << ospf_version.to_s
|
182
|
+
s << packet_type.to_s
|
183
|
+
s << router_id.to_s
|
184
|
+
s << area_id.to_s
|
185
|
+
s << au_type.to_s
|
186
|
+
s << [@authentication].pack('a8')
|
187
|
+
s.join("\n ")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
alias :to_s_junos :to_s_default
|
192
|
+
alias :to_s_junos_verbose :to_s_junos
|
193
|
+
|
194
|
+
def to_s(*args)
|
195
|
+
return to_s_default(*args) unless defined?($style)
|
196
|
+
case $style
|
197
|
+
when :junos ; to_s_junos(*args)
|
198
|
+
when :junos_verbose ; to_s_junos_verbose(*args)
|
199
|
+
else
|
200
|
+
to_s_default(*args)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def method_missing(method, *args, &block)
|
205
|
+
puts "Method missing in #{self.class}: method: #{method}"
|
206
|
+
|
207
|
+
if method == :to_s_junos
|
208
|
+
to_s_default(*args)
|
209
|
+
else
|
210
|
+
super
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def to_hash(verbose=false)
|
215
|
+
#FIXME: verbose not working, i.e. always false
|
216
|
+
encode if verbose
|
217
|
+
h = super()
|
218
|
+
h.delete(:authentication) if @authentication==''
|
219
|
+
h.delete(:csum) unless verbose
|
220
|
+
h
|
221
|
+
end
|
222
|
+
|
223
|
+
private
|
224
|
+
|
225
|
+
def csum=(value)
|
226
|
+
raise if value.is_a?(Fixnum)
|
227
|
+
@_csum=value
|
228
|
+
end
|
229
|
+
|
230
|
+
def parse(s)
|
231
|
+
v, pt, len, rid, aid, csum, au_type, _, _, packet = s.unpack('CCnNNnnNNa*')
|
232
|
+
@ospf_version = OspfVersion.new(v)
|
233
|
+
@packet_type = PacketType.new(pt)
|
234
|
+
@router_id = RouterId.new(rid)
|
235
|
+
@area_id = AreaId.new(aid)
|
236
|
+
@au_type = AuType.new(au_type)
|
237
|
+
packet
|
238
|
+
end
|
239
|
+
|
240
|
+
def checksum(data)
|
241
|
+
data += "\000" if data.length % 2 >0
|
242
|
+
s = 0
|
243
|
+
data.unpack("n*").each { |x|
|
244
|
+
s += x
|
245
|
+
if s > 0xffff
|
246
|
+
carry = s >> 16
|
247
|
+
s &= 0xffff
|
248
|
+
s += carry
|
249
|
+
end
|
250
|
+
}
|
251
|
+
((s >> 16) + (s & 0xffff)) ^ 0xffff
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
require 'packet/hello'
|
256
|
+
require 'packet/database_description'
|
257
|
+
require 'packet/link_state_update'
|
258
|
+
require 'packet/link_state_request'
|
259
|
+
|
260
|
+
class OspfPacket
|
261
|
+
include OSPFv2
|
262
|
+
include OSPFv2::Common
|
263
|
+
|
264
|
+
HELLO = 1
|
265
|
+
DATABASE_DESCRIPTION = 2
|
266
|
+
LINK_STATE_REQUEST = 3
|
267
|
+
LINK_STATE_UPDATE = 4
|
268
|
+
LINK_STATE_ACKNOWLEDGMENT = 5
|
269
|
+
|
270
|
+
class << self
|
271
|
+
|
272
|
+
def factory(arg)
|
273
|
+
|
274
|
+
if arg.is_a?(String)
|
275
|
+
s = arg.dup
|
276
|
+
version, type, len = s.unpack('CCn')
|
277
|
+
|
278
|
+
raise RuntimeError, "Bogus OSPF Version #{version}" unless version==2
|
279
|
+
case type
|
280
|
+
when HELLO ; Hello.new(s)
|
281
|
+
when DATABASE_DESCRIPTION ; DatabaseDescription.new(s)
|
282
|
+
when LINK_STATE_REQUEST ; LinkStateRequest.new(s)
|
283
|
+
when LINK_STATE_UPDATE ; LinkStateUpdate.new(s)
|
284
|
+
when LINK_STATE_ACKNOWLEDGMENT ; LinkStateAck.new(s)
|
285
|
+
else
|
286
|
+
raise RuntimeError, "unknown OSPFv2 packet type #{type}"
|
287
|
+
end
|
288
|
+
|
289
|
+
elsif arg.is_a?(Hash)
|
290
|
+
case arg[:packet_type]
|
291
|
+
when :hello ; Hello.new(arg)
|
292
|
+
when :dd ; DatabaseDescription.new(arg)
|
293
|
+
else
|
294
|
+
raise RuntimeError, "Cannot yet build this packet from hash #{arg[:packet_type]}"
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
load "../../../test/ospfv2/packet/#{ File.basename($0.gsub(/.rb/,'_test.rb'))}" if __FILE__ == $0
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ospfv2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jean Michel Esnault
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-16 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: jme@spidercloud.com
|
23
|
+
executables:
|
24
|
+
- ospfv2
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/ie/au_type.rb
|
31
|
+
- lib/ie/external_route.rb
|
32
|
+
- lib/ie/id.rb
|
33
|
+
- lib/ie/interface_mtu.rb
|
34
|
+
- lib/ie/ls_age.rb
|
35
|
+
- lib/ie/ls_type.rb
|
36
|
+
- lib/ie/metric.rb
|
37
|
+
- lib/ie/mt_metric.rb
|
38
|
+
- lib/ie/options.rb
|
39
|
+
- lib/ie/ospf_version.rb
|
40
|
+
- lib/ie/packet_type.rb
|
41
|
+
- lib/ie/router_link.rb
|
42
|
+
- lib/ie/router_link_factory.rb
|
43
|
+
- lib/ie/router_link_type.rb
|
44
|
+
- lib/ie/sequence_number.rb
|
45
|
+
- lib/ie/tos_metric.rb
|
46
|
+
- lib/infra/ospf_common.rb
|
47
|
+
- lib/infra/ospf_constants.rb
|
48
|
+
- lib/infra/ospf_io.rb
|
49
|
+
- lib/infra/ospf_socket.rb
|
50
|
+
- lib/infra/parse_options.rb
|
51
|
+
- lib/infra/timer.rb
|
52
|
+
- lib/infra/to_s.rb
|
53
|
+
- lib/ls_db/advertised_routers.rb
|
54
|
+
- lib/ls_db/common.rb
|
55
|
+
- lib/ls_db/link_state_database.rb
|
56
|
+
- lib/ls_db/link_state_database_build.rb
|
57
|
+
- lib/ls_db/link_state_database_links.rb
|
58
|
+
- lib/ls_db/links.rb
|
59
|
+
- lib/lsa/external.rb
|
60
|
+
- lib/lsa/lsa.rb
|
61
|
+
- lib/lsa/lsa_factory.rb
|
62
|
+
- lib/lsa/network.rb
|
63
|
+
- lib/lsa/router.rb
|
64
|
+
- lib/lsa/summary.rb
|
65
|
+
- lib/neighbor/neighbor.rb
|
66
|
+
- lib/neighbor/neighbor_event_handler.rb
|
67
|
+
- lib/neighbor/recv_database_description.rb
|
68
|
+
- lib/neighbor/recv_hello.rb
|
69
|
+
- lib/neighbor/recv_ospf_packet.rb
|
70
|
+
- lib/neighbor_sm/attempt_state.rb
|
71
|
+
- lib/neighbor_sm/down_state.rb
|
72
|
+
- lib/neighbor_sm/exchange_state.rb
|
73
|
+
- lib/neighbor_sm/exstart_state.rb
|
74
|
+
- lib/neighbor_sm/full_state.rb
|
75
|
+
- lib/neighbor_sm/init_state.rb
|
76
|
+
- lib/neighbor_sm/loading_state.rb
|
77
|
+
- lib/neighbor_sm/neighbor_state.rb
|
78
|
+
- lib/packet/database_description.rb
|
79
|
+
- lib/packet/hello.rb
|
80
|
+
- lib/packet/link_state_ack.rb
|
81
|
+
- lib/packet/link_state_request.rb
|
82
|
+
- lib/packet/link_state_update.rb
|
83
|
+
- lib/packet/ospf_packet.rb
|
84
|
+
has_rdoc: true
|
85
|
+
homepage:
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
version: "0"
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 1.3.6
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: An OSPFv2 Emulator.
|
115
|
+
test_files: []
|
116
|
+
|