IBR-DTNSuite
0.10
Main Page
Namespaces
Classes
Files
File List
File Members
IBR-DTNSuite
Namespaces
Classes
Files
File List
daemon
src
api
core
AbstractWorker.cpp
AbstractWorker.h
BundleCore.cpp
BundleCore.h
BundleEvent.cpp
BundleEvent.h
BundleExpiredEvent.cpp
BundleExpiredEvent.h
BundleGeneratedEvent.cpp
BundleGeneratedEvent.h
BundlePurgeEvent.cpp
BundlePurgeEvent.h
CustodyEvent.cpp
CustodyEvent.h
Event.cpp
Event.h
EventDebugger.cpp
EventDebugger.h
EventDispatcher.h
EventReceiver.cpp
EventReceiver.h
EventSwitch.cpp
EventSwitch.h
FragmentManager.cpp
FragmentManager.h
GlobalEvent.cpp
GlobalEvent.h
Node.cpp
Node.h
NodeEvent.cpp
NodeEvent.h
StatusReportGenerator.cpp
StatusReportGenerator.h
TimeAdjustmentEvent.cpp
TimeAdjustmentEvent.h
TimeEvent.cpp
TimeEvent.h
WallClock.cpp
WallClock.h
net
routing
security
storage
CapsuleWorker.cpp
CapsuleWorker.h
Component.cpp
Component.h
config.h
Configuration.cpp
Configuration.h
Debugger.cpp
Debugger.h
DevNull.cpp
DevNull.h
DTNTPWorker.cpp
DTNTPWorker.h
EchoWorker.cpp
EchoWorker.h
Main.cpp
NativeDaemon.cpp
NativeDaemon.h
ibrcommon
ibrdtn
tools
File Members
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
"
23
#include "
core/StatusReportGenerator.h
"
24
#include "
core/BundleEvent.h
"
25
#include "
core/BundleGeneratedEvent.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
35
StatusReportGenerator::StatusReportGenerator
()
36
{
37
dtn::core::EventDispatcher<BundleEvent>::add
(
this
);
38
}
39
40
StatusReportGenerator::~StatusReportGenerator
()
41
{
42
dtn::core::EventDispatcher<BundleEvent>::remove
(
this
);
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
53
bundle.
set
(
dtn::data::PrimaryBlock::APPDATA_IS_ADMRECORD
,
true
);
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
{
63
case
StatusReportBlock::RECEIPT_OF_BUNDLE
:
64
report.
timeof_receipt
.
set
();
65
break
;
66
67
case
StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE
:
68
report.
timeof_custodyaccept
.
set
();
69
break
;
70
71
case
StatusReportBlock::FORWARDING_OF_BUNDLE
:
72
report.
timeof_forwarding
.
set
();
73
break
;
74
75
case
StatusReportBlock::DELIVERY_OF_BUNDLE
:
76
report.
timeof_delivery
.
set
();
77
break
;
78
79
case
StatusReportBlock::DELETION_OF_BUNDLE
:
80
report.
timeof_deletion
.
set
();
81
break
;
82
83
default
:
84
85
break
;
86
}
87
88
// set source and destination
89
bundle.
source
=
dtn::core::BundleCore::local
;
90
bundle.
set
(
dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON
,
true
);
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
102
dtn::data::PayloadBlock
&payload = bundle.
push_back
<
dtn::data::PayloadBlock
>();
103
report.
write
(payload);
104
105
dtn::core::BundleGeneratedEvent::raise
(bundle);
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
115
if
(b.
get
(
dtn::data::PrimaryBlock::APPDATA_IS_ADMRECORD
))
return
;
116
117
switch
(bundleevent.
getAction
())
118
{
119
case
BUNDLE_RECEIVED
:
120
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_RECEPTION
))
121
{
122
createStatusReport(b,
StatusReportBlock::RECEIPT_OF_BUNDLE
, bundleevent.
getReason
());
123
}
124
break
;
125
case
BUNDLE_DELETED
:
126
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_DELETION
))
127
{
128
createStatusReport(b,
StatusReportBlock::DELETION_OF_BUNDLE
, bundleevent.
getReason
());
129
}
130
break
;
131
132
case
BUNDLE_FORWARDED
:
133
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_FORWARDING
))
134
{
135
createStatusReport(b,
StatusReportBlock::FORWARDING_OF_BUNDLE
, bundleevent.
getReason
());
136
}
137
break
;
138
139
case
BUNDLE_DELIVERED
:
140
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_BUNDLE_DELIVERY
))
141
{
142
createStatusReport(b,
StatusReportBlock::DELIVERY_OF_BUNDLE
, bundleevent.
getReason
());
143
}
144
break
;
145
146
case
BUNDLE_CUSTODY_ACCEPTED
:
147
if
( b.
get
(
Bundle::REQUEST_REPORT_OF_CUSTODY_ACCEPTANCE
))
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
}
daemon
src
core
StatusReportGenerator.cpp
Generated on Mon Jul 22 2013 15:15:59 for IBR-DTNSuite by
1.8.3.1