26 #include "ns3/dhcp-client.h"
27 #include "ns3/dhcp-server.h"
30 #include "ns3/loopback-net-device.h"
31 #include "ns3/names.h"
32 #include "ns3/net-device-queue-interface.h"
33 #include "ns3/traffic-control-helper.h"
34 #include "ns3/traffic-control-layer.h"
35 #include "ns3/uinteger.h"
70 for (
auto i = netDevices.
Begin(); i != netDevices.
End(); ++i)
81 NS_ASSERT_MSG(node,
"DhcpClientHelper: NetDevice is not not associated with any node -> fail");
85 "DhcpHelper: NetDevice is associated"
86 " with a node without IPv4 stack installed -> fail "
87 "(maybe need to use InternetStackHelper?)");
89 int32_t
interface =
ipv4->GetInterfaceForDevice(netDevice);
92 interface =
ipv4->AddInterface(netDevice);
94 NS_ASSERT_MSG(interface >= 0,
"DhcpHelper: Interface index not found");
96 ipv4->SetMetric(interface, 1);
97 ipv4->SetUp(interface);
103 if (tc && !DynamicCast<LoopbackNetDevice>(netDevice) &&
104 !tc->GetRootQueueDiscOnDevice(netDevice))
113 std::size_t nTxQueues = ndqi->GetNTxQueues();
114 NS_LOG_LOGIC(
"DhcpHelper - Installing default traffic control configuration ("
115 << nTxQueues <<
" device queue(s))");
122 app->SetDhcpClientNetDevice(netDevice);
144 NS_ASSERT_MSG(node,
"DhcpHelper: NetDevice is not not associated with any node -> fail");
148 "DhcpHelper: NetDevice is associated"
149 " with a node without IPv4 stack installed -> fail "
150 "(maybe need to use InternetStackHelper?)");
152 int32_t
interface =
ipv4->GetInterfaceForDevice(netDevice);
155 interface =
ipv4->AddInterface(netDevice);
157 NS_ASSERT_MSG(interface >= 0,
"DhcpHelper: Interface index not found");
160 ipv4->AddAddress(interface, ipv4Addr);
161 ipv4->SetMetric(interface, 1);
162 ipv4->SetUp(interface);
168 if (tc && !DynamicCast<LoopbackNetDevice>(netDevice) &&
169 !tc->GetRootQueueDiscOnDevice(netDevice))
178 std::size_t nTxQueues = ndqi->GetNTxQueues();
179 NS_LOG_LOGIC(
"DhcpHelper - Installing default traffic control configuration ("
180 << nTxQueues <<
" device queue(s))");
189 if (iter->Get() >= minAddr.
Get() && iter->Get() <= maxAddr.
Get())
191 NS_ABORT_MSG(
"DhcpHelper: Fixed address can not conflict with a pool: "
192 << *iter <<
" is in [" << minAddr <<
", " << maxAddr <<
"]");
208 NS_ASSERT_MSG(node,
"DhcpHelper: NetDevice is not not associated with any node -> fail");
212 "DhcpHelper: NetDevice is associated"
213 " with a node without IPv4 stack installed -> fail "
214 "(maybe need to use InternetStackHelper?)");
216 int32_t
interface =
ipv4->GetInterfaceForDevice(netDevice);
219 interface =
ipv4->AddInterface(netDevice);
221 NS_ASSERT_MSG(interface >= 0,
"DhcpHelper: Interface index not found");
224 ipv4->AddAddress(interface, ipv4Addr);
225 ipv4->SetMetric(interface, 1);
226 ipv4->SetUp(interface);
233 if (tc && !DynamicCast<LoopbackNetDevice>(netDevice) &&
234 !tc->GetRootQueueDiscOnDevice(netDevice))
243 std::size_t nTxQueues = ndqi->GetNTxQueues();
244 NS_LOG_LOGIC(
"DhcpHelper - Installing default traffic control configuration ("
245 << nTxQueues <<
" device queue(s))");
254 if (addr.
Get() >= iter->first.Get() && addr.
Get() <= iter->second.Get())
256 NS_ABORT_MSG(
"DhcpHelper: Fixed address can not conflict with a pool: "
257 << addr <<
" is in [" << iter->first <<
", " << iter->second <<
"]");
holds a vector of ns3::Application pointers.
void Add(ApplicationContainer other)
Append the contents of another ApplicationContainer to the end of this container.
Hold a value for an Attribute.
Implements the functionality of a DHCP client.
static TypeId GetTypeId()
Get the type ID.
ObjectFactory m_serverFactory
DHCP server factory.
std::list< std::pair< Ipv4Address, Ipv4Address > > m_addressPools
list of address pools.
std::list< Ipv4Address > m_fixedAddresses
list of fixed addresses already allocated.
Ipv4InterfaceContainer InstallFixedAddress(Ptr< NetDevice > netDevice, Ipv4Address addr, Ipv4Mask mask)
Assign a fixed IP addresses to a net device.
ApplicationContainer InstallDhcpServer(Ptr< NetDevice > netDevice, Ipv4Address serverAddr, Ipv4Address poolAddr, Ipv4Mask poolMask, Ipv4Address minAddr, Ipv4Address maxAddr, Ipv4Address gateway=Ipv4Address())
Install DHCP server of a node / NetDevice.
ApplicationContainer InstallDhcpClient(Ptr< NetDevice > netDevice) const
Install DHCP client of a nodes / NetDevice.
void SetClientAttribute(std::string name, const AttributeValue &value)
Set DHCP client attributes.
void SetServerAttribute(std::string name, const AttributeValue &value)
Set DHCP server attributes.
Ptr< Application > InstallDhcpClientPriv(Ptr< NetDevice > netDevice) const
Function to install DHCP client on a node.
ObjectFactory m_clientFactory
DHCP client factory.
Implements the functionality of a DHCP server.
static TypeId GetTypeId()
Get the type ID.
Ipv4 addresses are stored in host order in this class.
uint32_t Get() const
Get the host-order 32-bit IP address.
Access to the IPv4 forwarding table, interfaces, and configuration.
a class to store IPv4 address information on an interface
holds a vector of std::pair of Ptr<Ipv4> and interface index.
void Add(const Ipv4InterfaceContainer &other)
Concatenate the entries in the other container with ours.
a class to represent an Ipv4 address mask
holds a vector of ns3::NetDevice pointers
Iterator Begin() const
Get an iterator which refers to the first NetDevice in the container.
Iterator End() const
Get an iterator which indicates past-the-last NetDevice in the container.
Network device transmission queue interface.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
Build a set of QueueDisc objects.
QueueDiscContainer Install(NetDeviceContainer c)
static TrafficControlHelper Default(std::size_t nTxQueues=1)
The Traffic Control layer aims at introducing an equivalent of the Linux Traffic Control infrastructu...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Every class exported by the ns3 library is enclosed in the ns3 namespace.