Class: OSPFv2::LinkStateUpdate
- Inherits:
-
OspfPacket
- Object
- OspfPacket
- OSPFv2::LinkStateUpdate
- Defined in:
- lib/packet/link_state_update.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
-
#lsas ⇒ Object
readonly
Returns the value of attribute lsas.
Attributes inherited from OspfPacket
#area_id, #au_type, #ospf_version, #packet_type, #router_id, #version
Class Method Summary collapse
Instance Method Summary collapse
- #[](val) ⇒ Object
- #ack_lsu(router_id) ⇒ Object
- #each ⇒ Object
- #encode ⇒ Object
-
#initialize(_arg = {}) ⇒ LinkStateUpdate
constructor
A new instance of LinkStateUpdate.
- #keys ⇒ Object
- #number_of_lsa ⇒ Object
- #parse(s) ⇒ Object
-
#to_s ⇒ Object
def to_s s = [] s << super s << lsas.collect { |x| x.to_s_junos }.join(“n ”) s.join(“n ”) end.
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 = {}) ⇒ LinkStateUpdate
Returns a new instance of LinkStateUpdate.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/packet/link_state_update.rb', line 87 def initialize(_arg={}) arg = _arg.dup @lsas=[] if arg.is_a?(Hash) arg.merge!({:packet_type=>4}) super arg elsif arg.is_a?(String) parse arg elsif arg.is_a?(self) 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
#lsas ⇒ Object (readonly)
Returns the value of attribute lsas.
85 86 87 |
# File 'lib/packet/link_state_update.rb', line 85 def lsas @lsas end |
Class Method Details
.new_lsas(arg = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/packet/link_state_update.rb', line 164 def new_lsas(arg={}) lsus=[] len=0 lsas = arg[:lsas] arg.delete(:lsas) lsu = new(arg) [lsas].flatten.compact.each do |lsa| lsa_len = lsa.encode.size if (len + lsa_len) > (1476-56-20) lsus << lsu lsu = new(arg) len = 0 end lsu.lsas << lsa len += lsa_len end lsus << lsu lsus end |
Instance Method Details
#[](val) ⇒ Object
127 128 129 |
# File 'lib/packet/link_state_update.rb', line 127 def [](val) lsas[val] end |
#ack_lsu(router_id) ⇒ Object
156 157 158 159 160 |
# File 'lib/packet/link_state_update.rb', line 156 def ack_lsu(router_id) ls_ack = LinkStateAck.new(:router_id => router_id, :area => area = @aread_id) each { |lsa| ls_ack.lsa_headers << lsa } ls_ack end |
#each ⇒ Object
148 149 150 |
# File 'lib/packet/link_state_update.rb', line 148 def each lsas.each { |ls| yield ls } end |
#encode ⇒ Object
106 107 108 109 110 111 |
# File 'lib/packet/link_state_update.rb', line 106 def encode headers = [] headers << [lsas.size].pack('N') headers << lsas.collect { |x| x.encode }.join super headers.join end |
#keys ⇒ Object
152 153 154 |
# File 'lib/packet/link_state_update.rb', line 152 def keys lsas.collect { |ls| ls.key } end |
#number_of_lsa ⇒ Object
102 103 104 |
# File 'lib/packet/link_state_update.rb', line 102 def number_of_lsa lsas.size end |
#parse(s) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/packet/link_state_update.rb', line 113 def parse(s) n, lsas = super(s).unpack('Na*') while lsas.size>0 len = lsas[18..19].unpack('n')[0] lsa = lsas.slice!(0,len) lsa = Lsa.factory lsa if lsa @lsas << lsa else puts "COULD NOT BUILD LSA OUT OF #{lsa.unpack('H*')}" end end end |
#to_s ⇒ Object
def to_s
s = []
s << super
s << lsas.collect { |x| x.to_s_junos }.join("\n ")
s.join("\n ")
end
138 139 140 141 142 143 144 145 |
# File 'lib/packet/link_state_update.rb', line 138 def to_s s = [] s << super(:brief) s << "\# LSAs #{@lsas.size}" s << "Age Options Type Link-State ID Advr Router Sequence Checksum Length" s << @lsas.collect { |x| x.to_s }.join("\n ") s.join("\n ") end |