A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dhcp6-helper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 NITK Surathkal
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kavya Bhat <kavyabhat@gmail.com>
7 *
8 */
9
10#include "dhcp6-helper.h"
11
12#include "ns3/dhcp6-client.h"
13#include "ns3/dhcp6-server.h"
14#include "ns3/ipv6.h"
15#include "ns3/log.h"
16#include "ns3/loopback-net-device.h"
17#include "ns3/names.h"
18#include "ns3/uinteger.h"
19
20namespace ns3
21{
22
23NS_LOG_COMPONENT_DEFINE("Dhcp6Helper");
24
30
31void
32Dhcp6Helper::SetClientAttribute(std::string name, const AttributeValue& value)
33{
34 m_clientFactory.Set(name, value);
35}
36
37void
38Dhcp6Helper::SetServerAttribute(std::string name, const AttributeValue& value)
39{
40 m_serverFactory.Set(name, value);
41}
42
45{
46 ApplicationContainer installedApps;
47 for (auto iter = clientNodes.Begin(); iter != clientNodes.End(); iter++)
48 {
50 installedApps.Add(app);
51 }
52
53 return installedApps;
54}
55
58{
59 ApplicationContainer installedApps;
60 for (auto itr = netDevices.Begin(); itr != netDevices.End(); itr++)
61 {
62 Ptr<NetDevice> netDevice = *itr;
63 Ptr<Node> node = netDevice->GetNode();
64 NS_ASSERT_MSG(node, "Dhcp6Helper: NetDevice is not associated with any node -> fail");
65
66 Ptr<Ipv6> ipv6 = node->GetObject<Ipv6>();
67 NS_ASSERT_MSG(ipv6,
68 "Dhcp6Helper: NetDevice is associated"
69 " with a node without IPv6 stack installed -> fail "
70 "(maybe need to use InternetStackHelper?)");
71
72 uint32_t nApplications = node->GetNApplications();
73
74 for (uint32_t i = 0; i < nApplications; i++)
75 {
76 Ptr<Dhcp6Server> server = DynamicCast<Dhcp6Server>(node->GetApplication(i));
77 if (!server)
78 {
80 node->AddApplication(app);
81 app->SetDhcp6ServerNetDevice(netDevices);
82 installedApps.Add(app);
83 }
84 }
85
86 if (nApplications == 0)
87 {
89 node->AddApplication(app);
90 app->SetDhcp6ServerNetDevice(netDevices);
91 installedApps.Add(app);
92 }
93 }
94
95 return installedApps;
96}
97
100{
102 for (uint32_t index = 0; index < clientNode->GetNApplications(); index++)
103 {
104 app = clientNode->GetApplication(index);
105 if (app->GetInstanceTypeId() == Dhcp6Client::GetTypeId())
106 {
107 return app;
108 }
109 }
110
112 clientNode->AddApplication(app);
113
114 return app;
115}
116
117} // namespace ns3
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.
Definition attribute.h:59
Implements the DHCPv6 client.
static TypeId GetTypeId()
Get the type ID.
void SetServerAttribute(std::string name, const AttributeValue &value)
Set DHCPv6 server attributes.
ObjectFactory m_serverFactory
DHCPv6 server factory.
Ptr< Application > InstallDhcp6ClientInternal(Ptr< Node > clientNode) const
Helper method that iterates through the installed applications on a node to look for a Dhcp6Client ap...
void SetClientAttribute(std::string name, const AttributeValue &value)
Set DHCPv6 client attributes.
ObjectFactory m_clientFactory
DHCPv6 client factory.
Dhcp6Helper()
Default constructor.
ApplicationContainer InstallDhcp6Client(NodeContainer clientNodes) const
Install DHCPv6 client on a set of nodes.
ApplicationContainer InstallDhcp6Server(NetDeviceContainer netDevices)
Install DHCPv6 server on a node / NetDevice.
Implements the DHCPv6 server.
static TypeId GetTypeId()
Get the type ID.
Access to the IPv6 forwarding table, interfaces, and configuration.
Definition ipv6.h:71
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.
keep track of a set of node pointers.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
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.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580