merge with trunk

This commit is contained in:
Craig Dowell
2007-09-10 15:50:07 -07:00
45 changed files with 675 additions and 165 deletions

View File

@@ -7,5 +7,3 @@ build
doc/html.*
doc/latex.*
.lock-wscript
.waf*
waf

159
examples/csma-broadcast.cc Normal file
View File

@@ -0,0 +1,159 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* 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
*/
//
// Example of the sending of a datagram to a broadcast address
//
// Network topology
// ==============
// | |
// n0 n1 n2
// | |
// ==========
//
// n0 originates UDP broadcast to 255.255.255.255, which is replicated
// and received on both n1 and n2
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/command-line.h"
#include "ns3/default-value.h"
#include "ns3/ptr.h"
#include "ns3/random-variable.h"
#include "ns3/debug.h"
#include "ns3/simulator.h"
#include "ns3/nstime.h"
#include "ns3/data-rate.h"
#include "ns3/ascii-trace.h"
#include "ns3/pcap-trace.h"
#include "ns3/internet-node.h"
#include "ns3/csma-channel.h"
#include "ns3/csma-net-device.h"
#include "ns3/csma-topology.h"
#include "ns3/csma-ipv4-topology.h"
#include "ns3/eui48-address.h"
#include "ns3/ipv4-address.h"
#include "ns3/inet-socket-address.h"
#include "ns3/ipv4.h"
#include "ns3/socket.h"
#include "ns3/ipv4-route.h"
#include "ns3/onoff-application.h"
using namespace ns3;
int main (int argc, char *argv[])
{
// Users may find it convenient to turn on explicit debugging
// for selected modules; the below lines suggest how to do this
#if 0
DebugComponentEnable("CsmaNetDevice");
DebugComponentEnable("Ipv4L3Protocol");
DebugComponentEnable("NetDevice");
DebugComponentEnable("Channel");
DebugComponentEnable("CsmaChannel");
DebugComponentEnable("PacketSocket");
#endif
// Set up some default values for the simulation. Use the Bind()
// technique to tell the system what subclass of Queue to use,
// and what the queue limit is
// The below Bind command tells the queue factory which class to
// instantiate, when the queue factory is invoked in the topology code
DefaultValue::Bind ("Queue", "DropTailQueue");
// Allow the user to override any of the defaults and the above
// Bind()s at run-time, via command-line arguments
CommandLine::Parse (argc, argv);
// Here, we will explicitly create four nodes. In more sophisticated
// topologies, we could configure a node factory.
Ptr<Node> n0 = Create<InternetNode> ();
Ptr<Node> n1 = Create<InternetNode> ();
Ptr<Node> n2 = Create<InternetNode> ();
// We create the channels first without any IP addressing information
Ptr<CsmaChannel> channel0 =
CsmaTopology::CreateCsmaChannel(
DataRate(5000000), MilliSeconds(2));
// We create the channels first without any IP addressing information
Ptr<CsmaChannel> channel1 =
CsmaTopology::CreateCsmaChannel(
DataRate(5000000), MilliSeconds(2));
uint32_t n0ifIndex0 = CsmaIpv4Topology::AddIpv4CsmaNode (n0, channel0,
Eui48Address("10:54:23:54:0:50"));
uint32_t n0ifIndex1 = CsmaIpv4Topology::AddIpv4CsmaNode (n0, channel1,
Eui48Address("10:54:23:54:0:51"));
uint32_t n1ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n1, channel0,
Eui48Address("10:54:23:54:23:51"));
uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channel1,
Eui48Address("10:54:23:54:23:52"));
// Later, we add IP addresses.
CsmaIpv4Topology::AddIpv4Address (
n0, n0ifIndex0, Ipv4Address("10.1.0.1"), Ipv4Mask("255.255.0.0"));
CsmaIpv4Topology::AddIpv4Address (
n1, n1ifIndex, Ipv4Address("10.1.0.2"), Ipv4Mask("255.255.0.0"));
CsmaIpv4Topology::AddIpv4Address (
n0, n0ifIndex1, Ipv4Address("192.168.1.1"), Ipv4Mask("255.255.255.0"));
CsmaIpv4Topology::AddIpv4Address (
n2, n2ifIndex, Ipv4Address("192.168.1.2"), Ipv4Mask("255.255.255.0"));
// Create the OnOff application to send UDP datagrams of size
// 210 bytes at a rate of 448 Kb/s
// from n0 to n1
Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
n0,
InetSocketAddress ("255.255.255.255", 80),
"Udp",
ConstantVariable(1),
ConstantVariable(0));
// Start the application
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the csma-broadcast.tr file
AsciiTrace asciitrace ("csma-broadcast.tr");
asciitrace.TraceAllNetDeviceRx ();
asciitrace.TraceAllQueues ();
// Also configure some tcpdump traces; each interface will be traced
// The output files will be named
// simple-point-to-point.pcap-<nodeId>-<interfaceId>
// and can be read by the "tcpdump -r" command (use "-tt" option to
// display timestamps correctly)
PcapTrace pcaptrace ("csma-broadcast.pcap");
pcaptrace.TraceAllIp ();
Simulator::Run ();
Simulator::Destroy ();
}

