Removing the --socket-mem eal parameter
[samplevnf.git] / VNFs / DPPD-PROX / tools / flow_extract / stream.hpp
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 #ifndef _STREAM_H_
18 #define _STREAM_H_
19
20 #include <list>
21 #include <string>
22 #include <fstream>
23 #include <cstring>
24 #include <vector>
25 #include <cstdlib>
26 #include <sys/time.h>
27
28 #include "pcappktref.hpp"
29 #include "pcappkt.hpp"
30 #include "netsocket.hpp"
31 #include "timestamp.hpp"
32 #include "halfstream.hpp"
33
34 using namespace std;
35
36 class PcapReader;
37
38 class Stream {
39 public:
40         struct Header {
41                 uint32_t streamId;
42                 uint16_t clientHdrLen;
43                 uint32_t clientContentLen;
44                 uint16_t serverHdrLen;
45                 uint32_t serverContentLen;
46                 uint32_t actionCount;
47                 uint32_t clientIP;
48                 uint16_t clientPort;
49                 uint32_t serverIP;
50                 uint16_t serverPort;
51                 double   upRate;
52                 double   dnRate;
53                 uint8_t  protocol;
54                 uint8_t  completedTCP;
55                 void     toFile(ofstream *f) const;
56                 int      fromFile(ifstream *f);
57                 size_t   getStreamLen() const;
58         };
59         struct ActionEntry {
60                 uint8_t peer;
61                 uint32_t beg;
62                 uint32_t len;
63         } __attribute__((packed));
64
65         Stream(uint32_t id = -1, uint32_t sizeHint = 0);
66         void addPkt(const PcapPkt &pkt);
67         void toFile(ofstream *f);
68         void toPcap(const string& outFile);
69         double getRate() const;
70         size_t actionCount() const {return m_actions.size();}
71
72 private:
73         Header getHeader() const;
74         void actionsToFile(ofstream *f) const;
75         void clientHdrToFile(ofstream *f) const;
76         void serverHdrToFile(ofstream *f) const;
77         void contentsToFile(ofstream *f, bool isClient) const;
78         bool isClient(const PcapPkt &pkt) const;
79         size_t pktCount() const;
80         struct pkt_tuple m_pt;
81         void setTupleFromPkt(const PcapPkt &pkt);
82         void addToClient(const PcapPkt &pkt);
83         void addToServer(const PcapPkt &pkt);
84         void addAction(HalfStream *half, HalfStream::Action::Part p, bool isClientPkt);
85
86         int m_id;
87         vector<PcapPkt> m_pkts;
88         vector<HalfStream::Action> m_actions;
89         HalfStream m_client;
90         HalfStream m_server;
91         bool m_prevPktIsClient;
92 };
93
94 #endif /* _STREAM_H_ */