SDN作业2 Open vSwitch 应用实践1
本文地址:
- https://type.dayiyi.top/index.php/archives/292/
- https://blog.dayi.ink/?p=162
- https://www.cnblogs.com/rabbit-dayi/p/17868059.html
- https://cmd.dayi.ink/ltQtj5aOSi-x2Xc6xOuHGg
本实验均在root用户下进行
如果失败了,可能是OVS的问题,请参考文章末尾
su
sudo su
预制
启动OVS服务
ovs-ctl start
然后想法开两个shell
任务1
先清空下
终端1:
mn -c
mn
终端2(另外开一个终端):
ovs-ofctl dump-flows s1
没有流表:
PingALL
#CLI 终端1
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2
h2 -> h1
*** Results: 0% dropped (2/2 received)
mininet>
查看流表:
#终端2
ovs-ofctl dump-flows s1
建立拓扑
# 终端1
# 清理并且建立 1个交换机4个主机
mn -c && mn --topo single,4
查看流表
# 终端2
# 查看流表
ovs-ofctl dump-flows s1 #这里应该是空的
<!-- ### 设置IP
更新内容
mininet> h1 ifconfig h1-eth0 10.0.0.1
mininet> h2 ifconfig h2-eth0 10.0.0.2
mininet> h3 ifconfig h3-eth0 10.0.0.3
mininet> h4 ifconfig h4-eth0 10.0.0.4
PINGALL
#终端1
mininet> pingall
*** Ping: testing ping reachability
h1 -> h2 h3 h4
h2 -> h1 h3 h4
h3 -> h1 h2 h4
h4 -> h1 h2 h3
*** Results: 0% dropped (12/12 received)
mininet>
这里全部可以PING通
查看目前的流表:
#终端2
root@ubuntu:/home/sdn# ovs-ofctl dump-flows s1
cookie=0x0, duration=55.843s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=ca:76:64:1b:37:77,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=2 actions=output:"s1-eth1"
cookie=0x0, duration=55.841s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=ca:76:64:1b:37:77,arp_spa=10.0.0.3,arp_tpa=10.0.0.1,arp_op=2 actions=output:"s1-eth1"
cookie=0x0, duration=55.839s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=ca:76:64:1b:37:77,arp_spa=10.0.0.4,arp_tpa=10.0.0.1,arp_op=2 actions=output:"s1-eth1"
cookie=0x0, duration=55.836s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=22:87:c2:36:ab:33,arp_spa=10.0.0.3,arp_tpa=10.0.0.2,arp_op=2 actions=output:"s1-eth2"
cookie=0x0, duration=55.833s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=22:87:c2:36:ab:33,arp_spa=10.0.0.4,arp_tpa=10.0.0.2,arp_op=2 actions=output:"s1-eth2"
cookie=0x0, duration=55.829s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=12:18:0f:59:6d:59,arp_spa=10.0.0.4,arp_tpa=10.0.0.3,arp_op=2 actions=output:"s1-eth3"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=12:18:0f:59:6d:59,arp_spa=10.0.0.4,arp_tpa=10.0.0.3,arp_op=1 actions=output:"s1-eth3"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=22:87:c2:36:ab:33,arp_spa=10.0.0.3,arp_tpa=10.0.0.2,arp_op=1 actions=output:"s1-eth2"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=ca:76:64:1b:37:77,arp_spa=10.0.0.2,arp_tpa=10.0.0.1,arp_op=1 actions=output:"s1-eth1"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=22:87:c2:36:ab:33,arp_spa=10.0.0.4,arp_tpa=10.0.0.2,arp_op=1 actions=output:"s1-eth2"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=ca:76:64:1b:37:77,arp_spa=10.0.0.3,arp_tpa=10.0.0.1,arp_op=1 actions=output:"s1-eth1"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=ca:76:64:1b:37:77,arp_spa=10.0.0.4,arp_tpa=10.0.0.1,arp_op=1 actions=output:"s1-eth1"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=c2:4d:1b:f3:02:51,arp_spa=10.0.0.3,arp_tpa=10.0.0.4,arp_op=2 actions=output:"s1-eth4"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=12:18:0f:59:6d:59,arp_spa=10.0.0.2,arp_tpa=10.0.0.3,arp_op=2 actions=output:"s1-eth3"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=22:87:c2:36:ab:33,arp_spa=10.0.0.1,arp_tpa=10.0.0.2,arp_op=2 actions=output:"s1-eth2"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=12:18:0f:59:6d:59,arp_spa=10.0.0.1,arp_tpa=10.0.0.3,arp_op=2 actions=output:"s1-eth3"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=c2:4d:1b:f3:02:51,arp_spa=10.0.0.1,arp_tpa=10.0.0.4,arp_op=2 actions=output:"s1-eth4"
cookie=0x0, duration=50.806s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,arp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=c2:4d:1b:f3:02:51,arp_spa=10.0.0.2,arp_tpa=10.0.0.4,arp_op=2 actions=output:"s1-eth4"
cookie=0x0, duration=55.843s, table=0, n_packets=3, n_bytes=294, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=22:87:c2:36:ab:33,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=55.843s, table=0, n_packets=1, n_bytes=98, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=ca:76:64:1b:37:77,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=55.841s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=12:18:0f:59:6d:59,nw_src=10.0.0.1,nw_dst=10.0.0.3,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth3"
cookie=0x0, duration=55.841s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=ca:76:64:1b:37:77,nw_src=10.0.0.3,nw_dst=10.0.0.1,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth1"
cookie=0x0, duration=55.839s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=c2:4d:1b:f3:02:51,nw_src=10.0.0.1,nw_dst=10.0.0.4,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth4"
cookie=0x0, duration=55.839s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=ca:76:64:1b:37:77,nw_src=10.0.0.4,nw_dst=10.0.0.1,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth1"
cookie=0x0, duration=55.838s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=ca:76:64:1b:37:77,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth1"
cookie=0x0, duration=55.838s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=22:87:c2:36:ab:33,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth2"
cookie=0x0, duration=55.835s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=12:18:0f:59:6d:59,nw_src=10.0.0.2,nw_dst=10.0.0.3,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth3"
cookie=0x0, duration=55.835s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=22:87:c2:36:ab:33,nw_src=10.0.0.3,nw_dst=10.0.0.2,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth2"
cookie=0x0, duration=55.833s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=c2:4d:1b:f3:02:51,nw_src=10.0.0.2,nw_dst=10.0.0.4,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth4"
cookie=0x0, duration=55.833s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=22:87:c2:36:ab:33,nw_src=10.0.0.4,nw_dst=10.0.0.2,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth2"
cookie=0x0, duration=55.832s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=ca:76:64:1b:37:77,nw_src=10.0.0.3,nw_dst=10.0.0.1,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth1"
cookie=0x0, duration=55.831s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=12:18:0f:59:6d:59,nw_src=10.0.0.1,nw_dst=10.0.0.3,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth3"
cookie=0x0, duration=55.830s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=22:87:c2:36:ab:33,nw_src=10.0.0.3,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth2"
cookie=0x0, duration=55.830s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=12:18:0f:59:6d:59,nw_src=10.0.0.2,nw_dst=10.0.0.3,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth3"
cookie=0x0, duration=55.829s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=c2:4d:1b:f3:02:51,nw_src=10.0.0.3,nw_dst=10.0.0.4,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth4"
cookie=0x0, duration=55.828s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=12:18:0f:59:6d:59,nw_src=10.0.0.4,nw_dst=10.0.0.3,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth3"
cookie=0x0, duration=55.827s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=ca:76:64:1b:37:77,nw_src=10.0.0.4,nw_dst=10.0.0.1,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth1"
cookie=0x0, duration=55.827s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth1",vlan_tci=0x0000,dl_src=ca:76:64:1b:37:77,dl_dst=c2:4d:1b:f3:02:51,nw_src=10.0.0.1,nw_dst=10.0.0.4,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth4"
cookie=0x0, duration=55.826s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=22:87:c2:36:ab:33,nw_src=10.0.0.4,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth2"
cookie=0x0, duration=55.826s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth2",vlan_tci=0x0000,dl_src=22:87:c2:36:ab:33,dl_dst=c2:4d:1b:f3:02:51,nw_src=10.0.0.2,nw_dst=10.0.0.4,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth4"
cookie=0x0, duration=55.825s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth4",vlan_tci=0x0000,dl_src=c2:4d:1b:f3:02:51,dl_dst=12:18:0f:59:6d:59,nw_src=10.0.0.4,nw_dst=10.0.0.3,nw_tos=0,icmp_type=8,icmp_code=0 actions=output:"s1-eth3"
cookie=0x0, duration=55.825s, table=0, n_packets=0, n_bytes=0, idle_timeout=60, priority=65535,icmp,in_port="s1-eth3",vlan_tci=0x0000,dl_src=12:18:0f:59:6d:59,dl_dst=c2:4d:1b:f3:02:51,nw_src=10.0.0.3,nw_dst=10.0.0.4,nw_tos=0,icmp_type=0,icmp_code=0 actions=output:"s1-eth4"
root@ubuntu:/home/sdn#
修改流表
阻止H1访问其他的主机
# 终端1
# 重新开一下 CTRL+D
mn -c && mn --topo single,4
# 终端2
ovs-ofctl add-flow s1 icmp,nw_src=10.0.0.1,icmp_type=8,action=drop
测试:
#终端1
mininet> pingall
*** Ping: testing ping reachability
h1 -> X X X
h2 -> h1 h3 h4
h3 -> h1 h2 h4
h4 -> h1 h2 h3
*** Results: 25% dropped (9/12 received)
mininet>
失败了?
把内核降到了5.8,然后又重新装了下OVS 2.17,记得删除内核模块哦。
大体就这样,挺麻烦的。
虚拟机放这里了,这样省脑子:
这个是我自己用的版本,没经过测试,可能多少有点不一样,OVS要手动启动哦。
Ubuntu_20.04_sdn_ovs_2.17.8-LTS-fix1
链接:https://pan.baidu.com/s/1fwvV2B_eH6D3xEQ2bYJnlQ?pwd=6y8l
提取码:6y8l
--来自百度网盘超级会员V6的分享