Class: OSPFv2::LinkStateAck

Inherits:
OspfPacket show all
Defined in:
lib/packet/link_state_ack.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, #set, #to_hash

Constructor Details

#initialize(_arg = {}) ⇒ LinkStateAck

Returns a new instance of LinkStateAck.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/packet/link_state_ack.rb', line 87

def initialize(_arg={})
  arg = _arg.dup
  @lsa_headers=[]
  if arg.is_a?(Hash)
    arg.merge!({:packet_type=>5})
    super arg
  elsif arg.is_a?(String)
    parse arg
  elsif arg.is_a?(self.class)
    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

#lsa_headersObject

Returns the value of attribute lsa_headers.



79
80
81
# File 'lib/packet/link_state_ack.rb', line 79

def lsa_headers
  @lsa_headers
end

Class Method Details

.ack_ls_update(lsu, *args) ⇒ Object



81
82
83
84
85
# File 'lib/packet/link_state_ack.rb', line 81

def self.ack_ls_update(lsu, *args)
  ls_ack = new(*args)
  ls_ack.lsa_headers = lsu.lsas
  ls_ack
end

Instance Method Details

#add_lsa_header(lsu) ⇒ Object



102
103
104
# File 'lib/packet/link_state_ack.rb', line 102

def add_lsa_header(lsu)
  lsu.lsas
end

#eachObject



118
119
120
121
122
# File 'lib/packet/link_state_ack.rb', line 118

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

#each_keyObject



112
113
114
115
116
# File 'lib/packet/link_state_ack.rb', line 112

def each_key
  @lsa_headers.each do |lsa|
    yield lsa.key
  end
end

#encodeObject



106
107
108
109
110
# File 'lib/packet/link_state_ack.rb', line 106

def encode
  headers = []
  headers << lsa_headers.collect { |x| x.encode.slice(0,20) }.join
  super headers.join
end

#parse(s) ⇒ Object



124
125
126
127
128
129
130
# File 'lib/packet/link_state_ack.rb', line 124

def parse(s)
  headers = super(s)
  while headers.size>0
    lsa = Lsa.new headers.slice!(0,20)
    @lsa_headers << lsa
  end
end

#to_sObject



132
133
134
135
136
137
138
# File 'lib/packet/link_state_ack.rb', line 132

def to_s
  s =[]
  s << super
  s << "Age  Options  Type    Link-State ID   Advr Router     Sequence   Checksum  Length" if lsa_headers.size>0
  s << lsa_headers.collect { |x| x.to_s_dd }
  s.join("\n ")
end