add Ipv4 and Udp node capabilities, rework Copy methods to include an extra Node * argument
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "net-device-list.h"
|
||||
#include "l3-demux.h"
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include "ipv4-l4-demux.h"
|
||||
#include "internet-node.h"
|
||||
#include "udp.h"
|
||||
@@ -34,31 +35,21 @@ InternetNode::InternetNode()
|
||||
{
|
||||
// Instantiate the capabilities
|
||||
m_netDevices = new NetDeviceList();
|
||||
m_l3Demux = new L3Demux();
|
||||
m_ipv4L4Demux = new Ipv4L4Demux();
|
||||
// add an ipv4 protocol handler.
|
||||
Ipv4 ipv4;
|
||||
m_l3Demux->Insert (ipv4);
|
||||
m_l3Demux = new L3Demux(this);
|
||||
m_ipv4L4Demux = new Ipv4L4Demux(this);
|
||||
m_udp = new Udp (this);
|
||||
m_ipv4 = new Ipv4 (this);
|
||||
m_l3Demux->Insert (Ipv4L3Protocol (this));
|
||||
// add a udp protocol handler.
|
||||
Udp udp = Udp (this);
|
||||
m_ipv4L4Demux->Insert (udp);
|
||||
}
|
||||
|
||||
InternetNode::InternetNode(const InternetNode& rhs)
|
||||
{ // Copy constructor
|
||||
// Note we do not copy the contents of the process list or
|
||||
// the interfaces list, as these are added later.
|
||||
m_netDevices = new NetDeviceList();
|
||||
// Make a copy of each capability
|
||||
m_l3Demux = rhs.GetL3Demux()->Copy();
|
||||
m_ipv4L4Demux = rhs.GetIpv4L4Demux()->Copy();
|
||||
//m_ipv4L4Demux->Insert (udp);
|
||||
}
|
||||
|
||||
// Copy this node
|
||||
InternetNode*
|
||||
InternetNode::Copy() const
|
||||
{
|
||||
return new InternetNode(*this);
|
||||
//return new InternetNode(*this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,12 +41,16 @@ public:
|
||||
virtual NetDeviceList* GetNetDevices() const;
|
||||
virtual L3Demux* GetL3Demux() const;
|
||||
virtual Ipv4L4Demux* GetIpv4L4Demux() const;
|
||||
virtual Ipv4 * GetIpv4 (void) const;
|
||||
virtual Udp * GetUdp (void) const;
|
||||
|
||||
private:
|
||||
// Capabilities
|
||||
NetDeviceList* m_netDevices;
|
||||
L3Demux* m_l3Demux;
|
||||
Ipv4L4Demux* m_ipv4L4Demux;
|
||||
Ipv4 * m_ipv4;
|
||||
Udp * m_udp;
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -16,18 +16,41 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Author: George F. Riley<riley@ece.gatech.edu>
|
||||
// Author: George F. Riley <riley@ece.gatech.edu>
|
||||
//
|
||||
// Define the base class for all node capabilities.
|
||||
// George F. Riley, Georgia Tech, Fall 2006
|
||||
|
||||
#include "capability.h"
|
||||
// NS3 - Layer 3 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include "ipv4.h"
|
||||
#include "node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Capability::~Capability ()
|
||||
Ipv4L3Protocol::Ipv4L3Protocol (Node *node)
|
||||
: L3Protocol (0x0800, 4),
|
||||
m_node (node)
|
||||
{}
|
||||
Ipv4L3Protocol::~Ipv4L3Protocol ()
|
||||
{}
|
||||
|
||||
Ipv4L3Protocol *
|
||||
Ipv4L3Protocol::Copy (Node *node) const
|
||||
{
|
||||
Ipv4L3Protocol *copy = new Ipv4L3Protocol (node);
|
||||
return copy;
|
||||
}
|
||||
void
|
||||
Ipv4L3Protocol::Receive(Packet& p, NetDevice &device)
|
||||
{
|
||||
Ipv4 *ipv4 = m_node->GetIpv4 ();
|
||||
if (ipv4 != 0)
|
||||
{
|
||||
ipv4->Receive (p, device);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
|
||||
@@ -16,28 +16,32 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// Author: George F. Riley<riley@ece.gatech.edu>
|
||||
// Author: George F. Riley <riley@ece.gatech.edu>
|
||||
//
|
||||
// Define the base class for all node capabilities.
|
||||
// George F. Riley, Georgia Tech, Fall 2006
|
||||
|
||||
#ifndef CAPABILITY_H
|
||||
#define CAPABILITY_H
|
||||
// NS3 - Layer 3 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
// All capabilities must implement a copy method, to allow node subclasses
|
||||
// to have a pointer to any subclass of the capability and still copy
|
||||
// correctly.
|
||||
#ifndef IPV4_L3_PROTOCOL_H
|
||||
#define IPV4_L3_PROTOCOL_H
|
||||
|
||||
#include "l3-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
|
||||
class Capability
|
||||
class Ipv4L3Protocol : public L3Protocol
|
||||
{
|
||||
public:
|
||||
virtual ~Capability();
|
||||
virtual Capability* Copy() const = 0;
|
||||
Ipv4L3Protocol (Node *node);
|
||||
virtual ~Ipv4L3Protocol ();
|
||||
|
||||
virtual Ipv4L3Protocol *Copy (Node *node) const;
|
||||
virtual void Receive (Packet& p, NetDevice &device);
|
||||
private:
|
||||
Node *m_node;
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* IPV4_L3_PROTOCOL_H */
|
||||
@@ -27,27 +27,26 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Ipv4L4Demux::Ipv4L4Demux ()
|
||||
Ipv4L4Demux::Ipv4L4Demux (Node *node)
|
||||
: m_node (node)
|
||||
{}
|
||||
|
||||
Ipv4L4Demux::Ipv4L4Demux(Ipv4L4Demux const &o)
|
||||
{
|
||||
for (L4List_t::const_iterator i = o.m_protocols.begin(); i != o.m_protocols.end(); ++i)
|
||||
{
|
||||
Insert(*(*i));
|
||||
}
|
||||
}
|
||||
Ipv4L4Demux::~Ipv4L4Demux()
|
||||
{}
|
||||
Ipv4L4Demux*
|
||||
Ipv4L4Demux::Copy() const
|
||||
Ipv4L4Demux::Copy(Node *node) const
|
||||
{
|
||||
return new Ipv4L4Demux(*this);
|
||||
Ipv4L4Demux * copy = new Ipv4L4Demux(node);
|
||||
for (L4List_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
|
||||
{
|
||||
copy->Insert(*(*i));
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
Ipv4L4Protocol*
|
||||
Ipv4L4Demux::Insert(const Ipv4L4Protocol&protocol)
|
||||
{
|
||||
Ipv4L4Protocol* copy = protocol.Copy(); // Make a copy of the protocol
|
||||
Ipv4L4Protocol* copy = protocol.Copy(m_node); // Make a copy of the protocol
|
||||
m_protocols.push_back (copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@@ -31,19 +31,20 @@
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv4L4Protocol;
|
||||
class Node;
|
||||
|
||||
class Ipv4L4Demux {
|
||||
public:
|
||||
Ipv4L4Demux ();
|
||||
Ipv4L4Demux(Ipv4L4Demux const&o);
|
||||
Ipv4L4Demux (Node *node);
|
||||
virtual ~Ipv4L4Demux();
|
||||
virtual Ipv4L4Demux* Copy() const;
|
||||
Ipv4L4Demux* Copy(Node *node) const;
|
||||
Ipv4L4Protocol* Insert(const Ipv4L4Protocol&);
|
||||
Ipv4L4Protocol* Lookup(int protocolNumber);
|
||||
void Erase(Ipv4L4Protocol*);
|
||||
private:
|
||||
typedef std::list<Ipv4L4Protocol*> L4List_t;
|
||||
L4List_t m_protocols;
|
||||
Node *m_node;
|
||||
};
|
||||
|
||||
} //namespace ns3
|
||||
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
int GetProtocolNumber (void) const;
|
||||
int GetVersion() const;
|
||||
|
||||
virtual Ipv4L4Protocol* Copy() const = 0;
|
||||
virtual Ipv4L4Protocol* Copy(Node *node) const = 0;
|
||||
/**
|
||||
* Called from lower-level layers to send the packet up
|
||||
* in the stack.
|
||||
|
||||
@@ -35,23 +35,13 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Ipv4::Ipv4()
|
||||
: L3Protocol (0x0800, 4),
|
||||
m_nInterfaces (0),
|
||||
Ipv4::Ipv4(Node *node)
|
||||
: m_nInterfaces (0),
|
||||
m_defaultTtl (64),
|
||||
m_identification (0),
|
||||
m_defaultRoute (0)
|
||||
m_defaultRoute (0),
|
||||
m_node (node)
|
||||
{}
|
||||
Ipv4::Ipv4(Ipv4 const &o)
|
||||
: L3Protocol (o),
|
||||
m_nInterfaces (0),
|
||||
m_defaultTtl (o.m_defaultTtl),
|
||||
m_identification (o.m_identification),
|
||||
m_defaultRoute (0)
|
||||
{
|
||||
// We do not copy the list of interfaces or the routes
|
||||
// purposedly.
|
||||
}
|
||||
Ipv4::~Ipv4 ()
|
||||
{
|
||||
// XXX I am not sure we are really allowed to do this here.
|
||||
@@ -289,9 +279,11 @@ Ipv4::GetNInterfaces (void) const
|
||||
|
||||
|
||||
Ipv4*
|
||||
Ipv4::Copy() const
|
||||
Ipv4::Copy(Node *node) const
|
||||
{
|
||||
return new Ipv4 (*this);
|
||||
Ipv4 *ipv4 = new Ipv4 (node);
|
||||
ipv4->SetDefaultTtl (m_defaultTtl);
|
||||
return ipv4;
|
||||
}
|
||||
void
|
||||
Ipv4::Receive(Packet& packet, NetDevice &device)
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
#include "l3-protocol.h"
|
||||
#include "ipv4-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -41,10 +40,9 @@ class Node;
|
||||
/**
|
||||
* ::Send is always defined in subclasses.
|
||||
*/
|
||||
class Ipv4 : public L3Protocol {
|
||||
class Ipv4 {
|
||||
public:
|
||||
Ipv4();
|
||||
Ipv4(Ipv4 const &o);
|
||||
Ipv4(Node *node);
|
||||
virtual ~Ipv4 ();
|
||||
|
||||
void SetDefaultTtl (uint8_t ttl);
|
||||
@@ -89,7 +87,7 @@ public:
|
||||
uint32_t GetNInterfaces (void) const;
|
||||
|
||||
|
||||
virtual Ipv4* Copy() const;
|
||||
Ipv4* Copy(Node *node) const;
|
||||
/**
|
||||
* Lower layer calls this method after calling L3Demux::Lookup
|
||||
* The ARP subclass needs to know from which NetDevice this
|
||||
@@ -97,7 +95,7 @@ public:
|
||||
* - implement a per-NetDevice ARP cache
|
||||
* - send back arp replies on the right device
|
||||
*/
|
||||
virtual void Receive(Packet& p, NetDevice &device);
|
||||
void Receive(Packet& p, NetDevice &device);
|
||||
|
||||
void Send (Packet const &packet, Ipv4Address source,
|
||||
Ipv4Address destination, uint8_t protocol);
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
L3Demux::L3Demux (Node *node)
|
||||
: m_node (node)
|
||||
{}
|
||||
|
||||
L3Demux::~L3Demux()
|
||||
{ // Delete each protocol in the map
|
||||
for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
|
||||
@@ -33,23 +37,21 @@ L3Demux::~L3Demux()
|
||||
delete i->second;
|
||||
}
|
||||
}
|
||||
|
||||
L3Demux::L3Demux(const L3Demux& rhs)
|
||||
{ // Copy constructor, copy each protocol
|
||||
for (L3Map_t::const_iterator i = rhs.m_protocols.begin(); i != rhs.m_protocols.end(); ++i)
|
||||
{
|
||||
Insert(*i->second);
|
||||
}
|
||||
}
|
||||
|
||||
L3Demux* L3Demux::Copy() const
|
||||
{ // Return a copy of this protocol manager
|
||||
return new L3Demux(*this);
|
||||
L3Demux* L3Demux::Copy(Node *node) const
|
||||
{
|
||||
L3Demux *copy = new L3Demux (node);
|
||||
for (L3Map_t::const_iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
|
||||
{
|
||||
copy->Insert(*i->second);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
L3Protocol* L3Demux::Insert(const L3Protocol& l3p)
|
||||
{
|
||||
L3Protocol* l = l3p.Copy(); // Make a copy of the protocol
|
||||
L3Protocol* l = l3p.Copy(m_node); // Make a copy of the protocol
|
||||
m_protocols.insert(L3Map_t::value_type(l3p.GetProtocolNumber (), l));
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@
|
||||
namespace ns3 {
|
||||
|
||||
class L3Protocol;
|
||||
class Node;
|
||||
|
||||
class L3Demux
|
||||
{
|
||||
public:
|
||||
L3Demux() {};
|
||||
L3Demux(const L3Demux&);
|
||||
L3Demux(Node *node);
|
||||
virtual ~L3Demux();
|
||||
virtual L3Demux* Copy() const;
|
||||
L3Demux* Copy(Node *node) const;
|
||||
|
||||
// Insert a new protocol
|
||||
ns3::L3Protocol* Insert(const ns3::L3Protocol&);
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
private:
|
||||
typedef std::map<int, ns3::L3Protocol*> L3Map_t;
|
||||
|
||||
Node *m_node;
|
||||
L3Map_t m_protocols;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,10 +31,6 @@ L3Protocol::L3Protocol(int protocolNumber, int version)
|
||||
: m_protocolNumber (protocolNumber),
|
||||
m_version (version)
|
||||
{}
|
||||
L3Protocol::L3Protocol (L3Protocol const &o)
|
||||
: m_protocolNumber (o.m_protocolNumber),
|
||||
m_version (o.m_version)
|
||||
{}
|
||||
L3Protocol::~L3Protocol ()
|
||||
{}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace ns3 {
|
||||
|
||||
class Packet;
|
||||
class NetDevice;
|
||||
class Node;
|
||||
|
||||
|
||||
/**
|
||||
@@ -37,13 +38,12 @@ class NetDevice;
|
||||
class L3Protocol {
|
||||
public:
|
||||
L3Protocol(int protocolNumber, int version);
|
||||
L3Protocol (L3Protocol const &o);
|
||||
virtual ~L3Protocol ();
|
||||
|
||||
int GetProtocolNumber (void) const;
|
||||
int GetVersion() const;
|
||||
|
||||
virtual L3Protocol* Copy() const = 0;
|
||||
virtual L3Protocol* Copy(Node *node) const = 0;
|
||||
/**
|
||||
* Lower layer calls this method after calling L3Demux::Lookup
|
||||
* The ARP subclass needs to know from which NetDevice this
|
||||
|
||||
@@ -25,19 +25,17 @@
|
||||
#define NET_DEVICE_LIST_H
|
||||
|
||||
#include <vector>
|
||||
#include "capability.h"
|
||||
|
||||
namespace ns3{
|
||||
|
||||
class NetDevice;
|
||||
|
||||
class NetDeviceList : public Capability {
|
||||
class NetDeviceList {
|
||||
public:
|
||||
typedef std::vector<NetDevice *>::iterator Iterator;
|
||||
|
||||
NetDeviceList();
|
||||
~NetDeviceList();
|
||||
NetDeviceList* Copy() const;
|
||||
// Manage the list
|
||||
NetDevice* Add(const NetDevice&); // Add a new netdevice
|
||||
NetDeviceList::Iterator Begin () const;
|
||||
|
||||
@@ -62,5 +62,17 @@ Node::GetNetDeviceList() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ipv4 *
|
||||
Node::GetIpv4 (void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Udp *
|
||||
Node::GetUdp (void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -96,6 +96,8 @@ namespace ns3 {
|
||||
class L3Demux;
|
||||
class Ipv4L4Demux;
|
||||
class NetDeviceList;
|
||||
class Ipv4;
|
||||
class Udp;
|
||||
|
||||
class Node {
|
||||
public:
|
||||
@@ -118,6 +120,8 @@ public:
|
||||
virtual L3Demux* GetL3Demux() const;
|
||||
virtual Ipv4L4Demux* GetIpv4L4Demux() const;
|
||||
virtual NetDeviceList* GetNetDeviceList() const;
|
||||
virtual Ipv4 * GetIpv4 (void) const;
|
||||
virtual Udp * GetUdp (void) const;
|
||||
|
||||
private:
|
||||
Id_t m_id; // Node id for this node
|
||||
|
||||
58
src/node/udp-ipv4-l4-protocol.cc
Normal file
58
src/node/udp-ipv4-l4-protocol.cc
Normal file
@@ -0,0 +1,58 @@
|
||||
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
|
||||
//
|
||||
// Copyright (c) 2006 Georgia Tech Research Corporation
|
||||
// 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: George F. Riley<riley@ece.gatech.edu>
|
||||
//
|
||||
|
||||
// NS3 - Layer 4 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
#include "udp-ipv4-l4-protocol.h"
|
||||
#include "node.h"
|
||||
#include "udp.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/* see http://www.iana.org/assignments/protocol-numbers */
|
||||
const uint8_t UdpIpv4L4Protocol::UDP_PROTOCOL = 17;
|
||||
|
||||
|
||||
UdpIpv4L4Protocol::UdpIpv4L4Protocol(Node *node)
|
||||
: Ipv4L4Protocol (UDP_PROTOCOL, 2),
|
||||
m_node (node)
|
||||
{}
|
||||
UdpIpv4L4Protocol::~UdpIpv4L4Protocol ()
|
||||
{}
|
||||
|
||||
UdpIpv4L4Protocol*
|
||||
UdpIpv4L4Protocol::Copy(Node *node) const
|
||||
{
|
||||
return new UdpIpv4L4Protocol (node);
|
||||
}
|
||||
void
|
||||
UdpIpv4L4Protocol::Receive(Packet& p,
|
||||
Ipv4Address const &source,
|
||||
Ipv4Address const &destination)
|
||||
{
|
||||
if (m_node->GetUdp () != 0)
|
||||
{
|
||||
m_node->GetUdp ()->Receive (p, source, destination);
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
58
src/node/udp-ipv4-l4-protocol.h
Normal file
58
src/node/udp-ipv4-l4-protocol.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*-
|
||||
//
|
||||
// Copyright (c) 2006 Georgia Tech Research Corporation
|
||||
// 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: George F. Riley<riley@ece.gatech.edu>
|
||||
//
|
||||
|
||||
// NS3 - Layer 4 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
#ifndef UDP_IPV4_L4_PROTOCOL_H
|
||||
#define UDP_IPV4_L4_PROTOCOL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "ipv4-l4-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class Packet;
|
||||
class Ipv4Address;
|
||||
|
||||
class UdpIpv4L4Protocol : Ipv4L4Protocol {
|
||||
public:
|
||||
UdpIpv4L4Protocol(Node *node);
|
||||
virtual ~UdpIpv4L4Protocol ();
|
||||
|
||||
virtual UdpIpv4L4Protocol* Copy(Node *node) const;
|
||||
/**
|
||||
* Called from lower-level layers to send the packet up
|
||||
* in the stack.
|
||||
*/
|
||||
virtual void Receive(Packet& p,
|
||||
Ipv4Address const &source,
|
||||
Ipv4Address const &destination);
|
||||
|
||||
private:
|
||||
Node *m_node;
|
||||
static const uint8_t UDP_PROTOCOL;
|
||||
};
|
||||
|
||||
} // Namespace ns3
|
||||
|
||||
#endif /* UDP_IPV4_L4_PROTOCOL */
|
||||
@@ -161,12 +161,7 @@ UdpSocket::ForwardUp (Packet &p, Ipv4Address saddr, uint16_t sport)
|
||||
Udp *
|
||||
UdpSocket::GetUdp (void) const
|
||||
{
|
||||
if (m_node->GetIpv4L4Demux () != 0)
|
||||
{
|
||||
// udp protocol number
|
||||
return static_cast<Udp *> (m_node->GetIpv4L4Demux ()->Lookup (17));
|
||||
}
|
||||
return 0;
|
||||
return m_node->GetUdp ();
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -36,17 +36,9 @@ namespace ns3 {
|
||||
const uint8_t Udp::UDP_PROTOCOL = 17;
|
||||
|
||||
Udp::Udp (Node *node)
|
||||
: Ipv4L4Protocol (UDP_PROTOCOL, 2),
|
||||
m_node (node),
|
||||
: m_node (node),
|
||||
m_endPoints (new Ipv4EndPointDemux<UdpEndPoint> ())
|
||||
{}
|
||||
Udp::Udp (Udp const &o)
|
||||
: Ipv4L4Protocol (UDP_PROTOCOL, 2),
|
||||
m_node (o.m_node),
|
||||
m_endPoints (new Ipv4EndPointDemux<UdpEndPoint> ())
|
||||
{
|
||||
// we do not copy the udp endpoints on purpose.
|
||||
}
|
||||
|
||||
Udp::~Udp ()
|
||||
{
|
||||
@@ -82,9 +74,9 @@ Udp::Allocate (Ipv4Address localAddress, uint16_t localPort,
|
||||
}
|
||||
|
||||
Udp*
|
||||
Udp::Copy() const
|
||||
Udp::Copy(Node *node) const
|
||||
{
|
||||
return new Udp (*this);
|
||||
return new Udp (node);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -121,14 +113,10 @@ Udp::Send (Packet packet,
|
||||
|
||||
packet.Add (udpHeader);
|
||||
|
||||
// Send to ipv4 layer.
|
||||
if (m_node->GetL3Demux () != 0 )
|
||||
Ipv4 *ipv4 = m_node->GetIpv4 ();
|
||||
if (ipv4 != 0)
|
||||
{
|
||||
Ipv4 *ipv4 = static_cast<Ipv4 *> (m_node->GetL3Demux ()->Lookup (0x0800));
|
||||
if (ipv4 != 0)
|
||||
{
|
||||
ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL);
|
||||
}
|
||||
ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ipv4-address.h"
|
||||
#include "ipv4-l4-protocol.h"
|
||||
#include "ipv4-end-point-demux.h"
|
||||
#include "udp-end-point.h"
|
||||
|
||||
@@ -34,10 +33,9 @@ namespace ns3 {
|
||||
|
||||
class Node;
|
||||
|
||||
class Udp : public Ipv4L4Protocol {
|
||||
class Udp {
|
||||
public:
|
||||
Udp (Node *node);
|
||||
Udp (Udp const &o);
|
||||
virtual ~Udp ();
|
||||
|
||||
UdpEndPoint *Allocate (void);
|
||||
@@ -52,10 +50,10 @@ public:
|
||||
Ipv4Address saddr, Ipv4Address daddr,
|
||||
uint16_t sport, uint16_t dport);
|
||||
// inherited from Ipv4L4Protocol
|
||||
virtual Udp* Copy() const;
|
||||
virtual void Receive(Packet& p,
|
||||
Ipv4Address const &source,
|
||||
Ipv4Address const &destination);
|
||||
Udp* Copy(Node *node) const;
|
||||
void Receive(Packet& p,
|
||||
Ipv4Address const &source,
|
||||
Ipv4Address const &destination);
|
||||
private:
|
||||
static const uint8_t UDP_PROTOCOL;
|
||||
Node *m_node;
|
||||
|
||||
Reference in New Issue
Block a user