OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bgp_session.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef SRC_BGP_BGP_SESSION_H_
6 #define SRC_BGP_BGP_SESSION_H_
7 
8 #include <boost/scoped_ptr.hpp>
9 
10 #include <string>
11 
12 #include "bgp/bgp_proto.h"
13 #include "io/tcp_session.h"
14 
15 class BgpPeer;
16 class BgpSessionManager;
17 
19 public:
20  BgpMessageReader(TcpSession *session, ReceiveCallback callback);
21  virtual ~BgpMessageReader();
22 
23 protected:
24  virtual int MsgLength(Buffer buffer, int offset);
25 
26  virtual const int GetHeaderLenSize() {
27  return kHeaderLenSize;
28  }
29 
30  virtual const int GetMaxMessageSize() {
31  return kMaxMessageSize;
32  }
33 
34 private:
35  static const int kHeaderLenSize = 18;
36  static const int kMaxMessageSize = 4096;
37 
39 };
40 
41 class BgpSession : public TcpSession {
42 public:
43  BgpSession(BgpSessionManager *session_mgr, Socket *socket);
44  virtual ~BgpSession();
45 
46  void SendNotification(int code, int subcode,
47  const std::string &data = std::string());
48  virtual int GetSessionInstance() const { return task_instance_; }
49  void ProcessWriteReady();
50 
51  void set_peer(BgpPeer *peer);
52  void clear_peer();
53  BgpPeer *peer() { return peer_; }
54  void LogNotification(int code, int subcode, const std::string &direction,
55  const std::string &peer_key,
56  const BgpProto::Notification &msg) const;
57 
58 protected:
59  virtual void OnRead(Buffer buffer) {
60  reader_->OnRead(buffer);
61  }
62 
63 private:
64  bool ReceiveMsg(const u_int8_t *msg, size_t size);
65  virtual void WriteReady(const boost::system::error_code &error);
66 
70  boost::scoped_ptr<BgpMessageReader> reader_;
71 
73 };
74 
75 #endif // SRC_BGP_BGP_SESSION_H_
virtual void WriteReady(const boost::system::error_code &error)
Definition: bgp_session.cc:91
boost::asio::const_buffer Buffer
Definition: tcp_session.h:64
boost::scoped_ptr< BgpMessageReader > reader_
Definition: bgp_session.h:70
boost::function< bool(const uint8_t *, size_t)> ReceiveCallback
Definition: tcp_session.h:311
DISALLOW_COPY_AND_ASSIGN(BgpSession)
void ProcessWriteReady()
Definition: bgp_session.cc:71
BgpSessionManager * session_mgr_
Definition: bgp_session.h:67
void set_peer(BgpPeer *peer)
Definition: bgp_session.cc:128
boost::asio::ip::tcp::socket Socket
Definition: tcp_session.h:60
virtual ~BgpSession()
Definition: bgp_session.cc:53
static const int kMaxMessageSize
Definition: bgp_session.h:36
virtual int MsgLength(Buffer buffer, int offset)
Definition: bgp_session.cc:22
virtual const int GetMaxMessageSize()
Definition: bgp_session.h:30
DISALLOW_COPY_AND_ASSIGN(BgpMessageReader)
boost::asio::const_buffer Buffer
Definition: tcp_session.h:310
bool ReceiveMsg(const u_int8_t *msg, size_t size)
Definition: bgp_session.cc:59
virtual int GetSessionInstance() const
Definition: bgp_session.h:48
virtual ~BgpMessageReader()
Definition: bgp_session.cc:41
BgpPeer * peer()
Definition: bgp_session.h:53
int task_instance_
Definition: bgp_session.h:69
static const int kHeaderLenSize
Definition: bgp_session.h:35
void clear_peer()
Definition: bgp_session.cc:138
virtual void OnRead(Buffer buffer)
Definition: bgp_session.h:59
BgpPeer * peer_
Definition: bgp_session.h:68
void LogNotification(int code, int subcode, const std::string &direction, const std::string &peer_key, const BgpProto::Notification &msg) const
Definition: bgp_session.cc:97
void SendNotification(int code, int subcode, const std::string &data=std::string())
Definition: bgp_session.cc:112
virtual Socket * socket() const
Definition: tcp_session.h:86
BgpMessageReader(TcpSession *session, ReceiveCallback callback)
Definition: bgp_session.cc:36
virtual const int GetHeaderLenSize()
Definition: bgp_session.h:26
BgpSession(BgpSessionManager *session_mgr, Socket *socket)
Definition: bgp_session.cc:44