IBR-DTNSuite
0.12
Main Page
Namespaces
Classes
Files
File List
File Members
PrimaryBlock.cpp
Go to the documentation of this file.
1
/*
2
* PrimaryBlock.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/PrimaryBlock.h
"
23
#include "
ibrdtn/data/Exceptions.h
"
24
#include "
ibrdtn/utils/Clock.h
"
25
#include <
ibrcommon/thread/MutexLock.h
>
26
27
namespace
dtn
28
{
29
namespace
data
30
{
31
Number
PrimaryBlock::__sequencenumber = 0;
32
Number
PrimaryBlock::__sequencenumber_abs = 0;
33
Timestamp
PrimaryBlock::__last_timestamp = 0;
34
ibrcommon::Mutex
PrimaryBlock::__sequence_lock;
35
36
PrimaryBlock::PrimaryBlock
(
bool
zero_timestamp)
37
: lifetime(3600), appdatalength(0)
38
{
39
relabel
(zero_timestamp);
40
41
// by default set destination as singleton bit
42
set
(
DESTINATION_IS_SINGLETON
,
true
);
43
}
44
45
PrimaryBlock::~PrimaryBlock
()
46
{
47
}
48
49
void
PrimaryBlock::set
(
FLAGS
flag,
bool
value)
50
{
51
procflags
.
setBit
(flag, value);
52
}
53
54
bool
PrimaryBlock::get
(
FLAGS
flag)
const
55
{
56
return
procflags
.
getBit
(flag);
57
}
58
59
PrimaryBlock::PRIORITY
PrimaryBlock::getPriority
()
const
60
{
61
if
(
get
(
PRIORITY_BIT1
))
62
{
63
return
PRIO_MEDIUM
;
64
}
65
66
if
(
get
(
PRIORITY_BIT2
))
67
{
68
return
PRIO_HIGH
;
69
}
70
71
return
PRIO_LOW
;
72
}
73
74
void
PrimaryBlock::setPriority
(
PrimaryBlock::PRIORITY
p)
75
{
76
// set the priority to the real bundle
77
switch
(p)
78
{
79
case
PRIO_LOW
:
80
set
(
PRIORITY_BIT1
,
false
);
81
set
(
PRIORITY_BIT2
,
false
);
82
break
;
83
84
case
PRIO_HIGH
:
85
set
(
PRIORITY_BIT1
,
false
);
86
set
(
PRIORITY_BIT2
,
true
);
87
break
;
88
89
case
PRIO_MEDIUM
:
90
set
(
PRIORITY_BIT1
,
true
);
91
set
(
PRIORITY_BIT2
,
false
);
92
break
;
93
}
94
}
95
96
bool
PrimaryBlock::isFragment
()
const
97
{
98
return
get
(
FRAGMENT
);
99
}
100
101
void
PrimaryBlock::setFragment
(
bool
val)
102
{
103
set
(
FRAGMENT
, val);
104
}
105
106
bool
PrimaryBlock::operator!=
(
const
PrimaryBlock
& other)
const
107
{
108
return
(
const
BundleID
&)*
this
!= (
const
BundleID
&)other;
109
}
110
111
bool
PrimaryBlock::operator==
(
const
PrimaryBlock
& other)
const
112
{
113
return
(
const
BundleID
&)*
this
== (
const
BundleID
&)other;
114
}
115
116
bool
PrimaryBlock::operator<
(
const
PrimaryBlock
& other)
const
117
{
118
return
(
const
BundleID
&)*
this
< other;
119
}
120
121
bool
PrimaryBlock::operator>
(
const
PrimaryBlock
& other)
const
122
{
123
return
(
const
BundleID
&)*
this
> other;
124
}
125
126
void
PrimaryBlock::relabel
(
bool
zero_timestamp)
127
{
128
if
((
dtn::utils::Clock::getRating
() > 0.0) && !zero_timestamp)
129
{
130
timestamp
=
dtn::utils::Clock::getTime
();
131
132
ibrcommon::MutexLock
l(__sequence_lock);
133
if
(
timestamp
> __last_timestamp) {
134
__last_timestamp =
timestamp
;
135
__sequencenumber = 0;
136
}
137
138
sequencenumber
= __sequencenumber;
139
__sequencenumber++;
140
}
141
else
142
{
143
// set timestamp to zero
144
timestamp
= 0;
145
146
// assign absolute sequence number
147
ibrcommon::MutexLock
l(__sequence_lock);
148
sequencenumber
= __sequencenumber_abs;
149
__sequencenumber_abs++;
150
}
151
}
152
}
153
}
ibrdtn
ibrdtn
data
PrimaryBlock.cpp
Generated on Thu Mar 27 2014 09:26:21 for IBR-DTNSuite by
1.8.4