コード例 #1
0
ファイル: link_detection.py プロジェクト: netixx/NetProbes
    def run(self):
        # TODO : remove lines
        import time
        while len(WatcherServices.getAllOtherProbes()) < self.options.overlay_size - 1:
            self.logger.info("Length of other probes %s", len(WatcherServices.getAllOtherProbes()))
            time.sleep(10)
        WatcherServices.writeOutput('up', '1', 'w')
        time.sleep(45)
        from managers.actions import ActionMan

        ActionMan.actionQueue.join()
        # self.initializeEvent.set()
        while not self.stop:
            self.initializeEvent.wait()
            self.initialize()
            self.initializeEvent.clear()
            WatcherServices.writeOutput('events', '1', 'w')
            # work until new initialisation is asked
            while not self.stop and not self.initializeEvent.is_set():
                while not self.initializeEvent.is_set() and not self.workEvent.is_set():
                    self.workEvent.wait(2.0)
                if self.initializeEvent.is_set():
                    break
                try:
                    self.work()
                    self._resetWork()
                    self.workEvent.clear()
                finally:
                    WatcherServices.writeOutput('done', '1', 'w')
コード例 #2
0
ファイル: bandwidth.py プロジェクト: netixx/NetProbes
    def _makeMeasure(self, probes, resContainer):
        import datetime

        for probe in probes:
            WatcherServices.doTest(self.BW_TEST_NAME, [probe],
                                   resContainer.addResult,
                                   resContainer.addError)
            resContainer.resultCollected.wait()
            self.logger.info("%s : Bw checked for probe %s\n" %
                             (datetime.datetime.now(), probe))
            resContainer.resultCollected.clear()
        resContainer.resultCollected.set()
        self.logger.info("Results in : %s" % (" ".join([
            "%s:%s" % (repr(host), bw.printAvg())
            for host, bw in resContainer.results.items()
        ])))
コード例 #3
0
 def makeBaseline(self, hosts):
     super().makeBaseline(hosts)
     opts = self.options.pingOptions + [self.lp[host].address for host in hosts]
     resContainer = self.TestResult()
     WatcherServices.doStandaloneTest(self.PING_TEST_NAME, opts, resContainer.addResult, resContainer.addError)
     resContainer.resultCollected.wait()
     redoBl = []
     for host, ping in resContainer.results.items():
         # check that values are consistent, redo if not
         if ping.rttdev > self.options.rttdevThreshold:
             redoBl.append(host)
         self.lp[host].baseline = ping
     if len(redoBl) > 0:
         self.logger.info("Retaking baseline for %s", repr(redoBl))
         print("Retaking baseline for %s" % repr(redoBl))
         self.makeBaseline(redoBl)
コード例 #4
0
 def makeMeasures(self, s):
     opts = self.options.pingOptions + [probe.address for probe in s]
     resContainer = self.TestResult()
     WatcherServices.doStandaloneTest(self.PING_TEST_NAME, opts, resContainer.addResult, resContainer.addError)
     # protect against tests hanging
     resContainer.resultCollected.wait(30)
     if not resContainer.resultCollected.is_set():
         self.makeMeasures(s)
         return
     redoMeasure = []
     for host, ping in resContainer.results.items():
         if ping.rttdev > self.options.rttdevThreshold:
             redoMeasure.append(self.lp[host])
         self.lp[host].add(ping)
     if len(redoMeasure) > 0:
         self.logger.info("Retaking measure for %s", repr(redoMeasure))
         print("Retaking measure for %s" % repr(redoMeasure))
         self.makeMeasures(redoMeasure)
コード例 #5
0
ファイル: link_detection.py プロジェクト: netixx/NetProbes
    def work(self):
        try:
            print("WORK...")
            self.logger.info("Starting algorithm ...\nProbes : %s", ", ".join(self.lp.keys()))
            # self.untested = self.options.bucket(self.lp.values())
            while not self.stop and self.stopCondition():
                # TODO : update for more than one set
                # and self.untested.largest(self.metric) > self.options.metricThreshold):
                self.runs += 1
                s = self.untested.getN(self.options.granularity, self.metric)
                print("sel", s)
                ndraws = 0
                while len(s) < 1 and ndraws < self.options.nDrawsThreshold:
                    self.logger.info("Empty selection from bucket, rerunning selection.")
                    s = self.untested.getN(self.options.maxTests, self.metric)
                    ndraws += 1
                if len(s) < 1:
                    break
                self.logger.info("Selection : %s" % repr(s))
                self.makeMeasures(s)
                clusters = self.clustering.cluster(self.tested)
                self.grey = clusters[KMeans.greySet]
                # TODO : remove names black and white
                self.sets = clusters['clusters']
                self.black = clusters['clusters'][0]
                self.white = clusters['clusters'][1]
                # update number of bytes
                self.bytes += sum(p.bytes for p in self.lp.values())

                self.logger.info("Step done, bytes used : %s KB, unknown host size %s, untested hosts : %s", self.bytes / (1024.0), len(self.grey),
                                 len(self.untested))
                self.logger.info("  white: %s\n  black: %s\n  grey: %s\n",
                                 self.white,
                                 self.black,
                                 self.grey)
                print("  white: %s\n  black: %s\n  grey: %s" % (
                    self.white,
                    self.black,
                    self.grey))
                self.logger.info("")

                if self.hasConverged(self.sets):
                    self.logger.info("Algorithm has converged...")
                    break

            print("Terminating :\n  white (%s): %s\n  black (%s): %s\n  grey : %s" % (
                self.white.printRepresentative(),
                ", ".join([p.address for p in self.white]),
                self.black.printRepresentative(),
                ", ".join([p.address for p in self.black]),
                self.grey))
            from consts import Identification

            parameters = vars(self.options)
            out = {
                'sets': {
                    'black': {
                        'hosts': [{'address': p.address,
                                   'stats': p.getMeasure().toDict()} for p in self.black],
                        'representative': self.black.representative.toDict()
                    },
                    'white': {
                        'hosts': [{'address': p.address,
                                   'stats': p.getMeasure().toDict()} for p in self.white],
                        'representative': self.white.representative.toDict()
                    }
                },
                'grey': [{'address': p.address,
                          'stats': p.getMeasure().toDict()} for p in self.grey],
                'bytes': self.bytes,
                'runs': self.runs,
                'untested': [{'address': p.address} for p in self.untested],
                'parameters': parameters,
                'watcher': Identification.PROBE_ID
            }
            self.logger.info("Terminating :\nRuns : %s\nBytes : %s KB\n  white (%s): %s\n  black (%s): %s\n  grey : %s",
                             self.runs,
                             self.bytes / (1024.0),
                             self.white.printRepresentative(),
                             ", ".join([str(p) for p in self.white]),
                             self.black.printRepresentative(),
                             ", ".join([str(p) for p in self.black]),
                             self.grey)

            import json
            import datetime

            jout = json.dumps(out, default = name)
            print(jout)
            WatcherServices.writeOutput("%s.json" % self.name, jout, mode = 'w')
            WatcherServices.writeOutput("%s-%s.json" % (self.name, datetime.datetime.now()), jout, mode = 'w')
        except Exception as e:
            self.logger.error("error %s", e, exc_info = 1)
            import traceback

            traceback.print_exc()
コード例 #6
0
ファイル: link_detection.py プロジェクト: netixx/NetProbes
 def setLp(self):
     self.lp = {p.address: self.newProbe(p.address, p.id, self.measureClass) for p in WatcherServices.getAllOtherProbes()}