Esempio n. 1
0
    def addMesh(self, node, cls=None, **params):
        """
        Configure wireless mesh
        
        node: name of the node
        cls: custom association class/constructor
        params: parameters for node
        """
        if 'intf' in params:
            for intf_ in node.params['wlan']:
                if params['intf'] == intf_:
                    wlan = node.params['wlan'].index(intf_)
        else:
            if node.type == 'station':
                wlan = node.ifaceToAssociate
            else:
                wlan = node.ifaceToAssociate

        node.func[wlan] = 'mesh'
        node.params['txpower'][wlan] = 20

        options = {
            'ip':
            ipAdd(params['nextIP'],
                  ipBaseNum=params['ipBaseNum'],
                  prefixLen=params['prefixLen']) + '/%s' % params['prefixLen']
        }

        if node.type == 'ap':
            node.params['ssid'].append('')
        else:
            node.params['ssid'] = []
            for n in range(len(node.params['wlan'])):
                node.params['ssid'].append('')

        ip = ("%s" % params.pop('ip', {}))
        if ip == "{}":
            ip = options['ip']

        ssid = ("%s" % params['ssid'])
        if (ssid != "{}"):
            node.params['ssid'][wlan] = ssid
        else:
            node.params['ssid'][wlan] = 'meshNetwork'

        deviceRange(node)

        options['node'] = node
        options.update(params)

        node.setMeshIface(node.params['wlan'][wlan])
        if 'channel' in params:
            node.setChannel(node.params['wlan'][wlan], params['channel'])

        cls = Association
        cls.configureMesh(node, wlan)
        if 'intf' not in params:
            node.ifaceToAssociate += 1
Esempio n. 2
0
    def addHoc(self, node, cls=None, **params):
        """
        Configure AdHoc
        
        node: name of the node
        cls: custom association class/constructor
        params: parameters for station
           
        """
        if 'intf' in params:
            for intf_ in node.params['wlan']:
                if params['intf'] == intf_:
                    wlan = node.params['wlan'].index(intf_)
        else:
            wlan = node.ifaceToAssociate

        node.func[wlan] = 'adhoc'
        node.params['txpower'][wlan] = 20

        node.params['ssid'] = []
        for w in range(0, len(node.params['wlan'])):
            node.params['ssid'].append('')

        ssid = ("%s" % params.pop('ssid', {}))
        if (ssid != "{}"):
            node.params['ssid'][wlan] = ssid
            node.params['associatedTo'][wlan] = ssid
        else:
            node.params['ssid'][wlan] = 'adhocNetwork'
            node.params['associatedTo'][wlan] = 'adhocNetwork'

        deviceRange(node)

        value = deviceDataRate(sta=node, wlan=wlan)
        self.bw = value.rate

        enable_wmediumd = self.useWmediumd

        if 'channel' in params:
            node.setChannel(node.params['wlan'][wlan], params['channel'])

        cls = Association
        cls.configureAdhoc(node, wlan, enable_wmediumd)
        if 'intf' not in params:
            node.ifaceToAssociate += 1
Esempio n. 3
0
    def addMesh(self, node, cls=None, **params):
        """
        Configure wireless mesh
        
        node: name of the node
        cls: custom association class/constructor
        params: parameters for node
        """
        if 'intf' in params:
            for intf_ in node.params['wlan']:
                if params['intf'] == intf_:
                    wlan = node.params['wlan'].index(intf_)
        else:
            if node.type == 'station':
                wlan = node.ifaceToAssociate
            else:
                wlan = node.ifaceToAssociate

        node.func[wlan] = 'mesh'
        node.params['txpower'][wlan] = 20

        if node.type == 'ap':
            node.params['ssid'].append('')
        else:
            node.params['ssid'] = []
            for n in range(len(node.params['wlan'])):
                node.params['ssid'].append('')

        ssid = ("%s" % params['ssid'])
        if (ssid != "{}"):
            node.params['ssid'][wlan] = ssid
        else:
            node.params['ssid'][wlan] = 'meshNetwork'

        deviceRange(node)

        node.setMeshIface(node.params['wlan'][wlan])
        if 'channel' in params:
            node.setChannel(node.params['wlan'][wlan], params['channel'])

        cls = Association
        cls.configureMesh(node, wlan)
        if 'intf' not in params:
            node.ifaceToAssociate += 1
