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

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_s_verbose

Methods included from TO_S

#to_s

Methods included from Common

#ivar_to_klassname, #ivars, #set

Constructor Details

#initialize(arg = {}) ⇒ External_Base

Returns a new instance of External_Base.



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

def initialize(arg={})
  @netmask, @external_route = nil
  @mt_metrics=[]
  super
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.



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

def external_route
  @external_route
end

#mt_metricsObject

Returns the value of attribute mt_metrics.



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

def mt_metrics
  @mt_metrics
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



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

def netmask
  @netmask
end

Class Method Details

.base_ip_addr(addr = EXTERNAL_BASE_ADDRESS) ⇒ Object



262
263
264
# File 'lib/lsa/external.rb', line 262

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

.countObject



249
250
251
# File 'lib/lsa/external.rb', line 249

def count
  @count ||= 0
end

.incr_countObject



253
254
255
256
# File 'lib/lsa/external.rb', line 253

def incr_count
  self.count
  @count += 1
end

.networkObject



266
267
268
# File 'lib/lsa/external.rb', line 266

def network
  @base_addr + count
end

.new_lsdb(arg = {}) ⇒ Object



270
271
272
# File 'lib/lsa/external.rb', line 270

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

.resetObject



258
259
260
# File 'lib/lsa/external.rb', line 258

def reset
  @count = nil
end

Instance Method Details

#<<(ext_route) ⇒ Object



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

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



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

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



231
232
233
# File 'lib/lsa/external.rb', line 231

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

#metric=(val) ⇒ Object



243
244
245
# File 'lib/lsa/external.rb', line 243

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

#parse(s) ⇒ Object



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

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



239
240
241
# File 'lib/lsa/external.rb', line 239

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

#to_hashObject



190
191
192
# File 'lib/lsa/external.rb', line 190

def to_hash
  super
end

#to_s_defaultObject



194
195
196
197
198
# File 'lib/lsa/external.rb', line 194

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



200
201
202
# File 'lib/lsa/external.rb', line 200

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


210
211
212
213
214
# File 'lib/lsa/external.rb', line 210

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



235
236
237
# File 'lib/lsa/external.rb', line 235

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