createrapid.py is now using heat templates yaml
[samplevnf.git] / VNFs / DPPD-PROX / prox_cksum.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 _PROX_CKSUM_H_
18 #define _PROX_CKSUM_H_
19
20 #include <inttypes.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <rte_version.h>
24 #include <rte_ip.h>
25 #include <rte_udp.h>
26 #include <rte_tcp.h>
27 #include <rte_mbuf.h>
28 #include "igmp.h"
29 #include "prox_compat.h"
30
31 #if RTE_VERSION >= RTE_VERSION_NUM(1,8,0,0)
32 #define CALC_TX_OL(l2_len, l3_len) ((uint64_t)(l2_len) | (uint64_t)(l3_len) << 7)
33 #else
34 #define CALC_TX_OL(l2_len, l3_len) (((uint64_t)(l2_len) << 9) | (uint64_t)(l3_len))
35 #endif
36
37 static void prox_ip_cksum_hw(struct rte_mbuf *mbuf, uint16_t l2_len, uint16_t l3_len)
38 {
39 #if RTE_VERSION < RTE_VERSION_NUM(1,8,0,0)
40         mbuf->pkt.vlan_macip.data = CALC_TX_OL(l2_len, l3_len);
41 #else
42         mbuf->tx_offload = CALC_TX_OL(l2_len, l3_len);
43 #endif
44         mbuf->ol_flags |= PKT_TX_IP_CKSUM;
45 }
46
47 void prox_ip_cksum_sw(prox_rte_ipv4_hdr *buf);
48
49 static inline void prox_ip_cksum(struct rte_mbuf *mbuf, prox_rte_ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int offload)
50 {
51         buf->hdr_checksum = 0;
52 #ifdef SOFT_CRC
53         prox_ip_cksum_sw(buf);
54 #else
55         if (offload)
56                 prox_ip_cksum_hw(mbuf, l2_len, l3_len);
57         else {
58                 prox_ip_cksum_sw(buf);
59                 /* TODO: calculate UDP checksum */
60         }
61 #endif
62 }
63
64 void prox_ip_udp_cksum(struct rte_mbuf *mbuf, prox_rte_ipv4_hdr *buf, uint16_t l2_len, uint16_t l3_len, int cksum_offload);
65
66 /* src_ip_addr/dst_ip_addr are in network byte order */
67 void prox_udp_cksum_sw(prox_rte_udp_hdr *udp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
68 void prox_tcp_cksum_sw(prox_rte_tcp_hdr *tcp, uint16_t len, uint32_t src_ip_addr, uint32_t dst_ip_addr);
69 void prox_igmp_cksum_sw(struct igmpv2_hdr *igmp, uint16_t len);
70
71 #endif /* _PROX_CKSUM_H_ */