コード例 #1
0
    def __init__(self, worker, mac, ip, ap, gateway_ip=None, client_info=None):
        """Create a Wireless Client attached to an AP.

        Args:
            worker: attached worker
            mac: mac address for the client, in str format
            ip: ip address for the client, in str format, or None in case of DHCP
            ap: attached AP
            gateway_ip: ip of the gateway, optional if e.g. DHCP, in byte format
            client_info (ClientInfo): original ClientInfo
        """
        name = "Client_{}".format(mac)
        super().__init__(worker, name, mac, gateway_ip, client_info)

        self.mac_bytes = mac2str(mac)
        self.mac = mac
        if not ip:
            self.ip = None
            self.ip_bytes = None
            self.dhcp = True  # flag is set to True if DHCP is needed to get an IP address
        else:
            self.dhcp = False
            check_ipv4_addr(ip)
            self.ip_bytes = is_valid_ipv4_ret(ip)
            self.ip = ip
        check_mac_addr(self.mac)
        # assert isinstance(ap, AP)
        self.ap = ap
        self.reset()
        self.retries = 0
        self.state = ClientState.AUTHENTICATION
        self.gateway_ip = None

        # event awaken when the client is associated
        self.joined_event = threading.Event()
    def __init__(self, port_id, ip, mac, radio_mac, udp_port, wlc_ip,
                 gateway_ip, ap_mode, rsa_ca_priv_file, rsa_priv_file,
                 rsa_cert_file):
        """Create the basic info for an AP.

        Args:
            port_id: the port id of the trex client that the AP will be attached to
            ip: ipv4 address of the AP, in string format, or None
            mac: mac address of the AP, in string format
            radio_mac: mac address of the AP, in string format
            udp_port: udp port of the AP for traffic
            wlc_ip: the ipv4 address of the wlc, or None in case of DHCP
            ap_mode: The Mode of the AP, APMode.LOCAL for Local mode APs, APMode.REMOTE for Remote aps (also called FlexConnect)
            rsa_ca_priv_file: rsa private key of WLC CA
            rsa_priv_file: rsa private key of AP (required if no rsa_ca_priv_file)
            rsa_cert_file: rsa certificate of AP (required if no rsa_ca_priv_file)
        """
        super().__init__(identifier=mac)
        # Mandatory parameters
        if not rsa_ca_priv_file and not (rsa_priv_file and rsa_cert_file):
            raise ValueError(
                "APInfo should be instanciated with values for either rsa_ca_priv_file either rsa_priv_file and rsa_cert_file"
            )

        if any([p is None for p in (port_id, mac, radio_mac, udp_port)]):
            raise ValueError(
                "APInfo should be instanciated with values for (port_id, mac, radio_mac, udp_port)"
            )

        # MAC addresses checks
        check_mac_addr(mac)
        check_mac_addr(radio_mac)

        # IP addresses checks
        if ip:
            check_ipv4_addr(ip)
        if wlc_ip:
            check_ipv4_addr(wlc_ip)
        if gateway_ip:
            check_ipv4_addr(gateway_ip)

        self.name = 'AP%s%s.%s%s.%s%s' % (mac[:2], mac[3:5], mac[6:8],
                                          mac[9:11], mac[12:14], mac[15:17])
        self.port_id = port_id
        self.mac = mac
        self.ip = ip
        self.radio_mac = radio_mac
        self.udp_port = udp_port
        self.wlc_ip = wlc_ip
        self.wlc_mac = None
        self.gateway_ip = gateway_ip
        self.ap_mode = ap_mode

        self.rsa_ca_priv_file = rsa_ca_priv_file
        self.rsa_priv_file = rsa_priv_file
        self.rsa_cert_file = rsa_cert_file

        self.clients = []