Esempio n. 4
0
    def addParameters(self, node, autoSetMacs, params, mode='managed'):
        """adds parameters to wireless nodes

        node: node
        autoSetMacs: set MAC addrs automatically like IP addresses
        params: parameters
        defaults: Default IP and MAC addresses
        mode: if interface is running in managed or master mode
        """
        node.params['frequency'] = []
        node.params['wlan'] = []
        node.params['mac'] = []
        node.phyID = []

        passwd = ("%s" % params.pop('passwd', {}))
        if (passwd != "{}"):
            passwd = passwd.split(',')
            node.params['passwd'] = []

        encrypt = ("%s" % params.pop('encrypt', {}))
        if (encrypt != "{}"):
            encrypt = encrypt.split(',')
            node.params['encrypt'] = []

        if (mode == 'managed'):
            node.params['apsInRange'] = []
            node.params['associatedTo'] = []
            node.params['rssi'] = []
            node.params['snr'] = []
            node.ifaceToAssociate = 0
            node.max_x = 0
            node.max_y = 0
            node.min_x = 0
            node.min_y = 0
            node.max_v = 0
            node.min_v = 0
            node.constantVelocity = 1.0
            node.constantDistance = 1.0

            # max_speed
            if 'max_speed' in params:
                node.max_speed = int(params['max_speed'])
            else:
                node.max_speed = 10

            # min_speed
            if 'min_speed' in params:
                node.min_speed = int(params['min_speed'])
            else:
                node.min_speed = 1

        # speed
        if 'speed' in params:
            node.speed = int(params['speed'])

        # max_x
        if 'max_x' in params:
            node.max_x = int(params['max_x'])

        # max_y
        if 'max_y' in params:
            node.max_y = int(params['max_y'])

        # min_x
        if 'min_x' in params:
            node.min_x = int(params['min_x'])

        # min_y
        if 'min_y' in params:
            node.min_y = int(params['min_y'])

        # min_v
        if 'min_v' in params:
            node.min_v = int(params['min_v'])

        # max_v
        if 'max_v' in params:
            node.max_v = int(params['max_v'])

        # constantVelocity
        if 'constantVelocity' in params:
            node.constantVelocity = int(params['constantVelocity'])

        # constantDistance
        if 'constantDistance' in params:
            node.constantDistance = int(params['constantDistance'])

        # position
        if 'position' in node.params:
            position = node.params['position']
            position = position.split(',')
            node.params['position'] = [
                float(position[0]),
                float(position[1]),
                float(position[2])
            ]
        else:
            position = ("%s" % params.pop('position', {}))
            if (position != "{}"):
                position = position.split(',')
                node.params['position'] = position

        wlans = self.countWiFiIfaces(params)

        for n in range(wlans):
            self.addParamsToNode(node)
            if mode == 'managed':
                self.appendAssociatedTo(node)
                if 'ssid' not in node.params:
                    self.appendEncrypt(node, n, passwd, encrypt)

            if mode == 'master':
                if 'phywlan' in node.params:
                    n = 1
                node.params['wlan'].append(node.name + '-wlan' + str(n + 1))
                if 'link' in params and params['link'] == 'mesh':
                    self.appendRSSI(node)
                    self.appendSNR(node)
                    self.appendAssociatedTo(node)
            else:
                node.params['wlan'].append(node.name + '-wlan' + str(n))
                self.appendRSSI(node)
                self.appendSNR(node)
            node.params.pop("wlans", None)

        if (mode == 'managed'):
            self.addMacParamToNode(node, wlans, autoSetMacs, params)
            self.addIpParamToNode(node, wlans, autoSetMacs, params)

        self.addAntennaHeightParamToNode(node, wlans, params)
        self.addAntennaGainParamToNode(node, wlans, params)
        self.addTxPowerParamToNode(node, wlans, params)
        self.addChannelParamToNode(node, wlans, params)
        self.addModeParamToNode(node, wlans, params)

        # Equipment Model
        equipmentModel = ("%s" % params.pop('equipmentModel', {}))
        if (equipmentModel != "{}"):
            node.equipmentModel = equipmentModel

        # Range
        if 'range' in params:
            node.params['range'] = int(params['range'])
        else:
            if mode == 'master' or node.func[0] == 'ap':
                value = deviceRange(node)
                node.params['range'] = value.range
            else:
                value = deviceRange(node)
                node.params['range'] = value.range - 15

        if mode == 'master' or 'ssid' in node.params:
            node.params['associatedStations'] = []
            node.params['stationsInRange'] = {}
            node.wds = False

            if 'config' in node.params:
                config = node.params['config']
                if (config != []):
                    config = node.params['config'].split(',')
                    for conf in config:
                        if 'wpa=' in conf or 'wpe=' in conf:
                            node.params['encrypt'] = []
                        if 'wpa=' in conf:
                            node.params['encrypt'].append('wpa')
                        if 'wpe=' in conf:
                            node.params['encrypt'].append('wpe')

            if mode == 'master':
                node.params['mac'] = []
                node.params['mac'].append('')
                if 'mac' in params:
                    node.params['mac'][0] = params['mac']

                ssid = ("%s" % params.pop('ssid', {}))
                ssid = ssid.split(',')
                node.params['ssid'] = []
                if (ssid[0] != "{}"):
                    if len(ssid) == 1:
                        node.params['ssid'].append(ssid[0])
                        if (encrypt != "{}"):
                            node.params['encrypt'].append(encrypt[0])
                        if (passwd != "{}"):
                            node.params['passwd'].append(passwd[0])
                    else:
                        for n in range(len(ssid)):
                            node.params['ssid'].append(ssid[n])
                            self.appendEncrypt(node, n, passwd, encrypt)
                else:
                    node.params['ssid'].append(params['ssid'])
