Class: OSPFv2::PacketType

Inherits:
Object show all
Defined in:
lib/ie/packet_type.rb

Instance Method Summary collapse

Constructor Details

#initialize(value = 0) ⇒ PacketType

Returns a new instance of PacketType.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ie/packet_type.rb', line 25

def initialize(value=0)
  case value
  when 1, :hello      ; @packet_type = 1
  when 2, :dd         ; @packet_type = 2
  when 3, :ls_request ; @packet_type = 3
  when 4, :ls_update  ; @packet_type = 4
  when 5, :ls_ack     ; @packet_type = 5
  else
    @packet_type = 0
  end
end

Instance Method Details

#encodeObject Also known as: enc



57
58
59
# File 'lib/ie/packet_type.rb', line 57

def encode
  [@packet_type].pack('C')
end

#to_hashObject



36
37
38
# File 'lib/ie/packet_type.rb', line 36

def to_hash
  to_sym
end

#to_iObject



39
40
41
# File 'lib/ie/packet_type.rb', line 39

def to_i
  @packet_type
end

#to_sObject



42
43
44
# File 'lib/ie/packet_type.rb', line 42

def to_s
  self.class.to_s.split('::').last + ": #{to_sym}"
end

#to_symObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/ie/packet_type.rb', line 45

def to_sym
  case @packet_type
  when 1  ; :hello
  when 2  ; :dd
  when 3  ; :ls_request
  when 4  ; :ls_update
  when 5  ; :ls_ack
  else
    'unknown'
  end
end