Teaching objectives and suggestions for class hours

  1. Ability to create computer network topologies using mininet visualization tools
  2. Ability to create topologies using mininet interface
  3. Ability to build computer network topologies using Python scripts
  4. Suggestion: 2 credit hours

Experimental environment

  1. Download and install VMware Workstation.
  2. Download the VM image (sdnhub_tutorial_vm_64-bit [NEW]), ****Baidu web disk download linkExtraction code: MHFI
  3. Because the VM image is in OVA format, you only need to open it and use it without creating a vm.
  4. Using the command line, installing packages,Refer to the article

Technical and knowledge background

1. What is a Mininet?

  1. Mininet is a network connected by virtual end-hosts, switches, and routersEmulator, is a lightweight software defined network and test platform; It uses lightweight virtualization technology to make a singleThe system looks like a complete network running thought of kernel system and user code, can also be simply understood as SDN network.
  2. A process-based virtualization platform in the system, which supports OpenFlow, OpenvSwith and other protocols. Mininet can also simulate a complete network host, link and switch on the same computer and facilitate interactive development, testing and demonstration. Especially those using OpenFlow and SDN; You can also migrate the virtualized platform code of this process to a real environment.
  3. Mininet makes it easy to create an SDN enabled network: hosts work just like real computers and can be logged in using SSH to launch applications that can send packets to Ethernet ports, which are received and processed by switches and routers. With this network, you have the flexibility to add new functionality and test it, and then easily deploy it to a real-world hardware environment.

2. Features of Mininet:

  1. You can easily and quickly create a network topology that supports user customization, shortening development and test cycles
  2. You can run real programs. Almost any program running on Linux can run on Mininet, such as Wireshark
  3. Mininet supports Openflow, and code running on Mininet can be easily ported to openFlow-enabled hardware devices
  4. Mininet can run on your own computer, or on a server, or on a virtual machine, or in the cloud (such as Amazon EC2)
  5. Mininet provides a Python API that is easy to use
  6. Mininet is open source

3. Mininet partial commands

4. Command operation

  • The terminal type mn to create a simple network. After creation, the command line becomes mininet>
  • Mininet>iperf — Network performance test between two nodes

  • Mininet> route – Similar to the Linux command, used to define entries in the node routing table

  • Mininet>help

  • Mininet>nodes

  • Mininet>net

  • Mininet>pingall

​​​​​​​

  • Mininet>dump

​​​​​​​

  • Mininet>h1 ping h2

​​​​​​​

  • Mininet>h2 ifconfig

​​​​​​​

  • Mininet>xterm h1

​​​​​​​

  • Mininet>exit

​​​​​​​

  • More Operation Commands

Test whether Mininet works properly

  • To quickly check if it works, type the following command:

  • This command will:

  • Create a single network with three hosts connected to a single switch in non-interactive mode.

  • Ping from all hosts to all other hosts.

  • This command uses the default switch and controller.

    sudo mn –test pingall –topo single,3

  • Command on

​​​​​​​

Create the topology

  • Create network topology using mininet visualization tools
  • Create a network topology using the Mininet command line tool
  • Use mininet interface to create network topology
  • Use Python scripts to build network topologies
  • Refer to the blog

Basic command-line arguments — you’ll find them later

  1. — Topo — Define the topology from the command line when Mininet starts
  2. –switch — Define the switch to use. By default, ovSK software switches are used
  3. — Controller — Defines the controller to use. If no default controller is specified, it is used as a hub

Visual tools to create topologies

  • After importing the image, the default location is /home/Ubuntu. You can use PWD to view the current path and adjust it dynamically. Into the/home/ubuntu/mininet/examples folder, use the command CD
  • Run sudo su to switch to root and run Python miniedit.py to start the visualization
  • Follow the steps and page layout below

  • Right-click the icon and select Preferences to configure the network topology. The default Settings are used, that is, no operation is performed.
  • Click Edit → Preferences, select Strat CLI (allow topology modification through interactive interface), and select the supported Openflow protocol version.

  • Save the File as a Python File, select “File” → “Export Level 2 Script”, give a name, and run the saved Python File on the terminal.
  • Or click run in the lower left corner. If you need to stop, click Stop.

Command line to create a topology

  • Minimum network, two hosts are connected to one switch.
  • Sudo mn – topo minimal

  • Each host is connected to a switch, and all switches are connected to each other.
  • In this case, there are four hosts and four switches.
  • sudo mn –topo linear,4

  • The picture below is pure fiction, please refer to the real object

  • Each host is connected to a switch.
  • In this example, there are three hosts and one switch.
  • sudo mn –topo single,3

  • The picture below is pure fiction, please refer to the real object

  • Tree-based topology with defined depth and fan out.
  • sudo mn –topo tree,depth=2,fanout=2

  • The picture below is pure fiction, please refer to the real object