Esempio n. 5
0
    def addHoc(self, node, cls=None, **params):
        """
        Configure AdHoc
        
        node: name of the node
        cls: custom association class/constructor
        params: parameters for station
           
        """
        if 'intf' in params:
            for intf_ in node.params['wlan']:
                if params['intf'] == intf_:
                    wlan = node.params['wlan'].index(intf_)
        else:
            wlan = node.ifaceToAssociate

        node.func[wlan] = 'adhoc'

        options = {
            'ip':
            ipAdd(params['nextIP'],
                  ipBaseNum=params['ipBaseNum'],
                  prefixLen=params['prefixLen']) + '/%s' % params['prefixLen']
        }
        options.update(params)

        node.params['cell'] = []
        node.params['ssid'] = []
        for w in range(0, len(node.params['wlan'])):
            node.params['cell'].append('')
            node.params['ssid'].append('')

        ip = ("%s" % params.pop('ip', {}))
        if ip == "{}":
            ip = options['ip']

        ssid = ("%s" % params.pop('ssid', {}))
        if (ssid != "{}"):
            node.params['ssid'][wlan] = ssid
            node.params['associatedTo'][wlan] = ssid
        else:
            node.params['ssid'][wlan] = 'adhocNetwork'
            node.params['associatedTo'][wlan] = 'adhocNetwork'

        cell = ("%s" % params.pop('cell', {}))
        if (cell != "{}"):
            node.params['cell'][wlan] = cell
        else:
            if 'position' not in node.params:
                node.params['cell'][wlan] = 'FE:4C:6A:B5:A9:7E'

        deviceRange(node)

        value = deviceDataRate(sta=node, wlan=wlan)
        self.bw = value.rate

        options['sta'] = node
        options.update(params)
        # Set default MAC - this should probably be in Link
        options.setdefault('addr1', self.randMac())

        cls = Association
        cls.configureAdhoc(node, self.useWmediumd)
        if 'intf' not in params:
            node.ifaceToAssociate += 1
Esempio n. 6
0
    def addMesh(self, node, cls=None, **params):
        """
        Configure wireless mesh
        
        node: name of the node
        cls: custom association class/constructor
        params: parameters for node
        """
        if 'intf' in params:
            for intf_ in node.params['wlan']:
                if params['intf'] == intf_:
                    wlan = node.params['wlan'].index(intf_)
        else:
            if node.type == 'station':
                wlan = node.ifaceToAssociate
            else:
                wlan = 0

        node.func[wlan] = 'mesh'

        options = {
            'ip':
            ipAdd(params['nextIP'],
                  ipBaseNum=params['ipBaseNum'],
                  prefixLen=params['prefixLen']) + '/%s' % params['prefixLen']
        }
        options.update(params)

        node.params['ssid'] = []
        if hasattr(node, 'meshMac'):
            for n in range(len(node.params['wlan'])):
                node.meshMac.append('')
                node.params['ssid'].append('')
        else:
            node.meshMac = []
            for n in range(len(node.params['wlan'])):
                node.meshMac.append('')
                node.params['ssid'].append('')

        ip = ("%s" % params.pop('ip', {}))
        if ip == "{}":
            ip = options['ip']

        ssid = ("%s" % params['ssid'])
        if (ssid != "{}"):
            node.params['ssid'][wlan] = ssid
        else:
            node.params['ssid'][wlan] = 'meshNetwork'

        deviceRange(node)

        value = deviceDataRate(sta=node, wlan=wlan)
        self.bw = value.rate

        options['node'] = node
        options.update(params)

        # Set default MAC - this should probably be in Link
        options.setdefault('addr1', self.randMac())

        cls = Association
        cls.configureMesh(node, wlan)
        if 'intf' not in params:
            node.ifaceToAssociate += 1