Class: OSPFv2::Network

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

Constant Summary collapse

NetworkMask =
Class.new(Id)
AttachRouter =
Class.new(Id)

Constants inherited from Lsa

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

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, #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?, #is_opaque?, #key, #ls_type, #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.



94
95
96
97
98
# File 'lib/lsa/network.rb', line 94

def initialize(arg={})
  @network_mask, @attached_routers = nil, []
  @ls_type = LsType.new(:network_lsa)
  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.



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

def attached_routers
  @attached_routers
end

#network_maskObject (readonly)

Returns the value of attribute network_mask.



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

def network_mask
  @network_mask
end

Class Method Details

.new_hash(h) ⇒ Object



162
163
164
165
# File 'lib/lsa/network.rb', line 162

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

Instance Method Details

#<<(neighbor) ⇒ Object



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

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

#encodeObject



100
101
102
103
104
105
106
107
# File 'lib/lsa/network.rb', line 100

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



118
119
120
121
122
123
124
# File 'lib/lsa/network.rb', line 118

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


138
139
140
141
# File 'lib/lsa/network.rb', line 138

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


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

def to_s_junos
  super
end

#to_s_junos_verboseObject



152
153
154
155
156
157
# File 'lib/lsa/network.rb', line 152

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