Class: OSPFv2::Network

Inherits:
Lsa show all
Defined in:
lib/lsa/network.rb,
lib/lsa/network.rb

Constant Summary

Constants inherited from Lsa

Lsa::AdvertisingRouter, Lsa::LsAge, Lsa::LsId

Constants included from Constant

Constant::DATABASE_DESCRIPTION, Constant::HELLO, Constant::LINK_STATE_ACKNOWLEDGEMENT, Constant::LINK_STATE_REQUEST, Constant::LINK_STATE_UPDATE, Constant::V2, Constant::V3

Instance Attribute Summary collapse

Attributes inherited from Lsa

#advertising_router, #ls_age, #ls_id, #ls_type, #options, #sequence_number

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Lsa

#<=>, #ack, #encode_header, #encode_request, factory, #find_lsa_from_link, #force_refresh, #header_lsa, #is_acked?, #key, #lsdb_link_id, #lsdb_link_id=, #maxage, #maxaged?, #method_missing, new_ntop, #refresh, #retransmit, #to_hash, #to_s_verbose

Methods included from TO_S

#to_s

Methods included from Common

#ivar_to_klassname, #ivars, #set, #to_hash

Constructor Details

#initialize(arg = {}) ⇒ Network

Returns a new instance of Network.



90
91
92
93
# File 'lib/lsa/network.rb', line 90

def initialize(arg={})
  @network_mask, @attached_routers = nil, []
  super
end

Dynamic Method Handling

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

Instance Attribute Details

#attached_routersObject

Returns the value of attribute attached_routers.



88
89
90
# File 'lib/lsa/network.rb', line 88

def attached_routers
  @attached_routers
end

#network_maskObject (readonly)

Returns the value of attribute network_mask.



88
89
90
# File 'lib/lsa/network.rb', line 88

def network_mask
  @network_mask
end

Class Method Details

.new_hash(h) ⇒ Object



157
158
159
160
# File 'lib/lsa/network.rb', line 157

def self.new_hash(h)
  r = new(h)
  r
end

Instance Method Details

#<<(neighbor) ⇒ Object



108
109
110
111
# File 'lib/lsa/network.rb', line 108

def <<(neighbor)
  @attached_routers ||=[]
  @attached_routers << AttachRouter.new(neighbor)
end

#encodeObject



95
96
97
98
99
100
101
102
# File 'lib/lsa/network.rb', line 95

def encode
  lsa=[]
  @network_mask ||= NetworkMask.new
  @attached_routers ||=[]
  lsa << network_mask.encode
  lsa << attached_routers.collect { |x| x.encode }
  super lsa.join
end

#parse(s) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/lsa/network.rb', line 113

def parse(s)
  network_mask, attached_routers = super(s).unpack('Na*')
  @network_mask = NetworkMask.new network_mask
  while attached_routers.size>0
    self << attached_routers.slice!(0,4).unpack('N')[0]
  end
end

#to_s_default(*args) ⇒ Object

Network:

LsAge: 34
Options:  0x22  [DC,E]
LsType: network_lsa
AdvertisingRouter: 192.168.1.200
LsId: 192.168.1.200
SequenceNumber: 0x80000001
LS checksum:  2dc
length: 32
NetworkMask: 255.255.255.0
AttachRouter: 192.168.1.200
AttachRouter: 193.0.0.0


133
134
135
136
# File 'lib/lsa/network.rb', line 133

def to_s_default(*args)
  super  +
  ['', network_mask, *attached_routers].join("\n   ")
end

#to_s_junosObject

Network *192.168.1.200 192.168.1.200 0x80000001 98 0x22 0x2dc 32

mask 255.255.255.0
attached router 192.168.1.200
attached router 193.0.0.0


143
144
145
# File 'lib/lsa/network.rb', line 143

def to_s_junos
  super
end

#to_s_junos_verboseObject



147
148
149
150
151
152
# File 'lib/lsa/network.rb', line 147

def to_s_junos_verbose
  mask = "mask #{network_mask.to_ip}"
  attrs = attached_routers.collect { |ar| "attached router #{ar.to_ip}"}
  super +
  ['', mask, *attrs].join("\n  ")
end