IBR-DTNSuite  0.12
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"
25 #include <stdlib.h>
26 #include <sstream>
27 
28 namespace dtn
29 {
30  namespace data
31  {
33  : custody_accepted(false), reason(NO_ADDITIONAL_INFORMATION), timeofsignal()
34  {
35  }
36 
38  {
39  }
40 
42  {
43  ibrcommon::BLOB::Reference r = p.getBLOB();
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 
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 
82  {
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;
107  }
108 
110 
111  (*stream) << timeofsignal
114  << sourceid;
115  }
116 
118  {
119  // set bundle parameter
120  bundleid = other;
121  }
122 
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 }