def testCase3(): post_delay = 0.3 post_count = 200 post_size = 700 def recordPDML(clientsocket, listener): clientsocket.send("cache\\clear") time.sleep(const_inter_cmd_delay) # start capturing filename = "recording_" + datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') th = prepare_recording(filename) cnt = 0 for i in range(post_count): clientsocket.send("post\\" + str(post_size)) time.sleep(post_delay) cnt += 1 print "Sent", cnt, "POST messages" waitForTCP() finalize_recording(th) return filename + ".pdml" server, clientsocket, listener = startup() filewriter.writeDelimiter("CASE 3 measure") ## HTTP2 clientsocket.send("http2\\enable") time.sleep(const_inter_cmd_delay) prefix = "case3.http2" filewriter.writeResult(prefix + ".post.count", post_count) filewriter.writeResult(prefix + ".post.size", post_size) pdmlFile = recordPDML(clientsocket, listener) analyze.analyzePDML(pdmlFile, prefix) if delete_traces: os.remove(pdmlFile) ## HTTP1 clientsocket.send("http2\\disable") time.sleep(const_inter_cmd_delay) prefix = "case3.http1" filewriter.writeResult(prefix + ".post.count", post_count) filewriter.writeResult(prefix + ".post.size", post_size) pdmlFile = recordPDML(clientsocket, listener) analyze.analyzePDML(pdmlFile, prefix) if delete_traces: os.remove(pdmlFile) shutdown(server, clientsocket, listener)
def printresults(useStdout): global errors, linecnt, current_proto, tcp_sum, ssl_sum, http_sum, http_metadata_sum, byte_sum, byte_sum_tcp_layer, tcp_cache_srcport, tcp_cache_dstport, tcp_connections, tcp_conn_opened, tcp_conn_closed, tcp_conn_max_parallel, tcp_packet_count, is_http2, is_http_version_mismatch, global_prefix, error_lost_segments tcp_overhead = float(tcp_sum) / float(byte_sum_tcp_layer) tcp_overhead = float('%.4f'%tcp_overhead)*100 # truncate float (does round) if useStdout: print print "===== RESULTS =====" print modestr = is_http2 and "2" or "1" print "http.ver =", modestr #print "bytes.http.meta =", http_metadata_sum, "Bytes (All HTTP except BODY / DATA)" print print "--- BYTECOUNTS ---" print "bytes =", byte_sum, "(Raw Frame bytes, including Eth, IP etc.)" print "bytes.tcp =", byte_sum_tcp_layer, "(TCP+Payload | Excluding Eth, IP)" print "bytes.tcp.meta =", tcp_sum, "(TCP meta | Excluding Payload, Eth and IP)" print "tcp.overhead =", tcp_overhead, "% (TCP_only / TCP_only+TCP_payload)" print print "--- CONN STATS ---" print "packets =", packet_num print "packets.tcp =", tcp_packet_count print "tcp.connections.count =", tcp_conn_opened, "(Total count of opened TCP connections)" print "tcp.connections.maxparallel =", tcp_conn_max_parallel, "(Max. parallel TCP connections at a time)" print if error_lost_segments: errors += "lost_segments" if is_http_version_mismatch: errors += "http_version_mismatch " if packet_num != tcp_packet_count: errors += "non_tcp_packets_captured " print "WARNING: Not all packets are TCP - this will lead to false results!" if tcp_conn_opened != tcp_conn_closed: print "ERROR: opened and closed TCP connections are not equal!" filewriter.writeResult(global_prefix + ".bytes", byte_sum) filewriter.writeResult(global_prefix + ".bytes.tcp", byte_sum_tcp_layer) filewriter.writeResult(global_prefix + ".tcp.overhead", tcp_overhead) filewriter.writeResult(global_prefix + ".packets", packet_num) filewriter.writeResult(global_prefix + ".tcp.count", tcp_conn_opened) filewriter.writeResult(global_prefix + ".tcp.maxparallel", tcp_conn_max_parallel) errors = (errors == "") and "none" or errors filewriter.writeResult(global_prefix + ".errors", errors)
def testCase1(modes, testCount = 1): htmlPath = case1_target_page def measurePLT(clientsocket, listener, count, useCache): avg = 0 resultList = [] if useCache: clientsocket.send("tab\\" + htmlPath) time.sleep(const_inter_cmd_delay) listener.waitForPLT() clientsocket.send("tab\\close") time.sleep(const_inter_cmd_delay) waitForTCP() else: clientsocket.send("cache\\clear") time.sleep(const_inter_cmd_delay) cnt = 0 for i in range(count): print "--- Run #" + str(i+1) + " for PLT measure ---" listener.resetPLT() clientsocket.send("tab\\" + htmlPath) time.sleep(const_inter_cmd_delay) val = int(listener.waitForPLT()) #print "DEBUG: val:", val avg += val resultList.append(val) clientsocket.send("tab\\close") waitForTCP() cnt += 1 if not useCache: clientsocket.send("cache\\clear") time.sleep(const_inter_cmd_delay) avg = avg / cnt cacheMsg = useCache and "(while using Cache)" or "(while NOT using Cache)" print "Avg over", cnt, "times:", avg, cacheMsg return cnt, avg, resultList def recordPDML(clientsocket, listener, useCache): if useCache: clientsocket.send("tab\\" + htmlPath) time.sleep(const_inter_cmd_delay) listener.waitForPLT() clientsocket.send("tab\\close") time.sleep(const_inter_cmd_delay) waitForTCP() else: clientsocket.send("cache\\clear") time.sleep(const_inter_cmd_delay) # start capture filename = "recording_" + datetime.datetime.now().strftime('%Y%m%d%H%M%S%f') th = prepare_recording(filename) listener.resetPLT() clientsocket.send("tab\\" + htmlPath) time.sleep(const_inter_cmd_delay) listener.waitForPLT() print "PLT received" clientsocket.send("tab\\close") time.sleep(const_inter_cmd_delay) waitForTCP() finalize_recording(th) return filename + ".pdml" if "plt" in modes: server, clientsocket, listener = startup() ### SCRIPT MAIN EXECUTION pltLoopCount = testCount filewriter.writeDelimiter("PLT measure") clientsocket.send("http2\\enable") time.sleep(const_inter_cmd_delay) print "---" print "Measuring PLT via HTTP2" cnt, avg, resultList = measurePLT(clientsocket, listener, pltLoopCount, False) for result in resultList: filewriter.writeResult("case1.http2.nocache.plt.value", result) filewriter.writeResult("case1.http2.nocache.plt.count", cnt) filewriter.writeResult("case1.http2.nocache.plt.average", avg) clientsocket.send("http2\\disable") time.sleep(const_inter_cmd_delay) print "---" print "Measuring PLT via HTTP1.1" cnt, avg, resultList = measurePLT(clientsocket, listener, pltLoopCount, False) for result in resultList: filewriter.writeResult("case1.http1.nocache.plt.value", result) filewriter.writeResult("case1.http1.nocache.plt.count", cnt) filewriter.writeResult("case1.http1.nocache.plt.average", avg) clientsocket.send("http2\\enable") time.sleep(const_inter_cmd_delay) print "---" print "Measuring PLT via HTTP2" cnt, avg, resultList = measurePLT(clientsocket, listener, pltLoopCount, True) for result in resultList: filewriter.writeResult("case1.http2.cache.plt.value", result) filewriter.writeResult("case1.http2.cache.plt.count", cnt) filewriter.writeResult("case1.http2.cache.plt.average", avg) clientsocket.send("http2\\disable") time.sleep(const_inter_cmd_delay) print "---" print "Measuring PLT via HTTP1.1" cnt, avg, resultList = measurePLT(clientsocket, listener, pltLoopCount, True) for result in resultList: filewriter.writeResult("case1.http1.cache.plt.value", result) filewriter.writeResult("case1.http1.cache.plt.count", cnt) filewriter.writeResult("case1.http1.cache.plt.average", avg) shutdown(server, clientsocket, listener) time.sleep(3) # static sleep time between phases if "other" in modes: server, clientsocket, listener = startup() filewriter.writeDelimiter("CASE 1 measure") ## HTTP2 NOCACHE clientsocket.send("http2\\enable") time.sleep(const_inter_cmd_delay) prefix = "case1.http2.nocache" pdmlFile = recordPDML(clientsocket, listener, False) analyze.analyzePDML(pdmlFile, prefix) if delete_traces: os.remove(pdmlFile) ## HTTP2 CACHE clientsocket.send("http2\\enable") time.sleep(const_inter_cmd_delay) prefix = "case1.http2.cache" pdmlFile = recordPDML(clientsocket, listener, True) analyze.analyzePDML(pdmlFile, prefix) if delete_traces: os.remove(pdmlFile) ## HTTP1 NOCACHE clientsocket.send("http2\\disable") time.sleep(const_inter_cmd_delay) prefix = "case1.http1.nocache" pdmlFile = recordPDML(clientsocket, listener, False) analyze.analyzePDML(pdmlFile, prefix) if delete_traces: os.remove(pdmlFile) ## HTTP1 CACHE clientsocket.send("http2\\disable") time.sleep(const_inter_cmd_delay) prefix = "case1.http1.cache" pdmlFile = recordPDML(clientsocket, listener, True) analyze.analyzePDML(pdmlFile, prefix) if delete_traces: os.remove(pdmlFile) shutdown(server, clientsocket, listener)