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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
/*
* Ouroboros - Copyright (C) 2016 - 2017
*
* Routing component of the IPCP
*
* Dimitri Staessens <dimitri.staessens@ugent.be>
* Sander Vrijders <sander.vrijders@ugent.be>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define OUROBOROS_PREFIX "routing"
#include <ouroboros/config.h>
#include <ouroboros/errno.h>
#include <ouroboros/list.h>
#include <ouroboros/logs.h>
#include <ouroboros/rib.h>
#include "routing.h"
#include "ribmgr.h"
#include "ribconfig.h"
#include "ipcp.h"
#include <assert.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#define ADDR_SIZE 30
struct edge {
struct list_head next;
uint64_t addr;
qosspec_t qs;
};
struct vertex {
struct list_head next;
uint64_t addr;
struct list_head edges;
};
struct routing_i {
struct pff * pff;
struct list_head vertices;
};
struct {
struct nbs * nbs;
struct nb_notifier nb_notifier;
char fso_path[RIB_MAX_PATH_LEN + 1];
} routing;
#if 0
/* FIXME: If zeroed since it is not used currently */
static int add_vertex(struct routing * instance,
uint64_t addr)
{
struct vertex * vertex;
vertex = malloc(sizeof(*vertex));
if (vertex == NULL)
return -1;
list_head_init(&vertex->next);
list_head_init(&vertex->edges);
vertex->addr = addr;
list_add(&vertex->next, &instance->vertices);
return 0;
}
#endif
struct routing_i * routing_i_create(struct pff * pff)
{
struct routing_i * tmp;
assert(pff);
tmp = malloc(sizeof(*tmp));
if (tmp == NULL)
return NULL;
tmp->pff = pff;
list_head_init(&tmp->vertices);
return tmp;
}
void routing_i_destroy(struct routing_i * instance)
{
assert(instance);
free(instance);
}
static int routing_neighbor_event(enum nb_event event,
struct conn conn)
{
char addr[ADDR_SIZE];
char path[RIB_MAX_PATH_LEN + 1];
strcpy(path, routing.fso_path);
snprintf(addr, ADDR_SIZE, "%" PRIx64, conn.conn_info.addr);
rib_path_append(path, addr);
switch (event) {
case NEIGHBOR_ADDED:
if (rib_add(routing.fso_path, addr)) {
log_err("Failed to add FSO.");
return -1;
}
if (rib_write(path, &conn.flow_info.qs,
sizeof(conn.flow_info.qs))) {
log_err("Failed to write qosspec to FSO.");
rib_del(path);
return -1;
}
break;
case NEIGHBOR_REMOVED:
if (rib_del(path)) {
log_err("Failed to remove FSO.");
return -1;
}
break;
case NEIGHBOR_QOS_CHANGE:
if (rib_write(path, &conn.flow_info.qs,
sizeof(conn.flow_info.qs))) {
log_err("Failed to write qosspec to FSO.");
return -1;
}
break;
default:
log_info("Unsupported event for routing.");
break;
}
return 0;
}
int routing_init(struct nbs * nbs)
{
char addr[ADDR_SIZE];
if (rib_add(RIB_ROOT, ROUTING_NAME))
return -1;
rib_path_append(routing.fso_path, ROUTING_NAME);
snprintf(addr, ADDR_SIZE, "%" PRIx64, ipcpi.dt_addr);
if (rib_add(routing.fso_path, addr)) {
rib_del(ROUTING_PATH);
return -1;
}
rib_path_append(routing.fso_path, addr);
routing.nbs = nbs;
routing.nb_notifier.notify_call = routing_neighbor_event;
if (nbs_reg_notifier(routing.nbs, &routing.nb_notifier)) {
rib_del(ROUTING_PATH);
return -1;
}
return 0;
}
void routing_fini(void)
{
rib_del(ROUTING_PATH);
nbs_unreg_notifier(routing.nbs, &routing.nb_notifier);
}
|