IBR-DTNSuite  0.12
PrimaryBlock.h
Go to the documentation of this file.
1 /*
2  * PrimaryBlock.h
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 #ifndef PRIMARYBLOCK_H_
23 #define PRIMARYBLOCK_H_
24 
25 #include "ibrdtn/data/Number.h"
26 #include "ibrdtn/data/EID.h"
27 #include "ibrdtn/data/BundleID.h"
28 #include "ibrdtn/data/Dictionary.h"
29 #include "ibrdtn/data/Serializer.h"
30 #include <ibrcommon/thread/Mutex.h>
31 #include <string>
32 #include <iostream>
33 #include <stdint.h>
34 
35 #ifdef SWIG
36 # define DEPRECATED
37 #else
38 # define DEPRECATED __attribute__ ((deprecated))
39 #endif
40 
41 namespace dtn
42 {
43  namespace data
44  {
45  static const unsigned char BUNDLE_VERSION = 0x06;
46 
47  class PrimaryBlock : public BundleID
48  {
49  public:
56  enum PRIORITY
57  {
58  PRIO_LOW = 0,
61  };
62 
63  enum FLAGS
64  {
65  FRAGMENT = 1 << 0x00,
66  APPDATA_IS_ADMRECORD = 1 << 0x01,
67  DONT_FRAGMENT = 1 << 0x02,
68  CUSTODY_REQUESTED = 1 << 0x03,
70  ACKOFAPP_REQUESTED = 1 << 0x05,
71  RESERVED_6 = 1 << 0x06,
72  PRIORITY_BIT1 = 1 << 0x07,
73  PRIORITY_BIT2 = 1 << 0x08,
74  CLASSOFSERVICE_9 = 1 << 0x09,
75  CLASSOFSERVICE_10 = 1 << 0x0A,
76  CLASSOFSERVICE_11 = 1 << 0x0B,
77  CLASSOFSERVICE_12 = 1 << 0x0C,
78  CLASSOFSERVICE_13 = 1 << 0x0D,
86 
87  // DTNSEC FLAGS (these are customized flags and not written down in any draft)
88  DTNSEC_REQUEST_SIGN = 1 << 0x1A,
94  };
95 
96  PrimaryBlock(bool zero_timestamp = false);
97  virtual ~PrimaryBlock();
98 
99  void set(FLAGS flag, bool value);
100  bool get(FLAGS flag) const;
101 
102  PRIORITY getPriority() const;
103  void setPriority(PRIORITY p);
104 
105  bool isFragment() const;
106  void setFragment(bool val);
107 
111  void relabel(bool zero_timestamp = false);
112 
113  bool operator==(const PrimaryBlock& other) const;
114  bool operator!=(const PrimaryBlock& other) const;
115  bool operator<(const PrimaryBlock& other) const;
116  bool operator>(const PrimaryBlock& other) const;
117 
121 
125 
126  private:
127  static ibrcommon::Mutex __sequence_lock;
128  static Number __sequencenumber;
129  static Number __sequencenumber_abs;
130  static Timestamp __last_timestamp;
131  };
132  }
133 }
134 
135 #endif /* PRIMARYBLOCK_H_ */