Esempio n. 1
0
    def __init__(self, new_rtt, interval=0.5, timeout=6.0):
        self.timeout = int(1000 * timeout)
        self.interval = interval
        self.stop_event = threading.Event()
        self.abort_traceroute = threading.Event()
        self.finished_event = threading.Event()
        # the thread is finished because it hasn't started
        self.finished_event.set()

        RTTMonitorBase.__init__(self, new_rtt)
Esempio n. 2
0
    def __init__(self, new_rtt, icmp, interval=0.5, timeout=6.0):
        """
          @param new_rtt called every time a ping arrives.
          @param icmp is the ICMP implementation.
          @param timeout (currently uses a static timeout threshold)
        """
        assert callable(new_rtt)
        assert isinstance(icmp, Icmp)

        self.icmp = icmp
        self.nodes = []
        self.timeout = int(1000 * timeout)  # in ms.
        self.interval = interval
        self.stop_event = threading.Event()
        self.abort_traceroute = threading.Event()
        self.finished_event = threading.Event()
        # the thread is finished because it hasn't started
        self.finished_event.set()

        RTTMonitorBase.__init__(self, new_rtt)
Esempio n. 3
0
 def __init__(self, *a, **k):
     self.doneflag = threading.Event()
     wx.App.__init__(self, *a, **k)
Esempio n. 4
0
    def run(self, nodes):

        q = Queue.Queue()

        dst = None
        # handy for hard-coding common node
        #dst = '68.87.195.50'; nodes = [dst,]; common = nodes
        if not dst:
            threads = []
            for i in nodes:
                t = daemon_thread(target=self.get_route, args=(
                    q,
                    i,
                ))
                threads.append(t)
                t.start()

            waiter_done_event = threading.Event()

            def waiter(threads, waiter_done_event):
                try:
                    for thread in threads:
                        thread.join()  # blocks until thread terminates.
                except Exception, e:
                    print "waiter hiccupped", e
                waiter_done_event.set()

            waiting_thread = daemon_thread(target=waiter,
                                           args=(
                                               threads,
                                               waiter_done_event,
                                           ))
            waiting_thread.start()

            common = []
            routes = {}
            while not waiter_done_event.isSet():
                try:
                    msg = q.get(True, 1.0)
                except Queue.Empty:
                    pass
                else:
                    dst = msg[0]
                    # nodes appear in the queue in
                    # increasing order of TTL.
                    new_node = msg[1]
                    routes.setdefault(dst, []).append(new_node)
                    branch, common = in_common(routes.values())
                    if branch:
                        break

            self.abort_traceroute.set()
            waiter_done_event.wait()
            self.abort_traceroute.clear()

            local_ips = get_host_ips()
            new_common = []
            for c in common:
                if c not in local_ips:
                    new_common.append(c)
            common = new_common

            if debug:
                pprint(common)

            if len(common) == 0:
                # this should be inspected, it's not a simple debug message
                if debug:
                    print "No common node"
                    pprint(routes)
                return

            del routes

            dst = common[-1]
Esempio n. 5
0
 def __init__(self, queue_task):
     self.killswitch = threading.Event()
     self.queue = defer.DeferredQueue()
     self.main_df = launch_coroutine(queue_task, self.run)
Esempio n. 6
0
 def __init__(self):
     self.thread = threading.Thread(target=self.run)
     self.queue = Queue.Queue()
     self.killswitch = threading.Event()
Esempio n. 7
0
    def run(self, nodes):

        q = Queue.Queue()

        dst = None
        # handy for hard-coding common node
        #dst = '68.87.195.50'
        if not dst:
            threads = []
            for i in nodes:
                t = daemon_thread(target=self.get_route, args=(
                    q,
                    i,
                ))
                threads.append(t)
                t.start()

            waiter_done_event = threading.Event()

            def waiter(threads, waiter_done_event):
                try:
                    for thread in threads:
                        thread.join()  # blocks until thread terminates.
                except Exception, e:
                    print "waiter hiccupped", e
                waiter_done_event.set()

            waiting_thread = daemon_thread(target=waiter,
                                           args=(
                                               threads,
                                               waiter_done_event,
                                           ))
            waiting_thread.start()

            common = []
            routes = {}
            #print "tracerouting..."
            hop_check = 0  # distance (in hops) being checked for branch.
            hop_cnt = {}  # number responses received at the given distance.
            farthest_possible = 1000  # farthest distance possible as
            # determined by the shortest number of
            # hops to a node in the passed nodes.
            branch = False
            while not waiter_done_event.isSet():
                try:
                    msg = q.get(True, 1.0)
                except Queue.Empty:
                    pass
                else:
                    dst = msg[0]
                    # nodes appear in the queue in
                    # increasing order of TTL.
                    new_node = msg[1]
                    if dst not in routes:
                        l = []
                        routes[dst] = l
                    else:
                        l = routes[dst]
                    l.append(new_node)
                    #print "calling in_common with ", routes.values()

                    # BEGIN replaces in_common
                    #hops_so_far = len(routes[dst])
                    ## It is not possible for the common path to be longer
                    ## than the closest node.
                    #if dst == new_node and hops_so_far < farthest_possible:
                    #    farthest_possible = hops_so_far
                    #if hop_cnt.has_key(hops_so_far):
                    #    hop_cnt[hops_so_far] += 1
                    #else:
                    #    hop_cnt[hops_so_far] = 1
                    #
                    #if hops_so_far == hop_check:
                    #    # if got all pings for a given distance then see if
                    #    # there is a branch.
                    #    while hop_cnt[hop_check] == len(nodes) and \
                    #          hop_check <= farthest_possible:
                    #        n = None
                    #        for r in routes:
                    #            if n is not None and n != routes[d]:
                    #                branch = True
                    #                break
                    #            if routes[hop_check] != '*':
                    #                n = routes[hop_check]
                    #        else:
                    #            common.append(n)
                    #        hop_check += 1
                    #    if hop_check > farthest_possible:
                    #        branch = True
                    ## END
                    branch, common = in_common(routes.values())
                    if branch:
                        break

            #print "done tracerouting..."
            self.abort_traceroute.set()
            waiter_done_event.wait()
            self.abort_traceroute.clear()

            local_ips = get_host_ips()
            new_common = []
            for c in common:
                if c not in local_ips:
                    new_common.append(c)
            common = new_common

            if debug:
                pprint(common)

            if len(common) == 0:
                # this should be inspected, it's not a simple debug message
                if debug:
                    print "No common node", routes
                return

            del routes

            dst = common[-1]