Class: PuppetX::Cisco::BgpUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/cisco/cmnutils.rb

Overview

PuppetX::Cisco::BgpUtil - Common BGP methods used by BGP Types/Providers

Class Method Summary collapse

Class Method Details

.dot_to_big(dot_str) ⇒ Object

Convert BGP ASN ASDOT+ to ASPLAIN



278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/puppet_x/cisco/cmnutils.rb', line 278

def self.dot_to_big(dot_str)
  fail ArgumentError unless dot_str.is_a? String
  return dot_str unless /\d+\.\d+/.match(dot_str)
  mask = 0b1111111111111111
  high = dot_str.to_i
  low = 0
  low_match = dot_str.match(/\.(\d+)/)
  low = low_match[1].to_i if low_match
  high_bits = (mask & high) << 16
  low_bits = mask & low
  high_bits + low_bits
end

.process_asnum(asnum) ⇒ Object



264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/puppet_x/cisco/cmnutils.rb', line 264

def self.process_asnum(asnum)
  err_msg = "BGP asnum must be either a 'String' or an" \
            " 'Integer' object"
  fail ArgumentError, err_msg unless asnum.is_a?(Integer) ||
                                     asnum.is_a?(String)
  if asnum.is_a? String
    # Match ASDOT '1.5' or ASPLAIN '55' strings
    fail ArgumentError unless /^(\d+|\d+\.\d+)$/.match(asnum)
    asnum = dot_to_big(asnum) if /\d+\.\d+/.match(asnum)
  end
  asnum.to_i
end