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