7
7
from mptcpanalyzer .data import load_into_pandas
8
8
from mptcpanalyzer .tshark import TsharkConfig
9
9
import enum
10
- from mptcpanalyzer .connection import MpTcpConnection
10
+ from mptcpanalyzer .connection import MpTcpConnection , TcpConnection
11
11
from typing import List , Tuple , Collection
12
12
import copy
13
13
import abc
@@ -56,9 +56,8 @@ def __init__(
56
56
self .input_pcaps = input_pcaps
57
57
# python shallow copies objects by default
58
58
self .tshark_config = copy .deepcopy (exporter )
59
- self .protocol = kwargs .get ("protocol" , "mptcp" )
60
59
# self.tshark_config.read_filter = protocol + " and not icmp"
61
-
60
+
62
61
63
62
def default_parser (
64
63
self ,
@@ -91,10 +90,11 @@ def default_parser(
91
90
parser .add_argument (name , action = "store" , type = str , help = 'Pcap file (or its associated csv)' )
92
91
93
92
if bitfield & PreprocessingActions .FilterStream :
94
- # TODO generate metavar
93
+ # difficult to change the varname here => change it everywhere
95
94
protocol = "mptcp" if bitfield & PreprocessingActions .FilterMpTcpStream else "tcp"
95
+ print ("PROTOCOL" , protocol )
96
96
parser .add_argument (
97
- protocol + 'stream' , action = "store" , type = int ,
97
+ protocol + 'stream' , metavar = protocol + "stream" , action = "store" , type = int ,
98
98
help = protocol + '.stream id' )
99
99
100
100
if direction :
@@ -118,13 +118,6 @@ def default_parser(
118
118
"not to take into account (because"
119
119
"it was filtered by iptables or else)" ))
120
120
121
- # not implemented yet
122
- # if dst_host:
123
- # parser.add_argument(
124
- # 'ipdst_host', action="store",
125
- # help='Filter flows according to the destination hostnames')
126
-
127
-
128
121
parser .add_argument ('-o' , '--out' , action = "store" , default = None ,
129
122
help = 'Name of the output plot' )
130
123
parser .add_argument ('--display' , action = "store_true" ,
@@ -149,7 +142,7 @@ def plot(self, rawdataframes, **kwargs):
149
142
pass
150
143
151
144
def filter_dataframe (
152
- self , rawdf , filterstream = None , skipped_subflows = [],
145
+ self , rawdf , tcpstream = None , mptcpstream = None , skipped_subflows = [],
153
146
destination : mp .ConnectionRoles = None ,
154
147
extra_query : str = None , ** kwargs
155
148
):
@@ -163,7 +156,7 @@ def filter_dataframe(
163
156
rawdf: Raw dataframe
164
157
kwargs: expanded arguments returned by the parser
165
158
destination: Filters packets depending on their :enum:`.ConnectionRoles`
166
- mptcpstream : keep only the packets related to mptcp.stream == mptcpstream
159
+ stream : keep only the packets related to mptcp.stream == mptcpstream
167
160
skipped_subflows: list of skipped subflows
168
161
extra_query: Add some more filters to the pandas query
169
162
@@ -178,21 +171,30 @@ def filter_dataframe(
178
171
"""
179
172
log .debug ("Preprocessing dataframe with extra args %s" % kwargs )
180
173
queries = []
174
+ print ("tcp.stream" , tcpstream , "mptcp:" , mptcpstream )
175
+ stream = tcpstream if tcpstream is not None else mptcpstream
181
176
dataframe = rawdf
182
177
183
178
for skipped_subflow in skipped_subflows :
184
179
log .debug ("Skipping subflow %d" % skipped_subflow )
185
180
queries .append (" tcpstream!=%d " % skipped_subflow )
186
181
187
- if filterstream is not None :
188
- log .debug ("Filtering %s stream ." % self .protocol )
189
- queries .append (self .protocol + "stream==%d" % filterstream )
182
+ if stream is not None :
183
+ protocol = "mptcp" if mptcpstream is not None else "tcp"
184
+ log .debug ("Filtering %s stream #%d." % (protocol , stream ))
185
+ queries .append (protocol + "stream==%d" % stream )
190
186
if destination is not None :
191
187
log .debug ("Filtering destination" )
188
+
192
189
# Generate a filter for the connection
193
- con = MpTcpConnection .build_from_dataframe (dataframe , filterstream )
194
- q = con .generate_direction_query (destination )
195
- queries .append (q )
190
+ if protocol == "mptcp" :
191
+ con = MpTcpConnection .build_from_dataframe (dataframe , stream )
192
+ q = con .generate_direction_query (destination )
193
+ queries .append (q )
194
+ else :
195
+ con2 = TcpConnection .build_from_dataframe (dataframe , stream )
196
+ q = con2 .generate_direction_query (destination )
197
+ queries .append (q )
196
198
197
199
if extra_query :
198
200
log .debug ("Appending extra_query=%s" % extra_query )
@@ -221,7 +223,7 @@ def preprocess(self, **kwargs) -> Collection[ pd.DataFrame ]:
221
223
"""
222
224
dataframes = []
223
225
for pcap_name , actions in self .input_pcaps :
224
- log .info ("pcap_name=" , pcap_name , " value=" , kwargs .get (pcap_name ))
226
+ log .info ("pcap_name=%s value=%r" % ( pcap_name , kwargs .get (pcap_name ) ))
225
227
if actions & PreprocessingActions .Preload :
226
228
filename = kwargs .get (pcap_name )
227
229
df = load_into_pandas (filename , self .tshark_config ,)
@@ -348,7 +350,7 @@ def savefig(fig, filename, **kwargs):
348
350
kwargs: Forwarded to :member:`matplotlib.Figure.savefig`.
349
351
You can set *dpi* for instance (80 by default ?)
350
352
"""
351
- print ("Saving into %s" % (filename ))
353
+ logging . info ("Saving into %s" % (filename ))
352
354
# most settings (dpi for instance) can be set from resource config
353
355
fig .savefig (filename , format = "png" , ** kwargs )
354
356
return filename
0 commit comments