Class: OSPFv2::Summary_Base

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

Direct Known Subclasses

AsbrSummary, Summary

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_s_verbose

Methods included from TO_S

#to_s

Methods included from Common

#ivar_to_klassname, #ivars, #set

Constructor Details

#initialize(arg = {}) ⇒ Summary_Base

Returns a new instance of Summary_Base.



38
39
40
41
42
43
# File 'lib/lsa/summary.rb', line 38

def initialize(arg={})
  @netmask=nil
  @metric=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

#metricObject (readonly)

Returns the value of attribute metric.



36
37
38
# File 'lib/lsa/summary.rb', line 36

def metric
  @metric
end

#mt_metricsObject

Returns the value of attribute mt_metrics.



36
37
38
# File 'lib/lsa/summary.rb', line 36

def mt_metrics
  @mt_metrics
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



36
37
38
# File 'lib/lsa/summary.rb', line 36

def netmask
  @netmask
end

Class Method Details

.new_hash(hash) ⇒ Object

Raises:

  • (ArgumentError)


152
153
154
155
# File 'lib/lsa/summary.rb', line 152

def self.new_hash(hash)
  raise ArgumentError, "Invalid argument" unless hash.is_a?(Hash)
  new(hash)
end

Instance Method Details

#<<(metric) ⇒ Object



49
50
51
52
# File 'lib/lsa/summary.rb', line 49

def <<(metric)
  @mt_metrics ||=[]
  @mt_metrics << MtMetric.new(metric)
end

#encodeObject



54
55
56
57
58
59
60
61
62
# File 'lib/lsa/summary.rb', line 54

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

#parse(s) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/lsa/summary.rb', line 64

def parse(s)
  netmask, metric, mt_metrics = super(s).unpack('NNa*')
  @netmask = Netmask.new netmask
  @metric = Metric.new metric
  while mt_metrics.size>0
    self << MtMetric.new(mt_metrics.slice!(0,4))
  end
end

#to_hashObject



73
74
75
# File 'lib/lsa/summary.rb', line 73

def to_hash
  super
end

#to_s_default(*args) ⇒ Object



77
78
79
80
# File 'lib/lsa/summary.rb', line 77

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

#to_s_junosObject



87
88
89
# File 'lib/lsa/summary.rb', line 87

def to_s_junos
  super
end

#to_s_junos_verboseObject



82
83
84
85
86
# File 'lib/lsa/summary.rb', line 82

def to_s_junos_verbose
  mask = "mask #{netmask.to_ip}"
  super +
  ['', mask, metric.to_s_junos, *mt_metrics.collect{|m| m.to_s_junos}].join("\n  ")
end