-
Notifications
You must be signed in to change notification settings - Fork 0
/
sr_router.c
128 lines (112 loc) · 3.63 KB
/
sr_router.c
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
118
119
120
121
122
123
124
125
126
127
128
#include "sr_router.h"
#include <stdlib.h>
#include "cli/cli.h"
#include "sr_integration.h"
#include "reg_defines.h"
#include "sr_reroute_multipath.h"
#define DEFAULT_IFACE "nf2c0"
void toggle_ospf_status(sr_router* router, bool status) {
router->ospf_status = status;
}
ls_info_t make_ls_info(uint32_t id, uint32_t area_id, uint16_t lsuint) {
ls_info_t ls_info;
ls_info.router_id = id;
ls_info.area_id = area_id;
ls_info.lsuint = lsuint;
ls_info.lsu_seq = 0;
return ls_info;
}
ls_info_t make_ls_info_id(sr_router* router, uint32_t area_id, uint16_t lsuint) {
ls_info_t ls_info;
interface_t* intf = get_interface_name(router, "eth0");
ls_info.router_id = intf->ip;
ls_info.area_id = area_id;
ls_info.lsuint = lsuint;
ls_info.lsu_seq = 0;
return ls_info;
}
void set_ls_info(sr_router* router, ls_info_t ls_info) {
router->ls_info = ls_info;
// copy ls info to each interface
int i = 0;
for( i = 0; i < router->num_interfaces ; i++) {
router->interface[i].router_id = ls_info.router_id;
router->interface[i].area_id = ls_info.area_id;
router->interface[i].lsuint = ls_info.lsuint;
}
}
void set_ls_info_id(sr_router* router, uint32_t area_id, uint16_t lsuint) {
printf(" ** set_ls_info_id(..) called \n");
ls_info_t ls_info = make_ls_info_id(router, area_id, lsuint);
set_ls_info(router, ls_info);
}
void display_ls_info(ls_info_t ls_info) {
printf(" ** id: %u, area id: %u, lsu int: %u, lsu seq: %lu\n", ls_info.router_id, ls_info.area_id, ls_info.lsuint, ls_info.lsu_seq);
}
void set_ping_info(sr_router* router, uint32_t rest, uint32_t ip, int fd) {
router->ping_info.rest = rest;
router->ping_info.ip = ip;
router->ping_info.fd = fd;
}
void clear_ping_info(sr_router* router) {
router->ping_info.rest = 0;
router->ping_info.ip = 0;
router->ping_info.fd = 0;
}
bool check_ospf_status(sr_router* router) {
return router->ospf_status;
}
void hw_init(sr_router* router) {
printf(" ** hw_init(..) called\n");
router->hw_device.device_name = DEFAULT_IFACE;
if(check_iface(&router->hw_device) == 0) {
int ret = openDescriptor(&router->hw_device);
if(ret < 0) {
printf(" ** hw_init(..): error opening device\n");
exit(1);
}
}
}
void toggle_reroute_multipath_status(sr_router* router, bool status) {
router->reroute_multipath_status = status;
//check if route/multipath is enabled
if(router->reroute_multipath_status == TRUE) {
//run multipath
reroute_multipath(router);
}
}
bool show_reroute_multipath_status(sr_router* router) {
return router->reroute_multipath_status;
}
void toggle_reroute_multipath() {
struct sr_instance* sr_inst = get_sr();
struct sr_router* router = (struct sr_router*)sr_get_subsystem(sr_inst);
char *str;
bool status = show_reroute_multipath_status(router);
if (status == TRUE) {
toggle_reroute_multipath_status(router, FALSE);
asprintf(&str, "Reroute and Multipath disabled\n");
cli_send_str(str);
free(str);
} else {
toggle_reroute_multipath_status(router, TRUE);
asprintf(&str, "Reroute and Multipath enabled\n");
cli_send_str(str);
free(str);
}
}
void show_reroute_multipath() {
struct sr_instance* sr_inst = get_sr();
struct sr_router* router = (struct sr_router*)sr_get_subsystem(sr_inst);
char *str;
bool status = show_reroute_multipath_status(router);
if (status == TRUE) {
asprintf(&str, "Reroute and Multipath is enabled\n");
cli_send_str(str);
free(str);
} else {
asprintf(&str, "Reroute and Multipath is disabled\n");
cli_send_str(str);
free(str);
}
}