DESERT 3.5.1
Loading...
Searching...
No Matches
uwtokenbus.h
Go to the documentation of this file.
1//
2// Copyright (c) 2021 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 UWTOKENBUS_H
40#define UWTOKENBUS_H
41
42#include "uwtokenbus_hdr.h"
43#include <mmac.h>
44#include <deque>
45
46extern packet_t PT_UWTOKENBUS;
47
51class UwTokenBus : public MMac
52{
53
54public:
58 UwTokenBus();
59
63 virtual ~UwTokenBus();
64
68 class TimerBusIdle : public TimerHandler
69 {
70
71 public:
77 : TimerHandler()
78 {
79 assert(m != NULL);
80 module = m;
81 }
82
83 protected:
88 virtual void expire(Event *e);
89 UwTokenBus *module;
90 };
91
96 class TimerTokenPass : public TimerHandler
97 {
98
99 public:
105 : TimerHandler()
106 {
107 assert(m != NULL);
108 module = m;
109 }
110
111 protected:
116 virtual void expire(Event *e);
117 UwTokenBus *module;
118 };
119
121 {
125 };
127protected:
128
132 virtual void expireBusIdle();
133
137 virtual void expireTokenPass();
138
142 virtual void initRing();
143
150 virtual bool validToken(Packet *p) const;
151
156 virtual void sendToken(int next_id);
157
161 virtual void txData();
162
166 virtual int normId(int id) const;
167
171 virtual int nextId(int id) const;
172
176 virtual int nextIdOwned(int id) const;
177
183 virtual void recvFromUpperLayers(Packet *p) override;
189 virtual void Phy2MacEndRx(Packet *p) override;
195 virtual void Phy2MacStartRx(const Packet *p) override;
201 virtual void Mac2PhyStartTx(Packet *p);
207 virtual void Phy2MacEndTx(const Packet *p) override;
208
214 virtual void initPkt(Packet *p);
215
227 virtual int command(int argc, const char *const *argv) override;
228
238 std::deque<Packet *> buffer;
241 double slot_time;
256 int debug;
262 static int count_nodes;
265 constexpr int NMOD(int n) {return ((n_nodes + (n % n_nodes)) % n_nodes);}
266};
267
268
269#endif
TimerBusIdle when expires calls UwTokenBus::TxData() to start the transmission.
Definition uwtokenbus.h:69
TimerBusIdle(UwTokenBus *m)
Costructor of the class TimerBusIdle.
Definition uwtokenbus.h:76
virtual void expire(Event *e)
Method call when the timer expire.
TimerTokenPass when expires it resends the token.
Definition uwtokenbus.h:97
TimerTokenPass(UwTokenBus *m)
Costructor of the class TimerTokenPass.
Definition uwtokenbus.h:104
virtual void expire(Event *e)
Method call when the timer expire.
Class that represents a TokenBus Node.
Definition uwtokenbus.h:52
UWTokenBus_STATUS rtx_status
Definition uwtokenbus.h:239
int count_token_invalid
node count of invalid received token
Definition uwtokenbus.h:254
double token_pass_timeout
timeout for the namesake timer for token retransmission attempt, should be 2*slot_time+min_token_hold...
Definition uwtokenbus.h:242
double min_token_hold_time
if the node has en empty queue when it receive the token, it waits this time before passing the token
Definition uwtokenbus.h:235
virtual void initRing()
Initialize the network and generates the first token.
virtual void expireBusIdle()
called when bus_idle_timer expires
int debug
Debug variable: 0 for no info.
Definition uwtokenbus.h:256
double slot_time
max travel time between any pair of nodes, used as time unit for some of the timers timeouts
Definition uwtokenbus.h:241
virtual void Phy2MacEndTx(const Packet *p) override
Method called when the Mac Layer finish to transmit a Packet.
virtual int nextIdOwned(int id) const
static int count_token_pass_exp
count token pass timer expirations
Definition uwtokenbus.h:263
virtual ~UwTokenBus()
Destructor of the TokenBus class.
TimerBusIdle bus_idle_timer
token_pass_timer is scheduled when a node pass the token, it's cancelled when activity from the follo...
Definition uwtokenbus.h:247
int n_nodes
number of nodes in the ring
Definition uwtokenbus.h:230
virtual int normId(int id) const
virtual void recvFromUpperLayers(Packet *p) override
Receive the packet from the upper layer (e.g.
virtual void Mac2PhyStartTx(Packet *p)
Method called when the Mac Layer start to transmit a Packet.
virtual int nextId(int id) const
static int count_nodes
counter of the instantiated nodes, used for assigning node ids in default contructor
Definition uwtokenbus.h:262
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
constexpr int NMOD(int n)
given any int returns the corresponding node id via modulo operations
Definition uwtokenbus.h:265
double bus_idle_timeout
base timeout for the namesake timer should be (slot_time+max_token_hold_time)
Definition uwtokenbus.h:243
double token_rx_time
time of token reception
Definition uwtokenbus.h:236
virtual void Phy2MacStartRx(const Packet *p) override
Method called when the Phy Layer start to receive a Packet.
std::deque< Packet * > buffer
outgoing packets dequeue
Definition uwtokenbus.h:238
TimerTokenPass token_pass_timer
Definition uwtokenbus.h:244
int last_token_id_heard
last token id heard on the bus
Definition uwtokenbus.h:231
int count_token_regen
node count of token regeneration
Definition uwtokenbus.h:253
int drop_old_
flag to set the drop packet policy in case of buffer overflow: if 0 (default) drops the new packet,...
Definition uwtokenbus.h:257
bool got_token
set if node is currently holding the token
Definition uwtokenbus.h:240
virtual void Phy2MacEndRx(Packet *p) override
Method called when the Phy Layer finish to receive a Packet.
int last_token_id_owned
last token id owned
Definition uwtokenbus.h:232
int max_queue_size
max packets in the queue
Definition uwtokenbus.h:237
virtual void initPkt(Packet *p)
Method called to add the MAC header size.
virtual void sendToken(int next_id)
Passes the token to the next node.
int node_id
id of the node (0 to n_nodes-1)
Definition uwtokenbus.h:229
int checkPriority
flag to set to 1 if UWCBR module uses packets with priority, set to 0 otherwise.
Definition uwtokenbus.h:259
virtual void txData()
Starts transmitting the packets from the queue.
int count_token_resend
bus_idle_timer is rescheduled everytime a new token_id is heard on the bus: the first time node n hea...
Definition uwtokenbus.h:252
virtual bool validToken(Packet *p) const
Assert if the received token id is valid, i.e it follows the monotonic progression taking in account ...
virtual void expireTokenPass()
called when token_pass_timer expires
static int count_bus_idle_exp
count bus idle timer expirations
Definition uwtokenbus.h:264
UwTokenBus()
Default constructor of the TokenBus class.
double max_token_hold_time
max token holding time
Definition uwtokenbus.h:234
Common structures and variables in the protocol.