IBR-DTNSuite  0.10
RoutingExtension.cpp
Go to the documentation of this file.
1 /*
2  * RoutingExtension.cpp
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
23 #include "routing/BaseRouter.h"
24 #include "core/BundleCore.h"
25 #include <ibrcommon/Logger.h>
26 
27 namespace dtn
28 {
29  namespace routing
30  {
31  BaseRouter *RoutingExtension::_router = NULL;
32  const std::string RoutingExtension::TAG = "RoutingExtension";
33 
38  { }
39 
41  { }
42 
44  {
45  return *_router;
46  }
47 
54  {
55  // acquire the transfer of this bundle, could throw already in transit or no resource left exception
56  {
57  // lock the list of neighbors
58  ibrcommon::MutexLock l(_router->getNeighborDB());
59 
60  // get the neighbor entry for the next hop
61  NeighborDatabase::NeighborEntry &entry = _router->getNeighborDB().get(destination);
62 
63  // acquire the transfer, could throw already in transit or no resource left exception
64  entry.acquireTransfer(meta);
65  }
66 
67  try {
68  // create a new bundle transfer object
69  dtn::net::BundleTransfer transfer(destination, meta);
70 
71  // transfer the bundle to the next hop
73 
74  IBRCOMMON_LOGGER_DEBUG_TAG(RoutingExtension::TAG, 20) << "bundle " << meta.toString() << " queued for " << destination.getString() << IBRCOMMON_LOGGER_ENDL;
75  } catch (const dtn::core::P2PDialupException&) {
76  // lock the list of neighbors
77  ibrcommon::MutexLock l(_router->getNeighborDB());
78 
79  // get the neighbor entry for the next hop
80  NeighborDatabase::NeighborEntry &entry = _router->getNeighborDB().get(destination);
81 
82  // release the transfer
83  entry.releaseTransfer(meta);
84 
85  // and abort the query
87  }
88  }
89 
91  {
92  if (eid.getApplication() == "routing")
93  {
94  return true;
95  }
96  else if ((eid.getScheme() == dtn::data::EID::CBHE_SCHEME) && (eid.getApplication() == "50"))
97  {
98  return true;
99  }
100 
101  return false;
102  }
103 
104  } /* namespace routing */
105 } /* namespace dtn */