merge tom's tree with trunk
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/simulator.h"
|
||||
@@ -26,17 +26,6 @@
|
||||
#include "arp-cache.h"
|
||||
#include "arp-header.h"
|
||||
|
||||
#ifdef TRACE_ARP
|
||||
#include <iostream>
|
||||
#include "simulator.h"
|
||||
# define TRACE(x) \
|
||||
std::cout << "ARP TRACE " << Simulator::Now () << " " \
|
||||
<< x << std::endl;
|
||||
#else /* TRACE_ARP */
|
||||
# define TRACE(format,...)
|
||||
#endif /* TRACE_ARP */
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
ArpCache::ArpCache (NetDevice *device, Ipv4Interface *interface)
|
||||
@@ -153,14 +142,14 @@ void
|
||||
ArpCache::Entry::MarkDead (void)
|
||||
{
|
||||
m_state = DEAD;
|
||||
//assert (m_waiting != 0);
|
||||
//NS_ASSERT (m_waiting != 0);
|
||||
UpdateSeen ();
|
||||
}
|
||||
Packet
|
||||
ArpCache::Entry::MarkAlive (MacAddress macAddress)
|
||||
{
|
||||
assert (m_state == WAIT_REPLY);
|
||||
//assert (m_waiting != 0);
|
||||
NS_ASSERT (m_state == WAIT_REPLY);
|
||||
//NS_ASSERT (m_waiting != 0);
|
||||
m_macAddress = macAddress;
|
||||
m_state = ALIVE;
|
||||
UpdateSeen ();
|
||||
@@ -172,7 +161,7 @@ ArpCache::Entry::MarkAlive (MacAddress macAddress)
|
||||
Packet
|
||||
ArpCache::Entry::UpdateWaitReply (Packet waiting)
|
||||
{
|
||||
assert (m_state == WAIT_REPLY);
|
||||
NS_ASSERT (m_state == WAIT_REPLY);
|
||||
/* We are already waiting for an answer so
|
||||
* we dump the previously waiting packet and
|
||||
* replace it with this one.
|
||||
@@ -184,8 +173,8 @@ ArpCache::Entry::UpdateWaitReply (Packet waiting)
|
||||
void
|
||||
ArpCache::Entry::MarkWaitReply (Packet waiting)
|
||||
{
|
||||
assert (m_state == ALIVE || m_state == DEAD);
|
||||
//assert (m_waiting == 0);
|
||||
NS_ASSERT (m_state == ALIVE || m_state == DEAD);
|
||||
//NS_ASSERT (m_waiting == 0);
|
||||
m_state = WAIT_REPLY;
|
||||
m_waiting = waiting;
|
||||
UpdateSeen ();
|
||||
@@ -194,7 +183,7 @@ ArpCache::Entry::MarkWaitReply (Packet waiting)
|
||||
MacAddress
|
||||
ArpCache::Entry::GetMacAddress (void)
|
||||
{
|
||||
assert (m_state == ALIVE);
|
||||
NS_ASSERT (m_state == ALIVE);
|
||||
return m_macAddress;
|
||||
}
|
||||
bool
|
||||
@@ -212,7 +201,7 @@ ArpCache::Entry::IsExpired (void)
|
||||
timeout = m_arp->GetAliveTimeout ();
|
||||
break;
|
||||
default:
|
||||
assert (false);
|
||||
NS_ASSERT (false);
|
||||
timeout = Seconds (0);
|
||||
/* NOTREACHED */
|
||||
break;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
#include "arp-header.h"
|
||||
#include "header-utils.h"
|
||||
|
||||
@@ -96,7 +96,7 @@ ArpHeader::PrintTo (std::ostream &os) const
|
||||
}
|
||||
else
|
||||
{
|
||||
assert (IsReply ());
|
||||
NS_ASSERT (IsReply ());
|
||||
os << " source mac: " << m_macSource
|
||||
<< " source ipv4: " << m_ipv4Source
|
||||
<< " dest mac: " << m_macDest
|
||||
@@ -114,7 +114,7 @@ void
|
||||
ArpHeader::SerializeTo (Buffer::Iterator start) const
|
||||
{
|
||||
Buffer::Iterator i = start;
|
||||
assert (m_macSource.GetLength () == m_macDest.GetLength ());
|
||||
NS_ASSERT (m_macSource.GetLength () == m_macDest.GetLength ());
|
||||
|
||||
/* ethernet */
|
||||
i.WriteHtonU16 (0x0001);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "arp.h"
|
||||
#include "node.h"
|
||||
#include "net-device.h"
|
||||
#include "ipv4.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -45,7 +46,7 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
|
||||
bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination);
|
||||
if (found)
|
||||
{
|
||||
GetDevice ()->Send (p, hardwareDestination, 0x0800 /* XXX */);
|
||||
GetDevice ()->Send (p, hardwareDestination, Ipv4::PROT_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
// -*- 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 3 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
#include "arp-l3-protocol.h"
|
||||
#include "arp.h"
|
||||
#include "node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
ArpL3Protocol::ArpL3Protocol (Node *node)
|
||||
: L3Protocol (0x0806, 0/* XXX: correct version number ? */ ),
|
||||
m_node (node)
|
||||
{}
|
||||
ArpL3Protocol::~ArpL3Protocol ()
|
||||
{}
|
||||
|
||||
ArpL3Protocol *
|
||||
ArpL3Protocol::Copy (Node *node) const
|
||||
{
|
||||
return new ArpL3Protocol (node);
|
||||
}
|
||||
void
|
||||
ArpL3Protocol::Receive(Packet& p, NetDevice &device)
|
||||
{
|
||||
Arp * arp = m_node->GetArp ();
|
||||
if (arp != 0)
|
||||
{
|
||||
arp->Receive (p, &device);
|
||||
}
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
@@ -1,49 +0,0 @@
|
||||
// -*- 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 3 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
#ifndef ARP_L3_PROTOCOL_H
|
||||
#define ARP_L3_PROTOCOL_H
|
||||
|
||||
#include "l3-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
class NetDevice;
|
||||
class Packet;
|
||||
|
||||
class ArpL3Protocol : public L3Protocol
|
||||
{
|
||||
public:
|
||||
ArpL3Protocol (Node *node);
|
||||
virtual ~ArpL3Protocol ();
|
||||
|
||||
virtual ArpL3Protocol *Copy (Node *node) const;
|
||||
virtual void Receive(Packet& p, NetDevice &device);
|
||||
private:
|
||||
Node *m_node;
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
#endif /* ARP_L3_PROTOCOL_H */
|
||||
@@ -19,6 +19,7 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/debug.h"
|
||||
#include "arp.h"
|
||||
#include "arp-header.h"
|
||||
#include "arp-cache.h"
|
||||
@@ -27,12 +28,15 @@
|
||||
#include "node.h"
|
||||
#include "ipv4.h"
|
||||
|
||||
#define TRACE(x)
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Arp");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const uint16_t Arp::PROT_NUMBER = 0x0806;
|
||||
|
||||
Arp::Arp (Node *node)
|
||||
: m_node (node)
|
||||
: L3Protocol (PROT_NUMBER, 0/* XXX: correct version number ? */ ),
|
||||
m_node (node)
|
||||
{}
|
||||
|
||||
Arp::~Arp ()
|
||||
@@ -44,7 +48,7 @@ Arp::~Arp ()
|
||||
}
|
||||
|
||||
Arp *
|
||||
Arp::Copy (Node *node)
|
||||
Arp::Copy (Node *node) const
|
||||
{
|
||||
return new Arp (node);
|
||||
}
|
||||
@@ -61,29 +65,29 @@ Arp::FindCache (NetDevice *device)
|
||||
}
|
||||
Ipv4Interface *interface = m_node->GetIpv4 ()->FindInterfaceForDevice (device);
|
||||
ArpCache * cache = new ArpCache (device, interface);
|
||||
assert (device->IsBroadcast ());
|
||||
NS_ASSERT (device->IsBroadcast ());
|
||||
device->SetLinkChangeCallback (MakeCallback (&ArpCache::Flush, cache));
|
||||
m_cacheList.push_back (cache);
|
||||
return cache;
|
||||
}
|
||||
|
||||
void
|
||||
Arp::Receive(Packet& packet, NetDevice *device)
|
||||
Arp::Receive(Packet& packet, NetDevice &device)
|
||||
{
|
||||
ArpCache *cache = FindCache (device);
|
||||
ArpCache *cache = FindCache (&device);
|
||||
ArpHeader arp;
|
||||
packet.Peek (arp);
|
||||
packet.Remove (arp);
|
||||
if (arp.IsRequest () &&
|
||||
arp.GetDestinationIpv4Address () == cache->GetInterface ()->GetAddress ())
|
||||
{
|
||||
TRACE ("got request from " << arp.GetSourceIpv4Address () << " -- send reply");
|
||||
NS_DEBUG ("got request from " << arp.GetSourceIpv4Address () << " -- send reply");
|
||||
SendArpReply (cache, arp.GetSourceIpv4Address (),
|
||||
arp.GetSourceHardwareAddress ());
|
||||
}
|
||||
else if (arp.IsReply () &&
|
||||
arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) &&
|
||||
arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ()))
|
||||
arp.GetDestinationHardwareAddress ().IsEqual (device.GetAddress ()))
|
||||
{
|
||||
Ipv4Address from = arp.GetSourceIpv4Address ();
|
||||
ArpCache::Entry *entry = cache->Lookup (from);
|
||||
@@ -91,7 +95,7 @@ Arp::Receive(Packet& packet, NetDevice *device)
|
||||
{
|
||||
if (entry->IsWaitReply ())
|
||||
{
|
||||
TRACE ("got reply from " << arp.GetSourceIpv4Address ()
|
||||
NS_DEBUG ("got reply from " << arp.GetSourceIpv4Address ()
|
||||
<< " for waiting entry -- flush");
|
||||
MacAddress from_mac = arp.GetSourceHardwareAddress ();
|
||||
Packet waiting = entry->MarkAlive (from_mac);
|
||||
@@ -101,14 +105,14 @@ Arp::Receive(Packet& packet, NetDevice *device)
|
||||
{
|
||||
// ignore this reply which might well be an attempt
|
||||
// at poisening my arp cache.
|
||||
TRACE ("got reply from " << arp.GetSourceIpv4Address () <<
|
||||
NS_DEBUG ("got reply from " << arp.GetSourceIpv4Address () <<
|
||||
" for non-waiting entry -- drop");
|
||||
// XXX report packet as dropped.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACE ("got reply for unknown entry -- drop");
|
||||
NS_DEBUG ("got reply for unknown entry -- drop");
|
||||
// XXX report packet as dropped.
|
||||
}
|
||||
}
|
||||
@@ -126,19 +130,19 @@ Arp::Lookup (Packet &packet, Ipv4Address destination,
|
||||
{
|
||||
if (entry->IsDead ())
|
||||
{
|
||||
TRACE ("dead entry for " << destination << " expired -- send arp request");
|
||||
NS_DEBUG ("dead entry for " << destination << " expired -- send arp request");
|
||||
entry->MarkWaitReply (packet);
|
||||
SendArpRequest (cache, destination);
|
||||
}
|
||||
else if (entry->IsAlive ())
|
||||
{
|
||||
TRACE ("alive entry for " << destination << " expired -- send arp request");
|
||||
NS_DEBUG ("alive entry for " << destination << " expired -- send arp request");
|
||||
entry->MarkWaitReply (packet);
|
||||
SendArpRequest (cache, destination);
|
||||
}
|
||||
else if (entry->IsWaitReply ())
|
||||
{
|
||||
TRACE ("wait reply for " << destination << " expired -- drop");
|
||||
NS_DEBUG ("wait reply for " << destination << " expired -- drop");
|
||||
entry->MarkDead ();
|
||||
// XXX report packet as 'dropped'
|
||||
}
|
||||
@@ -147,18 +151,18 @@ Arp::Lookup (Packet &packet, Ipv4Address destination,
|
||||
{
|
||||
if (entry->IsDead ())
|
||||
{
|
||||
TRACE ("dead entry for " << destination << " valid -- drop");
|
||||
NS_DEBUG ("dead entry for " << destination << " valid -- drop");
|
||||
// XXX report packet as 'dropped'
|
||||
}
|
||||
else if (entry->IsAlive ())
|
||||
{
|
||||
TRACE ("alive entry for " << destination << " valid -- send");
|
||||
NS_DEBUG ("alive entry for " << destination << " valid -- send");
|
||||
*hardwareDestination = entry->GetMacAddress ();
|
||||
return true;
|
||||
}
|
||||
else if (entry->IsWaitReply ())
|
||||
{
|
||||
TRACE ("wait reply for " << destination << " valid -- drop previous");
|
||||
NS_DEBUG ("wait reply for " << destination << " valid -- drop previous");
|
||||
Packet old = entry->UpdateWaitReply (packet);
|
||||
// XXX report 'old' packet as 'dropped'
|
||||
}
|
||||
@@ -168,7 +172,7 @@ Arp::Lookup (Packet &packet, Ipv4Address destination,
|
||||
else
|
||||
{
|
||||
// This is our first attempt to transmit data to this destination.
|
||||
TRACE ("no entry for " << destination << " -- send arp request");
|
||||
NS_DEBUG ("no entry for " << destination << " -- send arp request");
|
||||
entry = cache->Add (destination);
|
||||
entry->MarkWaitReply (packet);
|
||||
SendArpRequest (cache, destination);
|
||||
@@ -187,7 +191,7 @@ Arp::SendArpRequest (ArpCache const *cache, Ipv4Address to)
|
||||
to);
|
||||
Packet packet;
|
||||
packet.Add (arp);
|
||||
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), 0x0806);
|
||||
cache->GetDevice ()->Send (packet, cache->GetDevice ()->GetBroadcast (), PROT_NUMBER);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -199,7 +203,7 @@ Arp::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac)
|
||||
toMac, toIp);
|
||||
Packet packet;
|
||||
packet.Add (arp);
|
||||
cache->GetDevice ()->Send (packet, toMac, 0x0806);
|
||||
cache->GetDevice ()->Send (packet, toMac, PROT_NUMBER);
|
||||
}
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <list>
|
||||
#include "ipv4-address.h"
|
||||
#include "mac-address.h"
|
||||
#include "l3-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -32,14 +33,16 @@ class NetDevice;
|
||||
class Node;
|
||||
class Packet;
|
||||
|
||||
class Arp
|
||||
class Arp : public L3Protocol
|
||||
{
|
||||
public:
|
||||
static const uint16_t PROT_NUMBER;
|
||||
|
||||
Arp (Node *node);
|
||||
~Arp ();
|
||||
Arp *Copy (Node *node);
|
||||
virtual Arp *Copy (Node *node) const;
|
||||
|
||||
void Receive(Packet& p, NetDevice *device);
|
||||
virtual void Receive(Packet& p, NetDevice &device);
|
||||
bool Lookup (Packet &p, Ipv4Address destination,
|
||||
NetDevice *device,
|
||||
MacAddress *hardwareDestination);
|
||||
|
||||
@@ -20,17 +20,15 @@
|
||||
#include "ns3/debug.h"
|
||||
#include "drop-tail.h"
|
||||
|
||||
namespace ns3 {
|
||||
NS_DEBUG_COMPONENT_DEFINE ("DropTailQueue");
|
||||
|
||||
namespace {
|
||||
int dtqDebug = 1;
|
||||
}
|
||||
namespace ns3 {
|
||||
|
||||
DropTailQueue::DropTailQueue () :
|
||||
m_packets (),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DropTailQueue ()")
|
||||
}
|
||||
|
||||
@@ -38,7 +36,7 @@ DropTailQueue::DropTailQueue (TraceContainer &traceContainer) :
|
||||
m_packets(),
|
||||
m_maxPackets(DTQ_NPACKETS_MAX_DEFAULT)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DropTailQueue (" << &traceContainer << ")")
|
||||
|
||||
RegisterTraces(traceContainer);
|
||||
@@ -46,14 +44,14 @@ DropTailQueue::DropTailQueue (TraceContainer &traceContainer) :
|
||||
|
||||
DropTailQueue::~DropTailQueue ()
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::~DropTailQueue ()")
|
||||
}
|
||||
|
||||
void
|
||||
DropTailQueue::SetMaxPackets (uint32_t npackets)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::SetMaxPackets (" << npackets << ")")
|
||||
|
||||
m_maxPackets = npackets;
|
||||
@@ -62,7 +60,7 @@ DropTailQueue::SetMaxPackets (uint32_t npackets)
|
||||
uint32_t
|
||||
DropTailQueue::GetMaxPackets (void)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::GetMaxPackets () <= " << m_maxPackets)
|
||||
|
||||
return m_maxPackets;
|
||||
@@ -71,12 +69,12 @@ DropTailQueue::GetMaxPackets (void)
|
||||
bool
|
||||
DropTailQueue::DoEnque (const Packet& p)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DoEnque (" << &p << ")")
|
||||
|
||||
if (m_nPackets >= m_maxPackets)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DoEnque (): Queue full -- droppping pkt")
|
||||
Drop (p);
|
||||
return false;
|
||||
@@ -89,12 +87,12 @@ DropTailQueue::DoEnque (const Packet& p)
|
||||
bool
|
||||
DropTailQueue::DoDeque (Packet& p)
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DoDeque (" << &p << ")")
|
||||
|
||||
if (m_packets.empty())
|
||||
{
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DoDeque (): Queue empty")
|
||||
return false;
|
||||
}
|
||||
@@ -102,7 +100,7 @@ DropTailQueue::DoDeque (Packet& p)
|
||||
p = m_packets.front ();
|
||||
m_packets.pop ();
|
||||
|
||||
NS3_TRACE(dtqDebug,
|
||||
NS_DEBUG(
|
||||
"DropTailQueue::DoDeque (): Popped " << &p << " <= true")
|
||||
|
||||
return true;
|
||||
|
||||
@@ -23,14 +23,11 @@
|
||||
|
||||
#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"
|
||||
#include "ipv4.h"
|
||||
#include "arp.h"
|
||||
#include "udp-ipv4-l4-protocol.h"
|
||||
#include "arp-l3-protocol.h"
|
||||
#include "ipv4-loopback-interface.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -41,12 +38,9 @@ InternetNode::InternetNode()
|
||||
m_netDevices = new NetDeviceList();
|
||||
m_l3Demux = new L3Demux(this);
|
||||
m_ipv4L4Demux = new Ipv4L4Demux(this);
|
||||
m_udp = new Udp (this);
|
||||
m_ipv4 = new Ipv4 (this);
|
||||
m_arp = new Arp (this);
|
||||
m_l3Demux->Insert (Ipv4L3Protocol (this));
|
||||
m_l3Demux->Insert (ArpL3Protocol (this));
|
||||
m_ipv4L4Demux->Insert (UdpIpv4L4Protocol (this));
|
||||
m_l3Demux->Insert (Ipv4 (this));
|
||||
m_l3Demux->Insert (Arp (this));
|
||||
m_ipv4L4Demux->Insert (Udp (this));
|
||||
SetupLoopback ();
|
||||
}
|
||||
|
||||
@@ -55,9 +49,6 @@ InternetNode::InternetNode (InternetNode const &o)
|
||||
m_netDevices = new NetDeviceList ();
|
||||
m_l3Demux = o.m_l3Demux->Copy (this);
|
||||
m_ipv4L4Demux = o.m_ipv4L4Demux->Copy (this);
|
||||
m_udp = o.m_udp->Copy (this);
|
||||
m_ipv4 = o.m_ipv4->Copy (this);
|
||||
m_arp = o.m_arp->Copy (this);
|
||||
SetupLoopback ();
|
||||
}
|
||||
|
||||
@@ -66,9 +57,6 @@ InternetNode::~InternetNode ()
|
||||
delete m_netDevices;
|
||||
delete m_l3Demux;
|
||||
delete m_ipv4L4Demux;
|
||||
delete m_udp;
|
||||
delete m_ipv4;
|
||||
delete m_arp;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -77,8 +65,8 @@ InternetNode::SetupLoopback (void)
|
||||
Ipv4LoopbackInterface * interface = new Ipv4LoopbackInterface (this);
|
||||
interface->SetAddress (Ipv4Address::GetLoopback ());
|
||||
interface->SetNetworkMask (Ipv4Mask::GetLoopback ());
|
||||
uint32_t index = m_ipv4->AddInterface (interface);
|
||||
m_ipv4->AddHostRouteTo (Ipv4Address::GetLoopback (), index);
|
||||
uint32_t index = GetIpv4 ()->AddInterface (interface);
|
||||
GetIpv4 ()->AddHostRouteTo (Ipv4Address::GetLoopback (), index);
|
||||
interface->SetUp ();
|
||||
}
|
||||
|
||||
@@ -112,18 +100,18 @@ InternetNode::GetIpv4L4Demux() const
|
||||
Ipv4 *
|
||||
InternetNode::GetIpv4 (void) const
|
||||
{
|
||||
return m_ipv4;
|
||||
return static_cast<Ipv4*> (m_l3Demux->Lookup (Ipv4::PROT_NUMBER));
|
||||
}
|
||||
Udp *
|
||||
InternetNode::GetUdp (void) const
|
||||
{
|
||||
return m_udp;
|
||||
return static_cast<Udp*> (m_ipv4L4Demux->Lookup (Udp::PROT_NUMBER));
|
||||
}
|
||||
|
||||
Arp *
|
||||
InternetNode::GetArp (void) const
|
||||
{
|
||||
return m_arp;
|
||||
return static_cast<Arp*> (m_l3Demux->Lookup (Arp::PROT_NUMBER));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -52,9 +52,6 @@ private:
|
||||
NetDeviceList* m_netDevices;
|
||||
L3Demux* m_l3Demux;
|
||||
Ipv4L4Demux* m_ipv4L4Demux;
|
||||
Ipv4 * m_ipv4;
|
||||
Udp * m_udp;
|
||||
Arp * m_arp;
|
||||
};
|
||||
|
||||
}//namespace ns3
|
||||
|
||||
@@ -19,20 +19,12 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/debug.h"
|
||||
#include "ns3/header.h"
|
||||
#include "ipv4-header.h"
|
||||
|
||||
#define TRACE_CHUNK_IPV4 1
|
||||
|
||||
#ifdef TRACE_CHUNK_IPV4
|
||||
#include <iostream>
|
||||
#include "ns3/simulator.h"
|
||||
# define TRACE(x) \
|
||||
std::cout << "CHUNK IPV4 TRACE " << Simulator::Now () << " " << x << std::endl;
|
||||
#else /* TRACE_CHUNK_IPV4 */
|
||||
# define TRACE(format,...)
|
||||
#endif /* TRACE_CHUNK_IPV4 */
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Ipv4Header");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -137,13 +129,13 @@ Ipv4Header::IsDontFragment (void) const
|
||||
void
|
||||
Ipv4Header::SetFragmentOffset (uint16_t offset)
|
||||
{
|
||||
assert (!(offset & (~0x3fff)));
|
||||
NS_ASSERT (!(offset & (~0x3fff)));
|
||||
m_fragmentOffset = offset;
|
||||
}
|
||||
uint16_t
|
||||
Ipv4Header::GetFragmentOffset (void) const
|
||||
{
|
||||
assert (!(m_fragmentOffset & (~0x3fff)));
|
||||
NS_ASSERT (!(m_fragmentOffset & (~0x3fff)));
|
||||
return m_fragmentOffset;
|
||||
}
|
||||
|
||||
@@ -225,7 +217,6 @@ Ipv4Header::SerializeTo (Buffer::Iterator start) const
|
||||
{
|
||||
Buffer::Iterator i = start;
|
||||
|
||||
//TRACE ("init ipv4 current="<<buffer->GetCurrent ());
|
||||
uint8_t verIhl = (4 << 4) | (5);
|
||||
i.WriteU8 (verIhl);
|
||||
i.WriteU8 (m_tos);
|
||||
@@ -255,10 +246,9 @@ Ipv4Header::SerializeTo (Buffer::Iterator start) const
|
||||
#if 0
|
||||
// XXX we need to add Buffer::Iterator::PeekData method
|
||||
uint8_t *data = start.PeekData ();
|
||||
//TRACE ("fini ipv4 current="<<state->GetCurrent ());
|
||||
uint16_t checksum = UtilsChecksumCalculate (0, data, GetSize ());
|
||||
checksum = UtilsChecksumComplete (checksum);
|
||||
//TRACE ("checksum=" <<checksum);
|
||||
NS_DEBUG ("checksum=" <<checksum);
|
||||
i = start;
|
||||
i.Next (10);
|
||||
i.WriteU16 (checksum);
|
||||
@@ -272,7 +262,7 @@ Ipv4Header::DeserializeFrom (Buffer::Iterator start)
|
||||
uint8_t verIhl = i.ReadU8 ();
|
||||
uint8_t ihl = verIhl & 0x0f;
|
||||
uint16_t headerSize = ihl * 4;
|
||||
assert ((verIhl >> 4) == 4);
|
||||
NS_ASSERT ((verIhl >> 4) == 4);
|
||||
m_tos = i.ReadU8 ();
|
||||
uint16_t size = i.ReadNtohU16 ();
|
||||
m_payloadSize = size - headerSize;
|
||||
@@ -301,7 +291,6 @@ Ipv4Header::DeserializeFrom (Buffer::Iterator start)
|
||||
{
|
||||
#if 0
|
||||
uint8_t *data = start.PeekData ();
|
||||
//TRACE ("fini ipv4 current="<<state->GetCurrent ());
|
||||
uint16_t localChecksum = UtilsChecksumCalculate (0, data, headerSize);
|
||||
if (localChecksum == 0xffff)
|
||||
{
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
// -*- 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 3 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
#include "ipv4-l3-protocol.h"
|
||||
#include "ipv4.h"
|
||||
#include "node.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
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
|
||||
@@ -1,47 +0,0 @@
|
||||
// -*- 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 3 Protocol base class
|
||||
// George F. Riley, Georgia Tech, Spring 2007
|
||||
|
||||
#ifndef IPV4_L3_PROTOCOL_H
|
||||
#define IPV4_L3_PROTOCOL_H
|
||||
|
||||
#include "l3-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Ipv4L3Protocol : public L3Protocol
|
||||
{
|
||||
public:
|
||||
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 /* IPV4_L3_PROTOCOL_H */
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "ipv4-route.h"
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -180,7 +180,7 @@ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route)
|
||||
{
|
||||
if (route.IsDefault ())
|
||||
{
|
||||
assert (route.IsGateway ());
|
||||
NS_ASSERT (route.IsGateway ());
|
||||
os << "default out=" << route.GetInterface () << ", next hop=" << route.GetGateway ();
|
||||
}
|
||||
else if (route.IsHost ())
|
||||
@@ -215,7 +215,7 @@ std::ostream& operator<< (std::ostream& os, Ipv4Route const& route)
|
||||
}
|
||||
else
|
||||
{
|
||||
assert (false);
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
//
|
||||
|
||||
#include "ns3/packet.h"
|
||||
#include "ns3/debug.h"
|
||||
|
||||
#include "ipv4.h"
|
||||
#include "ipv4-l4-protocol.h"
|
||||
@@ -31,12 +32,15 @@
|
||||
#include "node.h"
|
||||
#include "ipv4-l4-demux.h"
|
||||
|
||||
#define TRACE(x)
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Ipv4");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
const uint16_t Ipv4::PROT_NUMBER = 0x0800;
|
||||
|
||||
Ipv4::Ipv4(Node *node)
|
||||
: m_nInterfaces (0),
|
||||
: L3Protocol (PROT_NUMBER, 4),
|
||||
m_nInterfaces (0),
|
||||
m_defaultTtl (64),
|
||||
m_identification (0),
|
||||
m_defaultRoute (0),
|
||||
@@ -129,7 +133,7 @@ Ipv4::Lookup (Ipv4Address dest)
|
||||
i != m_hostRoutes.end ();
|
||||
i++)
|
||||
{
|
||||
assert ((*i)->IsHost ());
|
||||
NS_ASSERT ((*i)->IsHost ());
|
||||
if ((*i)->GetDest ().IsEqual (dest))
|
||||
{
|
||||
return (*i);
|
||||
@@ -139,7 +143,7 @@ Ipv4::Lookup (Ipv4Address dest)
|
||||
j != m_networkRoutes.end ();
|
||||
j++)
|
||||
{
|
||||
assert ((*j)->IsNetwork ());
|
||||
NS_ASSERT ((*j)->IsNetwork ());
|
||||
Ipv4Mask mask = (*j)->GetDestNetworkMask ();
|
||||
Ipv4Address entry = (*j)->GetDestNetwork ();
|
||||
if (mask.IsMatch (dest, entry))
|
||||
@@ -149,7 +153,7 @@ Ipv4::Lookup (Ipv4Address dest)
|
||||
}
|
||||
if (m_defaultRoute != 0)
|
||||
{
|
||||
assert (m_defaultRoute->IsDefault ());
|
||||
NS_ASSERT (m_defaultRoute->IsDefault ());
|
||||
return m_defaultRoute;
|
||||
}
|
||||
return 0;
|
||||
@@ -204,7 +208,7 @@ Ipv4::GetRoute (uint32_t index)
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
assert (false);
|
||||
NS_ASSERT (false);
|
||||
// quiet compiler.
|
||||
return 0;
|
||||
}
|
||||
@@ -250,7 +254,7 @@ Ipv4::RemoveRoute (uint32_t index)
|
||||
}
|
||||
tmp++;
|
||||
}
|
||||
assert (false);
|
||||
NS_ASSERT (false);
|
||||
}
|
||||
|
||||
|
||||
@@ -352,7 +356,7 @@ Ipv4::Send (Packet const &packet,
|
||||
Ipv4Route *route = Lookup (ipHeader.GetDestination ());
|
||||
if (route == 0)
|
||||
{
|
||||
TRACE ("not for me -- forwarding but no route to host. drop.");
|
||||
NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -365,7 +369,7 @@ Ipv4::SendRealOut (Packet const &p, Ipv4Header const &ip, Ipv4Route const &route
|
||||
Packet packet = p;
|
||||
packet.Add (ip);
|
||||
Ipv4Interface *outInterface = GetInterface (route.GetInterface ());
|
||||
assert (packet.GetSize () <= outInterface->GetMtu ());
|
||||
NS_ASSERT (packet.GetSize () <= outInterface->GetMtu ());
|
||||
// XXX log trace here.
|
||||
if (route.IsGateway ())
|
||||
{
|
||||
@@ -386,7 +390,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device)
|
||||
{
|
||||
if ((*i)->GetAddress ().IsEqual (ipHeader.GetDestination ()))
|
||||
{
|
||||
TRACE ("for me 1");
|
||||
NS_DEBUG ("for me 1");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -399,7 +403,7 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device)
|
||||
{
|
||||
if (ipHeader.GetDestination ().IsEqual (interface->GetBroadcast ()))
|
||||
{
|
||||
TRACE ("for me 2");
|
||||
NS_DEBUG ("for me 2");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -408,29 +412,29 @@ Ipv4::Forwarding (Packet const &packet, Ipv4Header &ipHeader, NetDevice &device)
|
||||
|
||||
if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetBroadcast ()))
|
||||
{
|
||||
TRACE ("for me 3");
|
||||
NS_DEBUG ("for me 3");
|
||||
return false;
|
||||
}
|
||||
if (ipHeader.GetDestination ().IsEqual (Ipv4Address::GetAny ()))
|
||||
{
|
||||
TRACE ("for me 4");
|
||||
NS_DEBUG ("for me 4");
|
||||
return false;
|
||||
}
|
||||
if (ipHeader.GetTtl () == 1)
|
||||
{
|
||||
// Should send ttl expired here
|
||||
// XXX
|
||||
TRACE ("not for me -- ttl expired. drop.");
|
||||
NS_DEBUG ("not for me -- ttl expired. drop.");
|
||||
return true;
|
||||
}
|
||||
ipHeader.SetTtl (ipHeader.GetTtl () - 1);
|
||||
Ipv4Route *route = Lookup (ipHeader.GetDestination ());
|
||||
if (route == 0)
|
||||
{
|
||||
TRACE ("not for me -- forwarding but no route to host. drop.");
|
||||
NS_DEBUG ("not for me -- forwarding but no route to host. drop.");
|
||||
return true;
|
||||
}
|
||||
TRACE ("not for me -- forwarding.");
|
||||
NS_DEBUG ("not for me -- forwarding.");
|
||||
SendRealOut (packet, ipHeader, *route);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
#include "ipv4-address.h"
|
||||
#include "l3-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -40,8 +41,11 @@ class Node;
|
||||
/**
|
||||
* ::Send is always defined in subclasses.
|
||||
*/
|
||||
class Ipv4 {
|
||||
class Ipv4 : public L3Protocol
|
||||
{
|
||||
public:
|
||||
static const uint16_t PROT_NUMBER;
|
||||
|
||||
Ipv4(Node *node);
|
||||
virtual ~Ipv4 ();
|
||||
|
||||
@@ -88,7 +92,7 @@ public:
|
||||
Ipv4Interface *FindInterfaceForDevice (NetDevice const*device);
|
||||
|
||||
|
||||
Ipv4* Copy(Node *node) const;
|
||||
virtual Ipv4* Copy(Node *node) const;
|
||||
/**
|
||||
* Lower layer calls this method after calling L3Demux::Lookup
|
||||
* The ARP subclass needs to know from which NetDevice this
|
||||
@@ -96,7 +100,7 @@ public:
|
||||
* - implement a per-NetDevice ARP cache
|
||||
* - send back arp replies on the right device
|
||||
*/
|
||||
void Receive(Packet& p, NetDevice &device);
|
||||
virtual void Receive(Packet& p, NetDevice &device);
|
||||
|
||||
void Send (Packet const &packet, Ipv4Address source,
|
||||
Ipv4Address destination, uint8_t protocol);
|
||||
|
||||
@@ -19,22 +19,10 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
|
||||
#include "llc-snap-header.h"
|
||||
|
||||
#define noTRACE_LLC_SNAP_HEADER 1
|
||||
|
||||
#ifdef TRACE_LLC_SNAP_HEADER
|
||||
#include <iostream>
|
||||
#include "ns3/simulator.h"
|
||||
# define TRACE(x) \
|
||||
std::cout << "LLCSNAP HEAD TRACE " << Simulator::Now () << " " << x << std::endl;
|
||||
#else /* TRACE_LLC_SNAP_HEADER */
|
||||
# define TRACE(format,...)
|
||||
#endif /* TRACE_LLC_SNAP_HEADER */
|
||||
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
LlcSnapHeader::LlcSnapHeader ()
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
#include "mac-address.h"
|
||||
|
||||
#define ASCII_a (0x41)
|
||||
@@ -56,7 +56,7 @@ MacAddress::MacAddress () : m_len(0)
|
||||
|
||||
MacAddress::MacAddress (uint8_t const *address, uint8_t len)
|
||||
{
|
||||
assert(len <= MacAddress::MAX_LEN);
|
||||
NS_ASSERT (len <= MacAddress::MAX_LEN);
|
||||
for (int i=0; i < len; i++)
|
||||
{
|
||||
m_address[i] = address[i];
|
||||
@@ -164,7 +164,7 @@ bool operator < (MacAddress const&a, MacAddress const&b)
|
||||
uint8_t b_p[MacAddress::MAX_LEN];
|
||||
a.Peek (a_p);
|
||||
b.Peek (b_p);
|
||||
assert(a.GetLength() == b.GetLength());
|
||||
NS_ASSERT (a.GetLength() == b.GetLength());
|
||||
for (uint8_t i = 0; i < a.GetLength(); i++)
|
||||
{
|
||||
if (a_p[i] < b_p[i])
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
|
||||
#include "net-device.h"
|
||||
#include "l3-demux.h"
|
||||
@@ -93,7 +93,7 @@ NetDevice::IsBroadcast (void) const
|
||||
MacAddress const &
|
||||
NetDevice::GetBroadcast (void) const
|
||||
{
|
||||
assert (m_isBroadcast);
|
||||
NS_ASSERT (m_isBroadcast);
|
||||
return m_broadcast;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,9 @@
|
||||
#include "ns3/debug.h"
|
||||
#include "queue.h"
|
||||
|
||||
namespace ns3 {
|
||||
NS_DEBUG_COMPONENT_DEFINE ("Queue");
|
||||
|
||||
namespace {
|
||||
int qDebug = 1;
|
||||
}
|
||||
namespace ns3 {
|
||||
|
||||
Queue::Queue() :
|
||||
m_nBytes(0),
|
||||
@@ -34,20 +32,20 @@ Queue::Queue() :
|
||||
m_nTotalDroppedBytes(0),
|
||||
m_nTotalDroppedPackets(0)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Queue ()")
|
||||
NS_DEBUG("Queue::Queue ()")
|
||||
}
|
||||
|
||||
Queue::~Queue()
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::~Queue ()")
|
||||
NS_DEBUG("Queue::~Queue ()")
|
||||
}
|
||||
|
||||
bool
|
||||
Queue::Enque (const Packet& p)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Enque (" << &p << ")")
|
||||
NS_DEBUG("Queue::Enque (" << &p << ")")
|
||||
|
||||
NS3_TRACE(qDebug, "Queue::Enque (): m_traceEnque (p)")
|
||||
NS_DEBUG("Queue::Enque (): m_traceEnque (p)")
|
||||
m_traceEnque ("+ <timestamp> ", p);
|
||||
|
||||
bool retval = DoEnque (p);
|
||||
@@ -62,7 +60,7 @@ Queue::Enque (const Packet& p)
|
||||
bool
|
||||
Queue::Deque (Packet &p)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Deque (" << &p << ")")
|
||||
NS_DEBUG("Queue::Deque (" << &p << ")")
|
||||
|
||||
bool retval = DoDeque (p);
|
||||
|
||||
@@ -71,10 +69,10 @@ Queue::Deque (Packet &p)
|
||||
m_nBytes -= p.GetSize ();
|
||||
m_nPackets--;
|
||||
|
||||
assert(m_nBytes >= 0);
|
||||
assert(m_nPackets >= 0);
|
||||
NS_ASSERT (m_nBytes >= 0);
|
||||
NS_ASSERT (m_nPackets >= 0);
|
||||
|
||||
NS3_TRACE(qDebug, "Queue::Deque (): m_traceDeque (p)")
|
||||
NS_DEBUG("Queue::Deque (): m_traceDeque (p)")
|
||||
m_traceDeque ("+ <timestamp> ", static_cast<const Packet &>(p));
|
||||
}
|
||||
|
||||
@@ -84,15 +82,15 @@ Queue::Deque (Packet &p)
|
||||
void
|
||||
Queue::DequeAll (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::DequeAll ()")
|
||||
NS_DEBUG("Queue::DequeAll ()")
|
||||
|
||||
assert (!"Don't know what to do with dequeued packets!");
|
||||
NS_ASSERT (!"Don't know what to do with dequeued packets!");
|
||||
}
|
||||
|
||||
uint32_t
|
||||
Queue::GetNPackets (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::GetNPackets () <= " << m_nPackets)
|
||||
NS_DEBUG("Queue::GetNPackets () <= " << m_nPackets)
|
||||
|
||||
return m_nPackets;
|
||||
}
|
||||
@@ -100,7 +98,7 @@ Queue::GetNPackets (void)
|
||||
uint32_t
|
||||
Queue::GetNBytes (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::GetNBytes () <= " << m_nBytes)
|
||||
NS_DEBUG("Queue::GetNBytes () <= " << m_nBytes)
|
||||
|
||||
return m_nBytes;
|
||||
}
|
||||
@@ -109,14 +107,14 @@ Queue::GetNBytes (void)
|
||||
bool
|
||||
Queue::IsEmpty (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::IsEmpty () <= " << (m_nPackets == 0))
|
||||
NS_DEBUG("Queue::IsEmpty () <= " << (m_nPackets == 0))
|
||||
return m_nPackets == 0;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::RegisterTraces (TraceContainer &container)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::RegisterTraces (" << &container << ")")
|
||||
NS_DEBUG("Queue::RegisterTraces (" << &container << ")")
|
||||
|
||||
container.RegisterCallback ("Queue::Enque", &m_traceEnque);
|
||||
container.RegisterCallback ("Queue::Deque", &m_traceDeque);
|
||||
@@ -126,7 +124,7 @@ Queue::RegisterTraces (TraceContainer &container)
|
||||
uint32_t
|
||||
Queue::GetTotalReceivedBytes (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
NS_DEBUG(
|
||||
"Queue::GetTotalReceivedBytes () <= " << m_nTotalReceivedBytes)
|
||||
|
||||
return m_nTotalReceivedBytes;
|
||||
@@ -135,7 +133,7 @@ Queue::GetTotalReceivedBytes (void)
|
||||
uint32_t
|
||||
Queue::GetTotalReceivedPackets (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
NS_DEBUG(
|
||||
"Queue::GetTotalReceivedPackets () <= " << m_nTotalReceivedPackets)
|
||||
|
||||
return m_nTotalReceivedPackets;
|
||||
@@ -144,7 +142,7 @@ Queue::GetTotalReceivedPackets (void)
|
||||
uint32_t
|
||||
Queue:: GetTotalDroppedBytes (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
NS_DEBUG(
|
||||
"Queue::GetTotalDroppedBytes () <= " << m_nTotalDroppedBytes
|
||||
)
|
||||
return m_nTotalDroppedBytes;
|
||||
@@ -153,7 +151,7 @@ Queue:: GetTotalDroppedBytes (void)
|
||||
uint32_t
|
||||
Queue::GetTotalDroppedPackets (void)
|
||||
{
|
||||
NS3_TRACE(qDebug,
|
||||
NS_DEBUG(
|
||||
"Queue::GetTotalDroppedPackets () <= " << m_nTotalDroppedPackets)
|
||||
|
||||
return m_nTotalDroppedPackets;
|
||||
@@ -162,7 +160,7 @@ Queue::GetTotalDroppedPackets (void)
|
||||
void
|
||||
Queue::ResetStatistics (void)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::ResetStatistics ()")
|
||||
NS_DEBUG("Queue::ResetStatistics ()")
|
||||
|
||||
m_nTotalReceivedBytes = 0;
|
||||
m_nTotalReceivedPackets = 0;
|
||||
@@ -173,12 +171,12 @@ Queue::ResetStatistics (void)
|
||||
void
|
||||
Queue::Drop (const Packet& p)
|
||||
{
|
||||
NS3_TRACE(qDebug, "Queue::Drop (" << &p << ")")
|
||||
NS_DEBUG("Queue::Drop (" << &p << ")")
|
||||
|
||||
m_nTotalDroppedPackets++;
|
||||
m_nTotalDroppedBytes += p.GetSize ();
|
||||
|
||||
NS3_TRACE(qDebug, "Queue::Drop (): m_traceDrop (p)")
|
||||
NS_DEBUG("Queue::Drop (): m_traceDrop (p)")
|
||||
m_traceEnque ("d <timestamp> ", p);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// -*- 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
|
||||
@@ -1,58 +0,0 @@
|
||||
// -*- 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 : public 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 */
|
||||
@@ -30,7 +30,7 @@ UdpSocket::UdpSocket (Node *node)
|
||||
: m_endPoint (0),
|
||||
m_node (node)
|
||||
{
|
||||
assert (GetUdp () != 0);
|
||||
NS_ASSERT (GetUdp () != 0);
|
||||
}
|
||||
UdpSocket::~UdpSocket ()
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/packet.h"
|
||||
#include "udp.h"
|
||||
#include "udp-header.h"
|
||||
@@ -33,10 +33,11 @@
|
||||
namespace ns3 {
|
||||
|
||||
/* see http://www.iana.org/assignments/protocol-numbers */
|
||||
const uint8_t Udp::UDP_PROTOCOL = 17;
|
||||
const uint8_t Udp::PROT_NUMBER = 17;
|
||||
|
||||
Udp::Udp (Node *node)
|
||||
: m_node (node),
|
||||
: Ipv4L4Protocol (PROT_NUMBER, 2),
|
||||
m_node (node),
|
||||
m_endPoints (new Ipv4EndPointDemux<UdpEndPoint> ())
|
||||
{}
|
||||
|
||||
@@ -95,7 +96,7 @@ Udp::Receive(Packet& packet,
|
||||
}
|
||||
UdpSocket *socket = endPoint->GetSocket ();
|
||||
socket->ForwardUp (packet, source, udpHeader.GetSource ());
|
||||
assert (socket != 0);
|
||||
NS_ASSERT (socket != 0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -109,14 +110,14 @@ Udp::Send (Packet packet,
|
||||
udpHeader.SetPayloadSize (packet.GetSize ());
|
||||
udpHeader.InitializeChecksum (saddr,
|
||||
daddr,
|
||||
UDP_PROTOCOL);
|
||||
PROT_NUMBER);
|
||||
|
||||
packet.Add (udpHeader);
|
||||
|
||||
Ipv4 *ipv4 = m_node->GetIpv4 ();
|
||||
if (ipv4 != 0)
|
||||
{
|
||||
ipv4->Send (packet, saddr, daddr, UDP_PROTOCOL);
|
||||
ipv4->Send (packet, saddr, daddr, PROT_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,16 @@
|
||||
#include "ipv4-address.h"
|
||||
#include "ipv4-end-point-demux.h"
|
||||
#include "udp-end-point.h"
|
||||
#include "ipv4-l4-protocol.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Node;
|
||||
|
||||
class Udp {
|
||||
class Udp : public Ipv4L4Protocol {
|
||||
public:
|
||||
static const uint8_t PROT_NUMBER;
|
||||
|
||||
Udp (Node *node);
|
||||
virtual ~Udp ();
|
||||
|
||||
@@ -50,12 +53,11 @@ public:
|
||||
Ipv4Address saddr, Ipv4Address daddr,
|
||||
uint16_t sport, uint16_t dport);
|
||||
// inherited from Ipv4L4Protocol
|
||||
Udp* Copy(Node *node) const;
|
||||
void Receive(Packet& p,
|
||||
Ipv4Address const &source,
|
||||
Ipv4Address const &destination);
|
||||
virtual Udp* Copy(Node *node) const;
|
||||
virtual void Receive(Packet& p,
|
||||
Ipv4Address const &source,
|
||||
Ipv4Address const &destination);
|
||||
private:
|
||||
static const uint8_t UDP_PROTOCOL;
|
||||
Node *m_node;
|
||||
Ipv4EndPointDemux<UdpEndPoint> *m_endPoints;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user