Merge "VNF_Catalogue Codebase"
[samplevnf.git] / VNFs / DPPD-PROX / tools / flow_extract / halfstream.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 #include <inttypes.h>
18 #include <list>
19 #include <vector>
20
21 #include "timestamp.hpp"
22 #include "pcappkt.hpp"
23
24 struct HalfStream {
25         struct Action {
26         public:
27                 struct Part {
28                         Part(uint32_t pktId, uint32_t offset, uint32_t len)
29                                 : pktId(pktId), offset(offset), len(len) {}
30                         uint32_t pktId;
31                         uint32_t offset;
32                         uint32_t len;
33                 };
34
35                 Action(HalfStream* stream, const Part &p, bool isClient);
36                 void addPart(const Part& p);
37                 bool isClient() const {return m_isClient;}
38                 /* An action can consist of multiple
39                    packets. The data is not stored in the
40                    action. Instead, a packet id together with
41                    an offset into the packet and a length is
42                    kept to save space */
43                 void toFile(ofstream* f) const;
44                 uint32_t totLen() const;
45         private:
46                 HalfStream *halfStream;
47                 bool       m_isClient;
48                 list<Part> parts;
49         };
50
51         HalfStream();
52         Timestamp first;
53         Timestamp last;
54         uint64_t totLen;
55         uint64_t hdrLen;
56         uint8_t hdr[64];
57         vector<PcapPkt> pkts;
58         uint64_t contentLen;
59         bool tcpOpen;
60         bool tcpClose;
61         Action::Part addPkt(const PcapPkt &pkt);
62         double getRate() const;
63 };