コード例 #3
0
ファイル: trex_stl_wlc.py プロジェクト: yeze/trex-core
 def __init__(self,
              ssl_ctx,
              logger,
              trex_port,
              mac,
              ip,
              port,
              radio_mac,
              verbose_level=VERB_WARN,
              rsa_priv_file=None,
              rsa_cert_file=None):
     self.ssl_ctx = ssl_ctx
     self.logger = logger
     self.trex_port = trex_port
     self.port_id = trex_port.port_id
     check_mac_addr(mac)
     check_ipv4_addr(ip)
     check_mac_addr(radio_mac)
     try:
         self.mac_bytes = mac2str(mac)
     except:
         raise Exception('Bad MAC format, expected aa:bb:cc:dd:ee:ff')
     self.mac = mac
     self.name = 'AP%s%s.%s%s.%s%s' % (mac[:2], mac[3:5], mac[6:8],
                                       mac[9:11], mac[12:14], mac[15:17])
     self.name_bytes = self.name.encode('ascii')
     assert '.' in ip, 'Bad IP format, expected x.x.x.x'
     self.ip_src = is_valid_ipv4_ret(ip)
     self.ip_hum = ip
     self.udp_port = port
     self.udp_port_str = int2str(port, 2)
     try:
         self.radio_mac_bytes = mac2str(radio_mac)
     except:
         raise Exception('Bad radio MAC format, expected aa:bb:cc:dd:ee:ff')
     self.radio_mac = radio_mac
     self.ssl = None
     self.in_bio = None
     self.out_bio = None
     self.serial_number = 'FCZ1853QQQ'
     self.country = 'CH '
     self.echo_req_interval = 60
     self.last_echo_req_ts = 0
     self.verbose_level = verbose_level
     self.clients = []
     self.rsa_priv_file = rsa_priv_file
     self.rsa_cert_file = rsa_cert_file
     self.capwap_MaxRetransmit = 5
     self.capwap_RetransmitInterval = 0.5
     self.ssl_lock = threading.RLock()
     self._create_ssl()
     self.reset_vars()
コード例 #4
0
ファイル: trex_stl_wlc.py プロジェクト: SeboPG/trex-core
 def __init__(self,
              ssl_ctx,
              logger,
              trex_port,
              mac,
              ip,
              wlc_ip,
              verbose_level=VERB_WARN,
              rsa_ca_priv_file=None,
              rsa_priv_file=None,
              rsa_cert_file=None):
     self.ssl_ctx = ssl_ctx
     self.logger = logger
     self.trex_port = trex_port
     self.port_id = trex_port.port_id
     check_mac_addr(mac)
     check_ipv4_addr(ip)
     try:
         self.mac_bytes = mac2str(mac)
     except:
         raise TRexError('Bad MAC format, expected aa:bb:cc:dd:ee:ff')
     self.mac = mac
     self.name = 'AP%s%s.%s%s.%s%s' % (mac[:2], mac[3:5], mac[6:8],
                                       mac[9:11], mac[12:14], mac[15:17])
     self.name_bytes = self.name.encode('ascii')
     assert '.' in ip, 'Bad IP format, expected x.x.x.x'
     self.ip_bytes = is_valid_ipv4_ret(ip)
     self.ip = ip
     self.udp_port = 50000  # should not matter
     self.udp_port_str = int2str(self.udp_port, 2)
     self.radio_mac_bytes = b'\x94' + self.ip_bytes + b'\x00'
     self.radio_mac = str2mac(self.radio_mac_bytes)
     self.ssl = None
     self.in_bio = None
     self.out_bio = None
     self.serial_number = 'FCZ1853QQQ'
     self.country = 'CH '
     self.echo_req_interval = 60
     self.last_echo_req_ts = 0
     self.verbose_level = verbose_level
     self.clients = []
     self.ap_mode = 'Local'
     self.rsa_priv_file = rsa_priv_file
     self.rsa_cert_file = rsa_cert_file
     self.rsa_ca_priv_file = rsa_ca_priv_file
     self.capwap_MaxRetransmit = 5
     self.capwap_RetransmitInterval = 0.5
     self.ssl_lock = threading.RLock()
     self.reset_vars()
     if wlc_ip and wlc_ip != '255.255.255.255':
         self.ip_dst = wlc_ip
         self.wlc_ip_bytes = is_valid_ipv4_ret(wlc_ip)
    def __init__(self, mac, ip, ap_info):
        """Create the basic info for an AP.

        Args:
            mac: mac address of the client in string format
            ip: ipv4 address of the client in string format, or None if DHCP
            ap_info: APInfo of the AP attached to the client
        """
        super().__init__(identifier=mac)
        # Mandatory parameters
        if any([p is None for p in (mac, ap_info)]):
            raise ValueError(
                "ClientInfo should be instanciated with values for (mac, ap_info)"
            )

        if not isinstance(ap_info, APInfo):
            raise ValueError("ClientInfo should be instanciated with a APInfo")

        self.ap_info = ap_info

        # MAC addresses check
        check_mac_addr(mac)

        self.mac_bytes = mac2str(mac)
        self.mac = mac

        if ip:
            # IP address check
            check_ipv4_addr(ip)
            self.ip_bytes = socket.inet_aton(ip)
            self.ip = ip
        else:
            self.ip = None
            self.ip_bytes = None

        self.name = "Client {} - {}".format(mac, ip)
        self.got_disconnect = False
        self.is_associated = False
        self.seen_arp_reply = False
        self.state = ClientState.ASSOCIATION
        self.retries = 0
        self.gateway_ip = self.ap_info.gateway_ip
