Skip to content

Commit 24f13f3

Browse files
committed
ft-analyzer better active flows calculation and predict export time
1 parent 1168f26 commit 24f13f3

2 files changed

Lines changed: 38 additions & 23 deletions

File tree

tools/ft-analyzer/ftanalyzer/events/events.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import heapq
55
import math
66
import os
7+
import random
78
import shutil
89
import tempfile
910
from typing import Iterator
@@ -191,7 +192,10 @@ def convert_row_types(row):
191192

192193

193194
def create_event_queue(
194-
flows_path: os.PathLike, hosts_stats_file: os.PathLike, out_dir: str = None
195+
flows_path: os.PathLike,
196+
hosts_stats_file: os.PathLike,
197+
inactive_timeout: int = 30,
198+
out_dir: str = None,
195199
) -> Iterator[Event]:
196200
if not out_dir:
197201
out_dir = tempfile.mkdtemp(prefix="flows_split_")
@@ -264,23 +268,30 @@ def create_event_queue(
264268
)
265269

266270
# Export Events
267-
if "EXPORT_TIME" in chunk.columns:
268-
temp_export = tempfile.NamedTemporaryFile(
269-
mode="w", prefix="export_time", suffix=".csv", dir=out_dir, delete=False
271+
if "EXPORT_TIME" not in chunk.columns:
272+
# accurate expected EXPORT_TIME
273+
chunk["EXPORT_TIME"] = chunk["END_TIME"] // 1000 + inactive_timeout + 1
274+
# approximate SEQ_NUMBER
275+
chunk["SEQ_NUMER"] = chunk["EXPORT_TIME"] % 32
276+
# random MSG_LENGTH
277+
chunk["MSG_LENGTH"] = random.randint(100, 2048)
278+
279+
temp_export = tempfile.NamedTemporaryFile(
280+
mode="w", prefix="export_time", suffix=".csv", dir=out_dir, delete=False
281+
)
282+
tmp_export.append(temp_export)
283+
(
284+
chunk.groupby(["EXPORT_TIME", "SEQ_NUMBER"], as_index=False)
285+
.agg(
286+
MSG_LENGTH=("MSG_LENGTH", "first"),
287+
FLOWS=("MSG_LENGTH", "count"),
270288
)
271-
tmp_export.append(temp_export)
272-
(
273-
chunk.groupby(["EXPORT_TIME", "SEQ_NUMBER"], as_index=False)
274-
.agg(
275-
MSG_LENGTH=("MSG_LENGTH", "first"),
276-
FLOWS=("MSG_LENGTH", "count"),
277-
)
278-
.sort_values("EXPORT_TIME")
279-
.to_csv(
280-
temp_export.name,
281-
index=False,
282-
)
289+
.sort_values("EXPORT_TIME")
290+
.to_csv(
291+
temp_export.name,
292+
index=False,
283293
)
294+
)
284295

285296
# Multi-packet flows
286297
(

tools/ft-analyzer/ftanalyzer/models/statistical_model.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import numpy as np
2424
import pandas as pd
2525
from ftanalyzer.common.pandas_multiprocessing import PandasMultiprocessingHelper
26-
from ftanalyzer.events.events import ExportEvent
26+
from ftanalyzer.events.events import ExportEvent, FlowStartEvent
2727
from ftanalyzer.models.sm_data_types import (
2828
SMException,
2929
SMMetricType,
@@ -279,7 +279,9 @@ def _run_sim(
279279
statistic_objects, metric_to_obj = setup_statsitic_objects(
280280
sim, start_time, end_time, inactive_timeout
281281
)
282-
event_queue = create_event_queue(flows_file, host_stats, output_dir)
282+
event_queue = create_event_queue(
283+
flows_file, host_stats, inactive_timeout, output_dir
284+
)
283285
process_events(event_queue, statistic_objects, metric_to_obj, sim)
284286

285287
shutil.rmtree(output_dir, ignore_errors=True)
@@ -764,19 +766,17 @@ def _flush_event_data(
764766
# aggregate OnePacketFlow events within this window
765767
one_packet_data_rate = sum(e.bytes for e in one_packet_events) * 8 / duration_s
766768
one_packet_packet_rate = sum(e.packets for e in one_packet_events) / duration_s
767-
one_packet_flows = np.uint64(sum(e.flows for e in one_packet_events))
768769

769770
# Compose final rates
770771
total_data_rate = one_packet_data_rate + current_data_rate
771772
total_packet_rate = one_packet_packet_rate + current_packet_rate
772-
total_flows = one_packet_flows + current_flows
773773

774774
update_statistic_objects(
775775
statistic_objects,
776776
metric_mapping,
777777
data_rate=total_data_rate,
778778
packet_rate=total_packet_rate,
779-
flow_count=total_flows,
779+
flow_count=current_flows,
780780
)
781781

782782
export_events: List[ExportEvent] = [
@@ -889,14 +889,18 @@ def process_events(
889889

890890
# apply each event's effect to current rates
891891
for e in simultaneous_events:
892-
if isinstance(e, HostStatsEvent) or isinstance(e, ExportEvent):
892+
if isinstance(e, HostStatsEvent):
893893
pass
894+
elif isinstance(e, ExportEvent):
895+
current_flows -= e.flows
894896
elif isinstance(e, OnePacketFlow):
895897
one_packet_events.append(e)
898+
current_flows += e.flows
896899
else:
897900
current_data_rate += e.data_rate
898901
current_packet_rate += e.packet_rate
899-
current_flows += e.flows
902+
if isinstance(e, FlowStartEvent):
903+
current_flows += e.flows
900904

901905
current_data_rate = max(0, current_data_rate)
902906
current_packet_rate = max(0, current_packet_rate)

0 commit comments

Comments
 (0)