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