@@ -5,21 +5,14 @@ use crate::networking::types::data_info::DataInfo;
55use crate :: networking:: types:: data_info_host:: DataInfoHost ;
66use crate :: networking:: types:: host:: Host ;
77use crate :: networking:: types:: info_address_port_pair:: InfoAddressPortPair ;
8- use crate :: networking:: types:: traffic_direction:: TrafficDirection ;
98use crate :: utils:: types:: timestamp:: Timestamp ;
109use std:: collections:: { HashMap , HashSet } ;
1110
1211/// Struct containing overall traffic statistics and data.
1312#[ derive( Debug , Default ) ]
1413pub struct InfoTraffic {
15- /// Total amount of filtered bytes received.
16- pub tot_in_bytes : u128 ,
17- /// Total amount of filtered bytes sent.
18- pub tot_out_bytes : u128 ,
19- /// Total amount of filtered packets received.
20- pub tot_in_packets : u128 ,
21- /// Total amount of filtered packets sent.
22- pub tot_out_packets : u128 ,
14+ /// Total amount of exchanged data
15+ pub tot_data_info : DataInfo ,
2316 /// Total packets including those not filtered
2417 pub all_packets : u128 ,
2518 /// Total bytes including those not filtered
@@ -28,35 +21,24 @@ pub struct InfoTraffic {
2821 pub dropped_packets : u32 ,
2922 /// Timestamp of the latest parsed packet
3023 pub last_packet_timestamp : Timestamp ,
31- /// Total sent bytes filtered before the current time interval
32- pub tot_out_bytes_prev : u128 ,
33- /// Total received bytes filtered before the current time interval
34- pub tot_in_bytes_prev : u128 ,
35- /// Total sent packets filtered before the current time interval
36- pub tot_out_packets_prev : u128 ,
37- /// Total received packets filtered before the current time interval
38- pub tot_in_packets_prev : u128 ,
3924 /// Map of the filtered traffic
4025 pub map : HashMap < AddressPortPair , InfoAddressPortPair > ,
4126 /// Map of the upper layer services with their data info
4227 pub services : HashMap < Service , DataInfo > ,
4328 /// Map of the hosts with their data info
4429 pub hosts : HashMap < Host , DataInfoHost > ,
30+ /// Total amount of exchanged data before the current time interval
31+ pub tot_data_info_prev : DataInfo ,
4532 /// Collection of favorite hosts that exchanged data in the last interval
4633 pub favorites_last_interval : HashSet < ( Host , DataInfoHost ) > ,
4734}
4835
4936impl InfoTraffic {
5037 pub fn refresh ( & mut self , msg : InfoTrafficMessage , favorites : & HashSet < Host > ) {
51- self . tot_out_bytes_prev = self . tot_out_bytes ;
52- self . tot_in_bytes_prev = self . tot_in_bytes ;
53- self . tot_out_packets_prev = self . tot_out_packets ;
54- self . tot_in_packets_prev = self . tot_in_packets ;
38+ self . tot_data_info_prev = self . tot_data_info ;
39+
40+ self . tot_data_info . refresh ( msg. tot_data_info ) ;
5541
56- self . tot_in_bytes += msg. tot_in_bytes ;
57- self . tot_out_bytes += msg. tot_out_bytes ;
58- self . tot_in_packets += msg. tot_in_packets ;
59- self . tot_out_packets += msg. tot_out_packets ;
6042 self . all_packets += msg. all_packets ;
6143 self . all_bytes += msg. all_bytes ;
6244 self . dropped_packets = msg. dropped_packets ;
@@ -100,17 +82,21 @@ impl InfoTraffic {
10082 pub fn get_thumbnail_data ( & self , chart_type : ChartType ) -> ( u128 , u128 , u128 , u128 ) {
10183 if chart_type. eq ( & ChartType :: Bytes ) {
10284 (
103- self . tot_in_bytes ,
104- self . tot_out_bytes ,
105- self . all_bytes - self . tot_out_bytes - self . tot_in_bytes ,
85+ self . tot_data_info . incoming_bytes ( ) ,
86+ self . tot_data_info . outgoing_bytes ( ) ,
87+ self . all_bytes
88+ - self . tot_data_info . outgoing_bytes ( )
89+ - self . tot_data_info . incoming_bytes ( ) ,
10690 // assume that the dropped packets have the same size as the average packet
10791 u128:: from ( self . dropped_packets ) * self . all_bytes / self . all_packets ,
10892 )
10993 } else {
11094 (
111- self . tot_in_packets ,
112- self . tot_out_packets ,
113- self . all_packets - self . tot_out_packets - self . tot_in_packets ,
95+ self . tot_data_info . incoming_packets ( ) ,
96+ self . tot_data_info . outgoing_packets ( ) ,
97+ self . all_packets
98+ - self . tot_data_info . outgoing_packets ( )
99+ - self . tot_data_info . incoming_packets ( ) ,
114100 u128:: from ( self . dropped_packets ) ,
115101 )
116102 }
@@ -120,14 +106,8 @@ impl InfoTraffic {
120106/// Struct containing traffic statistics and data related to the last time interval.
121107#[ derive( Debug , Clone , Default ) ]
122108pub struct InfoTrafficMessage {
123- /// Total amount of filtered bytes received.
124- pub tot_in_bytes : u128 ,
125- /// Total amount of filtered bytes sent.
126- pub tot_out_bytes : u128 ,
127- /// Total amount of filtered packets received.
128- pub tot_in_packets : u128 ,
129- /// Total amount of filtered packets sent.
130- pub tot_out_packets : u128 ,
109+ /// Total amount of exchanged data
110+ pub tot_data_info : DataInfo ,
131111 /// Total packets including those not filtered
132112 pub all_packets : u128 ,
133113 /// Total bytes including those not filtered
@@ -145,18 +125,6 @@ pub struct InfoTrafficMessage {
145125}
146126
147127impl InfoTrafficMessage {
148- pub fn add_packet ( & mut self , bytes : u128 , traffic_direction : TrafficDirection ) {
149- if traffic_direction == TrafficDirection :: Outgoing {
150- //increment number of sent packets and bytes
151- self . tot_out_packets += 1 ;
152- self . tot_out_bytes += bytes;
153- } else {
154- //increment number of received packets and bytes
155- self . tot_in_packets += 1 ;
156- self . tot_in_bytes += bytes;
157- }
158- }
159-
160128 pub fn take_but_leave_something ( & mut self ) -> Self {
161129 let info_traffic = Self {
162130 last_packet_timestamp : self . last_packet_timestamp ,
0 commit comments