bool ForwarderRank::newRoutingInformation(const Metadata *m) { if (!m || m->getName() != getName()) return false; bubble_node_id_t node_b_id = id_from_string(m->getParameter("node_id")); HAGGLE_DBG("HAGGLE_DBG: New %s routing information received from %s number %ld \n", getName(), m->getParameter("node_id"), id_from_string(m->getParameter("node_id"))); const Metadata *mm = m->getMetadata("Metric"); while (mm) { //bubble_node_id_t node_c_id = id_from_string(mm->getParameter("node_id")); LABEL_T node_b_label = mm->getParameter("label"); const char* node_b_hostid = mm->getParameter("hostid"); const char* tmp = mm->getParameter("rank"); RANK_T node_b_rank = atol(tmp); rib[node_b_id].first = node_b_label; rib[node_b_id].second = node_b_rank; HAGGLE_DBG("Routing received from %s label:%s rank:%ld \n",node_b_hostid , rib[node_b_id].first.c_str(), rib[node_b_id].second); //HAGGLE_DBG("HAGGLE_DBG: Routing received from node:%s label:%s rank:%ld \n",id_number_to_nodeid[node_b_id].c_str(), rib[node_b_id].first.c_str(), rib[node_b_id].second); mm= m->getNextMetadata(); } bubble_rib_t::iterator jt = rib.begin(); while (jt != rib.end()) { //bool isNeighbor = getKernel()->getNodeStore()->stored(id_number_to_nodeid[jt->first], true); HAGGLE_DBG("HAGGLE_DBG: Printing node_id_num:%ld label:%s rank:%ld \n", jt->first, jt->second.first.c_str() , jt->second.second); jt++; } rib_timestamp = Timeval::now(); return true; }
/* * Converts an array of strings to query IDs using the given transforming * function. */ static struct query_id * query_id_array_from_strings(char **strings, unsigned int package_count, id_from_string_ptr id_from_string) { struct query_id *query_ids; assert(strings != NULL); assert(id_from_string != NULL); query_ids = query_id_array_alloc(package_count); if (query_ids != NULL) { bool success; unsigned int i; success = true; for (i = 0; i < package_count; i++) { success = id_from_string(strings[i], query_ids + i); if (!success) { query_id_array_free(&query_ids, package_count); break; } } if (!success) { query_id_array_free(&query_ids, package_count); } } return query_ids; }
void ForwarderRank::_generateDelegatesFor(const DataObjectRef &dObj, const NodeRef &target, const NodeRefList *other_targets) { List<Pair<NodeRef, bubble_metric_t> > sorted_delegate_list; // Figure out which node to look for: bubble_node_id_t target_id = id_from_string(target->getIdStr()); LABEL_T targetLabel = rib[target_id].first; //RANK_T targetRank = rib[target_id].second; HAGGLE_DBG("HAGGLE_DBG:_generateDelegatesFor node %d string %s label %s\n", target_id, target->getIdStr(), targetLabel.c_str()); for (bubble_rib_t::iterator it = rib.begin();it != rib.end(); it++) { if (it->first != this_node_id && it->first != target_id) { NodeRef delegate = kernel->getNodeStore()->retrieve(id_number_to_nodeid[it->first], true); if (delegate && !isTarget(delegate, other_targets)) { LABEL_T &neighborLabel = it->second.first; RANK_T &neighborRank = it->second.second; HAGGLE_DBG("HAGGLE_DBG: _generateDelegatesFor neighborLabel=%s, targetLabel=%s\n", neighborLabel.c_str(), targetLabel.c_str()); if (neighborLabel.compare(targetLabel)==0) { //NodeRef delegate = Node::create_with_id(Node::TYPE_PEER, id_number_to_nodeid[it->first].c_str(), "Label delegate node"); sortedNodeListInsert(sorted_delegate_list, delegate, it->second); HAGGLE_DBG("HAGGLE_DBG: _generateDelegatesFor Label same: Node '%s' is a good delegate for target '%s' [label=%s, rank=%ld]\n", delegate->getName().c_str(), target->getName().c_str(), neighborLabel.c_str(), neighborRank); } } } } // Add up to max_generated_delegates delegates to the result in order of decreasing metric if (!sorted_delegate_list.empty()) { NodeRefList delegates; unsigned long num_delegates = max_generated_delegates; while (num_delegates && sorted_delegate_list.size()) { NodeRef delegate = sorted_delegate_list.front().first; sorted_delegate_list.pop_front(); delegates.push_back(delegate); num_delegates--; } kernel->addEvent(new Event(EVENT_TYPE_DELEGATE_NODES, dObj, target, delegates)); HAGGLE_DBG("HAGGLE_DBG: Forward Generated %lu delegates for target %s\n", delegates.size(), target->getName().c_str()); } else { HAGGLE_DBG("No delegates found for target %s\n", target->getName().c_str()); } }
void ForwarderRank::_endNeighbor(const NodeRef &neighbor) { // We don't handle routing to anything but other haggle nodes: if (neighbor->getType() != Node::TYPE_PEER) return; // Update our private metric regarding this node: bubble_node_id_t neighbor_id = id_from_string(neighbor->getIdStr()); HAGGLE_DBG("HAGGLE_DBG: _endNeighbor node left: node %ld %s \n", neighbor_id, neighbor->getIdStr()); rib_timestamp = Timeval::now(); }
bool ForwarderProphet::newRoutingInformation(const Metadata *m) { if (!m || m->getName() != getName()) return false; bubble_node_id_t node_b_id = id_from_string(m->getParameter("node_id")); HAGGLE_DBG(" New %s routing information received from: %s number: %ld \n", getName(), m->getParameter("node_id"), id_from_string(m->getParameter("node_id"))); const Metadata *mm = m->getMetadata("Metric"); while (mm) { //bubble_node_id_t node_c_id = id_from_string(mm->getParameter("node_id")); LABEL_T node_b_label = mm->getParameter("label"); const char* node_b_hostid = mm->getParameter("hostid"); const char* tmp = mm->getParameter("rank"); RANK_T node_b_rank = atol(tmp); rib[node_b_id].first = node_b_label; rib[node_b_id].second = node_b_rank; HAGGLE_DBG("Routing info received xxx from %s label:%s rank:%ld \n",node_b_hostid , rib[node_b_id].first.c_str(), rib[node_b_id].second); mm= m->getNextMetadata(); } rib_timestamp = Timeval::now(); return true; }
ForwarderRank::ForwarderRank(ForwardingManager *m, const EventType type) : ForwarderAsynchronous(m, type, PROPHET_NAME), myRank(1), kernel(getManager()->getKernel()), next_id_number(1), rib_timestamp(Timeval::now()) { myNodeStr=kernel->getThisNode()->getIdStr(); // Ensure that the local node's forwarding id is 1: myNodeId=id_from_string(myNodeStr); myLabel=string("temp"); if (gethostname(hostname, HOSTNAME_LEN) != 0) { HAGGLE_ERR("Could not get hostname\n"); } // Always zero terminate in case the hostname didn't fit hostname[HOSTNAME_LEN-1] = '\0'; HAGGLE_DBG("Forwarding module \'%s\' hostname %s initialization.\n", getName(), hostname); }
bool ForwarderRank::setSaveState(RepositoryEntryRef& e) { if (strcmp(e->getAuthority(), getName()) != 0) return false; string value = e->getValueStr(); size_t pos = value.find(':'); bubble_metric_t& metric = rib[id_from_string(e->getKey())]; // The first part of the value is the label metric metric.first = value.substr(0, pos).c_str(); // The second part is the rank metric.second = atol(value.substr(pos + 1).c_str()); HAGGLE_DBG("HAGGLE_DBG: orig string=%s label=%s, rank=%ld\n", e->getValue(), metric.first.c_str(), metric.second); rib_timestamp = Timeval::now(); return true; }