参考:
https://github.com/osrg/gobgp/blob/master/docs/sources/grpc-client.md
注意保持gobgpd和api端的版本一致性(为此下载了对应的gobgpd二进制执行文件和源码包)
https://www.janog.gr.jp/meeting/janog37/download_file/gobgp.pdf
环境:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.2 LTS"
先安装gobgpd服务端
apt install gobgpd -y
systemctl stop gobgpd
下载gobgpd二进制
wgethttps://github.com/osrg/gobgp/releases/download/v2.11.0/gobgp_2.11.0_linux_amd64.tar.gz
下载gobgpd源码
wget https://github.com/osrg/gobgp/archive/v2.11.0.tar.gz
tar zxvf gobgp_2.11.0_linux_amd64.tar.gz
cp gobgpd /usr/bin/
cp gobgp /usr/bin/
编辑/etc/gobgpd.conf
[global.config]
as = 65080
router-id = "10.5.245.122"
[[neighbors]]
[neighbors.config]
neighbor-address = "10.5.245.198"
peer-as = 65060
[[neighbors.afi-safis]]
[neighbors.afi-safis.config]
afi-safi-name = "ipv4-unicast"
启动gobgpd
systemctl restart gobgpd
确认bgp邻居已确立
root@ubuntu:~/gobgp/tools/grpc/python# gobgp nei
Peer AS Up/Down State |#Received Accepted
10.5.245.198 65060 00:00:01Establ | 0 0
开始API端的准备与安装
apt install protobuf-compiler -y
apt install python-minimal -y
apt install python-pip -y
python -m pip install --upgrade pip
python -m pip install grpcio
python -m pip install grpcio-tools
注意以下三文件,后面会被/root/gobgp/api/gobgp.proto调用
/usr/local/lib/python2.7/dist-packages/grpc_tools/_proto/google/protobuf/any.proto
/usr/local/lib/python2.7/dist-packages/grpc_tools/_proto/google/protobuf/empty.proto
/usr/local/lib/python2.7/dist-packages/grpc_tools/_proto/google/protobuf/timestamp.proto
解压源码
tar zxvf v2.11.0.tar.gz
mv gobgp-2.11.0 gobgp
cd /root/gobgp/api/
python -m grpc_tools.protoc -I./ --python_out=. --grpc_python_out=. *.proto
export PYTHONPATH=$PYTHONPATH:/root/gobgp/api/
cd /root/gobgp/tools/grpc/python/
执行python list_peer.py
执行python add_path.py
(注意确保localhost:50051和179端口是open的)
在bgp对等体端查看 add_path.py执行后的效果
root@gobgpexabgp:~# gobgp nei
Peer AS Up/Down State |#Received Accepted
10.5.245.122 65080 00:07:23 Establ | 1 1
root@gobgpexabgp:~# gobgp global rib -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 111.111.111.0/24 1.1.1.1 65080 100 200 00:03:17 [{Origin: ?}]
查看 list_peer.py 执行效果
root@ubuntu:~/gobgp/tools/grpc/python# python list_peer.py
peer {
apply_policy {
export_policy {
direction: EXPORT
default_action: -1
}
import_policy {
direction: IMPORT
default_action: -1
}
}
conf {
local_as: 65080
neighbor_address: "10.5.245.198"
peer_as: 65060
peer_type: 1
}
ebgp_multihop {
}
route_reflector {
}
state {
messages {
received {
open: 1
keepalive: 3
total: 4
}
sent {
open: 1
keepalive: 3
total: 4
}
}
neighbor_address: "10.5.245.198"
peer_as: 65060
peer_type: 1
queues {
}
session_state: ESTABLISHED
remote_cap {
type_url: "type.googleapis.com/gobgpapi.FourOctetASNumberCapability"
value: "\010\244\374\003"
}
remote_cap {
type_url: "type.googleapis.com/gobgpapi.RouteRefreshCapability"
}
remote_cap {
type_url: "type.googleapis.com/gobgpapi.MultiProtocolCapability"
value: "\n\004\010\001\020\001"
}
local_cap {
type_url: "type.googleapis.com/gobgpapi.RouteRefreshCapability"
}
local_cap {
type_url: "type.googleapis.com/gobgpapi.MultiProtocolCapability"
value: "\n\004\010\001\020\001"
}
local_cap {
type_url: "type.googleapis.com/gobgpapi.FourOctetASNumberCapability"
value: "\010\270\374\003"
}
router_id: "192.168.20.1"
}
timers {
config {
connect_retry: 120
hold_time: 90
keepalive_interval: 30
idle_hold_time_after_reset: 30
}
state {
keepalive_interval: 30
negotiated_hold_time: 90
uptime {
seconds: 1597286234
}
downtime {
seconds: 1597286234
}
}
}
transport {
local_address: "10.5.245.122"
}
route_server {
}
graceful_restart {
}
afi_safis {
mp_graceful_restart {
config {
}
}
config {
family {
afi: AFI_IP
safi: SAFI_UNICAST
}
enabled: true
}
state {
family {
afi: AFI_IP
safi: SAFI_UNICAST
}
enabled: true
}
apply_policy {
export_policy {
direction: EXPORT
default_action: -1
}
import_policy {
direction: IMPORT
default_action: -1
}
}
route_selection_options {
config {
}
}
use_multiple_paths {
config {
}
ebgp {
config {
}
}
ibgp {
config {
}
}
}
route_target_membership {
config {
}
}
long_lived_graceful_restart {
config {
}
}
add_paths {
config {
}
}
}
}
网友评论