diff --git a/src/helper/udp-echo-helper.cc b/src/helper/udp-echo-helper.cc new file mode 100644 index 000000000..d30a647b0 --- /dev/null +++ b/src/helper/udp-echo-helper.cc @@ -0,0 +1,64 @@ +#include "udp-echo-helper.h" +#include "ns3/udp-echo-server.h" +#include "ns3/udp-echo-client.h" +#include "ns3/uinteger.h" + +namespace ns3 { + +UdpEchoServerHelper::UdpEchoServerHelper () + : m_port (9) +{} + +void +UdpEchoServerHelper::SetPort (uint16_t port) +{ + m_port = port; +} +ApplicationContainer +UdpEchoServerHelper::Build (NodeContainer c) +{ + ApplicationContainer apps; + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) + { + Ptr node = *i; + Ptr server = CreateObject ("Port", Uinteger (m_port)); + node->AddApplication (server); + apps.Add (server); + } + return apps; +} + +UdpEchoClientHelper::UdpEchoClientHelper () +{ + m_factory.SetTypeId (UdpEchoClient::GetTypeId ()); +} +void +UdpEchoClientHelper::SetRemote (Ipv4Address ip, uint16_t port) +{ + m_remoteIp = ip; + m_remotePort = port; +} +void +UdpEchoClientHelper::SetAppAttribute (std::string name, Attribute value) +{ + m_factory.Set (name, value); +} + +ApplicationContainer +UdpEchoClientHelper::Build (NodeContainer c) +{ + ApplicationContainer apps; + for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i) + { + Ptr node = *i; + Ptr client = m_factory.Create (); + client->SetRemote (m_remoteIp, m_remotePort); + node->AddApplication (client); + apps.Add (client); + } + return apps; +} + + + +} // namespace ns3 diff --git a/src/helper/udp-echo-helper.h b/src/helper/udp-echo-helper.h new file mode 100644 index 000000000..70ece7b4f --- /dev/null +++ b/src/helper/udp-echo-helper.h @@ -0,0 +1,39 @@ +#ifndef UDP_ECHO_HELPER_H +#define UDP_ECHO_HELPER_H + +#include +#include "application-container.h" +#include "node-container.h" +#include "ns3/object-factory.h" +#include "ns3/ipv4-address.h" + +namespace ns3 { + +class UdpEchoServerHelper +{ +public: + UdpEchoServerHelper (); + void SetPort (uint16_t port); + ApplicationContainer Build (NodeContainer c); +private: + uint16_t m_port; +}; + +class UdpEchoClientHelper +{ +public: + UdpEchoClientHelper (); + + void SetRemote (Ipv4Address ip, uint16_t port); + void SetAppAttribute (std::string name, Attribute value); + ApplicationContainer Build (NodeContainer c); + private: + ObjectFactory m_factory; + Ipv4Address m_remoteIp; + uint16_t m_remotePort; +}; + + +} // namespace ns3 + +#endif /* UDP_ECHO_HELPER_H */