Examples to show the use of BIRD Internet Routing Daemon (BIRD) Suite in NeST

This directory contains the examples to demonstrate how BIRD Internet Routing Daemon (BIRD) suite can be used for emulating dynamic routing in NeST.

IMPORTANT: BIRD module is not installed by default in Linux. Hence, before running this program, install the BIRD module as explained below (ignore if BIRD is already installed).

BIRD can be obtained from your Linux distribution packages. For Ubuntu, run:

sudo apt install bird

1. bird-ospf-point-to-point-2.py

This program emulates point to point networks that connect two hosts h1 and h2 via a router r1. Five ping packets are sent from h1 to h2, and the success/failure of these packets is reported. It is similar to ah-point-to-point-2.py available in examples/address-helpers, the only difference is that we use Open Shortest Path First (OSPF), a dynamic routing protocol, instead of manually configuring the routes. This program uses OSPF from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing. A new package called RoutingHelper is imported in this program. The routing logs are written to files in a dedicated logs directory.

Source code

 1# SPDX-License-Identifier: GPL-2.0-only
 2# Copyright (c) 2019-2023 NITK Surathkal
 3
 4########################
 5# SHOULD BE RUN AS ROOT
 6########################
 7from nest.topology import *
 8from nest import config
 9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11from nest.routing.routing_helper import RoutingHelper
12
13# This program emulates point to point networks that connect two hosts `h1`
14# and `h2` via a router `r1`. Five ping packets are sent from `h1` to `h2`, and
15# the success/failure of these packets is reported. It is similar to
16# `ah-point-to-point-2.py` available in `examples/address-helpers`, the only
17# difference is that we use Open Shortest Path First (OSPF), a dynamic routing
18# protocol, instead of manually configuring the routes. This program uses OSPF
19# from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing. A new
20# package called `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: BIRD module is not installed by default in Linux. Hence, before
23# running this program, install the BIRD module as explained in the README
24# file in the same directory as this program. Ignore, if BIRD is installed.
25
26##########################################################
27#                   Network Topology                     #
28#                                                        #
29#          5mbit, 5ms -->          5mbit, 5ms -->        #
30#   h1 -------------------- r1 -------------------- h2   #
31#       <-- 10mbit, 100ms        <-- 10mbit, 100ms       #
32#                                                        #
33##########################################################
34
35# Configure the program to use BIRD suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "bird")
38config.set_value("routing_logs", True)  # By default, this is False.
39
40# Create two hosts `h1` and `h2`, and one router `r1`
41h1 = Node("h1")
42h2 = Node("h2")
43r1 = Router("r1")  # Internally, `Router` API enables IP forwarding in `r1`
44
45# Set the IPv4 address for the networks, and not the interfaces.
46# We will use the `AddressHelper` later to assign addresses to the interfaces.
47# Note: this example has two networks, one each on either side of `r1`.
48n1 = Network("192.168.1.0/24")  # network on the left side of `r1`
49n2 = Network("192.168.2.0/24")  # network on the right side of `r1`
50
51# Connect `h1` to `r1` (left side), and then `r1` (right side) to `h2`.
52# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
53# `etr1a` is the first interface at `r1` which connects it with `h1`
54# `etr1b` is the second interface at `r1` which connects it with `h2`
55(eth1, etr1a) = connect(h1, r1, network=n1)
56(etr1b, eth2) = connect(r1, h2, network=n2)
57
58# Assign IPv4 addresses to all the interfaces in the network.
59AddressHelper.assign_addresses()
60
61# Set the link attributes: `h1` --> `r1` --> `h2`
62eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
63etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `h2`
64
65# Set the link attributes: `h2` --> `r1` --> `h1`
66eth2.set_attributes("10mbit", "100ms")  # from `h2` to `r1`
67etr1a.set_attributes("10mbit", "100ms")  # from `r1` to `h1`
68
69# Use OSPF to form routes.
70RoutingHelper(protocol="ospf").populate_routing_tables()
71
72# `Ping` from `h1` to `h2`.
73h1.ping(eth2.address)

