Ubuntu安装Mininet

Ubuntu安装Mininet

一、安装

apt-get update
apt-get upgrade
apt-get update --fix-missing
apt-get install git
#下载mininet
git clone https://github.com/mininet/mininet.git
cd mininet
#选择版本
git tag       
git checkout 2.2.0
#执行安装脚本
util/install.sh
#验证安装
sudo mn
#检查安装是否成功
sudo mn --test pingall

#如果出现报错
apt-get update
apt-get upgrade
apt-get install net-tools

#查看帮助
mininet/util/install.sh -h
 -a: (default) install (A)ll packages - good luck!
 #测试控制器性能工具
 -b: install controller (B)enchmark (oflops)
 -c: (C)lean up after kernel install
 -d: (D)elete some sensitive files from a VM image
 -e: install Mininet d(E)veloper dependencies
 -f: install Open(F)low
 -h: print this (H)elp message
 -i: install (I)ndigo Virtual Switch
 -k: install new (K)ernel
 -m: install Open vSwitch kernel (M)odule from source dir
 #安装mininet核心
 -n: install Mini(N)et dependencies + core files
 -p: install (P)OX OpenFlow Controller
 -r: remove existing Open vSwitch packages
 -s : place dependency (S)ource/build trees in 
 -t: complete o(T)her Mininet VM setup tasks
 #安装默认版本
 -v: install Open (V)switch
 #安装指定版本
 -V : install a particular version of Open (V)switch on Ubuntu
 -w: install OpenFlow (W)ireshark dissector
 -y: install R(y)u Controller
 -x: install NO(X) Classic OpenFlow controller
 -0: (default) -0[fx] installs OpenFlow 1.0 versions
 -3: -3[fx] installs OpenFlow 1.3 versions
 #安装比较久

二、命令

#网络构建启动参数
--topo
--custom
--switch
--controller
--max
#内部交互命令
dump
net
nodes
links
dpctl
iperf
#外部运行参数
-c #清除配置信息
-h #帮助

1. 网络构建启动参数

– –topo

  • 单一拓扑(single)

    整个网络拓扑中交换机有且只有一个,他可以下挂一个或者多个主机

    sudo mn --topo=single,3
    #一个交换机下挂3个主机
    (h1,s1)(h2,s1)(h3,s1)
    
single.png
  • 线形拓扑(linear)

    交换机连接呈现线形排列,且每个交换机所连接主机数目只有一个(交换机和主机数目是相同的)

sudo mn --topo=linear,4
#4个交换机,4个主机
(h1,s1)(h2,s2)(h3,s3)(h4,s4)
linear.png
  • 树形拓扑(tree)

    交换机连接成树形排列,且每个交换机所连接主机一般有多个

    sudo mn --topo=tree,depth=2,fanout=2
    #depth:交换机有两层
    #fanout:交换机有两个
    #主机不包含在depth中
    (s1,s2)(s1,s3)(h1,s2)(h2,s2)(h3,s3)(h4,s3)
    
tree.png
  • 自定义拓扑(custom)

    Python编写文件file.py,执行此脚本即可创建定义的拓扑,– –custom与– –topo联用

    sudo mn --custom file.py --topo mytopo
    (s1,s2)(s1,s3)(h1,s2)(h2,s2)(h3,s3)
    
custom.png

– – switch

定义mininet要使用的交换机(默认使用OVSK,即OpenVSwitch交换机)

– – controller

定义要使用的控制其,如果没有指定则使用mininet中默认的控制器

连接远程控制器,可以指定存在于本机或者与值相连通设备上的控制器,指定远程控制器方法:

#remote:远程,port可以使用默认的不写
sudo mn --controller=remote,--ip=[controller IP],--port=[port]

– – mac

自动设置设备的MAC地址

让MAC地址易读,即设置交换机的MAC、主机MAC及IP地址从小到大排序且设置简单唯一,不仅让机器容易获取,也容易让肉眼容易识别其ID,使用方法:

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

2.内部交互命令

使用mn默认创建网络,使用一系列命令查看并验证网络系统的链路健壮性

root@qiu-base:/home/qiu/mininet# sudo mn
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 #两个主机h1,h2
*** Adding switches:
s1 #添加了一个s1交换机
*** Adding links:
(h1, s1) (h2, s1) #添加了交换机和主机的链路
*** Configuring hosts
h1 h2 
*** Starting controller
c0 
*** Starting 1 switches
s1 ...
*** Starting CLI:
# net
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0 #
c0
# nodes
mininet> nodes
available nodes are: 
c0 h1 h2 s1
# links
mininet> links
h1-eth0<->s1-eth1 (OK OK) 
h2-eth0<->s1-eth2 (OK OK) 
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 
h2 -> h1 
*** Results: 0% dropped (2/2 received) #丢包率
#常用内部交互命令
help #显示命令帮助信息
dump #各个节点的信息
intfs #网络接口信息
nodes #查看节点
net #显示链接信息
links #链路健壮性信息
pingpair #只验证前两个host连通性
pingall #验证所有主机间通信
mininet> py net.addHost('h3')
 
