Class: OSPFv2::Hello

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

Defined Under Namespace

Classes: Neighbors

Constant Summary collapse

DesignatedRouterId =
Class.new(Id)
BackupDesignatedRouterId =
Class.new(Id)
Netmask =
Class.new(Id)

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, 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

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, #set, #to_hash

Constructor Details

#initialize(_arg = {}) ⇒ Hello

Returns a new instance of Hello.



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/packet/hello.rb', line 231

def initialize(_arg={})
  arg = _arg.dup
  if arg.is_a?(Hash)
    arg.merge!({:packet_type=>1})
    super arg
    @designated_router_id = DesignatedRouterId.new
    @backup_designated_router_id = BackupDesignatedRouterId.new
    @options = Options.new
    @rtr_pri = 0
    @netmask = Netmask.new
    @neighbors = nil
    @hello_interval, @router_dead_interval = 10, 40
    set arg
  elsif arg.is_a?(String)
    parse arg
  elsif arg.is_a?(Hello)
    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

#backup_designated_router_idObject (readonly)

Returns the value of attribute backup_designated_router_id.



190
191
192
# File 'lib/packet/hello.rb', line 190

def backup_designated_router_id
  @backup_designated_router_id
end

#designated_router_idObject (readonly)

Returns the value of attribute designated_router_id.



190
191
192
# File 'lib/packet/hello.rb', line 190

def designated_router_id
  @designated_router_id
end

#hello_intervalObject (readonly)

Returns the value of attribute hello_interval.



191
192
193
# File 'lib/packet/hello.rb', line 191

def hello_interval
  @hello_interval
end

#neighborsObject

Returns the value of attribute neighbors.



191
192
193
# File 'lib/packet/hello.rb', line 191

def neighbors
  @neighbors
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



190
191
192
# File 'lib/packet/hello.rb', line 190

def netmask
  @netmask
end

#optionsObject (readonly)

Returns the value of attribute options.



191
192
193
# File 'lib/packet/hello.rb', line 191

def options
  @options
end

#router_dead_intervalObject (readonly)

Returns the value of attribute router_dead_interval.



191
192
193
# File 'lib/packet/hello.rb', line 191

def router_dead_interval
  @router_dead_interval
end

#rtr_priObject (readonly)

Returns the value of attribute rtr_pri.



191
192
193
# File 'lib/packet/hello.rb', line 191

def rtr_pri
  @rtr_pri
end

Instance Method Details

#add_router_id(hello) ⇒ Object



266
267
268
# File 'lib/packet/hello.rb', line 266

def add_router_id(hello)
  self.neighbors = hello.router_id.to_hash
end

#encodeObject



284
285
286
287
288
289
290
291
292
293
294
# File 'lib/packet/hello.rb', line 284

def encode
  packet =[]
  packet << netmask.encode
  packet << [@hello_interval, @options.to_i, @rtr_pri, @router_dead_interval].pack('nCCN')
  packet << @designated_router_id.encode
  packet << @backup_designated_router_id.encode
  packet << neighbors.encode if neighbors
  super packet.join
rescue Exception => e
  p e
end

#has_neighbor?(neighbor) ⇒ Boolean

Returns:

  • (Boolean)


261
262
263
264
# File 'lib/packet/hello.rb', line 261

def has_neighbor?(neighbor)
  @neighbors ||=Hello::Neighbors.new
  neighbors.has?(neighbor)
end

#remove_neighbor(val) ⇒ Object



258
259
260
# File 'lib/packet/hello.rb', line 258

def remove_neighbor(val)
  self.neighbors - val
end

#to_sObject



275
276
277
278
279
280
281
282
# File 'lib/packet/hello.rb', line 275

def to_s
  s = []
  s << super
  s << "HellInt #{hello_interval}, DeadInt #{router_dead_interval}, Options #{options.to_s}, mask #{netmask}"
  s << "Prio #{@rtr_pri}, DR #{designated_router_id.to_ip}, BDR #{backup_designated_router_id.to_ip}"
  s << "Neighbors: #{@neighbors.to_s_ary.join(',')}" if @neighbors
  s.join("\n ")
end

#to_s_verboseObject



270
271
272
273
# File 'lib/packet/hello.rb', line 270

def to_s_verbose
  super +
  [@netmask, @options, rtr_pri_to_s, @designated_router_id, @backup_designated_router_id, neighbors_to_s].collect { |x| x.to_s }.join("\n ")
end