Class: OSPFv2::DatabaseDescription

Inherits:
OspfPacket show all
Defined in:
lib/packet/database_description.rb

Constant Summary

Constants inherited from OspfPacket

OspfPacket::DATABASE_DESCRIPTION, OspfPacket::HELLO, OspfPacket::LINK_STATE_ACKNOWLEDGMENT, OspfPacket::LINK_STATE_REQUEST, OspfPacket::LINK_STATE_UPDATE

Constants included from OSPFv2

ASBR_SUMMMARY_LSA, AllDRouters, AllSPFRouters, AreaId, CheckAge, DefaultDestination, EXTERNAL_BASE_ADDRESS, EXTERNAL_LSA, IPPROTO_OSPF, InitialSequenceNumber, LINK_BASE_ADDRESS, LSA_HEADER_LEN, LSInfinity, LSRefreshTime, MaxAge, MaxAgeDiff, MaxSequenceNumber, MinLSArrival, MinLSInterval, N, NETWORK_BASE_ADDRESS, NETWORK_LSA, NSSA_LSA, Netmask, PACKET_HEADER_LEN, ROUTER_LINK_P2P, ROUTER_LINK_STUB, ROUTER_LINK_TRANSIT, ROUTER_LINK_VL, ROUTER_LSA, RouterId, SUMMARY_BASE_ADDRESS, SUMMARY_LSA, VERSION

Instance Attribute Summary collapse

Attributes inherited from OspfPacket

#area_id, #au_type, #ospf_version, #packet_type, #router_id, #version

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OspfPacket

factory, #method_missing, #packet_name, #to_hash, #to_s_brief, #to_s_default

Methods included from Common

#ivar_to_klassname, #ivars, #to_hash

Constructor Details

#initialize(_arg = {}) ⇒ DatabaseDescription

Returns a new instance of DatabaseDescription.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/packet/database_description.rb', line 145

def initialize(_arg={})
  arg = _arg.dup
  @interface_mtu = InterfaceMtu.new
  @options = Options.new
  @imms, @dd_sequence_number, @number_of_lsa=0, nil, nil
  @lsas=[]

  if arg.is_a?(Hash)
    arg.merge!({:packet_type=>:dd})
    super arg
  elsif arg.is_a?(String)
    parse arg
  elsif arg.is_a?(DatabaseDescription)
    parse arg.encode
  else
    raise ArgumentError, "Invalid argument", caller
  end
  
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OSPFv2::OspfPacket

Instance Attribute Details

#dd_sequence_numberObject (readonly) Also known as: dd_seqn, seqn

Returns the value of attribute dd_sequence_number.



134
135
136
# File 'lib/packet/database_description.rb', line 134

def dd_sequence_number
  @dd_sequence_number
end

#interface_mtuObject (readonly)

Returns the value of attribute interface_mtu.



134
135
136
# File 'lib/packet/database_description.rb', line 134

def interface_mtu
  @interface_mtu
end

#ls_dbObject (readonly)

Returns the value of attribute ls_db.



134
135
136
# File 'lib/packet/database_description.rb', line 134

def ls_db
  @ls_db
end

#optionsObject

Returns the value of attribute options.



134
135
136
# File 'lib/packet/database_description.rb', line 134

def options
  @options
end

Class Method Details

.seqnObject



127
128
129
130
# File 'lib/packet/database_description.rb', line 127

def seqn
  @seqn ||= rand(0x4fff)
  @seqn +=1
end

Instance Method Details

#eachObject



250
251
252
253
254
# File 'lib/packet/database_description.rb', line 250

def each
  @lsas.each do |lsa|
    yield lsa
  end
end

#encodeObject



205
206
207
208
209
210
211
# File 'lib/packet/database_description.rb', line 205

def encode
  packet =[]
  packet << @interface_mtu.encode
  packet << [options.to_i, imms, dd_sequence_number].pack('CCN')
  packet << @lsas.collect { |x| x.encode.slice(0,20) }.join if @lsas
  super packet.join
end

#initObject Also known as: in_init



230
231
232
# File 'lib/packet/database_description.rb', line 230

def init 
  @imms |= 4
end

#init?Boolean

Returns:

  • (Boolean)


243
244
245
# File 'lib/packet/database_description.rb', line 243

def init?
  imms & 4 == 4
end

#masterObject Also known as: is_master



225
226
227
# File 'lib/packet/database_description.rb', line 225

def master 
  @imms |= 1
end

#master?Boolean

Returns:

  • (Boolean)


239
240
241
# File 'lib/packet/database_description.rb', line 239

def master?
  imms & 1 == 1
end

#moreObject



217
218
219
# File 'lib/packet/database_description.rb', line 217

def more
  @imms |= 2
end

#more?Boolean

Returns:

  • (Boolean)


235
236
237
# File 'lib/packet/database_description.rb', line 235

def more?
  imms & 2 == 2
end

#no_moreObject



221
222
223
# File 'lib/packet/database_description.rb', line 221

def no_more
  @imms &= ~2
end

#to_sObject



165
166
167
168
169
170
171
172
# File 'lib/packet/database_description.rb', line 165

def to_s
  s = []
  s << super(:brief)
  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}"
  s << "Age  Options  Type    Link-State ID   Advr Router     Sequence   Checksum  Length" if @lsas
  s << ((@lsas.collect { |x| x.to_s_dd })).join("\n ") if @lsas
  s.join("\n ")
end

#to_s_shortObject



202
203
204
# File 'lib/packet/database_description.rb', line 202

def to_s_short
  "I|M|MS: [#{[imms].pack('C').unpack('B8')[0][5..7]}] SEQN: #{dd_sequence_number}"
end