mininet> py net.addLink(s1,net.get('h3'))

#attach:添加
mininet> py s1.attach('s1-eth3')
mininet> py net.get('h3').cmd('ifconfig h3-eth0 10.3')
mininet> intfs
h1: h1-eth0
h2: h2-eth0
h3: h3-eth0
s1: lo,s1-eth1,s1-eth2,s1-eth3
c0:

mininet> dump
 
 
 #None,那么我们用ping验证一下
 
 
#
mininet> h1 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=40.5 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.203 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=4 ttl=64 time=0.038 ms
64 bytes from 10.0.0.3: icmp_seq=5 ttl=64 time=0.040 ms
64 bytes from 10.0.0.3: icmp_seq=6 ttl=64 time=0.038 ms
64 bytes from 10.0.0.3: icmp_seq=7 ttl=64 time=0.038 ms
64 bytes from 10.0.0.3: icmp_seq=8 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=9 ttl=64 time=0.050 ms
64 bytes from 10.0.0.3: icmp_seq=10 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=11 ttl=64 time=0.069 ms
64 bytes from 10.0.0.3: icmp_seq=12 ttl=64 time=0.040 ms
64 bytes from 10.0.0.3: icmp_seq=13 ttl=64 time=0.107 ms
^C
--- 10.0.0.3 ping statistics ---
13 packets transmitted, 13 received, 0% packet loss, time 12263ms
rtt min/avg/max/mdev = 0.038/3.168/40.450/10.762 ms
mininet> h2 ping h3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_seq=1 ttl=64 time=39.0 ms
64 bytes from 10.0.0.3: icmp_seq=2 ttl=64 time=0.180 ms
64 bytes from 10.0.0.3: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 10.0.0.3: icmp_seq=4 ttl=64 time=0.039 ms
^C
--- 10.0.0.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3049ms
rtt min/avg/max/mdev = 0.039/9.805/38.965/16.835 ms
#再次使用dump查看
mininet> dump
 
 
 
 
 

三、可视化

MiniEdit(不会python也无所谓)

直接在界面上编辑任意拓扑,生成python自定义拓扑脚本,简单方便

Mininet 2.2.0+(内置miniedit)

/mininet/examples 目录下

root@qiu-base:/home/qiu/mininet# ls
bin           custom  doc       LICENSE   mininet.egg-info  mnexec.1   setup.py
build         debian  examples  Makefile  mn.1              mnexec.c   util
CONTRIBUTORS  dist    INSTALL   mininet   mnexec            README.md
root@qiu-base:/home/qiu/mininet# cd examples/
root@qiu-base:/home/qiu/mininet/examples# ls
baresshd.py       controlnet.py       mobility.py       README.md
bind.py           cpu.py              multilink.py      scratchnet.py
clustercli.py     emptynet.py         multiping.py      scratchnetuser.py
clusterdemo.py    hwintf.py           multipoll.py      simpleperf.py
clusterperf.py    __init__.py         multitest.py      sshd.py
cluster.py        intfoptions.py      natnet.py         test
clusterSanity.py  limit.py            nat.py            tree1024.py
consoles.py       linearbandwidth.py  numberedports.py  treeping64.py
controllers2.py   linuxrouter.py      popenpoll.py      vlanhost.py
controllers.py    miniedit.py         popen.py
#执行miniedit脚本,出现可视化界面,在执行前,最好测试python环境变量是否正确
root@qiu-base:/home/qiu/mininet/examples# python3 miniedit.py
miniedit01.png
miniedit02.png
miniedit03.png
miniedit03-2.png
miniedit04.png
miniedit05.png
miniedit06.png
miniedit07.png
miniedit08.png

000000000000001

000000000000002

保存文件,run,然后进入命令行,输出命令查看结果

mininet> dump
 
 
 
 
 
 
mininet> links
s1-eth1<->h1-eth0 (OK OK) 
s1-eth2<->h2-eth0 (OK OK) 
s2-eth1<->h3-eth0 (OK OK) 
mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
h3 h3-eth0:s2-eth1
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0
s2 lo:  s2-eth1:h3-eth0
c0
mininet> nodes
available nodes are: 
c0 h1 h2 h3 s1 s2
mininet> 
#再启动一个控制器可以查看更多信息

你可能感兴趣的:(Ubuntu安装Mininet)