2. bird-ospf-point-to-point-3.py

This program emulates point to point networks that connect two hosts h1 and h2 via two routers r1 and r2. Five ping packets are sent from h1 to h2, and the success/failure of these packets is reported. It is similar to ah-point-to-point-3.py available in examples/address-helpers, the only difference is that we use Open Shortest Path First (OSPF), a dynamic routing protocol, instead of manually configuring the routes. This program uses OSPF from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing. A new package called RoutingHelper is imported in this program. The routing logs are written to files in a dedicated logs directory.

Source code

 1# SPDX-License-Identifier: GPL-2.0-only
 2# Copyright (c) 2019-2023 NITK Surathkal
 3
 4########################
 5# SHOULD BE RUN AS ROOT
 6########################
 7from nest.topology import *
 8from nest import config
 9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11from nest.routing.routing_helper import RoutingHelper
12
13# This program emulates point to point networks that connect two hosts `h1` and
14# `h2` via two routers `r1` and `r2`. Five ping packets are sent from `h1` to
15# `h2`, and the success/failure of these packets is reported. It is similar to
16# `ah-point-to-point-3.py` available in `examples/address-helpers`, the only
17# difference is that we use Open Shortest Path First (OSPF), a dynamic routing
18# protocol, instead of manually configuring the routes. This program uses OSPF
19# from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing. A new
20# package called `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: BIRD module is not installed by default in Linux. Hence, before
23# running this program, install the BIRD module as explained in the README
24# file in the same directory as this program. Ignore, if BIRD is installed.
25
26##############################################################################
27#                              Network Topology                              #
28#                                                                            #
29#        5mbit, 5ms -->          5mbit, 5ms -->          5mbit, 5ms -->      #
30# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
31#     <-- 10mbit, 100ms       <-- 10mbit, 100ms       <-- 10mbit, 100ms      #
32#                                                                            #
33##############################################################################
34
35# Configure the program to use BIRD suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "bird")  # `frr` is default in NeST.
38config.set_value("routing_logs", True)  # By default, this is False.
39
40# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`.
41h1 = Node("h1")
42h2 = Node("h2")
43r1 = Router("r1")
44r2 = Router("r2")
45
46# Set the IPv4 address for the networks, and not the interfaces.
47# We will use the `AddressHelper` later to assign addresses to the interfaces.
48# Note: this example has three networks: one on the left of `r1`, second
49# between the two routers, and third on the right of `r2`.
50n1 = Network("192.168.1.0/24")  # network on the left of `r1`
51n2 = Network("192.168.2.0/24")  # network between two routers
52n3 = Network("192.168.3.0/24")  # network on the right of `r2`
53
54# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
55# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
56# `etr1a` is the first interface at `r1` which connects it with `h1`
57# `etr1b` is the second interface at `r1` which connects it with `r2`
58# `etr2a` is the first interface at `r2` which connects it with `r1`
59# `etr2b` is the second interface at `r2` which connects it with `h2`
60(eth1, etr1a) = connect(h1, r1, network=n1)
61(etr1b, etr2a) = connect(r1, r2, network=n2)
62(etr2b, eth2) = connect(r2, h2, network=n3)
63
64# Assign IPv4 addresses to all the interfaces in the network.
65AddressHelper.assign_addresses()
66
67# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
68eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
69etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `r2`
70etr2b.set_attributes("5mbit", "5ms")  # from `r2` to `h2`
71
72# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
73eth2.set_attributes("10mbit", "100ms")  # from `h2` to `r2`
74etr2a.set_attributes("10mbit", "100ms")  # from `r2` to `r1`
75etr1a.set_attributes("10mbit", "100ms")  # from `r1` to `h1`
76
77# Use OSPF to form routes.
78RoutingHelper(protocol="ospf").populate_routing_tables()
79
80# `Ping` from `h1` to `h2`.
81h1.ping(eth2.address)

3. bird-rip-point-to-point-2.py

