main.py 7.71 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.6"
15
16
TCP_LOG_FORMAT_VERSION_MIN = "2"

17
DEFAULT_LOGFILE_PATH = "/tmp/tcplog.log"
18
DEFAULT_INPUT_BACKEND = "socket"
19
DEFAULT_TITLE = "TCPlivePLOT"
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
77

# 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()

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    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)
95
96
97
98
99
100
101
102
103
104
105
106


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)

107
    # TODO: remove
108
109
110
111
112
113
114
    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)

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

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

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

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

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

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

    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",
170
            help="Path where the log file is stored - only usable with file input-backend (default: " + DEFAULT_LOGFILE_PATH + ")",
171
            type=str,
172
            default=DEFAULT_LOGFILE_PATH,
173
174
            dest="logFilePath")

175
    # TODO: remove as param
176
177
178
179
180
181
182
183
184
185
186
    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,
187
            default=100)
188
189
190

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

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


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

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

222
223
224
225
226
227
228
229
    parser.add_argument(
            "-t",
            "--title",
            help="Set plot and figure title (default: " + DEFAULT_TITLE + ")",
            dest="title",
            type=str,
            default=DEFAULT_TITLE)

230
231
    parser.add_argument(
            "-d",
232
            "--debug", help="Debug mode - ignores quiet mode (default: false)",
233
234
235
236
237
238
            action="store_true",
            dest="debug",
            default=False)

    parser.add_argument(
            "-q",
239
            "--quiet", help="Whether to ouput anything at all on console (default: false)",
240
241
242
243
            action="store_true",
            dest="quiet",
            default=False)

244
245
246
    parser.add_argument(
            "-p",
            "--port",
Michael König (Student)'s avatar
Michael König (Student) committed
247
            help="Filter by dst-port. Multiple occurrences possible (" + str(DEFAULT_FILTER_PORT) + ")",
248
249
250
251
252
            dest="filterPorts",
            action='append',
            type=int,
            default=[])

253
    parser.add_argument(
Michael König (Student)'s avatar
Michael König (Student) committed
254
            "-v",
255
256
257
258
259
260
            "--version",
            help="Print version information",
            action="store_true",
            dest="showVersion",
            default=False)

261
262


263
264
265
266
267
268
269
270
271
    options = parser.parse_args()

    return options

def startupSelfCheck(options):
    pass

if __name__ == "__main__":
    main()