forest-net
an overlay networks for large-scale virtual worlds
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
RouterCore.h
Go to the documentation of this file.
1
9
#ifndef ROUTERCORE_H
10
#define ROUTERCORE_H
11
12
#include <queue>
13
#include <map>
14
15
#include "stdinc.h"
16
#include "
Forest.h
"
17
18
#include "
IfaceTable.h
"
19
#include "
LinkTable.h
"
20
#include "
ComtreeTable.h
"
21
#include "
RouteTable.h
"
22
#include "PacketStore.h"
23
#include "
CtlPkt.h
"
24
#include "QuManager.h"
25
#include "
IoProcessor.h
"
26
#include "
StatsModule.h
"
27
#include "
PacketLog.h
"
28
29
namespace
forest {
30
32
struct
RouterInfo {
33
string
mode
;
34
35
fAdr_t
myAdr
;
36
ipa_t
bootIp
;
37
ipp_t
portNum
;
38
fAdr_t
nmAdr
;
39
ipa_t
nmIp
;
40
fAdr_t
ccAdr
;
41
fAdr_t
firstLeafAdr
;
42
fAdr_t
lastLeafAdr
;
43
44
string
ifTbl
;
45
string
lnkTbl
;
46
string
comtTbl
;
47
string
rteTbl
;
48
string
statSpec
;
49
50
int
finTime
;
51
};
52
53
class
RouterCore
{
54
public
:
55
RouterCore
(
bool
,
const
RouterInfo
&);
56
~
RouterCore
();
57
58
bool
readTables
(
const
RouterInfo
&);
59
bool
setup
();
60
bool
setBooting(
bool
state) {
return
booting
= state; }
61
void
run
(uint64_t);
62
void
dump
(ostream& os);
63
private
:
64
ipa_t
bootIp
;
65
fAdr_t
myAdr
;
66
ipa_t
nmIp
;
67
fAdr_t
nmAdr
;
68
fAdr_t
ccAdr
;
69
70
bool
booting
;
71
72
uint64_t
now
;
73
74
uint64_t
seqNum
;
75
76
fAdr_t
firstLeafAdr
;
77
UiSetPair *
leafAdr
;
78
80
struct
ControlInfo
{
81
pktx
px
;
82
int
nSent
;
83
int
lnk
;
84
uint64_t
timestamp
;
85
};
86
map<uint64_t,ControlInfo> *
pending
;
87
88
int
nIfaces
;
89
int
nLnks
;
90
int
nComts
;
91
int
nRts
;
92
int
nPkts
;
93
int
nBufs
;
94
int
nQus
;
95
96
IfaceTable
*
ift
;
97
LinkTable
*
lt
;
98
ComtreeTable
*
ctt
;
99
RouteTable
*
rt
;
100
PacketStore
*
ps
;
101
QuManager
*
qm
;
102
IoProcessor
*
iop
;
103
StatsModule
*
sm
;
104
PacketLog
*
pktLog
;
105
107
struct
nuClient
{
108
uint64_t
nonce
;
109
time_t
timestamp
;
110
int
iface
;
111
int
link
;
112
};
113
list<nuClient> *
pendingClients
;
114
116
// setup
117
bool
setupIfaces
();
118
bool
setupLeafAddresses
();
119
bool
setupQueues
();
120
bool
checkTables
();
121
bool
setAvailRates
();
122
void
addLocalRoutes
();
123
124
fAdr_t
allocLeafAdr
();
125
bool
allocLeafAdr
(
fAdr_t
);
126
void
freeLeafAdr
(
fAdr_t
);
127
bool
validLeafAdr
(
fAdr_t
)
const
;
128
bool
isFreeLeafAdr
(
fAdr_t
)
const
;
129
130
// basic forwarding
131
void
forward
(pktx,
int
);
132
bool
pktCheck
(pktx,
int
);
133
void
multiSend
(pktx,
int
,
int
);
134
135
// inband control
136
void
handleConnDisc
(pktx);
137
void
handleRteReply
(pktx,
int
);
138
void
sendRteReply
(pktx,
int
);
139
void
subUnsub
(pktx,
int
);
140
141
// signalling packets
142
void
handleCtlPkt
(pktx);
143
144
bool
addIface
(
CtlPkt
&,
CtlPkt
&);
145
bool
dropIface(
CtlPkt
&,
CtlPkt
&);
146
bool
getIface(
CtlPkt
&,
CtlPkt
&);
147
bool
modIface(
CtlPkt
&,
CtlPkt
&);
148
bool
getIfaceSet
(
CtlPkt
&,
CtlPkt
&);
149
150
bool
addLink(
CtlPkt
&,
CtlPkt
&);
151
bool
dropLink(
CtlPkt
&,
CtlPkt
&);
152
void
dropLink(
int
,
fAdr_t
=0);
153
bool
getLink(
CtlPkt
&,
CtlPkt
&);
154
bool
modLink(
CtlPkt
&,
CtlPkt
&);
155
bool
getLinkSet
(
CtlPkt
&,
CtlPkt
&);
156
157
bool
addComtree(
CtlPkt
&,
CtlPkt
&);
158
bool
dropComtree(
CtlPkt
&,
CtlPkt
&);
159
bool
getComtree(
CtlPkt
&,
CtlPkt
&);
160
bool
modComtree(
CtlPkt
&,
CtlPkt
&);
161
bool
getComtreeSet
(
CtlPkt
&,
CtlPkt
&);
162
163
bool
addComtreeLink(
CtlPkt
&,
CtlPkt
&);
164
bool
dropComtreeLink(
CtlPkt
&,
CtlPkt
&);
165
void
dropComtreeLink(
int
,
int
,
int
);
166
bool
modComtreeLink(
CtlPkt
&,
CtlPkt
&);
167
bool
getComtreeLink(
CtlPkt
&,
CtlPkt
&);
168
169
bool
addRoute(
CtlPkt
&,
CtlPkt
&);
170
bool
dropRoute(
CtlPkt
&,
CtlPkt
&);
171
bool
getRoute(
CtlPkt
&,
CtlPkt
&);
172
bool
modRoute(
CtlPkt
&,
CtlPkt
&);
173
bool
getRouteSet
(
CtlPkt
&,
CtlPkt
&);
174
175
bool
addFilter
(
CtlPkt
&,
CtlPkt
&);
176
bool
dropFilter(
CtlPkt
&,
CtlPkt
&);
177
bool
getFilter(
CtlPkt
&,
CtlPkt
&);
178
bool
modFilter(
CtlPkt
&,
CtlPkt
&);
179
bool
getFilterSet
(
CtlPkt
&,
CtlPkt
&);
180
bool
getLoggedPackets
(
CtlPkt
&,
CtlPkt
&);
181
bool
enablePacketLog
(
CtlPkt
&,
CtlPkt
&);
182
183
bool
setLeafRange
(
CtlPkt
&,
CtlPkt
&);
184
185
void
sendConnDisc
(
int
,
Forest::ptyp_t
);
186
bool
sendCpReq
(
CtlPkt
&,
fAdr_t
);
187
bool
sendControl
(pktx,uint64_t,
int
);
188
void
resendControl
();
189
void
handleControlReply
(pktx);
190
191
void
returnToSender
(pktx,
CtlPkt
&);
192
};
193
198
inline
fAdr_t
RouterCore::allocLeafAdr
() {
199
int
offset =
leafAdr
->firstOut();
200
if
(offset == 0)
return
0;
201
leafAdr
->swap(offset);
202
return
firstLeafAdr
+ offset - 1;
203
}
204
210
inline
bool
RouterCore::allocLeafAdr
(
fAdr_t
adr) {
211
int
offset = (adr -
firstLeafAdr
) + 1;
212
if
(!
leafAdr
->isOut(offset))
return
false
;
213
leafAdr
->swap(offset);
214
return
true
;
215
}
216
220
inline
void
RouterCore::freeLeafAdr
(
fAdr_t
adr) {
221
int
offset = (adr -
firstLeafAdr
) + 1;
222
if
(!
leafAdr
->isIn(offset))
return
;
223
leafAdr
->swap(offset);
224
return
;
225
}
226
231
inline
bool
RouterCore::validLeafAdr
(
fAdr_t
adr)
const
{
232
int
offset = (adr -
firstLeafAdr
) + 1;
233
return
leafAdr
->isIn(offset);
234
}
235
240
inline
bool
RouterCore::isFreeLeafAdr
(
fAdr_t
adr)
const
{
241
int
offset = (adr -
firstLeafAdr
) + 1;
242
return
leafAdr
->isOut(offset);
243
}
244
245
}
// ends namespace
246
247
#endif
forest-net
cpp
include
RouterCore.h
Generated on Mon Aug 4 2014 11:13:35 for forest-net by
1.8.4