51 const std::string StaticRoutingExtension::TAG =
"StaticRoutingExtension";
63 for (std::list<StaticRoute*>::iterator iter = _routes.begin();
64 iter != _routes.end(); ++iter)
82 : _entry(entry), _routes(routes)
85 virtual ~BundleFilter() {};
87 virtual dtn::data::Size limit()
const throw () {
return _entry.getFreeTransferSlots(); };
112 if (_entry.has(meta))
118 for (std::list<const StaticRoute*>::const_iterator iter = _routes.begin();
119 iter != _routes.end(); ++iter)
134 const std::list<const StaticRoute*> &_routes;
140 for (std::multimap<std::string, std::string>::const_iterator iter = routes.begin(); iter != routes.end(); ++iter)
151 std::list<const StaticRoute*> routes;
154 Task *t = _taskqueue.getnpop(
true);
155 std::auto_ptr<Task> killer(t);
160 SearchNextBundleTask &task =
dynamic_cast<SearchNextBundleTask&
>(*t);
166 for (std::list<StaticRoute*>::const_iterator iter = _routes.begin();
167 iter != _routes.end(); ++iter)
173 routes.push_back(route);
190 BundleFilter filter(entry, routes);
197 (**this).getSeeker().get(filter, list);
201 for (std::list<dtn::data::MetaBundle>::const_iterator iter = list.begin(); iter != list.end(); ++iter)
215 }
catch (
const std::bad_cast&) { };
218 const ProcessBundleTask &task =
dynamic_cast<ProcessBundleTask&
>(*t);
222 for (std::list<StaticRoute*>::const_iterator iter = _routes.begin();
223 iter != _routes.end(); ++iter)
228 if (route.
match(task.bundle.destination))
238 }
catch (
const std::bad_cast&) { };
241 const RouteChangeTask &task =
dynamic_cast<RouteChangeTask&
>(*t);
244 for (std::list<StaticRoute*>::iterator iter = _routes.begin();
245 iter != _routes.end();)
248 if (route->
equals(*task.route))
251 _routes.erase(iter++);
259 if (task.type == RouteChangeTask::ROUTE_ADD)
261 _routes.push_back(task.route);
262 _taskqueue.push(
new SearchNextBundleTask(task.route->getDestination()) );
264 if (task.route->getExpiration() > 0)
267 if (next_expire == 0 || next_expire > task.route->getExpiration())
269 next_expire = task.route->getExpiration();
281 }
catch (
const bad_cast&) { };
284 dynamic_cast<ClearRoutesTask&
>(*t);
287 for (std::list<StaticRoute*>::iterator iter = _routes.begin();
288 iter != _routes.end(); ++iter)
297 }
catch (
const bad_cast&) { };
300 const ExpireTask &task =
dynamic_cast<ExpireTask&
>(*t);
306 for (std::list<StaticRoute*>::iterator iter = _routes.begin();
307 iter != _routes.end();)
315 _routes.erase(iter++);
319 if ((next_expire == 0) || (next_expire > route->
getExpiration()))
327 }
catch (
const bad_cast&) { };
329 }
catch (
const std::exception &ex) {
340 _taskqueue.push(
new SearchNextBundleTask(peer) );
345 _taskqueue.push(
new ProcessBundleTask(meta, peer) );
356 if ((next_expire != 0) && (next_expire < monotonic))
358 _taskqueue.push(
new ExpireTask( monotonic ) );
361 }
catch (
const bad_cast&) { };
369 _taskqueue.push(
new ClearRoutesTask() );
375 if (route.
pattern.length() > 0)
393 _taskqueue.push(
new RouteChangeTask( RouteChangeTask::ROUTE_ADD, r ) );
397 _taskqueue.push(
new RouteChangeTask( RouteChangeTask::ROUTE_DEL, r ) );
405 }
catch (
const bad_cast&) { };
441 : _nexthop(nexthop), _match(match), expiretime(et)
445 StaticRoutingExtension::EIDRoute::~EIDRoute()
449 bool StaticRoutingExtension::EIDRoute::match(
const dtn::data::EID &eid)
const
451 return _match.sameHost(eid);
454 const dtn::data::EID& StaticRoutingExtension::EIDRoute::getDestination()
const
463 const std::string StaticRoutingExtension::EIDRoute::toString()
const
465 std::stringstream ss;
466 ss << _match.
getString() <<
" => " << _nexthop.getString();
475 void StaticRoutingExtension::EIDRoute::raiseExpired()
const
480 bool StaticRoutingExtension::EIDRoute::equals(
const StaticRoute &route)
const
483 const StaticRoutingExtension::EIDRoute &r =
dynamic_cast<const StaticRoutingExtension::EIDRoute&
>(route);
484 return (_nexthop == r._nexthop) && (_match == r._match);
485 }
catch (
const std::bad_cast&) {
492 StaticRoutingExtension::SearchNextBundleTask::SearchNextBundleTask(
const dtn::data::EID &e)
496 StaticRoutingExtension::SearchNextBundleTask::~SearchNextBundleTask()
499 std::string StaticRoutingExtension::SearchNextBundleTask::toString()
501 return "SearchNextBundleTask: " + eid.
getString();
507 : bundle(meta), origin(o)
510 StaticRoutingExtension::ProcessBundleTask::~ProcessBundleTask()
513 std::string StaticRoutingExtension::ProcessBundleTask::toString()
515 return "ProcessBundleTask: " + bundle.toString();
520 StaticRoutingExtension::ClearRoutesTask::ClearRoutesTask()
524 StaticRoutingExtension::ClearRoutesTask::~ClearRoutesTask()
528 std::string StaticRoutingExtension::ClearRoutesTask::toString()
530 return "ClearRoutesTask";
535 StaticRoutingExtension::RouteChangeTask::RouteChangeTask(CHANGE_TYPE t, StaticRoute *r)
541 StaticRoutingExtension::RouteChangeTask::~RouteChangeTask()
546 std::string StaticRoutingExtension::RouteChangeTask::toString()
548 return "RouteChangeTask: " + (*route).toString();
559 StaticRoutingExtension::ExpireTask::~ExpireTask()
564 std::string StaticRoutingExtension::ExpireTask::toString()
566 std::stringstream ss;
567 ss <<
"ExpireTask: " << timestamp.toString();