+ /* The link will be recommended for insertion if it is better* than some
+ * link in the routing table that is not our parent.
+ * We are comparing the path quality up to the node, and ignoring the link
+ * quality from us to the node. This is because of a couple of things:
+ * 1. we expect this call only for links with white bit set
+ * 2. we are being optimistic to the nodes in the table, by ignoring the
+ * 1-hop quality to them (which means we are assuming it's 1 as well)
+ * This actually sets the bar a little higher for replacement
+ * 3. this is faster
+ */
+ event bool CompareBit.shouldInsert(message_t *msg, void* payload, uint8_t len) {
+
+ bool found = FALSE;
+ uint16_t pathEtx;
+ uint16_t neighEtx;
+ int i;
+ routing_table_entry* entry;
+ ctp_routing_header_t* rcvBeacon;
+
+ if ((call AMPacket.type(msg) != AM_CTP_ROUTING) ||
+ (len != sizeof(ctp_routing_header_t)))
+ return FALSE;
+
+ /* 1.determine this packet's path quality */
+ rcvBeacon = (ctp_routing_header_t*)payload;
+
+ if (rcvBeacon->parent == INVALID_ADDR)
+ return FALSE;
+ /* the node is a root, recommend insertion! */
+ if (rcvBeacon->etx == 0) {
+ return TRUE;
+ }
+
+ pathEtx = rcvBeacon->etx; // + linkEtx;
+
+ /* 2. see if we find some neighbor that is worse */
+ for (i = 0; i < routingTableActive && !found; i++) {
+ entry = &routingTable[i];
+ //ignore parent, since we can't replace it
+ if (entry->neighbor == routeInfo.parent)
+ continue;
+ neighEtx = entry->info.etx;
+ found |= (pathEtx < neighEtx);
+ }
+ return found;
+ }
+
+