diff options
Diffstat (limited to 'hicn-light/src/hicn/strategies')
-rw-r--r-- | hicn-light/src/hicn/strategies/CMakeLists.txt | 10 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/loadBalancer.c | 6 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/loadBalancerWithPD.c | 468 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/loadBalancerWithPD.h | 31 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/lowLatency.c | 765 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/lowLatency.h (renamed from hicn-light/src/hicn/strategies/rndSegment.h) | 15 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/nexthopStateLowLatency.c | 481 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/nexthopStateLowLatency.h | 116 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/nexthopStateWithPD.c | 254 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/nexthopStateWithPD.h | 106 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/rnd.c | 20 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/rndSegment.c | 225 | ||||
-rw-r--r-- | hicn-light/src/hicn/strategies/strategyImpl.h | 3 |
13 files changed, 1394 insertions, 1106 deletions
diff --git a/hicn-light/src/hicn/strategies/CMakeLists.txt b/hicn-light/src/hicn/strategies/CMakeLists.txt index 7f0730b2f..400efcde9 100644 --- a/hicn-light/src/hicn/strategies/CMakeLists.txt +++ b/hicn-light/src/hicn/strategies/CMakeLists.txt @@ -16,20 +16,18 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR) list(APPEND HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/strategyImpl.h ${CMAKE_CURRENT_SOURCE_DIR}/loadBalancer.h - ${CMAKE_CURRENT_SOURCE_DIR}/loadBalancerWithPD.h + ${CMAKE_CURRENT_SOURCE_DIR}/lowLatency.h ${CMAKE_CURRENT_SOURCE_DIR}/nexthopState.h - ${CMAKE_CURRENT_SOURCE_DIR}/nexthopStateWithPD.h + ${CMAKE_CURRENT_SOURCE_DIR}/nexthopStateLowLatency.h ${CMAKE_CURRENT_SOURCE_DIR}/rnd.h - ${CMAKE_CURRENT_SOURCE_DIR}/rndSegment.h ) list(APPEND SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/loadBalancer.c - ${CMAKE_CURRENT_SOURCE_DIR}/loadBalancerWithPD.c + ${CMAKE_CURRENT_SOURCE_DIR}/lowLatency.c ${CMAKE_CURRENT_SOURCE_DIR}/nexthopState.c - ${CMAKE_CURRENT_SOURCE_DIR}/nexthopStateWithPD.c + ${CMAKE_CURRENT_SOURCE_DIR}/nexthopStateLowLatency.c ${CMAKE_CURRENT_SOURCE_DIR}/rnd.c - ${CMAKE_CURRENT_SOURCE_DIR}/rndSegment.c ) set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE) diff --git a/hicn-light/src/hicn/strategies/loadBalancer.c b/hicn-light/src/hicn/strategies/loadBalancer.c index 35d64e763..878a58515 100644 --- a/hicn-light/src/hicn/strategies/loadBalancer.c +++ b/hicn-light/src/hicn/strategies/loadBalancer.c @@ -32,7 +32,8 @@ static void _strategyLoadBalancer_ReceiveObject(StrategyImpl *strategy, const NumberSet *egressId, const Message *objectMessage, - Ticks rtt); + Ticks pitEntryCreation, + Ticks objReception); static void _strategyLoadBalancer_OnTimeout(StrategyImpl *strategy, const NumberSet *egressId); static NumberSet *_strategyLoadBalancer_LookupNexthop( @@ -161,7 +162,8 @@ static unsigned _select_Nexthop(StrategyLoadBalancer *strategy) { static void _strategyLoadBalancer_ReceiveObject(StrategyImpl *strategy, const NumberSet *egressId, const Message *objectMessage, - Ticks rtt) { + Ticks pitEntryCreation, + Ticks objReception) { _strategyLoadBalancer_OnTimeout(strategy, egressId); } diff --git a/hicn-light/src/hicn/strategies/loadBalancerWithPD.c b/hicn-light/src/hicn/strategies/loadBalancerWithPD.c deleted file mode 100644 index dac759053..000000000 --- a/hicn-light/src/hicn/strategies/loadBalancerWithPD.c +++ /dev/null @@ -1,468 +0,0 @@ -/* - * 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. - */ - -#include <limits.h> -#include <hicn/hicn-light/config.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include <parc/assert/parc_Assert.h> - -#include <parc/algol/parc_HashMap.h> -#include <parc/algol/parc_Memory.h> -#include <parc/algol/parc_Object.h> -#include <parc/algol/parc_Unsigned.h> - -#include <hicn/strategies/loadBalancerWithPD.h> -#include <hicn/strategies/nexthopStateWithPD.h> - -const unsigned PROBE_FREQUENCY = 1024; - -static void _strategyLoadBalancerWithPD_ReceiveObject( - StrategyImpl *strategy, const NumberSet *egressId, - const Message *objectMessage, Ticks rtt); -static void _strategyLoadBalancerWithPD_OnTimeout(StrategyImpl *strategy, - const NumberSet *egressId); -static NumberSet *_strategyLoadBalancerWithPD_LookupNexthop( - 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, - unsigned connectionId); -static void _strategyLoadBalancerWithPD_ImplDestroy(StrategyImpl **strategyPtr); -static strategy_type _strategyLoadBalancerWithPD_GetStrategy( - StrategyImpl *strategy); - -static StrategyImpl _template = { - .context = NULL, - .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, - .getStrategy = &_strategyLoadBalancerWithPD_GetStrategy, -}; - -struct strategy_load_balancer_with_pd; -typedef struct strategy_load_balancer_with_pd StrategyLoadBalancerWithPD; - -struct strategy_load_balancer_with_pd { - double weights_sum; - unsigned min_delay; - // hash map from connectionId to StrategyNexthopState - PARCHashMap *strategy_state; -#ifndef WITH_POLICY - NumberSet *nexthops; -#endif /* ! WITH_POLICY */ - const ConnectionTable *connTable; - bool toInit; - unsigned int fwdPackets; -}; - -StrategyImpl *strategyLoadBalancerWithPD_Create() { - StrategyLoadBalancerWithPD *strategy = - parcMemory_AllocateAndClear(sizeof(StrategyLoadBalancerWithPD)); - parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL", - sizeof(StrategyLoadBalancerWithPD)); - - 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)); - parcAssertNotNull(impl, "parcMemory_AllocateAndClear(%zu) returned NULL", - sizeof(StrategyImpl)); - memcpy(impl, &_template, sizeof(StrategyImpl)); - impl->context = strategy; - strategy->connTable = NULL; - strategy->fwdPackets = 0; - strategy->toInit = true; - - return impl; -} - -void strategyLoadBalancerWithPD_SetConnectionTable(StrategyImpl *strategy, - ConnectionTable *connTable) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - lb->connTable = connTable; -} - -// ======================================================= -// Dispatch API - -strategy_type _strategyLoadBalancerWithPD_GetStrategy(StrategyImpl *strategy) { - return SET_STRATEGY_LOADBALANCER_WITH_DELAY; -} - -static void _update_Stats(StrategyLoadBalancerWithPD *strategy, - StrategyNexthopStateWithPD *state, bool inc, - Ticks rtt) { - const double ALPHA = 0.9; - double w = strategyNexthopStateWithPD_GetWeight(state); - strategy->weights_sum -= w; - w = strategyNexthopStateWithPD_UpdateState(state, inc, strategy->min_delay, - ALPHA); - 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++) { - unsigned nhop = numberSet_GetItem(strategy->nexthops, i); - Connection *conn = - (Connection *)connectionTable_FindById(strategy->connTable, nhop); - if (conn != NULL) { - 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); - } - } -} -#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) { - strategy->toInit = false; - strategy->fwdPackets = 0; - _sendProbes(strategy); - } - 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; -} -#endif /* WITH_POLICY */ - -static void _strategyLoadBalancerWithPD_ReceiveObject( - StrategyImpl *strategy, const NumberSet *egressId, - const Message *objectMessage, Ticks rtt) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - - for (unsigned i = 0; i < numberSet_Length(egressId); i++) { - unsigned outId = numberSet_GetItem(egressId, i); - PARCUnsigned *cid = parcUnsigned_Create(outId); - - const StrategyNexthopStateWithPD *state = - parcHashMap_Get(lb->strategy_state, cid); - if (state != NULL) { - _update_Stats(lb, (StrategyNexthopStateWithPD *)state, false, 0); - } else { - // this may happen if we remove a face/route while downloading a file - // we should ignore this timeout - } - parcUnsigned_Release(&cid); - } -} - -static void _strategyLoadBalancerWithPD_OnTimeout(StrategyImpl *strategy, - const NumberSet *egressId) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - - for (unsigned i = 0; i < numberSet_Length(egressId); i++) { - unsigned outId = numberSet_GetItem(egressId, i); - PARCUnsigned *cid = parcUnsigned_Create(outId); - - const StrategyNexthopStateWithPD *state = - parcHashMap_Get(lb->strategy_state, cid); - if (state != NULL) { - _update_Stats(lb, (StrategyNexthopStateWithPD *)state, false, 0); - } else { - // this may happen if we remove a face/route while downloading a file - // we should ignore this timeout - } - parcUnsigned_Release(&cid); - } -} - -// ATTENTION!! This interface force us to create a NumberSet which need to be -// delited somewhere The specification in the interface requires that this -// function never returns NULL. in case we have no output face we need to return -// an empty NumberSet -static NumberSet *_strategyLoadBalancerWithPD_LookupNexthop( - StrategyImpl *strategy, -#ifdef WITH_POLICY - NumberSet * nexthops, -#endif - const Message *interestMessage) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - - 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))) { - // there are no output faces or the input face is also the only output face. - // return null to avoid loops - parcUnsigned_Release(&in); - return outList; - } - - 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); - - const StrategyNexthopStateWithPD *state = - parcHashMap_Get(lb->strategy_state, out); - if (state == NULL) { - // this is an error and should not happen! - parcTrapNotImplemented( - "Try to send an interest on a face that does not exists"); - } - - _update_Stats(lb, (StrategyNexthopStateWithPD *)state, true, 0); - - parcUnsigned_Release(&in); - parcUnsigned_Release(&out); - - numberSet_Add(outList, out_connection); - return outList; -} - -#ifndef WITH_POLICY -static NumberSet *_strategyLoadBalancerWithPD_ReturnNexthops( - StrategyImpl *strategy) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - return lb->nexthops; -} - -unsigned _strategyLoadBalancerWithPD_CountNexthops(StrategyImpl *strategy) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - return (unsigned)numberSet_Length(lb->nexthops); -} -#endif /* WITH_POLICY */ - -static void _strategyLoadBalancerWithPD_resetState(StrategyImpl *strategy) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - lb->weights_sum = 0.0; - lb->min_delay = INT_MAX; - lb->toInit = true; - PARCIterator *it = parcHashMap_CreateKeyIterator(lb->strategy_state); - - while (parcIterator_HasNext(it)) { - PARCUnsigned *cid = parcIterator_Next(it); - StrategyNexthopStateWithPD *elem = - (StrategyNexthopStateWithPD *)parcHashMap_Get(lb->strategy_state, cid); - - strategyNexthopStateWithPD_Reset(elem); - lb->weights_sum += strategyNexthopStateWithPD_GetWeight(elem); - } - - parcIterator_Release(&it); -} - -static void _strategyLoadBalancerWithPD_AddNexthop(StrategyImpl *strategy, - unsigned connectionId) { - StrategyNexthopStateWithPD *state = strategyNexthopStateWithPD_Create(); - - PARCUnsigned *cid = parcUnsigned_Create(connectionId); - - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - - 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); - } -} - -static void _strategyLoadBalancerWithPD_RemoveNexthop(StrategyImpl *strategy, - unsigned connectionId) { - StrategyLoadBalancerWithPD *lb = - (StrategyLoadBalancerWithPD *)strategy->context; - - PARCUnsigned *cid = parcUnsigned_Create(connectionId); - - 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); - } - - parcUnsigned_Release(&cid); -} - -static void _strategyLoadBalancerWithPD_ImplDestroy( - StrategyImpl **strategyPtr) { - parcAssertNotNull(strategyPtr, "Parameter must be non-null double pointer"); - parcAssertNotNull(*strategyPtr, - "Parameter must dereference to non-null pointer"); - - StrategyImpl *impl = *strategyPtr; - StrategyLoadBalancerWithPD *strategy = - (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); - *strategyPtr = NULL; -} diff --git a/hicn-light/src/hicn/strategies/loadBalancerWithPD.h b/hicn-light/src/hicn/strategies/loadBalancerWithPD.h deleted file mode 100644 index a6ad94ab8..000000000 --- a/hicn-light/src/hicn/strategies/loadBalancerWithPD.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -/** - * Forward on the less loaded path taking into account the propagation delay of - * the first hop - */ - -#ifndef loadBalancerWithPD_h -#define loadBalancerWithPD_h - -#include <hicn/strategies/strategyImpl.h> -#include <hicn/core/connectionTable.h> - -StrategyImpl *strategyLoadBalancerWithPD_Create(); - -void strategyLoadBalancerWithPD_SetConnectionTable(StrategyImpl *strategy, - ConnectionTable *connTable); -#endif // loadBalancerWithPD_h diff --git a/hicn-light/src/hicn/strategies/lowLatency.c b/hicn-light/src/hicn/strategies/lowLatency.c new file mode 100644 index 000000000..a96b7b0af --- /dev/null +++ b/hicn-light/src/hicn/strategies/lowLatency.c @@ -0,0 +1,765 @@ +/* + * 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. + */ + +#include <hicn/hicn-light/config.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include <math.h> + +#include <parc/assert/parc_Assert.h> + +#include <parc/algol/parc_HashMap.h> +#include <parc/algol/parc_Memory.h> +#include <parc/algol/parc_Object.h> +#include <parc/algol/parc_Unsigned.h> + +#include <hicn/core/messageHandler.h> + +#include <hicn/strategies/lowLatency.h> +#include <hicn/strategies/nexthopStateLowLatency.h> +#include <hicn/processor/fibEntry.h> + +const unsigned STABILITY_FACTOR = 15; +const unsigned MAX_SWITCH_TRY = 10; +const unsigned MAX_LATENCY_DIFF = 10; +const unsigned MAX_TOLLERATED_LATENCY_DIFF = 15; +const unsigned MAX_ROUNDS_MP_WITHOUT_CHECK = 2; +const unsigned MAX_ROUNDS_AVOIDING_MULTIPATH = 40; //about 20 sec +const unsigned MAX_ROUNDS_WITH_ERROR = 4; +const unsigned PROBE_LIFETIME = 500; //ms + +static void _strategyLowLatency_ReceiveObject(StrategyImpl *strategy, + const NumberSet *egressId, + const Message *objectMessage, + Ticks pitEntryCreation, + Ticks objReception); +static void _strategyLowLatency_OnTimeout(StrategyImpl *strategy, + const NumberSet *egressId); +static NumberSet *_strategyLowLatency_LookupNexthop( + StrategyImpl *strategy, +#ifdef WITH_POLICY + NumberSet * nexthops, +#endif /* WITH_POLICY */ + const Message *interestMessage); +#ifndef WITH_POLICY +static NumberSet *_strategyLowLatency_ReturnNexthops(StrategyImpl *strategy); +static unsigned _strategyLowLatency_CountNexthops(StrategyImpl *strategy); +#endif /* ! WITH_POLICY */ +static void _strategyLowLatency_AddNexthop(StrategyImpl *strategy, + unsigned connectionId); +static void _strategyLowLatency_RemoveNexthop(StrategyImpl *strategy, + unsigned connectionId); +static void _strategyLowLatency_ImplDestroy(StrategyImpl **strategyPtr); +static strategy_type _strategyLowLatency_GetStrategy(StrategyImpl *strategy); + +static StrategyImpl _template = { + .context = NULL, + .receiveObject = &_strategyLowLatency_ReceiveObject, + .onTimeout = &_strategyLowLatency_OnTimeout, + .lookupNexthop = &_strategyLowLatency_LookupNexthop, +#ifndef WITH_POLICY + .returnNexthops = &_strategyLowLatency_ReturnNexthops, + .countNexthops = &_strategyLowLatency_CountNexthops, +#endif /* ! WITH_POLICY */ + .addNexthop = &_strategyLowLatency_AddNexthop, + .removeNexthop = &_strategyLowLatency_RemoveNexthop, + .destroy = &_strategyLowLatency_ImplDestroy, + .getStrategy = &_strategyLowLatency_GetStrategy, +}; + +struct strategy_low_latency; +typedef struct strategy_low_latency StrategyLowLatency; + +struct strategy_low_latency { + // hash map from connectionId to StrategyNexthopStateLL + PARCHashMap *strategy_state; + //hash map from sequence number to ticks (sent time) + PARCHashMap *pending_probes_ticks; + //hash map from sequence number to face id + PARCHashMap *pending_probes_faces; + const Forwarder * forwarder; + const FibEntry * fibEntry; + PARCEventTimer *sendProbes; + PARCEventTimer *computeBestFace; + uint8_t * probe; + hicn_name_t * name; + StrategyNexthopStateLL * bestFaces[2]; + unsigned round; + unsigned rounds_in_multipath; + unsigned rounds_with_error; + unsigned rounds_avoiding_multipath; + bool use2paths; + bool avoid_multipath; +#ifndef WITH_POLICY + NumberSet *nexthops; +#endif /* ! WITH_POLICY */ +}; + +static void strategyLowLatency_SendProbesCB(int fd, PARCEventType which_event, + void *data){ + parcAssertTrue(which_event & PARCEventType_Timeout, + "Event incorrect, expecting %X set, got %X", + PARCEventType_Timeout, which_event); + + StrategyLowLatency *ll = (StrategyLowLatency *) data; + + //delete old pending probes + if(parcHashMap_Size(ll->pending_probes_ticks) != 0){ + Ticks now = forwarder_GetTicks(ll->forwarder); + PARCIterator *iterator = parcHashMap_CreateKeyIterator(ll->pending_probes_ticks); + NumberSet *to_remove = numberSet_Create(); + while(parcIterator_HasNext(iterator)) { + PARCUnsigned *parc_seq = (PARCUnsigned *) parcIterator_Next(iterator); + PARCUnsigned *parc_time = (PARCUnsigned *) parcHashMap_Get(ll->pending_probes_ticks, parc_seq); + Ticks sent_time = parcUnsigned_GetUnsigned(parc_time); + if((now - sent_time) > PROBE_LIFETIME){ + //probes to delete + numberSet_Add(to_remove, parcUnsigned_GetUnsigned(parc_seq)); + } + } + parcIterator_Release(&iterator); + + for(int i = 0; i < numberSet_Length(to_remove); i++){ + PARCUnsigned *prob_seq = parcUnsigned_Create(numberSet_GetItem(to_remove,i)); + PARCUnsigned *cid = (PARCUnsigned *) parcHashMap_Get(ll->pending_probes_faces, prob_seq); + StrategyNexthopStateLL *state = + (StrategyNexthopStateLL *) parcHashMap_Get(ll->strategy_state, cid); + strategyNexthopStateLL_LostProbe(state); + parcHashMap_Remove(ll->pending_probes_ticks, prob_seq); + parcHashMap_Remove(ll->pending_probes_faces, prob_seq); + parcUnsigned_Release(&prob_seq); + } + numberSet_Release(&to_remove); + } + + ConnectionTable * ct = forwarder_GetConnectionTable(ll->forwarder); + + PARCIterator *iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + while(parcIterator_HasNext(iterator)){ + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + Connection *conn = + (Connection *)connectionTable_FindById(ct, + parcUnsigned_GetUnsigned(cid)); + if(!conn) + continue; + + StrategyNexthopStateLL *state = + (StrategyNexthopStateLL *) parcHashMap_Get(ll->strategy_state, cid); + + //probe only usable paths + if(!strategyNexthopStateLL_IsAllowed(state)) + continue; + + uint32_t seq = rand(); + messageHandler_SetProbeName(ll->probe, HF_INET6_TCP, + ll->name, seq); + connection_Probe(conn, ll->probe); + + PARCUnsigned *parc_seq = parcUnsigned_Create(seq); + Ticks now = forwarder_GetTicks(ll->forwarder); + PARCUnsigned *parc_time = parcUnsigned_Create(now); + parcHashMap_Put(ll->pending_probes_ticks, parc_seq, parc_time); + parcHashMap_Put(ll->pending_probes_faces, parc_seq, cid); + strategyNexthopStateLL_SentProbe(state); + parcUnsigned_Release(&parc_seq); + parcUnsigned_Release(&parc_time); + } + parcIterator_Release(&iterator); + + struct timeval timeout = {0,50000}; + parcEventTimer_Start(ll->sendProbes, &timeout); +} + +static void strategyLowLatency_SelectBestFaces(StrategyLowLatency *ll, + bool new_round){ + + if(new_round){ + ll->round++; + } + + if(parcHashMap_Size(ll->strategy_state) == 0){ + ll->bestFaces[0] = NULL; + ll->bestFaces[1] = NULL; + ll->use2paths = false; + goto NEW_ROUND; + } + + if(ll->use2paths && ll->bestFaces[0] != NULL && ll->bestFaces[1] != NULL){ + //multipath case + + if(!strategyNexthopStateLL_IsLossy(ll->bestFaces[0]) + && !strategyNexthopStateLL_IsLossy(ll->bestFaces[1]) + && strategyNexthopStateLL_IsAllowed(ll->bestFaces[0]) + && strategyNexthopStateLL_IsAllowed(ll->bestFaces[1])){ + + if(ll->rounds_in_multipath < MAX_ROUNDS_MP_WITHOUT_CHECK){ + //we are at the first rounds of the multipath let's wait a bit + //(MAX_ROUNDS_MP_WITHOUT_CHECK) to make the queuing converge + ll->rounds_in_multipath++; + goto NEW_ROUND; + } + + //we need to decide if we want ot keep using two paths or not + ll->rounds_in_multipath++; + double rtt0 = strategyNexthopStateLL_GetRTTLive(ll->bestFaces[0]); + double rtt1 = strategyNexthopStateLL_GetRTTLive(ll->bestFaces[1]); + double diff = fabs(rtt0 - rtt1); + + if(diff < MAX_LATENCY_DIFF){ + //everything is working, keep using the two paths + ll->rounds_with_error = 0; + goto NEW_ROUND; + } + + //check for how many rounds we had problems + if(ll->rounds_with_error < MAX_ROUNDS_WITH_ERROR && + diff < MAX_TOLLERATED_LATENCY_DIFF){ + //we can tollerate few round with errors + ll->rounds_with_error++; + goto NEW_ROUND; + } + + //prevent the usage of multiple paths + ll->rounds_with_error = 0; + ll->avoid_multipath = true; + ll->rounds_avoiding_multipath = 0; + } //else + //at least one of the two path is lossy + //or it is not allowed by the policies. + //search for a better possibility + } + + ll->bestFaces[0] = NULL; + ll->bestFaces[1] = NULL; + + //check if there is at least one non lossy connection + PARCIterator *iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + bool check_losses = true; + bool found_good_face = false; + while(parcIterator_HasNext(iterator) && !found_good_face){ + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + const StrategyNexthopStateLL *state = parcHashMap_Get(ll->strategy_state, cid); + if(!strategyNexthopStateLL_IsLossy(state) && + strategyNexthopStateLL_IsAllowed(state)){ + found_good_face = true; + } + } + parcIterator_Release(&iterator); + if(!found_good_face){ + // all the available faces are lossy, so we take into account only + // the latency computed with the probes + check_losses = false; + } + + if(ll->bestFaces[0] == NULL){ + //try to take a random face + PARCIterator *iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + bool face_found = false; + while(parcIterator_HasNext(iterator) && !face_found) { + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + StrategyNexthopStateLL *state = (StrategyNexthopStateLL *) + parcHashMap_Get(ll->strategy_state, cid); + + if((check_losses && strategyNexthopStateLL_IsLossy(state)) || + !strategyNexthopStateLL_IsAllowed(state)){ + //skip the face + continue; + } + + ll->bestFaces[0] = state; + face_found = true; + } + parcIterator_Release(&iterator); + } + + if(ll->bestFaces[0] == NULL){ + //no usable face exists + ll->bestFaces[0] = NULL; + ll->bestFaces[1] = NULL; + ll->use2paths = false; + goto NEW_ROUND; + } + + double bestRtt = strategyNexthopStateLL_GetRTTLive(ll->bestFaces[0]); + + if(ll->avoid_multipath) + ll->rounds_avoiding_multipath++; + + if(ll->rounds_avoiding_multipath > MAX_ROUNDS_AVOIDING_MULTIPATH){ + ll->avoid_multipath = false; + ll->rounds_avoiding_multipath = 0; + } + + iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + while (parcIterator_HasNext(iterator)) { + + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + StrategyNexthopStateLL *state = (StrategyNexthopStateLL *) + parcHashMap_Get(ll->strategy_state, cid); + double rtt = strategyNexthopStateLL_GetRTTLive(state); + + if((check_losses && strategyNexthopStateLL_IsLossy(state)) || + !strategyNexthopStateLL_IsAllowed(state)){ + //skip the face + continue; + } + + if(rtt + STABILITY_FACTOR < bestRtt){ + //maybe we found a better face + double rttInUse = strategyNexthopStateLL_GetRTTInUse(state); + unsigned try = strategyNexthopStateLL_GetTryToSwitch(state); + + //we check the rtt in use to check if the new face that we found + //gets congested when we use it to send the traffic + if(rttInUse < bestRtt || try > MAX_SWITCH_TRY){ + //we have a new best face! + strategyNexthopStateLL_ResetTryToSwitch((StrategyNexthopStateLL*) state); + bestRtt = rtt; + if(ll->bestFaces[0] != NULL) + strategyNexthopStateLL_SetUnusedFace(ll->bestFaces[0]); + ll->bestFaces[0] = (StrategyNexthopStateLL*) state; + }else{ + //in this case we should switch but we wait MAX_SWITCH_TRY + //before switch to avoid ossillations between different paths + strategyNexthopStateLL_IncreaseTryToSwitch( + (StrategyNexthopStateLL*) state, ll->round); + } + } + } + + parcIterator_Release(&iterator); + + if(ll->bestFaces[0] == NULL){ + //we found no face so return + ll->bestFaces[0] = NULL; + ll->bestFaces[1] = NULL; + ll->use2paths = false; + goto NEW_ROUND; + } + + if(parcHashMap_Size(ll->strategy_state) == 1 || ll->avoid_multipath){ + //in this case (one face available or avoid multipath) we stop the + //search here. Just reset face 1 if needed + if(ll->bestFaces[1] != NULL){ + strategyNexthopStateLL_SetUnusedFace(ll->bestFaces[1]); + ll->bestFaces[1] = NULL; + } + ll->use2paths = false; + goto NEW_ROUND; + } + + //if we are here we have more than 1 interface, so we search for a second one + //to use in case of multipath + iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + while (parcIterator_HasNext(iterator)) { + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + if(parcUnsigned_GetUnsigned(cid) != + strategyNexthopStateLL_GetFaceId(ll->bestFaces[0])){ + + StrategyNexthopStateLL *state = (StrategyNexthopStateLL *) + parcHashMap_Get(ll->strategy_state, cid); + + if((check_losses && strategyNexthopStateLL_IsLossy(state)) || + !strategyNexthopStateLL_IsAllowed(state)){ + //skip the face + continue; + } + + if(ll->bestFaces[1] == NULL){ + //in case of 2 faces we should pass always here + ll->bestFaces[1] = state; + }else{ + //TODO this must be tested with more then 2 faces + double rtt1 = strategyNexthopStateLL_GetRTTLive(ll->bestFaces[1]); + double rttNewFace = strategyNexthopStateLL_GetRTTLive(state); + if(rttNewFace + STABILITY_FACTOR < rtt1){ + strategyNexthopStateLL_SetUnusedFace(ll->bestFaces[1]); + ll->bestFaces[1] = state; + } + } + } + } + parcIterator_Release(&iterator); + + if(ll->bestFaces[1] != NULL){ + //we are not using the second face yet so we use the normal rtt for comparison + double rtt0 = strategyNexthopStateLL_GetRTTProbe(ll->bestFaces[0]); + double rtt1 = strategyNexthopStateLL_GetRTTProbe(ll->bestFaces[1]); + double diff = fabs(rtt0 - rtt1); + if(diff < MAX_LATENCY_DIFF) { + //let's start to use 2 paths + ll->rounds_with_error = 0; + ll->use2paths = true; + ll->rounds_in_multipath = 0; + }else{ + //we use only one path + strategyNexthopStateLL_SetUnusedFace(ll->bestFaces[1]); + ll->bestFaces[1] = NULL; + ll->use2paths = false; + } + }else{ + ll->use2paths = false; + } + + NEW_ROUND: +#if 1 + if(ll->use2paths){ + printf("use 2 paths. rtt face %d = %f queue = %f is_lossy = %d," + "rtt face %d = %f queue = %f is_lossy = %d\n", + strategyNexthopStateLL_GetFaceId(ll->bestFaces[0]), + strategyNexthopStateLL_GetRTTLive(ll->bestFaces[0]), + strategyNexthopStateLL_GetQueuing(ll->bestFaces[0]), + strategyNexthopStateLL_IsLossy(ll->bestFaces[0]), + strategyNexthopStateLL_GetFaceId(ll->bestFaces[1]), + strategyNexthopStateLL_GetRTTLive(ll->bestFaces[1]), + strategyNexthopStateLL_GetQueuing(ll->bestFaces[1]), + strategyNexthopStateLL_IsLossy(ll->bestFaces[1])); + }else{ + if(ll->bestFaces[0] != NULL){ + printf("use 1 path. rtt face %d = %f is_lossy = %d (avoid multipath = %d)\n", + strategyNexthopStateLL_GetFaceId(ll->bestFaces[0]), + strategyNexthopStateLL_GetRTTLive(ll->bestFaces[0]), + strategyNexthopStateLL_IsLossy(ll->bestFaces[0]), + ll->avoid_multipath); + }else{ + printf("no face to use!\n"); + } + } +#endif + //update the round only at the end for all the faces + if(new_round){ + PARCIterator * iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + while (parcIterator_HasNext(iterator)) { + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + strategyNexthopStateLL_StartNewRound((StrategyNexthopStateLL *) + parcHashMap_Get(ll->strategy_state, cid)); + } + parcIterator_Release(&iterator); + } +} + +static void strategyLowLatency_BestFaceCB(int fd, PARCEventType which_event, + void *data){ + parcAssertTrue(which_event & PARCEventType_Timeout, + "Event incorrect, expecting %X set, got %X", + PARCEventType_Timeout, which_event); + + StrategyLowLatency * ll = (StrategyLowLatency *) data; + strategyLowLatency_SelectBestFaces(ll, true); + + struct timeval timeout = {0, 500000}; + parcEventTimer_Start(ll->computeBestFace, &timeout); +} + +StrategyImpl *strategyLowLatency_Create() { + StrategyLowLatency *strategy = + parcMemory_AllocateAndClear(sizeof(StrategyLowLatency)); + parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL", + sizeof(StrategyLowLatency)); + + strategy->strategy_state = parcHashMap_Create(); + strategy->pending_probes_ticks = parcHashMap_Create(); + strategy->pending_probes_faces = parcHashMap_Create(); +#ifndef WITH_POLICY + strategy->nexthops = numberSet_Create(); +#endif /* ! WITH_POLICY */ + srand((unsigned int)time(NULL)); + + StrategyImpl *impl = parcMemory_AllocateAndClear(sizeof(StrategyImpl)); + parcAssertNotNull(impl, "parcMemory_AllocateAndClear(%zu) returned NULL", + sizeof(StrategyImpl)); + memcpy(impl, &_template, sizeof(StrategyImpl)); + impl->context = strategy; + + return impl; +} + +void strategyLowLatency_SetStrategy(StrategyImpl *strategy, + const Forwarder * forwarder, + const FibEntry * fibEntry){ + StrategyLowLatency *ll = + (StrategyLowLatency *)strategy->context; + ll->forwarder = forwarder; + ll->fibEntry = fibEntry; + + //create probe packet + ll->probe = messageHandler_CreateProbePacket(HF_INET6_TCP, PROBE_LIFETIME); + ip_prefix_t address; + nameBitvector_ToIPAddress(name_GetContentName( + fibEntry_GetPrefix(fibEntry)), &address); + ll->name = messageHandler_CreateProbeName(&address); + + + Dispatcher *dispatcher = forwarder_GetDispatcher((Forwarder *)ll->forwarder); + ll->sendProbes = dispatcher_CreateTimer(dispatcher, false, + strategyLowLatency_SendProbesCB, ll); + + ll->round = 0; + ll->rounds_in_multipath = 0; + ll->rounds_with_error = 0; + ll->rounds_avoiding_multipath = 0; + ll->use2paths = false; + ll->avoid_multipath = false; + + ll->computeBestFace = dispatcher_CreateTimer(dispatcher, false, + strategyLowLatency_BestFaceCB, ll); +} + +void _startTimers(StrategyImpl *strategy){ + StrategyLowLatency *ll = + (StrategyLowLatency *)strategy->context; + + struct timeval timeoutProbes = {0,10000}; + parcEventTimer_Start(ll->sendProbes, &timeoutProbes); + struct timeval timeoutBF = {1,0}; + parcEventTimer_Start(ll->computeBestFace, &timeoutBF); +} + +void _stopTimers(StrategyImpl *strategy){ + StrategyLowLatency *ll = + (StrategyLowLatency *)strategy->context; + + parcEventTimer_Stop(ll->sendProbes); + parcEventTimer_Stop(ll->computeBestFace); +} + +// ======================================================= +// Dispatch API + +strategy_type _strategyLowLatency_GetStrategy(StrategyImpl *strategy) { + return SET_STRATEGY_LOW_LATENCY; +} + +static void _strategyLowLatency_ReceiveObject(StrategyImpl *strategy, + const NumberSet *egressId, + const Message *objectMessage, + Ticks pitEntryCreation, + Ticks objReception) { + StrategyLowLatency *ll = (StrategyLowLatency *)strategy->context; + + if(!messageHandler_IsAProbe(message_FixedHeader(objectMessage))) + return; + + uint32_t seq = messageHandler_GetSegment(message_FixedHeader(objectMessage)); + PARCUnsigned *parc_seq = parcUnsigned_Create(seq); + if (!parcHashMap_Contains(ll->pending_probes_ticks, parc_seq)){ + parcUnsigned_Release(&parc_seq); + return; + } + + //here numberSet_Length(egressId) should be 1 + for (unsigned i = 0; i < numberSet_Length(egressId); i++) { + unsigned outId = numberSet_GetItem(egressId, i); + PARCUnsigned *cid = parcUnsigned_Create(outId); + + const StrategyNexthopStateLL *state = + parcHashMap_Get(ll->strategy_state, cid); + if (state != NULL) { + Ticks time = parcUnsigned_GetUnsigned( + parcHashMap_Get(ll->pending_probes_ticks, parc_seq)); + Ticks now = forwarder_GetTicks(ll->forwarder); + Ticks RTT = now - time; + if(RTT <= 0) + RTT = 1; + strategyNexthopStateLL_AddRttSample( + (StrategyNexthopStateLL *) state, RTT); + parcHashMap_Remove(ll->pending_probes_ticks, parc_seq); + } else { + // this may happen if we remove a face/route while downloading a file + // we should ignore this timeout + } + parcUnsigned_Release(&cid); + } + parcUnsigned_Release(&parc_seq); +} + +static void _strategyLowLatency_OnTimeout(StrategyImpl *strategy, + const NumberSet *egressId) {} + +static NumberSet *_strategyLowLatency_LookupNexthop(StrategyImpl *strategy, +#ifdef WITH_POLICY + NumberSet * nexthops, +#endif /* WITH_POLICY */ + const Message *interestMessage) { + //unsigned out_connection; + NumberSet *out = numberSet_Create(); + + StrategyLowLatency *ll = (StrategyLowLatency *)strategy->context; + + //update is_allowed flag of all the next hops + PARCIterator *iterator = parcHashMap_CreateKeyIterator(ll->strategy_state); + while(parcIterator_HasNext(iterator)){ + PARCUnsigned *cid = (PARCUnsigned *) parcIterator_Next(iterator); + StrategyNexthopStateLL *state = + (StrategyNexthopStateLL *) parcHashMap_Get(ll->strategy_state, cid); + if(numberSet_Contains(nexthops, parcUnsigned_GetUnsigned(cid))){ + strategyNexthopStateLL_SetIsAllowed(state,true); + }else{ + strategyNexthopStateLL_SetIsAllowed(state,false); + } + } + parcIterator_Release(&iterator); + + if(ll->bestFaces[0] != NULL && + !strategyNexthopStateLL_IsAllowed(ll->bestFaces[0])){ + //if ll->bestFaces[0] is not allowed we need to find a new face + strategyLowLatency_SelectBestFaces(ll, false); + } + + //at this point ll->bestFaces[0] must be allowed + //single path case + if(ll->bestFaces[0] != NULL && (ll->bestFaces[1] == NULL || !ll->use2paths)){ + strategyNexthopStateLL_SendPacket(ll->bestFaces[0]); + numberSet_Add(out, strategyNexthopStateLL_GetFaceId(ll->bestFaces[0])); + + //multipath case + }else if(ll->bestFaces[0] != NULL && ll->bestFaces[1] != NULL && ll->use2paths){ + //it may happen that ll->bestFaces[1] is not allowed, in that case we send on + //ll->bestFaces[0] until the next best face selection + if(!strategyNexthopStateLL_IsAllowed(ll->bestFaces[1])){ + strategyNexthopStateLL_SendPacket(ll->bestFaces[0]); + numberSet_Add(out, strategyNexthopStateLL_GetFaceId(ll->bestFaces[0])); + }else{ + double queue0 = strategyNexthopStateLL_GetQueuing(ll->bestFaces[0]); + double queue1 = strategyNexthopStateLL_GetQueuing(ll->bestFaces[1]); + double prob0 = 0.5; + if(queue0 > 1 || queue1 > 1){ + prob0 = 1.0 - (queue0 / (queue0 + queue1)); + } + double coin = ((double) rand() / (RAND_MAX)); + if(coin < prob0){ + strategyNexthopStateLL_SendPacket(ll->bestFaces[0]); + numberSet_Add(out, strategyNexthopStateLL_GetFaceId(ll->bestFaces[0])); + }else{ + strategyNexthopStateLL_SendPacket(ll->bestFaces[1]); + numberSet_Add(out, strategyNexthopStateLL_GetFaceId(ll->bestFaces[1])); + } + } + } + return out; +} + + +#ifndef WITH_POLICY +static NumberSet *_strategyLowLatency_ReturnNexthops(StrategyImpl *strategy) { + StrategyLoadBalancerLL *ll = (StrategyLoadBalancerLL *)strategy->context; + return ll->nexthops; +} + +unsigned _strategyLowLatency_CountNexthops(StrategyImpl *strategy) { + StrategyLoadBalancerLL *ll = (StrategyLoadBalancerLL *)strategy->context; + return (unsigned)numberSet_Length(ll->nexthops); +} +#endif /* ! WITH_POLICY */ + +static void _strategyLowLatency_AddNexthop(StrategyImpl *strategy, + unsigned connectionId) { + PARCUnsigned *cid = parcUnsigned_Create(connectionId); + + StrategyLowLatency *ll = (StrategyLowLatency *)strategy->context; + + if (!parcHashMap_Contains(ll->strategy_state, cid)) { + StrategyNexthopStateLL *state = strategyNexthopStateLL_Create(connectionId); + parcHashMap_Put(ll->strategy_state, cid, state); + if(ll->bestFaces[0] == NULL){ + ll->bestFaces[0] = state; + } +#ifndef WITH_POLICY + numberSet_Add(ll->nexthops, connectionId); +#endif /* WITH_POLICY */ + } + + if(parcHashMap_Size(ll->strategy_state) >= 2){ + _startTimers(strategy); + } + + parcUnsigned_Release(&cid); +} + +static void _strategyLowLatency_RemoveNexthop(StrategyImpl *strategy, + unsigned connectionId) { + StrategyLowLatency *ll = (StrategyLowLatency *)strategy->context; + + bool reset_bestFaces = false; + + if((ll->bestFaces[0] != NULL && + strategyNexthopStateLL_GetFaceId(ll->bestFaces[0]) == connectionId) || + (ll->bestFaces[1] != NULL && + strategyNexthopStateLL_GetFaceId(ll->bestFaces[1]) == connectionId)){ + reset_bestFaces = true; + } + + PARCUnsigned *cid = parcUnsigned_Create(connectionId); + + if (parcHashMap_Contains(ll->strategy_state, cid)) { + parcHashMap_Remove(ll->strategy_state, cid); +#ifndef WITH_POLICY + numberSet_Remove(lb->nexthops, connectionId); +#endif /* WITH_POLICY */ + } + + if(reset_bestFaces){ + ll->bestFaces[0] = NULL; + ll->bestFaces[1] = NULL; + strategyLowLatency_SelectBestFaces(ll, false); + } + + if(parcHashMap_Size(ll->strategy_state) < 2){ + _stopTimers(strategy); + } + + parcUnsigned_Release(&cid); +} + +static void _strategyLowLatency_ImplDestroy(StrategyImpl **strategyPtr) { + parcAssertNotNull(strategyPtr, "Parameter must be non-null double pointer"); + parcAssertNotNull(*strategyPtr, + "Parameter must dereference to non-null pointer"); + + StrategyImpl *impl = *strategyPtr; + StrategyLowLatency *strategy = (StrategyLowLatency *)impl->context; + + _stopTimers(impl); + + parcEventTimer_Destroy(&(strategy->sendProbes)); + parcEventTimer_Destroy(&(strategy->computeBestFace)); + + if (parcHashMap_Size(strategy->strategy_state) > 0) { + PARCIterator *it = parcHashMap_CreateKeyIterator(strategy->strategy_state); + while (parcIterator_HasNext(it)) { + PARCUnsigned *cid = parcIterator_Next(it); + StrategyNexthopStateLL *state = + (StrategyNexthopStateLL *)parcHashMap_Get(strategy->strategy_state, cid); + parcObject_Release((void**)&state); + } + parcIterator_Release(&it); + } + + parcHashMap_Release(&(strategy->strategy_state)); + parcHashMap_Release(&(strategy->pending_probes_ticks)); + parcHashMap_Release(&(strategy->pending_probes_faces)); + + parcMemory_Deallocate(&(strategy->probe)); + parcMemory_Deallocate(&(strategy->name)); +#ifndef WITH_POLICY + numberSet_Release(&(strategy->nexthops)); +#endif /* ! WITH_POLICY */ + + parcMemory_Deallocate((void **)&strategy); + parcMemory_Deallocate((void **)&impl); + *strategyPtr = NULL; +} diff --git a/hicn-light/src/hicn/strategies/rndSegment.h b/hicn-light/src/hicn/strategies/lowLatency.h index 6694f03e5..f82a576f1 100644 --- a/hicn-light/src/hicn/strategies/rndSegment.h +++ b/hicn-light/src/hicn/strategies/lowLatency.h @@ -14,15 +14,18 @@ */ /** - * Forward randomly, selects a path every time the client ask for a new dash - * segment + * Forward on the path with lowest latency */ -#ifndef rnd_Segment_h -#define rnd_Segment_h +#ifndef lowLatency_h +#define lowLatency_h #include <hicn/strategies/strategyImpl.h> +#include <hicn/core/forwarder.h> -StrategyImpl *strategyRndSegment_Create(); +StrategyImpl *strategyLowLatency_Create(); -#endif // rnd_Segment_h +void strategyLowLatency_SetStrategy(StrategyImpl *strategy, + const Forwarder * forwarder, + const FibEntry * fibEntry); +#endif // lowLatency_h diff --git a/hicn-light/src/hicn/strategies/nexthopStateLowLatency.c b/hicn-light/src/hicn/strategies/nexthopStateLowLatency.c new file mode 100644 index 000000000..fd83bb072 --- /dev/null +++ b/hicn-light/src/hicn/strategies/nexthopStateLowLatency.c @@ -0,0 +1,481 @@ +/* + * 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. + */ + +#include <hicn/hicn-light/config.h> +#include <stdio.h> +#include <float.h> + +#include <parc/algol/parc_DisplayIndented.h> +#include <parc/algol/parc_Memory.h> +#include <parc/algol/parc_Object.h> + +#include <parc/assert/parc_Assert.h> +#include <hicn/strategies/nexthopStateLowLatency.h> + +const unsigned MAX_ROUNS_WITHOUT_PROBES = 4; + //if we do not receives probes for 4 rounds it means + //that we had no responce from any producer for 2 sec + //we can say that this interface is daed +const unsigned MIN_NON_LOSSY_ROUNDS = 10; + //number of rounds in non lossy mode before switch to + //no lossy state +const double MAX_LOSS_RATE = 0.15; //15% + +struct strategy_nexthop_state_ll { + bool in_use; + bool is_allowed; // the policy may not allow the use of this face + unsigned face_id; + unsigned sent_packets; + //switch metrics + unsigned last_try_to_switch_round; + unsigned try_to_switch_counter; + //probes counters + unsigned recevied_probes; + unsigned rounds_without_probes; + unsigned sent_probes; + unsigned lost_probes; + unsigned non_lossy_rounds; + //avgs + double avg_rtt; + double avg_rtt_in_use; + double avg_queue; + double avg_loss_rate; + +}; + +static bool _strategyNexthopStateLL_Destructor( + StrategyNexthopStateLL **instancePtr) { + return true; +} + +parcObject_ImplementAcquire(strategyNexthopStateLL, StrategyNexthopStateLL); + +parcObject_ImplementRelease(strategyNexthopStateLL, StrategyNexthopStateLL); + +parcObject_Override( + StrategyNexthopStateLL, PARCObject, + .destructor = (PARCObjectDestructor *)_strategyNexthopStateLL_Destructor, + .copy = (PARCObjectCopy *)strategyNexthopStateLL_Copy, + .display = (PARCObjectDisplay *)strategyNexthopStateLL_Display, + .toString = (PARCObjectToString *)strategyNexthopStateLL_ToString, + .equals = (PARCObjectEquals *)strategyNexthopStateLL_Equals, + .compare = (PARCObjectCompare *)strategyNexthopStateLL_Compare, + .hashCode = (PARCObjectHashCode *)strategyNexthopStateLL_HashCode, + .display = (PARCObjectDisplay *)strategyNexthopStateLL_Display); + +void strategyNexthopStateLL_AssertValid(const StrategyNexthopStateLL *instance) { + parcAssertTrue(strategyNexthopStateLL_IsValid(instance), + "StrategyNexthopState is not valid."); +} + +StrategyNexthopStateLL *strategyNexthopStateLL_Create(unsigned face_id) { + StrategyNexthopStateLL *result = + parcObject_CreateInstance(StrategyNexthopStateLL); + if (result != NULL) { + result->in_use = false; + result->is_allowed = true; + result->face_id = face_id; + result->sent_packets = 0; + result->last_try_to_switch_round = 0; + result->try_to_switch_counter = 0; + result->recevied_probes = 0; + result->rounds_without_probes = 0; + result->sent_probes = 0; + result->lost_probes = 0; + result->non_lossy_rounds = MIN_NON_LOSSY_ROUNDS; + result->avg_rtt = -1.0; + result->avg_rtt_in_use = -1.0; + result->avg_queue = 0.0001; + result->avg_loss_rate = 0.0; + } + return result; +} + +void strategyNexthopStateLL_Reset(StrategyNexthopStateLL *x) { + x->in_use = false; + x->is_allowed = true; + x->sent_packets = 0; + x->last_try_to_switch_round = 0; + x->try_to_switch_counter = 0; + x->recevied_probes = 0; + x->rounds_without_probes = 0; + x->sent_probes = 0; + x->lost_probes = 0; + x->non_lossy_rounds = MIN_NON_LOSSY_ROUNDS; + x->avg_rtt = -1.0; + x->avg_rtt_in_use = -1.0; + x->avg_queue = 0.0001; + x->avg_loss_rate = 0.0; +} + + +int strategyNexthopStateLL_Compare(const StrategyNexthopStateLL *val, + const StrategyNexthopStateLL *other) { + if (val == NULL) { + if (other != NULL) { + return -1; + } + } else if (other == NULL) { + return 1; + } else { + strategyNexthopStateLL_OptionalAssertValid(val); + strategyNexthopStateLL_OptionalAssertValid(other); + + if (val->in_use < other->in_use){ + return -1; + }else if (val->in_use > other->in_use){ + return 1; + } + + if (val->is_allowed < other->is_allowed){ + return -1; + }else if (val->is_allowed> other->is_allowed){ + return 1; + } + + if (val->face_id < other->face_id) { + return -1; + } else if (val->face_id > other->face_id) { + return 1; + } + + if (val->sent_packets < other->sent_packets){ + return -1; + } else if (val->sent_packets > other->sent_packets){ + return 1; + } + + if (val->last_try_to_switch_round < + other->last_try_to_switch_round) { + return -1; + } else if (val->last_try_to_switch_round > + other->last_try_to_switch_round) { + return 1; + } + + if (val->try_to_switch_counter < + other->try_to_switch_counter) { + return -1; + } else if (val->try_to_switch_counter > + other->try_to_switch_counter) { + return 1; + } + + if (val->recevied_probes < other->recevied_probes) { + return -1; + } else if (val->recevied_probes > other->recevied_probes) { + return 1; + } + + if (val->rounds_without_probes < other->rounds_without_probes) { + return -1; + } else if (val->rounds_without_probes > other->rounds_without_probes) { + return 1; + } + + if (val->sent_probes < other->sent_probes) { + return -1; + } else if (val->sent_probes > other->sent_probes) { + return 1; + } + + if (val->lost_probes < other->lost_probes) { + return -1; + } else if (val->lost_probes > other->lost_probes) { + return 1; + } + + if (val->non_lossy_rounds < other->non_lossy_rounds) { + return -1; + } else if (val->non_lossy_rounds > other->non_lossy_rounds) { + return 1; + } + + if (val->avg_rtt < other->avg_rtt) { + return -1; + } else if (val->avg_rtt > other->avg_rtt) { + return 1; + } + + if (val->avg_rtt_in_use < other->avg_rtt_in_use) { + return -1; + } else if (val->avg_rtt_in_use > other->avg_rtt_in_use) { + return 1; + } + + if (val->avg_queue < other->avg_queue) { + return -1; + } else if (val->avg_queue > other->avg_queue) { + return 1; + } + + if (val->avg_loss_rate < other->avg_loss_rate) { + return -1; + } else if (val->avg_loss_rate > other->avg_loss_rate) { + return 1; + } + } + + return 0; +} + +StrategyNexthopStateLL *strategyNexthopStateLL_Copy( + const StrategyNexthopStateLL *original) { + StrategyNexthopStateLL *result = strategyNexthopStateLL_Create(original->face_id); + result->in_use = original->in_use; + result->is_allowed = original->is_allowed; + result->sent_packets = original->sent_packets; + result->last_try_to_switch_round = original->last_try_to_switch_round; + result->try_to_switch_counter = original->try_to_switch_counter; + result->recevied_probes = original->recevied_probes; + result->rounds_without_probes = original->rounds_without_probes; + result->sent_probes = original->sent_probes; + result->lost_probes = original->lost_probes; + result->non_lossy_rounds = original->non_lossy_rounds; + result->avg_rtt = original->avg_rtt; + result->avg_rtt_in_use = original->avg_rtt_in_use; + result->avg_queue = original->avg_queue; + result->avg_loss_rate = original->avg_loss_rate; + return result; +} + +void strategyNexthopStateLL_Display(const StrategyNexthopStateLL *instance, + int indentation) { + parcDisplayIndented_PrintLine(indentation, "StrategyNexthopStateLL@%p {", + instance); + parcDisplayIndented_PrintLine(indentation + 1, "%d", instance->face_id); + parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->avg_rtt); + parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->avg_rtt_in_use); + parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->avg_queue); + parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->avg_loss_rate); + parcDisplayIndented_PrintLine(indentation, "}"); +} + + +bool strategyNexthopStateLL_Equals(const StrategyNexthopStateLL *x, + const StrategyNexthopStateLL *y) { + bool result = false; + + if (x == y) { + result = true; + } else if (x == NULL || y == NULL) { + result = false; + } else { + strategyNexthopStateLL_OptionalAssertValid(x); + strategyNexthopStateLL_OptionalAssertValid(y); + + if (strategyNexthopStateLL_Compare(x, y) == 0) { + result = true; + } + } + + return result; +} + +PARCHashCode strategyNexthopStateLL_HashCode(const StrategyNexthopStateLL *x) { + PARCHashCode result = 0; + char str[128]; + sprintf(str, "ID:%d: RTT:%f: RTTUSE:%f: Q:%f L:%f", x->face_id, x->avg_rtt, + x->avg_rtt_in_use, x->avg_queue, x->avg_loss_rate); + result = parcHashCode_Hash((uint8_t *)&str, strlen(str)); + return result; +} + +bool strategyNexthopStateLL_IsValid(const StrategyNexthopStateLL *x) { + bool result = false; + + if (x != NULL) { + result = true; + } + + return result; +} + +char *strategyNexthopStateLL_ToString(const StrategyNexthopStateLL *x) { + // this is not implemented + parcTrapNotImplemented("strategyNexthopStateLL_ToString is not implemented"); + return NULL; +} + +double strategyNexthopStateLL_GetRTTProbe(StrategyNexthopStateLL *x) { + strategyNexthopStateLL_OptionalAssertValid(x); + + if(x->rounds_without_probes > MAX_ROUNS_WITHOUT_PROBES) + return DBL_MAX; + + if(x->avg_rtt == -1.0){ + if(x->avg_rtt_in_use == -1.0){ + return 0.0; + }else{ + //this happens if the face recevied probes only in in_use mode + //we set the avf_rtt with rtt_in_use + x->avg_rtt = x->avg_rtt_in_use; + } + } + + return x->avg_rtt; +} + +double strategyNexthopStateLL_GetRTTInUse(StrategyNexthopStateLL *x) { + strategyNexthopStateLL_OptionalAssertValid(x); + + if(x->rounds_without_probes > MAX_ROUNS_WITHOUT_PROBES) + return DBL_MAX; + + if(x->avg_rtt_in_use == -1.0) + return strategyNexthopStateLL_GetRTTProbe(x); + + return x->avg_rtt_in_use; +} + +double strategyNexthopStateLL_GetRTTLive(StrategyNexthopStateLL *x) { + strategyNexthopStateLL_OptionalAssertValid(x); + + if(x->in_use){ + return strategyNexthopStateLL_GetRTTInUse(x); + }else{ + return strategyNexthopStateLL_GetRTTProbe(x); + } +} + +double strategyNexthopStateLL_GetQueuing(const StrategyNexthopStateLL *x) { + strategyNexthopStateLL_OptionalAssertValid(x); + + if(x->rounds_without_probes > MAX_ROUNS_WITHOUT_PROBES) + return 0.0; + + return x->avg_queue; +} + +void strategyNexthopStateLL_AddRttSample(StrategyNexthopStateLL *x, + unsigned int rtt){ + strategyNexthopStateLL_OptionalAssertValid(x); + + x->recevied_probes++; + //form uint to double + double drtt = rtt; + + if(x->in_use){ + if(x->avg_rtt_in_use == -1.0){ + x->avg_rtt_in_use = drtt; + }else{ + x->avg_rtt_in_use = (x->avg_rtt_in_use * 0.9) + (drtt * 0.1); + } + }else{ + if(x->avg_rtt == -1.0){ + x->avg_rtt = drtt; + }else{ + x->avg_rtt = (x->avg_rtt * 0.9) + (drtt * 0.1); + } + } + + if(x->avg_rtt_in_use == -1.0 || x->avg_rtt == -1.0){ + x->avg_queue = 0.0001; + }else{ + double queue = x->avg_rtt_in_use - x->avg_rtt; + if(queue < 0){ + queue = 0.0001; + } + x->avg_queue = (x->avg_queue * 0.95) + (0.05 * queue); + } +} + +void strategyNexthopStateLL_SetUnusedFace(StrategyNexthopStateLL *x){ + strategyNexthopStateLL_OptionalAssertValid(x); + x->in_use = false; +} + +unsigned strategyNexthopStateLL_GetFaceId(StrategyNexthopStateLL *x) { + strategyNexthopStateLL_OptionalAssertValid(x); + return x->face_id; +} + +void strategyNexthopStateLL_IncreaseTryToSwitch(StrategyNexthopStateLL *x, + unsigned round){ + if(x->try_to_switch_counter == 0 || + round == (x->last_try_to_switch_round + 1)){ + x->last_try_to_switch_round = round; + x->try_to_switch_counter++; + }else{ + x->try_to_switch_counter = 0; + } +} + +unsigned strategyNexthopStateLL_GetTryToSwitch(const StrategyNexthopStateLL *x){ + return x->try_to_switch_counter; +} + +void strategyNexthopStateLL_ResetTryToSwitch(StrategyNexthopStateLL *x){ + x->try_to_switch_counter = 0; +} + +void strategyNexthopStateLL_SendPacket(StrategyNexthopStateLL *x){ + x->in_use = true; + x->sent_packets++; +} + +void strategyNexthopStateLL_SentProbe(StrategyNexthopStateLL *x){ + x->sent_probes++; +} + +void strategyNexthopStateLL_LostProbe(StrategyNexthopStateLL *x){ + x->lost_probes++; +} + +bool strategyNexthopStateLL_IsLossy(const StrategyNexthopStateLL *x){ + if(x->non_lossy_rounds < 10 || + x->avg_loss_rate > MAX_LOSS_RATE){ + return true; + } + return false; +} + +void strategyNexthopStateLL_SetIsAllowed(StrategyNexthopStateLL *x, bool allowed){ + x->is_allowed = allowed; +} + +bool strategyNexthopStateLL_IsAllowed(const StrategyNexthopStateLL *x){ + return x->is_allowed; +} + +void strategyNexthopStateLL_StartNewRound(StrategyNexthopStateLL *x){ + strategyNexthopStateLL_OptionalAssertValid(x); + if(x->sent_packets == 0) //the face was not used in the last round + x->in_use = false; + + x->sent_packets = 0; + + if(x->recevied_probes == 0){ + x->rounds_without_probes++; + }else{ + x->rounds_without_probes = 0; + } + + x->recevied_probes = 0; + + //compute losses in this round + if(x->sent_probes != 0){ + double loss_rate = (double) x->lost_probes / (double) x->sent_probes; + x->avg_loss_rate = x->avg_loss_rate * 0.7 + loss_rate * 0.3; + if(x->avg_loss_rate > MAX_LOSS_RATE){ + x->non_lossy_rounds = 0; + }else{ + x->non_lossy_rounds++; + } + } + + x->lost_probes = 0; + x->sent_probes = 0; +} diff --git a/hicn-light/src/hicn/strategies/nexthopStateLowLatency.h b/hicn-light/src/hicn/strategies/nexthopStateLowLatency.h new file mode 100644 index 000000000..34dbb8262 --- /dev/null +++ b/hicn-light/src/hicn/strategies/nexthopStateLowLatency.h @@ -0,0 +1,116 @@ +/* + * 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. + */ + +#ifndef nexthopstateLowLatency_h +#define nexthopstateLowLatency_h + +#include <parc/algol/parc_HashCode.h> +#include <parc/algol/parc_Object.h> + +struct strategy_nexthop_state_ll; +typedef struct strategy_nexthop_state_ll StrategyNexthopStateLL; +extern parcObjectDescriptor_Declaration(StrategyNexthopStateLL); + +/** + */ +StrategyNexthopStateLL *strategyNexthopStateLL_Acquire( + const StrategyNexthopStateLL *instance); + +#ifdef PARCLibrary_DISABLE_VALIDATION +#define strategyNexthopStateLL_OptionalAssertValid(_instance_) +#else +#define strategyNexthopStateLL_OptionalAssertValid(_instance_) \ + strategyNexthopStateLL_AssertValid(_instance_) +#endif + +/** + */ +void strategyNexthopStateLL_AssertValid(const StrategyNexthopStateLL *instance); + +/** + */ +StrategyNexthopStateLL *strategyNexthopStateLL_Create(unsigned face_id); + +void strategyNexthopStateLL_Reset(StrategyNexthopStateLL *x); +/** + */ +int strategyNexthopStateLL_Compare(const StrategyNexthopStateLL *instance, + const StrategyNexthopStateLL *other); + +/** + */ +StrategyNexthopStateLL *strategyNexthopStateLL_Copy( + const StrategyNexthopStateLL *original); + +/** + */ +void strategyNexthopStateLL_Display(const StrategyNexthopStateLL *instance, + int indentation); + +/** + */ +bool strategyNexthopStateLL_Equals(const StrategyNexthopStateLL *x, + const StrategyNexthopStateLL *y); + +/** + */ +PARCHashCode strategyNexthopStateLL_HashCode( + const StrategyNexthopStateLL *instance); + +/** + */ +bool strategyNexthopStateLL_IsValid(const StrategyNexthopStateLL *instance); + +/** + */ +void strategyNexthopStateLL_Release(StrategyNexthopStateLL **instancePtr); + +/** + */ +char *strategyNexthopStateLL_ToString(const StrategyNexthopStateLL *instance); + +/** + */ +double strategyNexthopStateLL_GetRTTProbe(StrategyNexthopStateLL *x); +double strategyNexthopStateLL_GetRTTInUse(StrategyNexthopStateLL *x); +double strategyNexthopStateLL_GetRTTLive(StrategyNexthopStateLL *x); +double strategyNexthopStateLL_GetQueuing(const StrategyNexthopStateLL *x); +void strategyNexthopStateLL_AddRttSample(StrategyNexthopStateLL *x, + unsigned int rtt); + + +void strategyNexthopStateLL_IncreaseTryToSwitch(StrategyNexthopStateLL *x, + unsigned round); +unsigned strategyNexthopStateLL_GetTryToSwitch(const StrategyNexthopStateLL *x); +void strategyNexthopStateLL_ResetTryToSwitch(StrategyNexthopStateLL *x); + +void strategyNexthopStateLL_SetUnusedFace(StrategyNexthopStateLL *x); + +unsigned strategyNexthopStateLL_GetFaceId(StrategyNexthopStateLL *x); + +void strategyNexthopStateLL_SendPacket(StrategyNexthopStateLL *x); + +void strategyNexthopStateLL_SentProbe(StrategyNexthopStateLL *x); + +void strategyNexthopStateLL_LostProbe(StrategyNexthopStateLL *x); + +bool strategyNexthopStateLL_IsLossy(const StrategyNexthopStateLL *x); + +void strategyNexthopStateLL_SetIsAllowed(StrategyNexthopStateLL *x, bool allowed); + +bool strategyNexthopStateLL_IsAllowed(const StrategyNexthopStateLL *x); + +void strategyNexthopStateLL_StartNewRound(StrategyNexthopStateLL *x); +#endif diff --git a/hicn-light/src/hicn/strategies/nexthopStateWithPD.c b/hicn-light/src/hicn/strategies/nexthopStateWithPD.c deleted file mode 100644 index 1a5d34b78..000000000 --- a/hicn-light/src/hicn/strategies/nexthopStateWithPD.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * 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. - */ - -#include <float.h> -#include <limits.h> -#include <hicn/hicn-light/config.h> -#include <stdio.h> - -#include <parc/algol/parc_DisplayIndented.h> -#include <parc/algol/parc_Memory.h> -#include <parc/algol/parc_Object.h> -#include <parc/assert/parc_Assert.h> - -#include <hicn/strategies/nexthopStateWithPD.h> - -struct strategy_nexthop_state_with_pd { - unsigned int pi; - unsigned delay; - double weight; - double avg_pi; -}; - -static bool _strategyNexthopStateWithPD_Destructor( - StrategyNexthopStateWithPD **instancePtr) { - return true; -} - -parcObject_ImplementAcquire(strategyNexthopStateWithPD, - StrategyNexthopStateWithPD); - -parcObject_ImplementRelease(strategyNexthopStateWithPD, - StrategyNexthopStateWithPD); - -parcObject_Override( - StrategyNexthopStateWithPD, PARCObject, - .destructor = (PARCObjectDestructor *) - _strategyNexthopStateWithPD_Destructor, - .copy = (PARCObjectCopy *)strategyNexthopStateWithPD_Copy, - .display = (PARCObjectDisplay *)strategyNexthopStateWithPD_Display, - .toString = (PARCObjectToString *)strategyNexthopStateWithPD_ToString, - .equals = (PARCObjectEquals *)strategyNexthopStateWithPD_Equals, - .compare = (PARCObjectCompare *)strategyNexthopStateWithPD_Compare, - .hashCode = (PARCObjectHashCode *)strategyNexthopStateWithPD_HashCode, - .display = (PARCObjectDisplay *)strategyNexthopStateWithPD_Display); - -void strategyNexthopStateWithPD_AssertValid( - const StrategyNexthopStateWithPD *instance) { - parcAssertTrue(strategyNexthopStateWithPD_IsValid(instance), - "StrategyNexthopStateWithPD is not valid."); -} - -StrategyNexthopStateWithPD *strategyNexthopStateWithPD_Create() { - StrategyNexthopStateWithPD *result = - parcObject_CreateInstance(StrategyNexthopStateWithPD); - if (result != NULL) { - result->pi = 0; - result->avg_pi = 1.0; - result->weight = 1; - result->delay = 0; - } - return result; -} - -void strategyNexthopStateWithPD_Reset(StrategyNexthopStateWithPD *x) { - x->pi = 0; - x->avg_pi = 1.0; - x->weight = 1; - x->delay = 0; -} - -int strategyNexthopStateWithPD_Compare( - const StrategyNexthopStateWithPD *val, - const StrategyNexthopStateWithPD *other) { - if (val == NULL) { - if (other != NULL) { - return -1; - } - } else if (other == NULL) { - return 1; - } else { - strategyNexthopStateWithPD_OptionalAssertValid(val); - strategyNexthopStateWithPD_OptionalAssertValid(other); - - if (val->pi < other->pi) { - return -1; - } else if (val->pi > other->pi) { - return 1; - } - - if (val->avg_pi < other->avg_pi) { - return -1; - } else if (val->avg_pi > other->avg_pi) { - return 1; - } - - if (val->weight < other->weight) { - return -1; - } else if (val->weight > other->weight) { - return 1; - } - - if (val->delay < other->delay) { - return -1; - } else if (val->delay > other->delay) { - return 1; - } - } - - return 0; -} - -StrategyNexthopStateWithPD *strategyNexthopStateWithPD_Copy( - const StrategyNexthopStateWithPD *original) { - StrategyNexthopStateWithPD *result = strategyNexthopStateWithPD_Create(); - result->pi = original->pi; - result->avg_pi = original->avg_pi; - result->weight = original->weight; - result->delay = original->delay; - - return result; -} - -void strategyNexthopStateWithPD_Display( - const StrategyNexthopStateWithPD *instance, int indentation) { - parcDisplayIndented_PrintLine(indentation, "StrategyNexthopStateWithPD@%p {", - instance); - parcDisplayIndented_PrintLine(indentation + 1, "%d", instance->pi); - parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->avg_pi); - parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->weight); - parcDisplayIndented_PrintLine(indentation + 1, "%f", instance->delay); - parcDisplayIndented_PrintLine(indentation, "}"); -} - -bool strategyNexthopStateWithPD_Equals(const StrategyNexthopStateWithPD *x, - const StrategyNexthopStateWithPD *y) { - bool result = false; - - if (x == y) { - result = true; - } else if (x == NULL || y == NULL) { - result = false; - } else { - strategyNexthopStateWithPD_OptionalAssertValid(x); - strategyNexthopStateWithPD_OptionalAssertValid(y); - - if (strategyNexthopStateWithPD_Compare(x, y) == 0) { - result = true; - } - } - - return result; -} - -PARCHashCode strategyNexthopStateWithPD_HashCode( - const StrategyNexthopStateWithPD *x) { - PARCHashCode result = 0; - char str[128]; - sprintf(str, "PI:%d: AVG_PI:%f: W:%f D:%d", x->pi, x->avg_pi, x->weight, - x->delay); - result = parcHashCode_Hash((uint8_t *)&str, strlen(str)); - return result; -} - -bool strategyNexthopStateWithPD_IsValid(const StrategyNexthopStateWithPD *x) { - bool result = false; - - if (x != NULL) { - result = true; - } - - return result; -} - -char *strategyNexthopStateWithPD_ToString(const StrategyNexthopStateWithPD *x) { - // this is not implemented - parcTrapNotImplemented( - "strategyNexthopStateWithPD_ToString is not implemented"); - return NULL; -} - -unsigned strategyNexthopStateWithPD_GetPI(const StrategyNexthopStateWithPD *x) { - strategyNexthopStateWithPD_OptionalAssertValid(x); - - return x->pi; -} - -double strategyNexthopStateWithPD_GetAvgPI( - const StrategyNexthopStateWithPD *x) { - strategyNexthopStateWithPD_OptionalAssertValid(x); - - return x->avg_pi; -} - -double strategyNexthopStateWithPD_GetWeight( - const StrategyNexthopStateWithPD *x) { - strategyNexthopStateWithPD_OptionalAssertValid(x); - - return x->weight; -} - -unsigned strategyNexthopStateWithPD_GetDelay( - const StrategyNexthopStateWithPD *x) { - strategyNexthopStateWithPD_OptionalAssertValid(x); - - return x->delay; -} - -void strategyNexthopStateWithPD_SetDelay(StrategyNexthopStateWithPD *x, - unsigned delay) { - strategyNexthopStateWithPD_OptionalAssertValid(x); - if (delay != 0) { - x->delay = delay; - } -} - -double strategyNexthopStateWithPD_UpdateState(StrategyNexthopStateWithPD *x, - bool inc, unsigned min_delay, - double alpha) { - strategyNexthopStateWithPD_OptionalAssertValid(x); - - if (inc) { - x->pi++; - } else { - if (x->pi > 0) { - x->pi--; - } - } - - x->avg_pi = (x->avg_pi * alpha) + (x->pi * (1 - alpha)); - if (x->avg_pi == 0.0) { - x->avg_pi = 0.1; - } - - double factor = 1.0; - if (min_delay != INT_MAX && x->delay != 0) { - factor = ((double)min_delay / (double)x->delay); - } - - x->weight = 1 / (x->avg_pi * factor); - - return x->weight; -} diff --git a/hicn-light/src/hicn/strategies/nexthopStateWithPD.h b/hicn-light/src/hicn/strategies/nexthopStateWithPD.h deleted file mode 100644 index 4d8bd6d15..000000000 --- a/hicn-light/src/hicn/strategies/nexthopStateWithPD.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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. - */ - -#ifndef nexthopstatewithpd_h -#define nexthopstatewithpd_h - -#include <parc/algol/parc_HashCode.h> -#include <parc/algol/parc_Object.h> - -struct strategy_nexthop_state_with_pd; -typedef struct strategy_nexthop_state_with_pd StrategyNexthopStateWithPD; -extern parcObjectDescriptor_Declaration(StrategyNexthopStateWithPD); - -/** - */ -StrategyNexthopStateWithPD *strategyNexthopStateWithPD_Acquire( - const StrategyNexthopStateWithPD *instance); - -#ifdef PARCLibrary_DISABLE_VALIDATION -#define strategyNexthopStateWithPD_OptionalAssertValid(_instance_) -#else -#define strategyNexthopStateWithPD_OptionalAssertValid(_instance_) \ - strategyNexthopStateWithPD_AssertValid(_instance_) -#endif - -/** - */ -void strategyNexthopStateWithPD_AssertValid( - const StrategyNexthopStateWithPD *instance); - -/** - */ -StrategyNexthopStateWithPD *strategyNexthopStateWithPD_Create(); - -void strategyNexthopStateWithPD_Reset(StrategyNexthopStateWithPD *x); -/** - */ -int strategyNexthopStateWithPD_Compare( - const StrategyNexthopStateWithPD *instance, - const StrategyNexthopStateWithPD *other); - -/** - */ -StrategyNexthopStateWithPD *strategyNexthopStateWithPD_Copy( - const StrategyNexthopStateWithPD *original); - -/** - */ -void strategyNexthopStateWithPD_Display( - const StrategyNexthopStateWithPD *instance, int indentation); - -/** - */ -bool strategyNexthopStateWithPD_Equals(const StrategyNexthopStateWithPD *x, - const StrategyNexthopStateWithPD *y); - -/** - */ -PARCHashCode strategyNexthopStateWithPD_HashCode( - const StrategyNexthopStateWithPD *instance); - -/** - */ -bool strategyNexthopStateWithPD_IsValid( - const StrategyNexthopStateWithPD *instance); - -/** - */ -void strategyNexthopStateWithPD_Release( - StrategyNexthopStateWithPD **instancePtr); - -/** - */ -char *strategyNexthopStateWithPD_ToString( - const StrategyNexthopStateWithPD *instance); - -/** - */ -unsigned strategyNexthopStateWithPD_GetPI(const StrategyNexthopStateWithPD *x); - -double strategyNexthopStateWithPD_GetAvgPI(const StrategyNexthopStateWithPD *x); - -double strategyNexthopStateWithPD_GetWeight( - const StrategyNexthopStateWithPD *x); - -unsigned strategyNexthopStateWithPD_GetDelay( - const StrategyNexthopStateWithPD *x); -void strategyNexthopStateWithPD_SetDelay(StrategyNexthopStateWithPD *x, - unsigned delay); - -double strategyNexthopStateWithPD_UpdateState(StrategyNexthopStateWithPD *x, - bool inc, unsigned min_delay, - double alpha); -#endif diff --git a/hicn-light/src/hicn/strategies/rnd.c b/hicn-light/src/hicn/strategies/rnd.c index 637fd90f9..064f3965b 100644 --- a/hicn-light/src/hicn/strategies/rnd.c +++ b/hicn-light/src/hicn/strategies/rnd.c @@ -28,9 +28,12 @@ static void _strategyRnd_ReceiveObject(StrategyImpl *strategy, const NumberSet *egressId, - const Message *objectMessage, Ticks rtt); + const Message *objectMessage, + Ticks pitEntryCreation, + Ticks objReception); static void _strategyRnd_OnTimeout(StrategyImpl *strategy, const NumberSet *egressId); + static NumberSet *_strategyRnd_LookupNexthop(StrategyImpl *strategy, #ifdef WITH_POLICY NumberSet * nexthops, @@ -62,21 +65,21 @@ static StrategyImpl _template = { .getStrategy = &_strategyRnd_GetStrategy, }; +#ifndef WITH_POLICY struct strategy_rnd; typedef struct strategy_rnd StrategyRnd; struct strategy_rnd { -#ifndef WITH_POLICY NumberSet *nexthops; -#endif /* ! WITH_POLICY */ }; +#endif /* ! WITH_POLICY */ StrategyImpl *strategyRnd_Create() { +#ifndef WITH_POLICY StrategyRnd *strategy = parcMemory_AllocateAndClear(sizeof(StrategyRnd)); parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(StrategyRnd)); -#ifndef WITH_POLICY strategy->nexthops = numberSet_Create(); #endif /* ! WITH_POLICY */ srand((unsigned int)time(NULL)); @@ -85,7 +88,9 @@ StrategyImpl *strategyRnd_Create() { parcAssertNotNull(impl, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(StrategyImpl)); memcpy(impl, &_template, sizeof(StrategyImpl)); +#ifndef WITH_POLICY impl->context = strategy; +#endif /* ! WITH_POLICY */ return impl; } @@ -111,7 +116,8 @@ static int _select_Nexthop(StrategyRnd *strategy) { static void _strategyRnd_ReceiveObject(StrategyImpl *strategy, const NumberSet *egressId, const Message *objectMessage, - Ticks rtt) {} + Ticks pitEntryCreation, + Ticks objReception) {} static void _strategyRnd_OnTimeout(StrategyImpl *strategy, const NumberSet *egressId) {} @@ -193,13 +199,13 @@ static void _strategyRnd_ImplDestroy(StrategyImpl **strategyPtr) { "Parameter must dereference to non-null pointer"); StrategyImpl *impl = *strategyPtr; - StrategyRnd *strategy = (StrategyRnd *)impl->context; #ifndef WITH_POLICY + StrategyRnd *strategy = (StrategyRnd *)impl->context; numberSet_Release(&(strategy->nexthops)); + parcMemory_Deallocate((void **)&strategy); #endif /* ! WITH_POLICY */ - parcMemory_Deallocate((void **)&strategy); parcMemory_Deallocate((void **)&impl); *strategyPtr = NULL; } diff --git a/hicn-light/src/hicn/strategies/rndSegment.c b/hicn-light/src/hicn/strategies/rndSegment.c deleted file mode 100644 index 93e39ee74..000000000 --- a/hicn-light/src/hicn/strategies/rndSegment.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * 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. - */ - -#include <hicn/hicn-light/config.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include <parc/assert/parc_Assert.h> - -#include <parc/algol/parc_HashMap.h> -#include <parc/algol/parc_Memory.h> -#include <hicn/core/nameBitvector.h> -#include <hicn/strategies/rndSegment.h> - -static void _strategyRndSegment_ReceiveObject(StrategyImpl *strategy, - const NumberSet *egressId, - const Message *objectMessage, - Ticks rtt); -static void _strategyRndSegment_OnTimeout(StrategyImpl *strategy, - const NumberSet *egressId); -static NumberSet *_strategyRndSegment_LookupNexthop( - 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, - unsigned connectionId); -static void _strategyRndSegment_ImplDestroy(StrategyImpl **strategyPtr); -static strategy_type _strategyRndSegment_GetStrategy(StrategyImpl *strategy); - -static StrategyImpl _template = { - .context = NULL, - .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, - .getStrategy = &_strategyRndSegment_GetStrategy, -}; - -struct strategy_rnd_segment; -typedef struct strategy_rnd_segment StrategyRndSegment; - -struct strategy_rnd_segment { - NumberSet *nexthops; - NameBitvector *segmentName; - int last_used_face; -}; - -StrategyImpl *strategyRndSegment_Create() { - StrategyRndSegment *strategy = - parcMemory_AllocateAndClear(sizeof(StrategyRndSegment)); - parcAssertNotNull(strategy, "parcMemory_AllocateAndClear(%zu) returned NULL", - sizeof(StrategyRndSegment)); - - strategy->nexthops = numberSet_Create(); - strategy->segmentName = NULL; - strategy->last_used_face = 0; - srand((unsigned int)time(NULL)); - - StrategyImpl *impl = parcMemory_AllocateAndClear(sizeof(StrategyImpl)); - parcAssertNotNull(impl, "parcMemory_AllocateAndClear(%zu) returned NULL", - sizeof(StrategyImpl)); - memcpy(impl, &_template, sizeof(StrategyImpl)); - impl->context = strategy; - - return impl; -} - -// ======================================================= -// Dispatch API - -strategy_type _strategyRndSegment_GetStrategy(StrategyImpl *strategy) { - return SET_STRATEGY_RANDOM_PER_DASH_SEGMENT; -} - -static int _select_Nexthop(StrategyRndSegment *strategy) { - unsigned len = (unsigned)numberSet_Length(strategy->nexthops); - if (len == 0) { - return -1; - } - - int rnd = (rand() % len); - return numberSet_GetItem(strategy->nexthops, rnd); -} - -static void _strategyRndSegment_ReceiveObject(StrategyImpl *strategy, - const NumberSet *egressId, - const Message *objectMessage, - Ticks rtt) {} - -static void _strategyRndSegment_OnTimeout(StrategyImpl *strategy, - const NumberSet *egressId) {} - -static NumberSet *_strategyRndSegment_LookupNexthop( - StrategyImpl *strategy, -#ifdef WITH_POLICY - NumberSet * nexthops, -#endif /* WITH_POLICY */ - const Message *interestMessage) { - StrategyRndSegment *srnd = (StrategyRndSegment *)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))) { - // there are no output faces or the input face is also the only output face. - // return null to avoid loops - return out; - } - - NameBitvector *interestName = - name_GetContentName(message_GetName(interestMessage)); - - if (srnd->segmentName == NULL) { - srnd->segmentName = nameBitvector_Copy(interestName); - } else if (!nameBitvector_Equals(srnd->segmentName, interestName)) { - nameBitvector_Destroy(&srnd->segmentName); - srnd->segmentName = nameBitvector_Copy(interestName); - } else { - // here we need to check if the output face still exists or if someone erase - // it - if (numberSet_Contains(srnd->nexthops, srnd->last_used_face)) { - // face exists, so keep using it! - numberSet_Add(out, srnd->last_used_face); - return out; - } else { - // the face does not exists anymore, try to find a new face but keep the - // name of the dash segment - } - } - - int out_connection; - do { - out_connection = _select_Nexthop(srnd); - } while (out_connection == in_connection); - - if (out_connection == -1) { - return out; - } - - srnd->last_used_face = out_connection; - numberSet_Add(out, out_connection); - return out; -} - -#ifndef WITH_POLICY -static NumberSet *_strategyRndSegment_ReturnNexthops(StrategyImpl *strategy) { - StrategyRndSegment *srnd = (StrategyRndSegment *)strategy->context; - return srnd->nexthops; -} - -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) { - parcAssertNotNull(strategyPtr, "Parameter must be non-null double pointer"); - parcAssertNotNull(*strategyPtr, - "Parameter must dereference to non-null pointer"); - - StrategyImpl *impl = *strategyPtr; - StrategyRndSegment *strategy = (StrategyRndSegment *)impl->context; - - numberSet_Release(&(strategy->nexthops)); - if (strategy->segmentName != NULL) { - nameBitvector_Destroy(&strategy->segmentName); - } - - parcMemory_Deallocate((void **)&strategy); - parcMemory_Deallocate((void **)&impl); - *strategyPtr = NULL; -} diff --git a/hicn-light/src/hicn/strategies/strategyImpl.h b/hicn-light/src/hicn/strategies/strategyImpl.h index d4001194a..140da5bf8 100644 --- a/hicn-light/src/hicn/strategies/strategyImpl.h +++ b/hicn-light/src/hicn/strategies/strategyImpl.h @@ -52,7 +52,8 @@ typedef struct strategy_impl StrategyImpl; struct strategy_impl { void *context; void (*receiveObject)(StrategyImpl *strategy, const NumberSet *egressId, - const Message *objectMessage, Ticks rtt); + const Message *objectMessage, Ticks pitEntryCreation, + Ticks objReception); void (*onTimeout)(StrategyImpl *strategy, const NumberSet *egressId); NumberSet *(*lookupNexthop)(StrategyImpl *strategy, #ifdef WITH_POLICY |