Opendaylight 看不到拓扑

Opendaylight does not see the topology

提问人:Al3x4ndru1 提问时间:11/10/2023 最后编辑:Al3x4ndru1 更新时间:11/10/2023 访问量:29

问:

我有一个我无法理解的大问题。我有两个程序,一个使用 Spring Boot 3.1.2 的 Java 17,另一个在 Ubuntu 14.04 上使用 Python 2.7,VM 正在 VMware 上运行。不幸的是,我无法更改 Python 和 Ubuntu,所以我必须使用它们。我的主要问题是稳定性。我试图理解为什么有一天它运行良好,而有一天我遇到了很多问题。

我将 Miniet 用于第一台有问题的机器,而对于另一台控制器的机器,我使用的是 Opendaylight。

我将从 Java 代码开始,然后从 Python 代码开始。

Java 程序:

编写拓扑类:

public class Write_Topology {

    public String write_topology(HashMap<Integer,Node> nodes,
                                 String Topology_name ){
        ObjectMapper mapper = new ObjectMapper();
//        Path path = Paths.get(System.getProperty("userhome"), "api", Topology_name + ".json");
//        String path = System.getProperty("userhome") + "/api/" + Topology_name + ".json";
        String path = "/home/mininet/api/" + Topology_name + ".json";
        try {
            File file = new File(path);
            FileWriter fileWriter = new FileWriter(path);
            fileWriter.write(mapper.writeValueAsString(nodes));
            fileWriter.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return path;
    }
}

服务类:

@Service
public class Create_Topology_Service {

    private final Create_Topology create_topology = new Create_Topology();
    private final Check_host_range checkHostRange = new Check_host_range();
    private final Write_Topology writeTopology = new Write_Topology();

    public Optional create_topology_service_method(Create_Topology_Model createTopologyModel){

        HashMap<Integer,Node> nodes;

        try {
            if(checkHostRange.check_host_range_method(
                    createTopologyModel.ipBase,
                    createTopologyModel.number_of_hosts_per_switch,
                    createTopologyModel.number_of_switches
                    )) {

                nodes = create_topology
                        .create_topology(createTopologyModel.number_of_switches,
                                createTopologyModel.number_of_hosts_per_switch);

                String path = writeTopology.write_topology(nodes, createTopologyModel.topology_name);

                String[] cmd = getStrings(createTopologyModel,path);

                IndexController.process = Runtime.getRuntime().exec(cmd);
                System.out.println(IndexController.process.pid());
                Read_Output read_output = new Read_Output();
                read_output.read_output();

            }else{
                return Optional.of(getResponse());
            }

        }catch (Exception e){
            throw new RuntimeException(e);
        }
        return Optional.of(nodes);
    }

    private String[] getStrings(Create_Topology_Model createTopologyModel, String path) {

        if(createTopologyModel.controller_port!=0) {
            String command = "nohup sudo python ~/api/API_TEST.py " +
                    path +
                    " " +
                    createTopologyModel.ipBase +
                    " " +
                    createTopologyModel.controller_ip +
                    " " +
                    createTopologyModel.controller_port +
                    " " +
                    createTopologyModel.switches_name_prefix +
                    " " +
                    createTopologyModel.hosts_name_prefix +
                    " " +
                    createTopologyModel.number_of_switches +
                    " " +
                    createTopologyModel.number_of_hosts_per_switch +
                    " " +
                    "&";

            System.out.println(command);

            return new String[]{"/bin/bash", "-c", command};
        }

        String command = "nohup sudo python ~/api/API_TEST.py " +
                path +
                " " +
                createTopologyModel.ipBase +
                " " +
                createTopologyModel.controller_ip +
                " " +
                6633 +
                createTopologyModel.switches_name_prefix +
                " " +
                createTopologyModel.hosts_name_prefix +
                " " +
                createTopologyModel.number_of_switches +
                " " +
                createTopologyModel.number_of_hosts_per_switch +
                " " +
                "&";

        System.out.println(command);

        return new String[]{"/bin/bash", "-c", command};
    }

