【mininet 0x02】如何使用mn工具来操作mininet

mininet

mininet 系列文章链接归类:

【mininet 0x01】mininet环境搭建
【mininet 0x02】如何使用mn工具来操作mininet
【mininet 0x03】如何使用Python API来操作mininet
【mininet 0x04】使用ryu作为mininet的controller完成HUB功能
【mininet 0x05】使用ryu作为mininet的controller完成L2Switch功能



前言

   安装好了mininet,我们就要尝试使用一下mininet

一、mininet mn工具初体验

   mininet 内置了一个方便的工具 mn

sudo mn

   输入mn后,mininet自动帮助创建了两个节点,并让它们与一台switch相连:

在这里插入图片描述
   如图所示:

sw1
host1
host2

   ovs中的状态如下:
在这里插入图片描述
   创建了 三个 Port: s1, s1-eth1, s1-eth2
   即如下部分信息:

		Port s1
            Interface s1
                type: internal
        Port s1-eth2
            Interface s1-eth2
        Port s1-eth1
            Interface s1-eth1

   在ifconfig中的消息如下:
   创建了 s1, s1-eth1, s1-eth2
在这里插入图片描述

二、mn 常用命令

   mn启动之后的一些常用命令:

序号命令功能
0help打印帮助信息
1nodes查看所有节点信息
2net查看网络拓扑信息
3dump输出节点信息
4h1 ping h2测试主机间的连通性
5iperfTCP打流
6iperfudpUDP打流
7xterm打开xterm窗口
8py运行py
9sh运行shell
10host cmd在主机内执行命令,如h1 ifconfig
11exit/quit退出Mininet

三、创建一些不一样的拓扑

   mn工具内置了--topo的参数供生成不同类型的拓扑,下面是mn工具 help的表述:

  --topo=TOPO           linear|minimal|reversed|single|torus|tree[,param=value
                        ...] linear=LinearTopo torus=TorusTopo tree=TreeTopo
                        single=SingleSwitchTopo

   下图是mn工具的源码关于内置拓扑的部分:
在这里插入图片描述
   使用表格总结一下:

序号拓扑类型名称含义
0linear指直线,一个交换机配一个主机,而主机和交换机的个数都可以任意指定。拓扑呈直线型。
1minimal指最小的,是默认的mininet拓扑,默认一个 交换机挂两个主机,不跟参数。
2reversed指颠倒、反的,这种类型的拓扑与single的拓扑一致。
3single指单个,这种类型的拓扑只有一个交换机,而主机的个数可以任意指定。拓扑呈星型。
4torus较为复杂,适用于需要非常稳定,高冗余量的拓扑,具体解释看下方
5tree树,这种类型的拓扑显然呈数状,交换机呈树杈状分散开来,最下面一层的交换机挂两个主机。tree后面的参数是指树的个数。

实际效果

   单纯看上方的表格,大家肯定云里雾里,所以画一下图,供大家理解:

0、linear

sudo mn --topo=linear,3
s1
s2
s3
h1
h2
h3

1、minimal

sudo mn --topo=minimal
s1
h1
h2

2、reversed

sudo mn --topo=reversed,3
s1
h1
h2
h3

3、single

sudo mn --topo=single,3 
s1
h1
h2
h3

4、torus

环形拓扑图的创建选项要用到参数n,mnm 均要求大于等于 3),生成 n*m 个 openflow 交换机,每个交换机连接一台主机,交换机之间保持与另外 4 台交换机连接,生成不同于完全网络的双向环形网络结构,主要为网络结构复杂,稳定性要求非常高的网络做冗余考虑。构建3*3的环形拓扑结构图的构造命令如下

mn --topo=torus,3,3

此图是从openDayLight截取:
在这里插入图片描述

5、tree

sudo mn --topo=tree,3
s1
s2
s3
s4
h1
h2
h3
h4
h5
h6
h7
h8
h9

四、进行抓包分析流量走向

   使用 h1 ping h2,
   在s1-eth1上进行抓包
h1pingh2抓包信息
   s1-eth2上进行抓包:
h1pingh2dumps1-eth2

   使用 ovs-ofctl dump-flows s1 -O openflow13 查看流表:

➜  ~ ovs-ofctl dump-flows s1 -O openflow13
 cookie=0x0, duration=100.609s, table=0, n_packets=77, n_bytes=7546, idle_timeout=60, reset_counts priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000/0x1fff,dl_src=ee:3c:42:32:f6:f9,dl_dst=7a:2b:18:a4:53:f6,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth1"
 cookie=0x0, duration=99.609s, table=0, n_packets=77, n_bytes=7546, idle_timeout=60, reset_counts priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000/0x1fff,dl_src=7a:2b:18:a4:53:f6,dl_dst=ee:3c:42:32:f6:f9,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth2"
 cookie=0x0, duration=95.475s, table=0, n_packets=2, n_bytes=84, idle_timeout=60, reset_counts priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000/0x1fff,dl_src=ee:3c:42:32:f6:f9,dl_dst=7a:2b:18:a4:53:f6,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=1 actions=output:"s1-eth1"
 cookie=0x0, duration=95.475s, table=0, n_packets=2, n_bytes=84, idle_timeout=60, reset_counts priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000/0x1fff,dl_src=7a:2b:18:a4:53:f6,dl_dst=ee:3c:42:32:f6:f9,arp_spa=10.0.0.1,arp_tpa=10.0.0.2,arp_op=1 actions=output:"s1-eth2"
 cookie=0x0, duration=95.474s, table=0, n_packets=2, n_bytes=84, idle_timeout=60, reset_counts priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000/0x1fff,dl_src=7a:2b:18:a4:53:f6,dl_dst=ee:3c:42:32:f6:f9,arp_spa=10.0.0.1,arp_tpa=10.0.0.2,arp_op=2 actions=output:"s1-eth2"
 cookie=0x0, duration=95.474s, table=0, n_packets=1, n_bytes=42, idle_timeout=60, reset_counts priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000/0x1fff,dl_src=ee:3c:42:32:f6:f9,dl_dst=7a:2b:18:a4:53:f6,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=2 actions=output:"s1-eth1"

   此处发现了一个有趣的现象,我在 ping 的过程中去dump流表,发现只有ip相关的流表(上表中0&1条流表)下发,关闭ping之后,再去dump流表,又多出了一些arp相关的流表,结合wireshark的抓包记录,确实是这样的一个现象
   此处留个坑,后面分析一下mininet的源码,了解一下h1 ping h2这个命令的具体实现。

五、通信原理:

   h1发送信息给s1s1会上报给控制器,由控制器对数据进行处理,控制器交换机下发流表。相关的数据根据流表将数据包发送出去。当数据包到达s2的时候,s2也会给控制器上报一个消息,这时候控制器也会给s2下发流表数据


总结

   以上即为mininet工具mn的使用,以及简单的mininet内部通信原理介绍


参考

http://mininet.org/walkthrough/#display-startup-options
https://www.wi1s0n030.top/archives/69
https://www.jianshu.com/p/31511e691c65

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值