aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/pit.h
blob: 1aedcfab969c27b9ccbe94eb93340b0004ce94ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef HICNLIGHT_PIT_H
#define HICNLIGHT_PIT_H


#include <hicn/base/khash.h>
#include <hicn/core/nexthops.h>
#include <hicn/core/msgbuf.h>
#include <hicn/core/fib.h>
#include <hicn/core/name.h>
#include <hicn/core/ticks.h>

typedef struct  {
  msgbuf_t * msgbuf;
  nexthops_t ingressIdSet;
  nexthops_t egressIdSet;

  fib_entry_t * fib_entry;

  Ticks creation_time;
  Ticks expiry_time;
} pit_entry_t;

typedef enum {
    PIT_VERDICT_FORWARD,
    PIT_VERDICT_AGGREGATE,
    PIT_VERDICT_RETRANSMIT,
} pit_verdict_t;

#define pit_entry_get_ingress(E) (&((E)->ingressIdSet))
#define pit_entry_get_egress(E) (&((E)->egressIdSet))
#define pit_entry_get_fib_entry(E) ((E)->fib_entry)
#define pit_entry_set_fib_entry(E, FIB_ENTRY) ((E)->fib_entry = FIB_ENTRY)
#define pit_entry_get_creation_time(E) ((E)->creation_time)
#define pit_entry_get_expiry_time(E) ((E)->expiry_time)
#define pit_entry_set_expiry_time(E, EXPIRY_TIME) \
    (entry)->expiry_time = EXPIRY_TIME

#define pit_entry_ingress_add(E, NH) \
    nexthops_add(pit_entry_get_ingress(E), (NH))

#define pit_entry_ingress_contains(E, NH) \
    nexthops_contains(pit_entry_get_ingress(E), (NH))

#define pit_entry_egress_add(E, NH) \
    nexthops_add(pit_entry_get_egress(E), (NH))

#define pit_entry_from_msgbuf(E, MSGBUF, EXPIRY_TIME, CREATION_TIME)        \
do {                                                                        \
    E->msgbuf = MSGBUF;                                                     \
    pit_entry_ingress_add(E, msgbuf_get_connection_id(MSGBUF));             \
    E->fib_entry = NULL;                                                    \
    E->creation_time = CREATION_TIME;                                       \
    E->expiry_time = EXPIRY_TIME;                                           \
} while(0)

#define name_hash(name) (name_HashCode(name))
#define name_hash_eq(a, b) (name_hash(b) - name_hash(a))

KHASH_INIT(pit_name, const Name *, unsigned, 0, name_hash, name_hash_eq);

typedef struct {
    pit_entry_t * entries; // pool
    kh_pit_name_t * index_by_name;
} pit_t;

pit_t * pit_create(size_t max_elts);

void pit_free(pit_t * pit);

#define _pit_var(x) _pit_ ## x

#define pit_allocate(pit, entry, msgbuf)                                        \
do {                                                                            \
    pool_get(pit->entries, entry);                                              \
    unsigned _pit_var(id) = entry - pit->entries;                               \
    int _pit_var(res);                                                          \
    khiter_t _pit_var(k) = kh_put(pit_name, pit->index_by_name,                 \
            msgbuf_get_name(msgbuf), &_pit_var(res));                           \
    kh_value(pit->index_by_name, _pit_var(k)) = _pit_var(id);                   \
} while(0)

#define pit_at(pit, i) (pit->entries + i)

pit_verdict_t pit_on_interest(pit_t * pit, msgbuf_t * msgbuf);

nexthops_t * pit_on_data(pit_t * pit, const msgbuf_t * msgbuf);

void pit_remove(pit_t * pit, const msgbuf_t * msgbuf);

pit_entry_t * pit_lookup(const pit_t * pit, const msgbuf_t * msgbuf);

#endif /* HICNLIGHT_PIT_H */