helper for UdpEcho client and server
This commit is contained in:
64
src/helper/udp-echo-helper.cc
Normal file
64
src/helper/udp-echo-helper.cc
Normal file
@@ -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> node = *i;
|
||||
Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> ("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> node = *i;
|
||||
Ptr<UdpEchoClient> client = m_factory.Create<UdpEchoClient> ();
|
||||
client->SetRemote (m_remoteIp, m_remotePort);
|
||||
node->AddApplication (client);
|
||||
apps.Add (client);
|
||||
}
|
||||
return apps;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
39
src/helper/udp-echo-helper.h
Normal file
39
src/helper/udp-echo-helper.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef UDP_ECHO_HELPER_H
|
||||
#define UDP_ECHO_HELPER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#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 */
|
||||
Reference in New Issue
Block a user