Beispiel #1
0
 def setUp(self):
     self.n0 = Node("n0")
     self.n1 = Node("n1")
     self.net1 = Network("10.0.1.0/24")
     self.net2 = Network("10.0.2.0/24")
     self.net3 = Network("2001:101::/122")
     self.net4 = Network("2002:101::/122")
##########################################################

# Configure the program to use Quagga routing suite and enable routing logs.
# Routing logs are written to files in a dedicated `logs` directory.
config.set_value("routing_suite", "quagga")  # `quagga` is default in NeST.
config.set_value("routing_logs", True)  # By default, this is False.

# Create two hosts `h1` and `h2`, and one router `r1`
h1 = Node("h1")
h2 = Node("h2")
r1 = Router("r1")  # Internally, `Router` API enables IP forwarding in `r1`

# Set the IPv4 address for the networks, and not the interfaces.
# We will use the `AddressHelper` later to assign addresses to the interfaces.
# Note: this example has two networks, one each on either side of `r1`.
n1 = Network("192.168.1.0/24")  # network on the left side of `r1`
n2 = Network("192.168.2.0/24")  # network on the right side of `r1`

# Connect `h1` to `r1` (left side), and then `r1` (right side) to `h2`.
# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
# `etr1a` is the first interface at `r1` which connects it with `h1`
# `etr1b` is the second interface at `r1` which connects it with `h2`
(eth1, etr1a) = connect(h1, r1, network=n1)
(etr1b, eth2) = connect(r1, h2, network=n2)

# Assign IPv4 addresses to all the interfaces in the network.
AddressHelper.assign_addresses()

# Set the link attributes: `h1` --> `r1` --> `h2`
eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `h2`
Beispiel #3
0
left_router.enable_ip_forwarding()
right_router.enable_ip_forwarding()

# Lists to store all the left and right nodes
left_nodes = []
right_nodes = []

# Creating all the left and right nodes
for i in range(num_of_left_nodes):
    left_nodes.append(Node("left-node-" + str(i)))

for i in range(num_of_right_nodes):
    right_nodes.append(Node("right-node-" + str(i)))

# Define networks
left_network = Network("10.0.0.0/24")
right_network = Network("10.0.1.0/24")
middle_network = Network("10.0.2.0/24")

# Add connections

# Lists of tuples to store the interfaces connecting the router and nodes
left_node_connections = []
right_node_connections = []

# Connections of the left-nodes to the left-router
with left_network:
    for i in range(num_of_left_nodes):
        left_node_connections.append(connect(left_nodes[i], left_router))

# Connections of the right-nodes to the right-router
Beispiel #4
0
# h1 -------------------- r1 -------------------- r2 -------------------- h2 #
#     <-- 10mbit, 100ms       <-- 10mbit, 100ms       <-- 10mbit, 100ms      #
#                                                                            #
##############################################################################

# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`
h1 = Node("h1")
h2 = Node("h2")
r1 = Router("r1")
r2 = Router("r2")

# Set the IPv6 address for the networks, and not the interfaces.
# We will use the `AddressHelper` later to assign addresses to the interfaces.
# Note: this example has three networks: one on the left of `r1`, second
# between the two routers, and third on the right of `r2`.
n1 = Network("2001:1::/122")  # network on the left of `r1`
n2 = Network("2001:2::/122")  # network between two routers
n3 = Network("2001:3::/122")  # network on the right of `r2`

# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
# `etr1a` is the first interface at `r1` which connects it with `h1`
# `etr1b` is the second interface at `r1` which connects it with `r2`
# `etr2a` is the first interface at `r2` which connects it with `r1`
# `etr2b` is the second interface at `r2` which connects it with `h2`
(eth1, etr1a) = connect(h1, r1, network=n1)
(etr1b, etr2a) = connect(r1, r2, network=n2)
(etr2b, eth2) = connect(r2, h2, network=n3)

# Assign IPv6 addresses to all the interfaces in the network.
AddressHelper.assign_addresses()
# Configure the program to use Quagga routing suite and enable routing logs.
# Routing logs are written to files in a dedicated `logs` directory.
config.set_value("routing_suite", "quagga")  # `quagga` is default in NeST.
config.set_value("routing_logs", True)  # By default, this is False.

# Create two hosts `h1` and `h2`, and two routers `r1` and `r2`.
h1 = Node("h1")
h2 = Node("h2")
r1 = Router("r1")
r2 = Router("r2")

