Skip to content

Commit 4e5a708

Browse files
committed
ok ?
1 parent ed34871 commit 4e5a708

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

mptcpanalyzer/cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import mptcpanalyzer.pdutils
5555
import dataclasses
5656
from colorama import Fore, Back
57-
57+
from mptcpanalyzer.pdutils import debug_dataframe
5858
from stevedore import extension
5959

6060
plugin_logger = logging.getLogger("stevedore")

mptcpanalyzer/data.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626

2727
# TODO might need a converter when saving/loading
2828
# TODO pandas.api.types.register_extension_dtype()
29-
dtype_role = pd.api.types.CategoricalDtype(categories=list(ConnectionRoles), ordered=True)
29+
dtype_role = pd.api.types.CategoricalDtype(categories=ConnectionRoles, ordered=True)
3030

3131
TCP_DEBUG_FIELDS = ['hash', 'packetid', "reltime", "abstime"]
3232
MPTCP_DEBUG_FIELDS = TCP_DEBUG_FIELDS + ['mptcpdest']
3333

3434

35-
# def _convert_role(x):
36-
# """
37-
# Workaround https://github.com/pandas-dev/pandas/pull/20826
38-
# """
39-
# log.log(mp.TRACE, "converting [%r] into role" % x)
40-
# return ConnectionRoles.from_string(x)
35+
def _convert_role(x):
36+
"""
37+
Workaround https://github.com/pandas-dev/pandas/pull/20826
38+
"""
39+
log.log(mp.TRACE, "converting [%r] into role" % x)
40+
return ConnectionRoles(x)
4141

4242
def ignore(f1, f2):
4343
return 0
@@ -96,6 +96,10 @@ def getrealpath(input_file):
9696
per_pcap_artificial_fields = {
9797
"mptcpdest": Field("mptcpdest", dtype_role, "MPTCP destination", False, None),
9898
"tcpdest": Field("tcpdest", dtype_role, "TCP destination", False, None),
99+
100+
# "mptcpdest": Field("mptcpdest", None, "MPTCP destination", False, _convert_role),
101+
# "tcpdest": Field("tcpdest", None, "TCP destination", False, _convert_role),
102+
99103
# TODO use int? as type
100104
"hash": Field("hash", str, "Hash of fields", False, None),
101105

@@ -287,7 +291,7 @@ def _gen_converters() -> Dict[str, Callable]:
287291
converters=converters,
288292
)
289293
# at this stage, destinatiosn are nan
290-
debug_dataframe(merged_df, "Merged dataframe", )
294+
# debug_dataframe(merged_df, "Merged dataframe", )
291295

292296
# log.debug("Column names after loading from cache: %s", merged_df.columns)
293297

@@ -316,8 +320,8 @@ def _gen_converters() -> Dict[str, Callable]:
316320
# don't do it here else we might repeat it
317321
# data["abstime"] += clock_offset
318322

319-
debug_dataframe(res, "checking merge", usecols=["merge_status"])
320-
print("%d nan values" % len(res[res.merge_status == np.nan]))
323+
# debug_dataframe(res, "checking merge", usecols=["merge_status"])
324+
# print("%d nan values" % len(res[res.merge_status == np.nan]))
321325

322326
# log.debug("Column names: %s", res.columns)
323327
# log.debug("Dtypes after load:%s\n" % dict(res.dtypes))
@@ -610,13 +614,14 @@ def _rename_column(col_name, suffixes) -> str:
610614
log.log(mp.TRACE, "renaming inplace")
611615

612616
tdf.rename(columns=rename_func, inplace=True)
613-
debug_dataframe(tdf, "temporary dataframe")
617+
# debug_dataframe(tdf, "temporary dataframe")
614618
total = pd.concat([total, tdf], ignore_index=True, sort=False, )
615619
print("total df size = %d" % len(total))
616620

617621
# subdf[ _first("tcpdest") == ConnectionRole.Client] .rename(columns=_rename_cols, inplace=True)
618622
# print(subdf.columns)
619623
# print(total.columns)
624+
debug_dataframe(total, "total")
620625

