-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudp_protocol.h
47 lines (39 loc) · 1.32 KB
/
udp_protocol.h
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
//CPP:networkDEVS/udp_protocol.cpp
#if !defined udp_protocol_h
#define udp_protocol_h
#include "template/protocol.h"
/**
* references:
* - https://www.ietf.org/rfc/rfc768.txt
* - https://en.wikibooks.org/wiki/Communication_Networks/TCP_and_UDP_Protocols
* - https://tools.ietf.org/html/rfc1071
*
*/
class udp_protocol: public Protocol<dns::Packet, udp::Control, udp::Segment, ip::Control> {
std::map<ushort,std::map<IPv4,udp::Socket>> sockets;
std::vector<IPv4> ips;
/********** TIMES ***************/
// in milliseconds
double add_rm_ip_time = 10;
double delivering_time = 10;
double app_ctrl_time = 10;
/************ Helper methods **************/
void processSegment(const udp::Segment&, double );
void processUDPCtrl(const udp::Control&, double);
void sendData(const dns::Packet&, const udp::Socket&, double);
void sendDataTo(const dns::Packet&, const udp::Socket&, ushort, IPv4, double);
bool verifyChecksum(udp::Segment d) const;
ushort calculateChecksum(udp::Segment d) const;
void processNtwCtrl(const ip::Control&);
bool existentIP(IPv4);
bool existentSocket(ushort, IPv4);
bool validAppSocket(ushort, IPv4, int);
public:
udp_protocol(const char *n): Protocol(n) {};
void init(double, ...);
double ta(double t);
Event lambda(double);
void exit();
virtual void dinternal(double);
};
#endif