aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/core/mapme.c
diff options
context:
space:
mode:
Diffstat (limited to 'hicn-light/src/hicn/core/mapme.c')
-rw-r--r--hicn-light/src/hicn/core/mapme.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/hicn-light/src/hicn/core/mapme.c b/hicn-light/src/hicn/core/mapme.c
index 4a254c701..8f40cb34a 100644
--- a/hicn-light/src/hicn/core/mapme.c
+++ b/hicn-light/src/hicn/core/mapme.c
@@ -116,10 +116,10 @@
#include <hicn/core/mapme.h>
#include <stdio.h> // printf
+#include <hicn/base/loop.h>
#include <hicn/core/connection.h>
#include <hicn/core/forwarder.h>
#include <hicn/core/msgbuf.h>
-#include <hicn/core/messagePacketType.h> // packet types
#include <hicn/core/ticks.h>
#include <hicn/core/fib_entry.h>
#include <hicn/core/pit.h>
@@ -187,7 +187,7 @@ struct mapme_s {
* Retransmissions
* Lite calendar queue with NUM_RETX_SLOT slots
*/
- int timer_fd;
+ event_t *timer;
mapme_retx_t retx_array[NUM_RETX_SLOT][NUM_RETX_ENTRIES];
uint8_t retx_len[NUM_RETX_SLOT];
uint8_t cur;
@@ -208,7 +208,7 @@ static mapme_t mapme_default = {
.discovery = MAPME_DEFAULT_DISCOVERY,
.protocol = MAPME_DEFAULT_PROTOCOL,
- .timer_fd = -1,
+ .timer = NULL,
// .retx_array = {{ 0 }}, // memset
.retx_len = { 0 },
.cur = 0, /* current slot */
@@ -217,6 +217,9 @@ static mapme_t mapme_default = {
/******************************************************************************/
+int
+mapme_on_timeout(void * mapme_arg, int fd, void * data);
+
mapme_t *
mapme_create(void * forwarder)
{
@@ -229,12 +232,19 @@ mapme_create(void * forwarder)
memset(mapme->retx_array, 0, NUM_RETX_SLOT * NUM_RETX_ENTRIES);
mapme->forwarder = forwarder;
+ loop_timer_create(&mapme->timer, MAIN_LOOP, mapme, mapme_on_timeout, NULL);
+ if (!mapme->timer) {
+ ERROR("Error allocating mapme timer.");
+ free(mapme);
+ return NULL;
+ }
return mapme;
}
void mapme_free(mapme_t * mapme)
{
+ loop_event_free(mapme->timer);
free(mapme);
}
@@ -518,9 +528,10 @@ mapme_create_fib_entry(const mapme_t * mapme, const Name * name, unsigned ingres
#endif
-void
-mapme_on_timeout(mapme_t * mapme, int fd, void * data)
+int
+mapme_on_timeout(void * mapme_arg, int fd, void * data)
{
+ mapme_t *mapme = mapme_arg;
assert(mapme);
assert(!data);
/* Timeout occurred, we have to retransmit IUs for all pending
@@ -580,9 +591,10 @@ mapme_on_timeout(mapme_t * mapme, int fd, void * data)
/* After two empty slots, we disable the timer */
if (mapme->idle > 1) {
- loop_unregister_timer(MAIN_LOOP, mapme->timer_fd);
- mapme->timer_fd = -1;
+ loop_event_unregister(mapme->timer);
}
+
+ return 0;
}
static
@@ -668,9 +680,12 @@ mapme_on_event(mapme_t * mapme, mapme_event_t event, fib_entry_t * entry,
.retx_count = 0,
};
- if (mapme->timer_fd == -1)
- mapme->timer_fd = loop_register_timer(MAIN_LOOP,
- mapme->retx, mapme, mapme_on_timeout, NULL);
+ if (!loop_timer_is_enabled(mapme->timer)) {
+ if (loop_timer_register(mapme->timer, mapme->retx) < 0) {
+ ERROR("Error setting mapme timer.");
+ break;
+ }
+ }
mapme->idle = 0;
break;
@@ -701,9 +716,8 @@ mapme_on_event(mapme_t * mapme, mapme_event_t event, fib_entry_t * entry,
mapme_send_to_nexthop(mapme, entry, ingress_id);
mapme->idle = 0;
- if (mapme->timer_fd == -1)
- mapme->timer_fd = loop_register_timer(MAIN_LOOP,
- mapme->retx, mapme, mapme_on_timeout, NULL);
+ if (!loop_timer_is_enabled(mapme->timer))
+ loop_timer_register(mapme->timer, mapme->retx);
break;
case MAPME_EVENT_PH_DEL:
@@ -742,7 +756,7 @@ mapme_on_interest(mapme_t * mapme, uint8_t * packet,
ERROR("Failed to send ACK packet");
}
- Name *name = name_CreateFromPacket(packet, MESSAGE_TYPE_INTEREST);
+ Name *name = name_create_from_interest(packet);
name_setLen(name, prefix->len);
char *name_str = name_ToString(name);
@@ -856,8 +870,7 @@ mapme_on_data(mapme_t *mapme, const uint8_t * packet,
{
INFO("Receive IU/IN Ack on connection %d", ingress_id);
- const Name * name =
- name_CreateFromPacket(packet, MESSAGE_TYPE_DATA);
+ const Name * name = name_create_from_data(packet);
name_setLen((Name*) name, prefix->len);
char * name_str = name_ToString(name);
@@ -904,10 +917,14 @@ mapme_on_data(mapme_t *mapme, const uint8_t * packet,
* processed by MAP-Me core.
*/
void
-mapme_process(mapme_t *mapme, uint8_t *packet, unsigned conn_id)
+mapme_process(mapme_t *mapme, msgbuf_t * msgbuf)
{
hicn_prefix_t prefix;
mapme_params_t params;
+
+ uint8_t * packet = msgbuf_get_packet(msgbuf);
+ unsigned conn_id = msgbuf_get_connection_id(msgbuf);
+
int rc = hicn_mapme_parse_packet(packet, &prefix, &params);
if (rc < 0)
return;