Examples to demonstrate how to generate TCP traffic in NeST¶
This directory contains the following examples to understand how TCP traffic
can be generated in NeST
. Flow
API is used in these examples to configure
flows between a pair of hosts.
IMPORTANT
Note 1: The third example listed below, which demonstrates how to disable
offloads in NeST, requires ethtool
to be pre-installed in your machine.
It can be installed on debian based systems as:
sudo apt install ethtool
1. dctcp-point-to-point-3.py¶
This program emulates point to point networks that connect two hosts h1
and h2
via two switches s1
and s2
. This program is similar to
udp-point-to-point-3.py
in examples/udp
. One DCTCP flow
is configured from h1
to h2
. The links between h1
to s1
and between
s2
to h2
are edge links. The link between s1
and s2
is the bottleneck
link with lesser bandwidth and higher propagation delays. codel
queue
discipline is enabled on the link from s1
to s2
, but not from s2
to
s1
because data packets flow in one direction only (h1
to h2
) in this
example.
This program runs for 200 seconds and creates a new directory called
dctcp-point-to-point-3(date-timestamp)_dump
. It contains a README
which
provides details about the sub-directories and files within this directory.
See the plots in netperf
, ping
and ss
sub-directories for this program.
1# SPDX-License-Identifier: GPL-2.0-only
2# Copyright (c) 2022-2023 NITK Surathkal
3
4########################
5# SHOULD BE RUN AS ROOT
6########################
7from nest.topology import *
8from nest.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12
13# This program emulates point to point networks that connect two hosts `h1`
14# and `h2` via two switches `s1` and `s2`. This program is similar to
15# `udp-point-to-point-3.py` in `examples/udp`. One DCTCP flow
16# is configured from `h1` to `h2`. The links between `h1` to `s1` and between
17# `s2` to `h2` are edge links. The link between `s1` and `s2` is the bottleneck
18# link with lesser bandwidth and higher propagation delays. `codel` queue
19# discipline is enabled on the link from `s1` to `s2`, but not from `s2` to
20# `s1` because data packets flow in one direction only (`h1` to `h2`) in this
21# example.
22
23##############################################################################
24# Network Topology #
25# #
26# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
27# h1 -------------------- s1 -------------------- s2 -------------------- h2 #
28# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
29# #
30##############################################################################
31
32# This program runs for 200 seconds and creates a new directory called
33# `dctcp-point-to-point-3(date-timestamp)_dump`. It contains a `README` which
34# provides details about the sub-directories and files within this directory.
35# See the plots in `netperf`, `ping` and `ss` sub-directories for this program.
36
37# Create two hosts `h1` and `h2`, and two switches `s1` and `s2`
38s1 = Switch("s1")
39s2 = Switch("s2")
40
41h1 = Node("h1")
42h2 = Node("h2")
43
44# Set the IPv4 address for the network, and not the interfaces.
45# We will use the `AddressHelper` later to assign addresses to the interfaces.
46n1 = Network("192.168.1.0/24")
47
48# Connect `h1` to `s1`, `s1` to `s2`, and then `s2` to `h2`
49# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
50# `ets1a` is the first interface at `s1` which connects it with `h1`
51# `ets1b` is the second interface at `s1` which connects it with `s2`
52# `ets2a` is the first interface at `s2` which connects it with `s1`
53# `ets2b` is the second interface at `s2` which connects it with `h2`
54(eth1, ets1a) = connect(h1, s1, network=n1)
55(ets1b, ets2a) = connect(s1, s2, network=n1)
56(ets2b, eth2) = connect(s2, h2, network=n1)
57
58# Assign IPv4 addresses to all the interfaces in the network.
59AddressHelper.assign_addresses()
60
61# Configure the parameters of `codel` qdisc to enable step marking with ECN,
62# which is essential for DCTCP. For more details about `codel` in Linux,
63# use this command on CLI: `man tc-codel`.
64qdisc = "codel"
65codel_parameters = {
66 "limit": "1000", # set the queue size to 1000 packets (default is 1000)
67 "target": "10000ms", # set the target queue delay to 10000ms (default is 5ms)
68 "interval": "100ms", # set the interval value to 100ms (default is 100ms)
69 "ce_threshold": "40ms", # ce_threshold = (17% of queue size in pckts * size of each packet * 8) / (bandwidth)
70 "ecn": "", # enables ecn marking for codel
71}
72
73# Set the link attributes: `h1` --> `s1` --> `s2` --> `h2`
74# Note: we enable `codel` queue discipline on the link from `s1` to `s2`.
75eth1.set_attributes("1000mbit", "1ms") # from `h1` to `s1`
76ets1b.set_attributes("10mbit", "10ms", qdisc, **codel_parameters) # from `s1` to `s2`
77ets2b.set_attributes("1000mbit", "1ms") # from 's2' to 'h2
78
79# Set the link attributes: `h2' --> `s2` --> `s1` --> `h1`
80eth2.set_attributes("1000mbit", "1ms") # from 'h2' to `s2`
81ets2a.set_attributes("10mbit", "10ms") # from `s2` to `s1`
82ets1a.set_attributes("1000mbit", "1ms") # from `s1` to `h1`
83
84# Set up an Experiment. This API takes the name of the experiment as a string.
85exp = Experiment("dctcp-point-to-point-3")
86
87# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
88# The `Flow` API takes in the source node, destination node, destination IP
89# address, start and stop time of the flow, and the total number of flows.
90# In this program, start time is 0 seconds, stop time is 200 seconds and the
91# number of flows is 1.
92flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
93
94# Configure the TCP parameter to enable ECN by setting the parameter value to 2
95# Note: DCTCP requires devices in a network to support ECN, hence we enable ECN
96# on them.
97h1.configure_tcp_param("ecn", "2")
98s1.configure_tcp_param("ecn", "2")
99s2.configure_tcp_param("ecn", "2")
100h2.configure_tcp_param("ecn", "2")
101
102# Use `flow1` as a DCTCP flow.
103exp.add_tcp_flow(flow1, "dctcp")
104
105# Enable collection of stats for `codel` qdisc installed on `ets1b` interface,
106# connecting `s1` to `s2`.
107exp.require_qdisc_stats(ets1b)
108
109# Run the experiment
110exp.run()
2. tcp-bbr-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
. This program is similar to
udp-point-to-point-3.py
in examples/udp
. Instead of UDP, one TCP BBR flow
is configured from h1
to h2
. The links between h1
to r1
and between
r2
to h2
are edge links. The link between r1
and r2
is the bottleneck
link with lesser bandwidth and higher propagation delays. pfifo
queue
discipline is enabled on the link from r1
to r2
, but not from r2
to
r1
because data packets flow in one direction only (h1
to h2
) in this
example. Address helper is used in this program to assign IPv4 addresses.
This program runs for 200 seconds and creates a new directory called
tcp-bbr-point-to-point-3(date-timestamp)_dump
. It contains a README
which
provides details about the sub-directories and files within this directory.
See the plots in netperf
, ping
and ss
sub-directories for this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `udp-point-to-point-3.py` in `examples/udp`. Instead of UDP, one TCP BBR flow
15# is configured from `h1` to `h2`. The links between `h1` to `r1` and between
16# `r2` to `h2` are edge links. The link between `r1` and `r2` is the bottleneck
17# link with lesser bandwidth and higher propagation delays. `pfifo` queue
18# discipline is enabled on the link from `r1` to `r2`, but not from `r2` to
19# `r1` because data packets flow in one direction only (`h1` to `h2`) in this
20# example.
21
22##############################################################################
23# Network Topology #
24# #
25# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
26# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
27# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
28# #
29##############################################################################
30
31# This program runs for 200 seconds and creates a new directory called
32# `tcp-bbr-point-to-point-3(date-timestamp)_dump`. It contains a `README` which
33# provides details about the sub-directories and files within this directory.
34# See the plots in `netperf`, `ping` and `ss` sub-directories for this program.
35
36# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
37h1 = Node("h1")
38h2 = Node("h2")
39r1 = Router("r1")
40r2 = Router("r2")
41
42# Set the IPv4 address for the networks, and not the interfaces.
43# We will use the `AddressHelper` later to assign addresses to the interfaces.
44n1 = Network("192.168.1.0/24") # network on the left of `r1`
45n2 = Network("192.168.2.0/24") # network between two routers
46n3 = Network("192.168.3.0/24") # network on the right of `r2`
47
48# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
49# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
50# `etr1a` is the first interface at `r1` which connects it with `h1`
51# `etr1b` is the second interface at `r1` which connects it with `r2`
52# `etr2a` is the first interface at `r2` which connects it with `r1`
53# `etr2b` is the second interface at `r2` which connects it with `h2`
54(eth1, etr1a) = connect(h1, r1, network=n1)
55(etr1b, etr2a) = connect(r1, r2, network=n2)
56(etr2b, eth2) = connect(r2, h2, network=n3)
57
58# Assign IPv4 addresses to all the interfaces in the network.
59AddressHelper.assign_addresses()
60
61# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
62# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
63# Default configuration of `pfifo` in Linux is used. For more details about
64# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
65eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
66etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
67etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
68
69# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
70eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
71etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
72etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
73
74# Set default routes in `h1` and `h2`. Additionally, set default routes in
75# `r1` and `r2` so that the packets that cannot be forwarded based on the
76# entries in their routing table are sent via a default interface.
77h1.add_route("DEFAULT", eth1)
78h2.add_route("DEFAULT", eth2)
79r1.add_route("DEFAULT", etr1b)
80r2.add_route("DEFAULT", etr2a)
81
82# Set up an Experiment. This API takes the name of the experiment as a string.
83exp = Experiment("tcp-bbr-point-to-point-3")
84
85# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
86# The `Flow` API takes in the source node, destination node, destination IP
87# address, start and stop time of the flow, and the total number of flows.
88# In this program, start time is 0 seconds, stop time is 200 seconds and the
89# number of flows is 1.
90flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
91
92# Use `flow1` as a TCP BBR flow.
93exp.add_tcp_flow(flow1, "bbr")
94
95# Run the experiment
96exp.run()
3. tcp-cubic-parameters-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
. This program is similar to
tcp-bbr-point-to-point-3.py
in examples/tcp
. Instead of TCP BBR
algorithm, TCP CUBIC algorithm is used for congestion control. This example
demonstrates how to customize the beta parameter for TCP CUBIC algorithm.
This program runs for 200 seconds and creates two new directories called
tcp-cubic-parameters-point-to-point-3-default(date-timestamp)_dump
and tcp-cubic-parameters-point-to-point-3-beta=1000(date-timestamp)_dump
.
They contain a README
which provides details about the sub-directories
and files within this directory. See the plots in netperf
, ping
and ss
sub-directories for this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `tcp-bbr-point-to-point-3.py` in `examples/tcp`. Instead of TCP BBR
15# algorithm, TCP CUBIC algorithm is used for congestion control. This example
16# demonstrates how to customize the beta parameter for TCP CUBIC algorithm.
17
18##############################################################################
19# Network Topology #
20# #
21# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
22# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
23# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
24# #
25##############################################################################
26
27# This program runs for 200 seconds and creates two new directories called
28# `tcp-cubic-parameters-point-to-point-3-default(date-timestamp)_dump`
29# and `tcp-cubic-parameters-point-to-point-3-beta=1000(date-timestamp)_dump`.
30# They contain a `README` which provides details about the sub-directories
31# and files within this directory. See the plots in `netperf`, `ping`
32# and `ss` sub-directories for this program.
33
34# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
35h1 = Node("h1")
36h2 = Node("h2")
37r1 = Router("r1")
38r2 = Router("r2")
39
40# Set the IPv4 address for the networks, and not the interfaces.
41# We will use the `AddressHelper` later to assign addresses to the interfaces.
42n1 = Network("192.168.1.0/24") # network on the left of `r1`
43n2 = Network("192.168.2.0/24") # network between two routers
44n3 = Network("192.168.3.0/24") # network on the right of `r2`
45
46# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
47# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
48# `etr1a` is the first interface at `r1` which connects it with `h1`
49# `etr1b` is the second interface at `r1` which connects it with `r2`
50# `etr2a` is the first interface at `r2` which connects it with `r1`
51# `etr2b` is the second interface at `r2` which connects it with `h2`
52(eth1, etr1a) = connect(h1, r1, network=n1)
53(etr1b, etr2a) = connect(r1, r2, network=n2)
54(etr2b, eth2) = connect(r2, h2, network=n3)
55
56# Assign IPv4 addresses to all the interfaces in the network.
57AddressHelper.assign_addresses()
58
59# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
60# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
61# Default configuration of `pfifo` in Linux is used. For more details about
62# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
63eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
64etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
65etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
66
67# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
68eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
69etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
70etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
71
72# Set default routes in `h1` and `h2`. Additionally, set default routes in
73# `r1` and `r2` so that the packets that cannot be forwarded based on the
74# entries in their routing table are sent via a default interface.
75h1.add_route("DEFAULT", eth1)
76h2.add_route("DEFAULT", eth2)
77r1.add_route("DEFAULT", etr1b)
78r2.add_route("DEFAULT", etr2a)
79
80# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
81# The `Flow` API takes in the source node, destination node, destination IP
82# address, start and stop time of the flow, and the total number of flows.
83# In this program, start time is 0 seconds, stop time is 200 seconds and the
84# number of flows is 1.
85flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
86
87# Set up an Experiment. This API takes the name of the experiment as a string.
88exp1 = Experiment("tcp-cubic-parameters-point-to-point-3-default")
89
90# Use `flow1` as a TCP CUBIC flow.
91# TCP CUBIC is default in Linux, hence no additional setting is required.
92exp1.add_tcp_flow(flow1)
93
94# Set up a second Experiment
95exp2 = Experiment("tcp-cubic-parameters-point-to-point-3-beta=1000")
96
97# Use `flow1` as a TCP CUBIC flow with cubic parameter beta set to 1000
98exp2.configure_tcp_module_params("cubic", beta=1000)
99exp2.add_tcp_flow(flow1)
100
101# Run the experiments
102exp1.run()
103exp2.run()
4. tcp-cubic-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
. This program is similar to
udp-point-to-point-3.py
in examples/udp
. Instead of UDP, one TCP CUBIC
flow is configured from h1
to h2
. The links between h1
to r1
and
between r2
to h2
are edge links. The link between r1
and r2
is the
bottleneck link with lesser bandwidth and higher propagation delays. pfifo
queue discipline is enabled on the link from r1
to r2
, but not from r2
to r1
because data packets flow in one direction only (h1
to h2
) in
this example. Address helper is used in this program to assign IPv4 addresses.
This program runs for 200 seconds and creates a new directory called
tcp-cubic-point-to-point-3(date-timestamp)_dump
. It contains a README
which provides details about the sub-directories and files within this
directory. See the plots in netperf
, ping
and ss
sub-directories for
this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `udp-point-to-point-3.py` in `examples/udp`. Instead of UDP, one TCP CUBIC
15# flow is configured from `h1` to `h2`. The links between `h1` to `r1` and
16# between `r2` to `h2` are edge links. The link between `r1` and `r2` is the
17# bottleneck link with lesser bandwidth and higher propagation delays. `pfifo`
18# queue discipline is enabled on the link from `r1` to `r2`, but not from `r2`
19# to `r1` because data packets flow in one direction only (`h1` to `h2`) in
20# this example.
21
22##############################################################################
23# Network Topology #
24# #
25# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
26# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
27# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
28# #
29##############################################################################
30
31# This program runs for 200 seconds and creates a new directory called
32# `tcp-cubic-point-to-point-3(date-timestamp)_dump`. It contains a `README`
33# which provides details about the sub-directories and files within this
34# directory. See the plots in `netperf`, `ping` and `ss` sub-directories for
35# this program.
36
37# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
38h1 = Node("h1")
39h2 = Node("h2")
40r1 = Router("r1")
41r2 = Router("r2")
42
43# Set the IPv4 address for the networks, and not the interfaces.
44# We will use the `AddressHelper` later to assign addresses to the interfaces.
45n1 = Network("192.168.1.0/24") # network on the left of `r1`
46n2 = Network("192.168.2.0/24") # network between two routers
47n3 = Network("192.168.3.0/24") # network on the right of `r2`
48
49# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
50# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
51# `etr1a` is the first interface at `r1` which connects it with `h1`
52# `etr1b` is the second interface at `r1` which connects it with `r2`
53# `etr2a` is the first interface at `r2` which connects it with `r1`
54# `etr2b` is the second interface at `r2` which connects it with `h2`
55(eth1, etr1a) = connect(h1, r1, network=n1)
56(etr1b, etr2a) = connect(r1, r2, network=n2)
57(etr2b, eth2) = connect(r2, h2, network=n3)
58
59# Assign IPv4 addresses to all the interfaces in the network.
60AddressHelper.assign_addresses()
61
62# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
63# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
64# Default configuration of `pfifo` in Linux is used. For more details about
65# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
66eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
67etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
68etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
69
70# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
71eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
72etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
73etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
74
75# Set default routes in `h1` and `h2`. Additionally, set default routes in
76# `r1` and `r2` so that the packets that cannot be forwarded based on the
77# entries in their routing table are sent via a default interface.
78h1.add_route("DEFAULT", eth1)
79h2.add_route("DEFAULT", eth2)
80r1.add_route("DEFAULT", etr1b)
81r2.add_route("DEFAULT", etr2a)
82
83# Set up an Experiment. This API takes the name of the experiment as a string.
84exp = Experiment("tcp-cubic-point-to-point-3")
85
86# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
87# The `Flow` API takes in the source node, destination node, destination IP
88# address, start and stop time of the flow, and the total number of flows.
89# In this program, start time is 0 seconds, stop time is 200 seconds and the
90# number of flows is 1.
91flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
92
93# Use `flow1` as a TCP CUBIC flow.
94# TCP CUBIC is default in Linux, hence no additional setting is required.
95exp.add_tcp_flow(flow1)
96
97# Run the experiment
98exp.run()
5. tcp-cubic-ssr-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
. This program is similar to
tcp-cubic-point-to-point-3.py
in examples/tcp
. This example demonstrates
how to disable and re-enable Slow Start Restart (SSR). By default, SSR is
enabled in Linux kernel.
This program runs for 200 seconds and creates a new directory called
tcp-cubic-ssr-point-to-point-3(date-timestamp)_dump
. It contains a README
which provides details about the sub-directories and files within this
directory. See the plots in netperf
, ping
and ss
sub-directories for
this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `tcp-cubic-point-to-point-3.py` in `examples/tcp`. This example demonstrates
15# how to disable and re-enable Slow Start Restart (SSR). By default, SSR is
16# enabled in Linux kernel.
17
18##############################################################################
19# Network Topology #
20# #
21# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
22# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
23# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
24# #
25##############################################################################
26
27# This program runs for 200 seconds and creates a new directory called
28# `tcp-cubic-ssr-point-to-point-3(date-timestamp)_dump`. It contains a `README`
29# which provides details about the sub-directories and files within this
30# directory. See the plots in `netperf`, `ping` and `ss` sub-directories for
31# this program.
32
33# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
34h1 = Node("h1")
35h2 = Node("h2")
36r1 = Router("r1")
37r2 = Router("r2")
38
39# Set the IPv4 address for the networks, and not the interfaces.
40# We will use the `AddressHelper` later to assign addresses to the interfaces.
41n1 = Network("192.168.1.0/24") # network on the left of `r1`
42n2 = Network("192.168.2.0/24") # network between two routers
43n3 = Network("192.168.3.0/24") # network on the right of `r2`
44
45# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
46# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
47# `etr1a` is the first interface at `r1` which connects it with `h1`
48# `etr1b` is the second interface at `r1` which connects it with `r2`
49# `etr2a` is the first interface at `r2` which connects it with `r1`
50# `etr2b` is the second interface at `r2` which connects it with `h2`
51(eth1, etr1a) = connect(h1, r1, network=n1)
52(etr1b, etr2a) = connect(r1, r2, network=n2)
53(etr2b, eth2) = connect(r2, h2, network=n3)
54
55# Assign IPv4 addresses to all the interfaces in the network.
56AddressHelper.assign_addresses()
57
58# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
59# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
60# Default configuration of `pfifo` in Linux is used. For more details about
61# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
62eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
63etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
64etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
65
66# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
67eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
68etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
69etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
70
71# Set default routes in `h1` and `h2`. Additionally, set default routes in
72# `r1` and `r2` so that the packets that cannot be forwarded based on the
73# entries in their routing table are sent via a default interface.
74h1.add_route("DEFAULT", eth1)
75h2.add_route("DEFAULT", eth2)
76r1.add_route("DEFAULT", etr1b)
77r2.add_route("DEFAULT", etr2a)
78
79# Set up an Experiment. This API takes the name of the experiment as a string.
80exp = Experiment("tcp-cubic-ssr-point-to-point-3")
81
82# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
83# The `Flow` API takes in the source node, destination node, destination IP
84# address, start and stop time of the flow, and the total number of flows.
85# In this program, start time is 0 seconds, stop time is 200 seconds and the
86# number of flows is 1.
87flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
88
89# Configure the TCP parameter to disable SSR by setting the parameter value to 0
90# Note: SSR algorithm works only at the sender. Hence, we disable it only in h1.
91h1.configure_tcp_param("slow_start_after_idle", "0")
92
93# Use `flow1` as a TCP CUBIC flow.
94# TCP CUBIC is default in Linux, hence no additional setting is required.
95exp.add_tcp_flow(flow1)
96
97# Run the experiment
98exp.run()
99
100# Configure the parameter back to its default value
101h1.configure_tcp_param("slow_start_after_idle", "1")
6. tcp-cubic-tfo-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
. This program is similar to
tcp-cubic-point-to-point-3.py
in examples/tcp
. This example demonstrates
how to disable and re-enable TCP Fast Open (TFO). By default, TFO is
enabled in Linux kernel.
This program runs for 200 seconds and creates a new directory called
tcp-cubic-tfo-point-to-point-3(date-timestamp)_dump
. It contains a README
which provides details about the sub-directories and files within this
directory. See the plots in netperf
, ping
and ss
sub-directories for
this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `tcp-cubic-point-to-point-3.py` in `examples/tcp`. This example demonstrates
15# how to disable and re-enable TCP Fast Open (TFO). By default, TFO is
16# enabled in Linux kernel.
17
18##############################################################################
19# Network Topology #
20# #
21# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
22# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
23# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
24# #
25##############################################################################
26
27# This program runs for 200 seconds and creates a new directory called
28# `tcp-cubic-tfo-point-to-point-3(date-timestamp)_dump`. It contains a `README`
29# which provides details about the sub-directories and files within this
30# directory. See the plots in `netperf`, `ping` and `ss` sub-directories for
31# this program.
32
33# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
34h1 = Node("h1")
35h2 = Node("h2")
36r1 = Router("r1")
37r2 = Router("r2")
38
39# Set the IPv4 address for the networks, and not the interfaces.
40# We will use the `AddressHelper` later to assign addresses to the interfaces.
41n1 = Network("192.168.1.0/24") # network on the left of `r1`
42n2 = Network("192.168.2.0/24") # network between two routers
43n3 = Network("192.168.3.0/24") # network on the right of `r2`
44
45# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
46# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
47# `etr1a` is the first interface at `r1` which connects it with `h1`
48# `etr1b` is the second interface at `r1` which connects it with `r2`
49# `etr2a` is the first interface at `r2` which connects it with `r1`
50# `etr2b` is the second interface at `r2` which connects it with `h2`
51(eth1, etr1a) = connect(h1, r1, network=n1)
52(etr1b, etr2a) = connect(r1, r2, network=n2)
53(etr2b, eth2) = connect(r2, h2, network=n3)
54
55# Assign IPv4 addresses to all the interfaces in the network.
56AddressHelper.assign_addresses()
57
58# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
59# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
60# Default configuration of `pfifo` in Linux is used. For more details about
61# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
62eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
63etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
64etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
65
66# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
67eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
68etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
69etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
70
71# Set default routes in `h1` and `h2`. Additionally, set default routes in
72# `r1` and `r2` so that the packets that cannot be forwarded based on the
73# entries in their routing table are sent via a default interface.
74h1.add_route("DEFAULT", eth1)
75h2.add_route("DEFAULT", eth2)
76r1.add_route("DEFAULT", etr1b)
77r2.add_route("DEFAULT", etr2a)
78
79# Set up an Experiment. This API takes the name of the experiment as a string.
80exp = Experiment("tcp-cubic-tfo-point-to-point-3")
81
82# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
83# The `Flow` API takes in the source node, destination node, destination IP
84# address, start and stop time of the flow, and the total number of flows.
85# In this program, start time is 0 seconds, stop time is 200 seconds and the
86# number of flows is 1.
87flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
88
89# Configure the TCP parameter to disable TFO by setting the parameter value to 0
90# Note: TFO is initiated by sender during the packet transfer. Hence, we disable
91# TFO only for h1.
92# TFO can take values 0, 1, 2, 3 in Linux kernel. To disable TFO, set the value
93# to 1. To enable TFO - set it to 1, if your machine is a client; set it to 2,
94# if your machine is a server; set it to 3, if your machine is a client as well
95# as a server.
96h1.configure_tcp_param("fastopen", "0")
97
98# Use `flow1` as a TCP CUBIC flow.
99# TCP CUBIC is default in Linux, hence no additional setting is required.
100exp.add_tcp_flow(flow1)
101
102# Run the experiment
103exp.run()
104
105# Configure the parameter back to its default value
106h1.configure_tcp_param("fastopen", "1")
7. tcp-cubic-wnd-scale-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
. This program is similar to
tcp-cubic-point-to-point-3.py
in examples/tcp
. This example demonstrates
how to disable and re-enable Window Scaling in TCP. By default, Window Scaling
is enabled in Linux kernel.
This program runs for 200 seconds and creates a new directory called
tcp-cubic-wnd-scale-point-to-point-3(date-timestamp)_dump
. It contains
a README
which provides details about the sub-directories and files within
this directory. See the plots in netperf
, ping
and ss
sub-directories
for this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `tcp-cubic-point-to-point-3.py` in `examples/tcp`. This example demonstrates
15# how to disable and re-enable Window Scaling in TCP. By default, Window Scaling
16# is enabled in Linux kernel.
17
18##############################################################################
19# Network Topology #
20# #
21# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
22# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
23# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
24# #
25##############################################################################
26
27# This program runs for 200 seconds and creates a new directory called
28# `tcp-cubic-wnd-scale-point-to-point-3(date-timestamp)_dump`. It contains
29# a `README` which provides details about the sub-directories and files within
30# this directory. See the plots in `netperf`, `ping` and `ss` sub-directories
31# for this program.
32
33# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
34h1 = Node("h1")
35h2 = Node("h2")
36r1 = Router("r1")
37r2 = Router("r2")
38
39# Set the IPv4 address for the networks, and not the interfaces.
40# We will use the `AddressHelper` later to assign addresses to the interfaces.
41n1 = Network("192.168.1.0/24") # network on the left of `r1`
42n2 = Network("192.168.2.0/24") # network between two routers
43n3 = Network("192.168.3.0/24") # network on the right of `r2`
44
45# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
46# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
47# `etr1a` is the first interface at `r1` which connects it with `h1`
48# `etr1b` is the second interface at `r1` which connects it with `r2`
49# `etr2a` is the first interface at `r2` which connects it with `r1`
50# `etr2b` is the second interface at `r2` which connects it with `h2`
51(eth1, etr1a) = connect(h1, r1, network=n1)
52(etr1b, etr2a) = connect(r1, r2, network=n2)
53(etr2b, eth2) = connect(r2, h2, network=n3)
54
55# Assign IPv4 addresses to all the interfaces in the network.
56AddressHelper.assign_addresses()
57
58# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
59# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
60# Default configuration of `pfifo` in Linux is used. For more details about
61# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
62eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
63etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
64etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
65
66# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
67eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
68etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
69etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
70
71# Set default routes in `h1` and `h2`. Additionally, set default routes in
72# `r1` and `r2` so that the packets that cannot be forwarded based on the
73# entries in their routing table are sent via a default interface.
74h1.add_route("DEFAULT", eth1)
75h2.add_route("DEFAULT", eth2)
76r1.add_route("DEFAULT", etr1b)
77r2.add_route("DEFAULT", etr2a)
78
79# Set up an Experiment. This API takes the name of the experiment as a string.
80exp = Experiment("tcp-cubic-wnd-scale-point-to-point-3")
81
82# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
83# The `Flow` API takes in the source node, destination node, destination IP
84# address, start and stop time of the flow, and the total number of flows.
85# In this program, start time is 0 seconds, stop time is 200 seconds and the
86# number of flows is 1.
87flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
88
89# Configure the tcp parameter to disable Window Scaling by setting the
90# parameter value to 0.
91# Note: Window Scaling is set for both sender and reciever during packet
92# transfer.
93h1.configure_tcp_param("window_scaling", "0")
94h2.configure_tcp_param("window_scaling", "0")
95
96# Use `flow1` as a TCP CUBIC flow.
97# TCP CUBIC is default in Linux, hence no additional setting is required.
98exp.add_tcp_flow(flow1)
99
100# Run the experiment
101exp.run()
102
103# Configure the parameter back to its default value.
104h1.configure_tcp_param("window_scaling", "1")
105h2.configure_tcp_param("window_scaling", "1")
8. tcp-offloads-point-to-point.py¶
This program emulates point to point networks that connect two hosts h1
and h2
via two routers r1
and r2
. This program is similar to
tcp-cubic-point-to-point-3.py
. It demonstrates how to disable Generic
Segmentation Offload (GSO), Generic Receive Offload (GRO) and TCP
Segmentation Offload (TSO). By default, these offloads are enabled in the
Linux kernel. Address helper is used in this program to assign IPv4 addresses.
This program runs for 200 seconds and creates a new directory called
tcp-offloads-point-to-point(date-timestamp)_dump
. It contains a README
which provides details about the sub-directories and files within this
directory. See the plots in netperf
, ping
and ss
sub-directories for
this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `tcp-cubic-point-to-point-3.py`. It demonstrates how to disable Generic
15# Segmentation Offload (GSO), Generic Receive Offload (GRO) and TCP
16# Segmentation Offload (TSO). By default, these offloads are enabled in the
17# Linux kernel.
18
19##############################################################################
20# Network Topology #
21# #
22# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
23# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
24# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
25# #
26##############################################################################
27
28# This program runs for 200 seconds and creates a new directory called
29# `tcp-offloads-point-to-point(date-timestamp)_dump`. It contains a `README`
30# which provides details about the sub-directories and files within this
31# directory. See the plots in `netperf`, `ping` and `ss` sub-directories for
32# this program.
33
34# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
35h1 = Node("h1")
36h2 = Node("h2")
37r1 = Router("r1")
38r2 = Router("r2")
39
40# Set the IPv4 address for the networks, and not the interfaces.
41# We will use the `AddressHelper` later to assign addresses to the interfaces.
42n1 = Network("192.168.1.0/24") # network on the left of `r1`
43n2 = Network("192.168.2.0/24") # network between two routers
44n3 = Network("192.168.3.0/24") # network on the right of `r2`
45
46# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
47# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
48# `etr1a` is the first interface at `r1` which connects it with `h1`
49# `etr1b` is the second interface at `r1` which connects it with `r2`
50# `etr2a` is the first interface at `r2` which connects it with `r1`
51# `etr2b` is the second interface at `r2` which connects it with `h2`
52(eth1, etr1a) = connect(h1, r1, network=n1)
53(etr1b, etr2a) = connect(r1, r2, network=n2)
54(etr2b, eth2) = connect(r2, h2, network=n3)
55
56# Assign IPv4 addresses to all the interfaces in the network.
57AddressHelper.assign_addresses()
58
59# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
60# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
61# Default configuration of `pfifo` in Linux is used. For more details about
62# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
63eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
64etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
65etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
66
67# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
68eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
69etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
70etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
71
72# Set default routes in all hosts and routers.
73h1.add_route("DEFAULT", eth1)
74h2.add_route("DEFAULT", eth2)
75r1.add_route("DEFAULT", etr1b)
76r2.add_route("DEFAULT", etr2a)
77
78# Disable GSO, GRO and TSO. For more details about offloads, visit this link:
79# https://www.kernel.org/doc/Documentation/networking/segmentation-offloads.txt
80offload_type = ["gso", "gro", "tso"]
81eth1.disable_offload(offload_type)
82etr1b.disable_offload(offload_type)
83etr2a.disable_offload(offload_type)
84eth2.disable_offload(offload_type)
85
86# Set up an Experiment. This API takes the name of the experiment as a string.
87exp = Experiment("tcp-offloads-point-to-point")
88
89# Configure a flow from `h1` to `h2`.
90flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
91
92# Use `flow1` as a TCP flow. TCP CUBIC is default in Linux.
93exp.add_tcp_flow(flow1)
94
95# Run the experiment
96exp.run()
9. tcp-reno-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
. This program is similar to
udp-point-to-point-3.py
in examples/udp
. Instead of UDP, one Reno flow
is configured from h1
to h2
. The links between h1
to r1
and between
r2
to h2
are edge links. The link between r1
and r2
is the bottleneck
link with lesser bandwidth and higher propagation delays. pfifo
queue
discipline is enabled on the link from r1
to r2
, but not from r2
to
r1
because data packets flow in one direction only (h1
to h2
) in this
example. Address helper is used in this program to assign IPv4 addresses.
This program runs for 200 seconds and creates a new directory called
tcp-reno-point-to-point-3(date-timestamp)_dump
. It contains a README
that
provides details about the sub-directories and files within this directory.
See the plots in netperf
, ping
and ss
sub-directories for this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect two hosts `h1`
13# and `h2` via two routers `r1` and `r2`. This program is similar to
14# `udp-point-to-point-3.py` in `examples/udp`. Instead of UDP, one Reno flow
15# is configured from `h1` to `h2`. The links between `h1` to `r1` and between
16# `r2` to `h2` are edge links. The link between `r1` and `r2` is the bottleneck
17# link with lesser bandwidth and higher propagation delays. `pfifo` queue
18# discipline is enabled on the link from `r1` to `r2`, but not from `r2` to
19# `r1` because data packets flow in one direction only (`h1` to `h2`) in this
20# example.
21
22##############################################################################
23# Network Topology #
24# #
25# 1000mbit, 1ms --> 10mbit, 10ms --> 1000mbit, 1ms --> #
26# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
27# <-- 1000mbit, 1ms <-- 10mbit, 10ms <-- 1000mbit, 1ms #
28# #
29##############################################################################
30
31# This program runs for 200 seconds and creates a new directory called
32# `tcp-reno-point-to-point-3(date-timestamp)_dump`. It contains a `README` that
33# provides details about the sub-directories and files within this directory.
34# See the plots in `netperf`, `ping` and `ss` sub-directories for this program.
35
36# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
37h1 = Node("h1")
38h2 = Node("h2")
39r1 = Router("r1")
40r2 = Router("r2")
41
42# Set the IPv4 address for the networks, and not the interfaces.
43# We will use the `AddressHelper` later to assign addresses to the interfaces.
44n1 = Network("192.168.1.0/24") # network on the left of `r1`
45n2 = Network("192.168.2.0/24") # network between two routers
46n3 = Network("192.168.3.0/24") # network on the right of `r2`
47
48# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
49# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
50# `etr1a` is the first interface at `r1` which connects it with `h1`
51# `etr1b` is the second interface at `r1` which connects it with `r2`
52# `etr2a` is the first interface at `r2` which connects it with `r1`
53# `etr2b` is the second interface at `r2` which connects it with `h2`
54(eth1, etr1a) = connect(h1, r1, network=n1)
55(etr1b, etr2a) = connect(r1, r2, network=n2)
56(etr2b, eth2) = connect(r2, h2, network=n3)
57
58# Assign IPv4 addresses to all the interfaces in the network.
59AddressHelper.assign_addresses()
60
61# Set the link attributes: `h1` --> `r1` --> `r2` --> `h2`
62# Note: we enable `pfifo` queue discipline on the link from `r1` to `r2`.
63# Default configuration of `pfifo` in Linux is used. For more details about
64# `pfifo` in Linux, use this command on CLI: `man tc-pfifo`.
65eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
66etr1b.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
67etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h2`
68
69# Set the link attributes: `h2` --> `r2` --> `r1` --> `h1`
70eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r2`
71etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
72etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
73
74# Set default routes in `h1` and `h2`. Additionally, set default routes in
75# `r1` and `r2` so that the packets that cannot be forwarded based on the
76# entries in their routing table are sent via a default interface.
77h1.add_route("DEFAULT", eth1)
78h2.add_route("DEFAULT", eth2)
79r1.add_route("DEFAULT", etr1b)
80r2.add_route("DEFAULT", etr2a)
81
82# Set up an Experiment. This API takes the name of the experiment as a string.
83exp = Experiment("tcp-reno-point-to-point-3")
84
85# Configure a flow from `h1` to `h2`. We do not use it as a TCP flow yet.
86# The `Flow` API takes in the source node, destination node, destination IP
87# address, start and stop time of the flow, and the total number of flows.
88# In this program, start time is 0 seconds, stop time is 200 seconds and the
89# number of flows is 1.
90flow1 = Flow(h1, h2, eth2.get_address(), 0, 200, 1)
91
92# Use `flow1` as a TCP Reno flow.
93exp.add_tcp_flow(flow1, "reno")
94
95# Run the experiment
96exp.run()
10. tcp-udp-point-to-point.py¶
This program emulates point to point networks that connect four hosts: h1
h4
via two routersr1
andr2
. One TCP flow is configured fromh1
toh3
and one UDP flow is configured fromh2
toh4
.
This program runs for 200 seconds and creates a new directory called
tcp-udp-point-to-point(date-timestamp)_dump
. It contains a README
which
provides details about the sub-directories and files within this directory.
See the plots in iperf3
, netperf
, ping
and ss
sub-directories for
this program.
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.experiment import *
9from nest.topology.network import Network
10from nest.topology.address_helper import AddressHelper
11
12# This program emulates point to point networks that connect four hosts: `h1`
13# - `h4` via two routers `r1` and `r2`. One TCP flow is configured from `h1` to
14# `h3` and one UDP flow is configured from `h2` to `h4`.
15
16##############################################################################
17# Network Topology #
18# #
19# <- 1000mbit, 1ms -> <- 1000mbit, 1ms -> #
20# h1 --------------------| |-------------------- h3 #
21# TCP | | TCP #
22# | <- 10mbit, 10ms -> | #
23# r1 -------------------- r2 #
24# | pfifo qdisc --> | #
25# UDP | | UDP #
26# h2 --------------------| |-------------------- h4 #
27# <- 1000mbit, 1ms -> <- 1000mbit, 1ms -> #
28# #
29##############################################################################
30
31# This program runs for 200 seconds and creates a new directory called
32# `tcp-udp-point-to-point(date-timestamp)_dump`. It contains a `README` which
33# provides details about the sub-directories and files within this directory.
34# See the plots in `iperf3`, `netperf`, `ping` and `ss` sub-directories for
35# this program.
36
37# Create four hosts `h1` to `h4`, and two routers `r1` and `r2`
38h1 = Node("h1")
39h2 = Node("h2")
40h3 = Node("h3")
41h4 = Node("h4")
42r1 = Router("r1")
43r2 = Router("r2")
44
45# Set the IPv4 address for the networks
46n1 = Network("192.168.1.0/24") # network consisting `h1` and `r1`
47n2 = Network("192.168.2.0/24") # network consisting `h2` and `r1`
48n3 = Network("192.168.3.0/24") # network between two routers
49n4 = Network("192.168.4.0/24") # network consisting `r2` and `h3`
50n5 = Network("192.168.5.0/24") # network consisting `r2` and `h4`
51
52# Connect `h1` and `h2` to `r1`, `r1` to `r2`, and then `r2` to `h3` and `h4`.
53# `eth1` to `eth4` are the interfaces at `h1` to `h4`, respectively.
54# `etr1a`, `etr1b` and `etr1c` are three interfaces at `r1` that connect it
55# with `h1`, `h2` and `r2`, respectively.
56# `etr2a`, `etr2b` and `etr2c` are three interfaces at `r2` that connect it
57# with `r1`, `h3` and `h4`, respectively.
58(eth1, etr1a) = connect(h1, r1, network=n1)
59(eth2, etr1b) = connect(h2, r1, network=n2)
60(etr1c, etr2a) = connect(r1, r2, network=n3)
61(etr2b, eth3) = connect(r2, h3, network=n4)
62(etr2c, eth4) = connect(r2, h4, network=n5)
63
64# Assign IPv4 addresses to all the interfaces in the network.
65AddressHelper.assign_addresses()
66
67# Set the link attributes: `h1` and `h2` --> `r1` --> `r2` --> `h3` and `h4`
68# Note: we enable `pfifo` queue discipline (qdisc) on the link from `r1` to
69# `r2`. Default configuration of `pfifo` in Linux is used. For more details
70# about `pfifo` qdisc in Linux, use this command on CLI: `man tc-pfifo`.
71eth1.set_attributes("1000mbit", "1ms") # from `h1` to `r1`
72eth2.set_attributes("1000mbit", "1ms") # from `h2` to `r1`
73etr1c.set_attributes("10mbit", "10ms", "pfifo") # from `r1` to `r2`
74etr2b.set_attributes("1000mbit", "1ms") # from `r2` to `h3`
75etr2c.set_attributes("1000mbit", "1ms") # from `r2` to `h4`
76
77# Set the link attributes: `h3` and `h4` --> `r2` --> `r1` --> `h1` and `h2`
78eth3.set_attributes("1000mbit", "1ms") # from `h3` to `r2`
79eth4.set_attributes("1000mbit", "1ms") # from `h4` to `r2`
80etr2a.set_attributes("10mbit", "10ms") # from `r2` to `r1`
81etr1a.set_attributes("1000mbit", "1ms") # from `r1` to `h1`
82etr1b.set_attributes("1000mbit", "1ms") # from `r1` to `h2`
83
84# Set default routes in all the hosts and routers.
85h1.add_route("DEFAULT", eth1)
86h2.add_route("DEFAULT", eth2)
87h3.add_route("DEFAULT", eth3)
88h4.add_route("DEFAULT", eth4)
89r1.add_route("DEFAULT", etr1c)
90r2.add_route("DEFAULT", etr2a)
91
92# Set up an Experiment. This API takes the name of the experiment as a string.
93exp = Experiment("tcp-udp-point-to-point")
94
95# Configure one flow from `h1` to `h3` and another from `h2` to `h4`.
96flow1 = Flow(h1, h3, eth3.get_address(), 0, 200, 1)
97flow2 = Flow(h2, h4, eth4.get_address(), 0, 200, 1)
98
99# Use `flow1` as a TCP flow. TCP CUBIC is default in Linux.
100exp.add_tcp_flow(flow1)
101
102# Use `flow2` as a UDP flow, and set the rate at which it would send packets.
103exp.add_udp_flow(flow2, target_bandwidth="10mbit")
104
105# Run the experiment
106exp.run()