NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
parse.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_PDUMP_PARSE_H
2 #define NDNDPDK_PDUMP_PARSE_H
3 
6 #include "../ndni/name.h"
7 #include "../ndni/tlv-decoder.h"
8 
9 __attribute__((nonnull)) static inline LName
10 Pdump_ExtractNameL3_(TlvDecoder* d) {
11  uint32_t length, type = TlvDecoder_ReadTL_MaybeTruncated(d, &length);
12  if (unlikely(type != TtName)) {
13  return (LName){0};
14  }
15  return (LName){
16  .value = rte_pktmbuf_mtod_offset(d->m, const uint8_t*, d->offset),
17  .length = RTE_MIN(length, d->m->data_len - d->offset),
18  };
19 }
20 
29 __attribute__((nonnull)) static inline LName
30 Pdump_ExtractName(struct rte_mbuf* pkt) {
31  TlvDecoder d = TlvDecoder_Init(pkt);
32  uint32_t length0, type0 = TlvDecoder_ReadTL(&d, &length0);
33  switch (type0) {
34  case TtInterest:
35  case TtData:
36  return Pdump_ExtractNameL3_(&d);
37  case TtLpPacket:
38  break;
39  default:
40  goto NO_MATCH;
41  }
42 
43  TlvDecoder_EachTL (&d, type1, length1) {
44  switch (type1) {
45  case TtFragIndex: {
46  uint8_t fragIndex = 0;
47  if (unlikely(!TlvDecoder_ReadNniTo(&d, length1, &fragIndex)) || fragIndex > 0) {
48  goto NO_MATCH;
49  }
50  break;
51  }
52  case TtLpPayload: {
53  uint32_t length2, type2 = TlvDecoder_ReadTL_MaybeTruncated(&d, &length2);
54  switch (type2) {
55  case TtInterest:
56  case TtData: {
57  return Pdump_ExtractNameL3_(&d);
58  }
59  default:
60  goto NO_MATCH;
61  }
62  }
63  default:
64  TlvDecoder_Skip(&d, length1);
65  break;
66  }
67  }
68 
69 NO_MATCH:;
70  return (LName){0};
71 }
72 
73 #endif // NDNDPDK_PDUMP_PARSE_H
@ TtName
Definition: an.h:20
@ TtFragIndex
Definition: an.h:14
@ TtInterest
Definition: an.h:30
@ TtData
Definition: an.h:40
@ TtLpPayload
Definition: an.h:12
@ TtLpPacket
Definition: an.h:11
Name in linear buffer.
Definition: name.h:11
TLV decoder.
Definition: tlv-decoder.h:15
uint16_t offset
offset within current segment
Definition: tlv-decoder.h:19
struct rte_mbuf * m
current segment
Definition: tlv-decoder.h:17
#define TlvDecoder_ReadNniTo(...)
Read non-negative integer to a pointer of any unsigned type.
Definition: tlv-decoder.h:321
#define TlvDecoder_EachTL(d, typeVar, lengthVar)
Iterate over TLV elements.
Definition: tlv-decoder.h:257