SDN第二次上机作业

SDN第二次上机作业

任务一实验截图

ovs-vsctl show
连通性测试

任务二实验截图

topo搭建
vlan 连通性测试
s1 s2 流表项
vlan 0 抓包
vlan 1 抓包

进阶任务

lab.py 代码如下所示:
# !/usr/bin/python
from mininet.topo import Topo
from mininet.net import Mininet
from mininet.node import Node
from mininet.link import Link
from mininet.node import CPULimitedHost,RemoteController
from mininet.link import TCLink
from mininet.util import dumpNodeConnections
from mininet.log import setLogLevel,info
from mininet.cli import CLI
import os
class myTopo(Topo):
    #"Single switch connected to n hosts."

    def __init__(self):
        Topo.__init__(self)
        s1=self.addSwitch('s1')
        s2=self.addSwitch('s2')
        h1=self.addHost('h1')
        h2 = self.addHost('h2')
        h3 = self.addHost('h3')
        h4 = self.addHost('h4')
        self.addLink(s1, s2)
        self.addLink(h1, s1)
        self.addLink(h2, s1)
        self.addLink(h3, s2)
        self.addLink(h4, s2)
def create_network():
   #"Create network and run simple performance test"
    topo = myTopo()
    net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink)
    net.start()
    os.system('./script.sh')
    CLI(net)
    net.stop()
if __name__ == '__main__':
    setLogLevel('info')
    create_network()
script.sh 文件代码如下:
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:2
sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:3
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=3,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:1
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:2
sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:3

个人心得

topo的端口我直接按照默认的端口来的,所以下发流表项有所不一样。进阶任务有点偷懒,没有按照老师给出的参考文件来写,不过这个偷懒的代码也是可以实现相关内容的。还有以前敲ovs代码指令差不多都忘记完了,还需要重新熟悉一下。同学们遇到的问题也是千奇百怪哈哈哈哈哈。

posted @ 2021-09-07 21:08  如梦的少年丶  阅读(200)  评论(0编辑  收藏  举报