OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dhcp_proto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_dhcp_proto_hpp
6 #define vnsw_agent_dhcp_proto_hpp
7 
8 #include "pkt/proto.h"
10 
11 #define DHCP_TRACE(obj, arg) \
12 do { \
13  std::ostringstream _str; \
14  _str << arg; \
15  Dhcp##obj::TraceMsg(DhcpTraceBuf, __FILE__, __LINE__, _str.str()); \
16 } while (false) \
17 
18 class Timer;
19 class Interface;
21 typedef boost::asio::ip::udp boost_udp;
22 
23 class DhcpProto : public Proto {
24 public:
25  static const uint32_t kDhcpMaxPacketSize = 1024;
26  static const uint32_t kDhcpLeaseFileDeleteTimeout = 60 * 60 * 1000; // 60min
27 
28  enum DhcpMsgType {
30  };
31 
32  typedef std::map<Interface *, DhcpLeaseDb *> LeaseManagerMap;
33  typedef std::pair<Interface *, DhcpLeaseDb *> LeaseManagerPair;
34 
36  uint8_t *pkt;
37  uint32_t len;
38 
39  DhcpVhostMsg(uint8_t *dhcp, uint32_t length)
40  : InterTaskMsg(DHCP_VHOST_MSG), pkt(dhcp), len(length) {}
41  virtual ~DhcpVhostMsg() { if (pkt) delete [] pkt; }
42  };
43 
44  struct DhcpStats {
45  DhcpStats() { Reset(); }
46  void Reset() {
50  }
51 
52  uint32_t discover;
53  uint32_t request;
54  uint32_t inform;
55  uint32_t decline;
56  uint32_t release;
57  uint32_t other;
58  uint32_t offers;
59  uint32_t acks;
60  uint32_t nacks;
61  uint32_t relay_req;
62  uint32_t relay_resp;
63  uint32_t errors;
64  uint32_t unknown_msg_drop;
66  uint32_t incorrect_mac;
67  };
68 
69  void Shutdown();
70  DhcpProto(Agent *agent, boost::asio::io_context &io, bool run_with_vrouter);
71  virtual ~DhcpProto();
72  ProtoHandler *AllocProtoHandler(boost::shared_ptr<PktInfo> info,
73  boost::asio::io_context &io);
74  void SendDhcpIpc(uint8_t *dhcp, std::size_t len);
75 
76  bool dhcp_relay_mode() const { return dhcp_relay_mode_; }
77  void set_dhcp_relay_mode(bool mode) { dhcp_relay_mode_ = mode; }
78 
81  uint32_t ip_fabric_interface_index() const {
83  }
84  void set_ip_fabric_interface_index(uint32_t ind) {
86  }
87  uint32_t pkt_interface_index() const {
88  return pkt_interface_index_;
89  }
90  void set_pkt_interface_index(uint32_t ind) {
92  }
95  }
98  }
99  bool IsRunningWithVrouter() const { return run_with_vrouter_; }
100 
108  void IncrStatsAcks() { stats_.acks++; }
116  const DhcpStats &GetStats() const { return stats_; }
117  void ClearStats() { stats_.Reset(); }
118 
119  void CreateLeaseDb(VmInterface *vmi);
120  void DeleteLeaseDb(VmInterface *vmi);
121  DhcpLeaseDb *GetLeaseDb(Interface *intrface);
122  const LeaseManagerMap &lease_manager() const { return lease_manager_; }
123 
124 private:
125  void ItfNotify(DBEntryBase *entry);
126  void VnNotify(DBEntryBase *entry);
127  void AsyncRead();
128  void ReadHandler(const boost::system::error_code &error, std::size_t len);
129  std::string GetLeaseFileName(const VmInterface *vmi);
131  bool LeaseFileCleanupExpiry(uint32_t seqno);
132 
142 
143  boost::asio::ip::udp::socket dhcp_server_socket_;
144  boost::asio::ip::udp::endpoint remote_endpoint_;
146 
147  std::set<VmInterface *> gw_vmi_list_;
151 
153 };
154 
155 #endif // vnsw_agent_dhcp_proto_hpp
void DeleteLeaseDb(VmInterface *vmi)
Definition: dhcp_proto.cc:206
MacAddress ip_fabric_interface_mac_
Definition: dhcp_proto.h:138
uint32_t pkt_interface_index() const
Definition: dhcp_proto.h:87
void StartLeaseFileCleanupTimer()
Definition: dhcp_proto.cc:252
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
Definition: dhcp_proto.cc:113
void set_ip_fabric_interface_index(uint32_t ind)
Definition: dhcp_proto.h:84
DISALLOW_COPY_AND_ASSIGN(DhcpProto)
uint32_t unknown_msg_drop
Definition: dhcp_proto.h:64
uint8_t * dhcp_server_read_buf_
Definition: dhcp_proto.h:145
void IncrStatsInform()
Definition: dhcp_proto.h:103
bool IsRunningWithVrouter() const
Definition: dhcp_proto.h:99
void Shutdown()
Definition: dhcp_proto.cc:63
void IncrStatsOffers()
Definition: dhcp_proto.h:107
void ClearStats()
Definition: dhcp_proto.h:117
uint32_t ip_fabric_interface_index_
Definition: dhcp_proto.h:136
DhcpLeaseDb * GetLeaseDb(Interface *intrface)
Definition: dhcp_proto.cc:226
void IncrStatsRelease()
Definition: dhcp_proto.h:105
int ListenerId
Definition: db_table.h:62
void IncrStatsNacks()
Definition: dhcp_proto.h:109
uint32_t gateway_delete_seqno_
Definition: dhcp_proto.h:149
void AsyncRead()
Definition: dhcp_proto.cc:82
LeaseManagerMap lease_manager_
Definition: dhcp_proto.h:148
DhcpStats stats_
Definition: dhcp_proto.h:141
void IncrIncorrectMac()
Definition: dhcp_proto.h:115
void IncrStatsOther()
Definition: dhcp_proto.h:106
const LeaseManagerMap & lease_manager() const
Definition: dhcp_proto.h:122
void set_ip_fabric_interface_mac(const MacAddress &mac)
Definition: dhcp_proto.h:96
void IncrStatsRelayReqs()
Definition: dhcp_proto.h:110
void ReadHandler(const boost::system::error_code &error, std::size_t len)
Definition: dhcp_proto.cc:92
DBTableBase::ListenerId iid_
Definition: dhcp_proto.h:139
Timer * lease_file_cleanup_timer_
Definition: dhcp_proto.h:150
void IncrStatsErrors()
Definition: dhcp_proto.h:112
bool LeaseFileCleanupExpiry(uint32_t seqno)
Definition: dhcp_proto.cc:260
Definition: agent.h:358
Interface * ip_fabric_interface() const
Definition: dhcp_proto.h:79
void CreateLeaseDb(VmInterface *vmi)
Definition: dhcp_proto.cc:158
uint32_t incorrect_mac
Definition: dhcp_proto.h:66
void IncrStatsAcks()
Definition: dhcp_proto.h:108
void ItfNotify(DBEntryBase *entry)
Definition: dhcp_proto.cc:118
void set_dhcp_relay_mode(bool mode)
Definition: dhcp_proto.h:77
void VnNotify(DBEntryBase *entry)
Definition: dhcp_proto.cc:215
DhcpProto(Agent *agent, boost::asio::io_context &io, bool run_with_vrouter)
Definition: dhcp_proto.cc:19
static const uint32_t kDhcpLeaseFileDeleteTimeout
Definition: dhcp_proto.h:26
const DhcpStats & GetStats() const
Definition: dhcp_proto.h:116
void SendDhcpIpc(uint8_t *dhcp, std::size_t len)
Definition: dhcp_proto.cc:108
void IncrStatsDiscover()
Definition: dhcp_proto.h:101
void IncrUnknownMsgDrops()
Definition: dhcp_proto.h:113
std::pair< Interface *, DhcpLeaseDb * > LeaseManagerPair
Definition: dhcp_proto.h:33
void IncrDhcpDisabledDrops()
Definition: dhcp_proto.h:114
DBTableBase::ListenerId vnid_
Definition: dhcp_proto.h:140
const MacAddress & ip_fabric_interface_mac() const
Definition: dhcp_proto.h:93
uint32_t pkt_interface_index_
Definition: dhcp_proto.h:137
void IncrStatsDecline()
Definition: dhcp_proto.h:104
void IncrStatsRequest()
Definition: dhcp_proto.h:102
std::string GetLeaseFileName(const VmInterface *vmi)
Definition: dhcp_proto.cc:234
void set_pkt_interface_index(uint32_t ind)
Definition: dhcp_proto.h:90
bool dhcp_relay_mode() const
Definition: dhcp_proto.h:76
uint32_t dhcp_disabled_drop
Definition: dhcp_proto.h:65
uint32_t ip_fabric_interface_index() const
Definition: dhcp_proto.h:81
virtual ~DhcpProto()
Definition: dhcp_proto.cc:60
Definition: timer.h:54
std::map< Interface *, DhcpLeaseDb * > LeaseManagerMap
Definition: dhcp_proto.h:32
static const uint32_t kDhcpMaxPacketSize
Definition: dhcp_proto.h:25
DhcpVhostMsg(uint8_t *dhcp, uint32_t length)
Definition: dhcp_proto.h:39
bool dhcp_relay_mode_
Definition: dhcp_proto.h:134
boost::asio::ip::udp::endpoint remote_endpoint_
Definition: dhcp_proto.h:144
bool run_with_vrouter_
Definition: dhcp_proto.h:133
void set_ip_fabric_interface(Interface *itf)
Definition: dhcp_proto.h:80
Interface * ip_fabric_interface_
Definition: dhcp_proto.h:135
std::set< VmInterface * > gw_vmi_list_
Definition: dhcp_proto.h:147
void IncrStatsRelayResps()
Definition: dhcp_proto.h:111
boost::asio::ip::udp boost_udp
Definition: dhcp_proto.h:20
boost::asio::ip::udp::socket dhcp_server_socket_
Definition: dhcp_proto.h:143