main.py 7.44 KB
Newer Older
1
2
3
4
5
6
7
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse
import sys
import signal

8
from .utils.utilty import Utility
9
10
11
12
13
from .tcpliveplot import TcpLivePlot
from .info_registry import InfoRegistry


# constants
Michael König (Student)'s avatar
Michael König (Student) committed
14
TCP_PLOT_VERSION = "0.2.5"
15
16
TCP_LOG_FORMAT_VERSION_MIN = "2"

17
DEFAULT_LOGFILE_PATH = "/tmp/tcplog.log"
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
DEFAULT_INPUT_BACKEND = "socket"

# default values
DEFAULT_SOCKETSERVER_PORT = 11337
DEFAULT_SOCKETSERVER_LOCATION = 'localhost:' + str(DEFAULT_SOCKETSERVER_PORT)
DEFAULT_LINES_TO_SHOW = ['cwnd']
DEFAULT_FILTER_PORT = 5001

# move
VALUES_TO_PLOT = ['cwnd', 'sst', 'rtt', 'bw'] # (only values for Y-axis)

# main prog
def main():
    inputBackend = None
    guiBackend = None
    infoRegistry = InfoRegistry()
    options = parse_options()
    startupSelfCheck(options)

    if(options.showVersion):
        print("TCPlivePLOT: " + TCP_PLOT_VERSION)
        sys.exit(0)

    options.guiBackend = "live"

    # init input backend
    if(options.inputBackend == "socket"):
        from .backends.input.socket import SocketInput
        inputBackend = SocketInput(options, infoRegistry)
    elif(options.inputBackend == "file"):
        from .backends.input.file import FileInput
        inputBackend = FileInput(options, infoRegistry)
    # elif(options.inputBackend == "stdin"):
    #     from .backends.input.stdin import StdinInput
    #     inputBackend = StdinInput(options, info)

    if(inputBackend is None):
        print("No valid input backend selected. Exiting...")
        sys.exit(1)

    # init guiBackend
    if(options.guiBackend == "live"):
        from .backends.gui.live import LiveGui
        guiBackend = LiveGui(options, infoRegistry)
    else:
        pass

    if(guiBackend is None):
        print("No valid GUI backend selected. Exiting...")
        sys.exit(1)

    if(inputBackend is not None):
        inputBackend.startupCheck()
        inputBackend.startUp()

    if(guiBackend is not None):
        guiBackend.startupCheck()
        guiBackend.startUp()

77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    tcpLivePlot = TcpLivePlot(inputBackend, guiBackend, options, infoRegistry)
    signal.signal(signal.SIGINT, tcpLivePlot.handleSignals)
    signal.signal(signal.SIGTERM, tcpLivePlot.handleSignals)
    tcpLivePlot.run()
    # try:
    #     tcpLivePlot = TcpLivePlot(inputBackend, guiBackend, options, infoRegistry)
    #     signal.signal(signal.SIGINT, tcpLivePlot.handleSignals)
    #     signal.signal(signal.SIGTERM, tcpLivePlot.handleSignals)
    #     tcpLivePlot.run()
    #     # ^-- starts the main programme
    # except Exception as e:
    #     Utility.eprint(str(e))
    #     raise e
    # finally:
    #     if(not options.quiet):
    #         print("Goodbye cruel world!")
    #     sys.exit(0)
94
95
96
97
98
99
100
101
102
103
104
105


def parse_options():
    parser = argparse.ArgumentParser()

    parser.add_argument(
            "-i",
            "--input-backend",
            help="Available input backends: \"socket\" and \"file\" (default: " + DEFAULT_INPUT_BACKEND + ")",
            dest="inputBackend",
            default=DEFAULT_INPUT_BACKEND)

106
    # TODO: remove
107
108
109
110
111
112
113
    parser.add_argument(
            "-b",
            "--buffer", help="Length of preload buffer (in seconds, default: 1, 0 to deactivate preload buffer)",
            type=float,
            dest="preloadBuffer",
            default=1)

114
    # TODO: remove
115
116
117
118
119
120
121
    parser.add_argument(
            "-ib",
            "--interimbuffer", help="Activate interim buffering.",
            action="store_true",
            dest="interimBuffering",
            default=False)

