cs42200:spring19:labs:lab08

Lab 08: Multi-tenant Data Center Network - Part I

  • Learn how to simulate a computer network using mininet (Part I)

The Open Networking Foundation (ONF) is the group that is most associated with the development and standardization of SDN. According to the ONF1, “Software-Defined Networking (SDN) is an emerging architecture that is dynamic, manageable, cost-effective, and adaptable, making it ideal for the high-bandwidth, dynamic nature of today’s applications.

SDN provides the ability to program networks directly by breaking the vertical integration of control and data planes. The separation of control and data planes allows network switches to become simple forwarding devices and gives us flexibility to control and program them by implementing the control logic in a centralized SDN controller using software called a Network Operating System (NOS). SDN represents a move away from vendor-specific management systems, and that the basic idea is to have an external controller (software running on a Linux box) that uses a protocol to send low-level configurations details to a set of network devices. In the current SDN paradigm, SDN controllers compromises three key layers including data plane, control plane, and application layers. Most of the SDN controllers employ two Application Programming Interfaces (APIs) called the Northbound and Southbound APIs. Network applications use northbound APIs to communicate with the controller, express network behaviors, define configuration requirements, and program forwarding devices. Southbound An example of SDN architecture is illustrated in Figure 1.

It is not practical to allow sudents to write software that controls and manages a production network. Even networking professionals cannot afford to build an entire network to test a new network control software (e.g., a routing protocol, traffic engineering applications, etc.). In situations where building a network is not practical, network simulations can be used to test new functions. Computer network simulations can also be used as a proof-of-concept before investing resources to build a large test network.

Mininet is a network emulator application, or perhaps more precisely, an application that can emulate an orchestration system. It emulates a network of end-hosts, switches, routers, and links on a single Linux kernel. It uses lightweight virtualization technology to make a single system look like a complete network, running the same kernel, system, and user code.

A Mininet host behaves just like a real machine; you can ssh into it (if you start up sshd and bridge the network to your host) and run arbitrary application programs, including any application that is installed on the underlying Linux system. The programs you run can send packets through what seems like a real Ethernet interface, with a given link speed and delay. Packets get processed by what looks like a real Ethernet switch, router, or middlebox, with a given amount of queueing. More information about Mininet can be found here

In this lab, you will use Mininet to build a data center network as specified in the following sections.

Mininet supports parametrized topologies. With a few lines of Python code, you can create a flexible topology which can be configured based on the parameters you pass into it, and reused for multiple experiments.

For example, the following code generates a simple network topology which consists of a specified number of hosts (h1 through hN) connected to a single switch (s1):

#!/usr/bin/python

    from mininet.topo import Topo
    from mininet.net import Mininet
    from mininet.util import dumpNodeConnections
    from mininet.log import setLogLevel

    class SingleSwitchTopo(Topo):
        "Single switch connected to n hosts."
        def build(self, n=2):
            switch = self.addSwitch('s1')
            # Python's range(N) generates 0..N-1
            for h in range(n):
                host = self.addHost('h%s' % (h + 1))
                self.addLink(host, switch)

    def simpleTest():
        "Create and test a simple network"
        topo = SingleSwitchTopo(n=4)
        net = Mininet(topo)
        net.start()
        print "Dumping host connections"
        dumpNodeConnections(net.hosts)
        print "Testing network connectivity"
        net.pingAll()
        net.stop()

    if __name__ == '__main__':
        # Tell mininet to print useful information
        setLogLevel('info')
        simpleTest()

Important classes, methods, functions and variables in the above code are explained below:

Topo: the base class for Mininet topologies

  Methods of class Topo:
     * addSwitch(name)       : adds a switch to a topology and returns the switch name
     * addHost(name)         : adds a host to a topology and returns the host name
     * addLink(name1, name2) : adds a bidirectional link to a topology (links are bi-directional)
Mininet: main class to create and manage a network

  Methods of class Mininet:
     * start()               : starts your network
     * pingAll()             : tests connectivity by trying to have all nodes ping each other
     * stop()                : stops your network
     * net.hosts             : all the hosts in a network
     * dumpNodeConnections() : dumps connections to/from a set of nodes.

Detailed documentation on mininet classes can be found here

Leaf-spine is a two-layer network topology composed of leaf switches, to which servers and storage connect, and spine switches, to which leaf switches connect. Spine switches, which are composed of a series of high-throughput layer 3 switches with high port density, form the core of the architecture. Leaf switches mesh into the spine, forming the access layer that delivers network connection points for servers.