This program emulates point to point networks that connect two hosts h1 and h2 via a router r1. Five ping packets are sent from h1 to h2, and the success/failure of these packets is reported. It is similar to ah-point-to-point-2.py available in examples/address-helpers, the only difference is that we use Routing Information Protocol (RIP), a dynamic routing protocol, instead of manually configuring the routes. This program uses RIP from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing. A new package called RoutingHelper is imported in this program. The routing logs are written to files in a dedicated logs directory.

Source code

 1# SPDX-License-Identifier: GPL-2.0-only
 2# Copyright (c) 2019-2023 NITK Surathkal
 3
 4########################
 5# SHOULD BE RUN AS ROOT
 6########################
 7from nest.topology import *
 8from nest import config
 9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11from nest.routing.routing_helper import RoutingHelper
12
13# This program emulates point to point networks that connect two hosts `h1`
14# and `h2` via a router `r1`. Five ping packets are sent from `h1` to `h2`,
15# and the success/failure of these packets is reported. This program is
16# similar to `ah-point-to-point-2.py` available in `examples/address-helpers`
17# , the only difference is that we use Routing Information Protocol (RIP),
18# a dynamic routing protocol, instead of manually configuring the routes. This
19# program uses RIP from BIRD Internet Routing Daemon (BIRD) suite for dynamic
20# routing. A new package called `RoutingHelper` is imported in this program
21# (Line 11 above).
22#
23# IMPORTANT: BIRD module is not installed by default in Linux. Hence, before
24# running this program, install the BIRD module as explained in the README
25# file in the same directory as this program. Ignore, if BIRD is installed.
26
27##########################################################
28#                   Network Topology                     #
29#                                                        #
30#          5mbit, 5ms -->          5mbit, 5ms -->        #
31#   h1 -------------------- r1 -------------------- h2   #
32#       <-- 10mbit, 100ms        <-- 10mbit, 100ms       #
33#                                                        #
34##########################################################
35
36# Configure the program to use BIRD suite and enable routing logs.
37# Routing logs are written to files in a dedicated `logs` directory.
38config.set_value("routing_suite", "bird")
39config.set_value("routing_logs", True)  # By default, this is False.
40
41# Create two hosts `h1` and `h2`, and one router `r1`
42h1 = Node("h1")
43h2 = Node("h2")
44r1 = Router("r1")  # Internally, `Router` API enables IP forwarding in `r1`
45
46# Set the IPv4 address for the networks, and not the interfaces.
47# We will use the `AddressHelper` later to assign addresses to the interfaces.
48# Note: this example has two networks, one each on either side of `r1`.
49n1 = Network("192.168.1.0/24")  # network on the left side of `r1`
50n2 = Network("192.168.2.0/24")  # network on the right side of `r1`
51
52# Connect `h1` to `r1` (left side), and then `r1` (right side) to `h2`.
53# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
54# `etr1a` is the first interface at `r1` which connects it with `h1`
55# `etr1b` is the second interface at `r1` which connects it with `h2`
56(eth1, etr1a) = connect(h1, r1, network=n1)
57(etr1b, eth2) = connect(r1, h2, network=n2)
58
59# Assign IPv4 addresses to all the interfaces in the network.
60AddressHelper.assign_addresses()
61
62# Set the link attributes: `h1` --> `r1` --> `h2`
63eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
64etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `h2`
65
66# Set the link attributes: `h2` --> `r1` --> `h1`
67eth2.set_attributes("10mbit", "100ms")  # from `h2` to `r1`
68etr1a.set_attributes("10mbit", "100ms")  # from `r1` to `h1`
69
70# Use RIP to form routes.
71RoutingHelper(protocol="rip").populate_routing_tables()
72
73# `Ping` from `h1` to `h2`.
74h1.ping(eth2.address)

4. bird-rip-point-to-point-3.py

This program emulates point to point networks that connect two hosts h1 and h2 via two routers r1 and r2. Five ping packets are sent from h1 to h2, and the success/failure of these packets is reported. It is similar to ah-point-to-point-3.py available in examples/address-helpers, the only difference is that we use Routing Information Protocol (RIP), a dynamic routing protocol, instead of manually configuring the routes. This program uses RIP from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing. A new package called RoutingHelper is imported in this program. The routing logs are written to files in a dedicated logs directory.

