NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
api.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_STRATEGYAPI_API_H
2 #define NDNDPDK_STRATEGYAPI_API_H
3 
6 #include "../strategycode/sec.h"
7 #include "fib.h"
8 #include "packet.h"
9 #include "pit.h"
10 
12 typedef struct SgGlobal {
13  uint64_t tscHz;
15 
17 typedef enum SgEvent {
24 
26 typedef struct SgCtx {
28  const SgGlobal* global;
29 
32 
35 
38 
43  const SgPacket* pkt;
44 
47 
50 
54 
57 SgTscFromMillis(SgCtx* ctx, uint64_t millis) {
58  return millis * ctx->global->tscHz / 1000;
59 }
60 
65 SUBROUTINE void
67  SgFibNexthopIt_Init(it, ctx->fibEntry, ctx->nhFlt);
68 }
69 
71 #define SgCtx_FibScratchT(ctx, T) \
72  __extension__({ \
73  static_assert(sizeof(T) <= FibScratchSize, ""); \
74  (T*)(ctx)->fibEntryDyn->scratch; \
75  })
76 
78 #define SgCtx_PitScratchT(ctx, T) \
79  __extension__({ \
80  static_assert(sizeof(T) <= PitScratchSize, ""); \
81  (T*)(ctx)->pitEntry->scratch; \
82  })
83 
89 __attribute__((nonnull)) uint32_t
90 SgRandInt(SgCtx* ctx, uint32_t max);
91 
101 __attribute__((nonnull)) bool
102 SgSetTimer(SgCtx* ctx, TscDuration after);
103 
112 
117 __attribute__((nonnull)) SgForwardInterestResult
118 SgForwardInterest(SgCtx* ctx, FaceID nh);
119 
124 __attribute__((nonnull)) void
125 SgReturnNacks(SgCtx* ctx, NackReason reason);
126 
133 __attribute__((section(SGSEC_MAIN), used, nonnull)) uint64_t
134 SgMain(SgCtx* ctx);
135 
136 enum {
139 };
140 
152 __attribute__((nonnull)) bool
153 SgGetJSON(SgCtx* ctx, const char* path, int index, int64_t* dst);
154 
161 #define SgGetJSONScalar(ctx, path, dflt) \
162  __extension__({ \
163  int64_t value = (dflt); \
164  char pathA[] = (path); \
165  SgGetJSON((ctx), pathA, SGJSON_SCALAR, &value); \
166  value; \
167  })
168 
176 #define SgGetJSONSlice(dst, ctx, path, dflt) \
177  __extension__({ \
178  int64_t length = (0); \
179  char pathA[] = (path); \
180  SgGetJSON((ctx), pathA, SGJSON_LEN, &length); \
181  for (int64_t i = 0; i < RTE_DIM((dst)); ++i) { \
182  int64_t value = (dflt); \
183  if (i < length) { \
184  SgGetJSON((ctx), pathA, i, &value); \
185  } \
186  (dst)[i] = value; \
187  } \
188  length; \
189  })
190 
199 __attribute__((section(SGSEC_INIT), used, nonnull)) uint64_t
200 SgInit(SgCtx* ctx);
201 
208 #define SGINIT_SCHEMA(...) \
209  char SgJSONSchema[] __attribute__((section(SGSEC_SCHEMA), used)) = #__VA_ARGS__;
210 
211 #endif // NDNDPDK_STRATEGYAPI_API_H
struct vlanhdr __rte_packed
SUBROUTINE TscDuration SgTscFromMillis(SgCtx *ctx, uint64_t millis)
Convert milliseconds to TscDuration.
Definition: api.h:57
SgForwardInterestResult SgForwardInterest(SgCtx *ctx, FaceID nh)
Forward an Interest to a nexthop.
Definition: fwd-interest.c:186
uint64_t SgMain(SgCtx *ctx)
The strategy dataplane program.
Definition: delay.c:32
void SgReturnNacks(SgCtx *ctx, NackReason reason)
Return Nacks downstream and erase PIT entry.
Definition: fwd-nack.c:49
SgEvent
Indicate why the strategy program is invoked.
Definition: api.h:17
@ SGEVT_TIMER
timer expires
Definition: api.h:22
@ SGEVT_NACK
Nack arrives.
Definition: api.h:21
@ SGEVT_DATA
Data arrives.
Definition: api.h:20
@ SGEVT_NONE
Definition: api.h:18
@ SGEVT_INTEREST
Interest arrives.
Definition: api.h:19
uint64_t SgInit(SgCtx *ctx)
The strategy initialization procedure.
Definition: delay.c:44
uint32_t SgRandInt(SgCtx *ctx, uint32_t max)
Generate a random integer.
Definition: strategy.c:8
struct SgGlobal SgGlobal
Global static parameters.
bool SgGetJSON(SgCtx *ctx, const char *path, int index, int64_t *dst)
Retrieve JSON parameter integer value.
Definition: strategy-code.c:28
bool SgSetTimer(SgCtx *ctx, TscDuration after)
Set a timer to invoke strategy after a duration.
Definition: strategy.c:43
struct SgCtx SgCtx
Context of strategy invocation.
SgForwardInterestResult
Definition: api.h:104
@ SGFWDI_HOPZERO
HopLimit has become zero.
Definition: api.h:110
@ SGFWDI_ALLOCERR
allocation error
Definition: api.h:107
@ SGFWDI_OK
success
Definition: api.h:105
@ SGFWDI_SUPPRESSED
forwarding is suppressed
Definition: api.h:109
@ SGFWDI_NONONCE
upstream has rejected all nonces
Definition: api.h:108
@ SGFWDI_BADFACE
face is down or FaceID is invalid
Definition: api.h:106
@ SGJSON_SCALAR
Definition: api.h:137
@ SGJSON_LEN
Definition: api.h:138
SUBROUTINE void SgFibNexthopIt_InitCtx(SgFibNexthopIt *it, const SgCtx *ctx)
Iterate over FIB nexthops passing ctx->nhFlt.
Definition: api.h:66
uint16_t FaceID
Numeric face identifier.
Definition: faceid.h:13
NackReason
Definition: an.h:69
#define SGSEC_INIT
Definition: sec.h:7
#define SGSEC_MAIN
Definition: sec.h:6
#define SUBROUTINE
Indicate that a function is a subroutine.
Definition: common.h:20
uint32_t SgFibNexthopFilter
Definition: fib.h:23
SUBROUTINE void SgFibNexthopIt_Init(SgFibNexthopIt *it, const SgFibEntry *entry, SgFibNexthopFilter filter)
Definition: fib.h:69
Context of strategy invocation.
Definition: api.h:26
SgFibNexthopFilter nhFlt
A bitmask filter on which FIB nexthops should be used.
Definition: api.h:37
const SgGlobal * global
Global static parameters.
Definition: api.h:28
const SgPacket * pkt
Incoming packet.
Definition: api.h:43
SgFibEntryDyn * fibEntryDyn
FIB entry dynamic area.
Definition: api.h:49
TscTime now
Packet arrival time or current time.
Definition: api.h:31
SgPitEntry * pitEntry
PIT entry.
Definition: api.h:52
SgEvent eventKind
Why strategy is triggered.
Definition: api.h:34
const SgFibEntry * fibEntry
FIB entry.
Definition: api.h:46
Definition: fib.h:10
Definition: fib.h:16
Iterator of FIB nexthops passing a filter.
Definition: fib.h:44
Global static parameters.
Definition: api.h:12
uint64_t tscHz
Definition: api.h:13
Definition: packet.h:9
Definition: pit.h:28
int64_t TscDuration
Duration in TscTime unit.
Definition: tsc.h:12
uint64_t TscTime
TSC clock time point.
Definition: tsc.h:9