Leaf switches also provide uplinks to spine switches. Every leaf switch connects to every spine switch in the network fabric; no matter which leaf switch a host is connected to, it has to cross the same number of devices every time it communicates with another host. The only exception is when the other host is on the same leaf. This minimizes latency and bottlenecks because each payload only has to travel to a spine switch and another leaf switch to reach its endpoint.

A very important advantage of leaf and spine topology is that it is highly scalable. Modern datacenters need such a highly scalable network architecture to support an ever increasing number of servers and VMs per server. Most modern data centers use a modified leaf and spine architecture, sometimes with more than two layers of switches.

The following figure illustrates the leaf-spine topology:

leaf_spine_topo.jpg

The ONOS (Open Network Operating System) project is an open source community hosted by The Linux Foundation. The goal of the project is to create a software-defined networking (SDN) operating system for communications service providers that is designed for scalability, high performance and high availability. The architecture of ONOS is illustrated as follows:

To run VM, you will need to log on to the machine mc18.cs.purdue.edu (your CS username and password should work on this machine).

You will use the command /scratch/mininet/mnctl to create/delete/start/stop the VM. Here is the usage of this command:

usage: mnctl start|stop|delete|port|status|help

start	start existing Mininet image; if none exists, a new one is created
stop	stop existing Mininet instance
status	show status of Mininet instance
ssh	open SSH connection to Mininet instance
delete	delete existing Mininet image
port	output SSH port on which Mininet is listening (ssh localhost -p PORT)
help	provide very little help

Following sections provide further details.

3.1.1 Create a VM for the first time

To create a VM use the following command:

$ /scratch/mininet/mnctl start
creating new Mininet image
starting Mininet...
Mininet now running as PID 3656 on SSH port 28114

If you are running this command for the first time, it will create a new VM for you. This VM can be accessed using ssh on the specified port number (28114 in this case). The port number will be different for you.

3.1.2 Log in to the VM

To log into the VM, you will need the ssh port your VM is listening on.

$ /scratch/mininet/mnctl status
Mininet running as PID 3656 on SSH port 28114

# Use the port number returned by the command above to ssh into the VM
# Initial password is mininet
$ ssh osboxes@localhost -p 28114

The initial login password is umbrella_cs422. When you log in for the first time, it will ask you to change the password. Once you change the password, you will be logged out. Use the ssh command specified above to log in again (Use the new password at this point).

3.1.3 Stop a VM

To stop a running VM, use the following command

$ /scratch/mininet/mnctl stop  
stopping Mininet with PID 3656

This will stop the running VM. Your data will not be lost. The VM will only be shut down, it can be started again. It is recommended to stop a VM if you are not going to use it for a long time.

3.1.4 Start a stopped VM

To start a stopped VM, use the following command

$ /scratch/mininet/mnctl start
starting Mininet...
Mininet now running as PID 4812 on SSH port 50386

Note 1 This command is exactly similar to the one we used to create a VM. If there does not exist any VM for you, this command will create a VM. If there is a VM created for you, this command will start it.

Note 2 If you stop a VM and start it, the port number associated with the ssh for this VM will change. You can see the above output to see how the port number has changed from the output shown in earlier sections. You can get the current port number using the /scratch/mininet/mnctl status at any time.

  1. ssh to mc18.cs.purdue.edu using your CS username and password
  2. Create a directory for this lab:
    mkdir ~/cs422/
  3. Download lab08_part1.tar.gz with wget under ~/cs422/. Note that the option '-O' is capitalized.
    cd ~/cs422/
    wget http://courses.cs.purdue.edu/_media/cs42200:spring19:lab08_part1.tar.gz -O lab08_part1.tar.gz
  4. Untar the downloaded file:
    tar -xvf lab08_part1.tar.gz
    rm lab08_part1.tar.gz
  5. Create a VM, if you haven't created it already and start it using the instructions in Section 3.1. Make sure you have changed the password before moving on to the next step
  6. From mc18.cs.purdue.edu, copy the lab contents to the VM using scp:
    scp -P <VM_port_number> -r ~/cs422/lab08_part1/ osboxes@localhost:~/
  7. Log in to the VM to start with the lab
  1. Log in to the VM and move to the lab directory:
    ssh osboxes@localhost -p <VM_port_number>
    ...
    osboxes@osboxes:~$ cd ~/lab08_part1
  2. In the lab directory, you will find the following items:
    $ ls
    leaf_spine.py
  3. In the file leaf_spine.py is defined the class LeafAndSpine. Inside the class LeafAndSpine is a method init:
    # Class specifying the leaf and spine topology
    class LeafAndSpine(Topo):
        def __init__(self, spine=2, leaf=2, fanout=2, **opts):
            "Create Leaf and Spine Topo."
    
            Topo.__init__(self, **opts)
    
            # This function builds a leaf and spine topology
            # Parameters passed to this function are
            #
            #    spine - Number of Spine switches
            #    leaf  - Number of Leaf switches
            #    fanout - Number of hosts per leaf switch
            #
  1. Your task is to fill out the method init to generate the leaf and spine topology. This function will use the arguments passed to it to determine the number of spine and leaf switches and the number of hosts per leaf switch.

