IBR-DTNSuite  0.12
StatusReportGenerator.cpp
Go to the documentation of this file.
1 /*
2  * StatusReportGenerator.cpp
3  *
4  * Copyright (C) 2011 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 
22 #include "core/EventDispatcher.h"
24 #include "core/BundleEvent.h"
26 #include "core/BundleCore.h"
27 #include <ibrdtn/data/MetaBundle.h>
28 
29 namespace dtn
30 {
31  namespace core
32  {
33  using namespace dtn::data;
34 
36  {
38  }
39 
41  {
43  }
44 
45  void StatusReportGenerator::createStatusReport(const dtn::data::MetaBundle &b, StatusReportBlock::TYPE type, StatusReportBlock::REASON_CODE reason)
46  {
47  // create a new bundle
48  Bundle bundle;
49 
50  // create a new statusreport block
51  StatusReportBlock report;
52 
54 
55  // get the flags and set the status flag
56  report.status |= static_cast<char>(type);
57 
58  // set the reason code
59  report.reasoncode |= static_cast<char>(reason);
60 
61  switch (type)
62  {
64  report.timeof_receipt.set();
65  break;
66 
68  report.timeof_custodyaccept.set();
69  break;
70 
72  report.timeof_forwarding.set();
73  break;
74 
76  report.timeof_delivery.set();
77  break;
78 
80  report.timeof_deletion.set();
81  break;
82 
83  default:
84 
85  break;
86  }
87 
88  // set source and destination
91  bundle.destination = b.reportto;
92 
93  // set lifetime to the origin bundle lifetime
94  bundle.lifetime = b.lifetime;
95 
96  // set bundle parameter
97  report.bundleid = b;
98 
100  report.write(payload);
101 
103  }
104 
106  {
107  try {
108  const BundleEvent &bundleevent = dynamic_cast<const BundleEvent&>(*evt);
109  const dtn::data::MetaBundle &b = bundleevent.getBundle();
110 
111  // do not generate status reports for other status reports or custody signals
113 
114  switch (bundleevent.getAction())
115  {
116  case BUNDLE_RECEIVED:
118  {
119  createStatusReport(b, StatusReportBlock::RECEIPT_OF_BUNDLE, bundleevent.getReason());
120  }
121  break;
122  case BUNDLE_DELETED:
124  {
125  createStatusReport(b, StatusReportBlock::DELETION_OF_BUNDLE, bundleevent.getReason());
126  }
127  break;
128 
129  case BUNDLE_FORWARDED:
131  {
132  createStatusReport(b, StatusReportBlock::FORWARDING_OF_BUNDLE, bundleevent.getReason());
133  }
134  break;
135 
136  case BUNDLE_DELIVERED:
138  {
139  createStatusReport(b, StatusReportBlock::DELIVERY_OF_BUNDLE, bundleevent.getReason());
140  }
141  break;
142 
145  {
146  createStatusReport(b, StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE, bundleevent.getReason());
147  }
148  break;
149 
150  default:
151  break;
152  }
153  } catch (const std::bad_cast&) { };
154  }
155  }
156 }