# Set the IPv4 address for the networks, and not the interfaces.
# We will use the `AddressHelper` later to assign addresses to the interfaces.
# Note: this example has three networks: one on the left of `r1`, second
# between the two routers, and third on the right of `r2`.
n1 = Network("192.168.1.0/24")  # network on the left of `r1`
n2 = Network("192.168.2.0/24")  # network between two routers
n3 = Network("192.168.3.0/24")  # network on the right of `r2`

# Connect `h1` to `r1`, `r1` to `r2`, and then `r2` to `h2`
# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
# `etr1a` is the first interface at `r1` which connects it with `h1`
# `etr1b` is the second interface at `r1` which connects it with `r2`
# `etr2a` is the first interface at `r2` which connects it with `r1`
# `etr2b` is the second interface at `r2` which connects it with `h2`
(eth1, etr1a) = connect(h1, r1, network=n1)
(etr1b, etr2a) = connect(r1, r2, network=n2)
(etr2b, eth2) = connect(r2, h2, network=n3)

# Assign IPv4 addresses to all the interfaces in the network.
AddressHelper.assign_addresses()
Beispiel #6
0
}

# Creating all the nodes
node = []
for i in range(10):
    node.append(Node("node" + str(i)))
    node[i].configure_tcp_param("ecn", "1")

# Creating all the routers
router = []
for i in range(4):
    router.append(Node("router" + str(i)))
    router[-1].enable_ip_forwarding()

# Define networks
network_A = Network("2001::/122")
network_B = Network("2002::/122")
network_C = Network("2003::/122")
network_D = Network("2004::/122")
network_E = Network("2005::/122")
network_F = Network("2006::/122")
network_G = Network("2007::/122")
network_H = Network("2008::/122")
network_I = Network("2009::/122")
network_J = Network("2010::/122")
network_K = Network("2011::/122")
network_L = Network("2012::/122")
network_M = Network("2013::/122")

# Create interfaces and connect nodes and routers
(r0_n0, n0_r0) = connect(router[0], node[0], network=network_A)
Beispiel #7
0
#                                                                                 #
#                               PHP        <-- Label: 201                         #
#                                                                                 #
###################################################################################

# Create two `ce` routers, two `pe` routers and one `p` router
ce1 = Router("ce1")
ce2 = Router("ce2")
pe1 = Router("pe1")
pe2 = Router("pe2")
p = Router("p")

# Set the IPv4 address for the networks.
# This example has four networks: one on the left of `pe1`, second between
# `pe1` and `p`, third between `p` and `pe2`, and fourth on the right of `pe2`.
n1 = Network("192.168.1.0/24")  # network on the left of `pe1`
n2 = Network("192.168.2.0/24")  # network between `pe1` and `p`
n3 = Network("192.168.3.0/24")  # network between `p` and `pe2`
n4 = Network("192.168.4.0/24")  # network on the right of `pe2`

# Connect `ce1` to `pe1`, `pe1` to `p`, `p` to `pe2`, and `pe2` to `ce2`
# `etce1` and `etce2` are the interfaces at `ce1` and `ce2`, respectively.
# `etpe1a` is the first interface at `pe1` which connects it with `ce1`
# `etpe1b` is the second interface at `pe1` which connects it with `p`
# `etpa` is the first interface at `p` which connects it with `pe1`
# `etpb` is the second interface at `p` which connects it with `pe2`
# `etpe2a` is the first interface at `pe2` which connects it with `p`
# `etpe2b` is the second interface at `pe2` which connects it with `ce2`
(etce1, etpe1a) = connect(ce1, pe1, network=n1)
(etpe1b, etpa) = connect(pe1, p, network=n2)
(etpb, etpe2a) = connect(p, pe2, network=n3)
Beispiel #8
0
#                                                        #
#          5mbit, 5ms -->          5mbit, 5ms -->        #
#   h1 -------------------- r1 -------------------- h2   #
#       <-- 10mbit, 100ms        <-- 10mbit, 100ms       #
#                                                        #
##########################################################

# Create two hosts `h1` and `h2`, and one router `r1`
h1 = Node("h1")
h2 = Node("h2")
r1 = Router("r1")  # Internally, `Router` API enables IP forwarding in `r1`

