diff --git a/src/applications/helper/bulk-send-helper.cc b/src/applications/helper/bulk-send-helper.cc index 6e53e06d4..594ba90ef 100644 --- a/src/applications/helper/bulk-send-helper.cc +++ b/src/applications/helper/bulk-send-helper.cc @@ -21,59 +21,16 @@ #include "bulk-send-helper.h" -#include "ns3/inet-socket-address.h" -#include "ns3/names.h" -#include "ns3/packet-socket-address.h" -#include "ns3/string.h" +#include namespace ns3 { -BulkSendHelper::BulkSendHelper(std::string protocol, Address address) +BulkSendHelper::BulkSendHelper(const std::string& protocol, const Address& address) + : ApplicationHelper("ns3::BulkSendApplication") { - m_factory.SetTypeId("ns3::BulkSendApplication"); m_factory.Set("Protocol", StringValue(protocol)); m_factory.Set("Remote", AddressValue(address)); } -void -BulkSendHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -BulkSendHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -BulkSendHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -BulkSendHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -BulkSendHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - } // namespace ns3 diff --git a/src/applications/helper/bulk-send-helper.h b/src/applications/helper/bulk-send-helper.h index 803b11d91..5cb6a7137 100644 --- a/src/applications/helper/bulk-send-helper.h +++ b/src/applications/helper/bulk-send-helper.h @@ -22,15 +22,7 @@ #ifndef BULK_SEND_HELPER_H #define BULK_SEND_HELPER_H -#include "ns3/address.h" -#include "ns3/application-container.h" -#include "ns3/attribute.h" -#include "ns3/net-device.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" - -#include -#include +#include namespace ns3 { @@ -40,7 +32,7 @@ namespace ns3 * \brief A helper to make it easier to instantiate an ns3::BulkSendApplication * on a set of nodes. */ -class BulkSendHelper +class BulkSendHelper : public ApplicationHelper { public: /** @@ -53,58 +45,9 @@ class BulkSendHelper * \param address the address of the remote node to send traffic * to. */ - BulkSendHelper(std::string protocol, Address address); - - /** - * Helper function used to set the underlying application attributes, - * _not_ the socket attributes. - * - * \param name the name of the application attribute to set - * \param value the value of the application attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * Install an ns3::BulkSendApplication on each node of the input container - * configured with all the attributes set with SetAttribute. - * - * \param c NodeContainer of the set of nodes on which an BulkSendApplication - * will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(NodeContainer c) const; - - /** - * Install an ns3::BulkSendApplication on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an BulkSendApplication will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install an ns3::BulkSendApplication on the node configured with all the - * attributes set with SetAttribute. - * - * \param nodeName The node on which an BulkSendApplication will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(std::string nodeName) const; - - private: - /** - * Install an ns3::BulkSendApplication on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an BulkSendApplication will be installed. - * \returns Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - - ObjectFactory m_factory; //!< Object factory. + BulkSendHelper(const std::string& protocol, const Address& address); }; } // namespace ns3 -#endif /* ON_OFF_HELPER_H */ +#endif /* BULK_SEND_HELPER_H */ diff --git a/src/applications/helper/on-off-helper.cc b/src/applications/helper/on-off-helper.cc index 12a03300c..31b327267 100644 --- a/src/applications/helper/on-off-helper.cc +++ b/src/applications/helper/on-off-helper.cc @@ -16,83 +16,23 @@ * * Author: Mathieu Lacage */ + #include "on-off-helper.h" -#include "ns3/data-rate.h" -#include "ns3/inet-socket-address.h" -#include "ns3/names.h" -#include "ns3/onoff-application.h" -#include "ns3/packet-socket-address.h" -#include "ns3/random-variable-stream.h" -#include "ns3/string.h" -#include "ns3/uinteger.h" +#include +#include +#include namespace ns3 { -OnOffHelper::OnOffHelper(std::string protocol, Address address) +OnOffHelper::OnOffHelper(const std::string& protocol, const Address& address) + : ApplicationHelper("ns3::OnOffApplication") { - m_factory.SetTypeId("ns3::OnOffApplication"); m_factory.Set("Protocol", StringValue(protocol)); m_factory.Set("Remote", AddressValue(address)); } -void -OnOffHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -OnOffHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -OnOffHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -OnOffHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -OnOffHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - -int64_t -OnOffHelper::AssignStreams(NodeContainer c, int64_t stream) -{ - int64_t currentStream = stream; - Ptr node; - for (auto i = c.Begin(); i != c.End(); ++i) - { - node = (*i); - for (uint32_t j = 0; j < node->GetNApplications(); j++) - { - currentStream += node->GetApplication(j)->AssignStreams(currentStream); - } - } - return (currentStream - stream); -} - void OnOffHelper::SetConstantRate(DataRate dataRate, uint32_t packetSize) { diff --git a/src/applications/helper/on-off-helper.h b/src/applications/helper/on-off-helper.h index d0bf8e77f..b0f1ebb79 100644 --- a/src/applications/helper/on-off-helper.h +++ b/src/applications/helper/on-off-helper.h @@ -16,31 +16,24 @@ * * Author: Mathieu Lacage */ + #ifndef ON_OFF_HELPER_H #define ON_OFF_HELPER_H -#include "ns3/address.h" -#include "ns3/application-container.h" -#include "ns3/attribute.h" -#include "ns3/net-device.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" -#include "ns3/onoff-application.h" +#include +#include #include -#include namespace ns3 { -class DataRate; - /** * \ingroup onoff * \brief A helper to make it easier to instantiate an ns3::OnOffApplication * on a set of nodes. */ -class OnOffHelper +class OnOffHelper : public ApplicationHelper { public: /** @@ -53,15 +46,7 @@ class OnOffHelper * \param address the address of the remote node to send traffic * to. */ - OnOffHelper(std::string protocol, Address address); - - /** - * Helper function used to set the underlying application attributes. - * - * \param name the name of the application attribute to set - * \param value the value of the application attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); + OnOffHelper(const std::string& protocol, const Address& address); /** * Helper function to set a constant rate source. Equivalent to @@ -72,59 +57,6 @@ class OnOffHelper * \param packetSize size in bytes of the packet payloads generated */ void SetConstantRate(DataRate dataRate, uint32_t packetSize = 512); - - /** - * Install an ns3::OnOffApplication on each node of the input container - * configured with all the attributes set with SetAttribute. - * - * \param c NodeContainer of the set of nodes on which an OnOffApplication - * will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(NodeContainer c) const; - - /** - * Install an ns3::OnOffApplication on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an OnOffApplication will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install an ns3::OnOffApplication on the node configured with all the - * attributes set with SetAttribute. - * - * \param nodeName The node on which an OnOffApplication will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(std::string nodeName) const; - - /** - * Assign a fixed random variable stream number to the random variables - * used by this model. Return the number of streams (possibly zero) that - * have been assigned. The Install() method should have previously been - * called by the user. - * - * \param stream first stream index to use - * \param c NodeContainer of the set of nodes for which the OnOffApplication - * should be modified to use a fixed stream - * \return the number of stream indices assigned by this helper - */ - int64_t AssignStreams(NodeContainer c, int64_t stream); - - private: - /** - * Install an ns3::OnOffApplication on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an OnOffApplication will be installed. - * \returns Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - - ObjectFactory m_factory; //!< Object factory. }; } // namespace ns3 diff --git a/src/applications/helper/packet-sink-helper.cc b/src/applications/helper/packet-sink-helper.cc index 72f8af81a..3c61cfb37 100644 --- a/src/applications/helper/packet-sink-helper.cc +++ b/src/applications/helper/packet-sink-helper.cc @@ -19,58 +19,16 @@ #include "packet-sink-helper.h" -#include "ns3/inet-socket-address.h" -#include "ns3/names.h" -#include "ns3/string.h" +#include namespace ns3 { -PacketSinkHelper::PacketSinkHelper(std::string protocol, Address address) +PacketSinkHelper::PacketSinkHelper(const std::string& protocol, const Address& address) + : ApplicationHelper("ns3::PacketSink") { - m_factory.SetTypeId("ns3::PacketSink"); m_factory.Set("Protocol", StringValue(protocol)); m_factory.Set("Local", AddressValue(address)); } -void -PacketSinkHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -PacketSinkHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -PacketSinkHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -PacketSinkHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -PacketSinkHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - } // namespace ns3 diff --git a/src/applications/helper/packet-sink-helper.h b/src/applications/helper/packet-sink-helper.h index c1c17225c..b1d43e8d9 100644 --- a/src/applications/helper/packet-sink-helper.h +++ b/src/applications/helper/packet-sink-helper.h @@ -16,13 +16,11 @@ * * Author: Mathieu Lacage */ + #ifndef PACKET_SINK_HELPER_H #define PACKET_SINK_HELPER_H -#include "ns3/application-container.h" -#include "ns3/ipv4-address.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" +#include namespace ns3 { @@ -32,7 +30,7 @@ namespace ns3 * \brief A helper to make it easier to instantiate an ns3::PacketSinkApplication * on a set of nodes. */ -class PacketSinkHelper +class PacketSinkHelper : public ApplicationHelper { public: /** @@ -45,54 +43,7 @@ class PacketSinkHelper * \param address the address of the sink, * */ - PacketSinkHelper(std::string protocol, Address address); - - /** - * Helper function used to set the underlying application attributes. - * - * \param name the name of the application attribute to set - * \param value the value of the application attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * Install an ns3::PacketSinkApplication on each node of the input container - * configured with all the attributes set with SetAttribute. - * - * \param c NodeContainer of the set of nodes on which a PacketSinkApplication - * will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(NodeContainer c) const; - - /** - * Install an ns3::PacketSinkApplication on each node of the input container - * configured with all the attributes set with SetAttribute. - * - * \param node The node on which a PacketSinkApplication will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install an ns3::PacketSinkApplication on each node of the input container - * configured with all the attributes set with SetAttribute. - * - * \param nodeName The name of the node on which a PacketSinkApplication will be installed. - * \returns Container of Ptr to the applications installed. - */ - ApplicationContainer Install(std::string nodeName) const; - - private: - /** - * Install an ns3::PacketSink on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an PacketSink will be installed. - * \returns Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - ObjectFactory m_factory; //!< Object factory. + PacketSinkHelper(const std::string& protocol, const Address& address); }; } // namespace ns3 diff --git a/src/applications/helper/three-gpp-http-helper.cc b/src/applications/helper/three-gpp-http-helper.cc index 4cc25643a..c00c19702 100644 --- a/src/applications/helper/three-gpp-http-helper.cc +++ b/src/applications/helper/three-gpp-http-helper.cc @@ -25,105 +25,23 @@ #include "three-gpp-http-helper.h" -#include - namespace ns3 { // 3GPP HTTP CLIENT HELPER ///////////////////////////////////////////////////////// ThreeGppHttpClientHelper::ThreeGppHttpClientHelper(const Address& address) + : ApplicationHelper("ns3::ThreeGppHttpClient") { - m_factory.SetTypeId("ns3::ThreeGppHttpClient"); m_factory.Set("RemoteServerAddress", AddressValue(address)); } -void -ThreeGppHttpClientHelper::SetAttribute(const std::string& name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -ThreeGppHttpClientHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -ThreeGppHttpClientHelper::Install(const std::string& nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -ThreeGppHttpClientHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -ThreeGppHttpClientHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - // HTTP SERVER HELPER ///////////////////////////////////////////////////////// ThreeGppHttpServerHelper::ThreeGppHttpServerHelper(const Address& address) + : ApplicationHelper("ns3::ThreeGppHttpServer") { - m_factory.SetTypeId("ns3::ThreeGppHttpServer"); m_factory.Set("LocalAddress", AddressValue(address)); } -void -ThreeGppHttpServerHelper::SetAttribute(const std::string& name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -ThreeGppHttpServerHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -ThreeGppHttpServerHelper::Install(const std::string& nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -ThreeGppHttpServerHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -ThreeGppHttpServerHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - } // namespace ns3 diff --git a/src/applications/helper/three-gpp-http-helper.h b/src/applications/helper/three-gpp-http-helper.h index f4f131812..5d2363a17 100644 --- a/src/applications/helper/three-gpp-http-helper.h +++ b/src/applications/helper/three-gpp-http-helper.h @@ -26,9 +26,7 @@ #ifndef THREE_GPP_HTTP_HELPER_H #define THREE_GPP_HTTP_HELPER_H -#include -#include -#include +#include namespace ns3 { @@ -37,7 +35,7 @@ namespace ns3 * \ingroup applications * Helper to make it easier to instantiate an ThreeGppHttpClient on a set of nodes. */ -class ThreeGppHttpClientHelper +class ThreeGppHttpClientHelper : public ApplicationHelper { public: /** @@ -46,61 +44,13 @@ class ThreeGppHttpClientHelper * \param address The address of the remote server node to send traffic to. */ ThreeGppHttpClientHelper(const Address& address); - - /** - * Helper function used to set the underlying application attributes, but - * *not* the socket attributes. - * \param name The name of the application attribute to set. - * \param value The value of the application attribute to set. - */ - void SetAttribute(const std::string& name, const AttributeValue& value); - - /** - * Install a ThreeGppHttpClient on each node of the input container configured with - * all the attributes set with SetAttribute(). - * \param c NodeContainer of the set of nodes on which an ThreeGppHttpClient - * will be installed. - * \return Container of Ptr to the applications installed. - */ - ApplicationContainer Install(NodeContainer c) const; - - /** - * Install a ThreeGppHttpClient on each node of the input container - * configured with all the attributes set with SetAttribute(). - * \param node The node on which an ThreeGppHttpClient will be installed. - * \return Container of Ptr to the applications installed. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install a ThreeGppHttpClient on each node of the input container - * configured with all the attributes set with SetAttribute(). - * \param nodeName The name of the node on which an ThreeGppHttpClient - * will be installed. - * \return Container of Ptr to the applications installed. - */ - ApplicationContainer Install(const std::string& nodeName) const; - - private: - /** - * \internal - * Install a ThreeGppHttpClient on the node configured with all the - * attributes set with SetAttribute(). - * \param node The node on which an ThreeGppHttpClient will be installed. - * \return Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - - /// Used to instantiate an ThreeGppHttpClient instance. - ObjectFactory m_factory; - }; // end of `class ThreeGppHttpClientHelper` /** * \ingroup http * Helper to make it easier to instantiate an ThreeGppHttpServer on a set of nodes. */ -class ThreeGppHttpServerHelper +class ThreeGppHttpServerHelper : public ApplicationHelper { public: /** @@ -109,54 +59,6 @@ class ThreeGppHttpServerHelper * \param address The address of the server. */ ThreeGppHttpServerHelper(const Address& address); - - /** - * Helper function used to set the underlying application attributes, but - * *not* the socket attributes. - * \param name The name of the application attribute to set. - * \param value The value of the application attribute to set. - */ - void SetAttribute(const std::string& name, const AttributeValue& value); - - /** - * Install an ThreeGppHttpServer on each node of the input container - * configured with all the attributes set with SetAttribute(). - * \param c NodeContainer of the set of nodes on which an ThreeGppHttpServer - * will be installed. - * \return Container of Ptr to the applications installed. - */ - ApplicationContainer Install(NodeContainer c) const; - - /** - * Install an ThreeGppHttpServer on each node of the input container - * configured with all the attributes set with SetAttribute(). - * \param node The node on which an ThreeGppHttpServer will be installed. - * \return Container of Ptr to the applications installed. - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Install an ThreeGppHttpServer on each node of the input container - * configured with all the attributes set with SetAttribute(). - * \param nodeName The name of the node on which an ThreeGppHttpServer - * will be installed. - * \return Container of Ptr to the applications installed. - */ - ApplicationContainer Install(const std::string& nodeName) const; - - private: - /** - * \internal - * Install an ThreeGppHttpServer on the node configured with all the - * attributes set with SetAttribute(). - * \param node The node on which an ThreeGppHttpServer will be installed. - * \return Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - - /// Used to instantiate a ThreeGppHttpServer instance. - ObjectFactory m_factory; - }; // end of `class ThreeGppHttpServerHelper` } // namespace ns3 diff --git a/src/applications/helper/udp-client-server-helper.cc b/src/applications/helper/udp-client-server-helper.cc index 99fd4b710..0ca97f60f 100644 --- a/src/applications/helper/udp-client-server-helper.cc +++ b/src/applications/helper/udp-client-server-helper.cc @@ -16,47 +16,32 @@ * * Author: Mohamed Amine Ismail */ + #include "udp-client-server-helper.h" -#include "ns3/string.h" -#include "ns3/udp-client.h" -#include "ns3/udp-server.h" -#include "ns3/udp-trace-client.h" -#include "ns3/uinteger.h" +#include +#include namespace ns3 { UdpServerHelper::UdpServerHelper() + : ApplicationHelper(UdpServer::GetTypeId()) { - m_factory.SetTypeId(UdpServer::GetTypeId()); } UdpServerHelper::UdpServerHelper(uint16_t port) + : UdpServerHelper() { - m_factory.SetTypeId(UdpServer::GetTypeId()); SetAttribute("Port", UintegerValue(port)); } -void -UdpServerHelper::SetAttribute(std::string name, const AttributeValue& value) +Ptr +UdpServerHelper::DoInstall(Ptr node) { - m_factory.Set(name, value); -} - -ApplicationContainer -UdpServerHelper::Install(NodeContainer c) -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - Ptr node = *i; - - m_server = m_factory.Create(); - node->AddApplication(m_server); - apps.Add(m_server); - } - return apps; + m_server = m_factory.Create(); + node->AddApplication(m_server); + return m_server; } Ptr @@ -66,81 +51,40 @@ UdpServerHelper::GetServer() } UdpClientHelper::UdpClientHelper() + : ApplicationHelper(UdpClient::GetTypeId()) { - m_factory.SetTypeId(UdpClient::GetTypeId()); } -UdpClientHelper::UdpClientHelper(Address address, uint16_t port) +UdpClientHelper::UdpClientHelper(const Address& address) + : UdpClientHelper() { - m_factory.SetTypeId(UdpClient::GetTypeId()); SetAttribute("RemoteAddress", AddressValue(address)); +} + +UdpClientHelper::UdpClientHelper(const Address& address, uint16_t port) + : UdpClientHelper(address) +{ SetAttribute("RemotePort", UintegerValue(port)); } -UdpClientHelper::UdpClientHelper(Address address) -{ - m_factory.SetTypeId(UdpClient::GetTypeId()); - SetAttribute("RemoteAddress", AddressValue(address)); -} - -void -UdpClientHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -UdpClientHelper::Install(NodeContainer c) -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - Ptr node = *i; - Ptr client = m_factory.Create(); - node->AddApplication(client); - apps.Add(client); - } - return apps; -} - UdpTraceClientHelper::UdpTraceClientHelper() + : ApplicationHelper(UdpTraceClient::GetTypeId()) { - m_factory.SetTypeId(UdpTraceClient::GetTypeId()); } -UdpTraceClientHelper::UdpTraceClientHelper(Address address, uint16_t port, std::string filename) +UdpTraceClientHelper::UdpTraceClientHelper(const Address& address, const std::string& filename) + : UdpTraceClientHelper() { - m_factory.SetTypeId(UdpTraceClient::GetTypeId()); SetAttribute("RemoteAddress", AddressValue(address)); + SetAttribute("TraceFilename", StringValue(filename)); +} + +UdpTraceClientHelper::UdpTraceClientHelper(const Address& address, + uint16_t port, + const std::string& filename) + : UdpTraceClientHelper(address, filename) +{ SetAttribute("RemotePort", UintegerValue(port)); - SetAttribute("TraceFilename", StringValue(filename)); -} - -UdpTraceClientHelper::UdpTraceClientHelper(Address address, std::string filename) -{ - m_factory.SetTypeId(UdpTraceClient::GetTypeId()); - SetAttribute("RemoteAddress", AddressValue(address)); - SetAttribute("TraceFilename", StringValue(filename)); -} - -void -UdpTraceClientHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -ApplicationContainer -UdpTraceClientHelper::Install(NodeContainer c) -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - Ptr node = *i; - Ptr client = m_factory.Create(); - node->AddApplication(client); - apps.Add(client); - } - return apps; } } // namespace ns3 diff --git a/src/applications/helper/udp-client-server-helper.h b/src/applications/helper/udp-client-server-helper.h index 41bf51cf1..aaa5cf1e0 100644 --- a/src/applications/helper/udp-client-server-helper.h +++ b/src/applications/helper/udp-client-server-helper.h @@ -16,15 +16,14 @@ * * Author: Mohamed Amine Ismail */ + #ifndef UDP_CLIENT_SERVER_HELPER_H #define UDP_CLIENT_SERVER_HELPER_H -#include "ns3/application-container.h" -#include "ns3/ipv4-address.h" -#include "ns3/node-container.h" -#include "ns3/object-factory.h" -#include "ns3/udp-client.h" -#include "ns3/udp-server.h" +#include +#include +#include +#include #include @@ -36,7 +35,7 @@ namespace ns3 * and uses the information carried into their payload to compute * delay and to determine if some packets are lost. */ -class UdpServerHelper +class UdpServerHelper : public ApplicationHelper { public: /** @@ -54,25 +53,6 @@ class UdpServerHelper */ UdpServerHelper(uint16_t port); - /** - * Record an attribute to be set in each Application after it is is created. - * - * \param name the name of the attribute to set - * \param value the value of the attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * Create one UDP server application on each of the Nodes in the - * NodeContainer. - * - * \param c The nodes on which to create the Applications. The nodes - * are specified by a NodeContainer. - * \returns The applications created, one Application per Node in the - * NodeContainer. - */ - ApplicationContainer Install(NodeContainer c); - /** * \brief Return the last created server. * @@ -83,7 +63,8 @@ class UdpServerHelper Ptr GetServer(); private: - ObjectFactory m_factory; //!< Object factory. + Ptr DoInstall(Ptr node) override; + Ptr m_server; //!< The last created server application }; @@ -93,7 +74,7 @@ class UdpServerHelper * a 32bit sequence number and a 64 bit time stamp. * */ -class UdpClientHelper +class UdpClientHelper : public ApplicationHelper { public: /** @@ -113,7 +94,7 @@ class UdpClientHelper * \param port The port number of the remote UDP server */ - UdpClientHelper(Address ip, uint16_t port); + UdpClientHelper(const Address& ip, uint16_t port); /** * Create UdpClientHelper which will make life easier for people trying * to set up simulations with udp-client-server. Use this variant with @@ -123,27 +104,7 @@ class UdpClientHelper * \param addr The address of the remote UDP server */ - UdpClientHelper(Address addr); - - /** - * Record an attribute to be set in each Application after it is is created. - * - * \param name the name of the attribute to set - * \param value the value of the attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * \param c the nodes - * - * Create one UDP client application on each of the input nodes - * - * \returns the applications created, one application per input node. - */ - ApplicationContainer Install(NodeContainer c); - - private: - ObjectFactory m_factory; //!< Object factory. + UdpClientHelper(const Address& addr); }; /** @@ -158,7 +119,7 @@ class UdpClientHelper * \li -3- the third one indicates the time on which the frame was generated by the encoder * \li -4- the fourth one indicates the frame size in byte */ -class UdpTraceClientHelper +class UdpTraceClientHelper : public ApplicationHelper { public: /** @@ -178,7 +139,8 @@ class UdpTraceClientHelper * \param port The port number of the remote UDP server * \param filename the file from which packet traces will be loaded */ - UdpTraceClientHelper(Address ip, uint16_t port, std::string filename); + UdpTraceClientHelper(const Address& ip, uint16_t port, const std::string& filename = ""); + /** * Create UdpTraceClientHelper which will make life easier for people trying * to set up simulations with udp-client-server. Use this variant with @@ -188,27 +150,7 @@ class UdpTraceClientHelper * \param addr The address of the remote UDP server * \param filename the file from which packet traces will be loaded */ - UdpTraceClientHelper(Address addr, std::string filename); - - /** - * Record an attribute to be set in each Application after it is is created. - * - * \param name the name of the attribute to set - * \param value the value of the attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * \param c the nodes - * - * Create one UDP trace client application on each of the input nodes - * - * \returns the applications created, one application per input node. - */ - ApplicationContainer Install(NodeContainer c); - - private: - ObjectFactory m_factory; //!< Object factory. + UdpTraceClientHelper(const Address& addr, const std::string& filename = ""); }; } // namespace ns3 diff --git a/src/applications/helper/udp-echo-helper.cc b/src/applications/helper/udp-echo-helper.cc index ce5760223..e85e4d93a 100644 --- a/src/applications/helper/udp-echo-helper.cc +++ b/src/applications/helper/udp-echo-helper.cc @@ -16,9 +16,9 @@ * * Author: Mathieu Lacage */ + #include "udp-echo-helper.h" -#include "ns3/names.h" #include "ns3/udp-echo-client.h" #include "ns3/udp-echo-server.h" #include "ns3/uinteger.h" @@ -27,72 +27,26 @@ namespace ns3 { UdpEchoServerHelper::UdpEchoServerHelper(uint16_t port) + : ApplicationHelper(UdpEchoServer::GetTypeId()) { - m_factory.SetTypeId(UdpEchoServer::GetTypeId()); SetAttribute("Port", UintegerValue(port)); } -void -UdpEchoServerHelper::SetAttribute(std::string name, const AttributeValue& value) +UdpEchoClientHelper::UdpEchoClientHelper(const Address& address, uint16_t port) + : ApplicationHelper(UdpEchoClient::GetTypeId()) { - m_factory.Set(name, value); -} - -ApplicationContainer -UdpEchoServerHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -UdpEchoServerHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -UdpEchoServerHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -UdpEchoServerHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - -UdpEchoClientHelper::UdpEchoClientHelper(Address address, uint16_t port) -{ - m_factory.SetTypeId(UdpEchoClient::GetTypeId()); SetAttribute("RemoteAddress", AddressValue(address)); SetAttribute("RemotePort", UintegerValue(port)); } -UdpEchoClientHelper::UdpEchoClientHelper(Address address) +UdpEchoClientHelper::UdpEchoClientHelper(const Address& address) + : ApplicationHelper(UdpEchoClient::GetTypeId()) { - m_factory.SetTypeId(UdpEchoClient::GetTypeId()); SetAttribute("RemoteAddress", AddressValue(address)); } void -UdpEchoClientHelper::SetAttribute(std::string name, const AttributeValue& value) -{ - m_factory.Set(name, value); -} - -void -UdpEchoClientHelper::SetFill(Ptr app, std::string fill) +UdpEchoClientHelper::SetFill(Ptr app, const std::string& fill) { app->GetObject()->SetFill(fill); } @@ -112,38 +66,4 @@ UdpEchoClientHelper::SetFill(Ptr app, app->GetObject()->SetFill(fill, fillLength, dataLength); } -ApplicationContainer -UdpEchoClientHelper::Install(Ptr node) const -{ - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -UdpEchoClientHelper::Install(std::string nodeName) const -{ - Ptr node = Names::Find(nodeName); - return ApplicationContainer(InstallPriv(node)); -} - -ApplicationContainer -UdpEchoClientHelper::Install(NodeContainer c) const -{ - ApplicationContainer apps; - for (auto i = c.Begin(); i != c.End(); ++i) - { - apps.Add(InstallPriv(*i)); - } - - return apps; -} - -Ptr -UdpEchoClientHelper::InstallPriv(Ptr node) const -{ - Ptr app = m_factory.Create(); - node->AddApplication(app); - - return app; -} - } // namespace ns3 diff --git a/src/applications/helper/udp-echo-helper.h b/src/applications/helper/udp-echo-helper.h index 6b904baf0..dfa6587d1 100644 --- a/src/applications/helper/udp-echo-helper.h +++ b/src/applications/helper/udp-echo-helper.h @@ -16,14 +16,11 @@ * * Author: Mathieu Lacage */ + #ifndef UDP_ECHO_HELPER_H #define UDP_ECHO_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 #include @@ -35,7 +32,7 @@ namespace ns3 * \brief Create a server application which waits for input UDP packets * and sends them back to the original sender. */ -class UdpEchoServerHelper +class UdpEchoServerHelper : public ApplicationHelper { public: /** @@ -45,66 +42,13 @@ class UdpEchoServerHelper * \param port The port the server will wait on for incoming packets */ UdpEchoServerHelper(uint16_t port); - - /** - * Record an attribute to be set in each Application after it is is created. - * - * \param name the name of the attribute to set - * \param value the value of the attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); - - /** - * Create a UdpEchoServerApplication on the specified Node. - * - * \param node The node on which to create the Application. The node is - * specified by a Ptr. - * - * \returns An ApplicationContainer holding the Application created, - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Create a UdpEchoServerApplication on specified node - * - * \param nodeName The node on which to create the application. The node - * is specified by a node name previously registered with - * the Object Name Service. - * - * \returns An ApplicationContainer holding the Application created. - */ - ApplicationContainer Install(std::string nodeName) const; - - /** - * \param c The nodes on which to create the Applications. The nodes - * are specified by a NodeContainer. - * - * Create one udp echo server application on each of the Nodes in the - * NodeContainer. - * - * \returns The applications created, one Application per Node in the - * NodeContainer. - */ - ApplicationContainer Install(NodeContainer c) const; - - private: - /** - * Install an ns3::UdpEchoServer on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an UdpEchoServer will be installed. - * \returns Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - - ObjectFactory m_factory; //!< Object factory. }; /** * \ingroup udpecho * \brief Create an application which sends a UDP packet and waits for an echo of this packet */ -class UdpEchoClientHelper +class UdpEchoClientHelper : public ApplicationHelper { public: /** @@ -115,7 +59,7 @@ class UdpEchoClientHelper * \param ip The IP address of the remote udp echo server * \param port The port number of the remote udp echo server */ - UdpEchoClientHelper(Address ip, uint16_t port); + UdpEchoClientHelper(const Address& ip, uint16_t port); /** * Create UdpEchoClientHelper which will make life easier for people trying * to set up simulations with echos. Use this variant with addresses that do @@ -123,15 +67,7 @@ class UdpEchoClientHelper * * \param addr The address of the remote udp echo server */ - UdpEchoClientHelper(Address addr); - - /** - * Record an attribute to be set in each Application after it is is created. - * - * \param name the name of the attribute to set - * \param value the value of the attribute to set - */ - void SetAttribute(std::string name, const AttributeValue& value); + UdpEchoClientHelper(const Address& addr); /** * Given a pointer to a UdpEchoClient application, set the data fill of the @@ -145,7 +81,7 @@ class UdpEchoClientHelper * \param app Smart pointer to the application (real type must be UdpEchoClient). * \param fill The string to use as the actual echo data bytes. */ - void SetFill(Ptr app, std::string fill); + void SetFill(Ptr app, const std::string& fill); /** * Given a pointer to a UdpEchoClient application, set the data fill of the @@ -183,49 +119,6 @@ class UdpEchoClientHelper * \param dataLength The desired length of the final echo data. */ void SetFill(Ptr app, uint8_t* fill, uint32_t fillLength, uint32_t dataLength); - - /** - * Create a udp echo client application on the specified node. The Node - * is provided as a Ptr. - * - * \param node The Ptr on which to create the UdpEchoClientApplication. - * - * \returns An ApplicationContainer that holds a Ptr to the - * application created - */ - ApplicationContainer Install(Ptr node) const; - - /** - * Create a udp echo client application on the specified node. The Node - * is provided as a string name of a Node that has been previously - * associated using the Object Name Service. - * - * \param nodeName The name of the node on which to create the UdpEchoClientApplication - * - * \returns An ApplicationContainer that holds a Ptr to the - * application created - */ - ApplicationContainer Install(std::string nodeName) const; - - /** - * \param c the nodes - * - * Create one udp echo client application on each of the input nodes - * - * \returns the applications created, one application per input node. - */ - ApplicationContainer Install(NodeContainer c) const; - - private: - /** - * Install an ns3::UdpEchoClient on the node configured with all the - * attributes set with SetAttribute. - * - * \param node The node on which an UdpEchoClient will be installed. - * \returns Ptr to the application installed. - */ - Ptr InstallPriv(Ptr node) const; - ObjectFactory m_factory; //!< Object factory. }; } // namespace ns3 diff --git a/src/applications/test/udp-client-server-test.cc b/src/applications/test/udp-client-server-test.cc index 33ffae14f..b663ba39a 100644 --- a/src/applications/test/udp-client-server-test.cc +++ b/src/applications/test/udp-client-server-test.cc @@ -97,29 +97,28 @@ UdpClientServerTestCase::DoRun() Ipv4InterfaceContainer i = ipv4.Assign(d); uint16_t port = 4000; - UdpServerHelper server(port); - ApplicationContainer apps = server.Install(n.Get(1)); - apps.Start(Seconds(1.0)); - apps.Stop(Seconds(10.0)); + UdpServerHelper serverHelper(port); + auto serverApp = serverHelper.Install(n.Get(1)); + serverApp.Start(Seconds(1.0)); + serverApp.Stop(Seconds(10.0)); uint32_t MaxPacketSize = 1024; Time interPacketInterval = Seconds(1.); uint32_t maxPacketCount = 10; - UdpClientHelper client(i.GetAddress(1), port); - client.SetAttribute("MaxPackets", UintegerValue(maxPacketCount)); - client.SetAttribute("Interval", TimeValue(interPacketInterval)); - client.SetAttribute("PacketSize", UintegerValue(MaxPacketSize)); - apps = client.Install(n.Get(0)); - apps.Start(Seconds(2.0)); - apps.Stop(Seconds(10.0)); + UdpClientHelper clientHelper(i.GetAddress(1), port); + clientHelper.SetAttribute("MaxPackets", UintegerValue(maxPacketCount)); + clientHelper.SetAttribute("Interval", TimeValue(interPacketInterval)); + clientHelper.SetAttribute("PacketSize", UintegerValue(MaxPacketSize)); + auto clientApp = clientHelper.Install(n.Get(0)); + clientApp.Start(Seconds(2.0)); + clientApp.Stop(Seconds(10.0)); Simulator::Run(); Simulator::Destroy(); - NS_TEST_ASSERT_MSG_EQ(server.GetServer()->GetLost(), 0, "Packets were lost !"); - NS_TEST_ASSERT_MSG_EQ(server.GetServer()->GetReceived(), - 8, - "Did not receive expected number of packets !"); + auto server = DynamicCast(serverApp.Get(0)); + NS_TEST_ASSERT_MSG_EQ(server->GetLost(), 0, "Packets were lost !"); + NS_TEST_ASSERT_MSG_EQ(server->GetReceived(), 8, "Did not receive expected number of packets !"); } /** @@ -173,23 +172,24 @@ UdpTraceClientServerTestCase::DoRun() Ipv4InterfaceContainer i = ipv4.Assign(d); uint16_t port = 4000; - UdpServerHelper server(port); - ApplicationContainer apps = server.Install(n.Get(1)); - apps.Start(Seconds(1.0)); - apps.Stop(Seconds(10.0)); + UdpServerHelper serverHelper(port); + auto serverApp = serverHelper.Install(n.Get(1)); + serverApp.Start(Seconds(1.0)); + serverApp.Stop(Seconds(10.0)); uint32_t MaxPacketSize = 1400 - 28; // ip/udp header - UdpTraceClientHelper client(i.GetAddress(1), port, ""); - client.SetAttribute("MaxPacketSize", UintegerValue(MaxPacketSize)); - apps = client.Install(n.Get(0)); - apps.Start(Seconds(2.0)); - apps.Stop(Seconds(10.0)); + UdpTraceClientHelper clientHelper(i.GetAddress(1), port); + clientHelper.SetAttribute("MaxPacketSize", UintegerValue(MaxPacketSize)); + auto clientApp = clientHelper.Install(n.Get(0)); + clientApp.Start(Seconds(2.0)); + clientApp.Stop(Seconds(10.0)); Simulator::Run(); Simulator::Destroy(); - NS_TEST_ASSERT_MSG_EQ(server.GetServer()->GetLost(), 0, "Packets were lost !"); - NS_TEST_ASSERT_MSG_EQ(server.GetServer()->GetReceived(), + auto server = DynamicCast(serverApp.Get(0)); + NS_TEST_ASSERT_MSG_EQ(server->GetLost(), 0, "Packets were lost !"); + NS_TEST_ASSERT_MSG_EQ(server->GetReceived(), 247, "Did not receive expected number of packets !"); }