Class: OSPFv2::LsType

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ls_type = 1) ⇒ LsType

Returns a new instance of LsType.



125
126
127
128
129
130
131
132
133
134
# File 'lib/ie/ls_type.rb', line 125

def initialize(ls_type=1)
  @ls_type = case ls_type
  when Symbol
    LsType.ls_type_sym_to_i(ls_type)
  when Fixnum
    ls_type
  else
    raise ArgumentError, "Invalid LsType #{ls_type}"
  end
end

Class Method Details

.allObject



68
69
70
# File 'lib/ie/ls_type.rb', line 68

def all
  [:router, :network, :summary, :asbr_summary, :as_external]
end

.ls_type_sym_to_i(arg) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/ie/ls_type.rb', line 97

def ls_type_sym_to_i(arg)
  return arg if arg.is_a?(Fixnum)
  if @ls_type_sym_to_i.has_key?(arg)
    @ls_type_sym_to_i[arg]
  else
    raise
  end
end

.to_i(arg) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ie/ls_type.rb', line 72

def to_i(arg)
  return arg unless arg.is_a?(Symbol)
  case arg.to_s
  when /^router(_lsa|)$/       ; @ls_type=1
  when /^network(_lsa|)$/      ; @ls_type=2
  when /^summary(_lsa|)$/      ; @ls_type=3
  when /^asbr_summary(_lsa|)$/ ; @ls_type=4
  when /^as_external(_lsa|)$/  ; @ls_type=5
    #FIXME: finish and unit-test
    # when :as_external7_lsa ; @ls_type=7
    # when :opaque_link      ; @ls_type=9
    # when :opaque_area      ; @ls_type=10
    # when :opaque_as        ; @ls_type=11
  end    
end

.to_junos(arg) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/ie/ls_type.rb', line 106

def to_junos(arg)
  return arg unless arg.is_a?(Fixnum)
  if @ls_type_junos.has_key?(arg)
    @ls_type_junos[arg]
  else
    raise
  end
end

.to_short(arg) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/ie/ls_type.rb', line 115

def to_short(arg)
  return arg unless arg.is_a?(Fixnum)
  if @ls_type_short.has_key?(arg)
    @ls_type_short[arg]
  else
    raise
  end
end

.to_sym(arg) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/ie/ls_type.rb', line 88

def to_sym(arg)
  return arg unless arg.is_a?(Fixnum)
  if @ls_type_sym.has_key?(arg)
    @ls_type_sym[arg]
  else
    raise
  end
end

Instance Method Details

#encodeObject Also known as: enc



146
147
148
# File 'lib/ie/ls_type.rb', line 146

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

#is_opaque?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/ie/ls_type.rb', line 63

def is_opaque?
  (9..11) === @ls_type
end

#to_hashObject



151
152
153
# File 'lib/ie/ls_type.rb', line 151

def to_hash
  to_sym
end

#to_iObject



135
136
137
# File 'lib/ie/ls_type.rb', line 135

def to_i
  @ls_type
end

#to_junosObject



159
160
161
# File 'lib/ie/ls_type.rb', line 159

def to_junos
  LsType.to_junos(to_i)
end

#to_sObject



138
139
140
# File 'lib/ie/ls_type.rb', line 138

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

#to_s_shortObject



155
156
157
# File 'lib/ie/ls_type.rb', line 155

def to_s_short
  LsType.to_short(to_i)
end

#to_symObject



142
143
144
# File 'lib/ie/ls_type.rb', line 142

def to_sym
  LsType.to_sym @ls_type
end