Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for configuring BGP maximum paths on a BGP neighbor #183

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 61 additions & 12 deletions lib/rbeapi/api/bgp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,11 @@ class BgpNeighbors < Entity
# remote_as: <string>,
# send_community: <string>,
# shutdown: <boolean>,
# description: <integer>
# next_hop_self: <boolean>
# route_map_in: <string>
# route_map_out: <string>
# description: <integer>,
# next_hop_self: <boolean>,
# route_map_in: <string>,
# route_map_out: <string>,
# maximum_routes: <integer>
# }
#
# @param name [String] The name of the BGP neighbor to manage.
Expand All @@ -473,6 +474,7 @@ def get(name)
response.merge!(parse_next_hop_self(config, name))
response.merge!(parse_route_map_in(config, name))
response.merge!(parse_route_map_out(config, name))
response.merge!(parse_maximum_routes(config, name))
response
end

Expand All @@ -487,20 +489,22 @@ def get(name)
# remote_as: <string>,
# send_community: <string>,
# shutdown: <boolean>,
# description: <integer>
# next_hop_self: <boolean>
# route_map_in: <string>
# route_map_out: <string>
# description: <integer>,
# next_hop_self: <boolean>,
# route_map_in: <string>,
# route_map_out: <string>,
# maximum_routes: <integer>
# },
# <name>: {
# peer_group: <string>,
# remote_as: <string>,
# send_community: <string>,
# shutdown: <boolean>,
# description: <integer>
# next_hop_self: <boolean>
# route_map_in: <string>
# route_map_out: <string>
# description: <integer>,
# next_hop_self: <boolean>,
# route_map_in: <string>,
# route_map_out: <string>,
# maximum_routes: <integer>
# },
# ...
# }
Expand Down Expand Up @@ -685,6 +689,26 @@ def parse_route_map_out(config, name)
end
private :parse_route_map_out

##
# parse_maximum_routes scans the BGP neighbor entries for the
# maximum routes.
#
# @api private
#
# @param config [String] The switch config.
#
# @param name [String] The name of the BGP neighbor to manage.
# This value can be either an IPv4 address or string (in the
# case of managing a peer group).
#
# @return [Hash<Symbol, Object>] Returns the resource hash attribute
def parse_maximum_routes(config, name)
value = config.scan(/neighbor #{name} maximum-routes (\d+)/)
maximum_routes = value[0] ? value[0][0] : nil
{ maximum_routes: maximum_routes }
end
private :parse_maximum_routes

##
# configure_bgp adds the command to go to BGP config mode.
# Then it adds the passed in command. The commands are then
Expand Down Expand Up @@ -965,6 +989,31 @@ def set_route_map_out(name, opts = {})
def set_description(name, opts = {})
configure_bgp(neigh_command_builder(name, 'description', opts))
end

##
# set_maximum_routes configures the maximum routes number for a neighbor
# (peer).
#
# ===Commands
# router bgp <bgp_as>
# {no | default} neighbor <name> maximum-routes <integer>
#
# @param name [String] The IP address or name of the peer group.
#
# @param opts [hash] Optional keyword arguments.
#
# @option opts value [Integer] The maximum routes to receive from the neighbor.
#
# @option opts enable [Boolean] If false then the command is
# negated. Default is true.
#
# @option opts default [Boolean] Configure the peer group using
# the default keyword.
#
# @return [Boolean] Returns true if the command complete successfully.
def set_maximum_routes(name, opts = {})
configure_bgp(neigh_command_builder(name, 'maximum-routes', opts))
end
end
end
end
36 changes: 28 additions & 8 deletions spec/system/rbeapi/api/bgp_neighbors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
description: nil,
next_hop_self: false,
route_map_in: nil,
route_map_out: nil }
route_map_out: nil,
maximum_routes: nil }
end