View File

@@ -65,6 +65,7 @@
#include "ns3/ipv4-route.h"
#include "ns3/point-to-point-topology.h"
#include "ns3/onoff-application.h"
#include "ns3/packet-sink.h"
#include "ns3/global-route-manager.h"
using namespace ns3;
@@ -151,6 +152,17 @@ int main (int argc, char *argv[])
ooff->Start (Seconds (1.0));
ooff->Stop (Seconds (10.0));
// Create a packet sink to receive these packets
// The last argument "true" disables output from the Receive callback
Ptr<PacketSink> sink = Create<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), 80),
"Udp",
true);
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = Create<OnOffApplication> (
n3,
@@ -162,6 +174,16 @@ int main (int argc, char *argv[])
ooff->Start (Seconds (1.1));
ooff->Stop (Seconds (10.0));
// Create a packet sink to receive these packets
sink = Create<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), 80),
"Udp",
true);
// Start the sink
sink->Start (Seconds (1.1));
sink->Stop (Seconds (10.0));
// Configure tracing of all enqueue, dequeue, and NetDevice receive events
// Trace output will be sent to the simple-global-routing.tr file
AsciiTrace asciitrace ("simple-global-routing.tr");

View File

@@ -60,6 +60,7 @@
#include "ns3/ipv4-route.h"
#include "ns3/point-to-point-topology.h"
#include "ns3/onoff-application.h"
#include "ns3/packet-sink.h"
using namespace ns3;
@@ -180,6 +181,15 @@ main (int argc, char *argv[])
ooff->Start(Seconds(1.0));
ooff->Stop (Seconds(10.0));
// Create an optional packet sink to receive these packets
Ptr<PacketSink> sink = Create<PacketSink> (
n3,
InetSocketAddress (Ipv4Address::GetAny (), 80),
"Udp");
// Start the sink
sink->Start (Seconds (1.0));
sink->Stop (Seconds (10.0));
// Create a similar flow from n3 to n1, starting at time 1.1 seconds
ooff = Create<OnOffApplication> (
n3,
@@ -191,6 +201,16 @@ main (int argc, char *argv[])
ooff->Start(Seconds(1.1));
ooff->Stop (Seconds(10.0));
// Create a packet sink to receive these packets
sink = Create<PacketSink> (
n1,
InetSocketAddress (Ipv4Address::GetAny (), 80),
"Udp");
// Start the sink
sink->Start (Seconds (1.1));
sink->Stop (Seconds (10.0));
sink->SetQuiet (); // disable output from the Receive callback
// Here, finish off packet routing configuration
// This will likely set by some global StaticRouting object in the future
NS_DEBUG("Set Default Routes.");

1
examples/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../waf "$@"

View File

@@ -14,6 +14,10 @@ def build(bld):
['csma', 'internet-node'])
obj.source = 'csma-one-subnet.cc'
obj = bld.create_ns3_program('csma-broadcast',
['csma', 'internet-node'])
obj.source = 'csma-broadcast.cc'
obj = bld.create_ns3_program('csma-packet-socket',
['csma', 'internet-node'])
obj.source = 'csma-packet-socket.cc'

1
samples/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../waf "$@"

View File

