Mininet

here for website of introduce to this tool

  • Author: Bob Lantz
  • Network Emulator; Python


What is Mininet?

Mininet is a network emulator, or perhaps more precisely a network emulation orchestration system. It runs a collection of end-hosts, switches, routers, and links on a single Linux kernel.

You can send packets through what seems like a real Ethernet interface.
Packets get processed by what looks like a real Ethernet switch, router, or middlebox, with a given amount of queueing.

Iperf 是一个网络性能测试工具。Iperf可以测试最大TCP和UDP带宽性能,具有多种参数和UDP特性,可以根据需要调整,可以报告带宽、延迟抖动和数据包丢失。

Why is Mininet cool?

fast

create custom topology

run real program

customize packet forwarding

run Miniet on your laptop

share and replicate results

open source https://github.com/mininet

under active development

Working with Mininet

1.Creating Topologies

2.

host-only顾名思义,这种技术提供的是主机和虚拟机之间的网络互访,而不是虚拟机访问internet的技术。在某些特殊的网络调试环境中,要求将真实环境和虚拟环境隔离开(就是说不希望外网环境访问虚拟机,也不希望虚拟机访问外网环境),这时你就可采用host-only模式。在host-only模式中,所有的虚拟系统是可以相互通信的,但虚拟系统和真实的网络是被隔离开的。

Mininet walkthrough

Mininet代码合集,网课

1
sudo mn --test pingall  --topo single,3

此代码可以用来测试mininet下的拓扑结构。

1
sudo dhclient eth0

1
ifconfig {interface} {up|down}

查询、设置网卡和IP网段等相关参数
HWaddr:网卡的硬件地址,习惯称为MAC。
eth0:网卡的代号,也有lo这个loopback。

1
[root@linux ~]# ifconfig eth0 192.168.100.100

暂时修改网络接口.

1
2
[root@linux ~]# ifconfig eth0:0 down
[root@linux ~]# ifconfig eth1 up

关掉 eth0:0 这个接口;启动 eth1 这个接口。

1
2
3
4
[root@linux ~]# ip [option] [操作] [命令]
[root@linux ~]# ip link set eth0 up
[root@linux ~]# ip link set eth0 down
[root@linux ~]# ip route show

使用ip link show能显示出整个设备接口的硬件相关信息

使用ip link up可以打开某个设备

使用ip link down可以关掉某个设备

使用ip address show;ip route show


1
[root@linux ~]# dhClient eth0

想要重新取得ip但不希望网络中断。我们可以使用过dhclient
dhclient是主动向DHCP Server要求IP的指令..
如果只想对eth0这张网卡要求新的IP,可以使用dhclient eth0
-r 参数表示只释放


Mininet Command:

1
[root@linux ~]# mn --topo

定义了拓扑的格式

1
[root@linux ~]# mn --switch

定义了Switch的格式,默认OVSK

1
[root@linux ~]# mn --controller

定义了controller的格式,默认default hub

1
sudo mn --topo tree,depth=2,fanout=2

tree-like topology

How mn works: mn execute python code.

you can create your own code by python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from mininet.topo import Topo
from mininet.net import Mininet
net= Mininet()

# Create nodes in the network
c0 = net.addController()
h0 = net.addHost("h0")
s0 = net.addSwitch("s0")
h1 = net.addHost("h1")

# Create Links between nodes in network(2-ways)
net.addLink(h0,s0)
net.addLink(h1,s0)

# Configuration of IP addresses in the interfaces
h0.setIP("192.168.1.1",24)
h1.setIP("192.168.1.2",24)

net.start()
net.pingAll()
mininet.cli.CLI(net)
net.stop()

mininet.cli.CLI(net) 跳回命令行界面

addLink 可以更细粒度调整网络链接属性

setting link speed and properties

using custom controllers and switches

host configuration

performance measurement

see you tmr