IBR-DTNSuite  0.10
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 bundle parameter
94  report.bundleid = b;
95 
96  if (b.get(Bundle::FRAGMENT))
97  {
98  report.fragment_length = b.appdatalength;
99  report._admfield |= 1;
100  }
101 
103  report.write(payload);
104 
106  }
107 
108  void StatusReportGenerator::raiseEvent(const Event *evt) throw ()
109  {
110  try {
111  const BundleEvent &bundleevent = dynamic_cast<const BundleEvent&>(*evt);
112  const dtn::data::MetaBundle &b = bundleevent.getBundle();
113 
114  // do not generate status reports for other status reports or custody signals
116 
117  switch (bundleevent.getAction())
118  {
119  case BUNDLE_RECEIVED:
121  {
122  createStatusReport(b, StatusReportBlock::RECEIPT_OF_BUNDLE, bundleevent.getReason());
123  }
124  break;
125  case BUNDLE_DELETED:
127  {
128  createStatusReport(b, StatusReportBlock::DELETION_OF_BUNDLE, bundleevent.getReason());
129  }
130  break;
131 
132  case BUNDLE_FORWARDED:
134  {
135  createStatusReport(b, StatusReportBlock::FORWARDING_OF_BUNDLE, bundleevent.getReason());
136  }
137  break;
138 
139  case BUNDLE_DELIVERED:
141  {
142  createStatusReport(b, StatusReportBlock::DELIVERY_OF_BUNDLE, bundleevent.getReason());
143  }
144  break;
145 
148  {
149  createStatusReport(b, StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE, bundleevent.getReason());
150  }
151  break;
152 
153  default:
154  break;
155  }
156  } catch (const std::bad_cast&) { };
157  }
158  }
159 }