    private List<String> getResponse(){
        List<String> response = new ArrayList<>();
        response.add("Too many hosts the specified base Ip");
        response.add("1) You can reduce number of hosts per device");
        response.add("2) You can increase the number of hosts in the network");

     return response;
    }
}

端点:

@PostMapping(path = {"CreateTopology"})
public Optional create_topology(@RequestBody Create_Topology_Model createTopologyModel) {
    return this.createTopologyService.create_topology_service_method(createTopologyModel);
}

python 代码:

主文件:

#!/bin/python

import sys
import json
from Create_Topology2 import Create_Topology

if __name__ == '__main__':
    
    
    print(sys.argv[1])
    print(sys.argv[2],
        sys.argv[3],
        int(sys.argv[4]),
        sys.argv[5],
        sys.argv[6])
        
    with open(sys.argv[1], 'r') as f:
        data = json.load(f)
        print("2: ",sys.argv[2],
            "3: ",sys.argv[3],
            "4: ",int(sys.argv[4]),
            "5: ",sys.argv[5],
            "6: ",sys.argv[6],
            "data: ",data)
        
        topology = Create_Topology(sys.argv[2],
                                    sys.argv[3],
                                    int(sys.argv[4]),
                                    sys.argv[5],
                                    sys.argv[6],
                                    data)
        topology.create_topology()

The Create_Topology:

#!/bin/python


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 Random_nodes_service import random_nodes_service


class Create_Topology():
       
    def __init__(self,
                 ipBase,
                 controller_ip,
                 controller_port,
                 switches_name_prefix,
                 hosts_name_prefix,
                 topology
                ):
        self.ipBase = ipBase
        self.controller_ip = controller_ip
        self.controller_port = controller_port
        self.switches_name_prefix = switches_name_prefix
        self.hosts_name_prefix = hosts_name_prefix
        self.topology = topology
        self.copy_ipBase = ipBase
        self.host_number=0
        
        
    def get_host(self):

        ip = self.copy_ipBase.split('/')[0]
        
        a = ip.split('.')
        
        if 254 < (int(a[3]) + 1):
            if 254 < (int(a[2])+1):
                c = int(a[2]) +1
                host_ip = ""
                for b in range(0,1):
                    host_ip += a[b]+"."
                    
                host_ip += str(c) + "." + "0"+"."+"1"
                
                self.copy_ipBase = host_ip
                
                return host_ip
                
            else:
                c = int(a[2]) +1
                host_ip = ""
                for b in range(0,2):
                    host_ip += a[b]+"."
                    
                host_ip += str(c) + "." + "1"
                
                self.copy_ipBase = host_ip
                
                return host_ip
    
        c = int(a[3]) +1
        host_ip = ""
        for b in range(0,3):
            host_ip += a[b]+"."
            
        host_ip += str(c)
        
        self.copy_ipBase = host_ip
        
        return host_ip
        
            
    def create_topology(self):
        
        net = Mininet(topo=None,
                    build=False,
                    ipBase=self.ipBase)
        
        c0 = net.addController(name='c0',
                      controller=RemoteController,
                      ip=self.controller_ip, # variable that I will pass in the 
                      protocol='tcp',
                      port=self.controller_port) # vatiable with the default value of 6633
        

        switches_list = []
        
        for i in self.topology:
            print(i)
            switches_list.append(net.addSwitch((self.switches_name_prefix+str(i)), 
                                               cls=OVSKernelSwitch))
            

        print(switches_list)
        
        a=0
        
        for i in self.topology:
            
            for j in range(self.topology[i]["hosts"]):
                net.addLink(switches_list[int(i)],
                            net.addHost(
                                self.hosts_name_prefix+str(a+j), 
                                cls=Host,
                                ip=self.get_host(),
                                defaultRoute=None))
                a=a+1
            
            for j in self.topology[i]["list"]:
                
                net.addLink(switches_list[int(i)],switches_list[int(j)])
        
        
        info( '*** Starting network\n')
        net.build()
        
        info( '*** Starting controllers\n')
        for controller in net.controllers:
            controller.start()