@@ -0,0 +1,116 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
//
// Copyright (c) 2006 Georgia Tech Research Corporation
//
// 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
//
#include "ns3/address.h"
#include "ns3/debug.h"
#include "ns3/inet-socket-address.h"
#include "ns3/node.h"
#include "ns3/socket.h"
#include "ns3/simulator.h"
#include "ns3/socket-factory.h"
#include "ns3/packet.h"
#include "packet-sink.h"
using namespace std;
namespace ns3 {
// Constructors
PacketSink::PacketSink (Ptr<Node> n,
const Address &local,
std::string iid,
bool quiet)
: Application(n)
{
Construct (n, local, iid, quiet);
}
void
PacketSink::Construct (Ptr<Node> n,
const Address &local,
std::string iid,
bool quiet)
{
m_socket = 0;
m_local = local;
m_iid = iid;
m_quiet = quiet;
}
PacketSink::~PacketSink()
{}
void
PacketSink::SetQuiet()
{
m_quiet = true;
}
void
PacketSink::DoDispose (void)
{
m_socket = 0;
// chain up
Application::DoDispose ();
}
// Application Methods
void PacketSink::StartApplication() // Called at time specified by Start
{
// Create the socket if not already
if (!m_socket)
{
InterfaceId iid = InterfaceId::LookupByName (m_iid);
Ptr<SocketFactory> socketFactory =
GetNode ()->QueryInterface<SocketFactory> (iid);
m_socket = socketFactory->CreateSocket ();
m_socket->Bind (m_local);
}
m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
const Address &>) MakeCallback(&PacketSink::Receive, this));
}
void PacketSink::StopApplication() // Called at time specified by Stop
{
if (!m_socket)
{
m_socket->SetRecvCallback((Callback<void, Ptr<Socket>, const Packet &,
const Address &>) NULL);
}
}
// This callback body suggested by Joe Kopena's wiki
void PacketSink::Receive(Ptr<Socket> socket, const Packet &packet,
const Address &from)
{
if (!m_quiet)
{
if (InetSocketAddress::IsMatchingType (from))
{
InetSocketAddress address = InetSocketAddress::ConvertFrom (from);
NS_DEBUG_UNCOND ( __PRETTY_FUNCTION__ << ": Received " <<
packet.GetSize() << " bytes from " << address.GetIpv4() << " ["
<< address << "]---'" << packet.PeekData() << "'");
}
}
}
} // Namespace ns3

View File

@@ -0,0 +1,88 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
//
// Copyright (c) 2006 Georgia Tech Research Corporation
//
// 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
//
//
#ifndef __packet_sink_h__
#define __packet_sink_h__
#include "ns3/application.h"
#include "ns3/event-id.h"
#include "ns3/ptr.h"
namespace ns3 {
class Address;
class Socket;
class Packet;
/**
* \brief Receive and consume traffic generated to an IP address and port
*
* This Application can be used as a receiver for packets generated by
* traffic sourcing applications such as OnOffApplication. The constructor
* specifies the Address (IP address and port) and the transport protocol
* to use. A virtual Receive () method is installed as a callback on
* the receiving socket. By default, it prints out the size of packets
* and their address.
*/
class PacketSink : public Application
{
public:
/**
* \param n node associated to this application
* \param local local ip address
* \param iid
* \param ontime on time random variable
* \param offtime off time random variable
*/
PacketSink (Ptr<Node> n,
const Address &local,
std::string iid, bool quiet=false);
virtual ~PacketSink ();
/**
* \brief Turn off the logging output for the receive callback
*/
void SetQuiet (void);
protected:
virtual void DoDispose (void);
private:
// inherited from Application base class.
virtual void StartApplication (void); // Called at time specified by Start
virtual void StopApplication (void); // Called at time specified by Stop
void Construct (Ptr<Node> n,
const Address &local,
std::string iid,
bool quiet);
virtual void Receive (Ptr<Socket> socket, const Packet& packet, const Address& from);
Ptr<Socket> m_socket; // Associated socket
Address m_local; // Local address to bind to
std::string m_iid; // Protocol name (e.g., "Udp")
bool m_quiet; // Governs whether receive callback is quiet
};
} // namespace ns3
#endif

1
src/applications/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

View File

@@ -4,9 +4,11 @@ def build(bld):
obj = bld.create_ns3_module('applications', ['node'])
obj.source = [
'onoff-application.cc',
'packet-sink.cc',
]
headers = bld.create_obj('ns3header')
headers.source = [
'onoff-application.h',
'packet-sink.h',
]

View File

