Commit 4a7aadbf authored by Michael König's avatar Michael König

use user's default backend + reconn. to logserver

parent 7219255e
# LOCATION: ~/.config/matplotlib/matplotlibrc
#backend : qt5agg
backend : qt4agg
......@@ -4,7 +4,7 @@
from setuptools import setup
# keep in sync with main.py (!)
version = "0.2.0"
version = "0.2.1"
desc = "Realtime-visualization of TCP flows logged by TCPlog."
setup(
......@@ -37,7 +37,7 @@ setup(
platforms = "Linux",
zip_safe = False,
install_requires = [
'matplotlib==1.4.0',
'matplotlib==1.4.2',
'tcplog>=0.2'
],
keywords = ['tcp', 'flow', 'plot', 'visualize', 'graph', 'live', 'analyze', 'network', 'traffic'],
......
......@@ -6,12 +6,6 @@
# * fix socket-input
# * dynamic value detection
import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import matplotlib.animation as animation
from matplotlib.widgets import Button, RadioButtons
import numpy as np
import math
......@@ -19,7 +13,6 @@ import sys
import time
import threading
from collections import deque
from .gui_base import GuiBase
VALUES_TO_PLOT = ['cwnd', 'sst', 'rtt', 'smoothedThroughput'] # (only values for Y-axis)
......@@ -31,6 +24,12 @@ PLOT_TITLE = "Data from"
PAUSE = "Pause"
QUIT = "Quit"
import matplotlib
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import matplotlib.animation as animation
from matplotlib.widgets import Button, RadioButtons
# constants
CLEAR_GAP = 0.2 # gap in s
INFINITY_THRESHOLD = 1e8
......@@ -41,6 +40,7 @@ class LiveGui(GuiBase):
self.infoRegistry = infoRegistry
self.__stopped = threading.Event()
self.timestampOfLastGuiRefresh = 0
if(self.options.debug):
print("matplotlib-version: " + matplotlib.__version__)
print("available matplotlib-styles:" + str(plt.style.available))
......
......@@ -14,14 +14,17 @@ LOG_FORMAT = ['time', 'srcIp', 'srcPort', 'dstIp', 'dstPort', 'cwnd', 'rwnd', 's
#at least time & dstPort required
NUMBER_OF_VALUES = len(LOG_FORMAT)
LOGSERVER_CONNECT_RETRY_TIME = 3 #in s
LOGSERVER_CONNECT_RETRY_TIME = 1 #in s
LOGSERVER_ERROR_TIMEOUT = 0.5 #in s
class SocketInput(InputBase):
def __init__(self, options, infoRegistry):
self.options = options
self.infoRegistry = infoRegistry
self.__incomeBuffer = deque();
self.incomeBuffer = deque();
self.__incomeBuffer = deque()
self.incomeBuffer = deque()
self.connectionUp = False
self.socketUp = False
ip, separator, port = self.options.logServer.rpartition(':')
if(':' not in self.options.logServer or port is ''):
......@@ -37,22 +40,41 @@ class SocketInput(InputBase):
def startUp(self):
#TODO: eprint + debug..
self.createSocket()
while not self.connectToServer():
pass
def createSocket(self):
try:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print("Failed to create socket")
else:
self.socketUp = True
if(self.options.debug):
print("Socket created.")
while True:
def connectToServer(self):
try:
self.socket.connect((str(self.logServerIp), self.logServerPort))
self.connectionUp = True
print("Successfully connected to " + self.dst + "")
return
return True
except socket.error:
print("Error: Could not connect to " + self.dst + ". Retrying in " + str(LOGSERVER_CONNECT_RETRY_TIME) + "s ...")
time.sleep(LOGSERVER_CONNECT_RETRY_TIME)
return False
else:
time.sleep(LOGSERVER_CONNECT_RETRY_TIME)
return False
def reconnectToServer(self):
if not self.socketUp:
self.socket.close()
self.createSocket()
while not self.connectToServer():
pass
def tearDown(self):
......@@ -78,22 +100,31 @@ class SocketInput(InputBase):
def retrieveDataFromSocket(self):
if(self.connectionUp):
try:
data = self.socket.recv(4096)
except socket.timeout:
print("Connection timeout.")
self.socket.close()
self.socketUp = False
self.connectionUp = False
return ""
except IOError:
print("Error: Could not retrieve data from " + self.dst)
self.socket.close()
self.socketUp = False
self.connectionUp = False
return ""
else:
if(len(data) == 0):
print("Connection closed by foreign host.")
self.socket.close()
self.socketUp = False
self.connectionUp = False
else:
self.__incomeBuffer.append(data)
else:
self.reconnectToServer()
def processDataFromSocket(self):
......
......@@ -11,7 +11,7 @@ from .info_registry import InfoRegistry
# constants
TCP_PLOT_VERSION = "0.2.0"
TCP_PLOT_VERSION = "0.2.1"
TCP_LOG_FORMAT_VERSION_MIN = "2"
DEFAULT_LOGFILE_PATH = "/tmp/tcplog.log"
......@@ -103,6 +103,7 @@ def parse_options():
dest="inputBackend",
default=DEFAULT_INPUT_BACKEND)
# TODO: remove
parser.add_argument(
"-b",
"--buffer", help="Length of preload buffer (in seconds, default: 1, 0 to deactivate preload buffer)",
......@@ -110,6 +111,7 @@ def parse_options():
dest="preloadBuffer",
default=1)
# TODO: remove
parser.add_argument(
"-ib",
"--interimbuffer", help="Activate interim buffering.",
......@@ -117,12 +119,15 @@ def parse_options():
dest="interimBuffering",
default=False)
# TODO: remove
parser.add_argument(
"-ps",
"--playback-speed", help="Playback speed (factor, default: 1)",
type=float,
dest="playbackSpeed",
default=1)
# TODO: remove
parser.add_argument(
"-aps",
"--adaptive-playback-speed", help="Enable adaptive playback speed (default: false)",
......@@ -136,6 +141,12 @@ def parse_options():
dest="bufferLength",
default=5000)
parser.add_argument(
"-4",
"--useQt4", help="Use Qt-4 instead of Qt-5 (default) as matplotlib-backend (default: False)",
action="store_true",
dest="useQt4",
default=False)
parser.add_argument(
"-z",
......
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