void find_neighbor_polygon(uint *ref, uint length, uint vertex_length, uint *vertex) { uint i, j, poly; length *= 4; for(i = 0; i < length; i++) { for(j = 0; j < 2; j++) { if(ref[i] == vertex[j]) { poly = (i / 4) * 4; if(ref[poly + 3] < vertex_length) { add_neighbor(j, ref[poly + ((i + 1) % 4)], j, 0, poly / 4, TRUE); add_neighbor(j, ref[poly + ((i + 3) % 4)], 1 - j, 0, poly / 4, TRUE); }else { add_neighbor(j, ref[poly + ((i + 1 - poly) % 3)], j, 0, poly / 4, TRUE); add_neighbor(j, ref[poly + ((i + 2 - poly) % 3)], 1 - j, 0, poly / 4, TRUE); } } } } }
/*----------------------------------------------------------------------------*/ void test_neighbor_table(void) { address_t addr1; addr1.u8[0] = 1; addr1.u8[1] = 1; uint8_t rssi1 = 100; address_t addr3; addr3.u8[0] = 1; addr3.u8[1] = 1; uint8_t rssi3 = 50; address_t addr2; addr2.u8[0] = 2; addr2.u8[1] = 2; uint8_t rssi2 = 200; if (!list_length(neighbor_table)){ add_neighbor(&addr1,rssi1); add_neighbor(&addr2,rssi2); add_neighbor(&addr3,rssi3); print_neighbor_table(); }else{ purge_neighbor_table(); print_neighbor_table(); } }
static void add_neighbor(t_room *room, t_room *neighbor) { if (room && neighbor) { // ICI IL FAUT REMPLIR LES VOISINS DE LA ROOM AVEC NEIGHBOR // room->neighbors = neighbor printf("ptr = %p\n", room->neighbors); } static int check_tubes(char *str, t_infos *infos, t_list **rooms) { int len; char **split; t_room *left; t_room *right; (void)infos; if (str) { split = ft_strsplit(str, '-'); len = tablen(split); if (len == 2) { left = name_to_room(split[0], rooms); right = name_to_room(split[1], rooms); printf("left = %s right = %s\n", left->name, right->name); add_neighbor(left, right); add_neighbor(right, left); return (1); } // PENSES A FREE LE **SPLIT } return (0); }
void find_neighbor_edges(uint *edge, uint length, uint *vertex) { uint i; length *= 2; for(i = 0; i < length; i++) { if(edge[i] == vertex[0]) add_neighbor(0, edge[(i / 2) * 2 + (i + 1) % 2], 0, 0, i / 2, FALSE); if(edge[i] == vertex[1]) add_neighbor(1, edge[(i / 2) * 2 + (i + 1) % 2], 0, 0, i / 2, FALSE); } }
/*---------------------------------------------------------------------------*/ void neighbor_info_packet_sent(int status, int numtx) { const rimeaddr_t *dest; link_metric_t packet_metric; #if UIP_DS6_LL_NUD uip_ds6_nbr_t *nbr; #endif /* UIP_DS6_LL_NUD */ dest = packetbuf_addr(PACKETBUF_ADDR_RECEIVER); if(rimeaddr_cmp(dest, &rimeaddr_null)) { return; } packet_metric = numtx; PRINTF("neighbor-info: packet sent to %d.%d, status=%d, metric=%u\n", dest->u8[sizeof(*dest) - 2], dest->u8[sizeof(*dest) - 1], status, (unsigned)packet_metric); switch(status) { case MAC_TX_OK: add_neighbor(dest); #if UIP_DS6_LL_NUD nbr = uip_ds6_nbr_ll_lookup((uip_lladdr_t *)dest); if(nbr != NULL && (nbr->state == STALE || nbr->state == DELAY || nbr->state == PROBE)) { nbr->state = REACHABLE; // stimer_set(&nbr->reachable, UIP_ND6_REACHABLE_TIME / 1000); PRINTF("neighbor-info : received a link layer ACK : "); PRINTLLADDR((uip_lladdr_t *)dest); PRINTF(" is reachable.\n"); } #endif /* UIP_DS6_LL_NUD */ break; case MAC_TX_NOACK: add_neighbor(dest); printf("neighbor-info: ETX_NOACK_PENALTY\n"); packet_metric = ETX_NOACK_PENALTY; break; default: /* Do not penalize the ETX when collisions or transmission errors occur. */ return; } update_metric(dest, packet_metric); }
void init_routing_table(node whoami) { /* Not really required to lock, but for sanity */ size_t neighbor; pthread_rwlock_wrlock(&routing_table_lock); for (size_t i = 0; i < MAX_HOSTS; ++i) { routing_table[i].next_hop = whoami; routing_table[i].distance = INFINTITY; routing_table[i].ttl = MAX_ROUTE_TTL; routing_table[i].host = NULL; memset(routing_table[i].pathentries, false , MAX_HOSTS); } //Connect to our neighbors for (size_t i = 0; hosts[whoami].neighbors[i] != TERMINATOR; ++i) { neighbor = hosts[whoami].neighbors[i]; add_neighbor(whoami,neighbor); } routing_table[whoami].next_hop = whoami; routing_table[whoami].distance = 0; routing_table[whoami].pathentries[whoami] = true; pthread_rwlock_unlock(&routing_table_lock); }
int set_contact_weight(CELL *cell1, CELL *cell2, double weight) { int n1, n2; for (n1 = 0; n1 < cell1->num_neighbors; n1++) { if (cell1->neighbor[n1] == cell2) break; } for (n2 = 0; n2 < cell2->num_neighbors; n2++) { if (cell2->neighbor[n2] == cell1) break; } if ((n1 < cell1->num_neighbors) && (n2 < cell2->num_neighbors)) { cell1->contact_weight[n1] = weight; cell2->contact_weight[n2] = weight; return (0); } else if ((n1 == cell1->num_neighbors) && (n2 == cell2->num_neighbors)) return (add_neighbor(cell1, cell2, weight)); else { fprintf(stderr, "set_contact_weight: inconsistent contacts\n"); return (-1); } }
/*---------------------------------------------------------------------------*/ void neighbor_info_packet_received(cyg_uint8 rssi) { const rimeaddr_t *src; src = packetbuf_addr(PACKETBUF_ADDR_SENDER); if(rimeaddr_cmp(src, &rimeaddr_null)) { return; } PRINTF("neighbor-info: packet received from %x.%x\n", src->u8[sizeof(*src) - 2], src->u8[sizeof(*src) - 1]); /* if ( NULL != neighbor_attr_get_data(&etx, src)){ if (rssi > 0) ///// MODIFIED LATER update_etx(src, rssi); } */ /******************** lock the Scheduler ************************/ cyg_scheduler_lock(); /****************************************************************/ add_neighbor(src); update_etx(src, rssi); /******************** unlock the Scheduler ************************/ cyg_scheduler_unlock(); /****************************************************************/ }
void init_sample(int const *bond_site, double const *bond_value, int *n, double *J4, int *z, int *offset, double *h2m, double *um) { int i, b; /* 1st pass: calculate vertex degrees and offsets */ memset(z, 0, N * sizeof(int)); for (i = 0; i < NZ; i++) z[bond_site[i]]++; offset[0] = 0; for (i = 1; i < N; i++) offset[i] = offset[i-1] + z[i-1]; /* 2nd pass: fill in values */ memset(z, 0, N * sizeof(int)); memset(h2m, 0., N * sizeof(double)); *um = 0.; for (i = 0; i < NUM_BONDS; i++) { for (b = 0; b < 2; b++) add_neighbor(bond_site[2*i+b], bond_site[2*i+(1^b)], bond_value[i], z, offset, n, J4, h2m); *um -= bond_value[i]; } }
/* Crea un nuevo nodo principal (xNode). Agrega su vecino segun el sentido * de direccion establecido. Devuelve NULL en caso de error */ xNode *new_node (edge *xy, u32 n1, u32 n2, flag_s DIRECTION){ int status = SCHARR_ERR; xNode *xnod = NULL; assert (xy != NULL); xnod = (xNode *) malloc(sizeof(struct xNodeSt)); /* Se guarda 'x' y se intenta agregar 'y' segun el sentido establecido*/ if (xnod != NULL){ xnod->x = n1; if (DIRECTION == FORWARD){ status = add_neighbor(xy, n2, xnod->Farr, &xnod->Fcounter); }else if (DIRECTION == BACKWARD){ status = add_neighbor(xy, n1, bnod->Barr, &bnod->Bcounter); } } /* se dio memoria, pero ocurrio algun otro error*/ if (xnod != NULL && status = SCHARR_ERR) free(xnod); return xnod; }
/*---------------------------------------------------------------------------*/ void neighbor_info_packet_received(void) { const rimeaddr_t *src; src = packetbuf_addr(PACKETBUF_ADDR_SENDER); if(rimeaddr_cmp(src, &rimeaddr_null)) { return; } PRINTF("neighbor-info: packet received from %d.%d\n", src->u8[sizeof(*src) - 2], src->u8[sizeof(*src) - 1]); add_neighbor(src); }
void pwospf_hello_type(struct ip* ip_header, byte* payload, uint16_t payload_len, pwospf_header_t* pwospf_header, interface_t* intf) { printf(" ** pwospf_hello_type(..) called \n"); printf(" ** pwospf_hello_type(..) packet with length: %u \n", payload_len); // make hello packet pwospf_hello_packet_t* hello_packet = (pwospf_hello_packet_t*) malloc_or_die(sizeof(pwospf_hello_packet_t)); memcpy(&hello_packet->network_mask, payload, 4); memcpy(&hello_packet->helloint, payload + 4, 2); memcpy(&hello_packet->padding, payload + 6, 2); // display packet printf(" ** pwospf_hello_type(..) displayed header contents:\n"); display_hello_packet(hello_packet); // check mask and hello interval if(intf->subnet_mask == hello_packet->network_mask && intf->helloint == ntohs(hello_packet->helloint)) { printf(" ** pwospf_hello_type(..) network mask and hello interval correct\n"); // if the interface has no neighbors if(intf->neighbor_list == NULL) { printf(" ** pwospf_hello_type(..) interface has no neighbors, adding new neighbor\n"); add_neighbor(intf, pwospf_header->router_id, ip_header->ip_src.s_addr, hello_packet->helloint, hello_packet->network_mask); } else { // interface has existing neighbors // generate neighbor object neighbor_t* neighbor = make_neighbor(pwospf_header->router_id, ip_header->ip_src.s_addr, hello_packet->helloint, hello_packet->network_mask); // get last instance so that lsu info can be put back pthread_mutex_lock(&intf->neighbor_lock); node* ret = llist_find( intf->neighbor_list, predicate_id_neighbor_t,(void*) &pwospf_header->router_id); pthread_mutex_unlock(&intf->neighbor_lock); if( ret!= NULL) { neighbor_t *neighbor_ret = (neighbor_t*) ret->data; neighbor->last_adverts = neighbor_ret->last_adverts; neighbor->last_lsu_packet = neighbor_ret->last_lsu_packet; } // lock neighbor list pthread_mutex_lock(&intf->neighbor_lock); // if exists, then update, otherwise add intf->neighbor_list = llist_update_beginning_delete(intf->neighbor_list, predicate_neighbor_t, (void*) neighbor); pthread_mutex_unlock(&intf->neighbor_lock); } // update info in neighbor db // get instance of router struct sr_instance* sr_inst = get_sr(); struct sr_router* router = (struct sr_router*)sr_get_subsystem(sr_inst); update_neighbor_vertex_t_rid(router, ip_header->ip_src.s_addr, pwospf_header->router_id); } else { printf(" ** pwospf_hello_type(..) network mask or hello interval incorrect\n"); } }
/*----------------------------------------------------------------------------*/ void handle_beacon(packet_t* p) { add_neighbor(&(p->header.src),p->info.rssi); #if !SINK // TODO what if the network changes? uint8_t new_hops = get_payload_at(p, BEACON_HOPS_INDEX); if (new_hops <= conf.hops_from_sink-1 && p->info.rssi > conf.rssi_from_sink) { conf.nxh_vs_sink = p->header.src; conf.hops_from_sink = new_hops+1; conf.rssi_from_sink = p->info.rssi; conf.sink_address = p->header.nxh; } #endif packet_deallocate(p); }
/* ************************************************** */ void rx(call_t *c, packet_t *packet) { struct nodedata *nodedata = get_node_private_data(c); array_t *up = get_entity_bindings_up(c); int i = up->size; struct routing_header *header = (struct routing_header *) (packet->data + nodedata->overhead); switch(header->type) { case HELLO_PACKET: nodedata->hello_rx++; add_neighbor(c, header); packet_dealloc(packet); break; case DATA_PACKET : nodedata->data_rx++; if ((header->dst != BROADCAST_ADDR) && (header->dst != c->node) ) { forward(c, packet); return; } while (i--) { call_t c_up = {up->elts[i], c->node, c->entity}; packet_t *packet_up; if (i > 0) { packet_up = packet_clone(packet); } else { packet_up = packet; } RX(&c_up, packet_up); } break; default : break; } return; }
/*----------------------------------------------------------------------------*/ void handle_beacon(packet_t* p) { add_neighbor(&(p->header.src),p->info.rssi); #if !SINK uint8_t new_hops = get_payload_at(p, BEACON_HOPS_INDEX); uint8_t new_distance = p->info.rssi; if (address_cmp(&(conf.nxh_vs_sink), &(p->header.src)) || #if MOBILE (new_distance < conf.distance_from_sink) #else (new_hops <= conf.hops_from_sink-1 && new_distance < conf.distance_from_sink) #endif ) { conf.nxh_vs_sink = p->header.src; conf.distance_from_sink = new_distance; conf.sink_address = p->header.nxh; conf.hops_from_sink = new_hops+1; } #endif packet_deallocate(p); }
void parse_cache(char *filename) { xmlDoc *doc = NULL; xmlNode *root_element = NULL; xmlNode *neighbor = NULL; char *c; LIBXML_TEST_VERSION; /*parse the file and get the DOM */ doc = xmlReadFile(cache_path, NULL, 0); /*Get the root element node */ root_element = xmlDocGetRootElement(doc); neighbor = root_element->children; while(neighbor != NULL) { if( !STRCMP(neighbor->name,"neighbor") ) { struct in6_addr lla; struct ether_addr mac, eth; xmlNode *param = neighbor->children; uint16_t vlan_id = 4095; while(param != NULL) { if (param->type == XML_ELEMENT_NODE) { if( !STRCMP(param->name,"mac") ) { c=(char *)XML_GET_CONTENT(param->children); memcpy(&mac,ether_aton(c),sizeof(struct ether_addr)); /* memcpy(&mac,ether_aton((char *)XML_GET_CONTENT(param->children)),sizeof(struct ether_addr)); */ add_neighbor(&neighbors, vlan_id, mac); } else if( !STRCMP(param->name,"vlan_id") ) { char *text = (char*)XML_GET_CONTENT(param->children); vlan_id = atoi(text!=NULL?text:"4095"); } else if( !STRCMP(param->name,"time") ) { c=(char *)XML_GET_CONTENT(param->children); set_neighbor_timer(&neighbors, vlan_id, mac,atoi(c)); /* set_neighbor_timer(&neighbors, mac,atoi((char *)XML_GET_CONTENT(param->children))); */ } else if( !STRCMP(param->name,"lla") ) { if(param->children != NULL) { inet_pton(AF_INET6,(char *)XML_GET_CONTENT(param->children), &lla); set_neighbor_lla(&neighbors, vlan_id, mac, lla); } } else if( !STRCMP(param->name,"addresses") ) { xmlNode *address = param->children; while(address != NULL) { if (address->type == XML_ELEMENT_NODE) { if( !STRCMP(address->name,"address") ) { struct in6_addr addr; struct _xmlAttr *attr = address->properties; inet_pton(AF_INET6,(char *)XML_GET_CONTENT(address->children), &addr); add_neighbor_ip(&neighbors, vlan_id, mac, addr); while(attr != NULL) { if (attr->type == XML_ATTRIBUTE_NODE) { if( !STRCMP(attr->name,"lastseen") ) { set_neighbor_address_timer(&neighbors, vlan_id, mac, addr, (time_t) atoi((const char *)(attr->children->content))); } else if ( !STRCMP(attr->name,"firstseen") ) { set_neighbor_first_address_timer(&neighbors, vlan_id, mac, addr, (time_t) atoi((const char *)(attr->children->content))); } } attr = attr->next; } } } address = address->next; } } else if( !STRCMP(param->name,"old_mac") ) { xmlNode *old = param->children; while(old != NULL) { if (old->type == XML_ELEMENT_NODE) { if( !STRCMP(old->name,"mac") ) { struct _xmlAttr *attr = old->properties; memcpy(ð,ether_aton((char *)XML_GET_CONTENT(old->children)),sizeof(struct ether_addr)); add_neighbor_old_mac(&neighbors, vlan_id, lla, eth); while(attr != NULL) { if (attr->type == XML_ATTRIBUTE_NODE) { if( !STRCMP(attr->name,"last") ) { neighbor_set_last_mac(&neighbors, vlan_id, lla, eth); } } attr = attr->next; } } } old = old->next; } } } param = param->next; } } neighbor = neighbor->next; } xmlFreeDoc(doc); return; }
/** * @brief neighs_register: receive a packet whose payload contains nodes * that are 1 hop and 2 hops away. * @param pkt_hdr: The pointer to the packet received buffer * @return */ uint8_t neighs_register(data_packet_t *pkt_hdr, int pldLen, uint8_t probe_counter){ uint8_t k = 0, sndr_id, sndr_p; int16_t offsetH1, offsetH2; uint8_t spatSim = 1; //extract sender ID and period sndr_id = pkt_hdr->src_id; //period sndr_p = pkt_hdr->period; //computes the offset to the sender of the packet. int16_t ownOffset = ((int16_t)probe_counter - pkt_hdr->offset); //uint8_t periodLength = compute_node_period(pkt_hdr->energy); offsetH1 = ownOffset; //if the offset is negative, we compute the positive offset by summing //the sender's period length. if (ownOffset < 0){ offsetH1 = pkt_hdr->period + ownOffset; //COOJA_DEBUG_PRINTF("dc:%u\n",compute_node_period(pkt_hdr->energy)); } struct nodelist_item *srcL = NULL; srcL = neighs_get(sndr_id); if((srcL == NULL) && sndr_id != rimeaddr_node_addr.u8[0] ){ //add the sender node here.. add_neighbor(sndr_id, offsetH1, sndr_p, 1); }else{ //node already exists..update the sender node here.. srcL->hopcount = 1 ; srcL->tconfirmed = get_discovery_time(); srcL->offset = offsetH1; srcL->offsetj = offsetH1; //generic discovery srcL->j_factor = 0; srcL->t_anchor = get_anchor_time(); //update spatial similarity spatSim++; } //go though all items in the packet and add them accordingly.. for ( k = 0; k < pldLen; k++){ uint8_t dpos = k*DATA_ITEM_LEN; struct data_item_t *ditem = (struct data_item_t*)(&pkt_hdr->data[dpos]); //filter packets based on hop-count number, remove also my id if ((ditem->node_id != 0) && (ditem->node_id != rimeaddr_node_addr.u8[0]) && (ditem->dc_hopc <= MAX_HOPCOUNT)){ struct nodelist_item *nli = NULL; //check if the nodeID is already registered/received.. nli = neighs_get(ditem->node_id); if(nli == NULL){ //add a new node here.. //compute offset of a hop 2 neighbor. offsetH2 = ( ditem->offset + ownOffset); if(offsetH2 < 0){ offsetH2 = nli->period + offsetH2; } if(offsetH2 >= 0){ add_neighbor(ditem->node_id, offsetH2, ditem->period, 2); } //COOJA_DEBUG_PRINTF("%u Epid(h2)-> %u offset:%2d\n",rimeaddr_node_addr.u8[0], ditem->node_id, offsetH2); }else{ //node already exists.. spatSim++; } } } // for ( k = 0; //update spatial similarity struct nodelist_item *nli = NULL; nli = neighs_get(sndr_id); if(nli != NULL){ nli->spat_sim = spatSim; } return 0; }
bool MsgNeighbor::MergePartialFromCodedStream( ::google::protobuf::io::CodedInputStream* input) { #define DO_(EXPRESSION) if (!(EXPRESSION)) return false ::google::protobuf::uint32 tag; while ((tag = input->ReadTag()) != 0) { switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { // optional string platform = 1; case 1: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { goto handle_uninterpreted; } DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_platform())); ::google::protobuf::internal::WireFormat::VerifyUTF8String( this->platform().data(), this->platform().length(), ::google::protobuf::internal::WireFormat::PARSE); if (input->ExpectTag(16)) goto parse_accountId; break; } // optional int64 accountId = 2; case 2: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_accountId: DO_(::google::protobuf::internal::WireFormatLite::ReadInt64( input, &accountid_)); _set_bit(1); if (input->ExpectTag(24)) goto parse_score; break; } // optional int32 score = 3; case 3: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_score: DO_(::google::protobuf::internal::WireFormatLite::ReadInt32( input, &score_)); _set_bit(2); if (input->ExpectTag(32)) goto parse_xp; break; } // optional int32 xp = 4; case 4: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_xp: DO_(::google::protobuf::internal::WireFormatLite::ReadInt32( input, &xp_)); _set_bit(3); if (input->ExpectTag(42)) goto parse_extId; break; } // optional string extId = 5; case 5: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { goto handle_uninterpreted; } parse_extId: DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_extid())); ::google::protobuf::internal::WireFormat::VerifyUTF8String( this->extid().data(), this->extid().length(), ::google::protobuf::internal::WireFormat::PARSE); if (input->ExpectTag(50)) goto parse_url; break; } // optional string url = 6; case 6: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { goto handle_uninterpreted; } parse_url: DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_url())); ::google::protobuf::internal::WireFormat::VerifyUTF8String( this->url().data(), this->url().length(), ::google::protobuf::internal::WireFormat::PARSE); if (input->ExpectTag(58)) goto parse_name; break; } // optional string name = 7; case 7: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { goto handle_uninterpreted; } parse_name: DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8String( this->name().data(), this->name().length(), ::google::protobuf::internal::WireFormat::PARSE); if (input->ExpectTag(64)) goto parse_isNeighbor; break; } // optional int32 isNeighbor = 8; case 8: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_isNeighbor: DO_(::google::protobuf::internal::WireFormatLite::ReadInt32( input, &isneighbor_)); _set_bit(7); if (input->ExpectTag(72)) goto parse_levelBasedOnScore; break; } // optional int32 levelBasedOnScore = 9; case 9: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_levelBasedOnScore: DO_(::google::protobuf::internal::WireFormatLite::ReadInt32( input, &levelbasedonscore_)); _set_bit(8); if (input->ExpectTag(82)) goto parse_wishlist; break; } // optional string wishlist = 10; case 10: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { goto handle_uninterpreted; } parse_wishlist: DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_wishlist())); ::google::protobuf::internal::WireFormat::VerifyUTF8String( this->wishlist().data(), this->wishlist().length(), ::google::protobuf::internal::WireFormat::PARSE); if (input->ExpectTag(88)) goto parse_damageProtectionTimeLeft; break; } // optional int64 damageProtectionTimeLeft = 11; case 11: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_damageProtectionTimeLeft: DO_(::google::protobuf::internal::WireFormatLite::ReadInt64( input, &damageprotectiontimeleft_)); _set_bit(10); if (input->ExpectTag(96)) goto parse_tutorialCompleted; break; } // optional int32 tutorialCompleted = 12; case 12: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_VARINT) { goto handle_uninterpreted; } parse_tutorialCompleted: DO_(::google::protobuf::internal::WireFormatLite::ReadInt32( input, &tutorialcompleted_)); _set_bit(11); if (input->ExpectTag(106)) goto parse_neighbor; break; } // repeated .MsgPlanet neighbor = 13; case 13: { if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) != ::google::protobuf::internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED) { goto handle_uninterpreted; } parse_neighbor: DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_neighbor())); if (input->ExpectTag(106)) goto parse_neighbor; if (input->ExpectAtEnd()) return true; break; } default: { handle_uninterpreted: if (::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { return true; } DO_(::google::protobuf::internal::WireFormat::SkipField( input, tag, mutable_unknown_fields())); break; } } } return true; #undef DO_ }
int8_t prov_received_thunder( uint16_t source_addr, wcom_msg_thunder_t *msg ){ // look for matching provisional neighbor provisional_neighbor_t *prov = get_prov( source_addr ); if( prov == 0 ){ return -1; } // check state if( prov->state != PROVISIONAL_STATE_WAIT_THUNDER ){ return -1; } if( msg->response != prov->challenge + 1 ){ log_v_info_P( PSTR("Invalid response:%d"), source_addr ); return -1; } // insert into neighbor table // first check if we already have an entry for this neighbor wcom_neighbor_t *neighbor = wcom_neighbors_p_get_neighbor( source_addr ); if( neighbor == 0 ){ // check if neighbor list is full if( neighbor_list_full() ){ // run neighbor drop policy uint16_t dropped_neighbor = drop_neighbor(); if( dropped_neighbor != 0 ){ evict( dropped_neighbor ); log_v_info_P( PSTR("Evicting:%d in favor of: %d"), dropped_neighbor, source_addr ); } } // create neighbor neighbor = add_neighbor( source_addr ); if( neighbor < 0 ){ log_v_critical_P( PSTR("Insufficient memory for neighbor list") ); return -1; } log_v_info_P( PSTR("Adding neighbor:%d"), source_addr ); } else{ log_v_info_P( PSTR("Rejoined neighbor:%d"), source_addr ); } // init neighbor neighbor->flags = prov->flags | WCOM_NEIGHBOR_FLAGS_NEW; neighbor->short_addr = source_addr; neighbor->age = 0; neighbor->replay_counter = msg->counter; neighbor->ip = prov->ip; memcpy( neighbor->iv, msg->iv, sizeof(neighbor->iv) ); // init link states so we default with the white bit set neighbor->rssi = 10; neighbor->lqi = 230; neighbor->prr = 128; neighbor->etx = 16; // check upstream status if( ( ( upstream == 0 ) || ( upstream == source_addr ) ) && ( prov->upstream != 0 ) && ( prov->depth < WCOM_NEIGHBOR_MAX_DEPTH ) ){ upstream = source_addr; depth = prov->depth + 1; log_v_debug_P( PSTR("Upstream: %d Depth: %d"), upstream, depth ); neighbor->flags |= WCOM_NEIGHBOR_FLAGS_UPSTREAM; } // reset beacon interval when adding new neighbor reset_beacon_interval(); // prov neighbor is now free remove_prov( source_addr ); return 0; }
void process_nw_ctrl_pkt(NW_Packet *pkt, int8_t rssi) { int8_t ret; // to hold the return value of various function calls int8_t i; if(DEBUG_NL >= 1) nrk_kprintf(PSTR("NL: Entered process_nw_ctrl_pkt()\n")); switch( nw_ctrl_type(pkt -> type) ) { case HELLO: // HELLO msg // unpack the Msg_Hello from the packet payload unpack_Msg_Hello(&mh, pkt -> data); mh.n.rssi = rssi; ret = add_neighbor(mh.n); if(ret == NRK_ERROR) { record_max_ngb_limit_reached(pkt); // record this fact } if(DEBUG_NL >= 1) { nrk_kprintf(PSTR("Received HELLO msg from: ")); printf("%d ", mh.n.addr); nrk_kprintf(PSTR("with RSSI = ")); printf("%d\r\n",mh.n.rssi); } break; case NGB_LIST: // NGB_LIST msg // if the node gets it's own NgbList message back, drop it if(pkt -> src == NODE_ADDR) break; // unpack the Msg_NgbList from the packet payload unpack_Msg_NgbList(&mnlist, pkt -> data); nlist = mnlist.nl; if(DEBUG_NL >= 1) { int8_t i; // loop index printf("NL: Received NGB_LIST msg from %d with count = %d\n", nlist.my_addr, nlist.count); for(i = 0; i < MAX_NGBS; i++) { if(nlist.ngbs[i].addr != BCAST_ADDR) // valid entry printf("%u, ", nlist.ngbs[i].addr); } printf("\r\n"); } //multihop(pkt); // multihop this NGB_LIST message. route_packet(pkt); if(CONNECTED_TO_GATEWAY == TRUE) // this node is connected to the gateway { // construct a packet to be sent to the gateway over the serial connection ntg_pkt.type = SERIAL_NGB_LIST; ntg_pkt.length = SIZE_MSG_NGB_LIST; // pack the message in the data field of the NodeToGatewaySerial_Packet pack_Msg_NgbList(ntg_pkt.data, &mnlist); // pack the NodeToGatewaySerial_Packet header into the serial transmit buffer pack_NodeToGatewaySerial_Packet_header(to_gw_buf, &ntg_pkt); // append the payload into the serial transmit buffer memcpy(to_gw_buf + SIZE_NODETOGATEWAYSERIAL_PACKET_HEADER, ntg_pkt.data, MAX_SERIAL_PAYLOAD); // CHECK //send the packet to gateway if(DEBUG_NL >= 1) { nrk_kprintf(PSTR("Sending packet to gateway\r\n")); } sendToSerial(to_gw_buf, SIZE_NODETOGATEWAYSERIAL_PACKET); //printBuffer(to_gw_buf, SIZE_NODETOGATEWAYSERIAL_PACKET); } break; case ROUTE_CONFIG: unpack_Msg_RoutingTable(&mrt, pkt -> data); enter_cr(nl_sem, 34); DEFAULT_GATEWAY = mrt.dg; // get the value of DEFAULT_GATEWAY in any case leave_cr(nl_sem, 34); if(DEBUG_NL == 0) { nrk_kprintf(PSTR("Received a ROUTE_CONFIG message\r\n")); for(i = 0; i < MAX_NODES; i++) { printf("%d -> %d [%d, %d]\r\n", mrt.node, mrt.rt[i].dest, mrt.rt[i].nextHop, mrt.rt[i].cost); } } if(mrt.node == NODE_ADDR) // this is my routing table { /*enter_cr(nl_sem, 34); initialise_routing_table(); // invalidate all entries for(i = 0; i < MAX_NODES; i++) { rt[i] = mrt.rt[i]; } leave_cr(nl_sem, 34); */ set_RoutingTable(&mrt); } else // some other node's routing table. Route it { route_packet(pkt); } break; default: nrk_kprintf(PSTR("NL: process_nw_ctrl_pkt(): Unsupported network control message received = ")); printf("%u\n", pkt -> type); break; } // end switch return; }
void process_hello(void *packet, u_int32_t from, u_int32_t to, unsigned int size, struct ospf_interface *oiface) { struct ospfhdr *ospfheader; struct ospf_hello *hello; struct ospf_neighbor *nbr; struct in_addr ospf_mcast, *neighbors; int nbr_count=0, i=0; nbr = NULL; ospfheader = (struct ospfhdr *)packet; hello = (struct ospf_hello *)(packet+OSPFHDR_LEN); inet_pton(AF_INET,OSPF_MULTICAST_ALLROUTERS,&ospf_mcast); if((to == ospf_mcast.s_addr) || (to == oiface->iface->ip.s_addr)) { add_neighbor(from,ospfheader->src_router,oiface,hello); nbr_count = ((size-sizeof(struct ospfhdr)) - (sizeof(struct ospf_hello) - sizeof(struct in_addr)))/(sizeof(struct in_addr)); if(nbr_count>0) { neighbors = (struct in_addr *)(packet + (size - (sizeof(struct in_addr)*nbr_count))); for(i=0;i<nbr_count;i++) { if(neighbors[i].s_addr == ospf0->router_id.s_addr) { nbr = find_neighbor_by_ip(from); //if(nbr) send_dbdesc(nbr); } } } send_hello(oiface,NULL); if(nbr) { //check if adjacency should form /* - p2p * - this is DR * - this is BDR * - other is DR * - other is BDR * */ // set the nbr state to 2way since hello has been seen if(nbr->state<=OSPF_NBRSTATE_2WAY) { nbr->state = OSPF_NBRSTATE_2WAY; //dr-bdr negotiation: handles most scenarios but not RFC compliant //if the dr is empty if(oiface->dr.s_addr == 0) { // figure out who is dr // if the nbr doesn't know... if(nbr->dr.s_addr==0) { //set it to whoever has larger priority or if equal then to greater router id if(oiface->priority>nbr->priority) { oiface->dr.s_addr = ospf0->router_id.s_addr; } else if (nbr->priority>oiface->priority) { oiface->dr.s_addr = nbr->router_id.s_addr; } else { if(ntohl(ospf0->router_id.s_addr)<ntohl(nbr->router_id.s_addr)) { oiface->dr.s_addr = nbr->router_id.s_addr; } else { oiface->dr.s_addr = ospf0->router_id.s_addr; } } //if nbr has a dr of itself then use it } else if (nbr->dr.s_addr == nbr->router_id.s_addr){ oiface->dr.s_addr = nbr->router_id.s_addr; //if nbr has a dr of this rtr then go ahead and use ourself as dr } else if (nbr->dr.s_addr == ospf0->router_id.s_addr){ oiface->dr.s_addr = ospf0->router_id.s_addr; } else { //wait for dr to talk } send_hello(oiface,NULL); // if the bdr is empty } else if (oiface->bdr.s_addr == 0){ //figure out who is bdr //if the nbr thinks it is the bdr believe it if (nbr->bdr.s_addr == nbr->router_id.s_addr) { oiface->bdr.s_addr = nbr->bdr.s_addr; } } if(nbr->dr.s_addr&&(nbr->dr.s_addr!=oiface->dr.s_addr)) { oiface->dr.s_addr = nbr->dr.s_addr; } //if self or nbr is dr or bdr then go to exstart and send dbdesc if((oiface->dr.s_addr == oiface->iface->ip.s_addr)||(oiface->bdr.s_addr==oiface->iface->ip.s_addr)||(nbr->dr.s_addr==nbr->ip.s_addr)||(nbr->bdr.s_addr==nbr->ip.s_addr)) { //if so, go to exstart nbr->state = OSPF_NBRSTATE_EXSTART; nbr->lsa_send_list = copy_lsalist(); nbr->lsa_send_count = ospf0->lsdb->count; send_dbdesc(nbr,0); } } } } else { // how did this packet get here } }