def setupTopology(): topology = topologyParser.Topology("topology4.xml") hostList = topology.getHost() for host in hostList: cmd.lxcStart(host) openflowSwitchList = topology.getOpenflowSwitch() ipList = topology.getInterfaceIp() ipList = list(set(ipList)) dpidlist = cmd.getDpidList() for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) for interface in interfaceList: cmd.ovsDpctl(openflowSwitch, interface) i = 0 for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) inportList = cmd.getPort(dpidlist[i]) for interface in interfaceList: for ip in ipList: cmd.addFlowSpace( dpidlist[i], "20", "in_port=" + inportList[interface] + ",nw_src=" + ip, "Slice:rfSlice=4" ) i = i + 1
def setupTopology(): topology = topologyParser.Topology('topology.xml') hostList = topology.getHost() for host in hostList: cmd.lxcStart(host) openflowSwitchList = topology.getOpenflowSwitch() ipList = topology.getInterfaceIp() ipList = list(set(ipList)) dpidlist = cmd.getDpidList() openflowSwitchList = topology.getOpenflowSwitch() for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) cmd.ovsOpenflowd(openflowSwitch, '210.25.137.243', 6633) for interface in interfaceList: cmd.ovsDpctl(openflowSwitch, interface) i=0 for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) inportList = cmd.getPort(dpidlist[i]) for interface in interfaceList: for ip in ipList: cmd.addFlowSpace(dpidlist[i],'20','in_port='+ inportList[interface]+',nw_src='+ip,'Slice:rfSlice=4') i=i+1
def setupTopology(): #从xml文件读取拓扑 topology = topologyParser.Topology('topology.xml') hostList = topology.getHost() #启动虚拟机 for host in hostList: cmd.lxcStart(host) #获取拓扑中的ip地址 openflowSwitchList = topology.getOpenflowSwitch() ipList = topology.getInterfaceIp() ipList = list(set(ipList)) dpidlist = cmd.getDpidList() #连接拓扑 for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) for interface in interfaceList: cmd.ovsDpctl(openflowSwitch, interface) i=0 #添加flowspace项 for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) inportList = cmd.getPort(dpidlist[i]) for interface in interfaceList: for ip in ipList: cmd.addFlowSpace(dpidlist[i],'20','in_port='+ inportList[interface]+',nw_src='+ip,'Slice:rfSlice=4') i=i+1
def setupTopology(): topology = topologyParser.Topology('topology2.xml') hostList = topology.getHost() for host in hostList: cmd.lxcStart(host) openflowSwitchList = topology.getOpenflowSwitch() openflowSwitchNum = len(openflowSwitchList) file = open('/switchDict','rb') tmpDict = pickle.load(file) file.close() sortedList = sorted(tmpDict.items(), lambda x, y: cmp(x[1], y[1])) for i in range(0,openflowSwitchNum): ovsDict[openflowSwitchList[i]] = sortedList[i][0] tmpDict[sortedList[i][0]]=tmpDict[sortedList[i][0]]+1 file = open('/switchDict','wb') pickle.dump(tmpDict,file) file.close() dpidlist = cmd.getDpidList() for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) for interface in interfaceList: cmd.ovsDpctl(ovsDict[openflowSwitch], interface) i=0 for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) inportList = cmd.getPort(dpidlist[i]) for interface in interfaceList: cmd.addFlowSpace(dpidlist[i],'20','in_port='+ inportList[interface],'Slice:slice1=4') i=i+1
def setupTopology(): topology = topologyParser.Topology() hostList = topology.getHost() for host in hostList: cmd.lxcStart(host) openflowSwitchList = topology.getOpenflowSwitch() for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) cmd.ovsOpenflowd(openflowSwitch, '127.0.0.1', 6633) for interface in interfaceList: cmd.ovsDpctl(openflowSwitch, interface)
def setupControlPlane(): cmd.lxcStart('router1') cmd.lxcStart('router2') cmd.ovsOpenflowd('dp0', '127.0.0.1', 6633, 'rfovs') cmd.ifconfig('dp0', 'up') cmd.ovsOpenflowd('br0', '127.0.0.1', 6363) cmd.ifconfig('br0', 'up', '192.168.1.1', '255.255.255.0') dp0Interface = ['router1.1', 'router1.2', 'router2.1', 'router2.2'] for interface in dp0Interface: cmd.ovsDpctl('dp0', interface) br0Interface = ['router1.0', 'router2.0'] for interface in br0Interface: cmd.ovsDpctl('br0', interface)
def setupTopology(): topology = topologyParser.Topology('topology.xml') hostList = topology.getHost() for host in hostList: cmd.lxcStart(host) openflowSwitchList = topology.getOpenflowSwitch() dpidlist = cmd.getDpidList() for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) for interface in interfaceList: cmd.ovsDpctl(openflowSwitch, interface) i=0 for openflowSwitch in openflowSwitchList: interfaceList = topology.getOpenflowSwitchInterface(openflowSwitch) inportList = cmd.getPort(dpidlist[i]) for interface in interfaceList: cmd.addFlowSpace(dpidlist[i],'20','in_port='+ inportList[interface],'Slice:slice1=4') i=i+1
cmd.createDaemons(lxc,topology["nodes"][lxc]["attrs"]["protocol"]) if(topology["nodes"][lxc]["attrs"]["protocol"]=="rip"): cmd.createRipd(lxc,vmInterfaceList,vmInterfaceDict) elif(topology["nodes"][lxc]["attrs"]["protocol"]=="ospf"): cmd.createOspf(lxc,vmInterfaceList,vmInterfaceDict,address) address+=1 #else #start rf cmd.startNox("switch","6363") cmd.startNox("routeflowc","6666") cmd.startRf() for lxc in lxcList: cmd.lxcStart(lxc) cmd.ovsOpenflowd('dp0', '127.0.0.1', 6666, 'rfovs') cmd.ifconfig('dp0', 'up') cmd.ovsOpenflowd('br0', '127.0.0.1', 6363) cmd.ifconfig('br0', 'up', '192.168.1.1', '255.255.255.0') for lxc in lxcList: vmInterfaceList=topology["nodes"][lxc]["interface"].keys() for vmInterface in vmInterfaceList: cmd.ovsDpctl("dp0",vmInterface) for lxc in lxcList: cmd.ovsDpctl("br0",lxc+".0")