before do
Expand All @@ -70,17 +71,17 @@
'eBGP_GROUP' => {
peer_group: nil, remote_as: nil, send_community: false,
shutdown: false, description: nil, next_hop_self: false,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: '12000'
},
'192.168.255.1' => {
peer_group: 'eBGP_GROUP', remote_as: '65000', send_community: true,
shutdown: true, description: nil, next_hop_self: true,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: nil
},
'192.168.255.3' => {
peer_group: 'eBGP_GROUP', remote_as: '65001', send_community: true,
shutdown: true, description: nil, next_hop_self: true,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: nil
}
}
end
Expand Down Expand Up @@ -115,7 +116,8 @@
description: nil,
next_hop_self: true,
route_map_in: nil,
route_map_out: nil }
route_map_out: nil,
maximum_routes: nil }
end

let(:after) do
Expand All @@ -126,7 +128,8 @@
description: nil,
next_hop_self: false,
route_map_in: nil,
route_map_out: nil }
route_map_out: nil,
maximum_routes: nil }
end

before { node.config(['no router bgp 64600', 'router bgp 64600']) }
Expand All @@ -148,7 +151,8 @@
description: nil,
next_hop_self: false,
route_map_in: nil,
route_map_out: nil }
route_map_out: nil,
maximum_routes: nil }
end

let(:after) do
Expand All @@ -159,7 +163,8 @@
description: nil,
next_hop_self: true,
route_map_in: nil,
route_map_out: nil }
route_map_out: nil,
maximum_routes: nil }
end

it 'delete a BGP resource' do
Expand Down Expand Up @@ -351,4 +356,19 @@
expect(subject.get('eng')[:description]).to eq(nil)
end
end

describe '#set_maximum_routes' do
it 'set the maximum routes value' do
expect(subject.get('eng')[:maximum_routes]).to eq('12000')
expect(subject.set_maximum_routes('eng', value: '10')).to be_truthy
expect(subject.get('eng')[:maximum_routes]).to eq('0')
end

it 'defaults the maximum routes value' do
expect(subject.set_maximum_routes('eng', value: '0')).to be_truthy
expect(subject.set_maximum_routes('eng', default: true))
.to be_truthy
expect(subject.get('eng')[:maximum_routes]).to eq('12000')
end
end
end
20 changes: 17 additions & 3 deletions spec/unit/rbeapi/api/bgp/bgp_neighbors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
'eBGP_GROUP' => {
peer_group: nil, remote_as: nil, send_community: false,
shutdown: false, description: nil, next_hop_self: false,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: '12000'
},
'192.168.255.1' => {
peer_group: 'eBGP_GROUP', remote_as: '65000', send_community: true,
shutdown: true, description: nil, next_hop_self: true,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: nil
},
'192.168.255.3' => {
peer_group: 'eBGP_GROUP', remote_as: '65001', send_community: true,
shutdown: true, description: nil, next_hop_self: true,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: nil
}
} }
end
Expand Down Expand Up @@ -287,4 +287,18 @@ def bgp
expect(subject.set_description('eng', default: true)).to be_truthy
end
end

describe '#set_maximum_routes' do
it 'set the maximum routes value' do
expect(node).to receive(:config).with(['router bgp 64600',
'neighbor eng maximum-routes 0'])
expect(subject.set_maximum_routes('eng', value: 0)).to be_truthy
end

it 'defaults the maximum routes value' do
expect(node).to receive(:config)
.with(['router bgp 64600', 'default neighbor eng maximum-routes'])
expect(subject.set_maximum_routes('eng', default: true)).to be_truthy
end
end
end
6 changes: 3 additions & 3 deletions spec/unit/rbeapi/api/bgp/bgp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
'eBGP_GROUP' => {
peer_group: nil, remote_as: nil, send_community: false,
shutdown: false, description: nil, next_hop_self: false,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: '12000'
},
'192.168.255.1' => {
peer_group: 'eBGP_GROUP', remote_as: '65000', send_community: true,
shutdown: true, description: nil, next_hop_self: true,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: nil
},
'192.168.255.3' => {
peer_group: 'eBGP_GROUP', remote_as: '65001', send_community: true,
shutdown: true, description: nil, next_hop_self: true,
route_map_in: nil, route_map_out: nil
route_map_in: nil, route_map_out: nil, maximum_routes: nil
}
} }
end
Expand Down