OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pkt0_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_contrail_pkt0_interface_hpp
6 #define vnsw_agent_contrail_pkt0_interface_hpp
7 
8 #include <string>
9 #include <boost/bind.hpp>
10 #include <boost/function.hpp>
11 #include <boost/asio.hpp>
12 
13 #include <pkt/vrouter_interface.h>
14 
15 // pkt0 interface implementation of VrouterControlInterface
17 public:
18  typedef std::vector<boost::asio::const_buffer> buffer_list;
19 
20  Pkt0Interface(const std::string &name, boost::asio::io_context *io);
21  virtual ~Pkt0Interface();
22 
23  virtual void InitControlInterface();
24  virtual void IoShutdownControlInterface();
25  virtual void ShutdownControlInterface();
26 
27  const std::string &Name() const { return name_; }
28  int Send(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt);
29  const unsigned char *mac_address() const { return mac_address_; }
30 protected:
31  // Implements system specific send for Pkt0Interface
32  void SendImpl(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt,
33  buffer_list& buff_list);
34 
35  void AsyncRead();
36  void ReadHandler(const boost::system::error_code &err, std::size_t length);
37  void WriteHandler(const boost::system::error_code &error,
38  std::size_t length, uint8_t *buff);
39 
40  std::string name_;
41  int tap_fd_;
42  unsigned char mac_address_[ETHER_ADDR_LEN];
43 
44  boost::asio::posix::stream_descriptor input_;
45 
46  uint8_t *read_buff_;
49 };
50 
52 public:
53  Pkt0RawInterface(const std::string &name, boost::asio::io_context *io);
54  virtual ~Pkt0RawInterface();
55 
56  void InitControlInterface();
57 
58 protected:
60 };
61 
63 public:
64  static const uint32_t kConnectTimeout = 1000; // 1 second
65  static string sSocketDir;
66  static string sAgentSocketPath;
67  static string sVrouterSocketPath;
68  static void CreateMockAgent(const string&);
69 
70  Pkt0Socket(const std::string &name,
71  boost::asio::io_context *io);
72  ~Pkt0Socket();
73 
74  virtual void InitControlInterface();
75  virtual void IoShutdownControlInterface();
76  virtual void ShutdownControlInterface();
77  const std::string &Name() const { return name_; }
78 
79  int Send(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt);
80 private:
81  void AsyncRead();
82  void ReadHandler(const boost::system::error_code &err, std::size_t length);
83  void WriteHandler(const boost::system::error_code &error,
84  std::size_t length, PacketBufferPtr pkt, uint8_t *buff);
85  void CreateUnixSocket();
86  void StartConnectTimer();
87  bool OnTimeout();
88  bool connected_;
89 
90  boost::asio::local::datagram_protocol::socket socket_;
91 
92  boost::scoped_ptr<Timer> timer_;
93  uint8_t *read_buff_;
95  std::string name_;
97 };
98 #endif // vnsw_agent_contrail_pkt0_interface_hpp
boost::shared_ptr< PacketBuffer > PacketBufferPtr
Definition: packet_buffer.h:18
Pkt0RawInterface(const std::string &name, boost::asio::io_context *io)
std::string name_
static string sVrouterSocketPath
uint8_t * read_buff_
Pkt0Interface(const std::string &name, boost::asio::io_context *io)
void WriteHandler(const boost::system::error_code &error, std::size_t length, uint8_t *buff)
unsigned char mac_address_[ETHER_ADDR_LEN]
const unsigned char * mac_address() const
uint8_t * read_buff_
boost::asio::local::datagram_protocol::socket socket_
DISALLOW_COPY_AND_ASSIGN(Pkt0Interface)
virtual void IoShutdownControlInterface()
boost::scoped_ptr< Timer > timer_
static const uint32_t kConnectTimeout
virtual void IoShutdownControlInterface()
static void CreateMockAgent(const string &)
virtual void InitControlInterface()
DISALLOW_COPY_AND_ASSIGN(Pkt0Socket)
void ReadHandler(const boost::system::error_code &err, std::size_t length)
DISALLOW_COPY_AND_ASSIGN(Pkt0RawInterface)
std::string name_
virtual ~Pkt0Interface()
PktHandler * pkt_handler_
virtual void ShutdownControlInterface()
boost::asio::posix::stream_descriptor input_
std::vector< boost::asio::const_buffer > buffer_list
void ReadHandler(const boost::system::error_code &err, std::size_t length)
void WriteHandler(const boost::system::error_code &error, std::size_t length, PacketBufferPtr pkt, uint8_t *buff)
void SendImpl(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt, buffer_list &buff_list)
static string sSocketDir
static string sAgentSocketPath
const std::string & Name() const
int Send(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt)
int Send(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt)
Pkt0Socket(const std::string &name, boost::asio::io_context *io)
PktHandler * pkt_handler_
virtual void ShutdownControlInterface()
virtual void InitControlInterface()
const std::string & Name() const