Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Task 1: Create Topology in Mininet

In this task, we first introduce the basic commands in Mininet which can be used to test the created topology. Then, students are asked to create a network topology based on the given network diagram, using Mininet and Python. The skeleton code is also given.

Objectives of Task 1

▪   Learn the basic commands in Mininet

▪   Create a basic network topology in Mininet

▪   Set performance limits of network topology

▪   Add flow entries in switch

Running Mininet

Mininet can be used by running the command sudo mn. However, just running this will give you a simple default topology. To run mininet with a somewhat customized topology, you   can use the following command:


$ sudo mn --topo single,3 --mac


Note: The $ indicates that you should run the command in VM’s terminal

Either of these commands will create a topology and show you the Mininet CLI (command- line interface, signified by the line start mininet>).

Some useful mininet commands are as follows:

▪   Display mininet CLI commands: help

▪   Display nodes: nodes

▪   Display links: net

▪   Dump information about all nodes: dump

▪   Show bash for a specific host: xterm h1 (replacing h1 with the desired host)

▪   Test that all nodes can reach each other: pingall

▪   Have one node ping another: h1 ping h2 (replacing h1/h2 with the desired hosts, Ctrl + C to stop)

▪   Exit the mininet CLI: exit

Using commands from a host’s xterm window is usually best.

After you have exited Mininet using exit, run the following command to have a clean-up:


$ sudo mn -c


Testing a Topology

You can test a Mininet topology with the same tools that you would test real networks with, including ping, iperf, wireshark, and traceroute.

1.   Create a topology with 3 hosts all connected to a switch:


$ sudo mn --topo single,3 --mac


 

Figure 1 topology with three single hosts

2.   Next, to be able to run commands as a host, open a terminal window for the host in   the network:                                                                                                                                  mininet> xterm h1               

Note: The mininet> indicates that you should run the command in Mininet’s CLI

Replacing h1 with the host to run as.

3.   Testing ICMP connectivity between the hosts is a good first test . Simply running the ping command from one host to another will work. You should run the ping              command from within the hosts terminal you have opened, for example, from a      terminal for h1 you can ping h2 like so:

[h1]# ping 10.0.0.2 -c 5                                                                                                               

Note: The [h1]# indicates that you should run the command in h1’s xterm window

If you want to change the font size in xterm window, hold down the Ctrl key and the right-hand mouse button within the xterm window. This will display the VTfonts      menu where you can select the preferred font size like Large or ‘Huge’.

If you want to quickly run this test, you can also run this directly from the Mininet       CLI by running:                                                                                                                               mininet> h1 ping h2                                                                                                                    

Use Ctrl + C to stop.

4.   You can also test the bandwidth between hosts using iperf. On one host, you should run the iperf server and the other the client. To run this, open a terminal for a host, e.g., h1 and run the server:

[h1]# iperf -s                                                                                                                                  Following this, open another xterm for another host e.g. h3 and run the client:             [h3]# iperf -c 10.0.0.1                                                                                                                 

After waiting a few seconds for the test to complete, you should get the bandwidth measurement.

5.   You can test connectivity beyond ICMP too, using hping3. This uses TCP by default,

and you can send TCP syn packets to a host by using the following command:                [h3]# hping3 --syn 10.0.0.1                                                                                                         You can also change the rate of the pings with the following options:

[h3]# hping3 --faster 10.0.0.1                                                                                                   

6.   Finally, you can use Wireshark to see the packets being sent and received on a given  interface. To open wireshark, open a new terminal, and run the following command:   $ sudo wireshark   

Once it has opened in a new window and has discovered the interfaces, select s1- eth1 and click start. This will monitor the packets along the link connecting h1 and the switch(s1). Running the same hping3 command as the syn generator shown     before, you can confirm that they are being sent.

[h1]# hping3 --syn 10.0.0.2                                                                                                        

Spend a few minutes generating different types of packets and monitoring them on wireshark. You can also type tcp in the filter, which only show you tcp packets.

Create Your own Topology

Using Mininet solely via the mn command can become restrictive quickly. Custom         topologies can be easily defined using a simple Python API. A simple custom topology   example is topo-2sw-2host.py. This example connects two switches directly, with a single host connected on each switch.

