第二次sdn实验:
1. 利用mininet创建如下拓扑,要求拓扑支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确,请给出拓扑Mininet执行结果,展示端口连接情况。
本次使用python脚本fattree生成拓扑,这样方便设置路由器的转发端口号。
python代码:
"""Custom topology example
Adding the 'topos' dict with a key/value pair to generate our newly defined
topology enables one to pass in '--topo=mytopo' from the command line.
"""
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import RemoteController, CPULimitedHost
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
class MyTopo(Topo):
"Simple topology example."
def __init__(self):
"Create custom topo."
# Initialize topology
Topo.__init__(self)
host1 = self.addHost('h1')
host2 = self.addHost('h2')
host3 = self.addHost('h3')
host4 = self.addHost('h4')
host5 = self.addHost('h5')
host6 = self.addHost('h6')
switch1 = self.addSwitch('s1')
switch2 = self.addSwitch('s2')
self.addLink(host1, switch1, 1, 1)
self.addLink(host2, switch1, 1, 2)
self.addLink(host3, switch1, 1, 3)
self.addLink(switch1, switch2, 4, 4)
self.addLink(host4, switch2, 1, 1)
self.addLink(host5, switch2, 1, 2)
self.addLink(host6, switch2, 1, 3)
topos = {'mytopo': (lambda: MyTopo())}
运行以及端口连接展示:
2.直接在Open vSwitch下发流表,用vlan得到下列虚拟网段,请逐条说明所下发的流表含义。(需要再开启一个终端进行操作)
h1 -- h4互通
h2 -- h5互通
h3 -- h6互通
其余主机不通
①使用如下OVS命令实现s1接收从h1、h2和h3传来的包,并从端口4发出
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096\>vlan_vid,output:4//将h1进入s1的包打上vlan tag,从端口4发出
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097\>vlan_vid,output:4//将h2进入s1的包打上vlan tag,从端口4发出
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4098\>vlan_vid,output:4//将h3进入s1的包打上vlan tag,从端口4发出
②使用如下OVS命令实现s2接收从h4、h5和h6传来的包,并从端口4发出
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096\>vlan_vid,output:4//将h4进入s2的包打上vlan tag,从端口4发出
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097\>vlan_vid,output:4//将h5进入s2的包打上vlan tag,从端口4发出
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4098\>vlan_vid,output:4//将h6进入s2的包打上vlan tag,从端口4发出
③使用如下OVS命令实现s1接收从端口4传来的包,并从端口1、2、3分别发给h1、h2、h3
sudo ovsofctlOOpenFlow13addflows1priority=1,dl_vlan=0,actions=pop_vlan,output:1
//将从端口4的包去除vlan tag, 并根据tag进行转发端口1
sudo ovsofctlOOpenFlow13addflows1priority=1,dl_vlan=1,actions=pop_vlan,output:2
//将从端口4的包去除vlan tag, 并根据tag进行转发端口2
sudo ovsofctlOOpenFlow13addflows1priority=1,dl_vlan=2,actions=pop_vlan,output:3
//将从端口4的包去除vlan tag, 并根据tag进行转发端口3
④使用如下OVS命令实现s2接收从端口4传来的包,并从端口1、2、3分别发给h1、h2、h3
sudo ovsofctlOOpenFlow13addflows2priority=1,dl_vlan=0,actions=pop_vlan,output:1
//将从端口4的包去除vlan tag, 并根据tag进行转发端口1
sudoovsofctlOOpenFlow13addflows2priority=1,dl_vlan=1,actions=pop_vlan,output:2
//将从端口4的包去除vlan tag, 并根据tag进行转发端口2
sudo ovsofctlOOpenFlow13addflows2priority=1,dl_vlan=2,actions=pop_vlan,output:3
//将从端口4的包去除vlan tag, 并根据tag进行转发端口3