51 const std::string ProphetRoutingExtension::TAG =
"ProphetRoutingExtension";
56 : _deliveryPredictabilityMap(time_unit, beta, gamma),
57 _forwardingStrategy(strategy), _next_exchange_timeout(next_exchange_timeout), _next_exchange_timestamp(0),
58 _p_encounter_max(p_encounter_max), _p_encounter_first(p_encounter_first),
59 _p_first_threshold(p_first_threshold), _delta(delta), _i_typ(i_typ)
78 delete _forwardingStrategy;
125 updateNeighbor(neighbor_node);
140 _deliveryPredictabilityMap.
update(neighbor_node, neighbor_dp_map, _p_encounter_first);
142 }
catch (std::exception&) { }
151 (**this).setKnown(*it);
157 _acknowledgementSet.
merge(neighbor_ack_set);
167 : _ackset(neighbor_ack_set)
170 virtual ~BundleFilter() {}
180 if(!_ackset.has(meta))
188 } filter(neighbor_ack_set);
191 storage.
get(filter, removeList);
193 for (std::list<dtn::data::MetaBundle>::const_iterator it = removeList.begin(); it != removeList.end(); ++it)
211 }
catch (std::exception&) { }
226 if ((_next_exchange_timestamp > 0) && (_next_exchange_timestamp < time.
getUnixTimestamp()))
228 _taskqueue.push(
new NextExchangeTask() );
231 _next_exchange_timestamp = time.
getUnixTimestamp() + _next_exchange_timeout;
234 }
catch (
const std::bad_cast&) { };
243 for (std::set<dtn::core::Node>::const_iterator iter = nl.begin(); iter != nl.end(); ++iter)
249 _taskqueue.push(
new SearchNextBundleTask( n.
getEID() ) );
253 }
catch (
const std::bad_cast&) { };
262 _taskqueue.push(
new SearchNextBundleTask( n.
getEID() ) );
266 _taskqueue.push(
new SearchNextBundleTask( n.
getEID() ) );
270 }
catch (
const std::bad_cast&) { };
278 _taskqueue.push(
new SearchNextBundleTask(ce.
peer) );
281 }
catch (
const std::bad_cast&) { };
289 _taskqueue.push(
new SearchNextBundleTask( handshake.
peer ) );
294 _taskqueue.push(
new SearchNextBundleTask( handshake.
peer ) );
297 }
catch (
const std::bad_cast&) { };
304 _taskqueue.push(
new SearchNextBundleTask( aborted.
getPeer() ) );
307 }
catch (
const std::bad_cast&) { };
321 _acknowledgementSet.add(meta);
328 }
catch (
const std::bad_cast &ex) { };
331 _taskqueue.push(
new SearchNextBundleTask( completed.
getPeer() ) );
333 }
catch (
const std::bad_cast&) { };
380 void ProphetRoutingExtension::ProphetRoutingExtension::run() throw ()
386 : _entry(entry), _strategy(strategy), _dpm(dpm)
389 virtual ~BundleFilter() {};
391 virtual dtn::data::Size limit()
const throw () {
return _entry.getFreeTransferSlots(); };
396 if (meta.hopcount == 0)
403 if (isRouting(meta.source))
424 if (_entry.eid == meta.destination.getNode())
432 if (_entry.has(meta,
true))
443 return _strategy.shallForward(_dpm, meta);
450 const NeighborDatabase::NeighborEntry &_entry;
451 const ForwardingStrategy &_strategy;
452 const DeliveryPredictabilityMap &_dpm;
460 Task *t = _taskqueue.getnpop(
true);
461 std::auto_ptr<Task> killer(t);
472 SearchNextBundleTask &task =
dynamic_cast<SearchNextBundleTask&
>(*t);
476 NeighborDatabase &db = (**this).getNeighborDB();
479 NeighborDatabase::NeighborEntry &entry = db.get(task.eid);
482 if (!entry.isTransferThresholdReached())
483 throw NeighborDatabase::NoMoreTransfersAvailable();
486 const DeliveryPredictabilityMap &dpm = entry.getDataset<DeliveryPredictabilityMap>();
489 BundleFilter filter(entry, *_forwardingStrategy, dpm);
496 (**this).getSeeker().get(filter, list);
497 }
catch (
const NeighborDatabase::DatasetNotAvailableException&) {
500 (**this).doHandshake(task.eid);
503 (**this).doHandshake(task.eid);
507 for (std::list<dtn::data::MetaBundle>::const_iterator iter = list.begin(); iter != list.end(); ++iter)
512 transferTo(task.eid, meta);
513 }
catch (
const NeighborDatabase::AlreadyInTransitException&) { };
515 }
catch (
const NeighborDatabase::NoMoreTransfersAvailable &ex) {
517 }
catch (
const NeighborDatabase::NeighborNotAvailableException &ex) {
521 }
catch (
const std::bad_cast&) { }
528 dynamic_cast<NextExchangeTask&
>(*t);
531 std::set<dtn::core::Node>::const_iterator it;
532 for(it = neighbors.begin(); it != neighbors.end(); ++it)
535 (**this).doHandshake(it->getEID());
538 }
catch (
const std::bad_cast&) { }
543 }
catch (
const std::exception &ex) {
557 float ProphetRoutingExtension::p_encounter(
const dtn::data::EID &neighbor)
const
559 age_map::const_iterator it = _ageMap.find(neighbor);
560 if(it == _ageMap.end())
563 return _p_encounter_max;
568 #ifdef __DEVELOPMENT_ASSERTIONS__
569 assert(currentTime >= it->second &&
"the ageMap timestamp should be smaller than the current timestamp");
571 if(time_diff > _i_typ)
573 return _p_encounter_max;
577 return _p_encounter_max *
static_cast<float>(time_diff.
get<
size_t>() / _i_typ);
581 void ProphetRoutingExtension::updateNeighbor(
const dtn::data::EID &neighbor)
587 float neighbor_dp = _deliveryPredictabilityMap.
get(neighbor);
589 if (neighbor_dp < _p_first_threshold)
591 neighbor_dp = _p_encounter_first;
595 neighbor_dp += (1 - _delta - neighbor_dp) * p_encounter(neighbor);
598 _deliveryPredictabilityMap.
set(neighbor, neighbor_dp);
599 }
catch (
const DeliveryPredictabilityMap::ValueNotFoundException&) {
600 _deliveryPredictabilityMap.
set(neighbor, _p_encounter_first);
606 void ProphetRoutingExtension::age()
608 _deliveryPredictabilityMap.
age(_p_first_threshold);
611 ProphetRoutingExtension::SearchNextBundleTask::SearchNextBundleTask(
const dtn::data::EID &eid)
616 ProphetRoutingExtension::SearchNextBundleTask::~SearchNextBundleTask()
620 std::string ProphetRoutingExtension::SearchNextBundleTask::toString()
const
622 return "SearchNextBundleTask: " + eid.
getString();
625 ProphetRoutingExtension::NextExchangeTask::NextExchangeTask()
629 ProphetRoutingExtension::NextExchangeTask::~NextExchangeTask()
633 std::string ProphetRoutingExtension::NextExchangeTask::toString()
const
635 return "NextExchangeTask";
648 return neighborDPIsGreater(neighbor_dpm, bundle.
destination);
662 nf_map::iterator nf_it = _NF_map.find(
id);
664 if (nf_it == _NF_map.end()) {
665 nf_it = _NF_map.insert(std::make_pair(
id, 0)).first;
675 nf_map::const_iterator nf_it = _NF_map.find(bundle);
676 if(nf_it != _NF_map.end()) {
680 if (NF > _NF_max)
return false;
682 return neighborDPIsGreater(neighbor_dpm, bundle.
destination);