Ejemplo n.º 1
0
    def my_start_function(self):
        self.log.info("Topology control app started")

        # channel hopping every 100ms
        self.staTimer = TimerEventSender(self, PeriodicTimeEvent)
        self.staTimer.start(self.interval)

        self.running = True
Ejemplo n.º 2
0
    def my_start_function(self):
        print("BiGAP control app started")

        # channel hopping every 100ms
        self.staDiscoveryTimer = TimerEventSender(self, PeriodicSTADiscoveryTimeEvent)
        self.staDiscoveryTimer.start(self.sta_discovery_interval)

        self.running = True
Ejemplo n.º 3
0
    def __init__(self):
        super(MyController, self).__init__()
        self.log = logging.getLogger('MyController')
        self.running = False
        self.nodes = []

        self.timeInterval = 10
        self.timer = TimerEventSender(self, PeriodicEvaluationTimeEvent)
        self.timer.start(self.timeInterval)
Ejemplo n.º 4
0
class MininetWiFiController(modules.ControlApplication):
    def __init__(self):
        super(MininetWiFiController, self).__init__()
        self.log = logging.getLogger('MininetWiFiController')
        self.interval = 5
        self.nodes = {}  # APs UUID -> node
        self.running = False

    @modules.on_start()
    def my_start_function(self):
        self.log.info("Topology control app started")

        # channel hopping every 100ms
        self.staTimer = TimerEventSender(self, PeriodicTimeEvent)
        self.staTimer.start(self.interval)

        self.running = True

    @modules.on_exit()
    def my_stop_function(self):
        self.running = False

    @modules.on_event(events.NewNodeEvent)
    def add_node(self, event):
        node = event.node

        self.log.info("Added new node: {}".format(node.uuid))
        self.nodes[node.uuid] = node

    @modules.on_event(events.NodeExitEvent)
    @modules.on_event(events.NodeLostEvent)
    def remove_node(self, event):
        self.log.info("Node lost".format())
        node = event.node
        reason = event.reason
        if node.uuid in self.nodes:
            del self.nodes[node.uuid]
            self.log.info("Node: {}, removed reason: {}".format(
                node.uuid, reason))

    @modules.on_event(PeriodicTimeEvent)
    def periodic_tx_stats(self, event):

        self.log.info("Periodic getting tx stats")
        self.staTimer.start(self.interval)

        try:

            ap_uuids = list(self.nodes.keys())

            for ap_uuid in ap_uuids:
                ap_node = self.nodes[ap_uuid]

                if ap_node.name == "AP1":
                    node_iface = 'ap1-wlan0'
                elif ap_node.name == "AP2":
                    node_iface = 'ap2-wlan0'

                self.log.info("Querying node ... %s for iface: %s" %
                              (ap_node.name, node_iface))
                ap_sta = ap_node.net.get_tx_bytes_of_connected_devices(
                    node_iface)

                self.log.info('STAs of AP:\n{}'.format(pprint.pformat(ap_sta)))

        except Exception as e:
            self.log.error("{} !!!Exception!!!: {}".format(
                datetime.datetime.now(), e))
