Task 2: Mininet Network Configuration
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 2
▪ Learn the basic commands in Mininet
▪ Learn how to create basic network topologies in Mininet
▪ Learn Mininet API
▪ Learn how to measure network performance in Mininet
▪ Gain insights into examining delay, loss, and throughput for a given network topology
Using commands from a host’s xterm window is usually best. (Note: for xterm to work over SSH, your host needs to be running an X Server and the -X flag must be used for the SSH connection.)
After you have exited Mininet using exit, run the command sudo mn -c to run a clean-up.
Custom Topologies
1. In the first step, we start a simple network topology by running the following command:
mininet>sudo mn
To display an xterm for host h1, run the following command. This will be useful to run commands within a host or switch.
mininet>xterm h1
If the first part of a command in Mininet is py, then the CLI interprets the command as a Python command. This helps you to manipulate the network objects, such as hosts, switches, and controllers, using the CLI. Here is an example which displays the IP address of host h1.
mininet>py h1.IP()
2. Mininet supports a simple Python API to create custom network topologies. You can create your custom topology by writing a few lines of Python code that you were asked to create a simple topology in task 1.
Now assume that we want to accomplish the following:
• Create the topology shown in Figure 1
• Start the network
• Show the detailed connectivity of all nodes in the network
• Test the connectivity by pinging all nodes
We can automate this sequence of operations by writing a Python script. This helps us to automate network experiments, as shown in Figure 1.
Figure 1 Source code for an experiment on the custom topology.
Then you could save source code in a file named myfirstexpr.py and run the following command:
mininet>sudo python myfirstexpr.py
Remember to clean up (sudo mn –c) and also to save your work in your CSE home directory before moving forward.
Mininet Python Classes
The Mininet Python API consists of a number of Python classes, such as Topo, Mininet, Host, Switch, Link and their subclasses. The API is built at three primary levels which provide different level of abstractions for customising the network topologies. Here is a brief description of the levels:
• Low-level API: This API includes the base node and link classes such as Host, Switch and Link. You can directly instantiate some objects from these classes to create a network.
• Mid-level API: This API consists of the Mininet class which provides a number of methods, such as addHost(), addSwitch(), and addLink(), for creating a network.
• High-level API: This API consists of the Topo class, which provides the ability to create reusable, parameterised topology templates. These templates can be passed to the mn command (via the –custom option as in Part 2 above) and used from the command line.
The above figure 1 shows how to use the high-level API. As you can see, the high-level API provides an object-oriented framework by presenting the Topo class. You can find the detailed documentation of all classes provided in the Mininet Python API in http://mininet.org/api/annotated.html.
Network-testing tool
The iperf tool is a commonly used network-testing tool for measuring the bandwidth and quality of a network link. The tool can create TCP and UDP data streams and measure the throughput of a network that is carrying these streams. The iperf tool implements both client and server functionality and can measure the throughput between the two end hosts, either uni-directionally or bi-directionally.
Figure 2 A sample client/server in Iperf.
For more information about the iperf tool and bandwidth monitoring in general, refer to the following:
• The article titled “Testing Network Performance with Iperf” which is available on the lab resources page.
• The link: http://openmaniak.com/iperf.php.
• An overview of bandwidth monitoring tools for Ubuntu users in
Please finish the following small tasks:
In this exercise you will work with a linear topology, as shown in Figure 3. A linear topology consists of an equal number (𝑛 in Figure 3) of hosts and switches such that each host is connected to one switch and the switches are connected as a linear topology. Figure 4 shows (incomplete) sample code for implementing the linear topology using the high-level Python API provided by Mininet
1. Complete the source code shown in Figure 4. In particular, you will need to complete function init in the code. Include your source code as lineartoplogy_experiment.py with your submission.
Figure 3 Hosts and switches connected in a linear topology.
Figure 4 Template code for an experiment on a linear topology.
Figure 5 Simple method for performance experiment.
2. The SimpleTest method in the code above initiates a ping test (pingAll()) amongst all
Computer Science Tutoring
hosts. Figure 5 shows a simple experiment method called perfTest. The experiment executes the iperf tool between two hosts h1 and h4.
3. Add this experiment to the linear topology code and execute it as above.
Question 1: Report and explain the results of the above experiment.
Learning to use network configuration
In addition to basic behavioural networking, Mininet provides performance limiting and isolation features, through the CPULimitedHost and TCLink classes. There are multiple ways that these classes may be used, but one simple way is to specify them as the default host and link classes/constructors to Mininet(), and then to specify the appropriate parameters in the topology.
There are two important performance settings supported by the Mininet classes. The first one is for configuring the CPU resources in a host machine. To this end, method self.addHost(name, cpu=f) is used for defining a host. The second argument in this method allows you to specify a fraction of overall system CPU resources which will be allocated to the virtual host.
The second method is self.addLink( node1, node2, opts), where opts refers to link options. For example, the statement self.addLink( node1, node2, bw=10, delay=’5ms’, max_queue_size=1000, loss=1, use_htb=True) adds a bidirectional link with bandwidth of 10 Mb/s, (propagation) delay of 5ms, loss rate of 1% (i.e. 1 packet out of 100 packets is lost) and a maximum queue size of 1000 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 maximum_queue_size is expressed in packets.
You may find it useful to create a Python dictionary to make it easy to pass the same parameters into multiple method calls. There are two ways to specify the dictionary as indicated below:
Figure 6 Configuring link performance parameters.
Measurement in Mininet
In this exercise you are asked to work on topology shown in Figure 7. As you can see, the network consists of three links L1 (s1-s2), L2 (s2-s3) and L3 (s3-s4). The bandwidth and delay for these links are shown in Table 1.
Figure 7 Network topology for Exercise 4.
Table 1 The bandwidth and delay for links in topology shown in Figure 7.
L1 20 10 L2 10 15 L3 20 20
Question 2: Write a Python script for generating the network topology shown in Figure 7 and performance parameters reported in Table 1. Store and submit your script in a file named exercise2_topo.py.
Question 3: Measure the RTT and TCP throughput between h1 and h5 using the ping and iperf tools. Store the output in files called RTT.txt and throughput.txt. Report average RTT and throughput in your submission and explain the results. Include all text files in your submission.
CS Help, Email: tutorcs@163.com
Useful Resources
• Introduction to Mininet: https://github.com/mininet/mininet/wiki/Introduction-to-Mininet
• Mininet Walkthrough: http://mininet.org/walkthrough/
• Mininet Python API Reference Manual: http://mininet.org/api/annotated.html
Marking Criteria
You are asked to finish 3 questions in Task 2, here’s what you will need to submit:
• A brief report in question 1
• Completed Python file exercise2_topo.py that achieves the above small tasks
• txt files in Question 3 which should measure the RTT and TCP throughput.
The submitted script, report and output will account for 20% and 80% of the total marks.
浙大学霸代写 加微信 cstutorcs