脚本宝典收集整理的这篇文章主要介绍了实验2:Open vSwitch虚拟交换机实践,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.能够对Open vSwitch进行基本操作; 2.能够通过命令行终端使用OVS命令操作Open vSwitch交换机,管理流表; 3.能够通过Mininet的Python代码运行OVS命令,控制网络拓扑中的Open vSwitch交换机
1.下载虚拟机软件oracle VisualBox 或 VMware; 2.在虚拟机中@R_777_636@ 20.04 Desktop amd64,并完整安装Mininet;
1.创建OVS交换机,并以ovs-switchxxx命名,其中xxx为本人在选课班级中的序号,例如ovs-switch001, ovs-switch088等。在创建的交换机上增加端口p0和p1,设置p0的端口号为100,p1的端口号为101,类型均为internal;为了避免网络接口上的地址和本机已有网络地址冲突,需要创建虚拟网络空间(参考命令netns)ns0和ns1,分别将p0和p1移入,并分别配置p0和p1端口的ip地址为190.168.0.100、192.168.0.101,子网掩码为255.255.255.0;最后测试p0和p1的连通性。
2.使用Mininet搭建的SDN拓扑,如下图所示,要求支持OpenFlow 1.3协议,主机名、交换机名以及端口对应正确。
先给拓扑生成python文件,然后在修改python文件,并在命令行运行
1.通过命令行终端输入“ovs-ofctl”命令,直接在s1和s2上添加流表,划分出所要求的VLAN。
VLAN_ID | Hosts |
---|---|
0 | h1 h3 |
1 | h2 h4 |
1.主机连通性要求: - h1 – h3互通 - h2 – h4互通
以下为代码:
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 setNetwork():
net =Mininet( topo=None,
build=False,
ipBase='196.168.0.0/24')
info('***add the controllern')
c0=net.addController(name='c0',
controller=Controller,
prococol='tcp',
port=6633)
info('***add switchn')
switch=[]
for i in range(2):
sw=net.addSwitch('s{}'.format(i+1),cls=OVSKernelSwitch)
switch.append(sw)
info('***add hostn')
host=[]
for i in range(4):
ip='196.168.0.'+str(i+1)
name='h'+str(i+1)
h=net.addHost(name,clas=Host,ip=ip,defaltRoute=None)
host.append(h)
info('***add linksn')
for i in range(4):
if i<2:
net.addLink(switch[0],host[i],i+1,1)
else:
net.addLink(switch[1],host[i],i-1,1)
net.addLink(switch[0],switch[1],3,3)
info ('*** start networkn')
net.build()
info('***start controllersn')
for ctl in net.controllers:
ctl.start()
info('***start swicthn')
net.get('s1').start([c0])
net.get('s2').start([c0])
info( '*** Post configure switches and hostsn')
for i in range(2):
for t in range(2):
port=t+1
field=4096+t
switch[i].cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s{cnt} priority=1,in_port={Port},actions=push_vlan:0x8100,set_field:{Field}->vlan_vid,output:3'.format(cnt=i+1,Port=port,Field=field))
for t in range(2):
switch[i].cmd('sudo ovs-ofctl -O OpenFlow13 add-flow s{cnt} priority=1,dl_vlan={iiiddd},actions=pop_vlan,output:{outPut}'.format(cnt=i+1,iiiddd=t,outPut=t+1))
CLI(net)
net.stop()
if __name__=='__main__':
setLogLevel('info')
setNetwork()
可以看到拓扑的联通情况(h1-h3, h2-h4)与(一)中一样
以上是脚本宝典为你收集整理的实验2:Open vSwitch虚拟交换机实践全部内容,希望文章能够帮你解决实验2:Open vSwitch虚拟交换机实践所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。