Minor update to fix compilation issues on recent gcc and dpdk
[samplevnf.git] / VNFs / DPPD-PROX / bng_pkts.h
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 _BNG_PKTS_H_
18 #define _BNG_PKTS_H_
19
20 #include <rte_ether.h>
21 #include <rte_ip.h>
22 #include <rte_udp.h>
23 #include <rte_byteorder.h>
24
25 #include "prox_compat.h"
26 #include "gre.h"
27 #include "mpls.h"
28 #include "qinq.h"
29 #include "arp.h"
30 #include "hash_entry_types.h"
31
32 struct cpe_pkt {
33 #ifdef USE_QINQ
34         struct qinq_hdr qinq_hdr;
35 #else
36         prox_rte_ether_hdr ether_hdr;
37 #endif
38         prox_rte_ipv4_hdr ipv4_hdr;
39         prox_rte_udp_hdr udp_hdr;
40 } __attribute__((packed)) __attribute__((__aligned__(2)));
41
42 struct cpe_packet_arp {
43         struct qinq_hdr qinq_hdr;
44         struct my_arp_t arp;
45 } __attribute__((packed)) __attribute__((__aligned__(2)));
46
47 /* Struct used for setting all the values a packet
48    going to the core netwerk. Payload may follow
49    after the headers, but no need to touch that. */
50 struct core_net_pkt_m {
51         prox_rte_ether_hdr ether_hdr;
52 #ifdef MPLS_ROUTING
53         union {
54                 struct mpls_hdr mpls;
55                 uint32_t mpls_bytes;
56         };
57 #endif
58         prox_rte_ipv4_hdr tunnel_ip_hdr;
59         struct gre_hdr gre_hdr;
60         prox_rte_ipv4_hdr ip_hdr;
61         prox_rte_udp_hdr udp_hdr;
62 } __attribute__((packed)) __attribute__((__aligned__(2)));
63
64 struct core_net_pkt {
65         prox_rte_ether_hdr ether_hdr;
66         prox_rte_ipv4_hdr tunnel_ip_hdr;
67         struct gre_hdr gre_hdr;
68         prox_rte_ipv4_hdr ip_hdr;
69         prox_rte_udp_hdr udp_hdr;
70 } __attribute__((packed)) __attribute__((__aligned__(2)));
71
72 #define UPSTREAM_DELTA   ((uint32_t)(sizeof(struct core_net_pkt) - sizeof(struct cpe_pkt)))
73 #define DOWNSTREAM_DELTA ((uint32_t)(sizeof(struct core_net_pkt_m) - sizeof(struct cpe_pkt)))
74
75 struct cpe_pkt_delta {
76         uint8_t encap[DOWNSTREAM_DELTA];
77         struct cpe_pkt pkt;
78 } __attribute__((packed)) __attribute__((__aligned__(2)));
79
80 static inline void extract_key_cpe(struct rte_mbuf *mbuf, uint64_t* key)
81 {
82         uint8_t* packet = rte_pktmbuf_mtod(mbuf, uint8_t*);
83 #ifdef USE_QINQ
84         *key = (*(uint64_t *)(packet + 12)) & 0xFF0FFFFFFF0FFFFF;
85 #else
86         *key = rte_bswap32(*(uint32_t *)(packet + 26)) & 0x00FFFFFF;
87 #endif
88 }
89
90 static inline void key_core(struct gre_hdr* gre, __attribute__((unused)) prox_rte_ipv4_hdr* ip, uint64_t* key)
91 {
92         struct cpe_key *cpe_key = (struct cpe_key*)key;
93
94         cpe_key->gre_id = rte_be_to_cpu_32(gre->gre_id) & 0xFFFFFFF;
95
96 #ifdef USE_QINQ
97         cpe_key->ip = ip->dst_addr;
98 #else
99         cpe_key->ip = 0;
100 #endif
101 }
102
103 static inline void extract_key_core(struct rte_mbuf *mbuf, uint64_t* key)
104 {
105         struct core_net_pkt *packet = rte_pktmbuf_mtod(mbuf, struct core_net_pkt *);
106         key_core(&packet->gre_hdr, &packet->ip_hdr, key);
107 }
108
109 static inline void extract_key_core_m(struct rte_mbuf *mbuf, uint64_t* key)
110 {
111         struct core_net_pkt_m *packet = rte_pktmbuf_mtod(mbuf, struct core_net_pkt_m *);
112         key_core(&packet->gre_hdr, &packet->ip_hdr, key);
113 }
114
115 #endif /* _BNG_PKTS_H_ */