Ejemplo n.º 5
0
class BigAPController(modules.ControlApplication):
    """
    BigAP controller - makes handover decisions based on the CQI reports of the APs.
    Gets information about new clients from DHCP.
    """
    def __init__(self, mode, ap_iface):
        super(BigAPController, self).__init__()
        self.log = logging.getLogger('BigAPController')
        self.mode = mode
        self.ap_iface = ap_iface
        self.sta_discovery_interval = 5

        self.running = False
        self.activeSTAs = {}  # MAC_ADDR -> IP_ADDR
        self.nodes = {}  # APs UUID -> node
        self.servingAPs = {}  # STA_MAC_ADDR -> AP node


    @modules.on_start()
    def my_start_function(self):
        print("BiGAP control app started")

        # channel hopping every 100ms
        self.staDiscoveryTimer = TimerEventSender(self, PeriodicSTADiscoveryTimeEvent)
        self.staDiscoveryTimer.start(self.sta_discovery_interval)

        self.running = True


    @modules.on_exit()
    def my_stop_function(self):
        print("BiGAP control app stopped")
        self.running = False


    @modules.on_event(events.NewNodeEvent)
    def add_node(self, event):
        node = event.node

        if self.mode == "GLOBAL" and node.local:
            return

        self.log.info("Added new node: {}, Local: {}"
                      .format(node.uuid, node.local))
        self.nodes[node.uuid] = node

        devs = node.get_devices()
        for dev in devs:
            self.log.info("Dev: ", dev.name)


    @modules.on_event(events.NodeExitEvent)
    @modules.on_event(events.NodeLostEvent)
    def remove_node(self, event):
        self.log.info("Node lost".format())
        node = event.node
        reason = event.reason
        if node in self.nodes:
            del self.nodes[node.uuid]
            self.log.info("Node: {}, Local: {} removed reason: {}"
                          .format(node.uuid, node.local, reason))


    @modules.on_event(PeriodicSTADiscoveryTimeEvent)
    def periodic_sta_discovery(self, event):
        if self.node is None:
            return

        self.log.debug("Periodic STA discovery")
        self.log.debug("My node: %s" % self.node.uuid)
        self.staDiscoveryTimer.start(self.sta_discovery_interval)

        try:
            active_sta_mac_addrs = list(self.nodes.keys())

            for sta_mac_addr_tmp in active_sta_mac_addrs:
                self.send_servingAP_req(sta_mac_addr_tmp, self.ap_iface)
        except Exception as e:
            self.log.error("{} !!!Exception!!!: {}".format(
                datetime.datetime.now(), e))


    @modules.on_event(CQIReportingEvent)
    def serve_cqi_report_event(self, event):
        '''
            From APs
        '''
        curr_sigpower = event.curr_sigpower
        candidate_sigpower = event.candidate_sigpower
        self.log.info("CQIReportingEvent curr: {}"
                      .format(curr_sigpower))
        self.log.info("CQIReportingEvent curr: {}"
                      .format(candidate_sigpower))

        # data structure: STA_MAC_ADDR -> dBm
        mac_addrs = list(self.curr_sigpower.keys())

        for sta_mac_addr in mac_addrs:
            print('tbd')
            pass


    @modules.on_event(DHCPNewEvent)
    def serve_dhcp_new_event(self, event):
        '''
            From DHCP
        '''
        self.log.info("DHCPNewEvent NEW: {}"
                      .format(event.mac_addr))
        self.log.info("DHCPNewEvent NEW: {}"
                      .format(event.ip_addr))

        if event.mac_addr not in self.activeSTAs:
            # new STA to be served
            self.activeSTAs[event.mac_addr] = event.ip_addr
        else:
            # already known
            pass


    @modules.on_event(DHCPDelEvent)
    def serve_dhcp_del_event(self, event):
        '''
            From DHCP
        '''
        self.log.info("DHCPNewEvent DEL: {}"
                      .format(event.mac_addr))
        self.log.info("DHCPNewEvent DEL: {}"
                      .format(event.ip_addr))

        if event.mac_addr in self.activeSTAs:
            # new STA to be served
            del self.activeSTAs[event.mac_addr]
        else:
            # unknown STA
            pass


    def send_servingAP_req(self, sta_mac_addr, iface):
        '''
            Functions send out a message to wireless topology
            app to discover the AP serving a particular client.
        '''
        try:
            self.log.debug('send_servingAP_req')

            ho_event = WiFiGetServingAPRequestEvent(sta_mac_addr, iface)
            self.send_event(ho_event)
        except Exception as e:
            self.log.fatal("... An error occurred : %s" % e)
            raise e


    @modules.on_event(WiFiGetServingAPReplyEvent)
    def rx_servingAP_reply(self, event):
        '''
            From wireless topology app.
        '''
        self.log.info("rx_servingAP_reply: {}"
                      .format(event))

        sta_mac_addr = event.sta_mac_addr
        wifi_intf = event.wifi_intf
        ap_uuids = event.ap_uuids

        # STA_MAC_ADDR -> AP node
        if ap_uuids in self.nodes:
            self.servingAPs[sta_mac_addr] = self.nodes[ap_uuids]
        else:
            self.log.error('Unknown ap_uuids %s' % ap_uuids)


    def trigger_handover(self, sta_mac_addr, serving_AP, target_AP, gateway, **kwargs):
        '''
            Functions triggers handover by sending
            a WiFiTriggerHandoverRequestEvent to the corresponding app.
        '''
        try:
            self.log.debug('performHO: send event to HO app')
            ho_event = WiFiHandoverRequestEvent(sta_mac_addr, serving_AP, target_AP, gateway, **kwargs)
            self.send_event(ho_event)
        except Exception as e:
            self.log.fatal("... An error occurred : %s" % e)
            raise e


    @modules.on_event(upis.net_func.TriggerHandoverReplyEvent)
    def handle_handover_reply(self, event):
        '''
            From Handover module
        '''
        if not event.success:
            self.log.error('Handover failed!')
        else:
            self.log.info('Handover done')