        info( '*** Starting switches\n')
        for i in switches_list:
            net.get(str(i)).start([c0])

        info( '*** Post configure switches and hosts\n')
        CLI(net)
        net.stop()

现在让我解释一程:

Java 代码将获取包含详细信息的请求并创建拓扑。它会将其写入 JSON 文件,将命令行中的所有内容传递给 Python 脚本,并在后台执行我想运行的程序的工作。

输出为:

nohup sudo python ~/api/API_TEST.py /home/mininet/api/topology3.json 10.0.0.0/8 192.168.241.129 6633 sw h 10 10 &
nohup sudo python ~/api/API_TEST.py /home/mininet/api/topology3.json 10.0.0.0/8 192.168.241.129 6633 sw h 10 10 &
nohup sudo python ~/api/API_TEST.py /home/mininet/api/topology3.json 10.0.0.0/8 192.168.241.129 6633 sw h 10 10 &
/home/mininet/api/topology3.json
('10.0.0.0/8', '192.168.241.129', 6633, 'sw', 'h')
('2: ', '10.0.0.0/8', '3: ', '192.168.241.129', '4: ', 6633, '5: ', 'sw', '6: ', 'h', 'data: ', {u'1': {u'hosts': 3, u'list': [3, 4, 6, 7, 8, 9]}, u'0': {u'hosts': 3, u'list': [1, 3, 4, 5, 6, 7, 9]}, u'3': {u'hosts': 8, u'list': [4, 5, 6, 7, 8, 9]}, u'2': {u'hosts': 4, u'list': [3, 5, 6, 8, 9]}, u'5': {u'hosts': 8, u'list': [6, 7, 8]}, u'4': {u'hosts': 4, u'list': [5, 7]}, u'7': {u'hosts': 2, u'list': [8]}, u'6': {u'hosts': 7, u'list': [7, 8]}, u'9': {u'hosts': 0, u'list': []}, u'8': {u'hosts': 9, u'list': [9]}})
1
0
3
2
5
4
7
6
9
8
[<OVSSwitch sw1: lo:127.0.0.1 pid=9709> , <OVSSwitch sw0: lo:127.0.0.1 pid=9712> , <OVSSwitch sw3: lo:127.0.0.1 pid=9715> , <OVSSwitch sw2: lo:127.0.0.1 pid=9718> , <OVSSwitch sw5: lo:127.0.0.1 pid=9721> , <OVSSwitch sw4: lo:127.0.0.1 pid=9724> , <OVSSwitch sw7: lo:127.0.0.1 pid=9727> , <OVSSwitch sw6: lo:127.0.0.1 pid=9730> , <OVSSwitch sw9: lo:127.0.0.1 pid=9733> , <OVSSwitch sw8: lo:127.0.0.1 pid=9736> ]
mininet> 

在这种情况下,opendaylight 没有显示任何内容,如下图所示:enter image description here

如果我将相同的命令直接调用 python 脚本:

sudo python ~/api/API_TEST.py /home/mininet/api/topology3.json 10.0.0.0/8 192.168.241.129 6633 sw h 10 10

我会得到正确的输出:

enter image description here

此外,当我使用 nohup 运行 scrip 时:

nohup sudo python ~/api/API_TEST.py /home/mininet/api/topology3.json 10.0.0.0/8 192.168.241.129 6633 sw h 10 10 &

我会得到正确的输出:enter image description here

opendaylight 中的错误是:

Exception in thread "Thread-421" java.lang.IllegalStateException: Expected state: HANDSHAKING, actual state:RIP
    at org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl.checkState(ConnectionConductorImpl.java:386)
    at org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductorImpl.onConnectionReady(ConnectionConductorImpl.java:448)
    at org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterImpl$1.run(ConnectionAdapterImpl.java:185)
    at java.lang.Thread.run(Thread.java:750)

在这一点上,我仍在努力弄清楚我应该做些什么;如果您有任何建议,请随时发表评论。

python java linux mininet opendaylight

评论


答: 暂无答案