kakkotetsu

GoBGP インストール~簡易動作確認 (original : 2015/11/08)

この記事は某所で 2015/11/08 に書いたもののコピーです。
そのため 2017/05/13 時点ではやや古い情報も含まれています。

概要

本項でやること

  • gobgp をインストール~起動~適当なノードとiBGP Peeringするところまでです
  • gobgp 公式 Getting started に従います

環境情報

$ uname -a
Linux as65000-s1 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

$ uname -r
3.19.0-25-generic

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"

構築手順

Go インストール

$ wget --no-check-certificate https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz
$ ls -al
total 76060
drwxrwxr-x 2 kotetsu kotetsu     4096 Nov  7 20:53 .
drwxr-xr-x 5 kotetsu kotetsu     4096 Nov  7 20:49 ..
-rw-rw-r-- 1 kotetsu kotetsu 77875767 Sep  9 13:20 go1.5.1.linux-amd64.tar.gz

$ sudo tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gz
$ ls -al /usr/local/go/
total 136
drwxr-xr-x 11 root root  4096 Sep  9 10:37 .
drwxr-xr-x 11 root root  4096 Nov  7 20:57 ..
drwxr-xr-x  2 root root  4096 Sep  9 10:24 api
-rw-r--r--  1 root root 21146 Sep  9 10:24 AUTHORS
drwxr-xr-x  2 root root  4096 Sep  9 10:37 bin
drwxr-xr-x  4 root root  4096 Sep  9 10:37 blog
-rw-r--r--  1 root root  1107 Sep  9 10:24 CONTRIBUTING.md
-rw-r--r--  1 root root 28953 Sep  9 10:24 CONTRIBUTORS
drwxr-xr-x  8 root root  4096 Sep  9 10:24 doc
-rw-r--r--  1 root root  1150 Sep  9 10:24 favicon.ico
drwxr-xr-x  3 root root  4096 Sep  9 10:24 lib
-rw-r--r--  1 root root  1479 Sep  9 10:24 LICENSE
drwxr-xr-x 13 root root  4096 Sep  9 10:37 misc
-rw-r--r--  1 root root  1303 Sep  9 10:24 PATENTS
drwxr-xr-x  7 root root  4096 Sep  9 10:37 pkg
-rw-r--r--  1 root root  1519 Sep  9 10:24 README.md
-rw-r--r--  1 root root    26 Sep  9 10:24 robots.txt
drwxr-xr-x 43 root root  4096 Sep  9 10:24 src
drwxr-xr-x 16 root root 12288 Sep  9 10:36 test
-rw-r--r--  1 root root     7 Sep  9 10:24 VERSION

$ mkdir $HOME/go
$ echo 'export GOPATH=$HOME/go'  >> $HOME/.profile
$ echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> $HOME/.profile
$ source $HOME/.profile
$ env | grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin:/usr/local/go/bin:/usr/local/go/bin:/home/kotetsu/go/bin
GOPATH=/home/kotetsu/go

$ go version
go version go1.5.1 linux/amd64

gobgp インストール

  • インストールに使う go get コマンドに必要なパッケージを適宜インストール GoGetTools
$ sudo apt-get update
$ sudo apt-get install git mercurial
$ go get github.com/osrg/gobgp/gobgpd
warning: code.google.com is shutting down; import path code.google.com/p/go-uuid/uuid will stop working

$ go get github.com/osrg/gobgp/gobgp

$ ls -al ~/go/bin/
total 29056
drwxrwxr-x 2 kotetsu kotetsu     4096 Nov  7 21:43 .
drwxrwxr-x 5 kotetsu kotetsu     4096 Nov  7 21:36 ..
-rwxr-xr-x 1 kotetsu kotetsu 13801080 Nov  7 21:43 gobgp
-rwxr-xr-x 1 kotetsu kotetsu 15939792 Nov  7 21:36 gobgpd

gobgpd.conf 作成

  • 適当なディレクトリに config ファイルを作成して、適当な設定を書き込む
  • 以下例では iBGP しか設定していないが、eBGP も動く
$ mkdir ~/gobgp
$ touch ~/gobgp/gobgpd.conf

$ cat ~/gobgp/gobgpd.conf
[Global]
  [Global.GlobalConfig]
    As = 65000
    RouterId = "192.168.101.170"

[Neighbors]
  [[Neighbors.NeighborList]]
    [Neighbors.NeighborList.NeighborConfig]
      NeighborAddress = "10.0.1.2"
      PeerAs = 65000
    [Neighbors.NeighborList.AfiSafis]
      [[Neighbors.NeighborList.AfiSafis.AfiSafiList]]
        AfiSafiName = "l2vpn-evpn"

  [[Neighbors.NeighborList]]
    [Neighbors.NeighborList.NeighborConfig]
      NeighborAddress = "10.0.2.2"
      PeerAs = 65000
    [Neighbors.NeighborList.AfiSafis]
      [[Neighbors.NeighborList.AfiSafis.AfiSafiList]]
        AfiSafiName = "l2vpn-evpn"

gobgpd 起動

  • root 権限で実行しないと、IP アドレス bind に失敗する
  • デフォルトではフォアグラウンドで動く
