Examples to demonstrate the usage of Free Range Routing (FRR) Suite in NeST

This directory contains the examples to demonstrate how Free Range Routing (FRR) suite can be used for emulating dynamic routing in NeST.

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

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

(Credits: these steps are taken from this link: https://deb.frrouting.org/)

sudo apt install curl

# Add GPG key
curl -s https://deb.frrouting.org/frr/keys.asc | sudo apt-key add -

# Possible values for FRRVER: frr-6 frr-7 frr-8 frr-stable
# frr-stable will be the latest official stable release
FRRVER="frr-stable"
echo deb https://deb.frrouting.org/frr $(lsb_release -s -c) $FRRVER | sudo tee -a /etc/apt/sources.list.d/frr.list

# Update and install FRR
sudo apt update
sudo apt install frr frr-pythontools

Edit /etc/frr/daemons with an editor using sudo and turn on ospfd, ospf6d, ripd, ripngd and isisd (by default they are disabled):

ospfd=yes
ospf6d=yes
ripd=yes
ripngd=yes
isisd=yes

1. frr-isis-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. This program is similar to ah-point-to-point-2.py available in examples/address-helpers, the only difference is that we use Intermediate System to Intermediate System (ISIS), a dynamic routing protocol, instead of manually configuring the routes. This program uses ISIS from Free Range Routing (FRR) 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-2022 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 a router `r1`. Five ping packets are sent from `h1` to `h2`, and the
15# success/failure of these packets is reported. This program is similar to
16# `ah-point-to-point-2.py` available in `examples/address-helpers`, the only
17# difference is that we use Intermediate System to Intermediate System (ISIS),
18# a dynamic routing protocol, instead of manually configuring the routes. This
19# program uses ISIS from Free Range Routing (FRR) suite for dynamic routing. A
20# new package called `RoutingHelper` is imported in this program (Line 11
21# above).
22#
23# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
24# running this program, install the FRR module as explained in the README
25# file in the same directory as this program. Ignore, if FRR 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 FRR suite and enable routing logs.
37# Routing logs are written to files in a dedicated `logs` directory.
38config.set_value("routing_suite", "frr")  # `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 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 ISIS to form routes.
71RoutingHelper(protocol="isis").populate_routing_tables()
72
73# `Ping` from `h1` to `h2`.
74h1.ping(eth2.address)

2. frr-isis-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 Intermediate System to Intermediate System (ISIS), a dynamic routing protocol, instead of manually configuring the routes. This program uses ISIS from Free Range Routing (FRR) 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-2022 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 Intermediate System to Intermediate System (ISIS),
18# a dynamic routing protocol, instead of manually configuring the routes. This
19# program uses ISIS from Free Range Routing (FRR) suite for dynamic routing. A
20# new package called `RoutingHelper` is imported in this program (Line 11
21# above).
22#
23# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
24# running this program, install the FRR module as explained in the README
25# file in the same directory as this program. Ignore, if FRR 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 FRR suite and enable routing logs.
37# Routing logs are written to files in a dedicated `logs` directory.
38config.set_value("routing_suite", "frr")  # `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 ISIS to form routes.
79RoutingHelper(protocol="isis").populate_routing_tables()
80
81# `Ping` from `h1` to `h2`.
82h1.ping(eth2.address)

3. frr-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 Free Range Routing (FRR) 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-2022 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 Free Range Routing (FRR) suite for dynamic routing. A new package called
20# `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
23# running this program, install the FRR module as explained in the README
24# file in the same directory as this program. Ignore, if FRR 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 FRR suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "frr")  # `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 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)

4. frr-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 Free Range Routing (FRR) 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-2022 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 Free Range Routing (FRR) suite for dynamic routing. A new package called
20# `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
23# running this program, install the FRR module as explained in the README
24# file in the same directory as this program. Ignore, if FRR 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 FRR suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "frr")  # `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)

5. frr-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 Free Range Routing (FRR) 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-2022 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 Routing Information Protocol (RIP), a dynamic
18# routing protocol, instead of manually configuring the routes. This program
19# uses RIP from Free Range Routing (FRR) suite for dynamic routing. A new
20# package called `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
23# running this program, install the FRR module as explained in the README
24# file in the same directory as this program. Ignore, if FRR 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 FRR suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "frr")  # `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 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 RIP to form routes.
70RoutingHelper(protocol="rip").populate_routing_tables()
71
72# `Ping` from `h1` to `h2`.
73h1.ping(eth2.address)

6. frr-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 Free Range Routing (FRR) 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-2022 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 Free Range Routing (FRR) suite for dynamic routing. A new
20# package called `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
23# running this program, install the FRR module as explained in the README
24# file in the same directory as this program. Ignore, if FRR 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 FRR suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "frr")  # `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 RIP to form routes.
78RoutingHelper(protocol="rip").populate_routing_tables()
79
80# `Ping` from `h1` to `h2`.
81h1.ping(eth2.address)

7. frr-rip-point-to-point-multi-address.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 frr-rip-point-to-point-3.py available in examples/routing/frr, the only difference is that we assign both IPv4 and IPv6 addresses to the interfaces. This program uses RIP from FRR routing 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-2022 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# `frr-rip-point-to-point-3.py` available in `examples/routing/frr`, the only
17# difference is that we assign both IPv4 and IPv6 addresses to the interfaces.
18# This program uses RIP from FRR routing suite for dynamic routing. A new
19# package called `RoutingHelper` is imported in this program (Line 11 above).
20#
21# IMPORTANT: FRR module is not installed by default in Linux. Hence, before
22# running this program, install the FRR module as explained in the README
23# file in the same directory as this program. Ignore, if FRR is installed.
24
25##############################################################################
26#                              Network Topology                              #
27#                                                                            #
28#        5mbit, 5ms -->          5mbit, 5ms -->          5mbit, 5ms -->      #
29# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
30#     <-- 10mbit, 100ms       <-- 10mbit, 100ms       <-- 10mbit, 100ms      #
31#                                                                            #
32##############################################################################
33
34# Configure the program to use FRR suite and enable routing logs.
35# Routing logs are written to files in a dedicated `logs` directory.
36config.set_value("routing_suite", "frr")  # `frr` is default in NeST.
37config.set_value("routing_logs", True)  # By default, this is False.
38
39# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`.
40h1 = Node("h1")
41h2 = Node("h2")
42r1 = Router("r1")
43r2 = Router("r2")
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 three networks: one on the left of `r1`, second
48# between the two routers, and third on the right of `r2`.
49n1 = Network("192.168.1.0/24")  # network on the left of `r1`
50n2 = Network("192.168.2.0/24")  # network between two routers
51n3 = Network("192.168.3.0/24")  # network on the right of `r2`
52
53# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
54# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
55# `etr1a` is the first interface at `r1` which connects it with `h1`
56# `etr1b` is the second interface at `r1` which connects it with `r2`
57# `etr2a` is the first interface at `r2` which connects it with `r1`
58# `etr2b` is the second interface at `r2` which connects it with `h2`
59(eth1, etr1a) = connect(h1, r1, network=n1)
60(etr1b, etr2a) = connect(r1, r2, network=n2)
61(etr2b, eth2) = connect(r2, h2, network=n3)
62
63# Assign IPv4 addresses to all the interfaces in the network.
64AddressHelper.assign_addresses()
65
66# Note: this example has three networks: one on the left of `r1`, second
67# between the two routers, and third on the right of `r2`.
68# Assign IPv6 addresses to interfaces in the network which is on the left of
69# `r1`.
70eth1.add_address("2001::1:1/122")
71etr1a.add_address("2001::1:2/122")
72
73# Add IPv6 addresses to interfaces in the network which is between `r1`
74#  and `r2`
75etr1b.add_address("2001::2:1/122")
76etr2a.add_address("2001::2:2/122")
77
78# Assign IPv6 addresses to interfaces in the network which is on the right of
79# `r2`.
80etr2b.add_address("2001::3:1/122")
81eth2.add_address("2001::3:2/122")
82
83# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
84eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
85etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `r2`
86etr2b.set_attributes("5mbit", "5ms")  # from `r2` to `h2`
87
88# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
89eth2.set_attributes("10mbit", "100ms")  # from `h2` to `r2`
90etr2a.set_attributes("10mbit", "100ms")  # from `r2` to `r1`
91etr1a.set_attributes("10mbit", "100ms")  # from `r1` to `h1`
92
93# Use RIP to form routes.
94RoutingHelper(protocol="rip").populate_routing_tables()
95RoutingHelper(protocol="rip", ipv6_routing=True).populate_routing_tables()
96
97# `Ping` from `h1` to `h2`.
98h1.ping(eth2.get_address(True, False, False))  # IPv4
99h1.ping(eth2.get_address(False, True, False))  # IPv6

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.