From 5c0974864b633a61448a8e3e0441c6f33efb4228 Mon Sep 17 00:00:00 2001 From: "kormiltsyn.roman" Date: Mon, 27 Oct 2025 15:37:37 +0300 Subject: [PATCH 01/33] feat: implement packet filter & tests --- front/src/static/netfront_f.js | 65 ++++++++++++++++++++++- front/src/templates/base.html | 20 ++++++- front/tests/test_packet_filters.py | 84 ++++++++++++++++++++++++++++++ 3 files changed, 166 insertions(+), 3 deletions(-) create mode 100644 front/tests/test_packet_filters.py diff --git a/front/src/static/netfront_f.js b/front/src/static/netfront_f.js index b256d592..0a53bd8a 100644 --- a/front/src/static/netfront_f.js +++ b/front/src/static/netfront_f.js @@ -4,7 +4,14 @@ let global_eh = undefined; var NetworkUpdateTimeoutId = -1; let NetworkCache = []; -const uid = function(){ +let packets_not_filtered = null; +let filterState = { + hideARP: false, + hideSTP: false, +} + + +const uid = function () { return Date.now().toString(36) + Math.random().toString(36).substr(2); } @@ -1276,7 +1283,10 @@ const CheckSimulation = function (simulation_id) { packets = JSON.parse(data.packets); pcaps = data.pcaps; - SetNetworkPlayerState(0); + + // Set filters + packets_not_filtered = null; + SetPacketFilter(); const answerButton = document.querySelector('button[name="answerQuestion"]'); if (answerButton) { @@ -1798,6 +1808,56 @@ const RunSimulation = function (network_guid) }); } + +const FilterPackets = function () { + if (filterState.hideARP) + packets = packets.map((step) => + step.filter((pkt) => + !(pkt.data.label.startsWith('ARP')) + ) + ).filter(step => step.length > 0); + + + if (filterState.hideSTP) + packets = packets.map((step) => + step.filter((pkt) => + !(pkt.data.label.startsWith('STP') || + pkt.data.label.startsWith('RSTP')) + ) + ).filter(step => step.length > 0); + console.log("filterState:", filterState); + console.log("Packets after filters:", packets); + +} + +const RecoverFilterStates = function () { + $("#ARPFilterCheckbox").prop('checked', filterState.hideARP); + $("#STPFilterCheckbox").prop('checked', filterState.hideSTP); +} + +const SetPacketFilter = function () { + console.log("Packet filter call"); + // SetPacketFilter first call on emulated network + if (packets && !packets_not_filtered) { + packets_not_filtered = JSON.parse(JSON.stringify(packets)); // Array deep copy + } + // Numerous filter call, we grab our packets copy to filter it + else if (packets_not_filtered) { + packets = JSON.parse(JSON.stringify(packets_not_filtered)); + } + + filterState.hideARP = $('#ARPFilterCheckbox').is(':checked'); + filterState.hideSTP = $('#STPFilterCheckbox').is(':checked'); + + console.log("filterState after filter call:", filterState); + if (packets) { + console.log('packets here'); + FilterPackets(); + + SetNetworkPlayerState(0); + } +} + // 2 states: // Do we need emulation // We have a packets and ready to play packets @@ -1807,6 +1867,7 @@ const SetNetworkPlayerState = function(simultaion_id) // Reset? if (simultaion_id === -1){ packets = null; + packets_not_filtered = null; pcaps = []; SetNetworkPlayerState(0); return; diff --git a/front/src/templates/base.html b/front/src/templates/base.html index 7e97ccda..d57daadb 100644 --- a/front/src/templates/base.html +++ b/front/src/templates/base.html @@ -133,6 +133,18 @@ Описание сети +
+
+
Настройки анимации
+
+ + +
+
+ + +
+