# Set the IPv6 address for the networks, and not the interfaces.
# We will use the `AddressHelper` later to assign addresses to the interfaces.
# Note: this example has two networks, one each on either side of `r1`.
n1 = Network("2001:1::/122")  # network on the left side of `r1`
n2 = Network("2001:2::/122")  # network on the right side of `r1`

# Connect `h1` to `r1` (left side), and then `r1` (right side) to `h2`.
# `eth1` and `eth2` are the interfaces at `h1` and `h2`, respectively.
# `etr1a` is the first interface at `r1` which connects it with `h1`
# `etr1b` is the second interface at `r1` which connects it with `h2`
(eth1, etr1a) = connect(h1, r1, network=n1)
(etr1b, eth2) = connect(r1, h2, network=n2)

# Assign IPv6 addresses to all the interfaces in the network.
AddressHelper.assign_addresses()

# Set the link attributes: `h1` --> `r1` --> `h2`
eth1.set_attributes("5mbit", "5ms")  # from `h1` to `r1`
etr1b.set_attributes("5mbit", "5ms")  # from `r1` to `h2`
Beispiel #9
0
#################################
#       Network Topology        #
#                               #
#          5mbit, 5ms -->       #
#   h1 ------------------- h2   #
#       <-- 10mbit, 100ms       #
#                               #
#################################

# Create two hosts `h1` and `h2`
h1 = Node("h1")
h2 = Node("h2")

# Set the IPv4 address for the network, and not the interfaces.
# We will use the `AddressHelper` later to assign addresses to the interfaces.
n1 = Network("192.168.1.0/24")

# Connect the above two hosts using a veth pair. Note that `connect` API in
# this program takes `network` as an additional parameter. The following line
# implies that `eth1` and `eth2` interfaces on `h1` and `h2`, respectively are
# in the same network `n1`.
(eth1, eth2) = connect(h1, h2, network=n1)

# Assign IPv4 addresses to all the interfaces in the network.
AddressHelper.assign_addresses()

# Set the link attributes: `h1` --> `h2` and `h2` --> `h1`
eth1.set_attributes("5mbit", "5ms")
eth2.set_attributes("10mbit", "100ms")

# `Ping` from `h1` to `h2`.
Beispiel #10
0
##############################
# Topology
#
# n1 -->-- r ---> n2
##############################

# Create Nodes
n2 = Node("n2")
r = Node("r")
n1 = Node("n1")

# Enable IP forwarding in routers
r.enable_ip_forwarding()

# Define networks
left_network = Network("::FFFF:10.0.0.0/124")
right_network = Network("::FFFF:11.0.0.0/124")

# Create interfaces and connect nodes and routers
(n1_r, r_n1) = connect(n1, r, network=left_network)
(r_n2, n2_r) = connect(r, n2, network=right_network)

# Assign addresses to each interface present in network
AddressHelper.assign_addresses()

# Routing
RoutingHelper(protocol="rip").populate_routing_tables()

# Sets attributes such as bandwidth, latency and
# queue discipline for the link.
n1_r.set_attributes("100mbit", "5ms")
Beispiel #11
0
##############################

### Create Nodes ###
n1 = Node("n1")
n2 = Node("n2")
r1 = Node("r1")
r2 = Node("r2")
r3 = Node("r3")

### Enable IP forwarding in routers ###
r1.enable_ip_forwarding()
r2.enable_ip_forwarding()
r3.enable_ip_forwarding()

# Define networks
net1 = Network("10.0.1.0/24")
net2 = Network("10.0.2.0/24")
net3 = Network("10.0.3.0/24")
net4 = Network("10.0.4.0/24")

# The API takes two nodes and network as the parameters
# where network is optional parameters
# It returns the pair of interfaces
# And it also add the interfaces to the network if mentioned
(n1_r1, r1_n1) = connect(n1, r1, network=net1)
(r1_r2, r2_r1) = connect(r1, r2, network=net2)
(r2_r3, r3_r2) = connect(r2, r3, network=net3)
(r3_n2, n2_r3) = connect(r3, n2, network=net4)

