Class: OSPFv2::SequenceNumber

Inherits:
Object
  • Object
show all
Includes:
Comparable, OSPFv2, IE
Defined in:
lib/ie/sequence_number.rb

Constant Summary

Constants included from OSPFv2

ASBR_SUMMMARY_LSA, AllDRouters, AllSPFRouters, CheckAge, DefaultDestination, EXTERNAL_BASE_ADDRESS, EXTERNAL_LSA, IPPROTO_OSPF, InitialSequenceNumber, LINK_BASE_ADDRESS, LSA_HEADER_LEN, LSInfinity, LSRefreshTime, MaxAge, MaxAgeDiff, MaxSequenceNumber, MinLSArrival, MinLSInterval, N, NETWORK_BASE_ADDRESS, NETWORK_LSA, NSSA_LSA, Netmask, PACKET_HEADER_LEN, ROUTER_LINK_P2P, ROUTER_LINK_STUB, ROUTER_LINK_TRANSIT, ROUTER_LINK_VL, ROUTER_LSA, SUMMARY_BASE_ADDRESS, SUMMARY_LSA, VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IE

#method_missing

Constructor Details

#initialize(seqn = :init) ⇒ SequenceNumber

Returns a new instance of SequenceNumber.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ie/sequence_number.rb', line 49

def initialize(seqn=:init)
  if seqn.is_a?(Symbol)
    if seqn == :max
      @seqn= MaxSequenceNumber
    elsif seqn == :init
      @seqn = InitialSequenceNumber
    elsif seqn == :reserved
      @seqn = N
    end 
  elsif seqn.is_a?(self.class)
    @seqn = seqn.to_I
  else
    @seqn=seqn
  end
  @seqn = [@seqn].pack('I')
end

Dynamic Method Handling

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

Class Method Details

.initialObject



33
34
35
# File 'lib/ie/sequence_number.rb', line 33

def SequenceNumber.initial
  [N + 1].pack('I').unpack('i')[0]
end

.maxObject



37
38
39
# File 'lib/ie/sequence_number.rb', line 37

def SequenceNumber.max
  [N - 1].pack('I').unpack('i')[0]
end

.NObject



41
42
43
# File 'lib/ie/sequence_number.rb', line 41

def SequenceNumber.N
  [N].pack('I').unpack('i')[0]
end

.to_s(seqn) ⇒ Object



45
46
47
# File 'lib/ie/sequence_number.rb', line 45

def SequenceNumber.to_s(seqn)
  new(seqn).to_s
end

Instance Method Details

#+(num) ⇒ Object



85
86
87
88
89
# File 'lib/ie/sequence_number.rb', line 85

def +(num)
  seqn = (@seqn.unpack('i')[0]+num)
  @seqn = [seqn].pack('I')
  self
end

#-(num) ⇒ Object



97
98
99
# File 'lib/ie/sequence_number.rb', line 97

def -(num)
  self.+(-num)
end

#<=>(o) ⇒ Object



66
67
68
# File 'lib/ie/sequence_number.rb', line 66

def <=>(o)
  to_i <=> o.to_i
end

#encodeObject



101
102
103
# File 'lib/ie/sequence_number.rb', line 101

def encode
  [to_i].pack('N')
end

#incr(num = 1) ⇒ Object



91
92
93
94
95
# File 'lib/ie/sequence_number.rb', line 91

def incr(num=1)
  seqn = (@seqn.unpack('i')[0]+num)
  @seqn = [seqn].pack('I')
  self
end

#to_hashObject



105
106
107
# File 'lib/ie/sequence_number.rb', line 105

def to_hash
  to_I
end

#to_iObject



70
71
72
# File 'lib/ie/sequence_number.rb', line 70

def to_i
  @seqn.unpack('i')[0]
end

#to_IObject



73
74
75
# File 'lib/ie/sequence_number.rb', line 73

def to_I
  @seqn.unpack('I')[0]
end

#to_sObject



77
78
79
# File 'lib/ie/sequence_number.rb', line 77

def to_s
  "0x"+ sprintf("%08.8x", to_I)
end

#to_s_iosObject



81
82
83
# File 'lib/ie/sequence_number.rb', line 81

def to_s_ios
  "LS Seq Number: " + sprintf("%08.8x", to_I)
end