Class: OSPFv2::LinkStateRequest

Inherits:
OspfPacket show all
Defined in:
lib/packet/link_state_request.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

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 = {}) ⇒ LinkStateRequest

Returns a new instance of LinkStateRequest.



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/packet/link_state_request.rb', line 85

def initialize(arg={})
  @requests=[]
  if arg.is_a?(String)
    parse arg
  elsif arg.is_a?(Hash)
    arg.merge! :packet_type=>3
    super arg
  elsif arg.is_a?(self)
    parse arg.encode
  else
    raise ArgumentError, "Invalid argument"
  end
end

Dynamic Method Handling

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

Instance Attribute Details

#requestsObject (readonly)

Returns the value of attribute requests.



83
84
85
# File 'lib/packet/link_state_request.rb', line 83

def requests
  @requests
end

Instance Method Details

#<<(req) ⇒ Object



99
100
101
# File 'lib/packet/link_state_request.rb', line 99

def <<(req)
  @request << req
end

#encodeObject



103
104
105
106
107
# File 'lib/packet/link_state_request.rb', line 103

def encode
  requests = []
  requests << @requests.collect { |lsa| lsa.pack('NNN') }.join
  super requests.join
end

#parse(s) ⇒ Object



109
110
111
112
113
114
# File 'lib/packet/link_state_request.rb', line 109

def parse(s)
  requests = super(s)
  while requests.size>0
    @requests << requests.slice!(0,12).unpack('NNN')
  end
end

#to_lsu(ls_db, arg = {}) ⇒ Object



125
126
127
# File 'lib/packet/link_state_request.rb', line 125

def to_lsu(ls_db, arg={})
  LinkStateUpdate.new_lsas arg.merge(:lsas => collect { |req| ls_db[req] })
end

#to_sObject



116
117
118
119
120
121
122
123
# File 'lib/packet/link_state_request.rb', line 116

def to_s
  s = []
  s << super
  s << @requests.collect { |x| 
    "LS type #{ls_type_to_s(x[0])} Link State ID #{ls_id_to_s(x[1])} Advertising Router #{advr_to_s(x[2])}"
  }.join("\n ")
  s.join("\n ")
end