We use the following nameing convention to name hosts and switches:

  1. Leaf switches named leaf301, leaf302, …
  2. Spine switches named spine401, spine402, …
  3. Hosts named h1, h2, h3, …
  4. When you add a host to the network topology, you need to assign a MAC address to each host as follows:
    1. 00:00:00:00:00:XX where XX should be replaced with host's ID. For example: h1's MAC address is 00:00:00:00:00:01
  1. Open up a separate terminal, ssh into your vm
  2. Run ONOS controller using the following commands:
        $ cd onos
        $ ok clean
        
  3. After executing the above commands, it takes a few minutes to boot up the SDN controller.
  4. Note that, you need to leave this terminal running while testing your code on a seperate terminal.
  5. To test the topology, you will run the leaf_spine.py file after the SDN controller boots up completely:
    $ sudo mn -c 
    $ sudo python leaf_spine.py --spine 2 --leaf 3 --fanout 2

    leaf_spine.py creates an object of class LeafAndSpine and uses that object to create a network. You do NOT need to modify main function. You can change the command line arguments to test your code with different values.

  6. Running the leaf_spine.py file will create the network using your topology, connect the network switches to the SDN controller, start the network, and drop into the mininet command-line interface (CLI):
    $ sudo mn -c 
    $ sudo python leaf_spine.py --spine 2 --leaf 3 --fanout 2
    mininet>
  7. Once in the CLI, you can run the command net to dump the network topology. Using this you can verify if the topology that you created is correct i.e. it creates the right number of switches and hosts and they are linked together as expected
  8. Run pingall from mininet CLI and see can you ping all of the hosts from each other? By default, ONOS runs a reactive forwarding application that installs flow rules when one host starts sending packets to another host.
  9. Open a new terminal, ssh to your VM and connect to ONOS cli using the following command:
         $ onos 127.0.0.1 
         
  10. Try commands like: devices, hosts, and links from ONOS CLI and confirm that number of links, hosts, devices are consistent with your network topology.
  11. Run the command quit in the mininet CLI to exit from the CLI. You can use the command help to explore other CLI commands

ONOS provides a graphical user interface that you can use to check the network topology and flow rules that have been installed on network switches. To access ONOS GUI after running ONOS, you will need to use X-forwarding as follows(For Mac users, replace -CX with -Y):

  1. ssh -CX username@xinu2.cs.purdue.edu
  2. ssh -CX username@mc18.cs.purdue.edu
  3. ssh -CX osboxes@localhost -p VM_PORT_NUMBER
  4. Run Firefox from the VM command line interface by typing Firefox (it takes 1-2 minutes to open it)
  5. Enter http://127.0.0.1:8181/onos/ui/login.html in Firefox location bar.
  6. Enter ONOS GUI's username and password. ONOS GUI's username is onos and its password is rocks

After completing the above steps, you should be able to see the network topology that you emulated using Mininet. Here is a screenshot of a leaf-spine topology with 2 spines, 3 leaves, and fanout of 2.

To learn more about ONOS GUI, you can refer to: https://wiki.onosproject.org/display/ONOS/The+ONOS+Web+GUI

NOTE : X-Forwarding is really slow. Thank you for your patience :)

Follow these instructions to turnin your work:

  1. Log in to mc18.cs.purdue.edu using your CS username and password
  2. Navigate to the lab directory:
    cd ~/cs422/lab08_part1
  3. Create a submit directory:
    mkdir submit
  4. Copy the python files from your VM to the submit directory:
    scp -P <VM_port_number> -r osboxes@localhost:~/lab08_part1/leaf_spine.py ~/cs422/lab08_part1/submit
  5. Turnin the submit directory:
    cd ~/cs422/lab08_part1/
    turnin -c cs422 -p lab08_part1 submit

This lab will be graded during the first PSO after the deadline.

  1. April 18th, Thursday
  2. April 19th, Friday
  • Note: Each student has 5 minutes to present his/her work. The TA will give you parameters and you should be able to emulate a leaf-spine topology as we explained in the handout. Please make your setup ready before grading.

Grading Form

  • cs42200/spring19/labs/lab08.txt
  • Last modified: 2019/04/04 11:53
  • by arastega