IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
IBR-DTNSuite
Namespaces
Classes
Files
File List
daemon
ibrcommon
ibrdtn
ibrdtn
api
data
AdministrativeBlock.cpp
AdministrativeBlock.h
AgeBlock.cpp
AgeBlock.h
Block.cpp
Block.h
Bundle.cpp
Bundle.h
BundleBuilder.cpp
BundleBuilder.h
BundleFragment.cpp
BundleFragment.h
BundleID.cpp
BundleID.h
BundleList.cpp
BundleList.h
BundleMerger.cpp
BundleMerger.h
BundleSet.cpp
BundleSet.h
BundleSetImpl.cpp
BundleSetImpl.h
BundleString.cpp
BundleString.h
CompressedPayloadBlock.cpp
CompressedPayloadBlock.h
CustodySignalBlock.cpp
CustodySignalBlock.h
Dictionary.cpp
Dictionary.h
DTNTime.cpp
DTNTime.h
EID.cpp
EID.h
Endianess.cpp
Endianess.h
Exceptions.h
ExtensionBlock.cpp
ExtensionBlock.h
MemoryBundleSet.cpp
MemoryBundleSet.h
MetaBundle.cpp
MetaBundle.h
Number.h
PayloadBlock.cpp
PayloadBlock.h
PrimaryBlock.cpp
PrimaryBlock.h
SchedulingBlock.cpp
SchedulingBlock.h
ScopeControlHopLimitBlock.cpp
ScopeControlHopLimitBlock.h
SDNV.cpp
SDNV.h
Serializer.cpp
Serializer.h
StatusReportBlock.cpp
StatusReportBlock.h
StreamBlock.cpp
StreamBlock.h
TrackingBlock.cpp
TrackingBlock.h
security
streams
utils
config.h
dummy.cpp
ibrdtn.h
tools
File Members
CustodySignalBlock.cpp
Go to the documentation of this file.
1
/*
2
* CustodySignalBlock.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 "
ibrdtn/data/Bundle.h
"
23
#include "
ibrdtn/data/CustodySignalBlock.h
"
24
#include "
ibrdtn/data/BundleString.h
"
25
#include <stdlib.h>
26
#include <sstream>
27
28
namespace
dtn
29
{
30
namespace
data
31
{
32
CustodySignalBlock::CustodySignalBlock
()
33
: custody_accepted(false), reason(NO_ADDITIONAL_INFORMATION), timeofsignal()
34
{
35
}
36
37
CustodySignalBlock::~CustodySignalBlock
()
38
{
39
}
40
41
void
CustodySignalBlock::read
(
const
dtn::data::PayloadBlock
&p)
throw
(
WrongRecordException
)
42
{
43
ibrcommon::BLOB::Reference
r = p.getBLOB();
44
ibrcommon::BLOB::iostream
stream = r.
iostream
();
45
46
char
admfield;
47
(*stream).get(admfield);
48
49
// check type field
50
if
((admfield >> 4) != 2)
throw
WrongRecordException
();
51
52
char
status = 0;
53
(*stream).get(status);
54
55
// decode custody acceptance
56
custody_accepted = (status & 0x01);
57
58
// decode reason flag
59
reason =
REASON_CODE
(status >> 1);
60
61
if
( admfield & 0x01 )
62
{
63
bundleid.setFragment(
true
);
64
65
(*stream) >> bundleid.fragmentoffset;
66
67
dtn::data::Number
tmp;
68
(*stream) >> tmp;
69
bundleid.setPayloadLength(tmp.get<
dtn::data::Length
>());
70
}
71
72
(*stream) >> timeofsignal;
73
(*stream) >> bundleid.timestamp;
74
(*stream) >> bundleid.sequencenumber;
75
76
BundleString
source;
77
(*stream) >> source;
78
bundleid.source =
EID
(source);
79
}
80
81
void
CustodySignalBlock::write
(
dtn::data::PayloadBlock
&p)
const
82
{
83
ibrcommon::BLOB::Reference
r = p.
getBLOB
();
84
ibrcommon::BLOB::iostream
stream = r.
iostream
();
85
86
// clear the whole data first
87
stream.
clear
();
88
89
char
admfield =
bundleid
.
isFragment
() ? 33 : 32;
90
91
// write the content
92
(*stream).put(admfield);
93
94
// encode reason flag
95
char
status =
static_cast<
char
>
(
reason
<< 1);
96
97
// encode custody acceptance
98
if
(
custody_accepted
) status |= 0x01;
99
100
// write the status byte
101
(*stream).put(status);
102
103
if
(
bundleid
.
isFragment
() )
104
{
105
(*stream) <<
bundleid
.
fragmentoffset
;
106
(*stream) <<
dtn::data::Number
(
bundleid
.
getPayloadLength
());
107
}
108
109
BundleString
sourceid(
bundleid
.
source
.
getString
());
110
111
(*stream) <<
timeofsignal
112
<<
bundleid
.
timestamp
113
<<
bundleid
.
sequencenumber
114
<< sourceid;
115
}
116
117
void
CustodySignalBlock::setMatch
(
const
dtn::data::MetaBundle
& other)
118
{
119
// set bundle parameter
120
bundleid
= other;
121
}
122
123
void
CustodySignalBlock::setMatch
(
const
dtn::data::Bundle
& other)
124
{
125
// set bundle parameter
126
bundleid
= other;
127
}
128
129
bool
CustodySignalBlock::match
(
const
Bundle
& other)
const
130
{
131
return
other ==
bundleid
;
132
}
133
}
134
}
ibrdtn
ibrdtn
data
CustodySignalBlock.cpp
Generated on Thu Mar 27 2014 09:26:21 for IBR-DTNSuite by
1.8.4