-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHost.h
More file actions
108 lines (83 loc) · 2.58 KB
/
Host.h
File metadata and controls
108 lines (83 loc) · 2.58 KB
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
//
// This file is part of an OMNeT++/OMNEST simulation example.
//
// Copyright (C) 1992-2015 Andras Varga
//
// This file is distributed WITHOUT ANY WARRANTY. See the file
// `license' for details on this and other legal matters.
//
#ifndef __ALOHA_HOST_H_
#define __ALOHA_HOST_H_
#include <omnetpp.h>
using namespace omnetpp;
namespace csma {
/**
* CSMA host; see NED file for more info.
*/
class Host : public cSimpleModule, public cListener
{
private:
// parameters
simtime_t radioDelay;
double txRate;
cPar *iaTime;
cPar *pkLenBits;
simtime_t slotTime;
// state variables, event pointers etc
cModule *server;
cMessage *endTxEvent = nullptr;
enum { IDLE = 0, WAIT_CTS = 1, BEFORE_SNED = 2, TRANSMIT = 3, FREEZE = 4} state;
simsignal_t stateSignal;
simsignal_t channelStateSignal;
int pkCounter;
// position on the canvas, unit is m
double x, y;
// speed of light in m/s
const double propagationSpeed = 299792458.0;
// animation parameters
const double ringMaxRadius = 2000; // in m
const double circlesMaxRadius = 1000; // in m
double idleAnimationSpeed;
double transmissionEdgeAnimationSpeed;
double midtransmissionAnimationSpeed;
// figures and animation state
cPacket *lastPacket = nullptr; // a copy of the last sent message, needed for animation
mutable cRingFigure *transmissionRing = nullptr; // shows the last packet
mutable std::vector<cOvalFigure *> transmissionCircles; // ripples inside the packet ring
cMessage *DIFSEvent = nullptr;
int channelBusy;
simtime_t backoffTime;
int maxBackoffs;
int backoffCount;
cMessage *backoff = nullptr;
// simtime_t SIFS;
simtime_t DIFS;
simtime_t DIFS_FLAG;
simtime_t RTS_TIME;
simtime_t SIFS;
cPacket *pk;
char pkname[40];
int numOtherHosts;
cModule **otherHosts;
cGate **otherHostGate;
simtime_t *otherHostDelay;
char broadcast[40];
cMessage *endListen = nullptr;
char endListenName[10] = "endListen";
cMessage *RTSEvent = nullptr;
bool contentFailFlag;
cMessage *cancleChannelBusy = nullptr;
public:
virtual ~Host();
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
virtual void refreshDisplay() const override;
simtime_t generateBackofftime();
simtime_t getNextTransmissionTime();
void sendRTS();
void sendPacket(cPacket *pk);
virtual void receiveSignal(cComponent *source, simsignal_t signalID, intval_t i, cObject *details) override;
};
}; //namespace
#endif