122
    # TODO: remove
123
124
125
126
127
128
    parser.add_argument(
            "-ps",
            "--playback-speed", help="Playback speed (factor, default: 1)",
            type=float,
            dest="playbackSpeed",
            default=1)
129
130

    # TODO: remove
131
132
133
134
135
136
137
    parser.add_argument(
            "-aps",
            "--adaptive-playback-speed", help="Enable adaptive playback speed (default: false)",
            action="store_true",
            dest="adaptivePlaybackSpeed",
            default=False)

138
    # TODO: remove
139
140
141
142
143
    parser.add_argument(
            "--buffer-size", help="Number of elements to buffer from socket per filter (5000)",
            dest="bufferLength",
            default=5000)

144
145
146
147
148
149
    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)
150
151
152

    parser.add_argument(
            "-z",
153
154
            "--blit", help="Activate blitting for better performance - but broken axis labels (default: False)",
            action="store_true",
155
            dest="blitting",
156
            default=False)
157
158
159
160
161
162
163
164
165
166
167
168

    logTypeGroup = parser.add_mutually_exclusive_group()

    logTypeGroup.add_argument(
            "-s",
            "--server",
            help="IP and Port of socket-logging server (" + DEFAULT_SOCKETSERVER_LOCATION + ")",
            dest="logServer",
            default=DEFAULT_SOCKETSERVER_LOCATION)
    logTypeGroup.add_argument(
            "-f",
            "--filepath",
169
            help="Path where the log file is stored - only usable with file input-backend (default: " + DEFAULT_LOGFILE_PATH + ")",
170
            type=str,
171
            default=DEFAULT_LOGFILE_PATH,
172
173
            dest="logFilePath")

174
    # TODO: remove as param
175
176
177
178
179
180
181
182
183
184
185
    parser.add_argument(
            "-df",
            help="Number of FPS to draw",
            dest="drawFps",
            type=int,
            default=60)
    parser.add_argument(
            "-di",
            help="Draw intervall",
            dest="drawIntervall",
            type=int,
186
            default=100)
187
188
189

    parser.add_argument(
            "-x",
190
            help="Seconds to plot (default: 20)",
191
192
193
            dest="xDelta",
            type=int,
            default=20)
194

195
196
197
198
199
200
201
202
    parser.add_argument(
            "-y",
            help="Static Y-axis (default: 0 = auto)",
            dest="yAxisMax",
            type=int,
            default=0)


203
    # TODO: remove as param
204
205
206
    parser.add_argument(
            "-r",
            "--resolution",
207
            help="Plot resolution (in seconds, default: 0.01)",
208
209
            dest="plotResolution",
            type=float,
210
            default=0.1)
211
212

    parser.add_argument(
213
214
215
216
            "-l",
            "--line-visibility",
            help="List of initially visible value-lines - currently available: " + ", ".join(VALUES_TO_PLOT) + " (default: empty = all visible)",
            dest="initialLineVisibility",
217
            action='append',
218
            type=str,
219
220
221
222
            default=[])

    parser.add_argument(
            "-d",
223
            "--debug", help="Debug mode - ignores quiet mode (default: false)",
224
225
226
227
228
229
            action="store_true",
            dest="debug",
            default=False)

    parser.add_argument(
            "-q",
230
            "--quiet", help="Whether to ouput anything at all on console (default: false)",
231
232
233
234
            action="store_true",
            dest="quiet",
            default=False)

235
236
237
    parser.add_argument(
            "-p",
            "--port",
Michael König (Student)'s avatar
Michael König (Student) committed
238
            help="Filter by dst-port. Multiple occurrences possible (" + str(DEFAULT_FILTER_PORT) + ")",
239
240
241
242
243
            dest="filterPorts",
            action='append',
            type=int,
            default=[])

244
245
246
247
248
249
250
    parser.add_argument(
            "--version",
            help="Print version information",
            action="store_true",
            dest="showVersion",
            default=False)

251
252


253
254
255
256
257
258
259
260
261
    options = parser.parse_args()

    return options

def startupSelfCheck(options):
    pass

if __name__ == "__main__":
    main()