621626
logging.debug("Converted to sender/receiver format")
622627
return total
@@ -641,14 +646,14 @@ def merge_tcp_dataframes_known_streams(
641646
2/ identify which dataframe is server's/client's
642647
2/
643648
644-
Adds a merge_status column
645649
646650
Args:
647651
con1: Tuple dataframe/tcpstream id
648652
con2: same
649653
650654
Returns:
651-
res
655+
A dataframe with a "merge_status" column and valid tcp/mptcp destinations
656+
652657
To ease debug we want to see packets in chronological order
653658
654659
"""
@@ -690,14 +695,15 @@ def merge_tcp_dataframes_known_streams(
690695
# generate_mptcp_direction_query
691696
if isinstance(main_connection, MpTcpSubflow):
692697

693-
print("THIS IS A SUBFLOW")
698+
log.debug("This is a subflow, setting mptcp destinations...")
694699
mptcpdest = main_connection.mptcp_dest_from_tcpdest(tcpdest)
695700
res[_first('mptcpdest')][:] = mptcpdest
696701
res[_second('mptcpdest')][:] = mptcpdest
697702

698703
log.debug("Setting mptcpdest to %s" % mptcpdest)
699704
# if tcpdest == main_connection.mptcpdest
700705

706+
debug_dataframe(total, "concanated df", usecols=["tcpdest", "mptcpdest"])
701707
# TODO here we should
702708
total = pd.concat([res, total])
703709

@@ -894,6 +900,7 @@ def map_tcp_packets(
894900
# con1: TcpConnection, con2: TcpConnection
895901
) -> pd.DataFrame:
896902
'''
903+
Dataframe with format
897904
'''
898905
if mode == "hash":
899906
res = map_tcp_packets_via_hash(sender_df, receiver_df, explain)
@@ -923,14 +930,14 @@ def map_tcp_packets_via_hash(
923930
):
924931
"""
925932
Merge on hash of different fields
933+
Resulting dataframe has H1_SUFFIX / H2_SUFFIX
926934
"""
927935
log.info("Merging packets via hash")
928936
debug_cols = ["packetid", "hash", "reltime"]
929937

930938
from .pdutils import debug_dataframe
931-
debug_dataframe(sender_df, "sender_df", )
932-
debug_dataframe(receiver_df, "receiver df")
933-
# print(receiver_df[debug_cols].head(20))
939+
# debug_dataframe(sender_df, "sender_df", )
940+
# debug_dataframe(receiver_df, "receiver df")
934941
# print("sender_df dtype=", sender_df.dtypes.tcpdest)
935942
# print("receiver_df dtype=", receiver_df.dtypes.tcpdest)
936943

mptcpanalyzer/exporter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import subprocess
99
import logging
1010
import sys
11-
from mptcpanalyzer.tshark import TsharkConfig, convert_csv_to_sql
11+
from mptcpanalyzer.tshark import TsharkConfig
1212

1313
log = logging.getLogger(__name__)
1414

mptcpanalyzer/parser.py

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def cmd_wrapper(instance, cmdline):
178178
class AppendDestination(DataframeAction):
179179
"""
180180
assume convention on naming
181+
TODO check if it's ok with FilterDest
181182
"""
182183

183184
def __init__(self, *args, **kwargs) -> None:
@@ -335,6 +336,7 @@ def __init__(self, df_name: str, **kwargs) -> None:
335336
# init with all destinations
336337
self.destinations = list(ConnectionRoles)
337338
self.already_called = False
339+
# TODO it could set choices automatically
338340
super().__init__(df_name, **kwargs)
339341

340342
def __call__(self, parser, namespace, values, option_string=None):

mptcpanalyzer/pdutils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def debug_dataframe(
4343
print(df.info())
4444
# print(df.columns)
4545
# print(df.dtypes)
46-
pp.pformat(df.dtypes)
46+
print(pp.pformat(df.dtypes))
4747
with pd.option_context('float_format', '{:f}'.format):
4848
sdf = df
4949
if usecols:

mptcpanalyzer/statistics.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ def tcp_get_stats(
7373
con = TcpConnection.build_from_dataframe(df, tcpstreamid)
7474

7575
df2 = tcpdest_from_connections(df, con)
76+
77+
log.debug("df2 size = %d" % len(df2))
7678
# q = con.generate_direction_query(destination)
7779
# df = unidirectional_df = df.query(q, engine="python")
7880
# return (TcpUnidirectionalStats(), TcpUnidirectionalStats() )
7981
# res = { }
8082
# debug_dataframe(df2, "before connection", )
8183
# for destination in ConnectionRoles:
82-
log.log(mp.TRACE, "Looking at role %s" % destination)
84+
log.debug("Looking at role %s" % destination)
8385
# print(df2["tcpdest"])
8486
# TODO assume it's already filtered ?
8587
sdf = df2[df2.tcpdest == destination]
@@ -132,13 +134,15 @@ def mptcp_compute_throughput(
132134
# -1 because of syn
133135
dsn_range = dsn_max - dsn_min - 1
134136

137+
# Could groupby destination as well
135138
d = df.groupby(_sender('tcpstream'))
136139
subflow_stats: List[TcpUnidirectionalStats] = []
137140
for tcpstream, subdf in d:
138141
# subdf.iloc[0, subdf.columns.get_loc(_second('abstime'))]
139-
debug_dataframe(subdf, "subdf")
142+
debug_dataframe(subdf, "subdf for stream %d" % tcpstream)
143+
dest = subdf.iloc[0, subdf.columns.get_loc(_sender('tcpdest'))]
140144
sf_stats = tcp_get_stats(subdf, tcpstream,
141-
subdf.iloc[0, subdf.columns.get_loc(_sender('tcpdest'))],
145+
dest,
142146
True)
143147

144148
# TODO drop retransmitted
@@ -173,6 +177,8 @@ def mptcp_compute_throughput_extended(
173177
174178
Should display goodput
175179
"""
180+
assert isinstance(destination, ConnectionRoles)
181+
log.debug("Looking at destination ", destination)
176182
df_both = classify_reinjections(rawdf)
177183

178184
df = df_both[df_both.mptcpdest == destination]

0 commit comments

Comments
 (0)