Move API for socket factory to a Socket::CreateSocket () factory method

This commit is contained in:
Tom Henderson committed 2008-05-12 06:39:00 -07:00
1 parent 3ebec1046c
commit a042d0bbef
11 files changed
+38 -27

No files matched your search

+2 -3
View File
@@ -176,9 +176,8 @@ int main (int argc, char *argv[])
apps.Start (Seconds (0.0));
// and generate traffic to remote sink.
Ptr<SocketFactory> socketFactory =
c0.Get (0)->GetObject<Tcp> ();
Ptr<Socket> localSocket = socketFactory->CreateSocket ();
//TypeId tid = TypeId::LookupByName ("ns3::Tcp");
Ptr<Socket> localSocket = Socket::CreateSocket (c0.Get (0), Tcp::GetTypeId ());
localSocket->Bind ();
Simulator::ScheduleNow (&StartFlow, localSocket, nBytes,
ipInterfs.GetAddress (1), servPort);
+3 -4
View File
@@ -102,9 +102,8 @@ Experiment::ReceivePacket (Ptr<Socket> socket)
Ptr<Socket>
Experiment::SetupPacketReceive (Ptr<Node> node)
{
TypeId tid = TypeId::LookupByName ("ns3::PacketSocketFactory");
Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
Ptr<Socket> sink = socketFactory->CreateSocket ();
TypeId tid = TypeId::LookupByName ("ns3::PacketSocket");
Ptr<Socket> sink = Socket::CreateSocket (node, tid);
sink->Bind ();
sink->SetRecvCallback (MakeCallback (&Experiment::ReceivePacket, this));
return sink;
@@ -137,7 +136,7 @@ Experiment::Run (const WifiHelper &wifi)
socket.SetPhysicalAddress (devices.Get (1)->GetAddress ());
socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
OnOffHelper onoff ("ns3::PacketSocket", Address (socket));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (250)));
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
onoff.SetAttribute ("DataRate", DataRateValue (DataRate (60000000)));
+1 -1
View File
@@ -162,7 +162,7 @@ int main (int argc, char *argv[])
socket.SetPhysicalAddress (staDevs.Get (1)->GetAddress ());
socket.SetProtocol (1);
OnOffHelper onoff ("ns3::PacketSocketFactory", Address (socket));
OnOffHelper onoff ("ns3::PacketSocket", Address (socket));
onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (42)));
onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+2 -4
View File
@@ -49,13 +49,11 @@ RunSimulation (void)
TypeId tid = TypeId::LookupByName ("ns3::Udp");
Ptr<SocketFactory> socketFactory = c.Get (0)->GetObject<SocketFactory> (tid);
Ptr<Socket> sink = socketFactory->CreateSocket ();
Ptr<Socket> sink = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 80);
sink->Bind (local);
Ptr<Socket> source = socketFactory->CreateSocket ();
Ptr<Socket> source = Socket::CreateSocket (c.Get (0), tid);
InetSocketAddress remote = InetSocketAddress (Ipv4Address::GetLoopback (), 80);
source->Connect (remote);
+1 -2
View File
@@ -130,8 +130,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Start
// Create the socket if not already
if (!m_socket)
{
Ptr<SocketFactory> socketFactory = GetNode ()->GetObject<SocketFactory> (m_tid);
m_socket = socketFactory->CreateSocket ();
m_socket = Socket::CreateSocket (GetNode(), m_tid);
m_socket->Bind ();
m_socket->Connect (m_peer);
}
+1 -3
View File
@@ -80,9 +80,7 @@ void PacketSink::StartApplication() // Called at time specified by Start
// Create the socket if not already
if (!m_socket)
{
Ptr<SocketFactory> socketFactory =
GetNode ()->GetObject<SocketFactory> (m_tid);
m_socket = socketFactory->CreateSocket ();
m_socket = Socket::CreateSocket (GetNode(), m_tid);
m_socket->Bind (m_local);
m_socket->Listen (0);
}
+1 -3
View File
@@ -96,9 +96,7 @@ UdpEchoClient::StartApplication (void)
if (!m_socket)
{
TypeId tid = TypeId::LookupByName ("ns3::Udp");
Ptr<SocketFactory> socketFactory =
GetNode ()->GetObject<SocketFactory> (tid);
m_socket = socketFactory->CreateSocket ();
m_socket = Socket::CreateSocket (GetNode(), tid);
m_socket->Bind ();
m_socket->Connect (InetSocketAddress (m_peerAddress, m_peerPort));
}
+1 -3
View File
@@ -72,9 +72,7 @@ UdpEchoServer::StartApplication (void)
if (!m_socket)
{
TypeId tid = TypeId::LookupByName ("ns3::Udp");
Ptr<SocketFactory> socketFactory =
GetNode ()->GetObject<SocketFactory> (tid);
m_socket = socketFactory->CreateSocket ();
m_socket = Socket::CreateSocket (GetNode(), tid);
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), m_port);
m_socket->Bind (local);
}
+12
View File
@@ -22,7 +22,9 @@
#include "ns3/log.h"
#include "ns3/packet.h"
#include "node.h"
#include "socket.h"
#include "socket-factory.h"
NS_LOG_COMPONENT_DEFINE ("Socket");
@@ -83,6 +85,16 @@ Socket::~Socket ()
NS_LOG_FUNCTION_NOARGS ();
}
Ptr<Socket>
Socket::CreateSocket (Ptr<Node> node, TypeId tid)
{
Ptr<Socket> s;
Ptr<SocketFactory> socketFactory = node->GetObject<SocketFactory> (tid);
s = socketFactory->CreateSocket ();
NS_ASSERT (s != 0);
return s;
}
void
Socket::SetCloseCallback (Callback<void,Ptr<Socket> > closeCompleted)
{
+11
View File
@@ -98,6 +98,17 @@ public:
SOCKET_ERRNO_LAST
};
/**
* This method wraps the creation of sockets that is performed
* by a socket factory on a given node based on a TypeId.
*
* \return A smart pointer to a newly created socket.
*
* \param node The node on which to create the socket
* \param tid The TypeId of the socket to create
*/
static Ptr<Socket> CreateSocket (Ptr<Node> node, TypeId tid);
/**
* \return the errno associated to the last call which failed in this
* socket. Each socket's errno is initialized to zero
+3 -4
View File
@@ -258,9 +258,7 @@ void AgentImpl::Start ()
// Add OLSR as routing protocol, with slightly higher priority than
// static routing.
m_ipv4->AddRoutingProtocol (m_routingTable, 10);
Ptr<SocketFactory> socketFactory = GetObject<SocketFactory> (Udp::GetTypeId ());
Ipv4Address loopback ("127.0.0.1");
for (uint32_t i = 0; i < m_ipv4->GetNInterfaces (); i++)
{
@@ -281,7 +279,8 @@ void AgentImpl::Start ()
}
// Create a socket to listen only on this interface
Ptr<Socket> socket = socketFactory->CreateSocket ();
Ptr<Socket> socket = Socket::CreateSocket (GetObject<Node> (),
Udp::GetTypeId());
socket->SetRecvCallback (MakeCallback (&AgentImpl::RecvOlsr, this));
if (socket->Bind (InetSocketAddress (addr, OLSR_PORT_NUMBER)))
{