Source code

 1# SPDX-License-Identifier: GPL-2.0-only
 2# Copyright (c) 2019-2023 NITK Surathkal
 3
 4########################
 5# SHOULD BE RUN AS ROOT
 6########################
 7from nest.topology import *
 8from nest import config
 9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11from nest.routing.routing_helper import RoutingHelper
12
13# This program emulates point to point networks that connect two hosts `h1` and
14# `h2` via two routers `r1` and `r2`. Five ping packets are sent from `h1` to
15# `h2`, and the success/failure of these packets is reported. It is similar to
16# `ah-point-to-point-3.py` available in `examples/address-helpers`, the only
17# difference is that we use Routing Information Protocol (RIP), a dynamic
18# routing protocol, instead of manually configuring the routes. This program
19# uses RIP from BIRD Internet Routing Daemon (BIRD) suite for dynamic routing.
20# A new package called `RoutingHelper` is imported in this program
21# (Line 11 above).
22#
23# IMPORTANT: BIRD module is not installed by default in Linux. Hence, before
24# running this program, install the BIRD module as explained in the README
25# file in the same directory as this program. Ignore, if BIRD is installed.
26
27##############################################################################
28#                              Network Topology                              #
29#                                                                            #
30#        5mbit, 5ms -->          5mbit, 5ms -->          5mbit, 5ms -->      #
31# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
32#     <-- 10mbit, 100ms       <-- 10mbit, 100ms       <-- 10mbit, 100ms      #
33#                                                                            #
34##############################################################################
35
36# Configure the program to use BIRD suite and enable routing logs.
37# Routing logs are written to files in a dedicated `logs` directory.
38config.set_value("routing_suite", "bird")  # `frr` is default in NeST.
39config.set_value("routing_logs", True)  # By default, this is False.
40
41# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`.
42h1 = Node("h1")
43h2 = Node("h2")
44r1 = Router("r1")
45r2 = Router("r2")
46
47# Set the IPv4 address for the networks, and not the interfaces.
48# We will use the `AddressHelper` later to assign addresses to the interfaces.
49# Note: this example has three networks: one on the left of `r1`, second
50# between the two routers, and third on the right of `r2`.
51n1 = Network("192.168.1.0/24")  # network on the left of `r1`
52n2 = Network("192.168.2.0/24")  # network between two routers
53n3 = Network("192.168.3.0/24")  # network on the right of `r2`
54
55# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
56# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
57# `etr1a` is the first interface at `r1` which connects it with `h1`
58# `etr1b` is the second interface at `r1` which connects it with `r2`
59# `etr2a` is the first interface at `r2` which connects it with `r1`
60# `etr2b` is the second interface at `r2` which connects it with `h2`
61(eth1, etr1a) = connect(h1, r1, network=n1)
62(etr1b, etr2a) = connect(r1, r2, network=n2)
63(etr2b, eth2) = connect(r2, h2, network=n3)
64
65# Assign IPv4 addresses to all the interfaces in the network.
66AddressHelper.assign_addresses()
67
68# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
69eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
70etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `r2`
71etr2b.set_attributes("5mbit", "5ms")  # from `r2` to `h2`
72
73# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
74eth2.set_attributes("10mbit", "100ms")  # from `h2` to `r2`
75etr2a.set_attributes("10mbit", "100ms")  # from `r2` to `r1`
76etr1a.set_attributes("10mbit", "100ms")  # from `r1` to `h1`
77
78# Use RIP to form routes.
79RoutingHelper(protocol="rip").populate_routing_tables()
80
81# `Ping` from `h1` to `h2`.
82h1.ping(eth2.address)

Note: The above examples can be modified to work with IPv6 addressing by changing the IPv4 subnets to IPv6 subnets. Replace IPv4 subnets 192.168.1.0/24, 192.168.2.0/24 and 192.168.13.0/24 by IPv6 subnets 2001:1::/122, 2001:2::/122 and 2001:3::/122, respectively.