예제 #1
0
    def __init__(self, port=None):
        self.verbose = console.Option(False)
        self.strict = console.Option(False)
        self.autoTrace = console.Option(False)
        self.stretch = console.Option(100)

        self.console = console.Command()
        self.console.finishFunction = self.finish
        if port is None:
            self.nextPort = randomPort()
        else:
            self.nextPort = port
        self.eventManager = events.EventManager()
        self.fileManager = files.FileManager(printer=self.console)
        self.fileManager.purgeResponseFiles()
        self.requestManager = agents.RequestGenerator(self.eventManager,
                                                      self.fileManager,
                                                      self.console,
                                                      strict=self.strict,
                                                      verbose=self.verbose)
        self.servers = {}
        self.proxyProcess = None

        self.console.addOption(
            "strict", self.strict,
            "Apply strict testing of HTTP requests and responses")
        self.console.addOption("verbose", self.verbose, "Show details")
        self.console.addOption(
            "stretch", self.stretch,
            "Multiply all delays by factor = stretch / 100")
        self.console.addOption("autotrace", self.autoTrace,
                               "Trace every request for which check fails")
        self.console.addCommand("serve", self.doServe, "SID+",
                                "Set up servers")
        self.console.addCommand(
            "request", self.doRequest, "ID FILE SID",
            "Initiate request named ID for FILE from server SID")
        self.console.addCommand(
            "fetch", self.doFetch, "ID FILE SID",
            "Fetch FILE from server SID using request named ID")
        self.console.addCommand(
            "respond", self.doRespond, "ID+",
            "Allow servers to return reponses to requests")
        self.console.addCommand("delay", self.doDelay, "MS",
                                "Delay for MS milliseconds")
        self.console.addCommand(
            "check", self.doCheck, "ID [CODE]",
            "Make sure request ID handled properly and generated expected CODE"
        )
        self.console.addCommand(
            "generate", self.doGenerate, "FILE BYTES",
            "Generate file (extension '.txt' or '.bin') with specified number of bytes"
        )
        self.console.addCommand("delete", self.doDelete, "FILE+",
                                "Delete specified files")
        self.console.addCommand(
            "proxy", self.doProxy, "[PATH] ARG*",
            "(Re)start proxy server (pass arguments to proxy)")
        self.console.addCommand("trace", self.doTrace, "ID+",
                                "Trace histories of requests")
예제 #2
0
파일: agents.py 프로젝트: bhxxzp/CMU_18613
    def __init__(self, host, portLimit, eventManager, fileManager, portManager, printer, id = "main", strict = None, verbose = None, disabled = False):
        self.host = host
        self.eventManager = eventManager
        self.fileManager = fileManager
        self.portManager = portManager
        self.printer = printer
        self.id = id
        self.strict = strict
        self.verbose = console.Option(False) if verbose is None else verbose
        self.strict = console.Option(False) if strict is None else strict
        self.sock = None
        self.running = True
        self.httpStatus = HTTPStatus()
        self.requestCount = 0
        self.readingHeader = False
        self.timeOut = 1.0
        self.allOK = True
        self.disruption = Disruption.none
        self.sequenceNumber = 0

        tryCount = 0
        portCount = 0
        for t in range(portLimit):
            self.port = self.portManager.newPort()
            portCount += 1
            tuples = socket.getaddrinfo(self.host, self.port, socket.AF_INET, socket.SOCK_STREAM)
            if len(tuples) == 0:
                self.running = False
                self.printer.errMsg("Couldn't get address information for port %d" % self.port)
                return
            msg = ""
            for info in tuples:
                tryCount += 1
                (family, socktype, proto, canonname, sockaddr) = info
                try:
                    self.sock = socket.socket(family, socktype)
                    self.sock.bind(sockaddr)
                    if not disabled:
                        self.sock.listen(0)
                        if self.timeOut > 0:
                            self.sock.settimeout(self.timeOut)
                except socket.error as ex:
                    self.sock = None
                    msg = str(ex)
                    time.sleep(20)
                    continue
                break
            if self.sock is not None:
                break

        if self.sock is None:
            self.printer.errMsg("Couldn't set up server on port %d (%s).  Attempted %d times with %d different ports." % (self.port, msg, tryCount, portCount))
            self.running = False
            return
        if disabled:
            self.thread = None
            self.running = False
        else:
            self.thread = threading.Thread(target=self.wrappedRun, name = "Server-Thread")
            self.thread.start()
