Class: OSPFv2::External_Base

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

Direct Known Subclasses

AsExternal

Constant Summary collapse

Netmask =
Class.new(OSPFv2::Id)
ExternalRoute =
Class.new(OSPFv2::ExternalRoute)

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_s_verbose

Methods included from TO_S

#to_s

Methods included from Common

#ivar_to_klassname, #ivars, #set

Constructor Details

#initialize(ls_type, arg = {}) ⇒ External_Base

Returns a new instance of External_Base.



166
167
168
169
170
171
# File 'lib/lsa/external.rb', line 166

def initialize(ls_type, arg={})
  @netmask, @external_route = nil
  @mt_metrics=[]
  @ls_type = LsType.new(ls_type)
  super arg
end

Dynamic Method Handling

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

Instance Attribute Details

#external_routeObject (readonly)

Returns the value of attribute external_route.



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

def external_route
  @external_route
end

#mt_metricsObject

Returns the value of attribute mt_metrics.



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

def mt_metrics
  @mt_metrics
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



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

def netmask
  @netmask
end

Class Method Details

.base_ip_addr(addr = EXTERNAL_BASE_ADDRESS) ⇒ Object



264
265
266
# File 'lib/lsa/external.rb', line 264

def base_ip_addr(addr=EXTERNAL_BASE_ADDRESS)
  @base_addr ||= IPAddr.new(addr)
end

.countObject



251
252
253
# File 'lib/lsa/external.rb', line 251

def count
  @count ||= 0
end

.incr_countObject



255
256
257
258
# File 'lib/lsa/external.rb', line 255

def incr_count
  self.count
  @count += 1
end

.networkObject



268
269
270
# File 'lib/lsa/external.rb', line 268

def network
  @base_addr + count
end

.new_lsdb(arg = {}) ⇒ Object



272
273
274
# File 'lib/lsa/external.rb', line 272

def new_lsdb(arg={})
  new({:network=> base_ip_addr ^ incr_count}.merge(arg))
end

.resetObject



260
261
262
# File 'lib/lsa/external.rb', line 260

def reset
  @count = nil
end

Instance Method Details

#<<(ext_route) ⇒ Object



224
225
226
227
228
229
230
231
# File 'lib/lsa/external.rb', line 224

def <<(ext_route)
  @mt_metrics ||=[]
  # p "calling MtExternalRoute with #{ext_route.inspect}"
  route = MtExternalRoute.new(ext_route)
  # p route
  @mt_metrics << route
  self
end

#encodeObject



173
174
175
176
177
178
179
180
# File 'lib/lsa/external.rb', line 173

def encode
  @netmask ||= Netmask.new
  external =[]
  external << netmask.encode
  external << external_route.encode
  external << mt_metrics.collect { |x| x.encode } if mt_metrics
  super external.join
end

#forwarding_address=(val) ⇒ Object



233
234
235
# File 'lib/lsa/external.rb', line 233

def forwarding_address=(val)
  @external_route.forwarding_address=(val)
end

#metric=(val) ⇒ Object



245
246
247
# File 'lib/lsa/external.rb', line 245

def metric=(val)
  @external_route.metric=(val)
end

#parse(s) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/lsa/external.rb', line 182

def parse(s)
  s = super(s)
  netmask, external_route = s.slice!(0,16).unpack('Na*')
  @netmask = Netmask.new netmask
  @external_route = ExternalRoute.new external_route
  while s.size>0
    self << MtExternalRoute.new(s.slice!(0,12))
  end
end

#tag=(val) ⇒ Object



241
242
243
# File 'lib/lsa/external.rb', line 241

def tag=(val)
  @external_route.tag=(val)
end

#to_hashObject



192
193
194
# File 'lib/lsa/external.rb', line 192

def to_hash
  super
end

#to_s_defaultObject



196
197
198
199
200
# File 'lib/lsa/external.rb', line 196

def to_s_default
  mt_metrics = self.mt_metrics.collect
  super  +
  ['',netmask, external_route, *mt_metrics ].collect { |x| x.to_s }.join("\n   ")
end

#to_s_junosObject



202
203
204
# File 'lib/lsa/external.rb', line 202

def to_s_junos
  super
end

#to_s_junos_verboseObject

Extern 50.0.2.0 128.3.0.1 0x80000001 39 0x0 0x1454 48

mask 255.255.255.0
Topology default (ID 0)
  Type: 1, Metric: 0, Fwd addr: 0.0.0.0, Tag: 0.0.0.0
Topology default (ID 0)
  Type: 1, Metric: 30, Fwd addr: 0.0.0.0, Tag: 0.0.0.10


212
213
214
215
216
# File 'lib/lsa/external.rb', line 212

def to_s_junos_verbose
  mt_metrics = self.mt_metrics.collect
  super  +
  ['',netmask, external_route, *mt_metrics ].collect { |x| x.to_s }.join("\n   ")
end

#type=(val) ⇒ Object



237
238
239
# File 'lib/lsa/external.rb', line 237

def type=(val)
  @external_route.type=(val)
end