define and implement IUdp

This commit is contained in:
Mathieu Lacage committed 2007-05-03 14:20:04 +02:00
1 parent b406de2008
commit 5e8a744bec
11 files changed
+198 -367

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "i-udp-impl.h"
#include "udp.h"
#include "ns3/assert.h"
namespace ns3 {
IUdpImpl::IUdpImpl (Udp *udp)
: m_udp (udp)
{
m_udp->Ref ();
}
IUdpImpl::~IUdpImpl ()
{
NS_ASSERT (m_udp == 0);
}
Socket *
IUdpImpl::CreateSocket (void)
{
return m_udp->CreateSocket ();
}
void
IUdpImpl::DoDispose (void)
{
if (m_udp != 0)
{
m_udp->Unref ();
m_udp = 0;
}
IUdp::DoDispose ();
}
} // namespace ns3
+46
View File
@@ -0,0 +1,46 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef I_UDP_IMPL_H
#define I_UDP_IMPL_H
#include "i-udp.h"
namespace ns3 {
class Udp;
class IUdpImpl : public IUdp
{
public:
IUdpImpl (Udp *udp);
virtual ~IUdpImpl ();
virtual Socket *CreateSocket (void);
protected:
virtual void DoDispose (void);
private:
Udp *m_udp;
};
} // namespace ns3
#endif /* I_UDP_IMPL_H */
+32
View File
@@ -0,0 +1,32 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "i-udp.h"
#include "ns3/iid-manager.h"
namespace ns3 {
const uint32_t IUdp::iid = IidManager::Allocate ("IUdp");
IUdp::IUdp ()
: NsUnknown (IUdp::iid)
{}
} // namespace ns3
+42
View File
@@ -0,0 +1,42 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef I_UDP_H
#define I_UDP_H
#include "ns3/ns-unknown.h"
namespace ns3 {
class Socket;
class IUdp : public NsUnknown
{
public:
static const uint32_t iid;
IUdp ();
virtual Socket *CreateSocket (void) = 0;
};
} // namespace ns3
#endif /* I_UDP_H */
+14 -7
View File
@@ -31,28 +31,34 @@
#include "ipv4.h"
#include "arp.h"
#include "net-device.h"
#include "i-udp-impl.h"
namespace ns3 {
InternetNode::InternetNode()
{
Ipv4 *ipv4 = new Ipv4 (this);
Arp *arp = new Arp (this);
Udp *udp = new Udp (this);
// Instantiate the capabilities
ApplicationList *applicationList = new ApplicationList(this);
L3Demux *l3Demux = new L3Demux(this);
Ipv4L4Demux *ipv4L4Demux = new Ipv4L4Demux(this);
l3Demux->Insert (ipv4);
l3Demux->Insert (arp);
ipv4L4Demux->Insert (udp);
IUdpImpl *udpImpl = new IUdpImpl (udp);
NsUnknown::AddInterface (udpImpl);
NsUnknown::AddInterface (applicationList);
NsUnknown::AddInterface (l3Demux);
NsUnknown::AddInterface (ipv4L4Demux);
Ipv4 *ipv4 = new Ipv4 (this);
Arp *arp = new Arp (this);
Udp *udp = new Udp (this);
l3Demux->Insert (ipv4);
l3Demux->Insert (arp);
ipv4L4Demux->Insert (udp);
applicationList->Unref ();
l3Demux->Unref ();
@@ -60,6 +66,7 @@ InternetNode::InternetNode()
ipv4->Unref ();
arp->Unref ();
udp->Unref ();
udpImpl->Unref ();
}
InternetNode::~InternetNode ()
+2 -2
View File
@@ -30,7 +30,7 @@
#include "ns3/random-variable.h"
#include "socket.h"
#include "ns3/simulator.h"
#include "udp.h"
#include "i-udp.h"
using namespace std;
@@ -170,7 +170,7 @@ void OnOffApplication::StartApplication() // Called at time specified by Star
this));
#endif
Udp *udp = PeekNode ()->GetUdp ();
IUdp *udp = PeekNode ()->QueryInterface<IUdp> (IUdp::iid);
m_socket = udp->CreateSocket ();
udp->Unref ();
m_socket->Connect (m_peerIP, m_peerPort);