@@ -69,7 +69,7 @@ public:
* to the same underlying buffer. Debug builds ensure
* this with an assert.
*/
inline int32_t GetDistanceFrom (Iterator const &o) const;
inline uint32_t GetDistanceFrom (Iterator const &o) const;
/**
* \return true if this iterator points to the end of the byte array.
@@ -502,13 +502,21 @@ Buffer::Iterator::Prev (uint32_t delta)
NS_ASSERT (m_current >= delta);
m_current -= delta;
}
int32_t
uint32_t
Buffer::Iterator::GetDistanceFrom (Iterator const &o) const
{
NS_ASSERT (m_data == o.m_data);
int32_t start = m_current;
int32_t end = o.m_current;
return end - start;
int32_t diff = end - start;
if (diff < 0)
{
return -diff;
}
else
{
return diff;
}
}
bool

View File

@@ -217,6 +217,7 @@ private:
template <int N>
void RegisterTrailer (void);
void CleanupPrints (void);
Packet DoAddHeader (Packet p);
bool Check (const char *file, int line, std::list<int> expected);
@@ -430,6 +431,14 @@ PacketMetadataTest::CheckHistory (Packet p, const char *file, int line, uint32_t
} \
}
Packet
PacketMetadataTest::DoAddHeader (Packet p)
{
ADD_HEADER (p, 10);
return p;
}
bool
PacketMetadataTest::RunTests (void)
{
@@ -659,6 +668,11 @@ PacketMetadataTest::RunTests (void)
ADD_HEADER (p, 10);
CHECK_HISTORY (p, 1, 10);
p = Packet ();
ADD_HEADER (p, 10);
p = DoAddHeader (p);
CHECK_HISTORY (p, 2, 10, 10);
return ok;
}

View File

@@ -306,24 +306,23 @@ PacketMetadata::PacketMetadata (PacketMetadata const &o)
PacketMetadata &
PacketMetadata::operator = (PacketMetadata const& o)
{
if (m_data == o.m_data)
if (m_data != o.m_data)
{
// self assignment
return *this;
// not self assignment
NS_ASSERT (m_data != 0);
m_data->m_count--;
if (m_data->m_count == 0)
{
PacketMetadata::Recycle (m_data);
}
m_data = o.m_data;
NS_ASSERT (m_data != 0);
m_data->m_count++;
}
NS_ASSERT (m_data != 0);
m_data->m_count--;
if (m_data->m_count == 0)
{
PacketMetadata::Recycle (m_data);
}
m_data = o.m_data;
m_head = o.m_head;
m_tail = o.m_tail;
m_used = o.m_used;
m_packetUid = o.m_packetUid;
NS_ASSERT (m_data != 0);
m_data->m_count++;
return *this;
}
PacketMetadata::~PacketMetadata ()

1
src/common/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

1
src/core/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

View File

@@ -452,8 +452,8 @@ private:
* @see class CallBackTraceSource
* @see class TraceResolver
*/
CallbackTraceSource<Packet &> m_rxTrace;
CallbackTraceSource<Packet &> m_dropTrace;
CallbackTraceSource<const Packet &> m_rxTrace;
CallbackTraceSource<const Packet &> m_dropTrace;
};

1
src/devices/csma/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../../waf "$@"

View File

@@ -290,7 +290,7 @@ private:
* @see class CallBackTraceSource
* @see class TraceResolver
*/
CallbackTraceSource<Packet &> m_rxTrace;
CallbackTraceSource<const Packet &> m_rxTrace;
/**
* Default data rate. Used for all newly created p2p net devices
*/

1
src/devices/point-to-point/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../../waf "$@"

View File

