DESERT 4.0.0
uw-aloha-q-node.h
Go to the documentation of this file.
1//
2// Copyright (c) 2017 Regents of the SIGNET lab, University of Padova.
3// All rights reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions
7// are met:
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// 2. Redistributions in binary form must reproduce the above copyright
11// notice, this list of conditions and the following disclaimer in the
12// documentation and/or other materials provided with the distribution.
13// 3. Neither the name of the University of Padova (SIGNET lab) nor the
14// names of its contributors may be used to endorse or promote products
15// derived from this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
21// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28//
29
39#ifndef UW_ALOHA_Q_NODE_H
40#define UW_ALOHA_Q_NODE_H
41
42#include <mmac.h>
43#include <deque>
44#include <iostream>
45#include <assert.h>
46#include <sys/time.h>
47#include <string>
48
49#include <mphy.h>
50
51#include <vector>
52
53extern packet_t PT_MMAC_ACK;
54
55#define UW_ALOHAQ_STATUS_MY_SLOT 1
56#define UW_ALOHAQ_STATUS_NOT_MY_SLOT 2
58class UwAloha_Q_NODE;
59
65class UwAlohaQTimer : public TimerHandler
66{
67
68public:
74 : TimerHandler()
75 {
76 assert(m != NULL);
77 module = m;
78 }
79
80protected:
85 virtual void expire(Event *e);
86 UwAloha_Q_NODE *module;
87};
88
92class UwAloha_Q_NODE : public MMac
93{
94
95 friend class UwAlohaQTimer;
96
97public:
102
106 virtual ~UwAloha_Q_NODE() = default;
107
108
115 virtual int recvSyncClMsg(ClMessage* m);
116
117protected:
122
124 virtual int decide_if_backoff(int slot);
125
127 virtual void stateRxAck(Packet *p);
128
130 virtual int getLayerIdFromTag(const std::string& tag);
131
133 virtual int findMySlot();
134
136 virtual void updateQ_table(int ack_received);
137
138 virtual void handleTimerExpiration();
139
143 virtual void txData();
148 virtual void start(double delay);
152 virtual void stop();
158 virtual void recvFromUpperLayers(Packet *p) override;
164 virtual void Phy2MacEndRx(Packet *p);
170 virtual void Phy2MacStartRx(const Packet *p);
176 virtual void Phy2MacEndTx(const Packet *p);
182 virtual void rxPacketNotForMe(Packet *p);
188 virtual void initPkt(Packet *p);
189
199 virtual int command(int argc, const char *const *argv);
214
218 std::vector <double> Q_table {};
219 double start_time;
224 double guard_time;
235 bool enable;
236
237 int debug_;
241 std::deque<Packet *> buffer;
247 std::string phy_data_tag;
248};
249
250#endif
Definition uw-aloha-q-node.h:66
UwAlohaQTimer(UwAloha_Q_NODE *m)
Definition uw-aloha-q-node.h:73
virtual void expire(Event *e)
Definition uw-aloha-q-node.cpp:78
Definition uw-aloha-q-node.h:93
UWALOHAQ_BACKOFF_STATUS
Definition uw-aloha-q-node.h:211
@ ADD_BACKOFF
Definition uw-aloha-q-node.h:211
@ HALT
Definition uw-aloha-q-node.h:211
UWALOHAQ_ACK_STATUS
Definition uw-aloha-q-node.h:207
@ ACK_RECEIVED
Definition uw-aloha-q-node.h:207
@ ACK_NOT_RECEIVED
Definition uw-aloha-q-node.h:207
virtual void initPkt(Packet *p)
Definition uw-aloha-q-node.cpp:367
UWALOHAQ_PKT_TYPE
Definition uw-aloha-q-node.h:118
@ UWALOHAQ_DATA_PKT
Definition uw-aloha-q-node.h:120
@ UWALOHAQ_ACK_PKT
Definition uw-aloha-q-node.h:119
virtual int recvSyncClMsg(ClMessage *m)
Definition uw-aloha-q-node.cpp:533
double start_time
Definition uw-aloha-q-node.h:219
int tot_slots
Definition uw-aloha-q-node.h:225
virtual void stateRxAck(Packet *p)
Definition uw-aloha-q-node.cpp:345
double slot_duration
Definition uw-aloha-q-node.h:217
virtual int getLayerIdFromTag(const std::string &tag)
Definition uw-aloha-q-node.cpp:149
virtual int command(int argc, const char *const *argv)
Definition uw-aloha-q-node.cpp:470
virtual void Phy2MacStartRx(const Packet *p)
Definition uw-aloha-q-node.cpp:284
virtual void handleTimerExpiration()
Definition uw-aloha-q-node.cpp:386
virtual void rxPacketNotForMe(Packet *p)
Definition uw-aloha-q-node.cpp:376
virtual void updateQ_table(int ack_received)
Definition uw-aloha-q-node.cpp:202
int max_queue_size
Definition uw-aloha-q-node.h:233
int data_phy_id
Definition uw-aloha-q-node.h:244
virtual ~UwAloha_Q_NODE()=default
UWALOHAQ_STATUS transceiver_status
Definition uw-aloha-q-node.h:220
int my_curr_slot
Definition uw-aloha-q-node.h:243
int max_packet_per_slot
Definition uw-aloha-q-node.h:228
int slot_status
Definition uw-aloha-q-node.h:216
std::string phy_data_tag
Definition uw-aloha-q-node.h:247
virtual void recvFromUpperLayers(Packet *p) override
Definition uw-aloha-q-node.cpp:218
int packet_sent_curr_frame
Definition uw-aloha-q-node.h:231
virtual void Phy2MacEndTx(const Packet *p)
Definition uw-aloha-q-node.cpp:273
bool enable
Definition uw-aloha-q-node.h:235
int debug_
Definition uw-aloha-q-node.h:237
virtual void txData()
Definition uw-aloha-q-node.cpp:230
int decide_backoff
Definition uw-aloha-q-node.h:245
UWALOHAQ_BACKOFF_MODE backoff_mode
Definition uw-aloha-q-node.h:223
UWALOHAQ_STATUS
Definition uw-aloha-q-node.h:203
@ IDLE
Definition uw-aloha-q-node.h:203
@ WAIT_ACK
Definition uw-aloha-q-node.h:203
@ RECEIVING
Definition uw-aloha-q-node.h:203
@ TRANSMITTING
Definition uw-aloha-q-node.h:203
std::deque< Packet * > buffer
Definition uw-aloha-q-node.h:241
UWALOHAQ_ACK_STATUS ack_status
Definition uw-aloha-q-node.h:221
int sea_trial_
Definition uw-aloha-q-node.h:239
virtual int findMySlot()
Definition uw-aloha-q-node.cpp:176
virtual void Phy2MacEndRx(Packet *p)
Definition uw-aloha-q-node.cpp:295
UwAlohaQTimer alohaq_timer
Definition uw-aloha-q-node.h:215
virtual void stop()
Definition uw-aloha-q-node.cpp:462
std::vector< double > Q_table
Definition uw-aloha-q-node.h:218
virtual void start(double delay)
Definition uw-aloha-q-node.cpp:445
virtual int decide_if_backoff(int slot)
Definition uw-aloha-q-node.cpp:164
int HDR_size
Definition uw-aloha-q-node.h:227
UWALOHAQ_BACKOFF_STATUS backoff_status
Definition uw-aloha-q-node.h:222
UwAloha_Q_NODE()
Definition uw-aloha-q-node.cpp:83
int curr_slot
Definition uw-aloha-q-node.h:242
UWALOHAQ_BACKOFF_MODE
Definition uw-aloha-q-node.h:213
@ B2
Definition uw-aloha-q-node.h:213
@ B1
Definition uw-aloha-q-node.h:213
int packet_sent_curr_slot_
Definition uw-aloha-q-node.h:229
double guard_time
Definition uw-aloha-q-node.h:224
packet_t PT_MMAC_ACK
Definition initlib.cpp:44