示例#1
0
class Resolve_Ctl_Misconfig(threading.Thread):
    def __init__(self, net_device, true_ctl_config):
        threading.Thread.__init__(self)
        self.net_device = net_device
        self.true_ctl_config = true_ctl_config

    def run(self):
        self.net_connect = ConnectHandler(**self.net_device)
        self.net_connect.find_prompt()

        #Remove false ctl config
        command = "sudo -S <<< 7654321 ovs-vsctl del-controller {}".format(
            BRIDGE)
        output = self.net_connect.send_command_timing(command,
                                                      strip_command=False,
                                                      strip_prompt=False)

        #Add true ctl config
        command = "sudo -S <<< 7654321 ovs-vsctl set-controller {} {}".format(
            BRIDGE, self.true_ctl_config)
        output = self.net_connect.send_command_timing(command,
                                                      strip_command=False,
                                                      strip_prompt=False)
示例#2
0
class Check_Ctl_Connectivity(threading.Thread):
    def __init__(self, net_device):
        threading.Thread.__init__(self)
        self.net_device = net_device

    def run(self):
        self.net_connect = ConnectHandler(**self.net_device)
        self.net_connect.find_prompt()
        output = self.net_connect.send_command_timing(
            "sudo -S <<< 7654321 ovs-vsctl show | grep is_connected",
            strip_command=False,
            strip_prompt=False)
        output = output.split('\n')[1]

        if 'true' in output:
            connected_ovses.append(self.net_device['ip'])

        else:
            #disconnected_ovses.append(self.net_device['ip'])
            command = "sudo -S <<< 7654321 ovs-vsctl get-controller {}".format(
                BRIDGE)
            controller_config = self.net_connect.send_command_timing(
                command, strip_command=False, strip_prompt=False)
            controller_config = controller_config.split('\n')[1]

            of_ver = self.net_connect.send_command_timing(
                "sudo -S <<< 7654321 ovs-vsctl get bridge br0 protocols",
                strip_command=False,
                strip_prompt=False)
            of_ver = of_ver.split('\n')[1]
            of_versions = re.findall(r'OpenFlow\d+', of_ver)

            disconnected_ovses.append({
                'switch_mgmt_ip': self.net_device['ip'],
                'controller_config': controller_config,
                'of_versions': of_versions,
            })
示例#3
0
class Resolve_Ver_Mismatch(threading.Thread):
    def __init__(self, net_device, true_of_version):
        threading.Thread.__init__(self)
        self.net_device = net_device
        self.true_of_version = true_of_version

    def run(self):
        self.net_connect = ConnectHandler(**self.net_device)
        self.net_connect.find_prompt()

        #Add true_of_version
        command = "sudo -S <<< 7654321 ovs-vsctl set bridge {} protocols={}".format(
            BRIDGE, self.true_of_version)

        output = self.net_connect.send_command_timing(command,
                                                      strip_command=False,
                                                      strip_prompt=False)

        print("Added Version: {}, Switch: {}".format(self.true_of_version,
                                                     self.net_device['ip']))
示例#4
0
class Check_BGP_Misconfig(threading.Thread):
    def __init__(self, net_device):
        threading.Thread.__init__(self)
        self.net_device = net_device

    def run(self):
        global misconfigured_routers_info
        #true remote ip is controller
        self.true_remote_as, self.true_remote_ip = get_bgp_config(
            self.net_device['ip'])

        self.net_connect = ConnectHandler(**self.net_device)
        #Assuming one neighbor
        self.neighbor_line = self.net_connect.send_command_timing(
            "sh run | include neighbor | exclude bgp",
            strip_command=False,
            strip_prompt=False)
        self.neighbor_line_list = self.neighbor_line.split()

        self.bgp_line = self.net_connect.send_command_timing(
            "sh run | include router bgp",
            strip_command=False,
            strip_prompt=False)

        self.bgp_line_list = self.bgp_line.split()

        self.local_as = self.bgp_line_list[8]
        self.neighbor_line = self.neighbor_line.split('bgp\n ')[-1]
        self.neighbor_line = self.neighbor_line.split('\n')[0]

        if len(self.neighbor_line_list) != 0:
            #Check for misconfiguration
            configured_remote_as = self.neighbor_line_list[3]
            configured_remote_ip = self.neighbor_line_list[1]

            if self.true_remote_as == configured_remote_as and configured_remote_ip == self.true_remote_ip:
                pass

            else:
                misconfigured_routers_info.append({
                    'router_ip':
                    self.net_device['ip'],
                    'local_as':
                    self.local_as,
                    'misconfigured_line':
                    self.neighbor_line,
                    'true_remote_as':
                    self.true_remote_as,
                    'true_remote_ip':
                    self.true_remote_ip
                })

        #Neighbor not configured at all. Configure now
        else:
            misconfigured_routers_info.append({
                'router_ip':
                self.net_device,
                'local_as':
                self.local_as,
                'misconfigured_line':
                None,
                'true_remote_as':
                self.true_remote_as,
                'true_remote_ip':
                self.true_remote_ip
            })