예제 #3
0
파일: agents.py 프로젝트: bhxxzp/CMU_18613
 def __init__(self, eventManager, fileManager, printer, proxy = None, strict = None, verbose = None):
     self.eventManager = eventManager
     self.fileManager = fileManager
     self.printer = printer
     self.proxy = proxy
     self.strict = console.Option(False) if strict is None else strict
     self.verbose = console.Option(False) if verbose is None else verbose
     self.httpStatus = HTTPStatus()
     self.allOK = True
     self.disruption = Disruption.none
     self.instrumenter = InstrumentCache()
예제 #4
0
    def __init__(self):
        self.verbose = console.Option(False)
        self.strict = console.Option(0)
        self.autoTrace = console.Option(False)
        self.stretch = console.Option(100)
        self.timeout = console.Option(5000)
        self.checkTiming = console.Option(False)
        self.checkUnsafe = console.Option(False)
        self.checkLocking = console.Option(False)
        self.checkSemaphore = console.Option(False)
        self.linefeedPercent = console.Option(5)

        self.console = console.Command()
        self.console.finishFunction = self.finish
        self.host = socket.gethostname()
        self.eventManager = events.EventManager()
        self.fileManager = files.FileManager(printer = self.console, fileGenerator = findFileGenerator())
        self.fileManager.purgeResponseFiles()
        self.requestManager = agents.RequestGenerator(self.eventManager, self.fileManager, self.console, strict = self.strict, verbose = self.verbose)
        self.portManager = agents.PortFinder(self.console)
        self.servers = {}
        self.monitors = []
        self.haveProxy = False
        self.proxyProcess = None
        self.activeEvents = {}
        self.getId = 0

        self.console.addOption("strict", self.strict, "Set level of strictness on HTTP message formatting (0-4)")
        self.console.addOption("timing", self.checkTiming, "Insert random delays into synchronization operations")
        self.console.addOption("unsafe", self.checkLocking, "Check for thread-unsafe functions")
        self.console.addOption("locking", self.checkLocking, "Check proper use of locks")
        self.console.addOption("semaphore", self.checkSemaphore, "Disallow use of semaphores")
        self.console.addOption("verbose", self.verbose, "Show details")
        self.console.addOption("stretch", self.stretch, "Multiply all delays by factor = stretch / 100")
        self.console.addOption("timeout", self.timeout, "Set default timeout for wait (in milliseconds)")
        self.console.addOption("autotrace", self.autoTrace, "Trace every request for which check fails")
        self.console.addOption("linefeed", self.linefeedPercent, "Frequency of line feeds in binary files (percent)")
        self.console.addCommand("serve", self.doServe,         "SID+",   "Set up servers.  (Server with SID starting with '-' is disabled.)")
        self.console.addCommand("request", self.doRequest,     "ID FILE SID",    "Initiate request named ID for FILE from server SID")
        self.console.addCommand("post-request", self.doPostRequest,     "ID FILE SID",    "Initiate request named ID for FILE from server SID")
        self.console.addCommand("fetch", self.doFetch,     "ID FILE SID",    "Fetch FILE from server SID using request named ID")
        self.console.addCommand("respond", self.doRespond,     "ID+",   "Allow servers to return reponses to requests")
        self.console.addCommand("get", self.doGet,            "URL", "Retrieve web object with and without proxy and compare the two")
        self.console.addCommand("delay", self.doDelay,         "MS",              "Delay for MS milliseconds")
        self.console.addCommand("check", self.doCheck,         "ID [CODE]",     "Make sure request ID handled properly and generated expected CODE")
        self.console.addCommand("generate", self.doGenerate,   "FILE BYTES",      "Generate file (extension '.txt' or '.bin') with specified number of bytes")
        self.console.addCommand("delete", self.doDelete,       "FILE+",  "Delete specified files")
        self.console.addCommand("proxy", self.doProxy,         "[PATH] ARG*", "(Re)start proxy server (pass arguments to proxy)")
        self.console.addCommand("external", self.doExternalProxy,    "HOST:PORT", "Use external proxy")
        self.console.addCommand("trace", self.doTrace,         "ID+",   "Trace histories of requests")
        self.console.addCommand("signal", self.doSignal,       "[SIGNO]", "Send signal number SIGNO to process.  Default = 13 (SIGPIPE)")
        self.console.addCommand("disrupt", self.doDisrupt,     "(request|response) [SID]", "Schedule disruption of request or response by client [or server SID]")
        self.console.addCommand("wait", self.doWait,          "* | ID+", "Wait until all or listed pending requests, fetches, and responses have completed")
