bgp4r 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bgp/common.rb CHANGED
@@ -121,16 +121,17 @@ class String
121
121
  alias packed? :is_packed?
122
122
 
123
123
  def hexlify
124
- return self unless is_packed?
125
- s=self.dup
126
- ls=[""]
127
- n=0
124
+ return self unless is_packed? or self.size==0
125
+ l,n,ls,s=0,0,[''],self.dup
128
126
  while s.size>0
129
127
  l = s.slice!(0,16)
130
- ls << format("0x%4.4x: %s", n,
131
- l.unpack("n#{l.size/2}").collect { |x| format("%4.4x",x) }.join(' '))
128
+ ls << format("0x%4.4x: %s", n, l.unpack("n#{l.size/2}").collect { |x| format("%4.4x",x) }.join(' '))
132
129
  n+=1
133
130
  end
131
+ if l.size%2 >0
132
+ ns = if l.size>1 then 1 else 0 end
133
+ ls.last << format("%s%2.2x",' '*ns,l[-1].unpack('C')[0])
134
+ end
134
135
  ls
135
136
  end
136
137
 
data/bgp/message.rb CHANGED
@@ -479,7 +479,19 @@ module BGP
479
479
  end
480
480
 
481
481
  def <<(val)
482
- #TODO add attr or nlri
482
+ if val.is_a?(Attr)
483
+ @path_attribute ||= Path_attribute.new
484
+ @path_attribute << val
485
+ elsif val.is_a?(String)
486
+ begin
487
+ Nlri.new(val)
488
+ @nlri ||=Nlri.new
489
+ @nlri << val
490
+ rescue => e
491
+ end
492
+ elsif val.is_a?(Nlri)
493
+ val.to_s.split.each { |n| self << n }
494
+ end
483
495
  end
484
496
 
485
497
  def to_s(as4byte=false, fmt=:tcpdump)
data/bgp4r.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{bgp4r}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jean-Michel Esnault"]
9
- s.date = %q{2009-06-30}
9
+ s.date = %q{2010-08-14}
10
10
  s.description = %q{BGP4R is a BGP-4 ruby library to create, send, and receive BGP messages in an object oriented manner}
11
11
  s.email = %q{jesnault@gmail.com}
