|
1 /* |
|
2 * Copyright 2004-2006 Intel Corporation |
|
3 * |
|
4 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 * you may not use this file except in compliance with the License. |
|
6 * You may obtain a copy of the License at |
|
7 * |
|
8 * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 * |
|
10 * Unless required by applicable law or agreed to in writing, software |
|
11 * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 * See the License for the specific language governing permissions and |
|
14 * limitations under the License. |
|
15 */ |
|
16 |
|
17 #ifdef HAVE_CONFIG_H |
|
18 # include <dtn-config.h> |
|
19 #endif |
|
20 |
|
21 #include "BundleRouter.h" |
|
22 #include "RouteTable.h" |
|
23 #include "bundling/Bundle.h" |
|
24 #include "bundling/BundleActions.h" |
|
25 #include "bundling/BundleDaemon.h" |
|
26 #include "bundling/BundleList.h" |
|
27 #include "contacts/Contact.h" |
|
28 #include "reg/Registration.h" |
|
29 #include <stdlib.h> |
|
30 |
|
31 #include "FloodBundleRouter.h" |
|
32 |
|
33 namespace dtn { |
|
34 |
|
35 //---------------------------------------------------------------------- |
|
36 FloodBundleRouter::FloodBundleRouter() |
|
37 : TableBasedRouter("FloodBundleRouter", "flood"), |
|
38 all_bundles_("FloodBundleRouter::all_bundles"), |
|
39 all_eids_(EndpointIDPattern::WILDCARD_EID()) |
|
40 { |
|
41 log_info("FloodBundleRouter initialized"); |
|
42 ASSERT(all_eids_.valid()); |
|
43 } |
|
44 |
|
45 //---------------------------------------------------------------------- |
|
46 void |
|
47 FloodBundleRouter::initialize() |
|
48 { |
|
49 TableBasedRouter::initialize(); |
|
50 config_.add_nexthop_routes_ = false; |
|
51 } |
|
52 |
|
53 //---------------------------------------------------------------------- |
|
54 void |
|
55 FloodBundleRouter::handle_bundle_received(BundleReceivedEvent* event) |
|
56 { |
|
57 Bundle* bundle = event->bundleref_.object(); |
|
58 log_debug("bundle received *%p", bundle); |
|
59 all_bundles_.push_back(bundle); |
|
60 |
|
61 TableBasedRouter::handle_bundle_received(event); |
|
62 } |
|
63 |
|
64 //---------------------------------------------------------------------- |
|
65 void |
|
66 FloodBundleRouter::handle_link_created(LinkCreatedEvent* event) |
|
67 { |
|
68 TableBasedRouter::handle_link_created(event); |
|
69 |
|
70 LinkRef link = event->link_; |
|
71 ASSERT(link != NULL); |
|
72 ASSERT(!link->isdeleted()); |
|
73 |
|
74 log_debug("FloodBundleRouter::handle_link_created: " |
|
75 "link_created *%p", link.object()); |
|
76 |
|
77 RouteEntry* entry = new RouteEntry(all_eids_, link); |
|
78 entry->set_action(ForwardingInfo::COPY_ACTION); |
|
79 |
|
80 // adds the route to the table and checks for bundles that may |
|
81 // need to be sent to the new link |
|
82 add_route(entry); |
|
83 } |
|
84 |
|
85 //---------------------------------------------------------------------- |
|
86 bool |
|
87 FloodBundleRouter::can_delete_bundle(const BundleRef& bundle) |
|
88 { |
|
89 (void)bundle; |
|
90 return false; |
|
91 } |
|
92 |
|
93 //---------------------------------------------------------------------- |
|
94 void |
|
95 FloodBundleRouter::delete_bundle(const BundleRef& bundle) |
|
96 { |
|
97 log_debug("bundle_expired *%p", bundle.object()); |
|
98 all_bundles_.erase(bundle); |
|
99 } |
|
100 |
|
101 } // namespace dtn |