LEFT | RIGHT |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2011 UPB | 3 * Copyright (c) 2011 UPB |
| 4 * Copyright (c) 2017 NITK Surathkal |
4 * | 5 * |
5 * This program is free software; you can redistribute it and/or modify | 6 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 7 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 8 * published by the Free Software Foundation; |
8 * | 9 * |
9 * This program is distributed in the hope that it will be useful, | 10 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 13 * GNU General Public License for more details. |
13 * | 14 * |
14 * You should have received a copy of the GNU General Public License | 15 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 16 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 18 * |
18 * Author: Radu Lupu <rlupu@elcom.pub.ro> for previous patch of DHCP on ns-3.12 | 19 * Author: Radu Lupu <rlupu@elcom.pub.ro> |
19 * Ankit Deepak <adadeepak8@gmail.com> and | 20 * Ankit Deepak <adadeepak8@gmail.com> |
20 * Deepti Rajagopal <deeptir96@gmail.com> for DHCP patch on ns-3.25 | 21 * Deepti Rajagopal <deeptir96@gmail.com> |
21 * | 22 * |
22 */ | 23 */ |
23 | 24 |
24 #include "ns3/log.h" | 25 #include "ns3/log.h" |
25 #include "ns3/assert.h" | 26 #include "ns3/assert.h" |
26 #include "ns3/ipv4-address.h" | 27 #include "ns3/ipv4-address.h" |
27 #include "ns3/nstime.h" | 28 #include "ns3/nstime.h" |
28 #include "ns3/inet-socket-address.h" | 29 #include "ns3/inet-socket-address.h" |
29 #include "ns3/socket.h" | 30 #include "ns3/socket.h" |
30 #include "ns3/simulator.h" | 31 #include "ns3/simulator.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 .AddAttribute ("PoolMask", | 83 .AddAttribute ("PoolMask", |
83 "Mask of the pool of addresses.", | 84 "Mask of the pool of addresses.", |
84 Ipv4MaskValue (), | 85 Ipv4MaskValue (), |
85 MakeIpv4MaskAccessor (&DhcpServer::m_poolMask), | 86 MakeIpv4MaskAccessor (&DhcpServer::m_poolMask), |
86 MakeIpv4MaskChecker ()) | 87 MakeIpv4MaskChecker ()) |
87 .AddAttribute ("DHCPServer", | 88 .AddAttribute ("DHCPServer", |
88 "DHCP Server Address", | 89 "DHCP Server Address", |
89 Ipv4AddressValue (), | 90 Ipv4AddressValue (), |
90 MakeIpv4AddressAccessor (&DhcpServer::m_server), | 91 MakeIpv4AddressAccessor (&DhcpServer::m_server), |
91 MakeIpv4AddressChecker ()) | 92 MakeIpv4AddressChecker ()) |
| 93 .AddAttribute ("Gateway", |
| 94 "Address of default gateway", |
| 95 Ipv4AddressValue (), |
| 96 MakeIpv4AddressAccessor (&DhcpServer::m_gateway), |
| 97 MakeIpv4AddressChecker ()) |
92 ; | 98 ; |
93 return tid; | 99 return tid; |
94 } | 100 } |
95 | 101 |
96 DhcpServer::DhcpServer () | 102 DhcpServer::DhcpServer () |
97 { | 103 { |
98 NS_LOG_FUNCTION (this); | 104 NS_LOG_FUNCTION (this); |
99 m_nextAddressSeq = 1; | 105 m_nextAddressSeq = 1; |
100 } | 106 } |
101 | 107 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 new_header.SetType (DhcpHeader::DHCPOFFER); | 290 new_header.SetType (DhcpHeader::DHCPOFFER); |
285 new_header.SetChaddr (source); | 291 new_header.SetChaddr (source); |
286 new_header.SetYiaddr (address); | 292 new_header.SetYiaddr (address); |
287 new_header.SetDhcps (m_server); | 293 new_header.SetDhcps (m_server); |
288 new_header.SetMask (m_poolMask.Get ()); | 294 new_header.SetMask (m_poolMask.Get ()); |
289 new_header.SetTran (tran); | 295 new_header.SetTran (tran); |
290 new_header.SetLease (m_lease.GetSeconds ()); | 296 new_header.SetLease (m_lease.GetSeconds ()); |
291 new_header.SetRenew (m_renew.GetSeconds ()); | 297 new_header.SetRenew (m_renew.GetSeconds ()); |
292 new_header.SetRebind (m_rebind.GetSeconds ()); | 298 new_header.SetRebind (m_rebind.GetSeconds ()); |
293 new_header.SetTime (); | 299 new_header.SetTime (); |
| 300 if (m_gateway != Ipv4Address ()) |
| 301 { |
| 302 new_header.SetRouter (m_gateway); |
| 303 } |
294 packet->AddHeader (new_header); | 304 packet->AddHeader (new_header); |
295 | 305 |
296 if ((m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255
.255.255"), InetSocketAddress::ConvertFrom (from).GetPort ()))) >= 0) | 306 if ((m_socket->SendTo (packet, 0, InetSocketAddress (Ipv4Address ("255.255
.255.255"), InetSocketAddress::ConvertFrom (from).GetPort ()))) >= 0) |
297 { | 307 { |
298 NS_LOG_INFO ("[node " << GetNode ()->GetId () << "] " << "Trace TX: D
HCP OFFER"); | 308 NS_LOG_INFO ("[node " << GetNode ()->GetId () << "] " << "Trace TX: D
HCP OFFER" << " Offered Address: "<< address); |
299 } | 309 } |
300 else | 310 else |
301 { | 311 { |
302 NS_LOG_INFO ("[node " << GetNode ()->GetId () << "] " << "Error while
sending DHCP OFFER"); | 312 NS_LOG_INFO ("[node " << GetNode ()->GetId () << "] " << "Error while
sending DHCP OFFER"); |
303 } | 313 } |
304 } | 314 } |
305 } | 315 } |
306 | 316 |
307 void DhcpServer::SendAck (DhcpHeader header, Address from) | 317 void DhcpServer::SendAck (DhcpHeader header, Address from) |
308 { | 318 { |
309 DhcpHeader new_header; | 319 DhcpHeader new_header; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 372 } |
363 else | 373 else |
364 { | 374 { |
365 m_socket->SendTo (packet, 0, InetSocketAddress (m_peer, InetSocketAddr
ess::ConvertFrom (from).GetPort ())); | 375 m_socket->SendTo (packet, 0, InetSocketAddress (m_peer, InetSocketAddr
ess::ConvertFrom (from).GetPort ())); |
366 } | 376 } |
367 NS_LOG_INFO ("[node " << GetNode ()->GetId () << "] " << "This IP addr do
es not exists or released!"); | 377 NS_LOG_INFO ("[node " << GetNode ()->GetId () << "] " << "This IP addr do
es not exists or released!"); |
368 } | 378 } |
369 } | 379 } |
370 | 380 |
371 } // Namespace ns3 | 381 } // Namespace ns3 |
LEFT | RIGHT |