12
12
  s.extra_rdoc_files = [
@@ -76,7 +76,7 @@ Gem::Specification.new do |s|
76
76
  s.require_paths = ["."]
77
77
  s.required_ruby_version = Gem::Requirement.new(">= 1.8.6")
78
78
  s.rubyforge_project = %q{bgp4r}
79
- s.rubygems_version = %q{1.3.4}
79
+ s.rubygems_version = %q{1.3.7}
80
80
  s.summary = %q{A BGP-4 Ruby Library}
81
81
  s.test_files = [
82
82
  "test/aggregator_test.rb",
@@ -106,7 +106,6 @@ Gem::Specification.new do |s|
106
106
  if s.respond_to? :specification_version then
107
107
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
108
108
  s.specification_version = 3
109
-
110
109
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
111
110
  else
112
111
  end
@@ -5,16 +5,16 @@ neighbor:
5
5
  router id: 1.1.1.1
6
6
  my as: 100
7
7
  holdtime: 180
8
- local address: 199.0.0.5
9
- neighbor address: 199.0.0.6
8
+ local address: 192.168.1.6
9
+ neighbor address: 192.168.1.199
10
10
  capabilities:
11
11
  - four byte as
12
12
  routes:
13
13
  nlris: 11.0.0.0/28, 1999, 127
14
- next hop: 199.0.0.5
14
+ next hop: 192.168.1.6
15
15
  local pref: 100
16
16
  med: 100
17
- origin: 0
17
+ origin: 1
18
18
  communities: 100:1 200:1 300:1
19
19
  as path: 200 300 400 500
20
20
 
data/test/common_test.rb CHANGED
@@ -59,8 +59,18 @@ class Common_Test < Test::Unit::TestCase
59
59
  assert_equal('10.32.0.0/12', ip3 ^ 2)
60
60
  end
61
61
  def test_string_1
62
- sbin = ['0a000001'].pack('H*')
63
- assert_equal('0x0000: 0a00 0001',sbin.hexlify.join)
62
+ sbin = ['00'].pack('H*')
63
+ assert_equal '0x0000: 00', sbin.hexlify.join
64
+ sbin = ['0001'].pack('H*')
65
+ assert_equal '0x0000: 0001', sbin.hexlify.join
66
+ sbin = ['000102'].pack('H*')
67
+ assert_equal '0x0000: 0001 02', sbin.hexlify.join
68
+ sbin = ['000102030405060708090a0b0c0d0e0f'].pack('H*')
69
+ assert_equal '0x0000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f', sbin.hexlify.join
70
+ sbin = ['000102030405060708090a0b0c0d0e0f10'].pack('H*')
71
+ sbin = ['000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20'].pack('H*')
72
+ assert_equal '0x0001: 1011 1213 1415 1617 1819 1a1b 1c1d 1e1f', sbin.hexlify[2]
73
+ assert_equal '0x0002: 20', sbin.hexlify[3]
64
74
  end
65
75
  def test_nlri
66
76
  assert_equal('14000000', IPAddr.new_nlri4(['101400'].pack('H*')).to_shex)
data/test/message_test.rb CHANGED
@@ -107,6 +107,24 @@ class Update_Test < Test::Unit::TestCase
107
107
  # Ship it!
108
108
  assert_equal(3*2, an_update.encode4.size - an_update.encode.size)
109
109
  end
110
+
111
+ def test_5
112
+ an_update = Update.new( Path_attribute.new( Origin.new(1),
113
+ Next_hop.new('10.0.0.1'),
114
+ Multi_exit_disc.new(100)
115
+ ))
116
+ assert ! an_update.path_attribute.has?(Local_pref), "Should not contain a Local Pref attr."
117
+ an_update << Local_pref.new(113)
118
+ assert an_update.path_attribute.has?(Local_pref), "Should contain a Local Pref attr."
119
+ assert_nil an_update.nlri
120
+ an_update << '77.0.0.0/17'
121
+ assert_equal Nlri, an_update.nlri.class
122
+ assert_equal 1, an_update.nlri.size
123
+ an_update << '88.0.0.0/18'
124
+ assert_equal 2, an_update.nlri.size
125
+ an_update << Nlri.new('21.0.0.0/11', '22.0.0.0/22')
126
+ assert_equal 4, an_update.nlri.size
127
+ end
110
128
 
111
129
  end
112
130
 
data/test/origin_test.rb CHANGED
@@ -52,6 +52,6 @@ class Origin_Test < Test::Unit::TestCase
52
52
  def test_6
53
53
  assert_equal("[wTcr] (1) Origin: [40010100] 'igp'", Origin.new.to_s)
54
54
  assert_equal("[wTcr] (1) Origin: [40010100] 'igp'", Origin.new(:igp).to_s)
55
- assert_equal("Origin (1), length: 1, Flags [T]: igp\n 0x0000: ", Origin.new.to_s(:tcpdump))
55
+ assert_equal("Origin (1), length: 1, Flags [T]: igp\n 0x0000: 00", Origin.new.to_s(:tcpdump))
56
56
  end
57
57
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bgp4r
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 5
9
+ version: 0.0.5
5
10
  platform: ruby
6
11
  authors:
7
12
  - Jean-Michel Esnault
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-06-30 00:00:00 -07:00
17
+ date: 2010-08-14 00:00:00 -07:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -92,21 +97,27 @@ rdoc_options:
92
97
  require_paths:
93
98
  - .
94
99
  required_ruby_version: !ruby/object:Gem::Requirement
100
+ none: false
95
101
  requirements:
96
102
  - - ">="
97
103
  - !ruby/object:Gem::Version
104
+ segments:
105
+ - 1
106
+ - 8
107
+ - 6
98
108
  version: 1.8.6
99
- version:
100
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
101
111
  requirements:
102
112
  - - ">="
103
113
  - !ruby/object:Gem::Version
114
+ segments:
115
+ - 0
104
116
  version: "0"
105
- version:
106
117
  requirements: []
107
118
 
108
119
  rubyforge_project: bgp4r
109
- rubygems_version: 1.3.5
120
+ rubygems_version: 1.3.7
110
121
  signing_key:
111
122
  specification_version: 3
112
123
  summary: A BGP-4 Ruby Library