2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
21 #include "programconfig.hpp"
23 ProgramConfig::ProgramConfig()
24 : path_file_in_pcap(""), path_dir_out("output"),
25 path_file_dest_lua("lua"), max_pkts(UINT32_MAX),
26 max_streams(UINT32_MAX), sampleCount(20000), flowTableSize(8*1024*1024),
27 run_first_step(true), write_pcaps(false)
31 string ProgramConfig::getUsage() const
35 ret << "Usage example: "<< m_programName << " -i in.pcap\n\n"
36 << "Flow Extract 2.0 analyzes and extracts a traffic profile\n"
37 << "configuration from a pcap file. The output is a lua\n"
38 << "configuration file and a binary file containing all the\n"
39 << "headers and payloads for each stream.\n\n"
41 << "The program supports analyzing large pcap file (> 300 GB).\n"
42 << "For this, it uses a multi-pass approach. The output of \n"
43 << "intermediary steps is stored in the working directory. The\n"
44 << "algorithm can be described by the following steps:\n\n"
45 << " 1. The pcap file in read chunks of 16 GB. The packets in\n"
46 << " each chunk are associated with streams. The streams are\n"
47 << " ordered through a global ID. Each stream is stored as a"
48 << " sequence of packets that belong to that stream. The\n"
49 << " resulting file at 'DIR/tmp' where DIR is specified\n"
50 << " through -o options as shown below.\n"
51 << " Each chunk in tmp is merged and the result is written\n"
52 << " to file1. Reading the stream with a given ID from all chunks\n"
53 << " gets all the packets for the stream from the whole pcap in\n"
54 << " memory. This first step forms is implemented by an\n"
55 << " external sorting algorithm.\n"
56 << " 2. File2 is read and the source IP for each stream is used to\n"
57 << " associate each stream with a bundle. SAMPLE_COUNT samples\n"
58 << " are taken from the set of bundles. The set of streams that\n"
59 << " are still referenced by the sampled bundles extracted from\n"
60 << " file2 and written to the final binary file. This binary file\n"
61 << " is referenced from the lua configuration. The lua config file\n"
62 << " is written out as part of this step.\n"
64 << "-i FILE Input pcap to process\n"
65 << "-o DIR output directory and working directory\n"
66 << "-s SAMPLE_COUNT Number of samples to take (default is 20K)\n"
67 << "-k Skip the first step as described above. Useful to\n"
68 << " adjust the number of samples without having to\n"
69 << " repeat the whole process\n";
75 int ProgramConfig::checkConfig()
77 if (path_file_in_pcap.empty()) {
78 m_error = "Missing input pcap file\n";
84 int ProgramConfig::parseOptions(int argc, char *argv[])
88 m_programName = argv[0];
89 while ((c = getopt(argc, argv, "hki:o:s:p")) != -1) {
95 run_first_step = false;
98 path_file_in_pcap = optarg;
101 path_dir_out = optarg;
104 sampleCount = atoi(optarg);
110 cerr << getUsage() << endl;
113 m_error = "Invalid parameter\n";
118 return checkConfig();