aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/strategies
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge+fdio@cisco.com>2019-07-26 23:20:30 +0200
committerMauro Sardara <msardara@cisco.com>2019-07-29 17:13:35 +0200
commit0a1c6b5565e20167d1f1f33a5a8b597f420b18b0 (patch)
tree98c5da8f231fbd3dc2ce6502040e29c8333d9ffc /hicn-light/src/hicn/strategies
parent05ca0aa8f612ee48fb66d4dbebe596b7f1e03181 (diff)
[HICN-252] Add per-application policy framework to hicn-light forwarder
Change-Id: I0531cd7a7de179581295ae34766c81cd9cf3e172 Signed-off-by: Jordan Augé <jordan.auge+fdio@cisco.com> Signed-off-by: Mauro Sardara <msardara@cisco.com> Co-authored-by: Mauro Sardara <msardara@cisco.com>
Diffstat (limited to 'hicn-light/src/hicn/strategies')
-rw-r--r--hicn-light/src/hicn/strategies/loadBalancer.c75
-rw-r--r--hicn-light/src/hicn/strategies/loadBalancer.h1
-rw-r--r--hicn-light/src/hicn/strategies/loadBalancerWithPD.c110
-rw-r--r--hicn-light/src/hicn/strategies/loadBalancerWithPD.h7
-rw-r--r--hicn-light/src/hicn/strategies/nexthopState.c6
-rw-r--r--hicn-light/src/hicn/strategies/rnd.c40
-rw-r--r--hicn-light/src/hicn/strategies/rnd.h1
-rw-r--r--hicn-light/src/hicn/strategies/rndSegment.c22
-rw-r--r--hicn-light/src/hicn/strategies/rndSegment.h3
-rw-r--r--hicn-light/src/hicn/strategies/strategyImpl.h6
10 files changed, 256 insertions, 15 deletions
diff --git a/hicn-light/src/hicn/strategies/loadBalancer.c b/hicn-light/src/hicn/strategies/loadBalancer.c
index 6ab26b7ca..b66de217e 100644
--- a/hicn-light/src/hicn/strategies/loadBalancer.c
+++ b/hicn-light/src/hicn/strategies/loadBalancer.c
@@ -36,9 +36,15 @@ static void _strategyLoadBalancer_ReceiveObject(StrategyImpl *strategy,
static void _strategyLoadBalancer_OnTimeout(StrategyImpl *strategy,
const NumberSet *egressId);
static NumberSet *_strategyLoadBalancer_LookupNexthop(
- StrategyImpl *strategy, const Message *interestMessage);
+ StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
+ const Message *interestMessage);
+#ifndef WITH_POLICY
static NumberSet *_strategyLoadBalancer_ReturnNexthops(StrategyImpl *strategy);
static unsigned _strategyLoadBalancer_CountNexthops(StrategyImpl *strategy);
+#endif /* ! WITH_POLICY */
static void _strategyLoadBalancer_AddNexthop(StrategyImpl *strategy,
unsigned connectionId);
static void _strategyLoadBalancer_RemoveNexthop(StrategyImpl *strategy,
@@ -51,8 +57,10 @@ static StrategyImpl _template = {
.receiveObject = &_strategyLoadBalancer_ReceiveObject,
.onTimeout = &_strategyLoadBalancer_OnTimeout,
.lookupNexthop = &_strategyLoadBalancer_LookupNexthop,
+#ifndef WITH_POLICY
.returnNexthops = &_strategyLoadBalancer_ReturnNexthops,
.countNexthops = &_strategyLoadBalancer_CountNexthops,
+#endif /* ! WITH_POLICY */
.addNexthop = &_strategyLoadBalancer_AddNexthop,
.removeNexthop = &_strategyLoadBalancer_RemoveNexthop,
.destroy = &_strategyLoadBalancer_ImplDestroy,
@@ -63,10 +71,14 @@ struct strategy_load_balancer;
typedef struct strategy_load_balancer StrategyLoadBalancer;
struct strategy_load_balancer {
+#ifndef WITH_POLICY
double weights_sum;
+#endif /* ! WITH_POLICY */
// hash map from connectionId to StrategyNexthopState
PARCHashMap *strategy_state;
+#ifndef WITH_POLICY
NumberSet *nexthops;
+#endif /* ! WITH_POLICY */
};
StrategyImpl *strategyLoadBalancer_Create() {
@@ -75,9 +87,13 @@ StrategyImpl *strategyLoadBalancer_Create() {
parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL",
sizeof(StrategyLoadBalancer));
+#ifndef WITH_POLICY
strategy->weights_sum = 0.0;
+#endif /* ! WITH_POLICY */
strategy->strategy_state = parcHashMap_Create();
+#ifndef WITH_POLICY
strategy->nexthops = numberSet_Create();
+#endif /* ! WITH_POLICY */
srand((unsigned int)time(NULL));
StrategyImpl *impl = parcMemory_AllocateAndClear(sizeof(StrategyImpl));
@@ -99,12 +115,17 @@ strategy_type _strategyLoadBalancer_GetStrategy(StrategyImpl *strategy) {
static void _update_Stats(StrategyLoadBalancer *strategy,
StrategyNexthopState *state, bool inc) {
const double ALPHA = 0.9;
+#ifdef WITH_POLICY
+ strategyNexthopState_UpdateState(state, inc, ALPHA);
+#else
double w = strategyNexthopState_GetWeight(state);
strategy->weights_sum -= w;
w = strategyNexthopState_UpdateState(state, inc, ALPHA);
strategy->weights_sum += w;
+#endif /* WITH_POLICY */
}
+#ifndef WITH_POLICY
static unsigned _select_Nexthop(StrategyLoadBalancer *strategy) {
double rnd = (double)rand() / (double)RAND_MAX;
double start_range = 0.0;
@@ -135,6 +156,7 @@ static unsigned _select_Nexthop(StrategyLoadBalancer *strategy) {
// this!
return nexthop;
}
+#endif /* ! WITH_POLICY */
static void _strategyLoadBalancer_ReceiveObject(StrategyImpl *strategy,
const NumberSet *egressId,
@@ -164,14 +186,47 @@ static void _strategyLoadBalancer_OnTimeout(StrategyImpl *strategy,
}
static NumberSet *_strategyLoadBalancer_LookupNexthop(
- StrategyImpl *strategy, const Message *interestMessage) {
+ StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
+ const Message *interestMessage) {
StrategyLoadBalancer *lb = (StrategyLoadBalancer *)strategy->context;
+ NumberSet *outList = numberSet_Create();
+#ifdef WITH_POLICY
+ /* Compute the sum of weights of potential next hops */
+ double sum = 0;
+ for (unsigned i = 0; i < numberSet_Length(nexthops); i++) {
+ PARCUnsigned *cid = parcUnsigned_Create(numberSet_GetItem(nexthops, i));
+ const StrategyNexthopState *elem =
+ parcHashMap_Get(lb->strategy_state, cid);
+ if (!elem)
+ continue;
+ sum += strategyNexthopState_GetWeight(elem);
+ }
+
+ /* Perform weighted random selection */
+ double distance = (double)rand() * sum / ((double)RAND_MAX + 1);
+
+ for (unsigned i = 0; i < numberSet_Length(nexthops); i++) {
+ PARCUnsigned *cid = parcUnsigned_Create(numberSet_GetItem(nexthops, i));
+ const StrategyNexthopState *state =
+ parcHashMap_Get(lb->strategy_state, cid);
+ if (!state)
+ continue;
+ distance -= strategyNexthopState_GetWeight(state);
+ if (distance < 0) {
+ numberSet_Add(outList, parcUnsigned_GetUnsigned(cid));
+ _update_Stats(lb, (StrategyNexthopState *)state, true);
+ break;
+ }
+ }
+#else
unsigned in_connection = message_GetIngressConnectionId(interestMessage);
PARCUnsigned *in = parcUnsigned_Create(in_connection);
unsigned mapSize = (unsigned)parcHashMap_Size(lb->strategy_state);
- NumberSet *outList = numberSet_Create();
if ((mapSize == 0) ||
((mapSize == 1) && parcHashMap_Contains(lb->strategy_state, in))) {
@@ -201,9 +256,12 @@ static NumberSet *_strategyLoadBalancer_LookupNexthop(
parcUnsigned_Release(&out);
numberSet_Add(outList, out_connection);
+#endif /* WITH_POLICY */
+
return outList;
}
+#ifndef WITH_POLICY
static NumberSet *_strategyLoadBalancer_ReturnNexthops(StrategyImpl *strategy) {
StrategyLoadBalancer *lb = (StrategyLoadBalancer *)strategy->context;
return lb->nexthops;
@@ -213,10 +271,13 @@ unsigned _strategyLoadBalancer_CountNexthops(StrategyImpl *strategy) {
StrategyLoadBalancer *lb = (StrategyLoadBalancer *)strategy->context;
return (unsigned)numberSet_Length(lb->nexthops);
}
+#endif /* ! WITH_POLICY */
static void _strategyLoadBalancer_resetState(StrategyImpl *strategy) {
StrategyLoadBalancer *lb = (StrategyLoadBalancer *)strategy->context;
+#ifndef WITH_POLICY
lb->weights_sum = 0.0;
+#endif/* ! WITH_POLICY */
PARCIterator *it = parcHashMap_CreateKeyIterator(lb->strategy_state);
while (parcIterator_HasNext(it)) {
@@ -225,7 +286,9 @@ static void _strategyLoadBalancer_resetState(StrategyImpl *strategy) {
(StrategyNexthopState *)parcHashMap_Get(lb->strategy_state, cid);
strategyNexthopState_Reset(elem);
+#ifndef WITH_POLICY
lb->weights_sum += strategyNexthopState_GetWeight(elem);
+#endif /* ! WITH_POLICY */
}
parcIterator_Release(&it);
@@ -241,7 +304,9 @@ static void _strategyLoadBalancer_AddNexthop(StrategyImpl *strategy,
if (!parcHashMap_Contains(lb->strategy_state, cid)) {
parcHashMap_Put(lb->strategy_state, cid, state);
+#ifndef WITH_POLICY
numberSet_Add(lb->nexthops, connectionId);
+#endif /* WITH_POLICY */
_strategyLoadBalancer_resetState(strategy);
}
}
@@ -254,7 +319,9 @@ static void _strategyLoadBalancer_RemoveNexthop(StrategyImpl *strategy,
if (parcHashMap_Contains(lb->strategy_state, cid)) {
parcHashMap_Remove(lb->strategy_state, cid);
+#ifndef WITH_POLICY
numberSet_Remove(lb->nexthops, connectionId);
+#endif /* WITH_POLICY */
_strategyLoadBalancer_resetState(strategy);
}
@@ -270,7 +337,9 @@ static void _strategyLoadBalancer_ImplDestroy(StrategyImpl **strategyPtr) {
StrategyLoadBalancer *strategy = (StrategyLoadBalancer *)impl->context;
parcHashMap_Release(&(strategy->strategy_state));
+#ifndef WITH_POLICY
numberSet_Release(&(strategy->nexthops));
+#endif /* ! WITH_POLICY */
parcMemory_Deallocate((void **)&strategy);
parcMemory_Deallocate((void **)&impl);
diff --git a/hicn-light/src/hicn/strategies/loadBalancer.h b/hicn-light/src/hicn/strategies/loadBalancer.h
index d0f4faece..74920768d 100644
--- a/hicn-light/src/hicn/strategies/loadBalancer.h
+++ b/hicn-light/src/hicn/strategies/loadBalancer.h
@@ -23,4 +23,5 @@
#include <hicn/strategies/strategyImpl.h>
StrategyImpl *strategyLoadBalancer_Create();
+
#endif // loadBalancer_h
diff --git a/hicn-light/src/hicn/strategies/loadBalancerWithPD.c b/hicn-light/src/hicn/strategies/loadBalancerWithPD.c
index 58f3b25fc..b0aae4cbb 100644
--- a/hicn-light/src/hicn/strategies/loadBalancerWithPD.c
+++ b/hicn-light/src/hicn/strategies/loadBalancerWithPD.c
@@ -38,11 +38,17 @@ static void _strategyLoadBalancerWithPD_ReceiveObject(
static void _strategyLoadBalancerWithPD_OnTimeout(StrategyImpl *strategy,
const NumberSet *egressId);
static NumberSet *_strategyLoadBalancerWithPD_LookupNexthop(
- StrategyImpl *strategy, const Message *interestMessage);
+ StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif
+ const Message *interestMessage);
+#ifndef WITH_POLICY
static NumberSet *_strategyLoadBalancerWithPD_ReturnNexthops(
StrategyImpl *strategy);
static unsigned _strategyLoadBalancerWithPD_CountNexthops(
StrategyImpl *strategy);
+#endif /* ! WITH_POLICY */
static void _strategyLoadBalancerWithPD_AddNexthop(StrategyImpl *strategy,
unsigned connectionId);
static void _strategyLoadBalancerWithPD_RemoveNexthop(StrategyImpl *strategy,
@@ -56,8 +62,10 @@ static StrategyImpl _template = {
.receiveObject = &_strategyLoadBalancerWithPD_ReceiveObject,
.onTimeout = &_strategyLoadBalancerWithPD_OnTimeout,
.lookupNexthop = &_strategyLoadBalancerWithPD_LookupNexthop,
+#ifndef WITH_POLICY
.returnNexthops = &_strategyLoadBalancerWithPD_ReturnNexthops,
.countNexthops = &_strategyLoadBalancerWithPD_CountNexthops,
+#endif /* ! WITH_POLICY */
.addNexthop = &_strategyLoadBalancerWithPD_AddNexthop,
.removeNexthop = &_strategyLoadBalancerWithPD_RemoveNexthop,
.destroy = &_strategyLoadBalancerWithPD_ImplDestroy,
@@ -72,13 +80,19 @@ struct strategy_load_balancer_with_pd {
unsigned min_delay;
// hash map from connectionId to StrategyNexthopState
PARCHashMap *strategy_state;
+#ifndef WITH_POLICY
NumberSet *nexthops;
- ConnectionTable *connTable;
+#endif /* ! WITH_POLICY */
+ const ConnectionTable *connTable;
bool toInit;
unsigned int fwdPackets;
};
+#ifdef WITH_POLICY
+StrategyImpl *strategyLoadBalancerWithPD_Create(const ConnectionTable *table) {
+#else
StrategyImpl *strategyLoadBalancerWithPD_Create() {
+#endif /* WITH_POLICY */
StrategyLoadBalancerWithPD *strategy =
parcMemory_AllocateAndClear(sizeof(StrategyLoadBalancerWithPD));
parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL",
@@ -87,7 +101,9 @@ StrategyImpl *strategyLoadBalancerWithPD_Create() {
strategy->weights_sum = 0.0;
strategy->min_delay = INT_MAX;
strategy->strategy_state = parcHashMap_Create();
+#ifndef WITH_POLICY
strategy->nexthops = numberSet_Create();
+#endif /* ! WITH_POLICY */
srand((unsigned int)time(NULL));
StrategyImpl *impl = parcMemory_AllocateAndClear(sizeof(StrategyImpl));
@@ -127,6 +143,31 @@ static void _update_Stats(StrategyLoadBalancerWithPD *strategy,
strategy->weights_sum += w;
}
+#ifdef WITH_POLICY
+static void _sendProbes(StrategyLoadBalancerWithPD *strategy, NumberSet * nexthops) {
+ unsigned size = (unsigned)numberSet_Length(nexthops);
+ for (unsigned i = 0; i < size; i++) {
+ unsigned nhop = numberSet_GetItem(nexthops, i);
+ Connection *conn =
+ (Connection *)connectionTable_FindById(strategy->connTable, nhop);
+ if (!conn)
+ continue;
+
+ connection_Probe(conn);
+ unsigned delay = (unsigned)connection_GetDelay(conn);
+ PARCUnsigned *cid = parcUnsigned_Create(nhop);
+ StrategyNexthopStateWithPD *elem =
+ (StrategyNexthopStateWithPD *)parcHashMap_Get(
+ strategy->strategy_state, cid);
+ strategyNexthopStateWithPD_SetDelay(elem, delay);
+ if (delay < strategy->min_delay && delay != 0) {
+ strategy->min_delay = delay;
+ }
+
+ parcUnsigned_Release(&cid);
+ }
+}
+#else
static void _sendProbes(StrategyLoadBalancerWithPD *strategy) {
unsigned size = (unsigned)numberSet_Length(strategy->nexthops);
for (unsigned i = 0; i < size; i++) {
@@ -149,7 +190,53 @@ static void _sendProbes(StrategyLoadBalancerWithPD *strategy) {
}
}
}
+#endif /* WITH_POLICY */
+
+#ifdef WITH_POLICY
+static unsigned _select_Nexthop(StrategyLoadBalancerWithPD *strategy, NumberSet * nexthops) {
+ strategy->fwdPackets++;
+ if (strategy->toInit || strategy->fwdPackets == PROBE_FREQUENCY) {
+ strategy->toInit = false;
+ strategy->fwdPackets = 0;
+ _sendProbes(strategy, nexthops);
+ }
+ double rnd = (double)rand() / (double)RAND_MAX;
+ double start_range = 0.0;
+
+ PARCIterator *it = parcHashMap_CreateKeyIterator(strategy->strategy_state);
+
+ unsigned nexthop = 100000;
+ while (parcIterator_HasNext(it)) {
+ PARCUnsigned *cid = parcIterator_Next(it);
+ const StrategyNexthopStateWithPD *elem =
+ parcHashMap_Get(strategy->strategy_state, cid);
+ double w = strategyNexthopStateWithPD_GetWeight(elem);
+
+ // printf("next = %u .. pi %u avgpi %f w %f avgrtt
+ // %f\n",parcUnsigned_GetUnsigned(cid),
+ // strategyNexthopStateWithPD_GetPI(elem),
+ // strategyNexthopStateWithPD_GetWeight(elem),
+ // strategyNexthopStateWithPD_GetWeight(elem),
+ // strategyNexthopStateWithPD_GetAvgRTT(elem));
+
+ double prob = w / strategy->weights_sum;
+ if ((rnd >= start_range) && (rnd < (start_range + prob))) {
+ nexthop = parcUnsigned_GetUnsigned(cid);
+ break;
+ } else {
+ start_range += prob;
+ }
+ }
+
+ parcIterator_Release(&it);
+
+ // if no face is selected by the algorithm (for example because of a wrong
+ // round in the weights) we may always select the last face here. Double check
+ // this!
+ return nexthop;
+}
+#else
static unsigned _select_Nexthop(StrategyLoadBalancerWithPD *strategy) {
strategy->fwdPackets++;
if (strategy->toInit || strategy->fwdPackets == PROBE_FREQUENCY) {
@@ -193,6 +280,7 @@ static unsigned _select_Nexthop(StrategyLoadBalancerWithPD *strategy) {
// this!
return nexthop;
}
+#endif /* WITH_POLICY */
static void _strategyLoadBalancerWithPD_ReceiveObject(
StrategyImpl *strategy, const NumberSet *egressId,
@@ -242,7 +330,11 @@ static void _strategyLoadBalancerWithPD_OnTimeout(StrategyImpl *strategy,
// function never returns NULL. in case we have no output face we need to return
// an empty NumberSet
static NumberSet *_strategyLoadBalancerWithPD_LookupNexthop(
- StrategyImpl *strategy, const Message *interestMessage) {
+ StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif
+ const Message *interestMessage) {
StrategyLoadBalancerWithPD *lb =
(StrategyLoadBalancerWithPD *)strategy->context;
@@ -262,7 +354,11 @@ static NumberSet *_strategyLoadBalancerWithPD_LookupNexthop(
unsigned out_connection;
do {
+#ifdef WITH_POLICY
+ out_connection = _select_Nexthop(lb, nexthops);
+#else
out_connection = _select_Nexthop(lb);
+#endif /* WITH_POLICY */
} while (out_connection == in_connection);
PARCUnsigned *out = parcUnsigned_Create(out_connection);
@@ -284,6 +380,7 @@ static NumberSet *_strategyLoadBalancerWithPD_LookupNexthop(
return outList;
}
+#ifndef WITH_POLICY
static NumberSet *_strategyLoadBalancerWithPD_ReturnNexthops(
StrategyImpl *strategy) {
StrategyLoadBalancerWithPD *lb =
@@ -296,6 +393,7 @@ unsigned _strategyLoadBalancerWithPD_CountNexthops(StrategyImpl *strategy) {
(StrategyLoadBalancerWithPD *)strategy->context;
return (unsigned)numberSet_Length(lb->nexthops);
}
+#endif /* WITH_POLICY */
static void _strategyLoadBalancerWithPD_resetState(StrategyImpl *strategy) {
StrategyLoadBalancerWithPD *lb =
@@ -328,7 +426,9 @@ static void _strategyLoadBalancerWithPD_AddNexthop(StrategyImpl *strategy,
if (!parcHashMap_Contains(lb->strategy_state, cid)) {
parcHashMap_Put(lb->strategy_state, cid, state);
+#ifndef WITH_POLICY
numberSet_Add(lb->nexthops, connectionId);
+#endif /* ! WITH_POLICY */
_strategyLoadBalancerWithPD_resetState(strategy);
}
}
@@ -342,7 +442,9 @@ static void _strategyLoadBalancerWithPD_RemoveNexthop(StrategyImpl *strategy,
if (parcHashMap_Contains(lb->strategy_state, cid)) {
parcHashMap_Remove(lb->strategy_state, cid);
+#ifndef WITH_POLICY
numberSet_Remove(lb->nexthops, connectionId);
+#endif /* ! WITH_POLICY */
_strategyLoadBalancerWithPD_resetState(strategy);
}
@@ -360,7 +462,9 @@ static void _strategyLoadBalancerWithPD_ImplDestroy(
(StrategyLoadBalancerWithPD *)impl->context;
parcHashMap_Release(&(strategy->strategy_state));
+#ifndef WITH_POLICY
numberSet_Release(&(strategy->nexthops));
+#endif /* ! WITH_POLICY */
parcMemory_Deallocate((void **)&strategy);
parcMemory_Deallocate((void **)&impl);
diff --git a/hicn-light/src/hicn/strategies/loadBalancerWithPD.h b/hicn-light/src/hicn/strategies/loadBalancerWithPD.h
index d8a215913..e6c9f8271 100644
--- a/hicn-light/src/hicn/strategies/loadBalancerWithPD.h
+++ b/hicn-light/src/hicn/strategies/loadBalancerWithPD.h
@@ -21,10 +21,15 @@
#ifndef loadBalancerWithPD_h
#define loadBalancerWithPD_h
-#include <hicn/core/connectionTable.h>
#include <hicn/strategies/strategyImpl.h>
+#include <hicn/core/connectionTable.h>
+#ifdef WITH_POLICY
+StrategyImpl *strategyLoadBalancerWithPD_Create(const ConnectionTable * table);
+#else
StrategyImpl *strategyLoadBalancerWithPD_Create();
+#endif /* WITH_POLICY */
+
void strategyLoadBalancerWithPD_SetConnectionTable(StrategyImpl *strategy,
ConnectionTable *connTable);
#endif // loadBalancerWithPD_h
diff --git a/hicn-light/src/hicn/strategies/nexthopState.c b/hicn-light/src/hicn/strategies/nexthopState.c
index 0997193ce..40af14832 100644
--- a/hicn-light/src/hicn/strategies/nexthopState.c
+++ b/hicn-light/src/hicn/strategies/nexthopState.c
@@ -23,6 +23,8 @@
#include <parc/assert/parc_Assert.h>
#include <hicn/strategies/nexthopState.h>
+#define AVG_PI_THRESHOLD 1e-3
+
struct strategy_nexthop_state {
unsigned int pi;
double avg_pi;
@@ -197,7 +199,11 @@ double strategyNexthopState_UpdateState(StrategyNexthopState *x, bool inc,
}
}
x->avg_pi = (x->avg_pi * alpha) + (x->pi * (1 - alpha));
+#ifdef WITH_POLICY
+ if (x->avg_pi < AVG_PI_THRESHOLD) {
+#else
if (x->avg_pi == 0.0) {
+#endif /* WITH_POLICY */
x->avg_pi = 0.1;
}
x->weight = 1 / x->avg_pi;
diff --git a/hicn-light/src/hicn/strategies/rnd.c b/hicn-light/src/hicn/strategies/rnd.c
index e2d74036c..637fd90f9 100644
--- a/hicn-light/src/hicn/strategies/rnd.c
+++ b/hicn-light/src/hicn/strategies/rnd.c
@@ -32,9 +32,14 @@ static void _strategyRnd_ReceiveObject(StrategyImpl *strategy,
static void _strategyRnd_OnTimeout(StrategyImpl *strategy,
const NumberSet *egressId);
static NumberSet *_strategyRnd_LookupNexthop(StrategyImpl *strategy,
- const Message *interestMessage);
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
+ const Message *interestMessage);
+#ifndef WITH_POLICY
static NumberSet *_strategyRnd_ReturnNexthops(StrategyImpl *strategy);
static unsigned _strategyRnd_CountNexthops(StrategyImpl *strategy);
+#endif /* ! WITH_POLICY */
static void _strategyRnd_AddNexthop(StrategyImpl *strategy,
unsigned connectionId);
static void _strategyRnd_RemoveNexthop(StrategyImpl *strategy,
@@ -47,8 +52,10 @@ static StrategyImpl _template = {
.receiveObject = &_strategyRnd_ReceiveObject,
.onTimeout = &_strategyRnd_OnTimeout,
.lookupNexthop = &_strategyRnd_LookupNexthop,
+#ifndef WITH_POLICY
.returnNexthops = &_strategyRnd_ReturnNexthops,
.countNexthops = &_strategyRnd_CountNexthops,
+#endif /* ! WITH_POLICY */
.addNexthop = &_strategyRnd_AddNexthop,
.removeNexthop = &_strategyRnd_RemoveNexthop,
.destroy = &_strategyRnd_ImplDestroy,
@@ -59,7 +66,9 @@ struct strategy_rnd;
typedef struct strategy_rnd StrategyRnd;
struct strategy_rnd {
+#ifndef WITH_POLICY
NumberSet *nexthops;
+#endif /* ! WITH_POLICY */
};
StrategyImpl *strategyRnd_Create() {
@@ -67,7 +76,9 @@ StrategyImpl *strategyRnd_Create() {
parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL",
sizeof(StrategyRnd));
+#ifndef WITH_POLICY
strategy->nexthops = numberSet_Create();
+#endif /* ! WITH_POLICY */
srand((unsigned int)time(NULL));
StrategyImpl *impl = parcMemory_AllocateAndClear(sizeof(StrategyImpl));
@@ -85,6 +96,7 @@ strategy_type _strategyRnd_GetStrategy(StrategyImpl *strategy) {
return SET_STRATEGY_RANDOM;
}
+#ifndef WITH_POLICY
static int _select_Nexthop(StrategyRnd *strategy) {
unsigned len = (unsigned)numberSet_Length(strategy->nexthops);
if (len == 0) {
@@ -94,6 +106,7 @@ static int _select_Nexthop(StrategyRnd *strategy) {
int rnd = (rand() % len);
return numberSet_GetItem(strategy->nexthops, rnd);
}
+#endif /* ! WITH_POLICY */
static void _strategyRnd_ReceiveObject(StrategyImpl *strategy,
const NumberSet *egressId,
@@ -104,13 +117,22 @@ static void _strategyRnd_OnTimeout(StrategyImpl *strategy,
const NumberSet *egressId) {}
static NumberSet *_strategyRnd_LookupNexthop(StrategyImpl *strategy,
- const Message *interestMessage) {
- StrategyRnd *srnd = (StrategyRnd *)strategy->context;
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
+ const Message *interestMessage) {
+ unsigned out_connection;
+ NumberSet *out = numberSet_Create();
+
+#ifdef WITH_POLICY
+ // We return one next hop at random
+ out_connection = numberSet_GetItem(nexthops, rand() % numberSet_Length(nexthops));
+#else
+ StrategyRnd *srnd = (StrategyRnd *)strategy->context;
unsigned in_connection = message_GetIngressConnectionId(interestMessage);
unsigned nexthopSize = (unsigned)numberSet_Length(srnd->nexthops);
- NumberSet *out = numberSet_Create();
if ((nexthopSize == 0) ||
((nexthopSize == 1) &&
numberSet_Contains(srnd->nexthops, in_connection))) {
@@ -119,7 +141,6 @@ static NumberSet *_strategyRnd_LookupNexthop(StrategyImpl *strategy,
return out;
}
- unsigned out_connection;
do {
out_connection = _select_Nexthop(srnd);
} while (out_connection == in_connection);
@@ -127,11 +148,13 @@ static NumberSet *_strategyRnd_LookupNexthop(StrategyImpl *strategy,
if (out_connection == -1) {
return out;
}
+#endif /* WITH_POLICY */
numberSet_Add(out, out_connection);
return out;
}
+#ifndef WITH_POLICY
static NumberSet *_strategyRnd_ReturnNexthops(StrategyImpl *strategy) {
StrategyRnd *srnd = (StrategyRnd *)strategy->context;
return srnd->nexthops;
@@ -141,22 +164,27 @@ unsigned _strategyRnd_CountNexthops(StrategyImpl *strategy) {
StrategyRnd *srnd = (StrategyRnd *)strategy->context;
return (unsigned)numberSet_Length(srnd->nexthops);
}
+#endif /* ! WITH_POLICY */
static void _strategyRnd_AddNexthop(StrategyImpl *strategy,
unsigned connectionId) {
+#ifndef WITH_POLICY
StrategyRnd *srnd = (StrategyRnd *)strategy->context;
if (!numberSet_Contains(srnd->nexthops, connectionId)) {
numberSet_Add(srnd->nexthops, connectionId);
}
+#endif /* ! WITH_POLICY */
}
static void _strategyRnd_RemoveNexthop(StrategyImpl *strategy,
unsigned connectionId) {
+#ifndef WITH_POLICY
StrategyRnd *srnd = (StrategyRnd *)strategy->context;
if (numberSet_Contains(srnd->nexthops, connectionId)) {
numberSet_Remove(srnd->nexthops, connectionId);
}
+#endif /* ! WITH_POLICY */
}
static void _strategyRnd_ImplDestroy(StrategyImpl **strategyPtr) {
@@ -167,7 +195,9 @@ static void _strategyRnd_ImplDestroy(StrategyImpl **strategyPtr) {
StrategyImpl *impl = *strategyPtr;
StrategyRnd *strategy = (StrategyRnd *)impl->context;
+#ifndef WITH_POLICY
numberSet_Release(&(strategy->nexthops));
+#endif /* ! WITH_POLICY */
parcMemory_Deallocate((void **)&strategy);
parcMemory_Deallocate((void **)&impl);
diff --git a/hicn-light/src/hicn/strategies/rnd.h b/hicn-light/src/hicn/strategies/rnd.h
index b57b41ccf..78fb34758 100644
--- a/hicn-light/src/hicn/strategies/rnd.h
+++ b/hicn-light/src/hicn/strategies/rnd.h
@@ -23,4 +23,5 @@
#include <hicn/strategies/strategyImpl.h>
StrategyImpl* strategyRnd_Create();
+
#endif // rnd_h
diff --git a/hicn-light/src/hicn/strategies/rndSegment.c b/hicn-light/src/hicn/strategies/rndSegment.c
index d7a5c6aec..93e39ee74 100644
--- a/hicn-light/src/hicn/strategies/rndSegment.c
+++ b/hicn-light/src/hicn/strategies/rndSegment.c
@@ -33,9 +33,15 @@ static void _strategyRndSegment_ReceiveObject(StrategyImpl *strategy,
static void _strategyRndSegment_OnTimeout(StrategyImpl *strategy,
const NumberSet *egressId);
static NumberSet *_strategyRndSegment_LookupNexthop(
- StrategyImpl *strategy, const Message *interestMessage);
+ StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
+ const Message *interestMessage);
+#ifndef WITH_POLICY
static NumberSet *_strategyRndSegment_ReturnNexthops(StrategyImpl *strategy);
static unsigned _strategyRndSegment_CountNexthops(StrategyImpl *strategy);
+#endif /* ! WITH_POLICY */
static void _strategyRndSegment_AddNexthop(StrategyImpl *strategy,
unsigned connectionId);
static void _strategyRndSegment_RemoveNexthop(StrategyImpl *strategy,
@@ -48,8 +54,10 @@ static StrategyImpl _template = {
.receiveObject = &_strategyRndSegment_ReceiveObject,
.onTimeout = &_strategyRndSegment_OnTimeout,
.lookupNexthop = &_strategyRndSegment_LookupNexthop,
+#ifndef WITH_POLICY
.returnNexthops = &_strategyRndSegment_ReturnNexthops,
.countNexthops = &_strategyRndSegment_CountNexthops,
+#endif /* ! WITH_POLICY */
.addNexthop = &_strategyRndSegment_AddNexthop,
.removeNexthop = &_strategyRndSegment_RemoveNexthop,
.destroy = &_strategyRndSegment_ImplDestroy,
@@ -111,7 +119,11 @@ static void _strategyRndSegment_OnTimeout(StrategyImpl *strategy,
const NumberSet *egressId) {}
static NumberSet *_strategyRndSegment_LookupNexthop(
- StrategyImpl *strategy, const Message *interestMessage) {
+ StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
+ const Message *interestMessage) {
StrategyRndSegment *srnd = (StrategyRndSegment *)strategy->context;
unsigned in_connection = message_GetIngressConnectionId(interestMessage);
@@ -161,6 +173,7 @@ static NumberSet *_strategyRndSegment_LookupNexthop(
return out;
}
+#ifndef WITH_POLICY
static NumberSet *_strategyRndSegment_ReturnNexthops(StrategyImpl *strategy) {
StrategyRndSegment *srnd = (StrategyRndSegment *)strategy->context;
return srnd->nexthops;
@@ -170,22 +183,27 @@ unsigned _strategyRndSegment_CountNexthops(StrategyImpl *strategy) {
StrategyRndSegment *srnd = (StrategyRndSegment *)strategy->context;
return (unsigned)numberSet_Length(srnd->nexthops);
}
+#endif /* ! WITH_POLICY */
static void _strategyRndSegment_AddNexthop(StrategyImpl *strategy,
unsigned connectionId) {
+#ifndef WITH_POLICY
StrategyRndSegment *srnd = (StrategyRndSegment *)strategy->context;
if (!numberSet_Contains(srnd->nexthops, connectionId)) {
numberSet_Add(srnd->nexthops, connectionId);
}
+#endif /* ! WITH_POLICY */
}
static void _strategyRndSegment_RemoveNexthop(StrategyImpl *strategy,
unsigned connectionId) {
+#ifndef WITH_POLICY
StrategyRndSegment *srnd = (StrategyRndSegment *)strategy->context;
if (numberSet_Contains(srnd->nexthops, connectionId)) {
numberSet_Remove(srnd->nexthops, connectionId);
}
+#endif /* ! WITH_POLICY */
}
static void _strategyRndSegment_ImplDestroy(StrategyImpl **strategyPtr) {
diff --git a/hicn-light/src/hicn/strategies/rndSegment.h b/hicn-light/src/hicn/strategies/rndSegment.h
index 897ccca47..6694f03e5 100644
--- a/hicn-light/src/hicn/strategies/rndSegment.h
+++ b/hicn-light/src/hicn/strategies/rndSegment.h
@@ -23,5 +23,6 @@
#include <hicn/strategies/strategyImpl.h>
-StrategyImpl* strategyRndSegment_Create();
+StrategyImpl *strategyRndSegment_Create();
+
#endif // rnd_Segment_h
diff --git a/hicn-light/src/hicn/strategies/strategyImpl.h b/hicn-light/src/hicn/strategies/strategyImpl.h
index 2634665eb..d4001194a 100644
--- a/hicn-light/src/hicn/strategies/strategyImpl.h
+++ b/hicn-light/src/hicn/strategies/strategyImpl.h
@@ -55,12 +55,18 @@ struct strategy_impl {
const Message *objectMessage, Ticks rtt);
void (*onTimeout)(StrategyImpl *strategy, const NumberSet *egressId);
NumberSet *(*lookupNexthop)(StrategyImpl *strategy,
+#ifdef WITH_POLICY
+ NumberSet * nexthops,
+#endif /* WITH_POLICY */
const Message *interestMessage);
+#ifndef WITH_POLICY
NumberSet *(*returnNexthops)(StrategyImpl *strategy);
unsigned (*countNexthops)(StrategyImpl *strategy);
+#endif /* ! WITH_POLICY */
void (*addNexthop)(StrategyImpl *strategy, unsigned connectionId);
void (*removeNexthop)(StrategyImpl *strategy, unsigned connectionId);
void (*destroy)(StrategyImpl **strategyPtr);
strategy_type (*getStrategy)(StrategyImpl *strategy);
};
+
#endif // strategyImpl_h