diff options
author | andrew-elder <aelder@audioscience.com> | 2017-05-08 08:44:00 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-08 08:44:00 -0400 |
commit | 402ce07d7547ced1e8e0582113acb1bb4aaaa591 (patch) | |
tree | 5caab590fe0244138e05ac285ddd8349774f9af1 /daemons | |
parent | c9b84533adb11fc9d850507aa799cff5564d1ee4 (diff) | |
parent | 58d88ba57eda3f2da922155edcbfc39d9c82653d (diff) | |
download | Open-AVB-402ce07d7547ced1e8e0582113acb1bb4aaaa591.tar.gz |
Merge pull request #590 from bdthomsen/maap_ui_update
Added YIELD command support to the MAAP daemon
Diffstat (limited to 'daemons')
-rw-r--r-- | daemons/maap/common/maap.c | 75 | ||||
-rw-r--r-- | daemons/maap/common/maap.h | 14 | ||||
-rw-r--r-- | daemons/maap/common/maap_iface.h | 3 | ||||
-rw-r--r-- | daemons/maap/common/maap_parse.c | 15 | ||||
-rw-r--r-- | daemons/maap/linux/src/maap_daemon.c | 1 |
5 files changed, 89 insertions, 19 deletions
diff --git a/daemons/maap/common/maap.c b/daemons/maap/common/maap.c index 03897753..304ee343 100644 --- a/daemons/maap/common/maap.c +++ b/daemons/maap/common/maap.c @@ -229,16 +229,16 @@ static int inform_status(Maap_Client *mc, const void *sender, int id, Range *ran return 0; } -static int inform_yielded(Maap_Client *mc, Range *range, int result) { +static int inform_yielded(Maap_Client *mc, const void *sender, int id, Range *range, Maap_Notify_Error result) { Maap_Notify note; note.kind = MAAP_NOTIFY_YIELDED; - note.id = range->id; - note.start = get_start_address(mc, range); - note.count = get_count(mc, range); + note.id = id; + note.start = (range ? get_start_address(mc, range) : 0); + note.count = (range ? get_count(mc, range) : 0 ); note.result = result; - add_notify(mc, range->sender, ¬e); + add_notify(mc, sender, ¬e); return 0; } @@ -422,15 +422,21 @@ void print_notify(Maap_Notify *mn, print_notify_callback_t notify_callback, void } break; case MAAP_NOTIFY_YIELDED: - sprintf(szOutput, "Address range %d yielded: 0x%012llx-0x%012llx (Size %d)", - mn->id, - (unsigned long long) mn->start, - (unsigned long long) mn->start + mn->count - 1, - mn->count); - notify_callback(callback_data, MAAP_LOG_LEVEL_WARNING, szOutput); - if (mn->result != MAAP_NOTIFY_ERROR_NONE) { - notify_callback(callback_data, MAAP_LOG_LEVEL_ERROR, - "A new address range will not be allocated"); + if (mn->result != MAAP_NOTIFY_ERROR_REQUIRES_INITIALIZATION && mn->result != MAAP_NOTIFY_ERROR_RELEASE_INVALID_ID) { + sprintf(szOutput, "Address range %d yielded: 0x%012llx-0x%012llx (Size %d)", + mn->id, + (unsigned long long) mn->start, + (unsigned long long) mn->start + mn->count - 1, + mn->count); + notify_callback(callback_data, MAAP_LOG_LEVEL_WARNING, szOutput); + if (mn->result != MAAP_NOTIFY_ERROR_NONE) { + notify_callback(callback_data, MAAP_LOG_LEVEL_ERROR, + "A new address range will not be allocated"); + } + } else { + sprintf(szOutput, "ID %d is not valid", + mn->id); + notify_callback(callback_data, MAAP_LOG_LEVEL_ERROR, szOutput); } break; default: @@ -765,6 +771,39 @@ void maap_range_status(Maap_Client *mc, const void *sender, int id) inform_status(mc, sender, id, NULL, MAAP_NOTIFY_ERROR_RELEASE_INVALID_ID); } +int maap_yield_range(Maap_Client *mc, const void *sender, int id) { + Range *range; + MAAP_Packet announce_packet; + uint8_t announce_buffer[MAAP_NET_BUFFER_SIZE]; + + if (!mc->initialized) { + MAAP_LOG_DEBUG("Yield not allowed, as MAAP not initialized"); + inform_yielded(mc, sender, id, NULL, MAAP_NOTIFY_ERROR_REQUIRES_INITIALIZATION); + return -1; + } + + range = mc->timer_queue; + while (range) { + if (range->id == id && range->state == MAAP_STATE_DEFENDING) { + // Create a conflicting packet for this range. + // Use a source address which will always be less than our address, so we should always yield. + init_packet(&announce_packet, 0x010000000000ull, 0x010000000000ull); + announce_packet.message_type = MAAP_ANNOUNCE; + announce_packet.requested_start_address = get_start_address(mc, range); + announce_packet.requested_count = get_count(mc, range); + pack_maap(&announce_packet, announce_buffer); + maap_handle_packet(mc, announce_buffer, MAAP_NET_BUFFER_SIZE); + + return 0; + } + range = range->next_timer; + } + + MAAP_LOGF_DEBUG("Range id %d does not exist", id); + inform_yielded(mc, sender, id, NULL, MAAP_NOTIFY_ERROR_RELEASE_INVALID_ID); + return -1; +} + int maap_handle_packet(Maap_Client *mc, const uint8_t *stream, int len) { MAAP_Packet p; Interval *iv; @@ -921,7 +960,7 @@ int maap_handle_packet(Maap_Client *mc, const uint8_t *stream, int len) { */ new_range = malloc(sizeof(Range)); if (new_range == NULL) { - inform_yielded(mc, range, MAAP_NOTIFY_ERROR_OUT_OF_MEMORY); + inform_yielded(mc, range->sender, range->id, range, MAAP_NOTIFY_ERROR_OUT_OF_MEMORY); } else { new_range->id = range->id; new_range->state = MAAP_STATE_PROBING; @@ -934,20 +973,20 @@ int maap_handle_packet(Maap_Client *mc, const uint8_t *stream, int len) { if (assign_interval(mc, new_range, 0, range_size) < 0) { /* Cannot find any available intervals of the requested size. */ - inform_yielded(mc, range, MAAP_NOTIFY_ERROR_RESERVE_NOT_AVAILABLE); + inform_yielded(mc, range->sender, range->id, range, MAAP_NOTIFY_ERROR_RESERVE_NOT_AVAILABLE); free(new_range); } else { #ifdef DEBUG_NEGOTIATE_MSG MAAP_LOGF_DEBUG("Requested replacement address range, id %d", new_range->id); MAAP_LOGF_DEBUG("Selected replacement address range 0x%012llx-0x%012llx", get_start_address(mc, new_range), get_end_address(mc, new_range)); #endif - inform_acquiring(mc, range); /* Send a probe for the replacement address range to try. */ schedule_timer(mc, new_range); send_probe(mc, new_range); - inform_yielded(mc, range, MAAP_NOTIFY_ERROR_NONE); + inform_yielded(mc, range->sender, range->id, range, MAAP_NOTIFY_ERROR_NONE); + inform_acquiring(mc, new_range); } } diff --git a/daemons/maap/common/maap.h b/daemons/maap/common/maap.h index 7c585304..13b4660c 100644 --- a/daemons/maap/common/maap.h +++ b/daemons/maap/common/maap.h @@ -176,6 +176,20 @@ int maap_release_range(Maap_Client *mc, const void *sender, int id); */ void maap_range_status(Maap_Client *mc, const void *sender, int id); +/** + * Yield a reserved block of addresses, in support of a MAAP_CMD_YIELD command. + * + * @note This call starts the yield process, which is only useful for testing. + * A MAAP_NOTIFY_YIELDED notification will be sent when the process is complete. + * + * @param mc Pointer to the Maap_Client structure to use + * @param sender Sender information pointer used to track the entity requesting the command + * @param id Identifier for the address block to yield + * + * @return 0 if the yield was started successfully, -1 otherwise. + */ +int maap_yield_range(Maap_Client *mc, const void *sender, int id); + /** * Processing for a received (incoming) networking packet diff --git a/daemons/maap/common/maap_iface.h b/daemons/maap/common/maap_iface.h index d388520a..55dcb8d3 100644 --- a/daemons/maap/common/maap_iface.h +++ b/daemons/maap/common/maap_iface.h @@ -45,6 +45,7 @@ typedef enum { MAAP_CMD_RESERVE, /**< Preserve a block of addresses within the initialized range */ MAAP_CMD_RELEASE, /**< Release a previously-reserved block of addresses */ MAAP_CMD_STATUS, /**< Return the block of reserved addresses associated with the supplied ID */ + MAAP_CMD_YIELD, /**< Yield a previously-reserved block of addresses. This is only useful for testing. */ MAAP_CMD_EXIT, /**< Have the daemon exit */ } Maap_Cmd_Tag; @@ -55,7 +56,7 @@ typedef enum { */ typedef struct { Maap_Cmd_Tag kind; /**< Type of command to perform */ - int32_t id; /**< ID to use for #MAAP_CMD_RELEASE or #MAAP_CMD_STATUS */ + int32_t id; /**< ID to use for #MAAP_CMD_RELEASE, #MAAP_CMD_STATUS, or #MAAP_CMD_YIELD */ uint64_t start; /**< Address range start for #MAAP_CMD_INIT */ uint32_t count; /**< Address range size for #MAAP_CMD_INIT, or address block size for #MAAP_CMD_RESERVE */ } Maap_Cmd; diff --git a/daemons/maap/common/maap_parse.c b/daemons/maap/common/maap_parse.c index c27bd0cd..1c51c3ba 100644 --- a/daemons/maap/common/maap_parse.c +++ b/daemons/maap/common/maap_parse.c @@ -93,6 +93,10 @@ int parse_text_cmd(char *buf, Maap_Cmd *cmd) { cmd->kind = MAAP_CMD_STATUS; cmd->id = (int)strtoul(argv[1], NULL, 0); set_cmd = 1; + } else if (strncmp(argv[0], "yield", 7) == 0 && argc == 2) { + cmd->kind = MAAP_CMD_YIELD; + cmd->id = (int)strtoul(argv[1], NULL, 0); + set_cmd = 1; } else if (strncmp(argv[0], "exit", 4) == 0 && argc == 1) { cmd->kind = MAAP_CMD_EXIT; set_cmd = 1; @@ -114,6 +118,7 @@ int parse_write(Maap_Client *mc, const void *sender, char *buf, int *input_is_te case MAAP_CMD_RESERVE: case MAAP_CMD_RELEASE: case MAAP_CMD_STATUS: + case MAAP_CMD_YIELD: case MAAP_CMD_EXIT: if (input_is_text) { *input_is_text = 0; } memcpy(&cmd, bufcmd, sizeof (Maap_Cmd)); @@ -162,6 +167,12 @@ int parse_write(Maap_Client *mc, const void *sender, char *buf, int *input_is_te #endif maap_range_status(mc, sender, cmd.id); break; + case MAAP_CMD_YIELD: +#ifdef DEBUG_CMD_MSG + MAAP_LOGF_DEBUG("Got cmd MAAP_CMD_YIELD, id: %d", (int) cmd.id); +#endif + rv = maap_yield_range(mc, sender, cmd.id); + break; case MAAP_CMD_EXIT: #ifdef DEBUG_CMD_MSG MAAP_LOG_DEBUG("Got cmd MAAP_CMD_EXIT"); @@ -201,6 +212,10 @@ void parse_usage(print_notify_callback_t print_callback, void *callback_data) print_callback(callback_data, MAAP_LOG_LEVEL_INFO, " status <id> - Get the range of addresses associated with identifier ID"); print_callback(callback_data, MAAP_LOG_LEVEL_INFO, + " yield <id> - Yield the range of addresses associated with identifier ID."); + print_callback(callback_data, MAAP_LOG_LEVEL_INFO, + " This is only useful for testing."); + print_callback(callback_data, MAAP_LOG_LEVEL_INFO, " exit - Shutdown the MAAP daemon"); print_callback(callback_data, MAAP_LOG_LEVEL_INFO, " "); // Blank line diff --git a/daemons/maap/linux/src/maap_daemon.c b/daemons/maap/linux/src/maap_daemon.c index 0c17e0c7..8943ee73 100644 --- a/daemons/maap/linux/src/maap_daemon.c +++ b/daemons/maap/linux/src/maap_daemon.c @@ -845,6 +845,7 @@ static int act_as_client(const char *listenport) case MAAP_CMD_RESERVE: case MAAP_CMD_RELEASE: case MAAP_CMD_STATUS: + case MAAP_CMD_YIELD: case MAAP_CMD_EXIT: memcpy(&recvcmd, bufcmd, sizeof(Maap_Cmd)); rv = 1; |