Ryu BGP application

Ryu can run a BGP application with the --bgp-app-config-file option, which can be taken in as input by the ryu/serivces/protocols/bgp/applications.py module:

$ sudo ryu-manager --verbose --bgp-app-config-file <config_file> ryu/services/protocols/bgp/application.py

There is a sample configuration file located in the same directory for reference:

$ less ryu/services/protocols/bgp/bgp_sample_conf.py

In our configuration file, Chapter11_6.py, we will start with a simple configuration file that establishes the BGP neighbor relationship and provides an SSH console:

BGP = {
'local_as': 65000,
'router_id': '172.16.1.174',
'neighbors': [
{
'address': '172.16.1.175',
'remote_as': 1,
'enable_ipv4': True,
'enable_ipv6': True,
'enable_vpnv4': True,
'enable_vpnv6': True
},
]
}

SSH = {
'ssh_port': 4990,
'ssh_host': 'localhost',
# 'ssh_host_key': '/etc/ssh_host_rsa_key',
# 'ssh_username': 'ryu',
# 'ssh_password': 'ryu',
}

You can launch the application using the --bgp-app-config-file option:

$ sudo ryu-manager --verbose --bgp-app-config-file mastering_python_networking/Chapter11_6.py ryu/services/protocols/bgp/application.py

You can SSH to the localhost and take a look at the neighbors, RIB, and so on:

$ ssh localhost -p 4990

Hello, this is Ryu BGP speaker (version 4.13).

bgpd>
bgpd> show neighbor
IP Address AS Number BGP State
172.16.1.175 1 Established
bgpd> show rib all
Status codes: * valid, > best
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Labels Next Hop Reason Metric LocPrf Path
Family: vpnv6
Family: ipv4fs
Family: vpnv4
Family: vpnv4fs
Family: ipv4
*> 192.168.0.1/32 None 172.16.1.175 Only Path 0 1 i
*> 192.168.0.2/32 None 172.16.1.175 Only Path 1 i
Family: ipv6
Family: rtfilter
Family: evpn
bgpd> quit
bgpd> bye.
Connection to localhost closed.

In the Chapter11_7.py configuration file, I've also included a section for route advertisement:

'routes': [
# Example of IPv4 prefix
{
'prefix': '10.20.0.0/24',
'next_hop': '172.16.1.1'
},
{
'prefix': '10.20.1.0/24',
'next_hop': '172.16.1.174'
},
]

In it, we can see the Ryu controller advertised to iosv-1:

iosv-1#sh ip route bgp
...
Gateway of last resort is not set

10.0.0.0/8 is variably subnetted, 4 subnets, 3 masks
B 10.20.0.0/24 [20/0] via 172.16.1.1, 00:01:16
B 10.20.1.0/24 [20/0] via 172.16.1.174, 00:01:16

Note that the next_hop attribute for the IPv4 prefix is pointed to 172.16.1.1 for the prefix 10.20.0.0/24. This is a great example of being able to flexibly control the BGP attributes that you wish to make (if you know what you are doing). The ryu/services/protocols/bgp/bgp_sample_config.py file provides lots of great examples and features; I would encourage you to take a closer look at what is available in the configuration file. In the next section, we will take a look at how to use the Ryu controller to simulate a firewall or access-list function.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.105.159