Interactive Topology Creation

Summary of Startup Parameters

  • -h, –help show this help message and exit
  • –switch=SWITCH [kernel user ovsk]
  • –host=HOST [process]
  • –controller=CONTROLLER [nox_dump none ref remote nox_pysw]
  • –topo=TOPO [tree reversed single linear minimal],arg1,arg2,… argN
  • -c, –clean clean and exit
  • –custom=CUSTOM read custom topo and node params from .py file
  • –test=TEST [cli build pingall pingpair iperf all iperfudp none]
  • -x, –xterms spawn xterms for each node
  • –mac set MACs equal to DPIDs
  • –arp set all-pairs ARP entries
  • -v VERBOSITY, –verbosity=VERBOSITY [info warning critical error debug output]
  • –ip=IP [ip address as a dotted decimal string for aremote controller]
  • –port=PORT [port integer for a listening remote controller]
  • –innamespace sw and ctrl in namespace?
  • –listenport=LISTENPORT [base port for passive switch listening controller]
  • –nolistenport don’t use passive listening port
  • –pre=PRE [CLI script to run before tests]
  • –post=POST [CLI script to run after tests]

Python scripts define the topology

  • To create a topology using the python script, add the executable permission chmod +x test.py to the file.
  • –topo linear,4
  • Operation:
  1. Create a New Python file called Linear, touch Linear
  2. Grant permission to chmod +x linear.py
  3. Write to the file vi Linear.py
  4. Copy and paste the following code into the linear.py file, press I to enter; Right mouse button, select paste code; Press the Esc key, shift and: at the same time, then type wq to save the code; # -*- coding: utf8 -*-
  5. Run the code sudo Python Linear
  6. View the output
  • code

    from mininet.net import Mininet from mininet.topo import LinearTopo Linear4 = LinearTopo(k=4) net = Mininet(topo=Linear4) net.start() net.pingAll() net.stop()

  • practice

  • –topo single,3
  • Operation:
  1. Create a New Python file called touch single.py with the name single
  2. Grant permission to chmod +x single.py
  3. Write to the file vi single.py
  4. Copy and paste the following code into the single.py file and press I to enter. Right mouse button, select paste code; Press the Esc key, shift and: at the same time, then type wq to save the code;
  5. Run the code sudo Python single.py
  6. View the output
  • Code:

    from mininet.net import Mininet from mininet.topo import SingleSwitchTopo Single3 = SingleSwitchTopo(k=3) net = Mininet(topo=Single3) net.start() net.pingAll() net.stop()

  • practice

  • –topo tree,depth=2,fanout=2
  • Operation:
  1. Create a python file named tree called touch tree.py
  2. Grant permission to chmod +x tree.py
  3. Write to the file vi tree.py
  4. Copy and paste the following code into the tree.py file. Press I to enter. Right mouse button, select paste code; Press the Esc key, shift and: at the same time, then type wq to save the code;
  5. Run the code sudo Python tree.py
  6. View the output
  • Code:

    from mininet.net import Mininet from mininet.topolib import TreeTopo Tree22 = TreeTopo(depth=2,fanout=2) net = Mininet(topo=Tree22) net.start() net.pingAll() net.stop()

  • practice

  • Limitations on performance
  • Operation:
  1. Create a new Python file named test, touch test.py
  2. Grant permission to chmod +x test.py
  3. Run vi test.py to write to the file
  4. Copy and paste the following code into the test.py file. Press I to enter. Right mouse button, select paste code; Press the Esc key, shift and: at the same time, then type wq to save the code;
  5. Run the code sudo Python test.py
  6. View the output
  • Explanation:

In addition to the basic topology that can be created through Python scripts, performance can be limited on this basis. Looking at the script file given below, the addHost() syntax sets the host CPU as a percentage; The addLink() syntax allows you to set bandwidth BW, delay, maximum queue size max_queue_size, and loss.

  • Code:

    from mininet.net import Mininet from mininet.node import CPULimitedHost from mininet.link import TCLink net = Mininet(host=CPULimitedHost, link=TCLink) c0 = net.addController() s0 = net.addSwitch(‘s0’) h0 = net.addHost(‘h0’) h1 = net.addHost(‘h1’, CPU =0.5) h2 = net.addHost(‘h1′, CPU =0.5) net.addLink(s0, h0, bw=10, delay=’5ms’, max_queue_size=1000, loss=10, use_htb=True) net.addLink(s0, h1) net.addLink(s0, h2) net.start() net.pingAll() net.stop()

  • practice