-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRouterDS.h
95 lines (73 loc) · 2.25 KB
/
RouterDS.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
//
// Created by subangkar on 12/7/18.
//
#ifndef DVR_ROUTERDS_H
#define DVR_ROUTERDS_H
#include "Utils.h"
#include <unistd.h>
#include <ostream>
#include "Socket.h"
#define INF (std::numeric_limits<int>::max())
#define UP 1
#define DOWN 0
#define SHOW_ROUTING_TABLE "show"
#define RECV_ROUTING_TABLE string("ntbl")
#define SEND_MESSAGE "send"
#define FORWARD_MESSAGE string("frwd")
#define UPDATE_COST "cost"
#define DRIVER_CLOCK "clk"
#define CLEAR_SCREEN "clscr"
#define NONE "-\t"
typedef string routerip_t;
typedef string packet_t;
typedef int cost_t;
struct RoutingTableEntry {
routerip_t destination;
routerip_t nextHop;
cost_t cost{};
RoutingTableEntry() = default;
RoutingTableEntry(const routerip_t &destination, const routerip_t &nextHop, cost_t cost) : destination(destination),
nextHop(nextHop), cost(cost) {}
friend ostream &operator<<(ostream &os, const RoutingTableEntry &entry) {
os << entry.destination << "\t" << setw(12) << entry.nextHop << "\t" << entry.cost;
return os;
}
bool operator==(const RoutingTableEntry &rhs) const {
return destination == rhs.destination &&
nextHop == rhs.nextHop &&
cost == rhs.cost;
}
bool operator!=(const RoutingTableEntry &rhs) const {
return !(rhs == *this);
}
};
struct Link {
routerip_t neighbor;
int cost;
int recvClock;
int status;
Link() {
cost = -1;
recvClock = -1;
status = DOWN;
}
Link(const routerip_t &neighbor, int cost, int recvClock, int status) : neighbor(neighbor), cost(cost),
recvClock(recvClock), status(status) {}
friend ostream &operator<<(ostream &os, const Link &link1) {
os << "neighbor: " << link1.neighbor << " cost: " << link1.cost << " recvClock: " << link1.recvClock
<< " status: " << link1.status;
return os;
}
bool operator==(const Link &rhs) const {
// return neighbor == rhs.neighbor &&
// cost == rhs.cost &&
// recvClock == rhs.recvClock &&
// status == rhs.status;
return neighbor == rhs.neighbor;
}
bool operator!=(const Link &rhs) const {
return !(rhs == *this);
}
};
typedef map<routerip_t, RoutingTableEntry> routingtable_t;
#endif //DVR_ROUTERDS_H