Ejemplo n.º 6
0
class MyController(modules.ControlApplication):
    def __init__(self):
        super(MyController, self).__init__()
        self.log = logging.getLogger('MyController')
        self.running = False
        self.nodes = []

        self.timeInterval = 10
        self.timer = TimerEventSender(self, PeriodicEvaluationTimeEvent)
        self.timer.start(self.timeInterval)

    @modules.on_start()
    def my_start_function(self):
        print("start control app")
        self.running = True

    @modules.on_exit()
    def my_stop_function(self):
        print("stop control app")
        self.running = False

    @modules.on_event(events.NewNodeEvent)
    def add_node(self, event):
        node = event.node
        self.log.info("Added new node: {}, Local: {}".format(
            node.uuid, node.local))
        self._add_node(node)

        for device in node.get_devices():
            print("Dev: ", device.name)
            device.radio.add_interface('mon0', 'monitor')
            device.start_service(upis.radio.RssiService)

    @modules.on_event(events.NodeExitEvent)
    @modules.on_event(events.NodeLostEvent)
    def remove_node(self, event):
        self.log.info("Node lost".format())
        node = event.node
        reason = event.reason
        if self._remove_node(node):
            self.log.info("Node: {}, Local: {} removed reason: {}".format(
                node.uuid, node.local, reason))

    @modules.on_event(AveragedRssiSampleEvent)
    def serve_spectral_scan_sample(self, event):
        receiver = event.receiverUuid
        if self._get_node_by_uuid(event.receiverUuid):
            receiver = self._get_node_by_uuid(event.receiverUuid)

        dev = event.receiverDevId
        if receiver:
            dev = receiver.get_device(event.receiverDevId)

        ta = event.ta
        avgSample = event.rssi

        if isinstance(receiver, Node) and isinstance(dev, Device):
            self.log.info(
                "Avg RSSI: receiver: {}:{}, TA: {}, value: {}".format(
                    receiver.hostname, dev.name, ta, avgSample))
        else:
            self.log.info(
                "Avg RSSI: receiver: {}:{}, TA: {}, value: {}".format(
                    receiver, dev, ta, avgSample))

    @modules.on_event(PeriodicEvaluationTimeEvent)
    def periodic_evaluation(self, event):
        # go over collected samples, etc....
        # make some decisions, etc...
        print("Periodic Evaluation")
        print("My nodes: ", [node.hostname for node in self.get_nodes()])
        self.timer.start(self.timeInterval)

        if len(self.get_nodes()) == 0:
            return