To download this file, please use the Web browser in VM to log in to the Moodle page of      this module and download the file topo-2sw-2host.py. You can find the downloaded file in Downloads. Please then move the file to Documents.

To read this file, you can double click on it. The functions used are explained below.

▪   self.addHost( 'h1' ) adds a host called h1

▪   self.addSwitch( 's1' ) adds a switch called s1

▪   self.addLink( ... ) creates a link between 2 nodes

To run it, you can first exit the Mininet and do a clean-up:


mininet> exit

$ sudo mn -c


Then, you can type the following in your terminal:


$ cd Documents

$ ls


which will show you the files in the Documents folder.

You can then use the following command to run the custom topology:


$ sudo mn --custom topo-2sw-2host.py --topo mytopo


Using the custom topology provided in the file topo-2sw-2host.py, you can build more

complex topologies, by applying theTopo classof Mininet.

Please finish the following sub-tasks. Please note that these tasks 1.1 and 1.2 won’t be assessed. You should use these tasks to get familiar with Mininet.

1.1 Create a topology that represents the following topology diagram (Figure 2). Save the file as custom_topo.py in the folder Documents. To test your     topology, you can navigate to the folder Documents and use the following   command:


$ sudo mn --custom custom_topo.py --topo mytopo


 

Figure 2 custom topology diagram

1.2 After creating the above topology, please test the connectivity by pinging all nodes.

Setting Performance Parameters

You have now created a network topology based on the given network diagram. Based on  that, now let’s look at the performance limits. In addition to basic behavioural networking, Mininet provides performance limiting and isolation features, through the CPULimitedHost and TCLink classes.

When the custom topology was created, the following methods were used:

▪   self.addHost( 'h1' ) adds a host called h1

▪   self.addSwitch( 's1' ) adds a switch called s1

▪   self.addLink( ... ) creates a link between 2 nodes

They can be more powerful than that. self.addHost(name, cpu=f) allows you to specify a fraction of overall system CPU resources which will be allocated to the virtual host.

self.addLink( node1, node2, bw=10, delay='5ms', max_queue_size=1000, loss=10,                     use_htb=True) adds a bidirectional link with bandwidth, delay and loss characteristics, with a maximum queue size of 1000 packets using the Hierarchical Token Bucket rate limiter and     netem delay/loss emulator. The parameter bw is expressed as a number in Mb/s; delay is      expressed as a string with units in place (e.g., '5ms', '100us', '1s'); loss is expressed as a           percentage (between 0 and 100); and max_queue_size is expressed in packets.

Please finish the following sub-tasks and answer the questions. Please note that these tasks will be assessed.

1.3 Please complete a new Python script named custom_topo_perf.py. Based on the topology created that represents Figure 2, please add a synthetic delay of 10ms on the link between h2 and s1, a 5ms delay between h3 and s2. Also, add a synthetic bandwidth limit of 50Mb/s on the link between h1 and s1. You might need to add cls=TCLink in the self.addLink(…). For example, self.addLink(node1, node2,             cls=TCLink,…).

1.4 Use tools such as iperf and ping to prove the limits imposed on your network.

Q1: After adding the performance limits, please use ping to get the delay between h1 and h2. What is the first delay your ping gets? Please provide your explanations.

Q2: What is the average delay your ping gets? Please provide your explanations.

Note: You need to include screenshots of your terminal window in your answers.

Using OVS-OFCTL

Now let’s get going with OpenFlow (OF). OpenFlow is a Software Defined Networking          control protocol that enables researchers to create new methods of controlling and             extending computer networks. OpenFlow is added as a feature to commercial Ethernet       switches, routers and wireless access points and provides a standardized hook to allow       researchers to run experiments, without requiring vendors to expose the internal workings of their network devices.

An OpenFlow switch separates its logic into the data plane and the control plane. The data plane forwards packets based on entries in the flow table. An entry is split into 3 parts: the match, the action, and the stats. The stats part is set by the switch and stores data such as counters. The match is a series of fields that represent what packets to perform the action on. The action represents how a packet with the correct match fields in its header will be   forwarded. A simplified template:

 

To create a network in the VM, in the terminal, enter:


$ sudo mn --topo single,3 --mac --switch ovsk --controller remote


