Commit 07352eeb authored by Marek Vavrusa's avatar Marek Vavrusa

scenario: track tested subject RTT

parent 4a423ba1
...@@ -5,7 +5,7 @@ import dns.dnssec ...@@ -5,7 +5,7 @@ import dns.dnssec
import dns.tsigkeyring import dns.tsigkeyring
import binascii import binascii
import socket, struct import socket, struct
import os, sys import os, sys, errno
import itertools import itertools
import time import time
from datetime import datetime from datetime import datetime
...@@ -34,6 +34,10 @@ def log_packet(sock, buf, query = True): ...@@ -34,6 +34,10 @@ def log_packet(sock, buf, query = True):
eth = dpkt.ethernet.Ethernet(data = ip) eth = dpkt.ethernet.Ethernet(data = ip)
g_pcap.writepkt(eth.pack()) g_pcap.writepkt(eth.pack())
# Global statistics
g_rtt = 0.0
g_nqueries = 0
# #
# Element comparators # Element comparators
# #
...@@ -452,17 +456,16 @@ class Step: ...@@ -452,17 +456,16 @@ class Step:
sock = None sock = None
destination = ctx.client[choice] destination = ctx.client[choice]
family = socket.AF_INET6 if ':' in destination[0] else socket.AF_INET family = socket.AF_INET6 if ':' in destination[0] else socket.AF_INET
sock = socket.socket(family, socket.SOCK_STREAM if tcp else socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if tcp: if tcp:
sock = socket.socket(family, socket.SOCK_STREAM) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, True)
sock.settimeout(3) sock.settimeout(3)
if source: sock.bind((source, 0)) if source:
sock.connect(destination) sock.bind((source, 0))
else: sock.connect(destination)
sock = socket.socket(family, socket.SOCK_DGRAM)
sock.settimeout(3)
if source: sock.bind((source, 0))
sock.connect(destination)
# Send query to client and wait for response # Send query to client and wait for response
tstart = datetime.now()
log_packet(sock, data_to_wire, query = True) log_packet(sock, data_to_wire, query = True)
while True: while True:
try: try:
...@@ -482,6 +485,11 @@ class Step: ...@@ -482,6 +485,11 @@ class Step:
except OSError, e: except OSError, e:
if e.errno == errno.ENOBUFS: if e.errno == errno.ENOBUFS:
time.sleep(0.1) time.sleep(0.1)
# Track RTT
rtt = (datetime.now() - tstart).total_seconds() * 1000
global g_rtt, g_nqueries
g_nqueries += 1
g_rtt += rtt
# Remember last answer for checking later # Remember last answer for checking later
self.raw_answer = answer self.raw_answer = answer
ctx.last_raw_answer = answer ctx.last_raw_answer = answer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment