Mininet介绍及安装

什么是Mininet

       Mininet是由一些虚拟的终端节点(end-hosts)、交换机、路由器连接而成的一个网络仿真器,它采用轻量级的虚拟化技术使得系统可以和真实网络相媲美。

       Mininet可以很方便地创建一个支持SDN的网络:host就像真实的电脑一样工作,可以使用ssh登录,启动应用程序,程序可以向以太网端口发送数 据包,数据包会被交换机、路由器接收并处理。有了这个网络,就可以灵活地为网络添加新的功能并进行相关测试,然后轻松部署到真实的硬件环境中。

Mininet的特性

       可以简单、迅速地创建一个支持用户自定义的网络拓扑,缩短开发测试周期

       可以运行真实的程序,在Linux上运行的程序基本上可以都可以在Mininet上运行,如Wireshark

       Mininet支持Openflow,在Mininet上运行的代码可以轻松移植到支持OpenFlow的硬件设备上

       Mininet可以在自己的电脑,或服务器,或虚拟机,或者云(例如Amazon EC2)上运行

       Mininet提供python API,简单易用

      

Mininet 是一个开源项目,简单好用成本低,代码托管在github上:

https://github.com/mininet/mininet

目前有三种方式使用mininet

  • Easiest "installation" - use our pre-built VM image!
  • Next-easiest option: use our Ubuntu package!
  • Native installation from source

三种方式都比较方便,以下第三种方式举例(第三种貌似最复杂)

1.从Github上获取mininet源码

git clone git://github.com/mininet/mininet     #这里需要提前安装git,ubuntu环境下还需要+sudo

2.安装获得源码可以选择mininet的版本,最新或者稳定都可以(目前最新的已经是2.3.0d1版本)

xxt@xxt-VirtualBox:~$ cd mininet/
xxt@xxt-VirtualBox:~/mininet$ git tag
1.0.0
2.0.0
2.1.0
2.1.0p1
2.1.0p2
2.2.0
2.2.0b0
2.2.0b1
2.2.0b2
2.2.0b3
2.2.0rc1
2.2.0rc2
2.2.1
2.2.1d2
2.2.1rc1
cs244-spring-2012-final
xxt@xxt-VirtualBox:~/mininet$ 

选择你所需要的版本

git checkout <release tag>      #这里的release tag就是你想选取的版本

此时就可以开始安装了

mininet/util/install.sh [options]
-a:  全部安装
-nfv:仅安装MINIENT OPENFLOW引用多SWITCH 和OPEN VSWITCH
-s mydir: 指定目录

3.测试

如果上面的步骤没有报错,那就可以试一下mininet了

xxt@xxt-VirtualBox:~/mininet$ sudo mn 
[sudo] password for xxt: 
*** Creating network
*** Adding controller
*** Adding hosts:
h1 h2 
*** Adding switches:
s1 
*** Adding links:
(h1, s1) (h2, s1) 
*** Configuring hosts
h1 h2 
*** Starting controller
c0 
*** Starting 1 switches
s1 ...
*** Starting CLI:
mininet> 

这是一个最简单的拓扑,包括两个host和一个switch

然后可以互相ping一下

mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 
h2 -> h1 
*** Results: 0% dropped (2/2 received)
mininet>

可以通过help命令了解其他功能

mininet> help

Documented commands (type help <topic>):
========================================
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:
  <node> 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

mininet> 

这里可以看到有许多功能都集成在mininet中,可以试几个

 

比如查看节点(nodes)

mininet> nodes
available nodes are: 
c0 h1 h2 s1
mininet> 

可以看到当前的拓扑里有四个节点,包括两个host,一个switch,还有一个控制器c0

 

查看连接情况(net)

mininet> net
h1 h1-eth0:s1-eth1
h2 h2-eth0:s1-eth2
s1 lo:  s1-eth1:h1-eth0 s1-eth2:h2-eth0
c0
mininet> 

可以看到h1的port0和s1的port1连接,h2的port0和s2的port2连接

 

dump(这不知道怎么翻译,好多语言里都有这个方法。。。)

mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=2531> 
<Host h2: h2-eth0:10.0.0.2 pid=2533> 
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=2538> 
<Controller c0: 127.0.0.1:6633 pid=2524> 
mininet> 

可以看到h1-eth0的ip是10.0.0.1 ,h2-eth0的ip是10.0.0.2 , s1的ip是127.0.0.1(本地)

 

还有一些集成在mininet里的工具,例如有名的网络性能测试工具iperf

mininet> iperfudp
*** Iperf: testing UDP bandwidth between h1 and h2 
*** Results: ['10M', '9.98 Mbits/sec', '9.98 Mbits/sec']        #这里结果分别是上行带宽和下行带宽 ,  前面的那个10M是什么就不太清楚了
mininet> iperf
*** Iperf: testing TCP bandwidth between h1 and h2 
*** Results: ['17.6 Gbits/sec', '17.6 Gbits/sec']          #上行带宽和下行带宽
mininet> 

 

退出 (quit 或 exit)

mininet> quit
*** Stopping 1 controllers
c0 
*** Stopping 2 links
..
*** Stopping 1 switches
s1 
*** Stopping 2 hosts
h1 h2 
*** Done
completed in 1119.156 seconds
xxt@xxt-VirtualBox:~/mininet$ 

 

 

功能很多,这里就不一一赘述了,如有不对的地方,欢迎批评指出。。

posted @ 2016-05-03 18:30  _Just  阅读(29026)  评论(0编辑  收藏  举报