-
Notifications
You must be signed in to change notification settings - Fork 0
/
sr_interface.h
85 lines (59 loc) · 2.21 KB
/
sr_interface.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
/*
* Filename: sr_interface.h
* Purpose: Data structure containing information about an interface.
*/
#ifndef SR_INTERFACE_H
#define SR_INTERFACE_H
#include <pthread.h>
#include "sr_common.h"
#include "sr_base_internal.h"
#include "linked_list.h"
#define SR_NAMELEN 32
#define PWOSPF_HELLO_INTERVAL 5;
/* forward declaration */
struct neighbor_t;
struct sr_router;
/** holds info about a router's interface */
typedef struct {
char name[SR_NAMELEN]; /* name of the interface */
addr_mac_t mac; /* MAC address of the interface */
addr_ip_t ip; /* IP address of the interface */
bool enabled; /* whether the interface is on */
addr_ip_t subnet_mask; /* subnet mask of the link */
#ifdef _CPUMODE_
# define INTF0 0x02
# define INTF1 0x08
# define INTF2 0x20
# define INTF3 0x80
byte hw_id; /* hardware id of the interface */
uint32_t hw_port;
int hw_fd; /* socket file descriptor to talk to the hw */
pthread_mutex_t hw_lock; /* lock to prevent issues w/ multiple writers */
#endif
pthread_mutex_t neighbor_lock;
node* neighbor_list; /* neighboring nodes */
uint16_t helloint;
uint32_t router_id;
uint32_t area_id;
uint16_t lsuint;
} interface_t;
interface_t set_interface(struct sr_vns_if* vns_intf, int intf_num);
interface_t make_interface(char* name, addr_mac_t mac, addr_ip_t ip, bool enabled, addr_ip_t subnet_mask);
interface_t* get_interface_name(struct sr_router* router, const char* name);
interface_t* get_interface_ip(struct sr_router* router, addr_ip_t ip);
void interface_init(struct sr_router* subsystem);
void display_interface(interface_t* intf);
void display_all_interfaces();
void display_all_interfaces_str();
void toggle_interface(interface_t* intf, int enabled);
bool check_interface(interface_t* intf);
void display_all_interfaces_neighbors_str();
void write_interface_hw(struct sr_router* router);
uint32_t get_hw_port(int intf_num);
interface_t get_hw_intf(int hw_port);
void read_interface_hw();
void read_info_hw();
uint16_t get_hw_port_from_name(char*);
uint16_t get_num_from_name(char* intf_name);
char* get_interface_from_multiple_hw_ports(uint16_t ports);
#endif /* SR_INTERFACE_H */