-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL2Header.hpp
755 lines (637 loc) · 27 KB
/
L2Header.hpp
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
// The L-Band Digital Aeronautical Communications System (LDACS) Link Layer Glue Library provides interfaces and common classes necessary for the LDACS Air-Air Medium Access Control simulator.
// Copyright (C) 2023 Sebastian Lindner, Konrad Fuger, Musab Ahmed Eltayeb Ahmed, Andreas Timm-Giel, Institute of Communication Networks, Hamburg University of Technology, Hamburg, Germany
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program 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 Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#ifndef INTAIRNET_LINKLAYER_GLUE_L2HEADER_HPP
#define INTAIRNET_LINKLAYER_GLUE_L2HEADER_HPP
#include <algorithm>
#include <vector>
#include <array>
#include "MacId.hpp"
#include "CPRPosition.hpp"
#include "SequenceNumber.hpp"
#include "LinkProposal.hpp"
#include "SlotDuration.hpp"
namespace TUHH_INTAIRNET_MCSOTDMA {
/**
* Data Link Layer Headers.
*/
class L2Header {
public:
enum FrameType {
unset,
base,
broadcast,
unicast,
link_establishment_request,
link_establishment_reply,
dme_request,
dme_response
};
enum Modulation {
BPSK,
QPSK
};
class Direction {
public:
bool North = false;
bool NorthEast = false;
bool East = false;
bool SouthEast = false;
bool South = false;
bool SouthWest = false;
bool West = false;
bool NorthWest = false;
};
L2Header() : frame_type(unset) {}
explicit L2Header(L2Header::FrameType frame_type) : frame_type(frame_type) {}
L2Header(const L2Header& other) = default;
virtual ~L2Header() = default;
virtual L2Header* copy() const {
return new L2Header(*this);
}
virtual unsigned int getBits() const {
return 3 /* frame type */;
}
bool operator==(const L2Header& other) const {
return frame_type == other.frame_type;
}
bool operator!=(const L2Header& other) const {
return !((*this) == other);
}
bool isUnicastType() const {
return frame_type == L2Header::link_establishment_reply || frame_type == L2Header::link_establishment_request || frame_type == L2Header::unicast;
}
bool isBroadcastType() const {
return frame_type == L2Header::broadcast;
}
bool isDMERequest() const {
return frame_type == L2Header::dme_request;
}
bool isDMEResponse() const {
return frame_type == L2Header::dme_response;
}
/** This frame's type. */
const FrameType frame_type;
};
class L2HeaderSH : public L2Header {
public:
L2HeaderSH() : L2Header(L2Header::FrameType::broadcast) {}
L2HeaderSH(MacId id) : L2Header(L2Header::FrameType::broadcast), src_id(id) {}
L2HeaderSH(const L2HeaderSH &other) : L2Header(other) {
signature = other.signature;
src_id = other.src_id;
slot_offset = other.slot_offset;
slot_duration = other.slot_duration;
position = other.position;
time_src = other.time_src;
num_hops = other.num_hops;
time_tx = other.time_tx;
request_time_rx = other.request_time_rx;
response_time_rx = other.response_time_rx;
link_status = other.link_status;
link_utilizations = other.link_utilizations;
link_proposals = other.link_proposals;
link_requests = other.link_requests;
link_reply = other.link_reply;
is_pkt_start = other.is_pkt_start;
is_pkt_end = other.is_pkt_end;
}
L2HeaderSH* copy() const override {
return new L2HeaderSH(*this);
}
/** ECC-384. Not actually used in the simulator. */
class Signature {
public:
static unsigned int getBits() {
return 96*8;
}
};
class LinkStatus {
public:
int num_proposals = 0;
/** indicates that links in particular directions are wanted */
Direction direction;
/** number of resource utilization messages */
int num_utilizations = 0;
/** datarates for (direction, priority)-pairs */
int datarates = 0;
static unsigned int getBits() {
return 4 /* num_proposals */
+ 4 /* direction */
+ 4 /* num_utilizations */
+ 16*8 /* datarates */
;
}
};
class LinkUtilizationMessage {
public:
LinkUtilizationMessage() : slot_offset(0), slot_duration(SlotDuration::twentyfour_ms), num_bursts_forward(0), num_bursts_reverse(0), period(0), center_frequency(0), timeout(0) {}
LinkUtilizationMessage(int slot_offset, SlotDuration slot_duration, int num_bursts_forward = 0, int num_bursts_reverse = 0, int period = 0, int center_frequency = 0, int timeout = 0)
: slot_offset(slot_offset), slot_duration(slot_duration), num_bursts_forward(num_bursts_forward), num_bursts_reverse(num_bursts_reverse), period(period), center_frequency(center_frequency), timeout(timeout) {}
bool operator==(LinkUtilizationMessage const& rhs) const { return slot_offset == rhs.slot_duration && slot_duration == rhs.slot_duration && num_bursts_forward == rhs.num_bursts_forward && num_bursts_reverse == rhs.num_bursts_reverse && period == rhs.period && center_frequency == rhs.center_frequency && timeout == rhs.timeout; }
bool operator!=(LinkUtilizationMessage const& rhs) const { return !(*this == rhs);}
int slot_offset = 0;
SlotDuration slot_duration = SlotDuration::twentyfour_ms;
int num_bursts_forward = 0, num_bursts_reverse = 0;
int period = 0;
int center_frequency = 0;
int timeout = 0;
static unsigned int getBits() {
return 14 /* slot_offset */ + 2 /* slot_duration */ + 2 /* num_bursts_forward */ + 2 /* num_bursts_reverse */ + 3 /* period */ + 9 /* center frequency */ + 8 /* timeout */;
}
};
class LinkProposalMessage {
public:
LinkProposalMessage() {}
explicit LinkProposalMessage(const LinkProposal &proposal) : proposed_link(proposal) {}
LinkProposal proposed_link;
int noise = 0;
static unsigned int getBits() {
return 14 /* slot_offset */ + 2 /* slot_duration */ + 4 /* noise */ + 3 /* period */ + 9 /* center_frequency */
;
}
};
class LinkRequest {
public:
LinkRequest() {}
LinkRequest(const MacId &dest_id, const LinkProposal &proposal) : dest_id(dest_id), proposed_link(proposal) {}
LinkRequest(const MacId &dest_id, const LinkProposal &proposal, uint64_t generation_time) : dest_id(dest_id), proposed_link(proposal), generation_time(generation_time) {}
Modulation modulation = Modulation::BPSK;
int type = 0;
MacId dest_id;
LinkProposal proposed_link = LinkProposal();
int num_forward_bursts = 1, num_reverse_bursts = 1;
/** Isn't part of an actual link request, but this allows the recipient to have a valid link establishment time statistic. */
uint64_t generation_time = 0;
static unsigned int getBits() {
return 4 /*modulation*/ + 4 /*type*/ + MacId::getBits() + 14 /*slot_offset*/
+ 2 /*slot_duration*/ + 3 /*period*/ + 9 /*center_frequency*/ + 4 /*forward/reverse*/;
}
};
class LinkReply {
public:
LinkReply() {}
LinkReply(const MacId &dest_id, const LinkProposal &proposal) : dest_id(dest_id), proposed_link(proposal) {}
bool operator==(LinkReply const& rhs) const {return type == rhs.type && dest_id == rhs.dest_id && proposed_link == rhs.proposed_link && num_forward_bursts == rhs.num_forward_bursts && num_reverse_bursts == rhs.num_reverse_bursts;}
bool operator!=(LinkReply const& rhs) const { return !(*this == rhs);}
Modulation modulation = Modulation::BPSK;
int type = 0;
MacId dest_id = SYMBOLIC_ID_UNSET;
LinkProposal proposed_link = LinkProposal();
int num_forward_bursts = 1, num_reverse_bursts = 1;
static unsigned int getBits() {
return 4 /*modulation*/ + 4 /*type*/ + MacId::getBits() + 14 /*slot_offset*/
+ 2 /*slot_duration*/ + 3 /*period*/ + 9 /*center_frequency*/ + 4 /*forward/reverse*/;
}
};
Signature signature = Signature();
MacId src_id = SYMBOLIC_ID_UNSET;
/** advertises next transmission slot */
unsigned int slot_offset = 0;
SlotDuration slot_duration = SlotDuration::twentyfour_ms;
CPRPosition position;
int time_src = 0;
int num_hops = 0;
int time_tx = 0;
/** flag to request the transmission of reception time for two-way ranging */
bool request_time_rx = false;
/** flag to indicate that requested reception time is saved in this message */
bool response_time_rx = false;
LinkStatus link_status;
std::vector<LinkUtilizationMessage> link_utilizations;
std::vector<LinkProposalMessage> link_proposals;
std::vector<LinkRequest> link_requests;
LinkReply link_reply;
bool is_pkt_end = false, is_pkt_start = false;
unsigned int getBits() const override {
return L2Header::getBits() + signature.getBits() + src_id.getBits()
+ 14 /* slot_offset */
+ 2 /* slot_duration */
+ position.getBits()
+ 3 /* time_src */
+ 4 /* num_hops */
+ 64 /* time_tx */
+ LinkStatus::getBits()
+ link_utilizations.size() * LinkUtilizationMessage::getBits()
+ link_proposals.size() * LinkProposalMessage::getBits()
+ link_requests.size() * LinkRequest::getBits()
;
}
};
class L2HeaderPP : public L2Header {
public:
L2HeaderPP() : L2Header(L2Header::FrameType::unicast) {}
L2HeaderPP(const MacId& dest_id) : L2Header(L2Header::FrameType::unicast), dest_id(dest_id) {}
L2HeaderPP(const MacId& src_id, const MacId& dest_id) : L2Header(L2Header::FrameType::unicast), src_id(src_id), dest_id(dest_id) {}
L2HeaderPP(const MacId& dest_id, bool use_arq, SequenceNumber arq_seqno, SequenceNumber ack_seqno) : L2Header(L2Header::FrameType::unicast), dest_id(dest_id), use_arq(use_arq), seqno(arq_seqno), seqno_next_expected(ack_seqno) {}
L2HeaderPP(const MacId& dest_id, bool use_arq, SequenceNumber arq_seqno, SequenceNumber arq_ack_no, unsigned int arq_ack_slot) : L2Header(L2Header::FrameType::unicast), dest_id(dest_id), use_arq(use_arq), seqno(arq_seqno), seqno_next_expected(arq_ack_no), arq_ack_slot(arq_ack_slot) {}
L2HeaderPP(const L2HeaderPP &other) : L2Header(other) {
src_id = other.src_id;
dest_id = other.dest_id;
is_pkt_start = other.is_pkt_start;
is_pkt_end = other.is_pkt_end;
use_arq = other.use_arq;
seqno = SequenceNumber(other.seqno);
seqno_next_expected = SequenceNumber(other.seqno_next_expected);
srej_bitmap = other.srej_bitmap;
srej = other.srej;
payload_length = other.payload_length;
payload_offset = other.payload_offset;
packet_id = other.packet_id;
}
L2HeaderPP* copy() const override {
return new L2HeaderPP(*this);
}
MacId src_id, dest_id;
bool is_pkt_end = false, is_pkt_start = false;
/** Whether the ARQ protocol is followed for this transmission, i.e. acknowledgements are expected. */
bool use_arq;
/** ARQ sequence number. */
SequenceNumber seqno;
/** ARQ acknowledgement. */
SequenceNumber seqno_next_expected;
unsigned int arq_ack_slot;
/** Selective rejection list. */
std::array<bool, 16> srej_bitmap = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
std::array<bool, 4> srej = {false, false, false, false};
/** Length of included payload */
unsigned int payload_length = 0;
/** Offset of included payload */
unsigned int payload_offset = 0;
/** Packet id of payload */
unsigned int packet_id = 0;
const MacId& getDestId() const {
return this->dest_id;
}
/** Sequence number setter */
void setSeqno(SequenceNumber seqno) {
this->seqno = seqno;
}
/** Next expected sequence number setter function */
void setSeqnoNextExpected(SequenceNumber seqno) {
this->seqno_next_expected = seqno;
}
/** Get srej list */
std::array<bool, 16> getSrejList() {
return this->srej_bitmap;
}
/** Set srej list */
void setSrejBitmap(std::array<bool, 16> srej) {
this->srej_bitmap = srej;
}
/** Get sequence number */
SequenceNumber getSeqno() {
return this->seqno;
}
/** Get next expected sequence number */
SequenceNumber getSeqnoNextExpected() {
return this->seqno_next_expected;
}
unsigned int getBits() const override {
return 40; // 5 bytes according to Spec v4.1 Figure 18
}
};
class L2HeaderDMERequest : public L2Header {
public:
L2HeaderDMERequest() : L2Header(FrameType::dme_request) {}
};
class L2HeaderDMEResponse : public L2Header {
public:
L2HeaderDMEResponse() : L2Header(FrameType::dme_response) {}
};
// class L2HeaderBase : public L2Header {
// public:
// L2HeaderBase(const MacId& icao_id, unsigned int burst_offset, unsigned int burst_length, unsigned int burst_length_tx, unsigned int timeout)
// : L2Header(FrameType::base), src_id(icao_id), burst_offset(burst_offset), burst_length(burst_length), burst_length_tx(burst_length_tx), timeout(timeout), message_authentication_code(0) {
// }
// L2HeaderBase() : L2HeaderBase(SYMBOLIC_ID_UNSET, 0, 0, 0, 0) {}
// L2HeaderBase(const L2HeaderBase& other) : L2Header((const L2Header&) other) {
// burst_offset = other.burst_offset;
// burst_length = other.burst_length;
// burst_length_tx = other.burst_length_tx;
// timeout = other.timeout;
// src_id = other.src_id;
// message_authentication_code = other.message_authentication_code;
// }
// L2HeaderBase* copy() const override {
// return new L2HeaderBase(*this);
// }
// unsigned int getBits() const override {
// return MacId::getBits()
// + L2Header::getBits()
// + 8 /* burst_offset */
// + 4 /* burst_length */
// + 4 /* burst_length_tx */
// + 8 /* timeout */
// + 96 /* message authentication code */
// + 1 /* padding */
// ;
// }
// bool operator==(const L2HeaderBase& other) const {
// return other.burst_offset == burst_offset && other.burst_length == burst_length && other.burst_length_tx == burst_length_tx && other.timeout == timeout && other.src_id == src_id && other.message_authentication_code == message_authentication_code;
// }
// bool operator!=(const L2HeaderBase& other) const {
// return !((*this) == other);
// }
// /** Number of slots until the next transmission. */
// unsigned int burst_offset;
// /** Number of slots next frame will occupy. */
// unsigned int burst_length;
// /** Number of initial transmission slots for the link initiator. */
// unsigned int burst_length_tx;
// /** Remaining number of repetitions this reservation remains valid for. */
// unsigned int timeout;
// /** Origin ID. */
// MacId src_id;
// /** Combines authentication with error detection / correction. */
// unsigned int message_authentication_code;
// };
// class L2HeaderWithDestination : public L2Header {
// public:
// MacId dest_id;
// explicit L2HeaderWithDestination(FrameType frame_type, const MacId& dest_id) : L2Header(frame_type), dest_id(dest_id) {}
// L2HeaderWithDestination(const L2HeaderWithDestination &other) : L2HeaderWithDestination(other.frame_type, other.dest_id) {}
// L2HeaderWithDestination* copy() const override {
// return new L2HeaderWithDestination(*this);
// }
// unsigned int getBits() const override {
// return MacId::getBits() + L2Header::getBits();
// }
// bool operator==(const L2HeaderWithDestination &other) {
// return dest_id == other.dest_id && ((L2Header&) *this) == ((L2Header&) other);
// }
// bool operator!=(const L2HeaderWithDestination &other) {
// return !(*this == other);
// }
// const MacId& getDestId() const {
// return this->dest_id;
// }
// };
// class L2HeaderBroadcast : public L2Header {
// public:
// L2HeaderBroadcast() : L2Header(FrameType::broadcast) {}
// L2HeaderBroadcast(const L2HeaderBroadcast& other) : L2Header((const L2Header&) other) {
// is_pkt_start = other.is_pkt_start;
// is_pkt_end = other.is_pkt_end;
// seqno = other.seqno;
// payload_length = other.payload_length;
// }
// L2HeaderBroadcast* copy() const override {
// return new L2HeaderBroadcast(*this);
// }
// /** Whether the contained L3 Packet starts with this fragment **/
// bool is_pkt_start = false;
// /** Whether the contained L3 Packet ends with this fragment **/
// bool is_pkt_end = false;
// bool operator==(const L2HeaderBroadcast& other) const {
// return other.is_pkt_start == is_pkt_start && other.is_pkt_end == is_pkt_end && other.seqno == seqno && other.payload_length == payload_length;
// }
// bool operator!=(const L2HeaderBroadcast& other) const {
// return !((*this) == other);
// }
// unsigned int getBits() const override {
// return L2Header::getBits()
// + 2 /** Two additional bits for start and end flags */
// + 8 /** seqno */
// + 12 /** payload length */
// + 7 /** padding */
// ;
// }
// unsigned int seqno = 0;
// unsigned int payload_length = 0;
// };
// class L2HeaderBeacon : public L2Header {
// public:
// enum CongestionLevel {
// uncongested,
// slightly_congested,
// moderately_congested,
// congested
// };
// L2HeaderBeacon(const CPRPosition& position, bool is_cpr_odd, L2HeaderBeacon::CongestionLevel congestion_level, CPRPosition::PositionQuality pos_quality)
// : L2Header(L2Header::FrameType::beacon), position(position), is_cpr_odd(is_cpr_odd), congestion_level(congestion_level), payload_length(0) {}
// L2HeaderBeacon() : L2HeaderBeacon(CPRPosition(), CPRPosition().odd, L2HeaderBeacon::CongestionLevel::uncongested, CPRPosition::PositionQuality::low) {}
// L2HeaderBeacon(const L2HeaderBeacon& other) : L2Header((const L2Header&) other) {
// position = other.position;
// is_cpr_odd = other.is_cpr_odd;
// payload_length = other.payload_length;
// congestion_level = other.congestion_level;
// }
// L2HeaderBeacon* copy() const override {
// return new L2HeaderBeacon(*this);
// }
// unsigned int getBits() const override {
// return position.getBits()
// + 1 /* odd/even identifier */
// + 4 /* congestion level */
// + 12 /* payload length */
// + L2Header::getBits()
// + 6 /* padding */
// ;
// }
// bool operator==(const L2HeaderBeacon& other) const {
// return other.position == position && other.is_cpr_odd == is_cpr_odd && congestion_level == other.congestion_level && payload_length == other.payload_length;
// }
// bool operator!=(const L2HeaderBeacon& other) const {
// return !((*this) == other);
// }
// CPRPosition position;
// bool is_cpr_odd;
// L2HeaderBeacon::CongestionLevel congestion_level;
// unsigned int payload_length;
// };
// class L2HeaderUnicast : public L2HeaderWithDestination {
// public:
// L2HeaderUnicast(const MacId& icao_dest_id, bool use_arq, const SequenceNumber& seqno, const SequenceNumber& seqno_next_expected, FrameType frame_type)
// : L2HeaderWithDestination(frame_type, icao_dest_id), use_arq(use_arq), seqno(seqno), seqno_next_expected(seqno_next_expected) {
// if (frame_type != FrameType::unicast && frame_type != FrameType::link_establishment_reply && frame_type != FrameType::link_establishment_request)
// throw std::invalid_argument("Cannot instantiate a unicast header with a non-unicast type.");
// }
// L2HeaderUnicast(const MacId& icao_dest_id, bool use_arq, SequenceNumber arq_seqno, SequenceNumber arq_ack_no)
// : L2HeaderUnicast(icao_dest_id, use_arq, arq_seqno, arq_ack_no, FrameType::unicast) {}
// L2HeaderUnicast(const L2HeaderUnicast& other) : L2HeaderWithDestination((const L2HeaderWithDestination&) other) {
// is_pkt_start = other.is_pkt_start;
// is_pkt_end = other.is_pkt_end;
// use_arq = other.use_arq;
// seqno = SequenceNumber(other.seqno);
// seqno_next_expected = SequenceNumber(other.seqno_next_expected);
// burst_length_tx_desire = other.burst_length_tx_desire;
// srej_bitmap = other.srej_bitmap;
// payload_length = other.payload_length;
// }
// L2HeaderUnicast* copy() const override {
// return new L2HeaderUnicast(*this);
// }
// explicit L2HeaderUnicast(FrameType frame_type) : L2HeaderUnicast(SYMBOLIC_ID_UNSET, false, SequenceNumber(0), SequenceNumber(0), frame_type) {}
// L2HeaderUnicast() : L2HeaderUnicast(FrameType::unicast) {}
// unsigned int getBits() const override {
// return L2HeaderWithDestination::getBits()
// + 1 /* Whether ARQ is used */
// + 2 /* RLC start and end flags */
// + 8 /* ARQ sequence number */
// + 8 /* ARQ ACK number */
// + 4 /* burst length desire */
// + 16 /* Srej bit map */
// + 12 /* payload length */
// + 6 /* padding */
// ;
// }
// bool operator==(const L2HeaderUnicast& other) const {
// return other.is_pkt_start == is_pkt_start && other.is_pkt_end == is_pkt_end && other.use_arq == use_arq && other.seqno == seqno && other.seqno_next_expected == seqno_next_expected
// && burst_length_tx_desire == other.burst_length_tx_desire && payload_length == other.payload_length && ((L2HeaderWithDestination&) *this == (L2HeaderWithDestination&) other);
// }
// bool operator!=(const L2HeaderUnicast& other) const {
// return !((*this) == other);
// }
// /** Whether the contained L3 Packet starts with this fragment **/
// bool is_pkt_start = false;
// /** Whether the contained L3 Packet ends with this fragment **/
// bool is_pkt_end = false;
// /** Whether the ARQ protocol is followed for this transmission, i.e. acknowledgements are expected. */
// bool use_arq;
// /** ARQ sequence number. */
// SequenceNumber seqno;
// /** ARQ acknowledgement. */
// SequenceNumber seqno_next_expected;
// /** Selective rejection list. */
// std::array<bool, 16> srej_bitmap = {false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
// /** The number of transmission slots the local node would like to have, which will be respected upon link renewal. */
// unsigned int burst_length_tx_desire = 0;
// unsigned int payload_length = 0;
// /** Sequence number setter */
// void setSeqno(SequenceNumber seqno) {
// this->seqno = seqno;
// }
// /** Next expected sequence number setter function */
// void setSeqnoNextExpected(SequenceNumber seqno) {
// this->seqno_next_expected = seqno;
// }
// /** Get srej list */
// std::array<bool, 16> getSrejList() {
// return this->srej_bitmap;
// }
// /** Set srej list */
// void setSrejBitmap(std::array<bool, 16> srej) {
// this->srej_bitmap = srej;
// }
// /** Get sequence number */
// SequenceNumber getSeqno() {
// return this->seqno;
// }
// /** Get next expected sequence number */
// SequenceNumber getSeqnoNextExpected() {
// return this->seqno_next_expected;
// }
// };
// class L2HeaderLinkRequest : public L2HeaderWithDestination {
// public:
// explicit L2HeaderLinkRequest(const MacId& dest_id) : L2HeaderWithDestination(FrameType::link_establishment_request, dest_id) {}
// L2HeaderLinkRequest() : L2HeaderLinkRequest(SYMBOLIC_ID_UNSET) {}
// L2HeaderLinkRequest(const L2HeaderLinkRequest& other) : L2HeaderLinkRequest(other.dest_id) {
// timeout = other.timeout;
// burst_offset = other.burst_offset;
// burst_length = other.burst_length;
// burst_length_tx = other.burst_length_tx;
// reply_offset = other.reply_offset;
// payload_length = other.payload_length;
// }
// L2HeaderLinkRequest* copy() const override {
// return new L2HeaderLinkRequest(*this);
// }
// unsigned int getBits() const override {
// return L2HeaderWithDestination::getBits()
// + 8 /* reply_offset */
// + 8 /* burst_offset */
// + 4 /* burst_length */
// + 4 /* burst_length_tx */
// + 8 /* timeout */
// + 12 /* payload length */
// + 5 /* padding */
// ;
// }
// bool operator==(const L2HeaderLinkRequest& other) const {
// return timeout == other.timeout
// && burst_offset == other.burst_offset
// && burst_length == other.burst_length
// && burst_length_tx == other.burst_length_tx
// && dest_id == other.dest_id
// && reply_offset == other.reply_offset
// && ((L2Header&) *this) == ((L2Header&) other);
// }
// bool operator!=(const L2HeaderLinkRequest& other) const {
// return !((*this) == other);
// }
// unsigned int timeout = 0;
// unsigned int burst_offset = 0;
// unsigned int burst_length = 0;
// unsigned int burst_length_tx = 0;
// unsigned int reply_offset = 0;
// unsigned int payload_length = 0;
// };
// class L2HeaderLinkReply : public L2HeaderWithDestination {
// public:
// explicit L2HeaderLinkReply(const MacId& dest_id) : L2HeaderWithDestination(FrameType::link_establishment_reply, dest_id) {}
// L2HeaderLinkReply() : L2HeaderLinkReply(SYMBOLIC_ID_UNSET) {}
// L2HeaderLinkReply(const L2HeaderLinkReply& other) : L2HeaderLinkReply(other.dest_id) {
// timeout = other.timeout;
// burst_offset = other.burst_offset;
// burst_length = other.burst_length;
// burst_length_tx = other.burst_length_tx;
// payload_length = other.payload_length;
// }
// L2HeaderLinkReply* copy() const override {
// return new L2HeaderLinkReply(*this);
// }
// unsigned int getBits() const override {
// return L2HeaderWithDestination::getBits()
// + 8 /* burst_offset */
// + 4 /* burst_length */
// + 4 /* burst_length_tx */
// + 8 /* timeout */
// + 12 /* payload length */
// + 5 /* padding */
// ;
// }
// bool operator==(const L2HeaderLinkReply& other) const {
// return timeout == other.timeout
// && burst_offset == other.burst_offset
// && burst_length == other.burst_length
// && burst_length_tx == other.burst_length_tx
// && dest_id == other.dest_id
// && ((L2Header&) *this) == ((L2Header&) other);
// }
// bool operator!=(const L2HeaderLinkReply& other) const {
// return !((*this) == other);
// }
// unsigned int timeout = 0;
// unsigned int burst_offset = 0;
// unsigned int burst_length = 0;
// unsigned int burst_length_tx = 0;
// unsigned int payload_length = 0;
// };
inline std::ostream& operator<<(std::ostream& stream, const L2Header::FrameType& frame_type) {
std::string s;
switch (frame_type) {
case L2Header::FrameType::unset: {s = "unset"; break;}
case L2Header::FrameType::base: {s = "base"; break;}
case L2Header::FrameType::broadcast: {s = "broadcast"; break;}
case L2Header::FrameType::unicast: {s = "unicast"; break;}
case L2Header::FrameType::link_establishment_reply: {s = "link_reply"; break;}
case L2Header::FrameType::link_establishment_request: {s = "link_request"; break;}
case L2Header::FrameType::dme_request: {s = "dme_request"; break;}
case L2Header::FrameType::dme_response: {s = "dme_response"; break;}
default: {throw std::invalid_argument("please add new header type to operator<< of FrameType: " + std::to_string(frame_type) + "!");}
}
return stream << s;
}
}
#endif //INTAIRNET_LINKLAYER_GLUE_L2HEADER_HPP