Beispiel #1
0
    def __init__(self, props, controller_vip):
        check_mandatory_values(props, ['name'])
        self.props = props

        self.name = props.get('name')
        self.protocol = 'http' if not props.get(
            'protocol') else props['protocol']
        self.vip = props.get['vip'] if props.get('vip') else controller_vip
        self.ip = '127.0.0.1' if not props.get('ip') else props['ip']
        self.port = '8181' if not props.get('port') else int(props['port'])
        self.user = '******' if not props.get('user') else props['user']
        self.password = '******' if not props.get(
            'password') else props['password']
        self.timeout = 30 if not props.get('timeout') else int(
            props['timeout'])
        self.sshuser = '******' if not props.get('sshuser') else props['sshuser']
        self.sshpassword = '******' if not props.get(
            'sshpassword') else props['sshpassword']
        self.sshport = '22' if not props.get('sshport') else props['sshport']

        # if IP address and user is not given
        # then we need to assume OVS is running locally
        self.execute_local = not props.get('ip') and not props.get('sshuser')
        self.execute_local = True if self.ip == '127.0.0.1' else self.execute_local

        self.fm_prefix = None
        self.lumina = False
Beispiel #2
0
def test_check_mandatory_values():
    props = return_switch()
    if props.get('switch'):
        for properties in props['switch']:
            print properties
            output = check_mandatory_values(properties, properties)
            assert output is None
Beispiel #3
0
 def __init__(self, props, expected=False):
     check_mandatory_values(props, ['name', 'ip'])
     self.props = props
     self.expected = expected
     self.ip = props['ip'].split(
         '/')[0] if '/' in props['ip'] else props['ip']
     self.mask = props['ip'].split('/')[1] if '/' in props['ip'] else '24'
     self.hosts_ip = {}
     self.hosts_ip[props['name']] = props['ip'].split('/')[0]
     self.type = 'mininet' if not props.get('type') else props['type']
     self.user = '******' if not props.get('user') else props['user']
     self.password = '******' if not props.get(
         'password') else props['password']
     self.port = 22 if not props.get('port') else props['port']
     self.mac = None if not props.get('mac') else props['mac']
     self.name = props['name']
     self.openflow_name = 'host:' + self.mac if self.mac else self.name
Beispiel #4
0
 def __init__(self, props, expected=False):
     self.found_openflow_topology = False
     self.found_sr_topology = False
     self.found_connected = False
     check_mandatory_values(props, ['name', 'dpid'])
     self.props = props
     self.expected = expected
     self.name = unicode(props['name'])
     self.dpid = str(int(props['dpid'], 16))
     self.openflow_name = "openflow:" + str(int(props['dpid'], 16))
     self.type = 'unknown' if not props.get('type') else props['type']
     self.user = None if not props.get('user') else props['user']
     self.password = None if not props.get(
         'password') else props['password']
     self.ip = None if not props.get('ip') else props['ip']
     self.port = 22 if not props.get('port') else props['port']
     self.links = {}
     self.flows = {}
     self.flows_by_name = {}
     self.flows_by_id = {}
     self.groups = {}
     logging.debug('SWITCH: created switch %s(%s), type %s, ip %s, dpid %s',
                   self.name, self.openflow_name, self.type, self.ip,
                   props['dpid'])
Beispiel #5
0
    def __init__(self, props):
        # Disable warnings
        try:
            urllib3.disable_warnings()
            from requests.packages.urllib3.exceptions import InsecureRequestWarning
            from requests.packages.urllib3.disable_warnings import InsecureRequestWarning
        except ImportError:
            pass

        self.hosts = {}
        self.hosts_by_openflow_name = {}
        if props.get('host'):
            for properties in props['host']:
                new_host = Host(properties, True)
                self.add_host(new_host)

        self.switches = {}
        self.switches_by_openflow_name = {}
        self.switches_by_dpid = {}
        if props.get('switch'):
            for properties in props['switch']:
                switch_type = get_switch_type(properties)
                if switch_type and switch_type == 'noviflow':
                    new_switch = Noviflow(properties, True)
                else:
                    new_switch = OVS(properties, True)

                self.add_switch(new_switch)
                # logging.info(self.switches.values())

        self.controllers = {}
        self.ctrl_name = None
        if props.get('controller'):
            for properties in props['controller']:
                new_controller = Controller(properties,
                                            props.get('controller_vip'))
                self.controllers[new_controller.name] = new_controller
                if not self.ctrl_name:
                    self.ctrl_name = new_controller.name
        else:
            new_controller = Controller({'name': 'c0'},
                                        props.get('controller_vip'))
            self.controllers[new_controller.name] = new_controller
            if not self.ctrl_name:
                self.ctrl_name = new_controller.name

        self.default_ctrl = self.get_random_controller()

        self.links = {}
        if props.get('link'):
            ports = {}
            for link in props['link']:
                check_mandatory_values(link, ['source', 'destination'])

                src_switch = self.get_switch(link['source'])
                src_name = src_switch.openflow_name if src_switch else None

                dst_switch = self.get_switch(link['destination'])
                dst_name = dst_switch.openflow_name if dst_switch else None

                src_host = self.get_host(
                    link['source']) if not src_switch else None
                dst_host = self.get_host(
                    link['destination']) if not dst_switch else None

                if src_switch:
                    src_port = link.get('source_port')
                    if not src_port:
                        if src_name not in ports:
                            ports[src_name] = 1
                        link['source_port'] = ports[src_name]
                        src_port = ports[src_name]
                        ports[src_name] = ports[src_name] + 1

                if dst_switch:
                    dst_port = link.get('destination_port')
                    if not dst_port:
                        if dst_name not in ports:
                            ports[dst_name] = 1
                        link['destination_port'] = ports[dst_name]
                        dst_port = ports[dst_name]
                        ports[dst_name] = ports[dst_name] + 1

                # add the links
                if src_switch and dst_switch:
                    src_switch.get_link(
                        src_switch.openflow_name + ':' + str(src_port),
                        dst_switch.openflow_name + ':' + str(dst_port))
                    dst_switch.get_link(
                        dst_switch.openflow_name + ':' + str(dst_port),
                        src_switch.openflow_name + ':' + str(src_port))

                elif src_switch and dst_host:
                    src_switch.get_link(
                        src_switch.openflow_name + ':' + str(src_port),
                        dst_host.openflow_name)

                elif dst_switch and src_host:
                    dst_switch.get_link(
                        dst_switch.openflow_name + ':' + str(dst_port),
                        src_host.openflow_name)