An Instant Virtual Network on your Laptop (or other PC),Mininet creates arealistic virtual network, runningreal kernel, switch and application code, on a single machine (VM, cloud or native)。
Mininet是一个软件工具或者说是一个网络仿真器,可以用它来定义各种网络资源,比如交换机、路由器以及终端节点,并以此生成各种逼真的SDN网络。在这个网络中,host就像我们平时用的电脑一样(当然是linux系统的),支持ssh远程登录,启动应用程序,程序可以向以太网端口发送数据包,数据包会被交换机、路由器接收并处理。正因为mininet的创建的网络可以和真实的网络环境相媲美,mininet多被用来搭建各种网络环境进行相关的测试。
在这里可以下载mininet虚拟机镜像,然后通过kvm、vmware或者virtbox进行安装,简单的说就是起一个minine的虚拟机。(这个个人用的比较少,推荐下面第二种方式)
进入一个linux系统的主机(或则虚拟机)中镜像安装,下面以在uubuntu中安装为例:
注意:mininet only supports Ubuntu|Debian|Fedora|RedHatEnterpriseServer|SUSE LINUX
(1) 先更新系统
apt-get update
(2) 如果没有git命令,先按照git
apt-get install git
(3) 克隆mininet源码
git clone git://github.com/mininet/mininet
(4) 选择源码版本
#进入mininet目录
cd mininet
#列出可用的版本
git tags
#选择可用的版本
git checkout -b 你想用的版本号
(5) 安装
#进入安装脚本目录
cd mininet/util/
#执行安装脚本 :
./install.sh [options]
[options]:
#To install everything (using your home directory):
install.sh -a
#To install everything (using another directory for build):
install.sh -s mydir -a
#To install Mininet + user switch + OVS (using your home dir):
install.sh -nfv
#To install Mininet + user switch + OVS (using another dir:)
install.sh -s mydir -nfv
(6) 验证
root@ubuntu:~# sudo mn --test pingall
*** Creating network
*** Adding controller
--------------------------------------------------------------------------------
Caught exception. Cleaning up...
Exception: Please shut down the controller which is running on port 6653:
Active Internet connections (servers and established)
tcp 0 0 0.0.0.0:6653 0.0.0.0:* LISTEN 11895/controller
tcp 0 0 127.0.0.1:6653 127.0.0.1:50560 ESTABLISHED 11895/controller
tcp 0 0 127.0.0.1:50560 127.0.0.1:6653 ESTABLISHED 11358/ovs-vswitchd
tcp 0 0 127.0.0.1:50570 127.0.0.1:6653 TIME_WAIT -
--------------------------------------------------------------------------------
*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes
killall controller ofprotocol ofdatapath ping nox_corelt-nox_core ovs-openflowd ovs-controllerovs-testcontroller udpbwtest mnexec ivs ryu-manager 2> /dev/null
killall -9 controller ofprotocol ofdatapath ping nox_corelt-nox_core ovs-openflowd ovs-controllerovs-testcontroller udpbwtest mnexec ivs ryu-manager 2> /dev/null
pkill -9 -f "sudo mnexec"
*** Removing junk from /tmp
rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log
*** Removing old X11 tunnels
*** Removing excess kernel datapaths
ps ax | egrep -o 'dp[0-9]+' | sed 's/dp/nl:/'
*** Removing OVS datapaths
ovs-vsctl --timeout=1 list-br
ovs-vsctl --if-exists del-br s1
ovs-vsctl --timeout=1 list-br
*** Removing all links of the pattern foo-ethX
ip link show | egrep -o '([-_.[:alnum:]]+-eth[[:digit:]]+)'
( ip link del s1-eth1;ip link del s1-eth2 ) 2> /dev/null
ip link show
*** Killing stale mininet node processes
pkill -9 -f mininet:
*** Shutting down stale tunnels
pkill -9 -f Tunnel=Ethernet
pkill -9 -f .ssh/mn
rm -f ~/.ssh/mn/*
*** Cleanup complete.
root@ubuntu:~# mn --version
2.3.0d4
1. mininet的启动参数
root@ubuntu:~# mn --help
Options:
-h, --help 显示帮助信息
--switch=SWITCH 指定交换机类型
default|ivs|lxbr|ovs|ovsbr|ovsk|user[,param=value...]
ovs=OVSSwitch default=OVSSwitch ovsk=OVSSwitch
lxbr=LinuxBridge user=UserSwitch ivs=IVSSwitch
ovsbr=OVSBridge
--host=HOST #用于选择主机的类型
cfs|proc|rt[,param=value...]
rt=CPULimitedHost{'sched': 'rt'} proc=Host
cfs=CPULimitedHost{'sched': 'cfs'}
--controller=CONTROLLER 控制器种类
default|none|nox|ovsc|ref|remote|ryu[,param=value...]
ovsc=OVSController none=NullController
remote=RemoteController default=DefaultController
nox=NOX ryu=Ryu ref=Controller
--link=LINK 链路的类型
default|ovs|tc|tcu[,param=value...] default=Link
ovs=OVSLink tcu=TCULink tc=TCLink
--topo=TOPO 指定网络拓扑的类型
linear|minimal|reversed|single|torus|tree[,param=value
...] linear=LinearTopo torus=TorusTopo tree=TreeTopo
single=SingleSwitchTopo
reversed=SingleSwitchReversedTopo minimal=MinimalTopo
-c, --clean 清除和退出
--custom=CUSTOM 定制网络拓扑的py文件
--test=TEST 测试
none|build|all|iperf|pingpair|iperfudp|pingall
-x, --xterms 打开终端节点
-i IPBASE, --ipbase=IPBASE 设置起始ip
--mac 自动设置主机mac,保证mac简单、易读,一般都尽量小
--arp 设置所有对ARP入口
--innamespace sw and ctrl in namespace?
--listenport=LISTENPORT 设置监听端口
--nolistenport 不监听端口
--pin pin hosts to CPU cores (requires --host cfs or --host
rt)
--nat [option=val...] adds a NAT to the topology that
connects Mininet hosts to the physical network.
Warning: This may route any traffic on the machine
that uses Mininet's IP subnet into the Mininet
network. If you need to change Mininet's IP subnet,
see the --ipbase option.
--cluster=server1,server2...
run on multiple servers (experimental!)
--placement=block|random
node placement for --cluster (experimental!)
(2)使用"mn"进入mininet终端后
mininet> help
Documented commands (type help ):
========================================
EOF gterm iperfudp nodes pingpair py switch
dpctl help link noecho pingpairfull quit time
dump intfs links pingall ports sh x
exit iperf net pingallfull px source xterm
You may also send a command to a node using:
command {args}
For example:
mininet> h1 ifconfig
The interpreter automatically substitutes IP addresses
for node names when a node is the first arg, so commands
like
mininet> h2 ping h3
should work.
Some character-oriented interactive commands require
noecho:
mininet> noecho h2 vi foo.py
However, starting up an xterm/gterm is generally better:
mininet> xterm h2
#nodes 查看全部节点
#net 查看链路信息
#dump 输出各节点的信息
#h1 ping -c 4 h2 测试主机之间的连通性
#iperf 两个节点之间用指定简单的 TCP 测试
#iperfudp 两个节点之间用指定款单 udp 进行测试
#noecho 运行交互窗口,关闭回应
#pingpair 两个主机将互 ping
#help 列出命令文档,查看命令帮助: help command
#dpctl 流表类操作
#exit/quit 退出 mininet 命令行
#hX ifconfig 查看当前那主机的 ip 地址,如: h1 ifconfig
#py/sh 执行 python 表达式或运行外部 shell 程序