52 const std::string ProphetRoutingExtension::TAG =
"ProphetRoutingExtension";
57 : _deliveryPredictabilityMap(time_unit, beta, gamma),
58 _forwardingStrategy(strategy), _next_exchange_timeout(next_exchange_timeout), _next_exchange_timestamp(0),
59 _p_encounter_max(p_encounter_max), _p_encounter_first(p_encounter_first),
60 _p_first_threshold(p_first_threshold), _delta(delta), _i_typ(i_typ)
79 delete _forwardingStrategy;
129 updateNeighbor(neighbor_node, neighbor_dp_map);
130 }
catch (std::exception&) { }
139 (**this).setKnown(*it);
145 _acknowledgementSet.
merge(neighbor_ack_set);
155 : _ackset(neighbor_ack_set)
158 virtual ~BundleFilter() {}
168 if(!_ackset.has(meta))
176 } filter(neighbor_ack_set);
179 storage.
get(filter, removeList);
181 for (std::list<dtn::data::MetaBundle>::const_iterator it = removeList.begin(); it != removeList.end(); ++it)
199 }
catch (std::exception&) { }
205 _taskqueue.push(
new SearchNextBundleTask( peer ) );
214 }
catch (
const std::bad_cast &ex) { };
222 for (std::set<dtn::core::Node>::const_iterator iter = nl.begin(); iter != nl.end(); ++iter)
229 eventDataChanged(n.
getEID());
248 if ((_next_exchange_timestamp > 0) && (_next_exchange_timestamp < now))
250 _taskqueue.push(
new NextExchangeTask() );
253 _next_exchange_timestamp = now + _next_exchange_timeout;
256 }
catch (
const std::bad_cast&) { };
264 _taskqueue.push(
new SearchNextBundleTask( handshake.
peer ) );
269 _taskqueue.push(
new SearchNextBundleTask( handshake.
peer ) );
272 }
catch (
const std::bad_cast&) { };
281 _acknowledgementSet.add(purge.
bundle);
286 }
catch (
const std::bad_cast&) { }
341 void ProphetRoutingExtension::ProphetRoutingExtension::run() throw ()
347 : _entry(entry), _strategy(strategy), _dpm(dpm), _neighbors(neighbors)
350 virtual ~BundleFilter() {};
352 virtual dtn::data::Size limit()
const throw () {
return _entry.getFreeTransferSlots(); };
357 if (meta.hopcount == 0)
378 if (_entry.eid == meta.destination.getNode())
389 if (_neighbors.find(n) != _neighbors.end())
398 if (_dpm.get(meta.source.getNode()) <= 0.0)
return false;
407 if (_entry.has(meta,
true))
418 return _strategy.shallForward(_dpm, meta);
425 const NeighborDatabase::NeighborEntry &_entry;
426 const ForwardingStrategy &_strategy;
427 const DeliveryPredictabilityMap &_dpm;
428 const std::set<dtn::core::Node> &_neighbors;
435 std::set<dtn::core::Node> neighbors;
440 Task *t = _taskqueue.getnpop(
true);
441 std::auto_ptr<Task> killer(t);
452 SearchNextBundleTask &task =
dynamic_cast<SearchNextBundleTask&
>(*t);
456 NeighborDatabase &db = (**this).getNeighborDB();
459 NeighborDatabase::NeighborEntry &entry = db.get(task.eid,
true);
462 if (!entry.isTransferThresholdReached())
463 throw NeighborDatabase::NoMoreTransfersAvailable();
466 const DeliveryPredictabilityMap &dpm = entry.getDataset<DeliveryPredictabilityMap>();
477 const BundleFilter filter(entry, *_forwardingStrategy, dpm, neighbors);
484 (**this).getSeeker().get(filter, list);
485 }
catch (
const NeighborDatabase::DatasetNotAvailableException&) {
488 (**this).doHandshake(task.eid);
491 (**this).doHandshake(task.eid);
495 for (std::list<dtn::data::MetaBundle>::const_iterator iter = list.begin(); iter != list.end(); ++iter)
500 transferTo(task.eid, meta);
501 }
catch (
const NeighborDatabase::AlreadyInTransitException&) { };
503 }
catch (
const NeighborDatabase::NoMoreTransfersAvailable &ex) {
505 }
catch (
const NeighborDatabase::NeighborNotAvailableException &ex) {
509 }
catch (
const std::bad_cast&) { }
516 dynamic_cast<NextExchangeTask&
>(*t);
519 std::set<dtn::core::Node>::const_iterator it;
520 for(it = neighbors.begin(); it != neighbors.end(); ++it)
523 (**this).doHandshake(it->getEID());
526 }
catch (
const std::bad_cast&) { }
531 }
catch (
const std::exception &ex) {
545 float ProphetRoutingExtension::p_encounter(
const dtn::data::EID &neighbor)
const
547 age_map::const_iterator it = _ageMap.find(neighbor);
548 if(it == _ageMap.end())
551 return _p_encounter_max;
556 #ifdef __DEVELOPMENT_ASSERTIONS__
557 assert(currentTime >= it->second &&
"the ageMap timestamp should be smaller than the current timestamp");
559 if(time_diff > _i_typ)
561 return _p_encounter_max;
565 return _p_encounter_max * time_diff.
get<
float>() / static_cast<float>(_i_typ);
569 void ProphetRoutingExtension::updateNeighbor(
const dtn::data::EID &neighbor,
const DeliveryPredictabilityMap& neighbor_dp_map)
581 float neighbor_dp = _deliveryPredictabilityMap.
get(neighbor);
583 if (neighbor_dp < _p_first_threshold)
585 neighbor_dp = _p_encounter_first;
589 neighbor_dp += (1 - _delta - neighbor_dp) * p_encounter(neighbor);
592 _deliveryPredictabilityMap.
set(neighbor, neighbor_dp);
593 }
catch (
const DeliveryPredictabilityMap::ValueNotFoundException&) {
594 _deliveryPredictabilityMap.
set(neighbor, _p_encounter_first);
600 _deliveryPredictabilityMap.
update(neighbor, neighbor_dp_map, _p_encounter_first);
603 void ProphetRoutingExtension::age()
605 _deliveryPredictabilityMap.
age(_p_first_threshold);
608 ProphetRoutingExtension::SearchNextBundleTask::SearchNextBundleTask(
const dtn::data::EID &eid)
613 ProphetRoutingExtension::SearchNextBundleTask::~SearchNextBundleTask()
617 std::string ProphetRoutingExtension::SearchNextBundleTask::toString()
const
619 return "SearchNextBundleTask: " + eid.
getString();
622 ProphetRoutingExtension::NextExchangeTask::NextExchangeTask()
626 ProphetRoutingExtension::NextExchangeTask::~NextExchangeTask()
630 std::string ProphetRoutingExtension::NextExchangeTask::toString()
const
632 return "NextExchangeTask";
645 return neighborDPIsGreater(neighbor_dpm, bundle.
destination);
659 nf_map::iterator nf_it = _NF_map.find(
id);
661 if (nf_it == _NF_map.end()) {
662 nf_it = _NF_map.insert(std::make_pair(
id, 0)).first;
672 nf_map::const_iterator nf_it = _NF_map.find(bundle);
673 if(nf_it != _NF_map.end()) {
677 if (NF > _NF_max)
return false;
679 return neighborDPIsGreater(neighbor_dpm, bundle.
destination);