ccn-lite-riot.h
1 /*
2  * Copyright (C) 2015, 2016 INRIA
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #ifndef CCN_LITE_RIOT_H
10 #define CCN_LITE_RIOT_H
11 
22 #include <unistd.h>
23 #include "kernel_types.h"
24 #include "arpa/inet.h"
25 #include "net/packet.h"
26 #include "net/ethernet/hdr.h"
27 #include "sys/socket.h"
28 #include "ccnl-defs.h"
29 #include "ccnl-core.h"
30 #include "ccnl-headers.h"
31 #include "net/gnrc/netreg.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
40 #define LOG_LEVEL LOG_DEBUG
41 #include "log.h"
42 
48 #define ccnl_malloc(s) malloc(s)
49 #define ccnl_calloc(n,s) calloc(n,s)
50 #define ccnl_realloc(p,s) realloc(p,s)
51 #define ccnl_free(p) free(p)
52 
59 #define ccnl_close_socket(s) close(s)
60 
66 #define FATAL LOG_ERROR
67 #define ERROR LOG_ERROR
68 #define WARNING LOG_WARNING
69 #define INFO LOG_INFO
70 #define DEBUG LOG_DEBUG
71 #define TRACE LOG_DEBUG
72 #define VERBOSE LOG_ALL
73 
82 #define DEBUGMSG(LVL, ...) do { \
83  if ((LVL)>debug_level) break; \
84  LOG(LVL, __VA_ARGS__); \
85  } while (0)
86 
87 #define DEBUGMSG_CORE(...) DEBUGMSG(__VA_ARGS__)
88 #define DEBUGMSG_CFWD(...) DEBUGMSG(__VA_ARGS__)
89 #define DEBUGMSG_CUTL(...) DEBUGMSG(__VA_ARGS__)
90 #define DEBUGMSG_PIOT(...) DEBUGMSG(__VA_ARGS__)
91 
92 #define DEBUGSTMT(LVL, ...) do { \
93  if ((LVL)>debug_level) break; \
94  __VA_ARGS__; \
95  } while (0)
96 
97 #define TRACEIN(...) do {} while(0)
98 #define TRACEOUT(...) do {} while(0)
99 
107 #define free_2ptr_list(a,b) ccnl_free(a), ccnl_free(b)
108 #define free_3ptr_list(a,b,c) ccnl_free(a), ccnl_free(b), ccnl_free(c)
109 #define free_4ptr_list(a,b,c,d) ccnl_free(a), ccnl_free(b), ccnl_free(c), ccnl_free(d);
110 #define free_5ptr_list(a,b,c,d,e) ccnl_free(a), ccnl_free(b), ccnl_free(c), ccnl_free(d), ccnl_free(e);
111 
118 #define free_prefix(p) do{ if(p) \
119  free_5ptr_list(p->bytes,p->comp,p->complen,p->chunknum,p); } while(0)
120 
121 
125 #define CONSTSTR(s) s
126 
130 #define CCNL_STACK_SIZE (THREAD_STACKSIZE_MAIN)
131 
135 #define CCNL_QUEUE_SIZE (8)
136 
140 typedef struct {
141  struct ccnl_prefix_s *prefix;
142  unsigned char *buf;
143  size_t buflen;
145 
146 
150 #define CCNL_PREFIX_BUFSIZE (50)
151 
155 #define CCNL_MSG_TIMEOUT (0x1701)
156 
160 #define CCNL_MSG_AGEING (0x1702)
161 
165 #ifndef CCNL_CACHE_SIZE
166 #define CCNL_CACHE_SIZE (5)
167 #endif
168 #ifdef DOXYGEN
169 #define CCNL_CACHE_SIZE
170 #endif
171 
175 extern struct ccnl_relay_s ccnl_relay;
176 
180 typedef int (*ccnl_producer_func)(struct ccnl_relay_s *relay,
181  struct ccnl_face_s *from,
182  struct ccnl_pkt_s *pkt);
183 
187 typedef int (*ccnl_cache_strategy_func)(struct ccnl_relay_s *relay,
188  struct ccnl_content_s *c);
189 
196 
207 int ccnl_open_netif(kernel_pid_t if_pid, gnrc_nettype_t netreg_type);
208 
219 int ccnl_send_interest(struct ccnl_prefix_s *prefix,
220  unsigned char *buf, size_t buf_len);
221 
238 int ccnl_wait_for_chunk(void *buf, size_t buf_len, uint64_t timeout);
239 
250 int ccnl_fib_add_entry(struct ccnl_relay_s *relay, struct ccnl_prefix_s *pfx,
251  struct ccnl_face_s *face);
252 
263 int ccnl_fib_rem_entry(struct ccnl_relay_s *relay, struct ccnl_prefix_s *pfx, struct ccnl_face_s *face);
264 
270 void ccnl_fib_show(struct ccnl_relay_s *relay);
271 
281 
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 #endif /* CCN_LITE_RIOT_H */
301 
Types used by the kernel.
Data structure for interest packet.
size_t buflen
size of the buffer
int(* ccnl_cache_strategy_func)(struct ccnl_relay_s *relay, struct ccnl_content_s *c)
Function pointer type for caching strategy function.
int ccnl_wait_for_chunk(void *buf, size_t buf_len, uint64_t timeout)
Wait for incoming content chunk.
void ccnl_set_cache_strategy_remove(ccnl_cache_strategy_func func)
Set a function to control the caching strategy.
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
int(* ccnl_producer_func)(struct ccnl_relay_s *relay, struct ccnl_face_s *from, struct ccnl_pkt_s *pkt)
Function pointer type for local producer function.
int ccnl_fib_add_entry(struct ccnl_relay_s *relay, struct ccnl_prefix_s *pfx, struct ccnl_face_s *face)
Add entry to the CCN-Lite FIB.
int ccnl_fib_rem_entry(struct ccnl_relay_s *relay, struct ccnl_prefix_s *pfx, struct ccnl_face_s *face)
Remove entry from the CCN-Lite FIB.
struct ccnl_prefix_s * prefix
requested prefix
int ccnl_open_netif(kernel_pid_t if_pid, gnrc_nettype_t netreg_type)
Opens a Network interfaces device for use with CCN-Lite.
unsigned char * buf
buffer to store the interest packet
void ccnl_set_local_producer(ccnl_producer_func func)
Set a local producer function.
Definitions to register network protocol PIDs to use with GNRC communication interface.
Ethernet header definitions.
Definitions for internet operations.
Defines the struct for AF_PACKET sockets.
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:42
void ccnl_fib_show(struct ccnl_relay_s *relay)
Prints the current CCN-Lite FIB.
System logging header.
Main socket header.
int ccnl_send_interest(struct ccnl_prefix_s *prefix, unsigned char *buf, size_t buf_len)
Sends out an Interest.
kernel_pid_t ccnl_start(void)
Start the main CCN-Lite event-loop.
struct ccnl_relay_s ccnl_relay
Struct holding CCN-Lite's central relay information.