mininet中下发流表
-
使用postman下发流表参考了这篇文章SDN-Postman及python编程对流表的操作
-
在mininet/custom文件夹中创建自己的拓扑,
touch po.py
,内容如下:from mininet.topo import Topo from mininet.net import Mininet from mininet.node import RemoteController from mininet.link import TCLink from mininet.util import dumpNodeConnections class MyTopo(Topo): def __init__(self): Topo.__init__(self) host1 = self.addHost('h1') host2 = self.addHost('h2') host3 = self.addHost('h3') host4 = self.addHost('h4') switch1 = self.addSwitch('s1') switch2 = self.addSwitch('s2') switch3 = self.addSwitch('s3') self.addLink(host1,switch1) self.addLink(host2,switch2) self.addLink(host3,switch3) self.addLink(host4,switch3) self.addLink(switch1,switch2) self.addLink(switch1,switch3) self.addLink(switch2,switch3) topos = {'mytopo':(lambda:MyTopo())}
-
cd到mininet/custom文件夹下,执行
su root
进入root权限,执行mn --custom po.py --topo mytopo --controller=remote,ip=192.168.40.154,port=6633 --switch ovsk,protocols=OpenFlow10 --mac
运行自己的拓扑文件。
如果不cd到custom文件夹的话,就需要提供自定义拓扑文件的绝对地址。ip就是控制器的ip地址,在这里就是我本地ubuntu虚拟机的地址,ifconfig就可以查看。
最后我使用的是protocols=OpenFlow10
,使用protocols=OpenFlow13
时得注意,执行dpctl命令时可能会遇到ovs-ofctl:version negotiation failed (we support version 0x01, peer supports version 0x04)
问题,解决方案参考这个链接,就是执行sudo ovs-ofctl -O OpenFlow13 dump-flows s1
之后在mininet交互行中执行py net.get('h1').cmd('ifconfig h1-eth0 10.1')
依次为四个主机分配ip地址。拓扑图如下:
-
我使用postman下发的流表内容是:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <flow xmlns="urn:opendaylight:flow:inventory"> <priority>200</priority> <flow-name>Foo1</flow-name> <idle-timeout>0</idle-timeout> <hard-timeout>0</hard-timeout> <match> <ethernet-match> <ethernet-type> <type>2048</type> </ethernet-type> </ethernet-match> <ipv4-destination>10.0.0.3/32</ipv4-destination> </match> <id>1</id> <table_id>0</table_id> <instructions> <instruction> <order>0</order> <apply-actions> <action> <order>0</order> <drop-action></drop-action> </action> </apply-actions> </instruction> </instructions> </flow>
-
下发成功之后,pingall可以发现,h1、h2、h4和h3ping不通,但是其他三台主机都能互相ping通。
-
单独为某个交换机执行流表操作:
- 下发流表:
sh ovs-ofctl add-flow s3 dl_type=0x0800,nw_dst=10.0.0.3,priority=300,table=0,actions=drop
- 删除流表:
sh ovs-ofctl del-flows s3 nw_dst=10.0.0.3
- 查看流表:
sh ovs-ofctl dump-flows s3
- 下发流表:
-
操作所有交换机的流表:
- 查看流表
dpctl dump-flows
- 删除流表:
dpctl del-flows in_port=1
- 添加流表:
dpctl add-flow in_port=1,action=output:2,3
- 查看流表
-
如果是在mininet交互命令中添加主机并通信:
py net.addHost('h5')
py net.addLink(s1,net.get('h5'))
py s1.attach('s1-eth0')
- 给主机分配地址:
py net.get('h5').cmd('ifconfig h5-etn0 10.5')
-
这篇文章也很好Mininet中文使用教程