main.py 6.64 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
14
15
16
from .tcpliveplot import TcpLivePlot
from .info_registry import InfoRegistry


# constants
TCP_PLOT_VERSION = "0.2.0"
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132


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)

    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)

    parser.add_argument(
            "-ib",
            "--interimbuffer", help="Activate interim buffering.",
            action="store_true",
            dest="interimBuffering",
            default=False)

    parser.add_argument(
            "-ps",
            "--playback-speed", help="Playback speed (factor, default: 1)",
            type=float,
            dest="playbackSpeed",
            default=1)
    parser.add_argument(
            "-aps",
            "--adaptive-playback-speed", help="Enable adaptive playback speed (default: false)",
            action="store_true",
            dest="adaptivePlaybackSpeed",
            default=False)

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


    parser.add_argument(
            "-z",
142
143
            "--blit", help="Activate blitting for better performance - but broken axis labels (default: False)",
            action="store_true",
144
            dest="blitting",
145
            default=False)
146
147
148
149
150
151
152
153
154
155
156
157

    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",
158
            help="Path where the log file is stored - only usable with file input-backend (default: " + DEFAULT_LOGFILE_PATH + ")",
159
            type=str,
160
            default=DEFAULT_LOGFILE_PATH,
161
162
            dest="logFilePath")

163
    # TODO: remove as param
164
165
166
167
168
169
170
171
172
173
174
    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,
175
            default=100)
176
177
178

    parser.add_argument(
            "-x",
179
            help="Seconds to plot (default: 20)",
180
181
182
            dest="xDelta",
            type=int,
            default=20)
183
184

    # TODO: remove as param
185
186
187
    parser.add_argument(
            "-r",
            "--resolution",
188
            help="Plot resolution (in seconds, default: 0.01)",
189
190
            dest="plotResolution",
            type=float,
191
            default=0.1)
192
193
194
195
196
197
198
199
200
201
202
203
204
205

    # Filter
    parser.add_argument(
            "-p",
            "--port",
            help="Filter by port. Multiple occurrences possible (" + str(DEFAULT_FILTER_PORT) + ")",
            dest="filterPorts",
            action='append',
            type=int,
            default=[])


    parser.add_argument(
            "-d",
206
            "--debug", help="Debug mode - ignores quiet mode (default: false)",
207
208
209
210
211
212
            action="store_true",
            dest="debug",
            default=False)

    parser.add_argument(
            "-q",
213
            "--quiet", help="Whether to ouput anything at all on console (default: false)",
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
            action="store_true",
            dest="quiet",
            default=False)

    parser.add_argument(
            "--version",
            help="Print version information",
            action="store_true",
            dest="showVersion",
            default=False)

    options = parser.parse_args()

    return options

def startupSelfCheck(options):
    pass

if __name__ == "__main__":
    main()