📄 listenmanagers_bakc
字号:
TimeoutList::iterator bound = _timedout.upper_bound(now); // find the unique set of neighbors that has timed out for (TimeoutList::iterator i = _timedout.begin(); ((i != bound) && (i != _timedout.end())); i++) { SrcStateList *nsl = (*i).second; for (SrcStateList::const_iterator j = nsl->begin(); j != nsl->end(); j++) { nl.insert((*j)->_src, 1); click_chatter("%s get_recps_timeout adding src %u to timedout list, timedout size is %u", id().cc(), (*j)->_src.addr(), _timedout.size()); } } RecpVector *rv = new RecpVector; for (SrcList::iterator i = nl.begin(); i != nl.end(); i++) { IPAddress src = i.key(); click_chatter("%s get recps timeout finding recpstatelist for %u, timedout size is %u", id().cc(), src.addr(), _timedout.size()); RecpStateList *rsl = _pending.find(src, 0); RecpStateList::iterator j = rsl->begin(); if (j == rsl->end()) { continue; } click_chatter("%s get recps timeout looking for first unrecepted element, timedout size is %u", id().cc(), _timedout.size()); uint16_t start = (*j)->_id; update_timeout_list((*j)->_timeout, src); click_chatter("%s Time Taken for reception report: %u", id().cc(), (now - (*j)->_timeout + _recp_timeout)); uint8_t bmp = 0; rsl->pop_front(); j = rsl->begin(); while (j != rsl->end()) { uint16_t ipid = (*j)->_id; if (ipid > start + 8) { break; } click_chatter("%s get_recps_timeout considering bitmap entry for %u, recped is %u, timedout size is %u", id().cc(), ipid, (*j)->_recped, _timedout.size()); if ((*j)->_recped == 0) { (*j)->_recped = 1; update_timeout_list((*j)->_timeout, src); click_chatter("%s Time Taken for reception report: %u", id().cc(), (now - (*j)->_timeout + _recp_timeout)); } int offset; if (ipid > start) { offset = ipid - start - 1; } else { offset = uint32_t(ipid) + uint32_t(1 << 16) - uint32_t(start); } bmp = bmp | (0x01 << offset); j++; } click_chatter("adding recpunit entry with src %u, start %u, bitmap %#x, timedout size is %u", src.addr(), start, bmp, _timedout.size()); rv->push_back(RecpUnit(src, start, bmp)); } // got all the timed out recps here return rv;} voidListenManager::flush_expired(){ uint32_t now = Timestamp::now().msec1(); EventMap::iterator bound = _eventmap.upper_bound(now); EventMap::iterator i = _eventmap.begin(); while (i != bound) { EventList *el = (*i).second; EventList::iterator prev = el->begin(); EventList::iterator next = prev; while (next != el->end()) { const Event &e = *next; PacketState *ps = _ovhdpacks.find(e._pid); if (ps != NULL) { ps->_p->kill(); } _ovhdpacks.remove(e._pid); click_chatter("%s: do_events() killing timed out packet", id().cc()); if (prev == next) { el->pop_front(); prev = next = el->begin(); } else { ++next; el->erase_after(prev); } } if (el->empty()) { click_chatter("%s: do_events() deleting eventmap entry", id().cc()); EventMap::iterator j = i++; _eventmap.erase(j); } else { ++i; } }} WritablePacket *ListenManager::get_recps(bool qempty, int now){ flush_expired(); if (!_enable_recps) { // no recps to send return 0; } if (_pending.begin() == _pending.end()) { return 0; } SrcList nl; RecpVector* rv = get_recps_timeout(now, nl); unsigned int num_recps = (unsigned)rv->size(); if (num_recps != 0) { click_chatter("%s get_recps returned from timeout with %u recps, timedout size is %u", id().cc(), num_recps, _timedout.size()); } if ((qempty) || (num_recps >= _max_recps)) { return make_packet(rv); } // now rv wasn't big enough, look for general recps int hash_size = _pending.size(); PendingRecps::iterator i = _pending.begin(); int jumps = random() % _pending.size(); for (int x = 0; x < jumps; x++) { if (i == _pending.end()) { i = _pending.begin(); } i++; } for (int j = 0; ((j < hash_size) && (num_recps < _max_recps)); j++) { if (i == _pending.end()) { i = _pending.begin(); } IPAddress src = i.key(); // don't insert another entry for a neighbor that has already been inserted by get_recps_timeout if (nl.findp(src)) { click_chatter("%s get_recps skipping src %u, already populated by get_recps_timeout, timedout size is %u", id().cc(), src.addr(), _timedout.size()); i++; continue; } RecpStateList *rsl = i.value(); RecpStateList::iterator k; for (k = rsl->begin(); (k != rsl->end()) && (*k)->_recped; k++); if (k == rsl->end()) { continue; } uint16_t start = (*k)->_id; (*k)->_recped = 1; update_timeout_list((*k)->_timeout, src); click_chatter("%s Time Taken for reception report: %u", id().cc(), (now - (*k)->_timeout + _recp_timeout)); uint8_t bmp = 0; k++; while (k != rsl->end()) { uint16_t ipid = (*k)->_id; if (ipid > start + 8) { break; } click_chatter("%s get_recps considering bitmap entry for %u, acked is %u, timedout size is %u", id().cc(), ipid, (*k)->_recped, _timedout.size()); if ((*k)->_recped == 0) { (*k)->_recped = 1; // update the entry for this neighbor in the timedout hash update_timeout_list((*k)->_timeout, src); click_chatter("%s Time Taken for reception report: %u", id().cc(), (now - (*k)->_timeout + _recp_timeout)); } int offset; if (ipid > start) { offset = ipid - start - 1; } else { offset = uint32_t(ipid) + uint32_t(1 << 16) - uint32_t(start); } bmp = bmp | (0x01 << offset); k++; // move on to the next ack } click_chatter("%s get_recps adding ackunit entry with src %u, start %u, bitmap %#x, timedout size is %u", id().cc(), src.addr(), start, bmp, _timedout.size()); rv->push_back(RecpUnit(src, start, bmp)); num_recps++; i++; } return make_packet(rv);} WritablePacket *ListenManager::make_packet(RecpVector *rv){ int nentries = rv->size(); if (nentries == 0) { return 0; } struct click_enc_recp *recph; uint8_t hlen = click_enc_recp::get_hlen(nentries); WritablePacket *p = Packet::make(hlen); recph = (struct click_enc_recp *)p->data(); memset(recph, 0, hlen); recph->set_nentries(nentries); int idx = 0; click_chatter("%s make_packet adding %u recph entries, timedout size is %u", id().cc(), nentries, _timedout.size()); for (RecpVector::const_iterator i = rv->begin(); i != rv->end(); i++, idx++) { recph->set_entry(idx, (*i)._src.addr(), (*i)._id, (*i)._bmp); StringAccum sa; sa << "make reception packet adding entry " << idx << "source " << (*i)._src << "ipid " << (*i)._id << "src u32 " << (*i)._src.addr(); click_chatter("%s %s", id().cc(), sa.c_str()); sa.clear(); } delete rv; return p;}voidListenManager::check_packet(Packet *p){ // has an recp header, try to separate that into another precpet struct click_enc_recp *recph = (struct click_enc_recp *)(p->data()); // uint8_t hlen = recph->get_hlen(recph->nentries()); for (uint16_t i = 0; i < recph->nentries(); i++) { IPAddress src = IPAddress(recph->get_entry_src(i)); uint16_t ipid = recph->get_entry_id(i); uint8_t bmap = recph->get_entry_bmap(i); StringAccum sa; sa << "push() matched reception report for src " << src << ", ipid " << ntohs(ipid) << " src u32 " << recph->get_entry_src(i); click_chatter("%s: %s, bmap %x at %u", id().cc(), sa.c_str(), (uint32_t)bmap, Timestamp::now().msec1()); } return;} uint32_tListenManager::get_next_recp_time(){ TimeoutList::iterator i = _timedout.begin(); if (i != _timedout.end()) { return (*i).first; } return 0;} #include <click/bighashmap.cc>#include <click/vector.cc>#if EXPLICIT_TEMPLATE_INSTANCEStemplate class Vector<RecpUnit>;template class HashMap<IPAddress, RecpStateList *>;template class HashMap<IPAddress, uint8_t>;#endifCLICK_ENDDECLSEXPORT_ELEMENT(ListenManager)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -