Esempio n. 1
0
 def execute_async(self, ud):
     events = yield async_helpers.select(
       async_helpers.StateCondition(ud.radio.activate_request, operator.__not__),
       async_helpers.StateCondition(ud.radio.associated, operator.__not__))
     if 0 in events:
         returnValue('disactivate')
     returnValue('unassociated')
Esempio n. 2
0
 def test_as_event_stream(self):
     es = async_helpers.ReadDescrEventStream(L2Port, iface = 'lo', filter='icmp')
     pkt = tst_icmp_pkt()
     es.port.send(pkt)
     while True:
         yield async_helpers.select(es)
         inpkt = es.recv()
         if inpkt == pkt:
             break
Esempio n. 3
0
 def execute_async(self, ud):
     events = yield async_helpers.select(
         async_helpers.StateCondition(ud.radio.activate_request,
                                      operator.__not__),
         async_helpers.StateCondition(ud.radio.associated,
                                      operator.__not__))
     if 0 in events:
         returnValue('disactivate')
     returnValue('unassociated')
Esempio n. 4
0
 def execute_async(self, ud):
     events = yield async_helpers.select(
       async_helpers.Timeout(ud.radio.disactivate_delay),
       async_helpers.StateCondition(ud.radio.activate_request, operator.truth),
       async_helpers.StateCondition(ud.radio.associated, operator.__not__))
     if 1 in events:
         returnValue('activate')
     if 2 in events:
         returnValue('unassociated')
     returnValue('done')
Esempio n. 5
0
    def execute_async(self, ud):
        ud.dhcp.socket.set_discard(True)
        ud.dhcp.binding_publisher.set(ud.dhcp.lease.public_config)
        events = yield async_helpers.select(
            async_helpers.StateCondition(ud.dhcp.link_addr_state, lambda x: x == False),
            async_helpers.Timeout(ud.dhcp.lease.timeout_time['BOUND'] - time.time()),
            )

        if 0 in events:
            returnValue('nolink')

        returnValue('timeout')
Esempio n. 6
0
 def execute_async(self, ud):
     events = yield async_helpers.select(
         async_helpers.Timeout(ud.radio.disactivate_delay),
         async_helpers.StateCondition(ud.radio.activate_request,
                                      operator.truth),
         async_helpers.StateCondition(ud.radio.associated,
                                      operator.__not__))
     if 1 in events:
         returnValue('activate')
     if 2 in events:
         returnValue('unassociated')
     returnValue('done')
Esempio n. 7
0
    def execute_async(self, ud):
        ud.dhcp.binding_publisher.set(None)
        ud.dhcp.error_event.trigger()
        ud.dhcp.socket.set_discard(True)
        events = yield async_helpers.select(
                async_helpers.StateCondition(ud.dhcp.link_addr_state, lambda x: x == False),
                async_helpers.Timeout(ud.dhcp.error_timeout)
                )

        if 0 in events:
            returnValue('nolink')

        returnValue('done')
Esempio n. 8
0
    def execute_async(self, ud):
        ud.radio._radio.associate(*ud.radio.requested_bss[0], **ud.radio.requested_bss[1])
        
        #print "Associating before", ud.radio.associated.get()
        events = yield async_helpers.select(
                async_helpers.StateCondition(ud.radio._up_state_pub, operator.__not__ ),
                async_helpers.StateCondition(ud.radio._radio.associated, lambda x: x != radio.Associating))

        if 0 in events or ud.radio.associated.get() == radio.Unassociated:
            returnValue('failed')
        else:
            #print "Associated", ud.radio.iface_name, ud.radio.associated.get()
            returnValue('associated')
Esempio n. 9
0
    def execute_async(self, ud):
        ud.radio._radio.associate(*ud.radio.requested_bss[0],
                                  **ud.radio.requested_bss[1])

        #print "Associating before", ud.radio.associated.get()
        events = yield async_helpers.select(
            async_helpers.StateCondition(ud.radio._up_state_pub,
                                         operator.__not__),
            async_helpers.StateCondition(ud.radio._radio.associated,
                                         lambda x: x != radio.Associating))

        if 0 in events or ud.radio.associated.get() == radio.Unassociated:
            returnValue('failed')
        else:
            #print "Associated", ud.radio.iface_name, ud.radio.associated.get()
            returnValue('associated')
Esempio n. 10
0
    def execute_async(self, ud):
        # Parameters that will depend on the state.
        timeout = async_helpers.Timeout(self.init_timeouts(ud))

        # Make sure we aren't discarding incoming dhcp packets.
        ud.dhcp.socket.set_discard(False)

        # Generate an xid for the exchange if necessary.
        self.init_xid(ud)

        while True:
            # Send a request packet
            try:
                self.send_time = time.time()
                self.send(ud)
            except:
                traceback.print_exc()
                returnValue('fail')

            # How long to wait before retry
            interval = self.get_next_retry(ud)

            while True:
                # Wait for an event
                events = yield async_helpers.select(
                        async_helpers.StateCondition(ud.dhcp.link_addr_state, lambda x: x == False), 
                        ud.dhcp.socket, 
                        async_helpers.Timeout(interval),
                        timeout)

                if 0 in events: # Lost link
                    returnValue('nolink')
    
                if 1 in events: # Got packet
                    pkt = scapy.Ether(ud.dhcp.socket.recv())
                    #print "In:", repr(pkt)

                    result = self.validate(ud, pkt)
                    if result:
                        returnValue(result)
    
                if 2 in events:
                    break
    
                if 3 in events:
                    returnValue('fail')
Esempio n. 11
0
    def execute_async(self, ud):
        # Use callLater so that no association request will arrive before
        # we select.
        reactor.callLater(0, ud.radio.scanning_enabled.set, True)
        assoc_event_stream = async_helpers.EventStream(ud.radio.associate_request)
        #print "Associated before", ud.radio.associated.get()
        events = yield async_helpers.select(
                async_helpers.StateCondition(ud.radio._up_state_pub, operator.__not__ ),
                async_helpers.StateCondition(ud.radio.activate_request, operator.truth),
                assoc_event_stream,
                )
        ud.radio.scanning_enabled.set(False)

        if 1 in events:
            returnValue('activate')
        if 2 in events:
            ud.radio.requested_bss = assoc_event_stream.get()
            #print "Assoc changed", ud.radio.iface_name, ud.radio.requested_bss
            returnValue('reassociate')
        returnValue('unassociated')
Esempio n. 12
0
    def execute_async(self, ud):
        # Use callLater so that no association request will arrive before
        # we select.
        reactor.callLater(0, ud.radio.scanning_enabled.set, True)
        assoc_event_stream = async_helpers.EventStream(
            ud.radio.associate_request)
        #print "Associated before", ud.radio.associated.get()
        events = yield async_helpers.select(
            async_helpers.StateCondition(ud.radio._up_state_pub,
                                         operator.__not__),
            async_helpers.StateCondition(ud.radio.activate_request,
                                         operator.truth),
            assoc_event_stream,
        )
        ud.radio.scanning_enabled.set(False)

        if 1 in events:
            returnValue('activate')
        if 2 in events:
            ud.radio.requested_bss = assoc_event_stream.get()
            #print "Assoc changed", ud.radio.iface_name, ud.radio.requested_bss
            returnValue('reassociate')
        returnValue('unassociated')
Esempio n. 13
0
    def execute_async(self, ud):
        # If we got here then were forcibly disactivated, and the previous
        # activation request is moot.
        ud.radio.activate_request.set(False)

        # We may have landed here after the interface went down causing
        # disassociation. Quickly check for that before getting to work.
        if not ud.radio._up_state_pub.get():
            returnValue('down')
        
        # Use callLater so that no association request will arrive before
        # we select.
        reactor.callLater(0, ud.radio.scanning_enabled.set, True)
        assoc_event_stream = async_helpers.EventStream(ud.radio.associate_request)
        events = yield async_helpers.select(
                async_helpers.StateCondition(ud.radio._up_state_pub, operator.__not__ ),
                assoc_event_stream
                )
        ud.radio.scanning_enabled.set(False)

        if 1 in events:
            ud.radio.requested_bss = assoc_event_stream.get()
            returnValue('associate')
        returnValue('down')
Esempio n. 14
0
    def execute_async(self, ud):
        # If we got here then were forcibly disactivated, and the previous
        # activation request is moot.
        ud.radio.activate_request.set(False)

        # We may have landed here after the interface went down causing
        # disassociation. Quickly check for that before getting to work.
        if not ud.radio._up_state_pub.get():
            returnValue('down')

        # Use callLater so that no association request will arrive before
        # we select.
        reactor.callLater(0, ud.radio.scanning_enabled.set, True)
        assoc_event_stream = async_helpers.EventStream(
            ud.radio.associate_request)
        events = yield async_helpers.select(
            async_helpers.StateCondition(ud.radio._up_state_pub,
                                         operator.__not__), assoc_event_stream)
        ud.radio.scanning_enabled.set(False)

        if 1 in events:
            ud.radio.requested_bss = assoc_event_stream.get()
            returnValue('associate')
        returnValue('down')