예제 #5
0
    def __init__(self, port=None):
        self.verbose = console.Option(False)
        self.strict = console.Option(0)
        self.autoTrace = console.Option(False)
        self.stretch = console.Option(100)
        self.timeout = console.Option(3000)

        self.console = console.Command()
        self.console.finishFunction = self.finish
        if port is None:
            self.nextPort = randomPort()
        else:
            self.nextPort = port
        self.host = socket.gethostname()
        self.eventManager = events.EventManager()
        self.fileManager = files.FileManager(printer=self.console)
        self.fileManager.purgeResponseFiles()
        self.requestManager = agents.RequestGenerator(self.eventManager,
                                                      self.fileManager,
                                                      self.console,
                                                      strict=self.strict,
                                                      verbose=self.verbose)
        self.servers = {}
        self.haveProxy = False
        self.proxyProcess = None
        self.activeEvents = {}

        self.console.addOption(
            "strict", self.strict,
            "Set level of strictness on HTTP message formatting (0-4)")
        self.console.addOption("verbose", self.verbose, "Show details")
        self.console.addOption(
            "stretch", self.stretch,
            "Multiply all delays by factor = stretch / 100")
        self.console.addOption(
            "timeout", self.timeout,
            "Set default timeout for wait (in milliseconds)")
        self.console.addOption("autotrace", self.autoTrace,
                               "Trace every request for which check fails")
        self.console.addCommand(
            "serve", self.doServe, "SID+",
            "Set up servers.  (Server with SID starting with '-' is disabled.)"
        )
        self.console.addCommand(
            "request", self.doRequest, "ID FILE SID",
            "Initiate request named ID for FILE from server SID")
        self.console.addCommand(
            "fetch", self.doFetch, "ID FILE SID",
            "Fetch FILE from server SID using request named ID")
        self.console.addCommand(
            "respond", self.doRespond, "ID+",
            "Allow servers to return reponses to requests")
        self.console.addCommand("delay", self.doDelay, "MS",
                                "Delay for MS milliseconds")
        self.console.addCommand(
            "check", self.doCheck, "ID [CODE]",
            "Make sure request ID handled properly and generated expected CODE"
        )
        self.console.addCommand(
            "generate", self.doGenerate, "FILE BYTES",
            "Generate file (extension '.txt' or '.bin') with specified number of bytes"
        )
        self.console.addCommand("delete", self.doDelete, "FILE+",
                                "Delete specified files")
        self.console.addCommand(
            "proxy", self.doProxy, "[PATH] ARG*",
            "(Re)start proxy server (pass arguments to proxy)")
        self.console.addCommand("external", self.doExternalProxy, "HOST:PORT",
                                "Use external proxy")
        self.console.addCommand("trace", self.doTrace, "ID+",
                                "Trace histories of requests")
        self.console.addCommand(
            "signal", self.doSignal, "[SIGNO]",
            "Send signal number SIGNO to process.  Default = 13 (SIGPIPE)")
        self.console.addCommand(
            "disrupt", self.doDisrupt, "(request|response) [SID]",
            "Schedule disruption of request or response by client [or server SID]"
        )
        self.console.addCommand(
            "wait", self.doWait, "* | ID+",
            "Wait until all or listed pending requests, fetches, and responses have completed"
        )
예제 #6
0
 def __init__(self, strict=None):
     self.headerDict = {}
     self.headerLines = []
     self.strict = console.Option(0) if strict is None else strict