-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRIPv0.h
117 lines (94 loc) · 2.42 KB
/
RIPv0.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// RIPv0.h
#ifndef RIPv0_H
#define RIPv0_H
#include <iostream>
#include <string>
#include "RoutingTable.h"
using namespace std;
/*
OVERVIEW
Our RIP Packet consists of:
Command[AMPERSAND]Source address[AMPERSAND]Destination address[AMPERSAND]Path[AMPERSAND]Data
*/
/*
Commands:
1. Add a new entry to table:
ADD <TableRow data, comma-delimited>
2. Update an existing entry in a table:
UPDATE <TableRow data, comma-delimited>
3. Delete the entry from a table:
DELETE <TableRow data, comma-delimited>
4. Send the whole table:
TABLE <Array of TableRow data, Newline-delimited and comma-delimited>
5. Pass a message (from a client, to a client/server):
MESSAGE <messageData>
*/
enum COMMAND {
ADD,
TABLE,
UPDATE,
DELETE,
MESSAGE
};
/*
4&1234&5678&DOM=<domain>&<path> //REQUEST
4&5678&1234&DOM=<domain>/IP=<ip_address>&<path> //RESPONSE
*/
string constructNewMessage (short cmd, int src, int dest, void* data){
string message;
switch (cmd)
{
case ADD:{
message += to_string(ADD);
message += '&';
message += to_string(src);
message += '&';
message += to_string(dest);
message += '&';
TableRow* table_row_data = static_cast<TableRow *> (data);
message += table_row_data->toString();
break;
}
case TABLE:{
message += to_string(TABLE);
message += '&';
message += to_string(src);
message += '&';
message += to_string(dest);
message += '&';
message += ( static_cast<char*> (data) );
break;
}
case UPDATE:{
message += to_string(UPDATE);
message += '&';
message += to_string(src);
message += '&';
message += to_string(dest);
message += '&';
TableRow* table_row_data = static_cast<TableRow *> (data);
message += table_row_data->toString();
break;
}
case DELETE:{
message += to_string(DELETE);
break;
}
case MESSAGE:{
message += to_string(MESSAGE);
message += '&';
message += to_string(src);
message += '&';
message += to_string(dest);
message += '&';
message += ( static_cast<char*> (data) );
break;
}
default:{
return NULL;
break;
}
}
return message;
}
#endif