aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/fib_entry.h
blob: 94d283d0f62d91ea7e9a1b661081873a431b18f6 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file fib_entry.h
 * @brief A forwarding entry in the FIB table
 *
 * A Forwarding Information Base (FIB) entry (fib_entry_t) is a
 * set of nexthops for a name.  It also indicates the forwarding strategy.
 *
 * Each nexthop contains the ConnectionId assocaited with it.  This could be
 * something specific like a MAC address or point-to-point tunnel.  Or, it
 * could be something general like a MAC group address or ip multicast overlay.
 *
 * See strategy.h for a description of forwarding strategies.
 * In short, a strategy is the algorithm used to select one or more nexthops
 * from the set of available nexthops.
 *
 * Each nexthop also contains a void* to a forwarding strategy data container.
 * This allows a strategy to keep proprietary information about each nexthop.
 *
 *
 */

#ifndef fib_entry_h
#define fib_entry_h

#include <hicn/core/name.h>
#include <hicn/core/strategy.h>
#include <hicn/core/msgbuf.h>
#include <hicn/core/nexthops.h>
#include <hicn/core/prefix_stats.h>
#include <hicn/utils/commands.h> // strategy type

#ifdef WITH_MAPME
//#include <parc/algol/parc_EventTimer.h>
//#include <parc/algol/parc_Iterator.h>
#endif /* WITH_MAPME */

typedef struct {
  Name *name;
  unsigned refcount;
  nexthops_t nexthops;
  strategy_entry_t strategy;

  const void * forwarder;

#ifdef WITH_POLICY
  policy_t policy;
#endif /* WITH_POLICY */

  prefix_counters_t prefix_counters;
  prefix_stats_t prefix_stats;

#ifdef WITH_MAPME
  /* In case of no multipath, this stores the previous decision taken by policy. As the list of nexthops is not expected to change, we can simply store the flags */
  uint_fast32_t prev_nexthops_flags;
  void *user_data;
  void (*user_data_release)(void **user_data);
#endif /* WITH_MAPME */
} fib_entry_t;

#define _fib_entry_var(x) _fib_entry_##x

#define fib_entry_strategy_type(fib_entry) ((fib_entry)->strategy.type)

#define fib_entry_get_nexthops(fib_entry) (&(fib_entry)->nexthops)
#define fib_entry_nexthops_len(fib_entry) (nexthops_len(&(fib_entry)->nexthops))
#define fib_entry_nexthops_curlen(fib_entry) (nexthops_curlen(&(fib_entry)->nexthops))
#define fib_entry_get_nexthop(fib_entry, i) ((fib_entry)->nexthops.elts[i])
#define fib_entry_foreach_nexthop(fib_entry, nexthop, BODY)             \
    nexthops_foreach(fib_entry->nexthops, BODY)

#define fib_entry_nexthops_changed(fib_entry) \
    ((fib_entry)->prev_nexthops_flags == fib_entry_get_nexthops(fib_entry)->flags)

#define fib_entry_set_prev_nexthops(fib_entry) \
    ((fib_entry)->prev_nexthops_flags = fib_entry_get_nexthops(fib_entry)->flags)

struct forwarder_s;
fib_entry_t *fib_entry_create(Name *name, strategy_type_t strategy_type,
        strategy_options_t * strategy_options, const struct forwarder_s * table);

void fib_entry_set_strategy(fib_entry_t *fib_entry,
        strategy_type_t strategy_type, strategy_options_t * strategy_options);

void fib_entry_nexthops_add(fib_entry_t * fib_entry, unsigned nexthop);

void fib_entry_nexthops_remove(fib_entry_t * fib_entry, unsigned nexthop);

size_t fib_entry_NexthopCount(const fib_entry_t *fib_entry);

/**
 * @function fib_entry_nexthops_get
 * @abstract Returns the nexthop set of the FIB entry.  You must Acquire if it
 * will be saved.
 * @discussion
 *   Returns the next hop set for the FIB entry.
 */
const nexthops_t * fib_entry_nexthops_get(const fib_entry_t *fib_entry);

const nexthops_t * fib_entry_nexthops_getFromForwardingStrategy(
    fib_entry_t *fib_entry, const msgbuf_t *interest_msgbuf, bool is_retransmission);

void fib_entry_on_data(fib_entry_t * fib_entry, const nexthops_t * nexthops,
        const msgbuf_t * object_msgbuf, Ticks pit_entry_creation,
        Ticks data_reception);

#ifdef WITH_POLICY
policy_t fib_entry_get_policy(const fib_entry_t *fib_entry);
void fib_entry_reconsider_policy(fib_entry_t *fib_entry);
void fib_entry_set_policy(fib_entry_t *fib_entry, policy_t policy);
void fib_entry_update_stats(fib_entry_t *fib_entry, uint64_t now);
#endif /* WITH_POLICY */

nexthops_t * fib_entry_get_available_nexthops(fib_entry_t *fib_entry,
    unsigned in_connection, nexthops_t * new_nexthops);
void fib_entry_on_timeout(fib_entry_t *fib_entry, const nexthops_t *egressId);
const nexthops_t * fib_entry_get_nexthops_from_strategy(fib_entry_t *fib_entry,
      const msgbuf_t *interest_msgbuf, bool is_retransmission);

/**
 * @function fib_entry_get_prefix
 * @abstract Returns a copy of the prefix.
 * @return A reference counted copy that you must destroy
 */
Name *fib_entry_get_prefix(const fib_entry_t *fib_entry);

bool fib_entry_has_local_nexthop(const fib_entry_t * entry);

#ifdef WITH_MAPME

/**
 * @function fib_entry_get_user_data
 * @abstract Returns user data associated to the FIB entry.
 * @param [in] fib_entry - Pointer to the FIB entry.
 * @return User data as a void pointer
 */
void *fib_entry_get_user_data(const fib_entry_t *fib_entry);

/**
 * @function fib_entry_get_user_data
 * @abstract Associates user data and release callback to a FIB entry.
 * @param [in] fib_entry - Pointer to the FIB entry.
 * @param [in] user_data - Generic pointer to user data
 * @param [in@ user_data_release - Callback used to release user data upon change
 *       of FIB entry removal.
 */
void fib_entry_set_user_data(fib_entry_t *fib_entry, const void *user_data,
                          void (*user_data_release)(void **));

#endif /* WITH_MAPME */

#endif  // fib_entry_h