OLD | NEW |
(Empty) | |
| 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 /* |
| 3 * Copyright (c) 2011 UPB |
| 4 * Copyright (c) 2017 NITK Surathkal |
| 5 * |
| 6 * This program is free software; you can redistribute it and/or modify |
| 7 * it under the terms of the GNU General Public License version 2 as |
| 8 * published by the Free Software Foundation; |
| 9 * |
| 10 * This program is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 * GNU General Public License for more details. |
| 14 * |
| 15 * You should have received a copy of the GNU General Public License |
| 16 * along with this program; if not, write to the Free Software |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 * |
| 19 * Author: Radu Lupu <rlupu@elcom.pub.ro> |
| 20 * Ankit Deepak <adadeepak8@gmail.com> |
| 21 * Deepti Rajagopal <deeptir96@gmail.com> |
| 22 * |
| 23 */ |
| 24 |
| 25 #ifndef DHCP_SERVER_H |
| 26 #define DHCP_SERVER_H |
| 27 |
| 28 #include "ns3/application.h" |
| 29 #include "ns3/event-id.h" |
| 30 #include "ns3/ptr.h" |
| 31 #include "ns3/address.h" |
| 32 #include <ns3/traced-value.h> |
| 33 #include "dhcp-header.h" |
| 34 #include <map> |
| 35 |
| 36 namespace ns3 { |
| 37 |
| 38 class Socket; |
| 39 class Packet; |
| 40 |
| 41 /** |
| 42 * \ingroup dhcp |
| 43 * |
| 44 * \class DhcpServer |
| 45 * \brief Implements the functionality of a DHCP server |
| 46 */ |
| 47 class DhcpServer : public Application |
| 48 { |
| 49 public: |
| 50 /** |
| 51 * \brief Get the type ID. |
| 52 * \return the object TypeId |
| 53 */ |
| 54 static TypeId GetTypeId (void); |
| 55 |
| 56 /** |
| 57 * \brief Constructor |
| 58 */ |
| 59 DhcpServer (); |
| 60 |
| 61 /** |
| 62 * \brief Destructor |
| 63 */ |
| 64 virtual ~DhcpServer (); |
| 65 |
| 66 protected: |
| 67 virtual void DoDispose (void); |
| 68 |
| 69 private: |
| 70 static const int PORT = 67; //!< Port number of DHCP ser
ver |
| 71 |
| 72 /* |
| 73 * \brief Handles incoming packets from the network |
| 74 * \param socket Socket bound to port 67 of the DHCP server |
| 75 */ |
| 76 void NetHandler (Ptr<Socket> socket); |
| 77 |
| 78 /* |
| 79 * \brief Sends DHCP offer after receiving DHCP Discover |
| 80 * \param header DHCP header of the received message |
| 81 * \param from Address of the DHCP client |
| 82 */ |
| 83 void SendOffer (DhcpHeader header, Address from); |
| 84 |
| 85 /* |
| 86 * \brief Sends DHCP ACK (or NACK) after receiving Request |
| 87 * \param header DHCP header of the received message |
| 88 * \param from Address of the DHCP client |
| 89 */ |
| 90 void SendAck (DhcpHeader header, Address from); |
| 91 |
| 92 /* |
| 93 * \brief Modifies the remaining lease time of addresses |
| 94 */ |
| 95 void TimerHandler (void); |
| 96 |
| 97 /* |
| 98 * \brief Starts the DHCP Server application |
| 99 */ |
| 100 virtual void StartApplication (void); |
| 101 |
| 102 /* |
| 103 * \brief Stops the DHCP client application |
| 104 */ |
| 105 virtual void StopApplication (void); |
| 106 |
| 107 Ptr<Socket> m_socket; //!< The socket bound to port 67 |
| 108 Address m_local; //!< The local address |
| 109 Ipv4Address m_poolAddress; //!< The network address available to t
he server |
| 110 Ipv4Address m_minAddress; //!< The first address in the address p
ool |
| 111 Ipv4Address m_maxAddress; //!< The last address in the address po
ol |
| 112 uint32_t m_occurange; //!< Number of occupied address in the
pool |
| 113 Ipv4Mask m_poolMask; //!< The network mask of the pool |
| 114 Ipv4Address m_server; //!< Address of DHCP server |
| 115 Ipv4Address m_peer; //!< Address of DHCP client |
| 116 Ipv4Address m_gateway; //!< Store the gateway address |
| 117 std::map<std::pair<Address, Ipv4Address>, uint32_t> m_leasedAddresses; //!< Le
ased address and their status (cache memory) |
| 118 uint32_t m_nextAddressSeq; //!< The next address in the sequence w
hich can be alloted |
| 119 Time m_lease; //!< The granted lease time for an addr
ess |
| 120 Time m_renew; //!< The renewal time for an address |
| 121 Time m_rebind; //!< The rebinding time for an address |
| 122 EventId m_expiredEvent; //!< The Event to trigger TimerHandler |
| 123 }; |
| 124 |
| 125 } // namespace ns3 |
| 126 |
| 127 #endif /* DHCP_SERVER_H */ |
OLD | NEW |