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  */
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/bind.hpp>
10 #include <boost/function.hpp>
11 #include <boost/asio.hpp>
12 
13 #include <pkt/vrouter_interface.h>
14 
15 using namespace boost::placeholders;
16 
17 // pkt0 interface implementation of VrouterControlInterface
19 public:
20  typedef std::vector<boost::asio::const_buffer> buffer_list;
21 
22  Pkt0Interface(const std::string &name, boost::asio::io_context *io);
23  virtual ~Pkt0Interface();
24 
25  virtual void InitControlInterface();
26  virtual void IoShutdownControlInterface();
27  virtual void ShutdownControlInterface();
28 
29  const std::string &Name() const { return name_; }
30  int Send(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt);
31  const unsigned char *mac_address() const { return mac_address_; }
32 protected:
33  // Implements system specific send for Pkt0Interface
34  void SendImpl(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt,
35  buffer_list& buff_list);
36 
37  void AsyncRead();
38  void ReadHandler(const boost::system::error_code &err, std::size_t length);
39  void WriteHandler(const boost::system::error_code &error,
40  std::size_t length, uint8_t *buff);
41 
42  std::string name_;
43  int tap_fd_;
44  unsigned char mac_address_[ETHER_ADDR_LEN];
45 
46  boost::asio::posix::stream_descriptor input_;
47 
48  uint8_t *read_buff_;
51 };
52 
54 public:
55  Pkt0RawInterface(const std::string &name, boost::asio::io_context *io);
56  virtual ~Pkt0RawInterface();
57 
58  void InitControlInterface();
59 
60 protected:
62 };
63 
65 public:
66  static const uint32_t kConnectTimeout = 1000; // 1 second
67  static string sSocketDir;
68  static string sAgentSocketPath;
69  static string sVrouterSocketPath;
70  static void CreateMockAgent(const string&);
71 
72  Pkt0Socket(const std::string &name,
73  boost::asio::io_context *io);
74  ~Pkt0Socket();
75 
76  virtual void InitControlInterface();
77  virtual void IoShutdownControlInterface();
78  virtual void ShutdownControlInterface();
79  const std::string &Name() const { return name_; }
80 
81  int Send(uint8_t *buff, uint16_t buff_len, const PacketBufferPtr &pkt);
82 private:
83  void AsyncRead();
84  void ReadHandler(const boost::system::error_code &err, std::size_t length);
85  void WriteHandler(const boost::system::error_code &error,
86  std::size_t length, PacketBufferPtr pkt, uint8_t *buff);
87  void CreateUnixSocket();
88  void StartConnectTimer();
89  bool OnTimeout();
90  bool connected_;
91 
92  boost::asio::local::datagram_protocol::socket socket_;
93 
94  boost::scoped_ptr<Timer> timer_;
95  uint8_t *read_buff_;
97  std::string name_;
99 };
100 #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:11
boost::shared_ptr< PacketBuffer > PacketBufferPtr
Definition: packet_buffer.h:18