PyBirdClient¶
- Learn more about Bird
The API was created in order to communicate with PyBirdBirdServer located at the TRex machine. Using this API the user can do various of bird commands on the Bird process remotely i.e: send and get current bird configuration.
The following snippet using BirdCFGCreator and push new bird config to server
pybird_c = PyBirdClient(ip='localhost', port=4509)
pybird_c.connect()
pybird_c.acquire()
bird_cfg = BirdCFGCreator()
bgp_data1 = """
local 1.1.1.3 as 65000;
neighbor 1.1.1.1 as 65000;
ipv4 {
import all;
export all;
};"""
bgp_data2 = """
local 1.1.2.3 as 65000;
neighbor 1.1.2.1 as 65000;
ipv4 {
import all;
export all;
};"""
bird_cfg.add_protocol(protocol = "bgp", name = "my_bgp1", data = bgp_data1)
bird_cfg.add_protocol(protocol = "bgp", name = "my_bgp2", data = bgp_data2)
bird_cfg.add_route(dst_cidr = "42.42.42.42/32", next_hop = "1.1.1.3")
bird_cfg.add_route(dst_cidr = "42.42.42.43/32", next_hop = "1.1.2.3")
# sending our new config
pybird_c.set_config(new_cfg = bird_cfg.build_config())
# check that our protocols are up
pybird_c.check_protocols_up(['my_bgp1, my_bgp2'])
# exit gracefully
pybird_c.release()
pybird_c.disconnect()
Print current configuration
pybird_c = PyBirdClient(ip='localhost', port=4509)
pybird_c.connect()
pybird_c.acquire()
# getting our current config
cfg = pybird_c.get_config()
print(cfg)
# exit gracefully
pybird_c.release()
pybird_c.disconnect()
PyBirdClient class¶
- class trex.pybird.pybird_zmq_client.PyBirdClient(ip='localhost', port=4509, verbose_level='error', logger=None, sync_timeout=None)[source]¶
- connect()[source]¶
Connect client to PyBird server. Only check versions and open the socket to bird.
- acquire(force=False)[source]¶
Acquire unique “handler” for client. PyBird Server can only acquire 1 client at a time.
- Parameters
force: bool force acquire, will disconnect connected clients. False by default
- Raises
ConnectionExceptionin case of error
- check_protocols_up(protocols_list, timeout=60, poll_rate=1, verbose=False)[source]¶
Query, waiting for all the bird protocols in ‘protocols’ list. In case bird protocols are still down after ‘timeout’ seconds, an exception will be raised.
usage example:
check_protocols_up(['bgp1', 'rip1', 'rip2'])
- Parameters
- protocols: list
list of all protocols names the new bird node will be followed by. notice the names should be exactly as they appear in bird configuration
- timeout: int
total time waiting for bird protocols
- poll_rate: int
polling rate for bird protocols check
- verbose: bool
True/False for verbose mode
- Raises
Exceptionin case of any error
- set_empty_config()[source]¶
Command, setting the minimal bird configuration with no routes and no routing protocols.
- set_config(new_cfg)[source]¶
Command, set the given config string as the new bird configuration.
- Parameters
- new_cfg: string
valid bird cfg as a string
- Raises
ConnectionErrorin case client is not connected