-
Notifications
You must be signed in to change notification settings - Fork 1
/
EmulNet.h
99 lines (91 loc) · 2.11 KB
/
EmulNet.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
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
/**********************************
* FILE NAME: EmulNet.h
*
* DESCRIPTION: Emulated Network classes header file
**********************************/
#ifndef _EMULNET_H_
#define _EMULNET_H_
#define MAX_NODES 1000
#define MAX_TIME 3600
#define ENBUFFSIZE 30000
#include "stdincludes.h"
#include "Params.h"
#include "Member.h"
using namespace std;
/**
* Struct Name: en_msg
*/
typedef struct en_msg {
// Number of bytes after the class
int size;
// Source node
Address from;
// Destination node
Address to;
}en_msg;
/**
* Class Name: EM
*/
class EM {
public:
int nextid;
int currbuffsize;
int firsteltindex;
en_msg* buff[ENBUFFSIZE];
EM() {}
EM& operator = (EM &anotherEM) {
this->nextid = anotherEM.getNextId();
this->currbuffsize = anotherEM.getCurrBuffSize();
this->firsteltindex = anotherEM.getFirstEltIndex();
int i = this->currbuffsize;
while (i > 0) {
this->buff[i] = anotherEM.buff[i];
i--;
}
return *this;
}
int getNextId() {
return nextid;
}
int getCurrBuffSize() {
return currbuffsize;
}
int getFirstEltIndex() {
return firsteltindex;
}
void setNextId(int nextid) {
this->nextid = nextid;
}
void settCurrBuffSize(int currbuffsize) {
this->currbuffsize = currbuffsize;
}
void setFirstEltIndex(int firsteltindex) {
this->firsteltindex = firsteltindex;
}
virtual ~EM() {}
};
/**
* CLASS NAME: EmulNet
*
* DESCRIPTION: This class defines an emulated network
*/
class EmulNet
{
private:
Params* par;
int sent_msgs[MAX_NODES + 1][MAX_TIME];
int recv_msgs[MAX_NODES + 1][MAX_TIME];
int enInited;
EM emulnet;
public:
EmulNet(Params *p);
EmulNet(EmulNet &anotherEmulNet);
EmulNet& operator = (EmulNet &anotherEmulNet);
virtual ~EmulNet();
void *ENinit(Address *myaddr, short port);
int ENsend(Address *myaddr, Address *toaddr, string data);
int ENsend(Address *myaddr, Address *toaddr, char *data, int size);
int ENrecv(Address *myaddr, int (* enq)(void *, char *, int), struct timeval *t, int times, void *queue);
int ENcleanup();
};
#endif /* _EMULNET_H_ */