Ejemplo n.º 7
0
class MyController(modules.ControlApplication):
    def __init__(self):
        super(MyController, self).__init__()
        self.log = logging.getLogger('MyController')
        self.running = False
        self.nodes = []

        self.timeInterval = 10
        self.timer = TimerEventSender(self, PeriodicEvaluationTimeEvent)
        self.timer.start(self.timeInterval)

    @modules.on_start()
    def my_start_function(self):
        print("start control app")
        self.running = True

        node = self.localNode
        self.log.info("My local node: {}, Local: {}".format(
            node.hostname, node.local))

        for dev in node.get_devices():
            print("Dev: ", dev.name)

        for m in node.get_modules():
            print("Module: ", m.name)

        for apps in node.get_control_applications():
            print("App: ", m.name)

        device = node.get_device(0)
        ifaces = device.radio.get_interfaces()
        print(ifaces)
        iface0 = ifaces[0]
        print(device.radio.get_interface_info(iface0))

        newIface = "wlan10"
        device.radio.add_interface(newIface, 'managed')
        ifaces = device.radio.get_interfaces()
        print(ifaces)

        device.radio.set_interface_up(newIface)
        # print(device.radio.is_interface_up(newIface))
        # device.radio.set_interface_down(newIface)
        # print(device.radio.is_interface_up(newIface))

        device.radio.del_interface(newIface)
        ifaces = device.radio.get_interfaces()
        print(ifaces)

    @modules.on_exit()
    def my_stop_function(self):
        print("stop control app")
        self.running = False

    @modules.on_event(PeriodicEvaluationTimeEvent)
    def periodic_evaluation(self, event):
        # go over collected samples, etc....
        # make some decisions, etc...
        print("Periodic Evaluation")

        node = self.localNode
        device = node.get_device(0)

        self.log.info("My local node: {}, Local: {}".format(
            node.hostname, node.local))
        self.timer.start(self.timeInterval)

        # execute non-blocking function immediately
        device.radio.set_tx_power(random.randint(1, 20))

        # execute non-blocking function immediately, with specific callback
        device.radio.get_tx_power()

        newChannel = random.randint(1, 11)
        device.radio.set_channel(channel=newChannel)

        # execute blocking function immediately
        result = device.radio.get_channel()
        print("{} Channel is: {}".format(datetime.datetime.now(), result))
Ejemplo n.º 8
0
class WiFiTopologyController(modules.ControlApplication):
    def __init__(self, mode, ap_iface):
        super(WiFiTopologyController, self).__init__()
        self.log = logging.getLogger('WiFiTopologyController')
        self.mode = mode
        self.ap_iface = ap_iface
        self.sta_discovery_interval = 5

        self.running = False
        self.nodes = {}  # APs UUID -> node
        self.active_sta_mac_addrs = ['00:11:22:33:44:55']

    @modules.on_start()
    def my_start_function(self):
        self.log.info("Topology control app started")

        # channel hopping every 100ms
        self.staDiscoveryTimer = TimerEventSender(
            self, PeriodicSTADiscoveryTimeEvent)
        self.staDiscoveryTimer.start(self.sta_discovery_interval)

        self.running = True

    @modules.on_exit()
    def my_stop_function(self):
        self.log.info("Topology control app stopped")
        self.running = False

    @modules.on_event(events.NewNodeEvent)
    def add_node(self, event):
        node = event.node

        self.log.info("Added new node: {}".format(node.uuid))
        self.nodes[node.uuid] = node

    @modules.on_event(events.NodeExitEvent)
    @modules.on_event(events.NodeLostEvent)
    def remove_node(self, event):
        self.log.info("Node lost".format())
        node = event.node
        reason = event.reason
        if node in self.nodes:
            del self.nodes[node.uuid]
            self.log.info("Node: {}, removed reason: {}".format(
                node.uuid, reason))

    @modules.on_event(PeriodicSTADiscoveryTimeEvent)
    def periodic_sta_discovery(self, event):

        self.log.info("Periodic STA discovery")
        self.staDiscoveryTimer.start(self.sta_discovery_interval)

        try:
            for sta_mac_addr_tmp in self.active_sta_mac_addrs:
                ho_event = upis.wifi.WiFiGetServingAPRequestEvent(
                    sta_mac_addr_tmp, self.ap_iface)
                self.log.info("... send event for %s " % sta_mac_addr_tmp)
                self.send_event(ho_event)

        except Exception as e:
            self.log.error("{} !!!Exception!!!: {}".format(
                datetime.datetime.now(), e))

    @modules.on_event(upis.wifi.WiFiGetServingAPReplyEvent)
    def rx_serving_reply(self, event):

        if event.ap_uuid in self.nodes:
            node = self.nodes[event.ap_uuid]

        self.log.info("RX WiFiGetServingAPReplyEvent: {}, {}, {}, {}".format(
            event.sta_mac_addr, event.wifi_intf, event.ap_uuid, node.hostname))