-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink.hpp
More file actions
66 lines (59 loc) · 1.9 KB
/
Copy pathlink.hpp
File metadata and controls
66 lines (59 loc) · 1.9 KB
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
#ifndef LINK_H
#define LINK_H
#include "dbg.hpp"
#include "ip.hpp"
#include "routing.hpp"
#include <arpa/inet.h>
#include <cstdlib>
#include <iostream>
#include <map>
#include <netinet/in.h>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <vector>
class Routing;
struct protocol_handler {
int protocol_num;
void (*handler)(std::string, iphdr header);
};
class Link {
private:
/* data */
struct sockaddr_in address;
int self_port;
int sockfd;
std::vector<protocol_handler> handlers;
std::string serialize_routing_table(
std::map<int, struct routing_table_info> routing_table);
std::string serialize_nodes_info(
std::map<std::string, struct node_physical_info> nodes_info);
static std::vector<std::string> tokenize(const std::string &str, char delim);
public:
Link(int port);
int get_self_port();
int send_data(iphdr header, std::string data, std::string ip, int port);
void recv_data();
void
send_routing_table(std::map<int, struct routing_table_info> routing_table,
std::string ip, int port, std::string self_virtual_ip);
void
send_nodes_info(std::map<std::string, struct node_physical_info> nodes_info,
std::string ip, int port, std::string self_virtual_ip);
void send_quit_msg(std::string ip, int port);
void send_user_data(std::string virtual_ip, std::string payload,
Routing *routing, int protocol);
void register_handler(protocol_handler handler);
static std::map<int, struct routing_table_info>
deserialize_routing_table(std::string data);
static std::map<std::string, struct node_physical_info>
deserialize_nodes_info(std::string data);
void forwarding(std::string data, iphdr header, Routing *routing,
int protocol);
int get_arrived_interface(int last_hub, Routing *routing);
};
#endif