-
Notifications
You must be signed in to change notification settings - Fork 390
/
bfd_udp_connection.h
56 lines (43 loc) · 1.74 KB
/
bfd_udp_connection.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
/*
* Copyright (c) 2014 CodiLime, Inc. All rights reserved.
*/
#ifndef SRC_BFD_UDP_CONNECTION_H_
#define SRC_BFD_UDP_CONNECTION_H_
#include "bfd/bfd_connection.h"
#include <boost/optional.hpp>
#include "io/udp_server.h"
namespace BFD {
class UDPConnectionManager : public Connection {
public:
typedef boost::function<void(const ControlPacket *)> RecvCallback;
UDPConnectionManager(EventManager *evm, int recvPort = kRecvPortDefault,
int remotePort = kRecvPortDefault);
~UDPConnectionManager();
void RegisterCallback(RecvCallback callback);
virtual void SendPacket(const boost::asio::ip::address &dstAddr,
const ControlPacket *packet);
private:
static const int kRecvPortDefault = 3784;
static const int kSendPortMin = 49152;
static const int kSendPortMax = 65535;
class UDPRecvServer : public UdpServer {
boost::optional<RecvCallback> callback_;
public:
UDPRecvServer(EventManager *evm, int recvPort);
void RegisterCallback(RecvCallback callback);
void HandleReceive(const boost::asio::const_buffer &recv_buffer,
boost::asio::ip::udp::endpoint remote_endpoint,
std::size_t bytes_transferred,
const boost::system::error_code& error);
} *udpRecv_;
class UDPCommunicator : public UdpServer {
const int remotePort_;
public:
UDPCommunicator(EventManager *evm, int remotePort);
virtual void SendPacket(const boost::asio::ip::address &dstAddr,
const ControlPacket *packet);
// TODO(bfd) add multiple instances to randomize source port (RFC5881)
} *udpSend_;
};
} // namespace BFD
#endif // SRC_BFD_UDP_CONNECTION_H_