Examine the JSONRPC over WebSocket

If we take a look at the ryu/services/protocols/bgp/api/jsonrpc.py file, we see that the methods are Python decorators, it calls the various functions from ryu/services/protocols/bgp. Let us make a new file under mastering_python_networking named chapter13_jsonrpc_1.py, by making a new file, we can make our changes safely independent of the original file. This is where we will experiment and make our changes.
We see that the file imports the neighbors module from rtconf
:

from ryu.services.protocols.bgp.rtconf import neighbors

From that module, we retrieve the IP_ADDRESS and REMOTE_AS attribute that we use when creating the neighbor. We can see in the neighbors section of the configuration that were is also a route reflector client option:

IS_ROUTE_REFLECTOR_CLIENT = 'is_route_reflector_client'

Aha, from the BGP API documentation (http://ryu.readthedocs.io/en/latest/library_bgp_speaker_ref.html#), we can tell that this is where we can specify our route reflector client for the neighbors. Therefore, we can add the additional attribute when we add our neighbors. We need to cast the value as Boolean, as this is either true or false:

@rpc_public('neighbor.create')
def _neighbor_create(self, ip_address='192.168.177.32',
remote_as=64513, is_route_reflector_client=False):
bgp_neighbor = {}
bgp_neighbor[neighbors.IP_ADDRESS] = str(ip_address)
bgp_neighbor[neighbors.REMOTE_AS] = remote_as
bgp_neighbor[neighbors.IS_ROUTE_REFLECTOR_CLIENT] = bool(is_route_reflector_client)
call('neighbor.create', **bgp_neighbor)
return {}

We can now relaunch our BGP speaker with our own RPC file:

$ sudo ryu-manager mastering_python_networking/Chapter13/chapter13_jsonrpc_1.py ryu/services/protocols/bgp/application.py

Proceed to repeat the initialization process and add the new neighbors with the route-reflector-client option:

$ wsdump.py ws://127.0.0.1:8080/bgp/ws
Press Ctrl+C to quit
> {"jsonrpc": "2.0", "id": 1, "method": "core.start", "params" : {"as_number":1, "router_id":"172.16.1.174"}}
< {"jsonrpc": "2.0", "id": 1, "result": {}}
> {"jsonrpc": "2.0", "id": 1, "method": "neighbor.create", "params": {"ip_address":"172.16.1.109", "remote_as":1, "is_route_reflector_client": "True"}}
< {"jsonrpc": "2.0", "id": 1, "result": {}}
> {"jsonrpc": "2.0", "id": 1, "method": "neighbor.create", "params": {"ip_address":"172.16.1.110", "remote_as":1, "is_route_reflector_client": "True"}}
< {"jsonrpc": "2.0", "id": 1, "result": {}}

We can see the two leaf routers have established the BGP relationship over the loopback interface:

iosv-1#sh ip bgp summary 

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
172.16.1.174 4 1 9 11 32 0 0 00:01:18 1
192.168.0.3 4 1 5 4 32 0 0 00:00:48 1

iosv-1#sh ip bgp summary

Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
172.16.1.174 4 1 9 11 32 0 0 00:01:18 1
192.168.0.3 4 1 5 4 32 0 0 00:00:48 1

This example demonstrates how we can take an example code and make adjustments by reading into the code and the Ryu documentation for the APIs. For more advanced BGP speaker examples, you can check Toshiki Tsuboi's SimpleRouter for Raspberry Pi 2 (https://github.com/ttsubo/simpleRouter), where he uses Raspberry Pi 2 devices and Ryu controller to establish MP-BGP for VPNv4 over external BGP devices. You can also refer to the Ryu-SDN-IP project by Takeshi Tseng (https://github.com/sdnds-tw/Ryu-SDN-IP), where he makes a Ryu version of the SDN-IP project from ONOS.

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

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