Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🕺 Feature/add different output types #23

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions feature-extraction-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ chrono = "0.4.34"
dashmap = "5.5.3"
pcap = "1.3.0"
pnet = "0.34.0"
lazy_static = "1.4.0"

[[bin]]
name = "feature-extraction-tool"
Expand Down
30 changes: 29 additions & 1 deletion feature-extraction-tool/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{Parser, Subcommand};
use clap::{Args, Parser, Subcommand};

#[derive(Debug, Parser)]
#[clap(author, version, about)]
Expand All @@ -20,6 +20,10 @@ pub enum Commands {
/// The maximum lifespan of a flow in seconds
lifespan: u64,

/// Output method
#[clap(flatten)]
export_method: Output,

/// The print interval for open flows in seconds, needs to be smaller than the flow maximum lifespan
interval: Option<u64>,
},
Expand All @@ -43,9 +47,33 @@ pub enum Commands {

/// The relative path to the pcap file
path: String,

/// Output method
#[clap(flatten)]
export_method: Output,
},
}

#[derive(Args, Debug, Clone)]
pub struct Output {
/// Output method
#[clap(value_enum)]
pub method: ExportMethodType,

/// File path for output (used if method is File)
#[clap(required_if_eq("method", "Csv"))]
pub export_path: Option<String>,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum ExportMethodType {
/// The output will be printed to the console
Print,

/// The output will be written to a CSV file
Csv,
}

#[derive(clap::ValueEnum, Clone, Debug)]
pub enum GeneratedMachineType {
/// The pcap file was generated on a Windows machine
Expand Down
12 changes: 8 additions & 4 deletions feature-extraction-tool/src/flows/cic_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,8 @@ mod tests {
let mut cic_flow = setup_cic_flow();

cic_flow.basic_flow.first_timestamp = chrono::Utc::now();
cic_flow.basic_flow.last_timestamp = chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();
cic_flow.basic_flow.last_timestamp =
chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();

cic_flow.fwd_pkt_len_tot = 100;
cic_flow.bwd_pkt_len_tot = 100;
Expand All @@ -1990,7 +1991,8 @@ mod tests {
let mut cic_flow = setup_cic_flow();

cic_flow.basic_flow.first_timestamp = chrono::Utc::now();
cic_flow.basic_flow.last_timestamp = chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();
cic_flow.basic_flow.last_timestamp =
chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();

cic_flow.basic_flow.fwd_packet_count = 5;
cic_flow.basic_flow.bwd_packet_count = 5;
Expand All @@ -2003,7 +2005,8 @@ mod tests {
let mut cic_flow = setup_cic_flow();

cic_flow.basic_flow.first_timestamp = chrono::Utc::now();
cic_flow.basic_flow.last_timestamp = chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();
cic_flow.basic_flow.last_timestamp =
chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();

cic_flow.basic_flow.fwd_packet_count = 5;

Expand All @@ -2015,7 +2018,8 @@ mod tests {
let mut cic_flow = setup_cic_flow();

cic_flow.basic_flow.first_timestamp = chrono::Utc::now();
cic_flow.basic_flow.last_timestamp = chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();
cic_flow.basic_flow.last_timestamp =
chrono::Utc::now() + chrono::Duration::try_seconds(5).unwrap();

cic_flow.basic_flow.bwd_packet_count = 5;

Expand Down
Loading