summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp
diff options
context:
space:
mode:
authorDeepak S <deepak.s@linux.intel.com>2017-07-13 21:26:50 -0700
committerDeepak S <deepak.s@linux.intel.com>2017-07-14 04:58:47 -0700
commit7286b2518ec8e4398b512ce95def9166a7af2e4a (patch)
treec93ef65d9e73e8893ccecb720152e16aae96a8b6 /VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp
parentadcb79da90176b27224eeb1d00aa0e611ef85a9b (diff)
Adding PROX(Packet pROcessing eXecution engine) VNF to sampleVNF
JIRA: SAMPLEVNF-55 PROX is a DPDK-based application implementing Telco use-cases such as a simplified BRAS/BNG, light-weight AFTR... It also allows configuring finer grained network functions like QoS, Routing, load-balancing... (We are moving PROX version v039 to sampleVNF https://01.org/intel-data-plane-performance-demonstrators/prox-overview) Change-Id: Ia3cb02cf0e49ac5596e922c197ff7e010293d033 Signed-off-by: Deepak S <deepak.s@linux.intel.com>
Diffstat (limited to 'VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp')
-rw-r--r--VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp b/VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp
new file mode 100644
index 00000000..e437c790
--- /dev/null
+++ b/VNFs/DPPD-PROX/tools/flow_extract/pcappkt.hpp
@@ -0,0 +1,104 @@
+/*
+// Copyright (c) 2010-2017 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#ifndef _PCAPPKT_H_
+#define _PCAPPKT_H_
+
+#include <inttypes.h>
+#include <pcap.h>
+#include <string>
+#include <cstring>
+
+using namespace std;
+
+struct pkt_tuple {
+ uint32_t src_addr;
+ uint32_t dst_addr;
+ uint8_t proto_id;
+ uint16_t src_port;
+ uint16_t dst_port;
+ bool operator!=(const pkt_tuple& other) const
+ {
+ return src_addr != other.src_addr ||
+ dst_addr != other.dst_addr ||
+ proto_id != other.proto_id ||
+ src_port != other.src_port ||
+ dst_port != other.dst_port;
+ }
+ bool operator==(const pkt_tuple& other) const
+ {
+ return src_addr == other.src_addr &&
+ dst_addr == other.dst_addr &&
+ proto_id == other.proto_id &&
+ src_port == other.src_port &&
+ dst_port == other.dst_port;
+ }
+ friend ostream& operator<<(ostream& stream, const pkt_tuple &other);
+ struct pkt_tuple flip() const
+ {
+ struct pkt_tuple ret;
+
+ ret = *this;
+ ret.src_addr = dst_addr;
+ ret.src_port = dst_port;
+ ret.dst_addr = src_addr;
+ ret.dst_port = src_port;
+ return ret;
+ }
+
+} __attribute__((packed));
+
+class Allocator;
+
+class PcapPkt {
+ friend class PcapReader;
+public:
+ struct tcp_hdr {
+ uint16_t src_port; /**< TCP source port. */
+ uint16_t dst_port; /**< TCP destination port. */
+ uint32_t sent_seq; /**< TX data sequence number. */
+ uint32_t recv_ack; /**< RX data acknowledgement sequence number. */
+ uint8_t data_off; /**< Data offset. */
+ uint8_t tcp_flags; /**< TCP flags */
+ uint16_t rx_win; /**< RX flow control window. */
+ uint16_t cksum; /**< TCP checksum. */
+ uint16_t tcp_urp; /**< TCP urgent pointer, if any. */
+ } __attribute__((__packed__));
+
+ static Allocator *allocator;
+ enum L4Proto {PROTO_TCP, PROTO_UDP};
+ PcapPkt();
+ void* operator new(size_t size);
+ static void operator delete(void *pointer);
+ PcapPkt(const PcapPkt& other);
+ PcapPkt(uint8_t *mem);
+ void toMem(uint8_t *mem) const;
+ void fromMem(uint8_t *mem);
+ void toFile(ofstream *file) const;
+ size_t memSize() const;
+ const struct timeval &ts() const {return header.ts;}
+ const uint16_t len() const {return header.len;}
+ pkt_tuple parsePkt(const uint8_t **l4_hdr = NULL, uint16_t *hdr_len = NULL, const uint8_t **l5 = NULL, uint32_t *l5_len = NULL) const;
+ const struct pcap_pkthdr &hdr() const {return header;}
+ const uint8_t *payload() const {return buf;}
+ enum L4Proto getProto() const;
+ ~PcapPkt();
+private:
+ struct pcap_pkthdr header;
+ uint8_t *buf;
+};
+
+#endif /* _PCAPPKT_H_ */