コード例 #6
0
ファイル: trex_stl_wlc.py プロジェクト: tbarbette/trex-core
 def __init__(self, mac, ip, ap):
     if ':' in mac:
         self.mac_bytes = mac2str(mac)
         self.mac = mac
     else:
         self.mac_bytes = mac
         self.mac = str2mac(mac)
     if '.' in ip:
         self.ip_bytes = is_valid_ipv4_ret(ip)
         self.ip = ip
     elif len(ip) == 4:
         self.ip_bytes = ip
         self.ip = str2ip(ip)
     else:
         raise TRexError('Bad IP provided, should be x.x.x.x, got: %s' % ip)
     check_mac_addr(self.mac)
     check_ipv4_addr(self.ip)
     assert isinstance(ap, AP)
     self.ap = ap
     self.reset()
コード例 #7
0
ファイル: trex_stl_wlc.py プロジェクト: tbarbette/trex-core
    def set_base_values(self, mac = None, ip = None, client_mac = None, client_ip = None, wlc_ip = None, save = None, load = None):
        if load:
            if any([mac, ip, client_mac, client_ip, save]):
                raise TRexError('Can not use --load with other arguments.')
            if not os.path.exists(self.base_file_path):
                raise TRexError('No saved file.')
            try:
                self.trex_client.logger.pre_cmd('Loading base values')
                with open(self.base_file_path) as f:
                    base_values = yaml.safe_load(f.read())
                mac        = base_values['ap_mac']
                ip         = base_values['ap_ip']
                client_mac = base_values['client_mac']
                client_ip  = base_values['client_ip']
                if 'wlc_ip' in base_values:
                    wlc_ip = base_values['wlc_ip']
                else:
                    wlc_ip = '255.255.255.255'
            except Exception as e:
                self.trex_client.logger.post_cmd(False)
                raise TRexError('Parsing of config file %s failed, error: %s' % (self.base_file_path, e))
            self.trex_client.logger.post_cmd(True)

        # first pass, check arguments
        if mac:
            check_mac_addr(mac)
        if ip:
            check_ipv4_addr(ip)
        if client_mac:
            check_mac_addr(client_mac)
        if client_ip:
            check_ipv4_addr(client_ip)
        if wlc_ip:
            check_ipv4_addr(wlc_ip)

        # second pass, assign arguments
        if mac:
            self.next_ap_mac = mac
        if ip:
            self.next_ap_ip = ip
        if client_mac:
            self.next_client_mac = client_mac
        if client_ip:
            self.next_client_ip = client_ip
        if wlc_ip:
            self.wlc_ip = wlc_ip
        if save:
            self.trex_client.logger.pre_cmd('Saving base values')
            try:
                with open(self.base_file_path, 'w') as f:
                    f.write(yaml.dump({
                        'ap_mac':     self.next_ap_mac,
                        'ap_ip':      self.next_ap_ip,
                        'client_mac': self.next_client_mac,
                        'client_ip':  self.next_client_ip,
                        'wlc_ip':     self.wlc_ip,
                        }))
            except Exception as e:
                self.trex_client.logger.post_cmd(False)
                raise TRexError('Could not save config file %s, error: %s' % (self.base_file_path, e))
            self.trex_client.logger.post_cmd(True)