# Assign addresses to each interface present in network
AddressHelper.assign_addresses()
Beispiel #12
0
def connect(
    node1: topology.Node,
    node2: topology.Node,
    interface1_name: str = "",
    interface2_name: str = "",
    network: Network = None,
):
    """
    Connects two nodes `node1` and `node2`.
    Creates two paired Virtual Ethernet interfaces (veth) and returns
    them as a 2-element tuple.
    The first interface belongs to `node1`, and the second interface
    belongs to `node2`.

    Parameters
    ----------
    node1 : Node
        First veth interface added in this node
    node2 : Node
        Second veth interface added in this node
    interface1_name : str
        Name of first veth interface
    interface2_name : str
        Name of second veth interface
    network : Network
        Object of the Network to add interfaces

    Returns
    -------
    (interface1, interface2)
        2 tuple of created (paired) veth interfaces. `interface1` is in
        `n1` and `interface2` is in `n2`.
    """
    # Number of connections between `node1` and `node2`, set to `None`
    # initially since it hasn't been computed yet
    connections = None

    # Check interface names
    if interface1_name == "":
        connections = _number_of_connections(node1, node2)
        interface1_name = _autogenerate_interface_name(node1, node2,
                                                       connections)

    if interface2_name == "":
        if connections is None:
            connections = _number_of_connections(node1, node2)
        # pylint: disable=arguments-out-of-order
        interface2_name = _autogenerate_interface_name(node2, node1,
                                                       connections)

    # Create 2 interfaces
    (interface1, interface2) = create_veth_pair(interface1_name,
                                                interface2_name)

    node1._add_interface(interface1)
    node2._add_interface(interface2)

    interface1.set_mode("UP")
    interface2.set_mode("UP")

    # Disabling Duplicate Address Detection(DAD) at the interfaces
    if config.get_value("disable_dad") is True:
        interface1.disable_ip_dad()
        interface2.disable_ip_dad()

    # The network parameter takes precedence over "global" network level
    if network is None:
        network = Network.current_network
    # Add the interfaces to the network if mentioned
    if network is not None:
        network.add_interface(interface1)
        network.add_interface(interface2)

    return (interface1, interface2)
#################################
#       Network Topology        #
#                               #
#          5mbit, 5ms -->       #
#   h1 ------------------- h2   #
#       <-- 10mbit, 100ms       #
#                               #
#################################

# Create two hosts `h1` and `h2`
h1 = Node("h1")
h2 = Node("h2")

# Set the IPv6 address for the network, and not the interfaces.
# We will use the `AddressHelper` later to assign addresses to the interfaces.
n1 = Network("2001:1::/122")

# Connect the above two hosts using a veth pair. Note that `connect` API in
# this program takes `network` as an additional parameter. The following line
# implies that `eth1` and `eth2` interfaces on `h1` and `h2`, respectively are
# in the same network `n1`.
(eth1, eth2) = connect(h1, h2, network=n1)

# Assign IPv6 addresses to all the interfaces in the network.
AddressHelper.assign_addresses()

# Set the link attributes: `h1` --> `h2` and `h2` --> `h1`
eth1.set_attributes("5mbit", "5ms")
eth2.set_attributes("10mbit", "100ms")

# `Ping` from `h1` to `h2`.
# 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.

# Create four hosts `h1` to `h4`, and two routers `r1` and `r2`
h1 = Node("h1")
h2 = Node("h2")
h3 = Node("h3")
h4 = Node("h4")
r1 = Router("r1")
r2 = Router("r2")

# Set the IPv4 address for the networks
n1 = Network("192.168.1.0/24")  # network consisting `h1` and `r1`
n2 = Network("192.168.2.0/24")  # network consisting `h2` and `r1`
n3 = Network("192.168.3.0/24")  # network between two routers
n4 = Network("192.168.4.0/24")  # network consisting `r2` and `h3`
n5 = Network("192.168.5.0/24")  # network consisting `r2` and `h4`

# Connect `h1` and `h2` to `r1`, `r1` to `r2`, and then `r2` to `h3` and `h4`.
# `eth1` to `eth4` are the interfaces at `h1` to `h4`, respectively.
# `etr1a`, `etr1b` and `etr1c` are three interfaces at `r1` that connect it
# with `h1`, `h2` and `r2`, respectively.
# `etr2a`, `etr2b` and `etr2c` are three interfaces at `r2` that connect it
# with `r1`, `h3` and `h4`, respectively.
(eth1, etr1a) = connect(h1, r1, network=n1)
(eth2, etr1b) = connect(h2, r1, network=n2)
(etr1c, etr2a) = connect(r1, r2, network=n3)
(etr2b, eth3) = connect(r2, h3, network=n4)