diff options
Diffstat (limited to 'hicn-light')
-rw-r--r-- | hicn-light/src/hicn/config/configuration.c | 19 | ||||
-rw-r--r-- | hicn-light/src/hicn/config/controlSetStrategy.c | 137 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/forwarder.c | 11 | ||||
-rw-r--r-- | hicn-light/src/hicn/core/forwarder.h | 3 | ||||
-rw-r--r-- | hicn-light/src/hicn/processor/messageProcessor.c | 4 | ||||
-rw-r--r-- | hicn-light/src/hicn/processor/messageProcessor.h | 4 | ||||
-rw-r--r-- | hicn-light/src/hicn/utils/commands.h | 7 |
7 files changed, 137 insertions, 48 deletions
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c index 8f97af3b1..509ad10ba 100644 --- a/hicn-light/src/hicn/config/configuration.c +++ b/hicn-light/src/hicn/config/configuration.c @@ -295,7 +295,7 @@ struct iovec *configuration_ProcessRegistrationList(Configuration *config, if (numberSet_Length(nexthops) > 1) { // payload extended, need reallocate, further entries via nexthops payloadSize = payloadSize + numberSet_Length(nexthops) - 1; - payloadResponse = (uint8_t *)parcMemory_Reallocate( + payloadResponse = (uint8_t *) parcMemory_Reallocate( payloadResponse, sizeof(list_routes_command) * payloadSize); } @@ -1035,10 +1035,25 @@ struct iovec *configuration_SetForwardingStrategy(Configuration *config, _configuration_StoreFwdStrategy(config, prefix, strategy); Name *hicnPrefix = name_CreateFromAddress(control->addressType, control->address, control->len); - forwarder_SetStrategy(config->forwarder, hicnPrefix, strategy); + Name *related_prefixes[MAX_FWD_STRATEGY_RELATED_PREFIXES]; + if(control->related_prefixes != 0){ + for(int i = 0; i < control->related_prefixes; i++){ + related_prefixes[i] = name_CreateFromAddress( + control->addresses_type[i], + control->addresses[i], control->lens[i]); + } + } + forwarder_SetStrategy(config->forwarder, hicnPrefix, strategy, + control->related_prefixes, related_prefixes); name_Release(&hicnPrefix); + if(control->related_prefixes != 0){ + for(int i = 0; i < control->related_prefixes; i++){ + name_Release(&related_prefixes[i]); + } + } } + free((char *) prefix); struct iovec *response = utils_CreateAck(header, control, sizeof(set_strategy_command)); diff --git a/hicn-light/src/hicn/config/controlSetStrategy.c b/hicn-light/src/hicn/config/controlSetStrategy.c index d8b326f42..5357a413e 100644 --- a/hicn-light/src/hicn/config/controlSetStrategy.c +++ b/hicn-light/src/hicn/config/controlSetStrategy.c @@ -75,12 +75,79 @@ strategy_type _validStrategy(const char *strategy) { return validStrategy; } +static void _getAddressAndLen(const char * prefixStr, char *addr, uint32_t *len){ + char *slash; + strcpy(addr, prefixStr); + slash = strrchr(addr, '/'); + if (slash != NULL) { + *len = atoi(slash + 1); + *slash = '\0'; + } +} + +static bool _checkAndSetIp(set_strategy_command * setStrategyCommand, + int index, char * addr, uint32_t len){ + // check and set IP address + int res; + if(index == -1) + res = inet_pton(AF_INET, addr, &setStrategyCommand->address.v4.as_u32); + else + res = inet_pton(AF_INET, addr, + &setStrategyCommand->addresses[index].v4.as_u32); + + if(res == 1) { + if (len == UINT32_MAX) { + printf("Netmask not specified: set to 32 by default\n"); + len = 32; + } else if (len > 32) { + printf("ERROR: exceeded INET mask length, max=32\n"); + return false; + } + if(index == -1) + setStrategyCommand->addressType = ADDR_INET; + else + setStrategyCommand->addresses_type[index] = ADDR_INET; + + } else { + + if(index == -1) + res = inet_pton(AF_INET6, addr, + &setStrategyCommand->address.v6.as_in6addr); + else + res = inet_pton(AF_INET6, addr, + &setStrategyCommand->addresses[index].v6.as_in6addr); + + if(res == 1) { + if (len == UINT32_MAX) { + printf("Netmask not specified: set to 128 by default\n"); + len = 128; + } else if (len > 128) { + printf("ERROR: exceeded INET6 mask length, max=128\n"); + return false; + } + + if(index == -1) + setStrategyCommand->addressType = ADDR_INET6; + else + setStrategyCommand->addresses_type[index] = ADDR_INET6; + + } else { + printf("Error: %s is not a valid network address \n", addr); + return false; + } + } + return true; +} + static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser, CommandOps *ops, PARCList *args) { - printf("set strategy <prefix> <strategy>\n"); + printf("set strategy <prefix> <strategy> "); + printf("[related_prefix1 related_preifx2 ...]\n"); printf("prefix: ipv4/ipv6 address (ex: 1234::/64)\n"); printf("strategy: strategy identifier\n"); + printf("optinal: list of related prefixes (max %u)\n", + MAX_FWD_STRATEGY_RELATED_PREFIXES); printf("available strategies:\n"); printf(" random\n"); printf(" loadbalancer\n"); @@ -90,12 +157,14 @@ static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser, return CommandReturn_Success; } + static CommandReturn _controlSetStrategy_Execute(CommandParser *parser, CommandOps *ops, PARCList *args) { ControlState *state = ops->closure; - if (parcList_Size(args) != 4) { + if (parcList_Size(args) < 4 || + parcList_Size(args) > (4 + MAX_FWD_STRATEGY_RELATED_PREFIXES)) { _controlSetStrategy_HelpExecute(parser, ops, args); return CommandReturn_Failure; } @@ -108,47 +177,17 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser, const char *prefixStr = parcList_GetAtIndex(args, 2); char *addr = (char *)malloc(sizeof(char) * (strlen(prefixStr) + 1)); - // separate address and len - char *slash; uint32_t len = UINT32_MAX; - strcpy(addr, prefixStr); - slash = strrchr(addr, '/'); - if (slash != NULL) { - len = atoi(slash + 1); - *slash = '\0'; - } + _getAddressAndLen(prefixStr, addr, &len); // allocate command payload set_strategy_command *setStrategyCommand = parcMemory_AllocateAndClear(sizeof(set_strategy_command)); - // check and set IP address - if (inet_pton(AF_INET, addr, &setStrategyCommand->address.v4.as_u32) == 1) { - if (len == UINT32_MAX) { - printf("Netmask not specified: set to 32 by default\n"); - len = 32; - } else if (len > 32) { - printf("ERROR: exceeded INET mask length, max=32\n"); - parcMemory_Deallocate(&setStrategyCommand); - free(addr); - return CommandReturn_Failure; - } - setStrategyCommand->addressType = ADDR_INET; - } else if (inet_pton(AF_INET6, addr, &setStrategyCommand->address.v6.as_in6addr) == - 1) { - if (len == UINT32_MAX) { - printf("Netmask not specified: set to 128 by default\n"); - len = 128; - } else if (len > 128) { - printf("ERROR: exceeded INET6 mask length, max=128\n"); - parcMemory_Deallocate(&setStrategyCommand); - free(addr); - return CommandReturn_Failure; - } - setStrategyCommand->addressType = ADDR_INET6; - } else { - printf("Error: %s is not a valid network address \n", addr); + bool success = _checkAndSetIp(setStrategyCommand, -1, addr, len); + if(!success){ parcMemory_Deallocate(&setStrategyCommand); + free(addr); return CommandReturn_Failure; } @@ -169,6 +208,32 @@ static CommandReturn _controlSetStrategy_Execute(CommandParser *parser, setStrategyCommand->len = len; setStrategyCommand->strategyType = strategy; + //check additional prefixes + if(parcList_Size(args) > 4){ + uint32_t index = 4; //first realted prefix + uint32_t addr_index = 0; + setStrategyCommand->related_prefixes = parcList_Size(args) - 4; + while(index < parcList_Size(args)){ + const char *str = parcList_GetAtIndex(args, index); + char *rel_addr = (char *)malloc(sizeof(char) * (strlen(str) + 1)); + uint32_t rel_len = UINT32_MAX; + _getAddressAndLen(str, rel_addr, &rel_len); + bool success = _checkAndSetIp(setStrategyCommand, addr_index, + rel_addr, rel_len); + if(!success){ + parcMemory_Deallocate(&setStrategyCommand); + free(rel_addr); + return CommandReturn_Failure; + } + setStrategyCommand->lens[addr_index] = rel_len; + free(rel_addr); + index++; + addr_index++; + } + }else{ + setStrategyCommand->related_prefixes = 0; + } + // send message and receive response struct iovec *response = utils_SendRequest( state, SET_STRATEGY, setStrategyCommand, sizeof(set_strategy_command)); diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c index 628cbd761..0d7575ea0 100644 --- a/hicn-light/src/hicn/core/forwarder.c +++ b/hicn-light/src/hicn/core/forwarder.c @@ -495,15 +495,14 @@ void forwarder_RemoveConnectionIdFromRoutes(Forwarder *forwarder, } void forwarder_SetStrategy(Forwarder *forwarder, Name *prefix, - strategy_type strategy) { + strategy_type strategy, + unsigned related_prefixes_len, + Name **related_prefixes) { parcAssertNotNull(forwarder, "Parameter hicn-light must be non-null"); parcAssertNotNull(prefix, "Parameter prefix must be non-null"); - // if (strategy == NULL) { - // strategy = SET_STRATEGY_RANDOM; - // } - - processor_SetStrategy(forwarder->processor, prefix, strategy); + processor_SetStrategy(forwarder->processor, prefix, strategy, + related_prefixes_len, related_prefixes); } FibEntryList *forwarder_GetFibEntries(Forwarder *forwarder) { diff --git a/hicn-light/src/hicn/core/forwarder.h b/hicn-light/src/hicn/core/forwarder.h index b8e68f0e4..a2401d625 100644 --- a/hicn-light/src/hicn/core/forwarder.h +++ b/hicn-light/src/hicn/core/forwarder.h @@ -263,7 +263,8 @@ bool forwarder_GetChacheServeFlag(Forwarder *forwarder); void forwarder_ClearCache(Forwarder *forwarder); void forwarder_SetStrategy(Forwarder *forwarder, Name *prefix, - strategy_type strategy); + strategy_type strategy, unsigned related_prefixes_len, + Name **related_prefixes); hicn_socket_helper_t *forwarder_GetHicnSocketHelper(Forwarder *forwarder); diff --git a/hicn-light/src/hicn/processor/messageProcessor.c b/hicn-light/src/hicn/processor/messageProcessor.c index ad9a4e6ac..c989f8cb6 100644 --- a/hicn-light/src/hicn/processor/messageProcessor.c +++ b/hicn-light/src/hicn/processor/messageProcessor.c @@ -401,7 +401,9 @@ void messageProcessor_RemoveConnectionIdFromRoutes(MessageProcessor *processor, } void processor_SetStrategy(MessageProcessor *processor, Name *prefix, - strategy_type strategy) { + strategy_type strategy, + unsigned related_prefixes_len, + Name **related_prefixes){ FibEntry *entry = fib_Contains(processor->fib, prefix); if (entry != NULL) { fibEntry_SetStrategy(entry, strategy); diff --git a/hicn-light/src/hicn/processor/messageProcessor.h b/hicn-light/src/hicn/processor/messageProcessor.h index 80cd22035..6a863aa38 100644 --- a/hicn-light/src/hicn/processor/messageProcessor.h +++ b/hicn-light/src/hicn/processor/messageProcessor.h @@ -187,7 +187,9 @@ bool messageProcessor_GetCacheServeFlag(MessageProcessor *processor); void messageProcessor_ClearCache(MessageProcessor *processor); void processor_SetStrategy(MessageProcessor *processor, Name *prefix, - strategy_type strategy); + strategy_type strategy, + unsigned related_prefixes_len, + Name **related_prefixes); #ifdef WITH_MAPME diff --git a/hicn-light/src/hicn/utils/commands.h b/hicn-light/src/hicn/utils/commands.h index bb566e688..1e227ad23 100644 --- a/hicn-light/src/hicn/utils/commands.h +++ b/hicn-light/src/hicn/utils/commands.h @@ -37,6 +37,7 @@ #endif /* WITH_POLICY */ #define SYMBOLIC_NAME_LEN 16 +#define MAX_FWD_STRATEGY_RELATED_PREFIXES 10 typedef struct in6_addr ipv6_addr_t; typedef uint32_t ipv4_addr_t; @@ -252,9 +253,13 @@ typedef struct { uint8_t strategyType; uint8_t addressType; uint8_t len; + uint8_t related_prefixes; + ip_address_t addresses[MAX_FWD_STRATEGY_RELATED_PREFIXES]; + uint8_t lens[MAX_FWD_STRATEGY_RELATED_PREFIXES]; + uint8_t addresses_type[MAX_FWD_STRATEGY_RELATED_PREFIXES]; } set_strategy_command; -// SIZE=20 +// SIZE=208 //========== [11] SET WLDR ========== |