コード例 #8
0
    def __init__(self, worker, ssl_ctx, port_layer_cfg, port_id, mac, ip, port, radio_mac, wlc_ip, gateway_ip, ap_mode='Local', rsa_ca_priv_file=None, rsa_priv_file=None, rsa_cert_file=None, ap_info=None):
        """Create an AP.

        Args:
            worker: attached worker of the AP
            ssl_ctx: ssl context, see SSL_Context
            port_layer_cfg: configuration of the Trex Port
            port_id: port id of the Trex Server that the AP will be attached to
            mac: mac address of the AP in string format
            ip: ipv4 address of the AP in string format, or None in case of DHCP
            port: udp port of the AP, used to generate traffic
            radio_mac: mac address of the radio of the AP, in string format
            wlc_ip: ip of the WLC, in string format
            rsa_ca_priv_file: rsa private key of WLC CA
            rsa_priv_file: rsa private key of AP (required if no rsa_ca_priv_file)
            rsa_cert_file: rsa certificate of AP (required if no rsa_ca_priv_file)
            ap_info (APInfo): original APInfo
        """
        name = 'AP%s%s.%s%s.%s%s' % (
            mac[:2], mac[3:5], mac[6:8], mac[9:11], mac[12:14], mac[15:17])
        super().__init__(worker, name, mac, gateway_ip, ap_info)
        # global config
        from .trex_wireless_config import config

        # final attributes
        self.name = name
        self.name_bytes = name.encode('ascii')
        self.ssl_ctx = ssl_ctx
        self.event_store = worker.event_store  # to be used to set events
        self.port_id = port_id
        self.port_layer_cfg = port_layer_cfg
        self.rsa_priv_file = rsa_priv_file
        self.rsa_cert_file = rsa_cert_file
        self.rsa_ca_priv_file = rsa_ca_priv_file
        self.serial_number = 'FCZ1853QQQ'
        self.country = 'CH '
        self.ap_mode = ap_mode
        self.reset_vars()

        # ip, mac
        check_mac_addr(mac)
        check_mac_addr(radio_mac)
        self.mac = mac
        if ip:
            check_ipv4_addr(ip)
            self.ip = ip
            self.ip_bytes = socket.inet_aton(self.ip)
            self.dhcp = False  # flag set in case of DHCP
        else:
            self.ip = None
            self.dhcp = True

        self.udp_port = port
        self.radio_mac = radio_mac
        self.udp_port_str = int2str(port, 2)
        self.mac_bytes = mac2str(mac)
        self.radio_mac_bytes = mac2str(radio_mac)

        # wlc
        self.wlc_ip = None
        self.wlc_ip_bytes = None
        self.wlc_mac = None
        self.wlc_mac_bytes = None
        if wlc_ip and wlc_ip != '255.255.255.255':
            check_ipv4_addr(wlc_ip)
            self.wlc_ip = wlc_ip
            self.wlc_ip_bytes = socket.inet_aton(wlc_ip)

        # ssl
        self.ssl = None
        self.ssl_lock = self.lock  # threading.RLock()
        self.in_bio = None
        self.out_bio = None
        self._create_ssl(config.openssl.buffer_size)

        self.last_echo_req_ts = 0
        self.retries = 0

        self.clients = []

        # services
        self.active_service = None  # for internal services e.g. Join or Discover
コード例 #9
0
ファイル: trex_stl_wlc.py プロジェクト: yeze/trex-core
    def set_base_values(self,
                        mac=None,
                        ip=None,
                        udp=None,
                        radio=None,
                        client_mac=None,
                        client_ip=None,
                        save=None,
                        load=None):
        if load:
            if any([mac, ip, udp, radio, client_mac, client_ip, save]):
                raise Exception('Can not use --load with other arguments.')
            if not os.path.exists(self.base_file_path):
                raise Exception('No saved file.')
            try:
                self.trex_client.logger.pre_cmd('Loading base values')
                with open(self.base_file_path) as f:
                    base_values = yaml.safe_load(f.read())
                mac = base_values['ap_mac']
                ip = base_values['ap_ip']
                udp = base_values['ap_udp']
                radio = base_values['ap_radio']
                client_mac = base_values['client_mac']
                client_ip = base_values['client_ip']
            except Exception as e:
                self.trex_client.logger.post_cmd(False)
                raise Exception('Parsing of config file %s failed, error: %s' %
                                (self.base_file_path, e))
            self.trex_client.logger.post_cmd(True)

        # first pass, check arguments
        if mac:
            check_mac_addr(mac)
        if ip:
            check_ipv4_addr(ip)
        if udp:
            if udp < 1023 and udp > 65000:
                raise Exception(
                    'Base UDP port should be within range 1024-65000')
        if radio:
            check_mac_addr(radio)
            if radio.split(':')[-1] != '00':
                raise Exception('Radio MACs should end with zero, got: %s' %
                                radio)
        if client_mac:
            check_mac_addr(client_mac)
        if client_ip:
            check_ipv4_addr(client_ip)

        # second pass, assign arguments
        if mac:
            self.next_ap_mac = mac
        if ip:
            self.next_ap_ip = ip
        if udp:
            self.next_ap_udp = udp
        if radio:
            self.next_ap_radio = radio
        if client_mac:
            self.next_client_mac = client_mac
        if client_ip:
            self.next_client_ip = client_ip
        if save:
            self.trex_client.logger.pre_cmd('Saving base values')
            try:
                with open(self.base_file_path, 'w') as f:
                    f.write(
                        yaml.dump({
                            'ap_mac': self.next_ap_mac,
                            'ap_ip': self.next_ap_ip,
                            'ap_udp': self.next_ap_udp,
                            'ap_radio': self.next_ap_radio,
                            'client_mac': self.next_client_mac,
                            'client_ip': self.next_client_ip,
                        }))
            except Exception as e:
                self.trex_client.logger.post_cmd(False)
                raise Exception('Could not save config file %s, error: %s' %
                                (self.base_file_path, e))
            self.trex_client.logger.post_cmd(True)