Class: PacketGen::Header::OSPFv2
- Defined in:
- lib/packetgen/header/ospfv2.rb,
lib/packetgen/header/ospfv2/lsa.rb,
lib/packetgen/header/ospfv2/hello.rb,
lib/packetgen/header/ospfv2/ls_ack.rb,
lib/packetgen/header/ospfv2/ls_update.rb,
lib/packetgen/header/ospfv2/ls_request.rb,
lib/packetgen/header/ospfv2/lsa_header.rb,
lib/packetgen/header/ospfv2/db_description.rb more...
Overview
This class supports OSPFv2 (RFC 2328). An OSPFv2 header has the following format:
0 1 2 3
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Version # | Type | Packet length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Router ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Area ID |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | AuType |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Authentication |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Authentication |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
An OSPFv2 header consists of:
-
a #version field (
BinStruct::Int8
), -
a #type field (
BinStruct::Int8Enum
), -
a #length field (
BinStruct::Int16
). The length includes the header, -
a #router_id field (
BinStruct::Int32
), -
an #area_id field (
BinStruct::Int32
), -
a #checksum field (
BinStruct::Int16
), -
an #au_type field (
BinStruct::Int16Enum
), -
an #authentication field (
BinStruct::Int64
), -
and a #body (
BinStruct::String
or PacketGen::Headerable).
OSPFv2 body
OSPFv2 #body should contain OSPF payload for given #type:
-
or LSAck.
Defined Under Namespace
Classes: ArrayOfExternal, ArrayOfLSA, ArrayOfLSR, ArrayOfLink, ArrayOfTosMetric, DbDescription, External, Hello, LSA, LSAASExternal, LSAHeader, LSANetwork, LSARouter, LSAck, LSR, LSRequest, LSUpdate, Link, TosMetric
Constant Summary collapse
- IP_PROTOCOL =
IP protocol number for OSPF
89
- TYPES =
OSPF packet types
{ 'HELLO' => 1, 'DB_DESCRIPTION' => 2, 'LS_REQUEST' => 3, 'LS_UPDATE' => 4, 'LS_ACK' => 5 }.freeze
- AU_TYPES =
Authentication types
{ 'NO_AUTH' => 0, 'PASSWORD' => 1, 'CRYPTO' => 2, 'CRYPTO_WITH_ESN' => 3 }.freeze
Instance Attribute Summary collapse
-
#area_id ⇒ Integer
32-bit area ID.
-
#au_type ⇒ Integer
16-bit authentication type.
-
#authentication ⇒ Integer
64-bit authentication data.
-
#body ⇒ String, Headerable
OSPF body.
-
#checksum ⇒ Integer
16-bit OSPF packet checksum.
-
#length ⇒ Integer
16-bit OSPF packet length.
-
#router_id ⇒ Integer
32-bit router ID.
-
#type ⇒ Integer
8-bit OSPF packet type.
-
#version ⇒ Integer
8-bit OSPF version.
Class Method Summary collapse
-
.define_options(hdr) ⇒ void
private
Helper class method to define an OSPFv2 options field.
Instance Method Summary collapse
-
#added_to_packet(packet) ⇒ void
private
Add
#ospfize
method topacket
. -
#calc_checksum ⇒ Integer
Compute checksum and set #checksum attribute.
-
#calc_length ⇒ Integer
Compute length and set #length attribute.
-
#human_au_type ⇒ String
Get human-readable AU type.
-
#human_type ⇒ String
Get human-readable type.
-
#ospfize(dst: nil) ⇒ void
Fixup IP header according to RFC 2328: * set TOS field to 0xc0, * optionally set destination address, * set TTL to 1 if destination is a mcast address.
Methods inherited from Base
bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header
Methods included from PacketGen::Headerable
included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s
Constructor Details
This class inherits a constructor from PacketGen::Header::Base
Instance Attribute Details
permalink #area_id ⇒ Integer
32-bit area ID
114 |
# File 'lib/packetgen/header/ospfv2.rb', line 114 define_attr :area_id, BinStruct::Int32 |
permalink #au_type ⇒ Integer
16-bit authentication type. Types are defined in AU_TYPES.
122 |
# File 'lib/packetgen/header/ospfv2.rb', line 122 define_attr :au_type, BinStruct::Int16Enum, enum: AU_TYPES |
permalink #authentication ⇒ Integer
64-bit authentication data
126 |
# File 'lib/packetgen/header/ospfv2.rb', line 126 define_attr :authentication, BinStruct::Int64 |
permalink #body ⇒ String, Headerable
OSPF body
130 |
# File 'lib/packetgen/header/ospfv2.rb', line 130 define_attr :body, BinStruct::String |
permalink #checksum ⇒ Integer
16-bit OSPF packet checksum
118 |
# File 'lib/packetgen/header/ospfv2.rb', line 118 define_attr :checksum, BinStruct::Int16 |
permalink #length ⇒ Integer
16-bit OSPF packet length
106 |
# File 'lib/packetgen/header/ospfv2.rb', line 106 define_attr :length, BinStruct::Int16 |
permalink #router_id ⇒ Integer
32-bit router ID
110 |
# File 'lib/packetgen/header/ospfv2.rb', line 110 define_attr :router_id, BinStruct::Int32 |
permalink #type ⇒ Integer
8-bit OSPF packet type. Types are defined in TYPES.
102 |
# File 'lib/packetgen/header/ospfv2.rb', line 102 define_attr :type, BinStruct::Int8Enum, enum: TYPES |
permalink #version ⇒ Integer
8-bit OSPF version
98 |
# File 'lib/packetgen/header/ospfv2.rb', line 98 define_attr :version, BinStruct::Int8, default: 2 |
Class Method Details
permalink .define_options(hdr) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Helper class method to define an OSPFv2 options field.
162 163 164 |
# File 'lib/packetgen/header/ospfv2.rb', line 162 def self.(hdr) hdr.define_bit_attr :options, dn_opt: 1, o_opt: 1, dc_opt: 1, l_opt: 1, n_opt: 1, mc_opt: 1, e_opt: 1, mt_opt: 1 end |
Instance Method Details
permalink #added_to_packet(packet) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method is used internally by PacketGen and should not be directly called
This method returns an undefined value.
Add #ospfize
method to packet
. This method calls #ospfize.
172 173 174 175 |
# File 'lib/packetgen/header/ospfv2.rb', line 172 def added_to_packet(packet) ospf_idx = packet.headers.size packet.instance_eval "def ospfize(**kwargs) @headers[#{ospf_idx}].ospfize(**kwargs); end" # def ospfize(**kwargs) @headers[2].ospfize(**kwargs); end end |
permalink #calc_checksum ⇒ Integer
Compute checksum and set #checksum attribute
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/packetgen/header/ospfv2.rb', line 179 def calc_checksum # #authentication field is not used in checksum calculation, # so force it to 0 before checksumming saved_auth = self.authentication self.authentication = 0 sum = IP.sum16(self) self.checksum = IP.reduce_checksum(sum) # Restore #authentication value self.authentication = saved_auth self.checksum end |
permalink #calc_length ⇒ Integer
Compute length and set #length attribute
208 209 210 |
# File 'lib/packetgen/header/ospfv2.rb', line 208 def calc_length self[:length].value = Base.calculate_and_set_length(self) end |
permalink #human_au_type ⇒ String
Get human-readable AU type
202 203 204 |
# File 'lib/packetgen/header/ospfv2.rb', line 202 def human_au_type self[:au_type].to_human end |
permalink #human_type ⇒ String
Get human-readable type
196 197 198 |
# File 'lib/packetgen/header/ospfv2.rb', line 196 def human_type self[:type].to_human end |
permalink #ospfize(dst: nil) ⇒ void
This method returns an undefined value.
Fixup IP header according to RFC 2328:
-
set TOS field to 0xc0,
-
optionally set destination address,
-
set TTL to 1 if destination is a mcast address.
This method may be called as:
# first way
pkt.ospfv2.ospfize
# second way
pkt.ospfize
225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/packetgen/header/ospfv2.rb', line 225 def ospfize(dst: nil) ip = ip_header(self) ip.tos = 0xc0 dst = case dst when :all_spf_routers '224.0.0.5' when :all_d_routers '224.0.0.6' else dst end ip.dst = dst unless dst.nil? ip.ttl = 1 if ip[:dst].mcast? end |