软件定义网络第一次报告
一、SDN实验环境安装
二、SDN拓扑实践
(一)基本要求
代码部分:
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
def myNetwork():
net = Mininet( topo=None,
build=False,
ipBase='10.0.0.0/8')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None)
info( '*** Add links\n')
net.addLink(h1, s1, bw=10,delay='5ms',max_queue_size=1000,loss=50,use_htb=True)
net.addLink(s1, s2)
net.addLink(s2, h3)
net.addLink(s2, h4)
net.addLink(s1, h2)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hosts\n')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
myNetwork()
Mininet运行部分:
(二)进阶要求
代码部分:
from mininet.topo import Topo
class MyTopo(Topo):
def __init__(self):
Topo.__init__(self)
#loop for add hosts
hosts = []
for i in range(16):
h = self.addHost('h'+str(i+1))
hosts.append(h)
#loop for add switchs
switchs = []
for i in range(14):
s = self.addSwitch('s'+str(i+1))
switchs.append(s)
#loops for add links
#s & s
for i in range(2):
for j in range(2, 6):
self.addLink(switchs[i], switchs[j])
for i in range(2, 4):
for j in range(6, 10):
self.addLink(switchs[i], switchs[j])
for i in range(4, 6):
for j in range(10, 14):
self.addLink(switchs[i], switchs[j])
#s & h
for i in range(6, 14):
loca = 2 * ( i - 6 )
self.addLink(switchs[i], hosts[loca])
self.addLink(switchs[i], hosts[loca+1])
topos = {'mytopo': (lambda: MyTopo())}
执行结果部分:
三、Open vSwitch虚拟交换机实践
(一)基本要求
执行结果部分:
(二)进阶要求
代码部分:
from mininet.net import Mininet
from mininet.node import Controller, RemoteController, OVSController
from mininet.node import CPULimitedHost, Host, Node
from mininet.node import OVSKernelSwitch, UserSwitch
from mininet.node import IVSSwitch
from mininet.cli import CLI
from mininet.log import setLogLevel, info
from mininet.link import TCLink, Intf
from subprocess import call
def mynetwork():
net = Mininet( topo=None,build=False,ipBase='192.168.0.0/24')
info( '*** Adding controller\n' )
c0=net.addController(name='c0',
controller=Controller,
protocol='tcp',
port=6633)
info( '*** Add switches\n')
s1 = net.addSwitch('s1', cls=OVSKernelSwitch)
s2 = net.addSwitch('s2', cls=OVSKernelSwitch)
info( '*** Add hosts\n')
h1 = net.addHost('h1', cls=Host, ip='192.168.0.1', defaultRoute=None)
h2 = net.addHost('h2', cls=Host, ip='192.168.0.2', defaultRoute=None)
h3 = net.addHost('h3', cls=Host, ip='192.168.0.3', defaultRoute=None)
h4 = net.addHost('h4', cls=Host, ip='192.168.0.4', defaultRoute=None)
info( '*** Add links\n')
net.addLink(h1, s1, 1, 1)
net.addLink(s1, h2, 2, 1)
net.addLink(s1, s2, 3, 3)
net.addLink(s2, h3, 1, 1)
net.addLink(s2, h4, 2, 1)
info( '*** Starting network\n')
net.build()
info( '*** Starting controllers\n')
for controller in net.controllers:
controller.start()
info( '*** Starting switches\n')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hosts\n')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
s1.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s1 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=1,actions=push_vlan:0x8100,set_field:4096-\>vlan_vid,output:3')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,in_port=2,actions=push_vlan:0x8100,set_field:4097-\>vlan_vid,output:3')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=0,actions=pop_vlan,output:1')
s2.cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s2 priority=1,dl_vlan=1,actions=pop_vlan,output:2')
CLI(net)
net.stop()
if __name__ == '__main__':
setLogLevel( 'info' )
mynetwork()
运行结果部分:
个人阶段总结:
在做实验的时候,首先遇到的第一个难点就是环境的配置,在配置mininet的时候没有开vpn导致多次下载失败,后面去csdn查找发现可以改一下网络配置,能ping通GitHub的网址就可以成功下载。后面学聪明了,在配置OpenDaylight 控制器以及ryu控制器的时候,下载相应文件的时候就开vpn去下载,效率会高很多。而在51OpenLab平台做实验的时候就完全不需要自己去配置,而且启动虚拟机相当快,省去了一大堆的烦恼。而且,课程类实验分为左右两边区域。左边为文档区,会详细讲解实验原理和实验步骤等;右边是实验环境,通过预置的镜像进行实验操作。然后在开放实验室可自主选择设备,自定义网络拓扑和镜像,可支撑网络、编程、云计算、大数据、人工智能等多技术领域的实验。第二个问题就是在做拓扑实践的时候,mininet运行失败,报错 No module named pip。后面去试了一下文档里面的解决方案发现不大行得通,改去csdn里面看,先是尝试了软连接,后面发现python3的软连接会一直报错,而后将python3.6更新为python3.8,并且重新更改软连接指向后就能正常使用mininet。第三个问题是,python文件的一个保存问题,后面发现要更改权限,先执行su命令,提高权限,然后执行chmod命令后便可以正常保存。第四个问题就是在做ovs虚拟交换机的时候,在使用wireshark抓包时,一开始默认抓取的端口是s1-eth1,一直看不到所抓到的数据包的vlan tag,而且执行h2 ping h4时没有任何抓包的消息。后面重新阅读文档,并且重新sudo wireshark,发现存在多个端口,才知道应该设置抓取的端口为s1-eth3,后面设置好后就可以看到h1 ping h3对应的vlan tag。