This tells Mininet to start up a 3-host, single-switch (Open vSwitch-based) topology, set the MAC address of each host equal to its IP, and point to a remote controller which defaults to the localhost.

Here's what Mininet just did:

▪   Created 3 virtual hosts, each with a separate IP address.

▪   Created a single OpenFlow software switch in the kernel with 3 ports.

▪   Connected each virtual host to the switch with a virtual ethernet cable.

▪   Set the MAC address of each host equal to its IP.

  Configure the OpenFlow switch to connect to a remote controller.

The topology now looks like this:

 

Now, you may have noticed that the control plane is set as remote, but we have no           controller running. Thus, the switch has no forwarding logic and an empty flow table. You can see this by running a ping… that will fail:


mininet> h1 ping -c3 h2


You should receive the error message of ‘Destination Host Unreachable’ . This is because     switch flow table is empty. Besides that, there is no controller connected to the switch and therefore the switch doesn't know what to do with incoming traffic, leading to ping failure.

You can use ovs-ofctl command to manually add flow entries. ovs-ofctl is a utility that comes with Open vSwitch and enables visibility and control over a single switch's flow table. You      should use this for seeing the current content of a switch’s flow table and for adding and       removing flow entries.

Start a new terminal window and run the following commands:


$ sudo ovs-ofctl add-flow s1 in_port=1,actions=output:2

$ sudo ovs-ofctl add-flow s1 in_port=2,actions=output:1


These represent the following entries (where * is a wildcard):

 

This indicates that the switch will forward packets coming at port 1 to port 2 and vice-versa. Now running the ping should work:


mininet> h1 ping -c3 h2


You can also check what entries are in the flow table with:


$ sudo ovs-ofctl dump-flows s1


Then, let’s make sure the switch has no existing flows using the command below.


$ sudo ovs-ofctl del-flows s1


The forwarding rules introduced above are port-based. You now need to get the ping work by using IP address-based rules.

You can get some help with ovs-ofctl with the following command or checkhere:

$ man ovs-ofctl                                                                                                                                           

Please complete the following sub-tasks and answer the questions. Please note that these tasks will be assessed.

1.5 Please first make sure there is no existing flows in the flow table by using del-flows command. Then, add the following entries to the flow table:

$ sudo ovs-ofctl add-flow s1 dl_type=0x800,nw_src=10.0.0.1,actions=output:2 $ sudo ovs-ofctl add-flow s1 dl_type=0x800,nw_src=10.0.0.2,actions=output:1

Now, run the ping:


mininet> h1 ping -c3 h2


Q3: Do the pings work? What is the reason? Please provide your explanations.

Based on the two flow entries we give, please add any necessary flow rules that can get the pings between h1 and h2 work.

Now, run the pingall command:


mininet> pingall


Q4: In your case, do the pings between h3 and the other nodes work? What is the reason? Please provide your explanations.

Q5: Now, if you are asked to rewrite the flow entries (you can delete all the existing flows) to get the pingall work (which means all three nodes can connect), what are the minimal IP address-based flow entries you would add? Please provide results and explanations.

1.6 Based on the connected network (all nodes can ping each other), using ovs-ofctl, add flow entries that will drop UDP packets coming from the host with the IP 10.0.0.3.     You can test this with hping3.

You can get some help with hping3 with the following command:


$ man hping3


Q6: Please take the screenshots to show the flow entries you added, the test command you used and the results. Why do you use them? Please provide your explanations.

Note: You need to include screenshots of your terminal window in your answers.

Marking Criteria

What you will need to submit:

•   For the tasks 1.3 and 1.4, the completed Python file named custom_topo_perf.py

•   A report including

1)   for the tasks 1.3 and 1.4, the screenshot of your Python code in        custom_topo_perf.py; the explanations and terminal outputs (using screenshots) that answer the questions Q1 and Q2

2)   for the tasks 1.5 and 1.6, the explanations, the commands and terminal outputs (using screenshots) that answer the questions Q3-Q6

You will be awarded the majority of marks for Python script and completed tasks. You need to make sure the submitted work meet the requirements given in the Task documentation.

References:

Mininet

Mininet Wiki

Mininet Walkthrough