@@ -74,8 +74,9 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest)
m_node->QueryInterface<ArpL3Protocol> (ArpL3Protocol::iid);
Address hardwareDestination;
bool found;
if (dest.IsBroadcast ())
if (dest.IsBroadcast () ||
dest.IsSubnetDirectedBroadcast (GetNetworkMask ()) )
{
NS_DEBUG ("ArpIpv4Interface::SendTo (): IsBroadcast");
hardwareDestination = GetDevice ()->GetBroadcast ();

View File

@@ -92,7 +92,7 @@ AsciiTrace::LogDevQueueDrop (TraceContext const &context,
m_os << std::endl;
}
void
AsciiTrace::LogDevRx (TraceContext const &context, Packet &p)
AsciiTrace::LogDevRx (TraceContext const &context, const Packet &p)
{
m_os << "r " << Simulator::Now ().GetSeconds () << " ";
context.Print (m_os);

View File

@@ -40,7 +40,7 @@ private:
void LogDevQueueEnqueue (TraceContext const &context, const Packet &p);
void LogDevQueueDequeue (TraceContext const &context, const Packet &p);
void LogDevQueueDrop (TraceContext const &context, const Packet &p);
void LogDevRx (TraceContext const &context, Packet &p);
void LogDevRx (TraceContext const &context, const Packet &p);
std::ofstream m_os;
};

View File

@@ -43,7 +43,7 @@ Ipv4EndPoint::GetLocalAddress (void)
return m_localAddr;
}
void
void
Ipv4EndPoint::SetLocalAddress (Ipv4Address address)
{
m_localAddr = address;

View File

@@ -38,7 +38,6 @@ public:
Ipv4Address GetLocalAddress (void);
void SetLocalAddress (Ipv4Address address);
uint16_t GetLocalPort (void);
Ipv4Address GetPeerAddress (void);
uint16_t GetPeerPort (void);

View File

@@ -22,6 +22,8 @@
#include "ns3/debug.h"
#include "ns3/node.h"
#include "ns3/inet-socket-address.h"
#include "ns3/ipv4-route.h"
#include "ns3/ipv4.h"
#include "udp-socket.h"
#include "udp-l4-protocol.h"
#include "ipv4-end-point.h"
@@ -175,7 +177,7 @@ int
UdpSocket::Connect(const Address & address)
{
NS_DEBUG ("UdpSocket::Connect (" << address << ")");
Ipv4Route routeToDest;
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
m_defaultAddress = transport.GetIpv4 ();
m_defaultPort = transport.GetPort ();
@@ -183,11 +185,17 @@ UdpSocket::Connect(const Address & address)
m_connected = true;
NS_DEBUG ("UdpSocket::Connect (): Updating local address");
Ptr<Ipv4> ipv4;
ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
m_endPoint->SetLocalAddress (ipv4->GetSourceAddress(m_defaultAddress));
if (GetIpv4RouteToDestination (m_node, routeToDest, m_defaultAddress) )
{
uint32_t localIfIndex = routeToDest.GetInterface ();
Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
m_endPoint->SetLocalAddress (ipv4->GetAddress(localIfIndex) );
}
NS_DEBUG ("UdpSocket::Connect (): Local address is " <<
m_endPoint->GetLocalAddress());
return 0;
}
@@ -201,6 +209,27 @@ UdpSocket::Send (const Packet &p)
m_errno = ERROR_NOTCONN;
return -1;
}
return DoSend (p);
}
int
UdpSocket::DoSend (const Packet &p)
{
if (m_endPoint == 0)
{
if (Bind () == -1)
{
NS_ASSERT (m_endPoint == 0);
return -1;
}
NS_ASSERT (m_endPoint != 0);
}
if (m_shutdownSend)
{
m_errno = ERROR_SHUTDOWN;
return -1;
}
return DoSendTo (p, m_defaultAddress, m_defaultPort);
}
@@ -208,18 +237,29 @@ int
UdpSocket::DoSendTo (const Packet &p, const Address &address)
{
NS_DEBUG("UdpSocket::DoSendTo (" << &p << ", " << address << ")");
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
Ipv4Address ipv4 = transport.GetIpv4 ();
uint16_t port = transport.GetPort ();
return DoSendTo (p, ipv4, port);
if (!m_connected)
{
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
Ipv4Address ipv4 = transport.GetIpv4 ();
uint16_t port = transport.GetPort ();
return DoSendTo (p, ipv4, port);
}
else
{
// connected UDP socket must use default addresses
return DoSendTo (p, m_defaultAddress, m_defaultPort);
}
}
int
UdpSocket::DoSendTo (const Packet &p, Ipv4Address addr, uint16_t port)
UdpSocket::DoSendTo (const Packet &p, Ipv4Address dest, uint16_t port)
{
NS_DEBUG("UdpSocket::DoSendTo (" << &p << ", " << addr << ", " <<
port << ")");
Ipv4Route routeToDest;
if (m_endPoint == 0)
{
if (Bind () == -1)
@@ -234,18 +274,37 @@ UdpSocket::DoSendTo (const Packet &p, Ipv4Address addr, uint16_t port)
m_errno = ERROR_SHUTDOWN;
return -1;
}
//
// If dest is sent to the limited broadcast address (all ones),
// convert it to send a copy of the packet out of every interface
//
if (dest.IsBroadcast ())
{
Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++ )
{
Ipv4Address addri = ipv4->GetAddress (i);
Ipv4Mask maski = ipv4->GetNetworkMask (i);
m_udp->Send (p, addri, addri.GetSubnetDirectedBroadcast (maski),
m_endPoint->GetLocalPort (), port);
NotifyDataSent (p.GetSize ());
}
}
else if (GetIpv4RouteToDestination (m_node, routeToDest, dest) )
{
uint32_t localIfIndex = routeToDest.GetInterface ();
Ptr<Ipv4> ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
m_udp->Send (p, ipv4->GetAddress (localIfIndex), dest,
m_endPoint->GetLocalPort (), port);
NotifyDataSent (p.GetSize ());
return 0;
}
else
{
m_errno = ERROR_NOROUTETOHOST;
return -1;
}
NS_DEBUG ("UdpSocket::DoSendTo (): Finding source address");
Ptr<Ipv4> ipv4;
ipv4 = m_node->QueryInterface<Ipv4> (Ipv4::iid);
Ipv4Address source = ipv4->GetSourceAddress(m_defaultAddress);
NS_DEBUG ("UdpSocket::DoSendTo (): Source address is " << source);
NS_DEBUG("UdpSocket::DoSendTo (): Send to UDP");
m_udp->Send (p, source, addr, m_endPoint->GetLocalPort (), port);
NotifyDataSent (p.GetSize ());
return 0;
}
@@ -253,13 +312,6 @@ int
UdpSocket::SendTo(const Address &address, const Packet &p)
{
NS_DEBUG("UdpSocket::SendTo (" << address << ", " << &p << ")");
#if 0
if (m_connected)
{
m_errno = ERROR_ISCONN;
return -1;
}
#endif
InetSocketAddress transport = InetSocketAddress::ConvertFrom (address);
Ipv4Address ipv4 = transport.GetIpv4 ();
uint16_t port = transport.GetPort ();

View File

@@ -62,6 +62,7 @@ private:
int FinishBind (void);
void ForwardUp (const Packet &p, Ipv4Address ipv4, uint16_t port);
void Destroy (void);
int DoSend (const Packet &p);
int DoSendTo (const Packet &p, const Address &daddr);
int DoSendTo (const Packet &p, Ipv4Address daddr, uint16_t dport);

1
src/internet-node/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

1
src/mobility/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

View File

@@ -99,6 +99,11 @@ Ipv4Mask::SetHostOrder (uint32_t value)
{
m_mask = value;
}
uint32_t
Ipv4Mask::GetInverse (void) const
{
return ~m_mask;
}
void
Ipv4Mask::Print (std::ostream &os) const
@@ -162,6 +167,18 @@ Ipv4Address::CombineMask (Ipv4Mask const &mask) const
return Ipv4Address (GetHostOrder () & mask.GetHostOrder ());
}
Ipv4Address
Ipv4Address::GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const
{
return Ipv4Address (GetHostOrder () | mask.GetInverse ());
}
bool
Ipv4Address::IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const
{
return ( (GetHostOrder () | mask.GetInverse ()) == GetHostOrder () );
}
bool
Ipv4Address::IsBroadcast (void) const
{

View File

@@ -119,6 +119,16 @@ public:
* \param mask a network mask
*/
Ipv4Address CombineMask (Ipv4Mask const &mask) const;
/**
* \brief Generate subnet-directed broadcast address corresponding to mask
*
* The subnet-directed broadcast address has the host bits set to all
* ones.
*
* \param mask a network mask
*/
Ipv4Address GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
bool IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const;
static bool IsMatchingType (const Address &address);
operator Address ();
@@ -151,6 +161,10 @@ public:
*/
uint32_t GetHostOrder (void) const;
void SetHostOrder (uint32_t value);
/**
* \brief Return the inverse mask in host order.
*/
uint32_t GetInverse (void) const;
void Print (std::ostream &os) const;

View File

@@ -18,6 +18,9 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ns3/assert.h"
#include "ns3/node.h"
#include "ipv4.h"
namespace ns3 {
@@ -32,4 +35,53 @@ Ipv4::Ipv4 ()
Ipv4::~Ipv4 ()
{}
uint32_t
GetIfIndexByIpv4Address (Ptr<Node> node, Ipv4Address a, Ipv4Mask amask)
{
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
NS_ASSERT_MSG (ipv4, "GetIfIndexByIpv4Address: No Ipv4 interface");
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
{
if (ipv4->GetAddress (i).CombineMask(amask) == a.CombineMask(amask) )
{
return i;
}
}
// Mapping not found
NS_ASSERT_MSG (false, "GetIfIndexByIpv4Address failed");
return 0;
}
bool
GetIpv4RouteToDestination (Ptr<Node> node, Ipv4Route& route,
Ipv4Address a, Ipv4Mask amask)
{
Ipv4Route tempRoute;
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
NS_ASSERT_MSG (ipv4, "GetIpv4RouteToDestination: No Ipv4 interface");
for (uint32_t i = 0; i < ipv4->GetNRoutes (); i++)
{
tempRoute = ipv4->GetRoute (i);
// Host route found
if ( tempRoute.IsNetwork () == false && tempRoute.GetDest () == a )
{
route = tempRoute;
return true;
}
else if ( tempRoute.IsNetwork () &&
tempRoute.GetDestNetwork () == a.CombineMask(amask) )
{
route = tempRoute;
return true;
}
else if ( tempRoute.IsDefault () )
{
route = tempRoute;
return true;
}
}
return false;
}
} // namespace ns3

View File

@@ -29,6 +29,7 @@
namespace ns3 {
class Node;
class NetDevice;
class Packet;
class Ipv4Route;
@@ -425,6 +426,19 @@ public:
virtual void SetDown (uint32_t i) = 0;
};
/**
* Convenience functions (Doxygen still needed)
*
* Return the ifIndex corresponding to the Ipv4Address provided.
*/
uint32_t GetIfIndexByIpv4Address (Ptr<Node> node,
Ipv4Address a,
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
bool GetIpv4RouteToDestination (Ptr<Node> node, Ipv4Route& route,
Ipv4Address a,
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
} // namespace ns3
#endif /* IPV4_H */

View File

@@ -20,6 +20,7 @@
*/
#include "packet-socket-factory.h"
#include "node.h"
#include "packet-socket.h"
namespace ns3 {

View File

@@ -22,7 +22,6 @@
#define PACKET_SOCKET_FACTORY_H
#include "socket-factory.h"
#include "packet-socket.h"
namespace ns3 {

View File

@@ -58,6 +58,7 @@ public:
ERROR_AFNOSUPPORT,
ERROR_INVAL,
ERROR_BADF,
ERROR_NOROUTETOHOST,
SOCKET_ERRNO_LAST
};

1
src/node/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

View File

@@ -337,8 +337,7 @@ GlobalRouteManagerImpl::SelectRouterNodes ()
{
NS_DEBUG ("GlobalRouteManagerImpl::SelectRouterNodes ()");
typedef std::vector < Ptr<Node> >::iterator Iterator;
for (Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
NS_DEBUG ("GlobalRouteManagerImpl::SelectRouterNodes (): "
@@ -366,8 +365,7 @@ GlobalRouteManagerImpl::BuildGlobalRoutingDatabase ()
//
// Walk the list of nodes looking for the GlobalRouter Interface.
//
typedef std::vector < Ptr<Node> >::iterator Iterator;
for (Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
@@ -448,8 +446,7 @@ GlobalRouteManagerImpl::InitializeRoutes ()
//
// Walk the list of nodes in the system.
//
typedef std::vector < Ptr<Node> >::iterator Iterator;
for (Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
for (NodeList::Iterator i = NodeList::Begin (); i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
//
@@ -1091,83 +1088,10 @@ GlobalRouteManagerImpl::SPFCalculate (Ipv4Address root)
m_spfroot = 0;
}
//
// XXX This should probably be a method on Ipv4
//
// Return the interface index corresponding to a given IP address
//
uint32_t
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a)
{
//
// We have an IP address <a> and a vertex ID of the root of the SPF tree.
// The question is what interface index does this address correspond to.
// The answer is a little complicated since we have to find a pointer to
// the node corresponding to the vertex ID, find the Ipv4 interface on that
// node in order to iterate the interfaces and find the one corresponding to
// the address in question.
//
Ipv4Address routerId = m_spfroot->GetVertexId ();
//
// Walk the list of nodes in the system looking for the one corresponding to
// the node at the root of the SPF tree. This is the node for which we are
// building the routing table.
//
std::vector<Ptr<Node> >::iterator i = NodeList::Begin ();
for (; i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
Ptr<GlobalRouter> rtr =
node->QueryInterface<GlobalRouter> (GlobalRouter::iid);
//
// If the node doesn't have a GlobalRouter interface it can't be the one
// we're interested in.
//
if (rtr == 0)
{
continue;
}
if (rtr->GetRouterId () == routerId)
{
//
// This is the node we're building the routing table for. We're going to need
// the Ipv4 interface to look for the ipv4 interface index. Since this node
// is participating in routing IP version 4 packets, it certainly must have
// an Ipv4 interface.
//
Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
NS_ASSERT_MSG (ipv4,
"GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
"QI for <Ipv4> interface failed");
//
// Look through the interfaces on this node for one that has the IP address
// we're looking for. If we find one, return the corresponding interface
// index.
//
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
{
if (ipv4->GetAddress (i) == a)
{
NS_DEBUG (
"GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
"Interface match for " << a);
return i;
}
}
}
}
//
// Couldn't find it.
//
return 0;
}
//
// XXX This should probably be a method on Ipv4
//
// Return the interface index corresponding to a given IP address
// This is a wrapper around GetIfIndexByIpv4Address(), but we first
// have to find the right node pointer to pass to that function.
//
uint32_t
GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
@@ -1186,7 +1110,7 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
// the node at the root of the SPF tree. This is the node for which we are
// building the routing table.
//
std::vector<Ptr<Node> >::iterator i = NodeList::Begin ();
NodeList::Iterator i = NodeList::Begin ();
for (; i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
@@ -1219,17 +1143,7 @@ GlobalRouteManagerImpl::FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask)
// we're looking for. If we find one, return the corresponding interface
// index.
//
for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i++)
{
if (ipv4->GetAddress (i).CombineMask(amask) ==
a.CombineMask(amask) )
{
NS_DEBUG (
"GlobalRouteManagerImpl::FindOutgoingInterfaceId (): "
"Interface match for " << a);
return i;
}
}
return (GetIfIndexByIpv4Address (node, a, amask) );
}
}
//
@@ -1277,7 +1191,7 @@ GlobalRouteManagerImpl::SPFIntraAddRouter (SPFVertex* v)
// ID corresponding to the root vertex. This is the one we're going to write
// the routing information to.
//
std::vector<Ptr<Node> >::iterator i = NodeList::Begin ();
NodeList::Iterator i = NodeList::Begin ();
for (; i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
@@ -1398,7 +1312,7 @@ GlobalRouteManagerImpl::SPFIntraAddTransit (SPFVertex* v)
// ID corresponding to the root vertex. This is the one we're going to write
// the routing information to.
//
std::vector<Ptr<Node> >::iterator i = NodeList::Begin ();
NodeList::Iterator i = NodeList::Begin ();
for (; i != NodeList::End (); i++)
{
Ptr<Node> node = *i;
@@ -1696,6 +1610,9 @@ GlobalRouteManagerImplTest::RunTests (void)
srm->DebugSPFCalculate (lsa0->GetLinkStateId ()); // node n0
Simulator::Run ();
// XXX here we should do some verification of the routes built
Simulator::Destroy ();
// This delete clears the srm, which deletes the LSDB, which clears
@@ -1706,7 +1623,6 @@ GlobalRouteManagerImplTest::RunTests (void)
}
// Instantiate this class for the unit tests
// XXX here we should do some verification of the routes built
static GlobalRouteManagerImplTest g_globalRouteManagerTest;
} // namespace ns3

View File

@@ -754,8 +754,8 @@ private:
GlobalRoutingLinkRecord* prev_link);
void SPFIntraAddRouter (SPFVertex* v);
void SPFIntraAddTransit (SPFVertex* v);
uint32_t FindOutgoingInterfaceId (Ipv4Address a);
uint32_t FindOutgoingInterfaceId (Ipv4Address a, Ipv4Mask amask);
uint32_t FindOutgoingInterfaceId (Ipv4Address a,
Ipv4Mask amask = Ipv4Mask("255.255.255.255"));
};
} // namespace ns3

1
src/routing/global-routing/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../../waf "$@"

1
src/simulator/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../../waf "$@"

View File

@@ -39,11 +39,9 @@ def configure(conf):
conf.sub_config('simulator')
blddir = os.path.abspath(os.path.join(conf.m_blddir, conf.env.variant()))
conf.env['NS3_MODULE_PATH'] = [os.path.join(blddir, 'src')]
for module in all_modules:
module_path = os.path.join(blddir, 'src', module)
if Params.g_options.enable_rpath:
conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (module_path,))
conf.env['NS3_MODULE_PATH'] = [os.path.join(blddir)]
if Params.g_options.enable_rpath:
conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),))
## Used to link the 'run-tests' program with all of ns-3 code
conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules]
@@ -64,12 +62,6 @@ def build(bld):
bld.add_subdirs(list(all_modules))
## Create a single ns3 library containing all modules
lib = bld.create_obj('cpp', 'shlib')
lib.name = 'ns3'
lib.target = 'ns3'
lib.add_objects = list(bld.env_of_name('default')['NS3_MODULES'])
class Ns3Header(Object.genobj):
"""A set of NS-3 header files"""

1
utils/waf vendored Executable file
View File

@@ -0,0 +1 @@
exec "`dirname "$0"`"/../waf "$@"

4
waf vendored

File diff suppressed because one or more lines are too long

View File

@@ -145,6 +145,9 @@ def create_ns3_program(bld, name, dependencies=('simulator',)):
def build(bld):
print "Entering directory `%s/build'" % Params.g_build.m_curdirnode.abspath()
Params.g_cwd_launch = Params.g_build.m_curdirnode.abspath()
bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
@@ -165,6 +168,11 @@ def build(bld):
bld.add_subdirs('src')
bld.add_subdirs('samples utils examples')
## Create a single ns3 library containing all modules
lib = bld.create_obj('cpp', 'shlib')
lib.name = 'ns3'
lib.target = 'ns3'
lib.add_objects = list(bld.env_of_name('default')['NS3_MODULES'])
def shutdown():
#import UnitTest