IBR-DTN  1.0.0
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/BundleCore.h"
25 #include <ibrdtn/data/MetaBundle.h>
26 
27 namespace dtn
28 {
29  namespace core
30  {
31  using namespace dtn::data;
32 
34  {
36  }
37 
39  {
41  }
42 
43  void StatusReportGenerator::createStatusReport(const dtn::data::MetaBundle &b, StatusReportBlock::TYPE type, StatusReportBlock::REASON_CODE reason)
44  {
45  // create a new bundle
46  Bundle bundle;
47 
48  // create a new statusreport block
49  StatusReportBlock report;
50 
52 
53  // get the flags and set the status flag
54  report.status |= static_cast<char>(type);
55 
56  // set the reason code
57  report.reasoncode |= static_cast<char>(reason);
58 
59  switch (type)
60  {
62  report.timeof_receipt.set();
63  break;
64 
66  report.timeof_custodyaccept.set();
67  break;
68 
70  report.timeof_forwarding.set();
71  break;
72 
74  report.timeof_delivery.set();
75  break;
76 
78  report.timeof_deletion.set();
79  break;
80 
81  default:
82 
83  break;
84  }
85 
86  // set source and destination
89  bundle.destination = b.reportto;
90 
91  // set lifetime to the origin bundle lifetime
92  bundle.lifetime = b.lifetime;
93 
94  // sign the report if the reference was signed too
97 
98  // set bundle parameter
99  report.bundleid = b;
100 
102  report.write(payload);
103 
105  }
106 
108  {
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  }
154  }
155 }
static void inject(const dtn::data::EID &source, dtn::data::Bundle &bundle)
Definition: BundleCore.cpp:706
dtn::data::BundleID bundleid
static dtn::data::EID local
Definition: BundleCore.h:79
bool get(dtn::data::PrimaryBlock::FLAGS flag) const
Definition: MetaBundle.cpp:160
static void add(EventReceiver< E > *receiver)
virtual void write(dtn::data::PayloadBlock &p) const
static void remove(const EventReceiver< E > *receiver)
void raiseEvent(const dtn::core::BundleEvent &evt)
T & push_back()
Definition: Bundle.h:180
dtn::data::EID reportto
Definition: MetaBundle.h:61
void set(FLAGS flag, bool value)
dtn::data::EID source
Definition: BundleID.h:53