-
Notifications
You must be signed in to change notification settings - Fork 3
/
endNode.cc
44 lines (39 loc) · 1.15 KB
/
endNode.cc
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
/*
* endNode.cc
*
* Created on: 4 dic. 2019
* Author: Adrian
*/
#include <stdio.h>
#include <string.h>
#include <omnetpp.h>
#include "custom_packet_m.h"
using namespace omnetpp;
class EndNode : public cSimpleModule
{
protected:
virtual void handleMessage(cMessage *msg) override;
};
Define_Module(EndNode);
void EndNode::handleMessage(cMessage *msg)
{
CustomPacket *pkt = (CustomPacket*) msg;
cGate *arrivalGate = pkt -> getArrivalGate();
int arrivalGateIndex = arrivalGate -> getIndex();
EV << "Packet arrived from gate " + std::to_string(arrivalGateIndex) + "\n";
if (pkt -> getKind() == 1) { // 1: Packet
if (pkt -> hasBitError()) {
EV << "Packet arrived with error, send NAK\n";
CustomPacket *nak = new CustomPacket("NAK");
nak -> setKind(3);
send(nak, "outPort", arrivalGateIndex);
}
else {
EV << "Packet arrived without error, send ACK\n";
CustomPacket *ack = new CustomPacket("ACK");
ack -> setKind(2);
send(ack, "outPort", arrivalGateIndex);
EV << "Packet it's okay!";
}
}
}