-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.h
58 lines (52 loc) · 1.25 KB
/
client.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
#ifndef CLIENT_H_
#define CLIENT_H_
#include <stdint.h>
#include <map>
#include <queue>
#include <set>
typedef struct {
uint8_t version;
uint8_t type;
uint16_t length;
uint32_t xid;
uint8_t data[];
} __attribute__((packed)) ofp_header_t;
class Write {
public:
uint8_t* data;
uint16_t pos;
uint16_t size;
Write(uint8_t*, uint16_t);
};
/*
* Clients are state machines. A client is either waiting to receive a header,
* or it is waiting to receive a packet.
* It is always known how many bytes a client has to receive for a given state.
*/
class Client {
public:
Client(int, void*);
void init();
void write_packet(void*, uint16_t);
void handle_read_event();
void flush_write_queue();
uint64_t uid;
ofp_header_t* cur_packet;
void* server;
uint8_t canwrite;
std::set<uint32_t> ports;
std::map<uint64_t, uint32_t> hosts; // Directly-connected hosts
std::map<uint64_t, uint32_t> written; // Switch's current next-hop
uint8_t has_mst;
private:
void handle_header();
void handle_packet();
int read_into_buffer();
void close_client();
int fd;
uint16_t bufsize;
uint16_t pos;
std::queue<Write> write_queue;
uint8_t state;
};
#endif /* CLIENT_H_ */