NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nni.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_NDNI_NNI_H
2 #define NDNDPDK_NDNI_NNI_H
3 
6 #include "common.h"
7 
12 __attribute__((nonnull)) static __rte_always_inline bool
13 Nni_Decode(uint32_t length, const uint8_t* value, uint64_t* n) {
14  switch (length) {
15  case 1:
16  *n = value[0];
17  return true;
18  case 2:
19  *n = rte_be_to_cpu_16(*(unaligned_uint16_t*)value);
20  return true;
21  case 4:
22  *n = rte_be_to_cpu_32(*(unaligned_uint32_t*)value);
23  return true;
24  case 8:
25  *n = rte_be_to_cpu_64(*(unaligned_uint64_t*)value);
26  return true;
27  default:
28  *n = 0;
29  return false;
30  }
31 }
32 
38 __attribute__((nonnull)) static __rte_always_inline uint8_t
39 Nni_Encode(uint8_t* room, uint64_t n) {
40  if (n > UINT16_MAX) {
41  if (n > UINT32_MAX) {
42  unaligned_uint64_t* b = (unaligned_uint64_t*)room;
43  *b = rte_cpu_to_be_64(n);
44  return 8;
45  }
46 
47  unaligned_uint32_t* b = (unaligned_uint32_t*)room;
48  *b = rte_cpu_to_be_32(n);
49  return 4;
50  }
51 
52  if (n > UINT8_MAX) {
53  unaligned_uint16_t* b = (unaligned_uint16_t*)room;
54  *b = rte_cpu_to_be_16(n);
55  return 2;
56  }
57 
58  *room = n;
59  return 1;
60 }
61 
67 __attribute__((nonnull)) static __rte_always_inline uint8_t
68 Nni_EncodeNameComponent(uint8_t* room, uint8_t typ, uint64_t n) {
69  room[0] = typ;
70  room[1] = Nni_Encode(RTE_PTR_ADD(room, 2), n);
71  return 2 + room[1];
72 }
73 
74 #endif // NDNDPDK_NDNI_NNI_H