LEFT | RIGHT |
(no file at all) | |
| 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_CLIENT_H |
| 26 #define DHCP_CLIENT_H |
| 27 |
| 28 #include "ns3/application.h" |
| 29 #include "ns3/event-id.h" |
| 30 #include "ns3/ptr.h" |
| 31 #include "ns3/ipv4-address.h" |
| 32 #include "ns3/random-variable-stream.h" |
| 33 #include "ns3/traced-value.h" |
| 34 #include "dhcp-header.h" |
| 35 #include <list> |
| 36 |
| 37 namespace ns3 { |
| 38 |
| 39 class Socket; |
| 40 class Packet; |
| 41 |
| 42 /** |
| 43 * \ingroup dhcp |
| 44 * |
| 45 * \class DhcpClient |
| 46 * \brief Implements the functionality of a DHCP client |
| 47 */ |
| 48 class DhcpClient : public Application |
| 49 { |
| 50 public: |
| 51 /** |
| 52 * \brief Get the type ID. |
| 53 * \return the object TypeId |
| 54 */ |
| 55 static TypeId |
| 56 GetTypeId (void); |
| 57 |
| 58 /** |
| 59 * \brief Constructor |
| 60 */ |
| 61 DhcpClient (); |
| 62 |
| 63 /** |
| 64 * \brief Destructor |
| 65 */ |
| 66 virtual ~DhcpClient (); |
| 67 |
| 68 /** |
| 69 * \brief Get the IPv4Address of current DHCP server |
| 70 * \return Ipv4Address of current DHCP server |
| 71 */ |
| 72 Ipv4Address GetDhcpServer (void); |
| 73 |
| 74 /** |
| 75 * Assign a fixed random variable stream number to the random variables |
| 76 * used by this model. Return the number of streams (possibly zero) that |
| 77 * have been assigned. |
| 78 * |
| 79 * \param stream First stream index to use |
| 80 * \return the number of stream indices assigned by this model |
| 81 */ |
| 82 int64_t AssignStreams (int64_t stream); |
| 83 |
| 84 protected: |
| 85 virtual void DoDispose (void); |
| 86 |
| 87 private: |
| 88 enum States |
| 89 { |
| 90 WAIT_OFFER = 1, //!< State of a client that waits for the offer |
| 91 REFRESH_LEASE = 2, //!< State of a client that needs to refresh the
lease |
| 92 WAIT_ACK = 9 //!< State of a client that waits for acknowledg
ement |
| 93 }; |
| 94 |
| 95 static const int DHCP_PEER_PORT = 67; //!< DHCP server port |
| 96 |
| 97 /* |
| 98 * \brief Starts the DHCP client application |
| 99 */ |
| 100 virtual void StartApplication (void); |
| 101 |
| 102 /* |
| 103 * \brief Stops the DHCP client application |
| 104 */ |
| 105 virtual void StopApplication (void); |
| 106 |
| 107 /* |
| 108 * \brief Handles changes in LinkState |
| 109 */ |
| 110 void LinkStateHandler (void); |
| 111 |
| 112 /* |
| 113 * \brief Handles incoming packets from the network |
| 114 * \param socket Socket bound to port 68 of the DHCP client |
| 115 */ |
| 116 void NetHandler (Ptr<Socket> socket); |
| 117 |
| 118 /* |
| 119 * \brief Sends DHCP DISCOVER and changes the client state to WAIT_OFFER |
| 120 */ |
| 121 void Boot (void); |
| 122 |
| 123 /* |
| 124 * \brief Stores DHCP offers in m_offerList |
| 125 * \param header DhcpHeader of the DHCP OFFER message |
| 126 */ |
| 127 void OfferHandler (DhcpHeader header); |
| 128 |
| 129 /* |
| 130 * \brief Selects an OFFER from m_offerList |
| 131 */ |
| 132 void Select (void); |
| 133 |
| 134 /* |
| 135 * \brief Sends the DHCP REQUEST message and changes the client state to WAIT_
ACK |
| 136 */ |
| 137 void Request (void); |
| 138 |
| 139 /* |
| 140 * \brief Receives the DHCP ACK and configures IP address of the client. |
| 141 * It also triggers the timeout, renew and rebind events. |
| 142 * \param header DhcpHeader of the DHCP ACK message |
| 143 * \param from Address of DHCP server that sent the DHCP ACK |
| 144 */ |
| 145 void AcceptAck (DhcpHeader header, Address from); |
| 146 |
| 147 /* |
| 148 * \brief Remove the current DHCP information and restart the process |
| 149 */ |
| 150 void RemoveAndStart (); |
| 151 |
| 152 uint8_t m_state; //!< State of the DHCP client |
| 153 uint32_t device; //!< Device identifier |
| 154 Ptr<Socket> m_socket; //!< Socket for remote communication |
| 155 Ipv4Address m_remoteAddress; //!< Initially set to 255.255.255.255 t
o start DHCP |
| 156 Ipv4Address m_offeredAddress; //!< Address offered to the client |
| 157 Ipv4Address m_myAddress; //!< Address assigned to the client |
| 158 Ipv4Mask m_myMask; //!< Mask of the address assigned |
| 159 Ipv4Address m_server; //!< Address of the DHCP server |
| 160 Ipv4Address m_gateway; //!< Address of the gateway |
| 161 EventId m_requestEvent; //!< Address refresh event |
| 162 EventId m_discoverEvent; //!< Message retransmission event |
| 163 EventId m_refreshEvent; //!< Message refresh event |
| 164 EventId m_rebindEvent; //!< Message rebind event |
| 165 EventId m_nextOfferEvent; //!< Message next offer event |
| 166 EventId m_timeout; //!< The timeout period |
| 167 Time m_lease; //!< Store the lease time of address |
| 168 Time m_renew; //!< Store the renew time of address |
| 169 Time m_rebind; //!< Store the rebind time of address |
| 170 Time m_nextoffer; //!< Time to try the next offer (if req
uest gets no reply) |
| 171 Ptr<RandomVariableStream> m_ran; //!< Uniform random variable for transa
ction ID |
| 172 Time m_rtrs; //!< Defining the time for retransmissi
on |
| 173 Time m_collect; //!< Time for which client should colle
ct offers |
| 174 bool m_offered; //!< Specify if the client has got any
offer |
| 175 std::list<DhcpHeader> m_offerList; //!< Stores all the offers given to the
client |
| 176 uint32_t m_tran; //!< Stores the current transaction num
ber to be used |
| 177 TracedCallback<const Ipv4Address&> m_newLease;//!< Trace of new lease |
| 178 TracedCallback<const Ipv4Address&> m_expiry; //!< Trace of expiry |
| 179 }; |
| 180 |
| 181 } // namespace ns3 |
| 182 |
| 183 #endif /* DHCP_CLIENT_H */ |
LEFT | RIGHT |