-
Notifications
You must be signed in to change notification settings - Fork 2
/
sr_router.h
81 lines (67 loc) · 2.44 KB
/
sr_router.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
/*-----------------------------------------------------------------------------
* File: sr_router.h
* Date: ?
* Authors: Guido Apenzeller, Martin Casado, Virkam V.
* Contact: [email protected]
* Edited b: Marcela Melara 16 Mar 2014.
*
*---------------------------------------------------------------------------*/
#ifndef SR_ROUTER_H
#define SR_ROUTER_H
#include <netinet/in.h>
#include <sys/time.h>
#include <stdio.h>
#include "sr_protocol.h"
#include "sr_arpcache.h"
/* we dont like this debug , but what to do for varargs ? */
#ifdef _DEBUG_
#define Debug(x, args...) printf(x, ## args)
#define DebugMAC(x) \
do { int ivyl; for(ivyl=0; ivyl<5; ivyl++) printf("%02x:", \
(unsigned char)(x[ivyl])); printf("%02x",(unsigned char)(x[5])); } while (0)
#else
#define Debug(x, args...) do{}while(0)
#define DebugMAC(x) do{}while(0)
#endif
#define INIT_TTL 255
#define PACKET_DUMP_SIZE 1024
/* forward declare */
struct sr_if;
struct sr_rt;
/* ----------------------------------------------------------------------------
* struct sr_instance
*
* Encapsulation of the state for a single virtual router.
*
* -------------------------------------------------------------------------- */
struct sr_instance
{
int sockfd; /* socket to server */
char user[32]; /* user name */
char host[32]; /* host name */
char template[30]; /* template name if any */
unsigned short topo_id;
struct sockaddr_in sr_addr; /* address to server */
struct sr_if* if_list; /* list of interfaces */
struct sr_rt* routing_table; /* routing table */
struct sr_arpcache cache; /* ARP cache */
pthread_attr_t attr;
FILE* logfile;
};
/* -- sr_main.c -- */
int sr_verify_routing_table(struct sr_instance* sr);
/* -- sr_vns_comm.c -- */
int sr_send_packet(struct sr_instance* , uint8_t* , unsigned int , const char*);
int sr_connect_to_server(struct sr_instance* ,unsigned short , char* );
int sr_read_from_server(struct sr_instance* );
/* -- sr_router.c -- */
void sr_init(struct sr_instance* );
void sr_handlepacket(struct sr_instance* , uint8_t * , unsigned int , char* );
/* -- sr_if.c -- */
void sr_add_interface(struct sr_instance* , const char* );
void sr_set_ether_ip(struct sr_instance* , uint32_t );
void sr_set_ether_addr(struct sr_instance* , const unsigned char* );
void sr_print_if_list(struct sr_instance* );
/* -- sr_arpcache.c and sr_router.c -- */
void handle_arpreq(struct sr_instance* , struct sr_arpreq* );
#endif /* SR_ROUTER_H */