$ gobgpd -f ~/gobgp/gobgpd.conf
{"level":"info","msg":"gobgpd started","time":"2015-11-07T22:11:54+09:00"}
{"level":"info","msg":"finished reading the config file","time":"2015-11-07T22:11:54+09:00"}
{"level":"info","msg":"listen tcp4 :179: bind: permission denied","time":"2015-11-07T22:11:54+09:00"}
{"level":"info","msg":"listen tcp6 :179: bind: permission denied","time":"2015-11-07T22:11:54+09:00"}
{"level":"fatal","msg":"can't listen either v4 and v6","time":"2015-11-07T22:11:54+09:00"}

$ sudo cat /etc/sudoers | grep Defaults
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Defaults        exempt_group="kotetsu"

$ sudo -E gobgpd -f ~/gobgp/gobgpd.conf &
[1] 8242
kotetsu@as65000-1:~$ {"level":"info","msg":"gobgpd started","time":"2015-11-07T22:28:37+09:00"}
{"level":"info","msg":"finished reading the config file","time":"2015-11-07T22:28:37+09:00"}
{"level":"info","msg":"Peer 10.0.1.2 is added","time":"2015-11-07T22:28:37+09:00"}
{"level":"info","msg":"Peer 10.0.2.2 is added","time":"2015-11-07T22:28:37+09:00"}

$ ps au | grep [g]o
root      8242  0.0  0.8  64956  4052 pts/1    S    Nov07   0:00 sudo -E gobgpd -f /home/kotetsu/gobgp/gobgpd.conf
root      8243  0.0  2.1 139396 11004 pts/1    Sl   Nov07   0:01 gobgpd -f /home/kotetsu/gobgp/gobgpd.conf

$ gobgp neighbor --help
Usage:
  gobgp neighbor [flags]

Flags:
  -a, --address-family="": address family
  -t, --transport="": specifying a transport protocol

Global Flags:
      --bash-cmpl-file="gobgp_completion.bash": bash cmpl filename
  -d, --debug[=false]: use debug
  -c, --gen-cmpl[=false]: generate completion file
  -u, --host="127.0.0.1": host
  -j, --json[=false]: use json format to output format
  -p, --port=8080: port
  -q, --quiet[=false]: use quiet

動作確認

適当な neighbor を用意して、動作確認(勿論 gobgp 同士でも可能)

  • neighbor の Peer 確立、切断時などにはデフォルトでは標準出力に以下のような出力
{"Key":"10.0.1.2","Reason":"Peer closed the session","State":6,"Topic":"Peer","level":"info","msg":"Peer Down","time":"2015-11-08T12:18:41+09:00"}
{"Key":"10.0.1.2","Topic":"Peer","level":"warning","msg":"Closed an accepted connection","time":"2015-11-08T12:18:41+09:00"}
{"Key":"10.0.1.2","State":5,"Topic":"Peer","level":"info","msg":"Peer Up","time":"2015-11-08T12:18:51+09:00"}
$ gobgp neighbor
Peer                AS  Up/Down State       |#Advertised Received Accepted
10.0.1.2         65000 02:07:33 Establ      |          0        0        0
10.0.2.2         65000    never Active      |          0        0        0

$ gobgp neighbor 10.0.1.2
BGP neighbor is 10.0.1.2, remote AS 65000
  BGP version 4, remote router ID 10.0.1.2
  BGP state = BGP_FSM_ESTABLISHED, up for 02:07:40
  BGP OutQ = 0, Flops = 0
  Hold time is 0, keepalive interval is 30 seconds
  Configured hold time is 90, keepalive interval is 30 seconds
  Neighbor capabilities:
    BGP_CAP_MULTIPROTOCOL:
        RF_EVPN:        advertised and received
        RF_IPv4_VPN:    received
        RF_RTC_UC:      received
    BGP_CAP_ROUTE_REFRESH:      advertised
    BGP_CAP_FOUR_OCTET_AS_NUMBER:       advertised and received
  Message statistics:
                         Sent       Rcvd
    Opens:                 20         20
    Notifications:          0          0
    Updates:                0          0
    Keepalives:           392        392
    Route Refesh:           0          0
    Discarded:              0          0
    Total:                412        412
  Route statistics:
    Advertised:             0
    Received:               0
    Accepted:               0

おまけ CLI’s tab 補完(bash 用) 導入

  • ‘gobgp’ 各種コマンドを Tab 補完できるようになるので、入れておくと便利
$ cd ~/gobgp
$ wget https://raw.githubusercontent.com/osrg/gobgp/master/tools/completion/gobgp-completion.bash

$ ls -al
total 56
drwxrwxr-x 2 kotetsu kotetsu  4096 Nov  7 23:32 .
drwxr-xr-x 6 kotetsu kotetsu  4096 Nov  7 22:07 ..
-rw-rw-r-- 1 kotetsu kotetsu 41832 Nov  7 23:32 gobgp-completion.bash
-rw-rw-r-- 1 kotetsu kotetsu   354 Nov  7 22:10 gobgpd.conf

$ source ~/gobgp/gobgp-completion.bash

おわり

  • インストールしただけなので別に…