Class: PacketGen::Header::OSPFv3
- Inherits:
-
Base
- Object
- Types::Fields
- Base
- PacketGen::Header::OSPFv3
- Defined in:
- lib/packetgen/header/ospfv3.rb,
lib/packetgen/header/ospfv3/lsa.rb,
lib/packetgen/header/ospfv3/hello.rb,
lib/packetgen/header/ospfv3/ls_ack.rb,
lib/packetgen/header/ospfv3/ls_update.rb,
lib/packetgen/header/ospfv3/ls_request.rb,
lib/packetgen/header/ospfv3/lsa_header.rb,
lib/packetgen/header/ospfv3/ipv6_prefix.rb,
lib/packetgen/header/ospfv3/db_description.rb
Overview
This class supports OSPFv3 (RFC 5340). A OSPFv3 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 | Instance ID | 0 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
An OSPFv3 header consists of:
-
a #version field (Types::Int8),
-
a #type field (Types::Int8Enum),
-
a #length field (Types::Int16). The length includes the header,
-
a #router_id field (Types::Int32),
-
an #area_id field (Types::Int32),
-
a #checksum field (Types::Int16),
-
an #instance_id field (Types::Int8),
-
a #reserved field (Types::Int8),
-
and a #body (Types::String).
Create an OSPFv3 header
# standalone
ospf = PacketGen::Header::OSPFv3.new
# in a packet
pkt = PacketGen.gen('IPv6', src: source_ip).add('OSPFv3')
# make IPv6 header correct for OSPF
pkt.ospfize
# or make it correct with specific destination address
pkt.ospfize(dst: :all_spf_routers)
# access to OSPF header
pkt.ospfv3 # => PacketGen::Header::OSPFv3
OSPFv3 attributes
ospf.version # => 3
ospf.type = 'LS_ACK' # or 5
ospf.length = 154
ospf.router_id = 0xc0a80001
ospf.area_id = 1
ospf.checksum = 0xabcd
ospf.instance_id = 0
OSPFv3 body
OSPFv3 #body should contain OSPF payload for given #type:
-
or LSAck.
Defined Under Namespace
Classes: ArrayOfIPv6Prefix, ArrayOfLSA, ArrayOfLSR, ArrayOfLink, DbDescription, Hello, IPv6Prefix, LSA, LSAHeader, LSAIntraAreaPrefix, LSALink, LSANetwork, LSARouter, LSAck, LSR, LSRequest, LSUpdate, Link
Constant Summary collapse
- IP_PROTOCOL =
IP protocol number for OSPF
OSPFv2::IP_PROTOCOL
- TYPES =
OSPF packet types
OSPFv2::TYPES
Instance Attribute Summary collapse
-
#area_id ⇒ Integer
32-bit area ID.
- #body ⇒ String, Base
-
#checksum ⇒ Integer
16-bit OSPF packet checksum.
-
#instance_id ⇒ Integer
8-bit instance ID.
-
#length ⇒ Integer
16-bit OSPF packet length.
-
#reserved ⇒ Integer
8-bit reserved field.
-
#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 OSPFv3 options field.
Instance Method Summary collapse
- #added_to_packet(packet) ⇒ Object private
-
#calc_checksum ⇒ Integer
Compute checksum and set
checksum
field. -
#calc_length ⇒ Integer
Compute length and set
length
field. -
#human_type ⇒ String
Get human-readable type.
-
#ospfize(dst: nil) ⇒ void
Fixup IPv6 header according to RFC 5340: * set Traffic Class field to 0xc0, * optionally set destination address, * set Hop-limit 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
Methods inherited from Types::Fields
#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field
Constructor Details
This class inherits a constructor from PacketGen::Header::Base
Instance Attribute Details
#area_id ⇒ Integer
32-bit area ID
93 |
# File 'lib/packetgen/header/ospfv3.rb', line 93 define_field :area_id, Types::Int32 |
#body ⇒ String, Base
108 |
# File 'lib/packetgen/header/ospfv3.rb', line 108 define_field :body, Types::String |
#checksum ⇒ Integer
16-bit OSPF packet checksum
97 |
# File 'lib/packetgen/header/ospfv3.rb', line 97 define_field :checksum, Types::Int16 |
#instance_id ⇒ Integer
8-bit instance ID.
101 |
# File 'lib/packetgen/header/ospfv3.rb', line 101 define_field :instance_id, Types::Int8 |
#length ⇒ Integer
16-bit OSPF packet length
85 |
# File 'lib/packetgen/header/ospfv3.rb', line 85 define_field :length, Types::Int16 |
#reserved ⇒ Integer
8-bit reserved field.
105 |
# File 'lib/packetgen/header/ospfv3.rb', line 105 define_field :reserved, Types::Int8, default: 0 |
#router_id ⇒ Integer
32-bit router ID
89 |
# File 'lib/packetgen/header/ospfv3.rb', line 89 define_field :router_id, Types::Int32 |
Class Method Details
.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 OSPFv3 options field.
138 139 140 141 142 |
# File 'lib/packetgen/header/ospfv3.rb', line 138 def self.(hdr) hdr.define_field :options, Types::Int24 hdr.define_bit_fields_on :options, :z, 18, :dc_opt, :r_opt, :n_opt, :x_opt, :e_opt, :v6_opt end |
Instance Method Details
#added_to_packet(packet) ⇒ Object
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
147 148 149 150 |
# File 'lib/packetgen/header/ospfv3.rb', line 147 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 |
#calc_checksum ⇒ Integer
Compute checksum and set checksum
field
154 155 156 157 158 159 160 161 |
# File 'lib/packetgen/header/ospfv3.rb', line 154 def calc_checksum ipv6 = ip_header(self) sum = ipv6.pseudo_header_checksum sum += IP_PROTOCOL sum += self.sz sum += IP.sum16(self) self.checksum = IP.reduce_checksum(sum) end |
#calc_length ⇒ Integer
Compute length and set length
field
171 172 173 |
# File 'lib/packetgen/header/ospfv3.rb', line 171 def calc_length self[:length].value = Base.calculate_and_set_length(self) end |
#human_type ⇒ String
Get human-readable type
165 166 167 |
# File 'lib/packetgen/header/ospfv3.rb', line 165 def human_type self[:type].to_human end |
#ospfize(dst: nil) ⇒ void
This method returns an undefined value.
Fixup IPv6 header according to RFC 5340:
-
set Traffic Class field to 0xc0,
-
optionally set destination address,
-
set Hop-limit to 1 if destination is a mcast address.
This method may be called as:
# first way
pkt.ospfv3.ospfize
# second way
pkt.ospfize
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/packetgen/header/ospfv3.rb', line 188 def ospfize(dst: nil) ipv6 = ip_header(self) ipv6.traffic_class = 0xc0 dst = case dst when :all_spf_routers 'ff02::5' when :all_d_routers 'ff02::6' else dst end ipv6.dst = dst unless dst.nil? ipv6.hop = 1 if ipv6[:dst].mcast? end |