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