-
Notifications
You must be signed in to change notification settings - Fork 1
/
syncparameters.h
executable file
·177 lines (159 loc) · 7.59 KB
/
syncparameters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* Copyright 2020-2021 Apostolos Karalis
* This file is part of Minimal 6TiSCH Synchronization Simulator (M6SS).
*
* M6SS is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* M6SS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with M6SS.
* If not, see <https://www.gnu.org/licenses/>.
*
* @author Apostolos Karalis <akaralis@unipi.gr>
*/
#ifndef M6SS_SYNCPARAMETERS_H
#define M6SS_SYNCPARAMETERS_H
#include <chrono>
#include <iostream>
#include <vector>
#include <map>
namespace M6SS {
/***
* This class represents the parameters of the synchronization procedure.
*/
class SyncParameters {
public:
/***
* Initializes a new instance of the SyncParameters class.
* @param chs the channel hopping sequence.
* @param s the number of slots in the slotframe.
* @param pEB the probability of an EB transmission (in the minimal cell).
* @param pSR a map that contains for each channel in chs the probability of the successful reception of an EB
* (in the context of the minimal cell).
* @param tScan the time that a selected channel is scanned for an EB.
* @param tSwitch the channel switch delay.
* @param tEB the time required for the transmission of an EB. Note that we allow Teb to be set to zero.
* @throw std::invalid_argument if:
* (a) chs contains channels that are not in the set {11, 12, ..., 26}, or,
* (b) chs contains a channel multiple times, or,
* (c) s is not a positive integer, or,
* (d) s and the size of chs (i.e., the number of channels) are not co-primes, or,
* (e) pEB is an invalid probability (i.e, less than 0 or greater than 1), or,
* (f) pSR does not contain all the channels included in chs, or,
* (g) pSR contains channels that are not included in chs, or,
* (h) pSR contains an invalid probability (i.e, less than 0 or greater than 1), or,
* (i) tScan is not a positive time, or,
* (k) tSwitch is a negative time, or,
* (l) tEB is a negative time.
*/
SyncParameters(const std::vector<int> &chs, int s, double pEB, const std::map<int, double> &pSR,
const std::chrono::nanoseconds &tScan,
const std::chrono::nanoseconds &tSwitch,
const std::chrono::nanoseconds &tEB);
/**
* Returns the channel hopping sequence of the network.
* @return the channel hopping sequence of the network.
*/
[[nodiscard]] const std::vector<int> &getCHS() const;
/**
* Returns the number of slots in the slotframe.
* @return the number of slots in the slotframe.
*/
[[nodiscard]] int getS() const;
/**
* Returns the transmission probability of an EB (in the minimal cell).
* @return the probability of an EB transmission (in the minimal cell).
*/
[[nodiscard]] double getPeb() const;
/**
* Returns a map that contains for each channel the probability of the successful reception of an EB (in the
* context of the minimal cell).
* @return returns a map that contains for each channel the probability of the successful reception of an EB
*/
[[nodiscard]] const std::map<int, double> &getPsr() const;
/**
* Returns the time that a selected channel is scanned for an EB.
* @return the time that a selected channel is scanned for an EB.
*/
[[nodiscard]] const std::chrono::nanoseconds &getTScan() const;
/**
* Returns the channel switch delay.
* @return the channel switch delay.
*/
[[nodiscard]] const std::chrono::nanoseconds &getTSwitch() const;
/**
* Returns the time required for the transmission of an EB.
* @return the time required for the transmission of an EB.
*/
[[nodiscard]] const std::chrono::nanoseconds &getTeb() const;
/**
* The default duration of a timeslot in the 2.4Ghz band.
*/
static constexpr auto DEFAULT_SLOT_DURATION = std::chrono::milliseconds(10);
/**
* The default channel hopping sequences as defined by the standard, depending on the number of channels
* used by the network (maximum 16 in the 2.4 Ghz band).
*/
inline static const std::map<int, std::vector<int> > DEFAULT_CHANNEL_HOPPING_SEQUENCES{
{1, {11}},
{2, {11, 12}},
{3, {11, 13, 12}},
{4, {11, 13, 14, 12}},
{5, {11, 13, 14, 15, 12}},
{6, {16, 12, 15, 11, 13, 14}},
{7, {14, 13, 15, 11, 16, 12, 17}},
{8, {16, 12, 15, 11, 14, 13, 17, 18}},
{9, {11, 13, 12, 16, 17, 18, 19, 14, 15}},
{10, {16, 12, 19, 13, 17, 14, 20, 18, 15, 11}},
{11, {16, 12, 11, 20, 17, 18, 14, 13, 19, 15, 21}},
{12, {16, 19, 15, 20, 13, 12, 21, 18, 22, 11, 14, 17}},
{13, {15, 13, 20, 19, 17, 23, 16, 12, 21, 22, 14, 11, 18}},
{14, {14, 11, 21, 18, 16, 19, 17, 20, 22, 24, 15, 23, 12, 13}},
{15, {17, 22, 24, 18, 12, 11, 25, 13, 19, 16, 14, 15, 20, 23, 21}},
{16, {16, 17, 23, 18, 26, 15, 25, 22, 19, 11, 12, 13, 24, 14, 20, 21}}
};
/**
* The time between the beginning of a timeslot and the start of frame transmission, considering the default
* timeslot template of the 2.4Ghz band.
*/
static constexpr auto DEFAULT_TX_OFFSET = std::chrono::microseconds(2120);
friend std::ostream &operator<<(std::ostream &out, const SyncParameters &syncParameters) {
out << "SyncParameters{" << std::endl
<< "CHS: [";
for (auto it = syncParameters.getCHS().begin(); it != syncParameters.getCHS().end(); ++it) {
out << *it;
if (it + 1 != syncParameters.getCHS().end()) {
out << ", ";
}
}
out << "]" << std::endl
<< "S: " << syncParameters.getS() << std::endl
<< "Peb: " << syncParameters.getPeb() << std::endl
<< "Psr: {";
for (auto it = syncParameters.getPsr().begin(); it != syncParameters.getPsr().end();) {
out << it->first << ":" << it->second;
if (++it != syncParameters.getPsr().end()) {
out << ", ";
}
}
out << "}" << std::endl
<< "Tscan: " << syncParameters.getTScan().count() << "ns" << std::endl
<< "Tswitch: " << syncParameters.getTSwitch().count() << "ns" << std::endl
<< "Teb: " << syncParameters.getTeb().count() << "ns" << std::endl
<< "}";
return out;
}
private:
std::vector<int> chs_;
int s_;
double pEB_;
std::map<int, double> pSR_;
std::chrono::nanoseconds tScan_{};
std::chrono::nanoseconds tSwitch_{};
std::chrono::nanoseconds tEB_{};
};
}
#endif //M6SS_SYNCPARAMETERS_H