Mininet简介

在Coursera SDN开放课程中,编程作业要用Mininet来完成。这里对Mininet做一个简单的介绍。 

什么是Mininet

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

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

Mininet的特性

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

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

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

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

       Mininet提供python API,简单易用

       Mininet是开源项目,源代码在这里:https://github.com/mininet

目前有三种方式使用mininet

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

测试

如果安装没有报错,那就可以试一下mininet了

root@ubuntu:~# mn
*** 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)

可以通过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中,可以试几个

比如查看节点(nodes)

mininet> nodes
available nodes are: 
c0 h1 h2 s1

可以看到当前的拓扑里有四个节点,包括两个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

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

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

mininet> dump
<Host h1: h1-eth0:10.0.0.1 pid=36658> 
<Host h2: h2-eth0:10.0.0.2 pid=36660> 
<OVSSwitch s1: lo:127.0.0.1,s1-eth1:None,s1-eth2:None pid=36665> 
<Controller c0: 127.0.0.1:6653 pid=36651> 

可以看到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', '2.94 Mbits/sec', '10.5 Mbits/sec'] #这里结果分别是上行带宽和下行带宽 
mininet> iperf
*** Iperf: testing TCP bandwidth between h1 and h2 
*** Results: ['10.1 Gbits/sec', '10.1 Gbits/sec']   #上行带宽和下行带宽

退出 (quit 或 exit)

mininet> exit
*** Stopping 1 controllers
c0 
*** Stopping 2 links
..
*** Stopping 1 switches
s1 
*** Stopping 2 hosts
h1 h2 
*** Done
completed in 507.131 seconds
原文地址:https://www.cnblogs.com/liujunjun/p/12213742.html