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_HEADER_H |
| 26 #define DHCP_HEADER_H |
| 27 |
| 28 #include "ns3/header.h" |
| 29 #include <ns3/mac48-address.h> |
| 30 #include <ns3/mac64-address.h> |
| 31 |
| 32 namespace ns3 { |
| 33 /** |
| 34 * \ingroup dhcp |
| 35 * |
| 36 * \class DhcpHeader |
| 37 * \brief BOOTP header with DHCP messages supports the following options: |
| 38 * Subnet Mask (1), Address Request (50), Refresh Lease Time (51), |
| 39 * DHCP Message Type (53), DHCP Server ID (54), Renew Time (58), |
| 40 * Rebind Time (59) and End (255) of BOOTP |
| 41 |
| 42 \verbatim |
| 43 0 1 2 3 |
| 44 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
| 45 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 46 | op (1) | htype (1) | hlen (1) | hops (1) | |
| 47 +---------------+---------------+---------------+---------------+ |
| 48 | xid (4) | |
| 49 +-------------------------------+-------------------------------+ |
| 50 | secs (2) | flags (2) | |
| 51 +-------------------------------+-------------------------------+ |
| 52 | ciaddr (4) | |
| 53 +---------------------------------------------------------------+ |
| 54 | yiaddr (4) | |
| 55 +---------------------------------------------------------------+ |
| 56 | siaddr (4) | |
| 57 +---------------------------------------------------------------+ |
| 58 | giaddr (4) | |
| 59 +---------------------------------------------------------------+ |
| 60 | | |
| 61 | chaddr (16) | |
| 62 | | |
| 63 | | |
| 64 +---------------------------------------------------------------+ |
| 65 | | |
| 66 | sname (64) | |
| 67 +---------------------------------------------------------------+ |
| 68 | | |
| 69 | file (128) | |
| 70 +---------------------------------------------------------------+ |
| 71 | | |
| 72 | options (variable) | |
| 73 +---------------------------------------------------------------+ |
| 74 \endverbatim |
| 75 |
| 76 */ |
| 77 class DhcpHeader : public Header |
| 78 { |
| 79 public: |
| 80 /** |
| 81 * \brief Get the type ID. |
| 82 * \return the object TypeId |
| 83 */ |
| 84 static TypeId GetTypeId (void); |
| 85 |
| 86 /** |
| 87 * \brief Constructor |
| 88 */ |
| 89 DhcpHeader (); |
| 90 |
| 91 /** |
| 92 * \brief Destructor |
| 93 */ |
| 94 ~DhcpHeader (); |
| 95 |
| 96 enum options |
| 97 { |
| 98 OP_MASK = 1, //!< BOOTP Option 1: Address Mask |
| 99 OP_ROUTE = 3, //!< BOOTP Option 3: Router Option |
| 100 OP_ADDREQ = 50, //!< BOOTP Option 50: Requested Address |
| 101 OP_LEASE = 51, //!< BOOTP Option 51: Address Lease Time |
| 102 OP_MSGTYPE = 53, //!< BOOTP Option 53: DHCP Message Type |
| 103 OP_SERVID = 54, //!< BOOTP Option 54: Server Identifier |
| 104 OP_RENEW = 58, //!< BOOTP Option 58: Address Renewal Time |
| 105 OP_REBIND = 59, //!< BOOTP Option 59: Address Rebind Time |
| 106 OP_END = 255 //!< BOOTP Option 255: END |
| 107 }; |
| 108 |
| 109 enum Messages |
| 110 { |
| 111 DHCPDISCOVER = 0, //!< Code for DHCP Discover |
| 112 DHCPOFFER = 1, //!< Code for DHCP Offer |
| 113 DHCPREQ = 2, //!< Code for DHCP Request |
| 114 DHCPACK = 4, //!< Code for DHCP ACK |
| 115 DHCPNACK = 5 //!< Code for DHCP NACK |
| 116 }; |
| 117 |
| 118 /** |
| 119 * \brief Set the type of BOOTP and DHCP messages |
| 120 * \param type The type of message |
| 121 */ |
| 122 void SetType (uint8_t type); |
| 123 |
| 124 /** |
| 125 * \brief Return the type of DHCP message |
| 126 * \return The type of message |
| 127 */ |
| 128 uint8_t GetType (void) const; |
| 129 |
| 130 /** |
| 131 * \brief Set the hardware information |
| 132 * \param htype Hardware type |
| 133 * \param hlen Hardware length |
| 134 */ |
| 135 void SetHWType (uint8_t htype, uint8_t hlen); |
| 136 |
| 137 /** |
| 138 * \brief Set the transaction ID |
| 139 * \param tran The transaction number |
| 140 */ |
| 141 void SetTran (uint32_t tran); |
| 142 |
| 143 /** |
| 144 * \brief Get the transaction id |
| 145 * \return The transaction id |
| 146 */ |
| 147 uint32_t GetTran (void) const; |
| 148 |
| 149 /** |
| 150 * \brief Set the time when message is sent |
| 151 */ |
| 152 void SetTime (); |
| 153 |
| 154 /** |
| 155 * \brief Set the Address of the device |
| 156 * \param addr Address of the device |
| 157 */ |
| 158 void SetChaddr (Address addr); |
| 159 |
| 160 /** |
| 161 * \brief Get the Address of the client |
| 162 * \return Address of the client |
| 163 */ |
| 164 Address GetChaddr (void); |
| 165 |
| 166 /** |
| 167 * \brief Set the IPv4Address of the client |
| 168 * \param addr The client Ipv4Address |
| 169 */ |
| 170 void SetYiaddr (Ipv4Address addr); |
| 171 |
| 172 /** |
| 173 * \brief Get the IPv4Address of the client |
| 174 * \return IPv4Address of the client |
| 175 */ |
| 176 Ipv4Address GetYiaddr (void) const; |
| 177 |
| 178 /** |
| 179 * \brief Set the DHCP server information |
| 180 * \param addr IPv4Address of the server |
| 181 */ |
| 182 void SetDhcps (Ipv4Address addr); |
| 183 |
| 184 /** |
| 185 * \brief Get the information about the DHCP server |
| 186 * \return IPv4Address of DHCP server |
| 187 */ |
| 188 Ipv4Address GetDhcps (void) const; |
| 189 |
| 190 /** |
| 191 * \brief Set the Ipv4Address requested by the client |
| 192 * \param addr Ipv4Address requested by the client |
| 193 */ |
| 194 void SetReq (Ipv4Address addr); |
| 195 |
| 196 /** |
| 197 * \brief Get the IPv4Address requested by the client |
| 198 * \return IPv4Address requested by the client |
| 199 */ |
| 200 Ipv4Address GetReq (void) const; |
| 201 |
| 202 /** |
| 203 * \brief Set the mask of the IPv4Address |
| 204 * \param addr 32 bit mask |
| 205 */ |
| 206 void SetMask (uint32_t addr); |
| 207 |
| 208 /** |
| 209 * \brief Return the mask of the network |
| 210 * \return 32 bit mask |
| 211 */ |
| 212 uint32_t GetMask (void) const; |
| 213 |
| 214 /** |
| 215 * \brief Set the Ipv4Address of gateway to be used |
| 216 * \param addr The Ipv4Address of the gateway |
| 217 */ |
| 218 void SetRouter (Ipv4Address addr); |
| 219 |
| 220 /** |
| 221 * \brief Return the Ipv4Address of gateway to be used |
| 222 * \return The Ipv4Address of the gateway |
| 223 */ |
| 224 Ipv4Address GetRouter (void) const; |
| 225 |
| 226 /** |
| 227 * \brief Set the lease time of the IPv4Address |
| 228 * \param time 32 bit time |
| 229 */ |
| 230 void SetLease (uint32_t time); |
| 231 |
| 232 /** |
| 233 * \brief Return the lease time of the IPv4Address |
| 234 * \return 32 bit time |
| 235 */ |
| 236 uint32_t GetLease (void) const; |
| 237 |
| 238 /** |
| 239 * \brief Set the Renewal time of the IPv4Address |
| 240 * \param time 32 bit time |
| 241 */ |
| 242 void SetRenew (uint32_t time); |
| 243 |
| 244 /** |
| 245 * \brief Return the Renewal time of the address |
| 246 * \return 32 bit time |
| 247 */ |
| 248 uint32_t GetRenew (void) const; |
| 249 |
| 250 /** |
| 251 * \brief Set the Rebind time of the IPv4Address |
| 252 * \param time 32 bit time |
| 253 */ |
| 254 void SetRebind (uint32_t time); |
| 255 |
| 256 /** |
| 257 * \brief Return the Rebind time of the address |
| 258 * \return 32 bit time |
| 259 */ |
| 260 uint32_t GetRebind (void) const; |
| 261 |
| 262 /** |
| 263 * \brief Reset the BOOTP options |
| 264 */ |
| 265 void ResetOpt (); |
| 266 |
| 267 private: |
| 268 virtual TypeId GetInstanceTypeId (void) const; |
| 269 virtual void Print (std::ostream &os) const; |
| 270 virtual uint32_t GetSerializedSize (void) const; |
| 271 virtual void Serialize (Buffer::Iterator start) const; |
| 272 virtual uint32_t Deserialize (Buffer::Iterator start); |
| 273 |
| 274 uint8_t m_op; //!< The DHCP Message type |
| 275 uint8_t m_bootp; //!< The BOOTP Message type |
| 276 uint8_t m_hType; //!< The hardware type |
| 277 uint8_t m_hLen; //!< The hardware length |
| 278 uint8_t m_hops; //!< The number of hops covered by the
message |
| 279 uint32_t m_xid; //!< The transaction number |
| 280 uint32_t m_mask; //!< The mask of the network |
| 281 uint32_t m_len; //!< The length of the header |
| 282 uint16_t m_secs; //!< Seconds elapsed |
| 283 uint16_t m_flags; //!< BOOTP flags |
| 284 uint8_t m_chaddr[16]; //!< The address identifier |
| 285 Ipv4Address m_yiAddr; //!< Your (client) IP address |
| 286 Ipv4Address m_ciAddr; //!< The IP address of the client |
| 287 Ipv4Address m_siAddr; //!< Next Server IP address |
| 288 Ipv4Address m_giAddr; //!< Relay Agent IP address |
| 289 Ipv4Address m_dhcps; //!< DHCP server IP address |
| 290 Ipv4Address m_req; //!< Requested Address |
| 291 Ipv4Address m_route; //!< Router Option Address |
| 292 uint8_t m_sname[64]; //!< Server name (Padded for now) |
| 293 uint8_t m_file[128]; //!< File name (Padded for now) |
| 294 uint8_t m_magic_cookie[4]; //!< DHCP Magic Cookie |
| 295 uint32_t m_lease; //!< The lease time of the address |
| 296 uint32_t m_renew; //!< The renewal time for the client |
| 297 uint32_t m_rebind; //!< The rebinding time for the client |
| 298 bool m_opt[255]; //!< BOOTP option list |
| 299 }; |
| 300 |
| 301 } // namespace ns3 |
| 302 |
| 303 #endif /* DHCP_HEADER_H */ |
LEFT | RIGHT |