📄 tora.cc
字号:
Time delay = 0.0; while((p0 = rqueue.deque(td->index))) { forward(p0, tn->index, delay); delay += ARP_SEPARATION_DELAY; } } Packet::free(p);}/* * IETF Draft - TORA Specification, section 3.7.6 */voidtoraAgent::recvQRY(Packet *p){ struct hdr_ip *ih = HDR_IP(p); struct hdr_tora_qry *qh = HDR_TORA_QRY(p); TORADest *td; TORANeighbor *tn; if(qh->tq_dst == ipaddr()) {#ifdef DEBUG fprintf(stderr, "node %d received `QRY` for itself.\n", index);#endif return; } td = dst_find(qh->tq_dst); if(td == 0) td = dst_add(qh->tq_dst); if(td->rt_req) { return; } if(td->height.r == 0) { // II, A tn = td->nb_find(ih->saddr()); if(tn && tn->time_act > td->time_upd) { // II, A, 1 td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } else { // II, A, 2 } } else { tn = td->nb_find_min_height(0); if(tn) { // II, B, 1 td->update_height(tn->height.tau, tn->height.oid, tn->height.r, tn->height.delta + 1, ipaddr()); td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } else { td->rt_req = 1; td->time_rt_req = CURRENT_TIME; if(td->num_active > 1) { // II, B, 1, a sendQRY(td->index); } else { // II, B, 1, b } } }}/* * IETF Draft - TORA Specification, section 3.7.7 */voidtoraAgent::recvUPD(Packet *p){ struct hdr_ip *ih = HDR_IP(p); struct hdr_tora_upd *uh = HDR_TORA_UPD(p); TORADest *td; TORANeighbor *tn; if(uh->tu_dst == ipaddr()) { return; } td = dst_find(uh->tu_dst); if(td == 0) td = dst_add(uh->tu_dst); tn = td->nb_find(ih->saddr()); if(tn == 0) { /* * update link status? -josh */ // No, don't update linkstatus: it may be an update // that was delayed in the IMEP layer for sequencing -dam // no way at the TORA level to tell if we're connected... trace("T %.9f _%d_ received `UPD` from non-neighbor %d", CURRENT_TIME, ipaddr(), ih->saddr()); #ifdef DEBUG fprintf(stderr, "node %d received `UPD` from non-neighbor %d\n", index, ih->src_);#endif return; } /* * Update height and link status for neighbor [j][k]. */ td->update_height_nb(tn, uh); if(td->rt_req && tn->height.r == 0) { // I td->update_height(tn->height.tau, tn->height.oid, tn->height.r, tn->height.delta + 1, ipaddr()); td->rt_req = 0; td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } else if(td->num_down == 0) { // II if(td->num_up == 0) { // II, A if(td->height.isNull()) // II, A, 1 return; // II, A, 1, a else { td->height.Null(); // II, A, 1, b td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } } else { if(td->nb_check_same_ref()) { // II, A, 2 TORANeighbor *tn; if( (tn = td->nb_find_min_height(0)) ) { // II, A, 2, a td->update_height(tn->height.tau, // II, A, 2, a, i tn->height.oid, 1, 0, ipaddr()); td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } else { if(td->height.oid == ipaddr()) { // II, A, 2, a, ii double temp_tau = td->height.tau; // II, A, 2, a, ii, x nsaddr_t temp_oid = td->height.oid; td->height.Null(); td->num_down = 0; td->num_up = 0; /* * For every active link n, if the neighbor connected * via link n is the destination j, set HT_NEIGH[j][n]=ZERO * and LNK_STAT[j][n] = DN. * Otherwise, set HT_NEIGH[j][n] = NULL and LNK_STAT[j][n] = UN. */ for(tn = td->nblist.lh_first; tn; tn = tn->link.le_next) { if(tn->index == td->index) { tn->height.Zero(); tn->lnk_stat = LINK_DN; } else { tn->height.Null(); tn->lnk_stat = LINK_UN; } } sendCLR(td->index, temp_tau, temp_oid); } else { td->update_height(Scheduler::instance().clock(), // II, A, 2, a, ii, y ipaddr(), 0, 0, ipaddr()); td->rt_req = 0; td->time_upd = Scheduler::instance().clock();#ifdef DEBUG // under what circumstances does this rule fire? // seems like it will prevent the detection of // partitions...??? -dam 8/24/98 if (logtarget) { sprintf(logtarget->pt_->buffer(), "T %.9f _%d_ rule IIA2a(ii)x fires %d", Scheduler::instance().clock(), ipaddr(), td->index); logtarget->pt_->dump(); }#endif sendUPD(td->index); } } } else { TORANeighbor *n = td->nb_find_max_height(); // II, A, 2, b assert(n); TORANeighbor *m = td->nb_find_min_nonnull_height(&n->height); assert(m); td->update_height(m->height.tau, m->height.oid, m->height.r, m->height.delta - 1, ipaddr()); td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } } } else { // II, B }}/* * IETF Draft - TORA Specification, section 3.7.8 */voidtoraAgent::recvCLR(Packet *p){ struct hdr_ip *ih = HDR_IP(p); struct hdr_tora_clr *th = HDR_TORA_CLR(p); TORADest *td; TORANeighbor *tn; if(th->tc_dst == ipaddr()) { return; } td = dst_find(th->tc_dst); if(td == 0) td = dst_add(th->tc_dst); assert(td); if(td->height.tau == th->tc_tau && td->height.oid == th->tc_oid && td->height.r == 1) { // I double temp_tau = td->height.tau; nsaddr_t temp_oid = td->height.oid; td->height.Null(); td->num_up = 0; td->num_down = 0; for(tn = td->nblist.lh_first; tn; tn = tn->link.le_next) { if(tn->index == td->index) { tn->height.Zero(); tn->lnk_stat = LINK_DN; } else { tn->height.Null(); tn->lnk_stat = LINK_UN; } } if(td->num_active > 1) { // I, A sendCLR(td->index, temp_tau, temp_oid); } else { // I, B } } else { tn = td->nb_find(ih->saddr()); // II if(tn == 0) { /* * XXX - update link status? */ trace("T %.9f _%d_ received `CLR` from non-neighbor %d", CURRENT_TIME, index, ih->saddr()); #ifdef DEBUG fprintf(stderr, "node %d received `CLR` from non-neighbor %d\n", index, ih->src_);#endif return; } tn->height.Null(); tn->lnk_stat = LINK_UN; for(tn = td->nblist.lh_first; tn; tn = tn->link.le_next) { if(tn->height.tau == th->tc_tau && tn->height.oid == th->tc_oid && tn->height.r == 1) { tn->height.Null(); tn->lnk_stat = LINK_UN; } } if(td->num_down == 0) { // II, A if(td->num_up == 0) { // II, A, 1 if(td->height.isNull()) { // II, A, 1, a } else { td->height.Null(); td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } } else { td->update_height(Scheduler::instance().clock(), ipaddr(), 0, 0, ipaddr()); td->rt_req = 0; td->time_upd = Scheduler::instance().clock(); sendUPD(td->index); } } else { // II, B } }}voidtoraAgent::trace(char* fmt, ...){ va_list ap; if (!logtarget) return; va_start(ap, fmt); vsprintf(logtarget->pt_->buffer(), fmt, ap); logtarget->pt_->dump(); va_end(ap);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -