dbarrosop / gobgp-grpc-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Requirements

  • docker
  • docker-compose 2.1

Instructions

In this demo we are going to set two gobgp instances, configure them so they peer with each other, deploy policies to them and manipulate their RIBs. All the operations will be performed from a control machine using gobgp's grpc interface (excluding some show operations due to lack of time).

Setting the environment

Build all necessary containers and start the environment

make build
make up

Open three terminal and connect to each container

make connect_control  # connect to the control machine
make connect_gobgp_1  # connect to gobgp instance 1
make connect_gobgp_2  # connect to gobgp instance 2

Configuring BGP peering

On the control machine, verify we don't have any peers on any of the devices:

root@control:/gobgprest/sample_scripts# python get_neighbor.py 10.0.123.100 50051
root@control:/gobgprest/sample_scripts# python get_neighbor.py 10.0.123.200 50051

Now let's add them:

root@control:/gobgprest/sample_scripts# python add_neighbor.py 10.0.123.100 50051 2001:db8:123::200 65002
root@control:/gobgprest/sample_scripts# python add_neighbor.py 10.0.123.200 50051 2001:db8:123::100 65001

And let's verify they are configured and sessions are established:

root@control:/gobgprest/sample_scripts# python get_neighbor.py 10.0.123.100 50051
BGP neighbor is 2001:db8:123::200, remote AS 65002
  BGP version 4, remote router ID 10.0.123.200
  BGP state = established, up for 1492432895
  BGP OutQ = 0, Flops = 0
  Hold time is 90, keepalive interval is 30 seconds
  Configured hold time is 90, keepalive interval is 30 seconds

root@control:/gobgprest/sample_scripts# python get_neighbor.py 10.0.123.200 50051
BGP neighbor is 2001:db8:123::100, remote AS 65001
  BGP version 4, remote router ID 10.0.123.100
  BGP state = established, up for 1492432895
  BGP OutQ = 0, Flops = 0
  Hold time is 90, keepalive interval is 30 seconds
  Configured hold time is 90, keepalive interval is 30 seconds

Deploying policies

We are going to deploy a policy from our control machine to gobgp_1. The policy should do the following:

  1. If community 65000:1 is present export the route
  2. If community 65000:666 don't export the route even if community 65000:1 is set
  3. Don't export routes by default

First, let's connect to gobgp_1 and gobgp_2 to verify we don't have any policies:

root@gobgp_1:/go# gobgp policy community
Nothing defined yet
root@gobgp_1:/go# gobgp policy statements
not found statements
root@gobgp_1:/go# gobgp policy
root@gobgp_1:/go# gobgp global policy
Import policy:
    Default: accept
Export policy:
    Default: accept

Now let's deploy policies on gobgp_1:

root@control:/gobgprest/sample_scripts# python add_policy.py 10.0.123.100 50051

Now we can fo back to gobgp_1 and verify the policies were deployed:

root@gobgp_1:/go# gobgp policy community
NAME             COMMUNITY
internal         65000:1
reject_internal  65000:666
root@gobgp_1:/go# gobgp global policy
Import policy:
    Default: accept
Export policy:
    Default: reject
    Name export_internal:
        StatementName reject_internal:
          Conditions:
            CommunitySet: any reject_internal
          Actions:
             reject
        StatementName accept_internal:
          Conditions:
            CommunitySet: any internal
          Actions:
             accept

Manipulating the RIB

Now we are going to manipulate the RIB of gobgp_1 and verify the policy we deployed is working as expected.

Let's start by verifying we have no routes on our RIB:

# On gobgp_1
root@gobgp_1:/go# gobgp global rib
Network not in table

Now, on the control machine, let's deploy a route on gobgp_1`s RIB:

root@control:/gobgprest/sample_scripts# python add_path.py 10.0.123.100 50051 2001:db8:666::/64 2001:db8:123::300 65000:1 110

Let's go back to gobgp_1 and see if it's there:

root@gobgp_1:/go# gobgp global rib -a ipv6
    Network             Next Hop             AS_PATH              Age        Attrs
*>  2001:db8:666::/64   2001:db8:123::300                         00:00:32   [{Origin: ?} {Med: 110} {Communities: 65000:1}]

As you can see it's there and it's locally generated. Let's see if it's being experted to gobgp_2 as per the policy:

root@gobgp_2:/go# gobgp global rib -a ipv6
    Network             Next Hop             AS_PATH              Age        Attrs
*>  2001:db8:666::/64   2001:db8:123::300    65001                00:00:45   [{Origin: ?} {Med: 110} {Communities: 65000:1}]

There it is. Let's go back to the control machine and set the community 65000:666 to filter it:

root@control:/gobgprest/sample_scripts# python add_path.py 10.0.123.100 50051 2001:db8:666::/64 2001:db8:123::300 65000:1,65000:666 110

Now let's go to gobgp_1 and verify the community is set:

root@gobgp_1:/go# gobgp global rib -a ipv6
    Network             Next Hop             AS_PATH              Age        Attrs
*>  2001:db8:666::/64   2001:db8:123::300                         00:00:45   [{Origin: ?} {Med: 110} {Communities: 65000:1, 65000:666}]

And, finally, let's see if the route is gone from gobgp_2:

root@gobgp_2:/go# gobgp global rib -a ipv6
Network not in table

Done, we have performed operations on multiple devices using gobgp's grpc interface

About

License:Apache License 2.0


Languages

Language:Python 98.9%Language:Makefile 1.1%