Examples to demonstrate the usage of Quagga Routing Suite in NeST¶
This directory contains the examples to demonstrate how Quagga Routing Suite
can be used for emulating dynamic routing in NeST
.
IMPORTANT
: Quagga module is not installed by default in Linux. Hence, before
running this program, install the Quagga module as explained below (ignore if
quagga is already installed).
Quagga can be obtained from your Linux distribution packages. For Ubuntu, run:
sudo apt install quagga quagga-doc
Edit /etc/quagga/daemons
with an editor using sudo
and turn on zebra
,
ospfd
, ospf6d
, ripd
, ripngd
and isisd
(by default they are disabled):
zebra=yes
ospfd=yes
ospf6d=yes
ripd=yes
ripngd=yes
isisd=yes
If the /etc/quagga/daemons
file does not exist, create one and add the
following lines to the file (in the same order as shown below):
zebra=yes
bgpd=no
ospfd=yes
ospf6d=yes
ripd=yes
ripngd=yes
isisd=yes
babeld=no
Border Gateway Protocol (BGP) and Babel routing algorithms are not yet supported in NeST.
Note
: Ensure that a quagga owned directory named ‘quagga’ exists under
/run
. If it does not exist, then use the following commands:
sudo mkdir /run/quagga
sudo chown quagga /run/quagga
1. quagga-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 Quagga 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.
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. 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 Quagga routing suite for dynamic routing. A new
20# package called `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
23# running this program, install the Quagga module as explained in the README
24# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "quagga") # `quagga` 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 ISIS to form routes.
70RoutingHelper(protocol="isis").populate_routing_tables()
71
72# `Ping` from `h1` to `h2`.
73h1.ping(eth2.address)
2. quagga-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 Quagga 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.
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 Quagga routing suite for dynamic routing. A new
20# package called `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
23# running this program, install the Quagga module as explained in the README
24# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "quagga") # `quagga` 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 ISIS to form routes.
78RoutingHelper(protocol="isis").populate_routing_tables()
79
80# `Ping` from `h1` to `h2`.
81h1.ping(eth2.address)
3. quagga-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 Quagga 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.
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`,
15# and 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 Quagga routing suite for dynamic routing. A new package called
20# `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
23# running this program, install the Quagga module as explained in the README
24# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "quagga") # `quagga` 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. quagga-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 Quagga 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.
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 Quagga routing suite for dynamic routing. A new package called
20# `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
23# running this program, install the Quagga module as explained in the README
24# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "quagga") # `quagga` 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. quagga-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 Quagga 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.
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`,
15# and 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 Quagga routing suite for dynamic routing. A new package called
20# `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
23# running this program, install the Quagga module as explained in the README
24# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "quagga") # `quagga` 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. quagga-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 Quagga 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.
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 Quagga routing suite for dynamic routing. A new package called
20# `RoutingHelper` is imported in this program (Line 11 above).
21#
22# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
23# running this program, install the Quagga module as explained in the README
24# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
36# Routing logs are written to files in a dedicated `logs` directory.
37config.set_value("routing_suite", "quagga") # `quagga` 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. quagga-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
quagga-rip-point-to-point-3.py
available in examples/routing/quagga
, the
only difference is that we assign both IPv4 and IPv6 addresses to the
interfaces. This program uses RIP from Quagga 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.
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# `quagga-rip-point-to-point-3.py` available in `examples/routing/quagga`, the only
17# difference is that we assign both IPv4 and IPv6 addresses to the interfaces.
18# This program uses RIP from Quagga routing suite for dynamic routing. A new
19# package called `RoutingHelper` is imported in this program (Line 11 above).
20#
21# IMPORTANT: Quagga module is not installed by default in Linux. Hence, before
22# running this program, install the Quagga module as explained in the README
23# file in the same directory as this program. Ignore, if Quagga 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 Quagga routing suite and enable routing logs.
35# Routing logs are written to files in a dedicated `logs` directory.
36config.set_value("routing_suite", "quagga") # `quagga` 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.