applications: Simplify helpers

This commit is contained in:
Sébastien Deronne
2024-01-11 21:42:31 +01:00
parent 4d098adbb2
commit 6b1afa1a5d
13 changed files with 114 additions and 914 deletions

View File

@@ -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 <ns3/string.h>
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> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
BulkSendHelper::Install(std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
BulkSendHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<Application>();
node->AddApplication(app);
return app;
}
} // namespace ns3

View File

@@ -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 <stdint.h>
#include <string>
#include <ns3/application-helper.h>
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> 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<Application> InstallPriv(Ptr<Node> 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 */

View File

@@ -16,83 +16,23 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#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 <ns3/onoff-application.h>
#include <ns3/string.h>
#include <ns3/uinteger.h>
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> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
OnOffHelper::Install(std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
OnOffHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<Application>();
node->AddApplication(app);
return app;
}
int64_t
OnOffHelper::AssignStreams(NodeContainer c, int64_t stream)
{
int64_t currentStream = stream;
Ptr<Node> 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)
{

View File

@@ -16,31 +16,24 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#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 <ns3/application-helper.h>
#include <ns3/data-rate.h>
#include <stdint.h>
#include <string>
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> 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<Application> InstallPriv(Ptr<Node> node) const;
ObjectFactory m_factory; //!< Object factory.
};
} // namespace ns3

View File

@@ -19,58 +19,16 @@
#include "packet-sink-helper.h"
#include "ns3/inet-socket-address.h"
#include "ns3/names.h"
#include "ns3/string.h"
#include <ns3/string.h>
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> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
PacketSinkHelper::Install(std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
PacketSinkHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<Application>();
node->AddApplication(app);
return app;
}
} // namespace ns3

View File

@@ -16,13 +16,11 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#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 <ns3/application-helper.h>
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> 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<Application> InstallPriv(Ptr<Node> node) const;
ObjectFactory m_factory; //!< Object factory.
PacketSinkHelper(const std::string& protocol, const Address& address);
};
} // namespace ns3

View File

@@ -25,105 +25,23 @@
#include "three-gpp-http-helper.h"
#include <ns3/names.h>
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> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
ThreeGppHttpClientHelper::Install(const std::string& nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
ThreeGppHttpClientHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<Application>();
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> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
ThreeGppHttpServerHelper::Install(const std::string& nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
ThreeGppHttpServerHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<Application>();
node->AddApplication(app);
return app;
}
} // namespace ns3

View File

@@ -26,9 +26,7 @@
#ifndef THREE_GPP_HTTP_HELPER_H
#define THREE_GPP_HTTP_HELPER_H
#include <ns3/application-container.h>
#include <ns3/node-container.h>
#include <ns3/object-factory.h>
#include <ns3/application-helper.h>
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> 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<Application> InstallPriv(Ptr<Node> 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> 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<Application> InstallPriv(Ptr<Node> node) const;
/// Used to instantiate a ThreeGppHttpServer instance.
ObjectFactory m_factory;
}; // end of `class ThreeGppHttpServerHelper`
} // namespace ns3

View File

@@ -16,47 +16,32 @@
*
* Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
*/
#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 <ns3/string.h>
#include <ns3/uinteger.h>
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<Application>
UdpServerHelper::DoInstall(Ptr<Node> node)
{
m_factory.Set(name, value);
}
ApplicationContainer
UdpServerHelper::Install(NodeContainer c)
{
ApplicationContainer apps;
for (auto i = c.Begin(); i != c.End(); ++i)
{
Ptr<Node> node = *i;
m_server = m_factory.Create<UdpServer>();
node->AddApplication(m_server);
apps.Add(m_server);
}
return apps;
m_server = m_factory.Create<UdpServer>();
node->AddApplication(m_server);
return m_server;
}
Ptr<UdpServer>
@@ -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> node = *i;
Ptr<UdpClient> client = m_factory.Create<UdpClient>();
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> node = *i;
Ptr<UdpTraceClient> client = m_factory.Create<UdpTraceClient>();
node->AddApplication(client);
apps.Add(client);
}
return apps;
}
} // namespace ns3

View File

@@ -16,15 +16,14 @@
*
* Author: Mohamed Amine Ismail <amine.ismail@sophia.inria.fr>
*/
#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 <ns3/application-helper.h>
#include <ns3/udp-client.h>
#include <ns3/udp-server.h>
#include <ns3/udp-trace-client.h>
#include <stdint.h>
@@ -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<UdpServer> GetServer();
private:
ObjectFactory m_factory; //!< Object factory.
Ptr<Application> DoInstall(Ptr<Node> node) override;
Ptr<UdpServer> 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

View File

@@ -16,9 +16,9 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#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> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
UdpEchoServerHelper::Install(std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
UdpEchoServerHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<UdpEchoServer>();
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<Application> app, std::string fill)
UdpEchoClientHelper::SetFill(Ptr<Application> app, const std::string& fill)
{
app->GetObject<UdpEchoClient>()->SetFill(fill);
}
@@ -112,38 +66,4 @@ UdpEchoClientHelper::SetFill(Ptr<Application> app,
app->GetObject<UdpEchoClient>()->SetFill(fill, fillLength, dataLength);
}
ApplicationContainer
UdpEchoClientHelper::Install(Ptr<Node> node) const
{
return ApplicationContainer(InstallPriv(node));
}
ApplicationContainer
UdpEchoClientHelper::Install(std::string nodeName) const
{
Ptr<Node> node = Names::Find<Node>(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<Application>
UdpEchoClientHelper::InstallPriv(Ptr<Node> node) const
{
Ptr<Application> app = m_factory.Create<UdpEchoClient>();
node->AddApplication(app);
return app;
}
} // namespace ns3

View File

@@ -16,14 +16,11 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#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 <ns3/application-helper.h>
#include <stdint.h>
@@ -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<Node>.
*
* \returns An ApplicationContainer holding the Application created,
*/
ApplicationContainer Install(Ptr<Node> 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<Application> InstallPriv(Ptr<Node> 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<Application> app, std::string fill);
void SetFill(Ptr<Application> 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<Application> 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<Node>.
*
* \param node The Ptr<Node> on which to create the UdpEchoClientApplication.
*
* \returns An ApplicationContainer that holds a Ptr<Application> to the
* application created
*/
ApplicationContainer Install(Ptr<Node> 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<Application> 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<Application> InstallPriv(Ptr<Node> node) const;
ObjectFactory m_factory; //!< Object factory.
};
} // namespace ns3

View File

@@ -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<UdpServer>(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<UdpServer>(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 !");
}