Removing the --socket-mem eal parameter
[samplevnf.git] / VNFs / DPPD-PROX / tools / flow_extract / programconfig.cpp
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 */
16
17 #include <sstream>
18 #include <getopt.h>
19 #include <iostream>
20 #include <cstdlib>
21 #include "programconfig.hpp"
22
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)
28 {
29 }
30
31 string ProgramConfig::getUsage() const
32 {
33         stringstream ret;
34
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"
40
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"
63             << "Arguments:\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";
70
71
72         return ret.str();
73 }
74
75 int ProgramConfig::checkConfig()
76 {
77         if (path_file_in_pcap.empty()) {
78                 m_error = "Missing input pcap file\n";
79                 return -1;
80         }
81         return 0;
82 }
83
84 int ProgramConfig::parseOptions(int argc, char *argv[])
85 {
86         char c;
87
88         m_programName = argv[0];
89         while ((c = getopt(argc, argv, "hki:o:s:p")) != -1) {
90                 switch (c) {
91                 case 'h':
92                         return -1;
93                         break;
94                 case 'k':
95                         run_first_step = false;
96                         break;
97                 case 'i':
98                         path_file_in_pcap = optarg;
99                         break;
100                 case 'o':
101                         path_dir_out = optarg;
102                         break;
103                 case 's':
104                         sampleCount = atoi(optarg);
105                         break;
106                 case 'p':
107                         write_pcaps = true;
108                         break;
109                 case '?':
110                         cerr << getUsage() << endl;
111                         return 0;
112                 default:
113                         m_error = "Invalid parameter\n";
114                         return -1;
115                 }
116         }
117
118         return checkConfig();
119 }