diff --git a/src/internet-apps/helper/ping-helper.cc b/src/internet-apps/helper/ping-helper.cc index 7807831b5..c76c84021 100644 --- a/src/internet-apps/helper/ping-helper.cc +++ b/src/internet-apps/helper/ping-helper.cc @@ -24,62 +24,19 @@ #include "ping-helper.h" -#include "ns3/names.h" -#include "ns3/ping.h" - namespace ns3 { PingHelper::PingHelper() + : ApplicationHelper("ns3::Ping") { - m_factory.SetTypeId("ns3::Ping"); } -PingHelper::PingHelper(Address remote, Address local) +PingHelper::PingHelper(const Address& remote, const Address& local) + : ApplicationHelper("ns3::Ping") { - m_factory.SetTypeId("ns3::Ping"); m_factory.Set("Destination", AddressValue(remote)); m_factory.Set("InterfaceAddress", AddressValue(local)); } -void -PingHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -PingHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -PingHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -PingHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -PingHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - } // namespace ns3 diff --git a/src/internet-apps/helper/ping-helper.h b/src/internet-apps/helper/ping-helper.h index c2cf4287e..29604969c 100644 --- a/src/internet-apps/helper/ping-helper.h +++ b/src/internet-apps/helper/ping-helper.h @@ -25,14 +25,8 @@ #ifndef PING_HELPER_H #define PING_HELPER_H -#include "ns3/application-container.h" -#include "ns3/ipv4-address.h" -#include "ns3/ipv6-address.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" #include "ns3/ping.h" - -#include +#include namespace ns3 { @@ -44,7 +38,7 @@ namespace ns3 * This class creates one or multiple instances of ns3::Ping and associates * it/them to one/multiple node(s). */ -class PingHelper +class PingHelper : public ApplicationHelper { public: /** @@ -60,55 +54,7 @@ class PingHelper * \param remote The address which should be pinged * \param local The source address */ - PingHelper(Address remote, Address local = Address()); - - /** - * Install a Ping application on each Node in the provided NodeContainer. - * - * \param nodes The NodeContainer containing all of the nodes to get a Ping - * application. - * - * \returns A list of Ping applications, one for each input node - */ - ApplicationContainer Install(NodeContainer nodes) const; - - /** - * Install a Ping application on the provided Node. The Node is specified - * directly by a Ptr - * - * \param node The node to install the Ping application on. - * - * \returns An ApplicationContainer holding the Ping application created. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install a Ping application on the provided Node. The Node is specified - * by a string that must have previously been associated with a Node using the - * Object Name Service. - * - * \param nodeName The node to install the Ping application on. - * - * \returns An ApplicationContainer holding the Ping application created. - */ - ApplicationContainer Install(std::string nodeName) const; - - /** - * \brief Configure ping applications attribute - * \param name attribute's name - * \param value attribute's value - */ - void SetAttribute(std::string name, const AttributeValue& value); - - private: - /** - * \brief Do the actual application installation in the node - * \param node the node - * \returns a Smart pointer to the installed application - */ - Ptr InstallPriv(Ptr node) const; - /// Object factory - ObjectFactory m_factory; + PingHelper(const Address& remote, const Address& local = Address()); }; } // namespace ns3 diff --git a/src/internet-apps/helper/radvd-helper.cc b/src/internet-apps/helper/radvd-helper.cc index 0891d51af..389594bd2 100644 --- a/src/internet-apps/helper/radvd-helper.cc +++ b/src/internet-apps/helper/radvd-helper.cc @@ -31,12 +31,14 @@ namespace ns3 NS_LOG_COMPONENT_DEFINE("RadvdHelper"); RadvdHelper::RadvdHelper() + : ApplicationHelper(Radvd::GetTypeId()) { - m_factory.SetTypeId(Radvd::GetTypeId()); } void -RadvdHelper::AddAnnouncedPrefix(uint32_t interface, Ipv6Address prefix, uint32_t prefixLength) +RadvdHelper::AddAnnouncedPrefix(uint32_t interface, + const Ipv6Address& prefix, + uint32_t prefixLength) { NS_LOG_FUNCTION(this << int(interface) << prefix << int(prefixLength)); if (prefixLength != 64) @@ -109,27 +111,19 @@ RadvdHelper::ClearPrefixes() m_radvdInterfaces.clear(); } -void -RadvdHelper::SetAttribute(std::string name, const AttributeValue& value) +Ptr +RadvdHelper::DoInstall(Ptr node) { - m_factory.Set(name, value); -} - -ApplicationContainer -RadvdHelper::Install(Ptr node) -{ - ApplicationContainer apps; - Ptr radvd = m_factory.Create(); - for (auto iter = m_radvdInterfaces.begin(); iter != m_radvdInterfaces.end(); iter++) + auto radvd = m_factory.Create(); + for (auto [index, interface] : m_radvdInterfaces) { - if (!iter->second->GetPrefixes().empty()) + if (!interface->GetPrefixes().empty()) { - radvd->AddConfiguration(iter->second); + radvd->AddConfiguration(interface); } } node->AddApplication(radvd); - apps.Add(radvd); - return apps; + return radvd; } } /* namespace ns3 */ diff --git a/src/internet-apps/helper/radvd-helper.h b/src/internet-apps/helper/radvd-helper.h index 5ba2ab745..dab52efed 100644 --- a/src/internet-apps/helper/radvd-helper.h +++ b/src/internet-apps/helper/radvd-helper.h @@ -20,13 +20,9 @@ #ifndef RADVD_HELPER_H #define RADVD_HELPER_H -#include "ns3/application-container.h" -#include "ns3/ipv6-address.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" #include "ns3/radvd-interface.h" +#include -#include #include #include @@ -37,7 +33,7 @@ namespace ns3 * \ingroup radvd * \brief Radvd application helper. */ -class RadvdHelper +class RadvdHelper : public ApplicationHelper { public: /** @@ -51,7 +47,7 @@ class RadvdHelper * \param prefix announced IPv6 prefix * \param prefixLength announced IPv6 prefix length */ - void AddAnnouncedPrefix(uint32_t interface, Ipv6Address prefix, uint32_t prefixLength); + void AddAnnouncedPrefix(uint32_t interface, const Ipv6Address& prefix, uint32_t prefixLength); /** * \brief Enable the router as default router for the interface. @@ -80,25 +76,8 @@ class RadvdHelper */ void ClearPrefixes(); - /** - * \brief Set some attributes. - * \param name attribute name - * \param value attribute value - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * \brief Install the application in a Node. - * \param node the Node - * \return application container - */ - ApplicationContainer Install(Ptr node); - private: - /** - * \brief An object factory. - */ - ObjectFactory m_factory; + Ptr DoInstall(Ptr node) override; /// Container: interface index, RadvdInterface typedef std::map> RadvdInterfaceMap; diff --git a/src/internet-apps/helper/v4traceroute-helper.cc b/src/internet-apps/helper/v4traceroute-helper.cc index 99f249fc3..5525bf95a 100644 --- a/src/internet-apps/helper/v4traceroute-helper.cc +++ b/src/internet-apps/helper/v4traceroute-helper.cc @@ -21,67 +21,24 @@ #include "v4traceroute-helper.h" -#include "ns3/names.h" +#include "ns3/output-stream-wrapper.h" #include "ns3/v4traceroute.h" namespace ns3 { -V4TraceRouteHelper::V4TraceRouteHelper(Ipv4Address remote) +V4TraceRouteHelper::V4TraceRouteHelper(const Ipv4Address& remote) + : ApplicationHelper("ns3::V4TraceRoute") { - m_factory.SetTypeId("ns3::V4TraceRoute"); m_factory.Set("Remote", Ipv4AddressValue(remote)); } -void -V4TraceRouteHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -V4TraceRouteHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -V4TraceRouteHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -V4TraceRouteHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -V4TraceRouteHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - void V4TraceRouteHelper::PrintTraceRouteAt(Ptr node, Ptr stream) { - Ptr trace; - for (uint32_t i = 0; i < node->GetNApplications(); ++i) { - trace = node->GetApplication(i)->GetObject(); - if (trace) + if (auto trace = node->GetApplication(i)->GetObject()) { *stream->GetStream() << "Tracing Route from Node " << node->GetId() << "\n"; trace->Print(stream); diff --git a/src/internet-apps/helper/v4traceroute-helper.h b/src/internet-apps/helper/v4traceroute-helper.h index 344683490..16a7b4937 100644 --- a/src/internet-apps/helper/v4traceroute-helper.h +++ b/src/internet-apps/helper/v4traceroute-helper.h @@ -22,14 +22,13 @@ #ifndef V4TRACEROUTE_HELPER_H #define V4TRACEROUTE_HELPER_H -#include "ns3/application-container.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" -#include "ns3/output-stream-wrapper.h" +#include namespace ns3 { +class OutputStreamWrapper; + /** * \ingroup v4traceroute * \brief Create a IPv4 traceroute application and associate it to a node @@ -37,7 +36,7 @@ namespace ns3 * This class creates one or multiple instances of ns3::V4TraceRoute and associates * it/them to one/multiple node(s). */ -class V4TraceRouteHelper +class V4TraceRouteHelper : public ApplicationHelper { public: /** @@ -46,61 +45,14 @@ class V4TraceRouteHelper * * \param remote The address which should be traced */ - V4TraceRouteHelper(Ipv4Address remote); + V4TraceRouteHelper(const Ipv4Address& remote); - /** - * Install a TraceRoute application on each Node in the provided NodeContainer. - * - * \param nodes The NodeContainer containing all of the nodes to get a V4TraceRoute - * application. - * - * \returns A list of TraceRoute applications, one for each input node - */ - ApplicationContainer Install(NodeContainer nodes) const; - - /** - * Install a TraceRoute application on the provided Node. The Node is specified - * directly by a Ptr - * - * \param node The node to install the V4TraceRouteApplication on. - * - * \returns An ApplicationContainer holding the TraceRoute application created. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install a TraceRoute application on the provided Node. The Node is specified - * by a string that must have previously been associated with a Node using the - * Object Name Service. - * - * \param nodeName The node to install the V4TraceRouteApplication on. - * - * \returns An ApplicationContainer holding the TraceRoute application created. - */ - ApplicationContainer Install(std::string nodeName) const; - - /** - * \brief Configure traceRoute applications attribute - * \param name attribute's name - * \param value attribute's value - */ - void SetAttribute(std::string name, const AttributeValue& value); /** * \brief Print the resulting trace routes from given node. * \param node The origin node where the traceroute is initiated. * \param stream The outputstream used to print the resulting traced routes. */ static void PrintTraceRouteAt(Ptr node, Ptr stream); - - private: - /** - * \brief Do the actual application installation in the node - * \param node the node - * \returns a Smart pointer to the installed application - */ - Ptr InstallPriv(Ptr node) const; - /// Object factory - ObjectFactory m_factory; }; } // namespace ns3