NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hdr-impl.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_ETHFACE_HDR_IMPL_H
2 #define NDNDPDK_ETHFACE_HDR_IMPL_H
3 
6 #include "../ndni/an.h"
7 #include "locator.h"
8 
9 enum {
12  GTP_INNER_LEN = sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr),
13 };
14 
15 __attribute__((nonnull)) static inline uint8_t
16 PutEtherHdr(uint8_t* buffer, const struct rte_ether_addr src, const struct rte_ether_addr dst,
17  uint16_t vid, uint16_t etherType) {
18  struct rte_ether_hdr* ether = (struct rte_ether_hdr*)buffer;
19  ether->dst_addr = dst;
20  ether->src_addr = src;
21  ether->ether_type = rte_cpu_to_be_16(vid == 0 ? etherType : RTE_ETHER_TYPE_VLAN);
22  return RTE_ETHER_HDR_LEN;
23 }
24 
25 __attribute__((nonnull)) static inline uint8_t
26 PutVlanHdr(uint8_t* buffer, uint16_t vid, uint16_t etherType) {
27  struct rte_vlan_hdr* vlan = (struct rte_vlan_hdr*)buffer;
28  vlan->vlan_tci = rte_cpu_to_be_16(vid);
29  vlan->eth_proto = rte_cpu_to_be_16(etherType);
30  return RTE_VLAN_HLEN;
31 }
32 
33 __attribute__((nonnull)) static inline uint8_t
34 PutEtherVlanHdr(uint8_t* buffer, const struct rte_ether_addr src, const struct rte_ether_addr dst,
35  uint16_t vid, uint16_t etherType) {
36  uint8_t off = PutEtherHdr(buffer, src, dst, vid, etherType);
37  if (vid != 0) {
38  off += PutVlanHdr(RTE_PTR_ADD(buffer, off), vid, etherType);
39  }
40  return off;
41 }
42 
43 __attribute__((nonnull)) static inline uint8_t
44 PutIpv4Hdr(uint8_t* buffer, const struct rte_ipv6_addr src, const struct rte_ipv6_addr dst) {
45  struct rte_ipv4_hdr* ip = (struct rte_ipv4_hdr*)buffer;
46  ip->version_ihl = RTE_IPV4_VHL_DEF;
47  ip->fragment_offset = rte_cpu_to_be_16(RTE_IPV4_HDR_DF_FLAG);
48  ip->time_to_live = IP_HOPLIMIT_VALUE;
49  ip->next_proto_id = IPPROTO_UDP;
50  rte_memcpy(&ip->src_addr, &src.a[V4_IN_V6_PREFIX_OCTETS], sizeof(ip->src_addr));
51  rte_memcpy(&ip->dst_addr, &dst.a[V4_IN_V6_PREFIX_OCTETS], sizeof(ip->dst_addr));
52  return sizeof(*ip);
53 }
54 
55 __attribute__((nonnull)) static inline uint8_t
56 PutIpv6Hdr(uint8_t* buffer, const struct rte_ipv6_addr src, const struct rte_ipv6_addr dst) {
57  struct rte_ipv6_hdr* ip = (struct rte_ipv6_hdr*)buffer;
58  ip->version = 6;
59  ip->proto = IPPROTO_UDP;
60  ip->hop_limits = IP_HOPLIMIT_VALUE;
61  ip->src_addr = src;
62  ip->dst_addr = dst;
63  return sizeof(*ip);
64 }
65 
66 __attribute__((nonnull)) static inline uint16_t
67 PutUdpHdr(uint8_t* buffer, uint16_t src, uint16_t dst) {
68  struct rte_udp_hdr* udp = (struct rte_udp_hdr*)buffer;
69  udp->src_port = rte_cpu_to_be_16(src);
70  udp->dst_port = rte_cpu_to_be_16(dst);
71  return sizeof(*udp);
72 }
73 
74 __attribute__((nonnull)) static __rte_always_inline void
75 PutVxlanVni(uint8_t vni[3], uint32_t vniH) {
76  rte_be32_t vniB = rte_cpu_to_be_32(vniH);
77  rte_memcpy(vni, RTE_PTR_ADD(&vniB, 1), 3);
78 }
79 
80 __attribute__((nonnull)) static inline uint8_t
81 PutVxlanHdr(uint8_t* buffer, uint32_t vni) {
82  struct rte_vxlan_hdr* vxlan = (struct rte_vxlan_hdr*)buffer;
83  vxlan->flag_i = 1;
84  PutVxlanVni(vxlan->vni, vni);
85  return sizeof(*vxlan);
86 }
87 
88 __attribute__((nonnull)) static inline uint8_t
89 PutGtpHdr(uint8_t* buffer, bool ul, uint32_t teid, uint8_t qfi) {
90  EthGtpHdr* gtp = (EthGtpHdr*)buffer;
91  static_assert(sizeof(*gtp) == 16, "");
92  gtp->hdr.ver = 1;
93  gtp->hdr.pt = 1;
94  gtp->hdr.e = 1;
95  gtp->hdr.msg_type = 0xFF;
96  gtp->hdr.teid = rte_cpu_to_be_32(teid);
97  gtp->ext.next_ext = EthGtpExtTypePsc;
98  gtp->psc.ext_hdr_len = 1;
99  gtp->psc.type = (int)ul;
100  gtp->psc.qfi = qfi;
101  return sizeof(*gtp);
102 }
103 
104 #endif // NDNDPDK_ETHFACE_HDR_IMPL_H
@ IP_HOPLIMIT_VALUE
Definition: hdr-impl.h:10
@ GTP_INNER_LEN
Definition: hdr-impl.h:12
@ V4_IN_V6_PREFIX_OCTETS
Definition: hdr-impl.h:11
GTP-U header with PDU session container.
Definition: xdp-locator.h:46
struct rte_gtp_psc_generic_hdr psc
Definition: xdp-locator.h:49
struct rte_gtp_hdr_ext_word ext
Definition: xdp-locator.h:48
struct rte_gtp_hdr hdr
Definition: xdp-locator.h:47
@ EthGtpExtTypePsc
Value of EthGtpHdr.ext.next_ext .
Definition: xdp-locator.h:55