-
Notifications
You must be signed in to change notification settings - Fork 0
/
packet.h
64 lines (49 loc) · 1.26 KB
/
packet.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
/*
http://webdocs.cs.ualberta.ca/~c379/F18/379only/lab-messages.html
FRAME and MSG definitions Adapted from lab code.
Messages and Frames
*/
#ifndef _packet_
#define _packet_
#include "flowTable.h"
#include <poll.h>
#include <string>
#define MAXLINE 132
#define MAXWORD 32
#define MSG_KINDS 5
using namespace std;
typedef enum {ACK, OPEN, QUERY, ADD, RELAY, CLOSE} P_TYPES;
typedef struct {
int lowIP;
int highIP;
int port1;
int port2;
int myID;
} MSG_OPEN;
typedef struct {
int srcIP;
int dstIP;
int port1;
int port2;
int myID;
} MSG_QUERY;
typedef struct {
int srcIP;
int dstIP;
} MSG_RELAY; // received packet header info
typedef union {
MSG_OPEN open;
MSG_QUERY query;
flow_entry add; //add
MSG_RELAY relay;
} MSG; // ACK has no message
typedef struct { P_TYPES type; int senderID; MSG msg; } FRAME;
FRAME rcvFrame(int fd);
void sendPacket(int fd, int sendID, int rcvID, P_TYPES type, MSG msg);
void sendACK(int fd, int senderID, int rcvID);
bool sendOPEN(int wfd, int rfd, int senderID, int rcvID, MSG msg);
flow_entry sendQUERY(int wfd, int rfd, int senderID, int rcvID, MSG msg);
void sendADD(int fd, int senderID, int rcvID, MSG msg);
void sendRELAY(int fd, int senderID, int rcvID, MSG msg);
const char* convertTypeToChar(int type);
#endif