# HG changeset patch # User Tom Henderson # Date 1184771203 25200 # Node ID 421c3d971423be7aafdc47c458097bf3d9511471 # Parent 7a81f1ef8c74c306e906fa5ec95dab37a2fbe906 Rename p2p-* to point-to-point-* diff -r 7a81f1ef8c74 -r 421c3d971423 doc/release_steps.txt --- a/doc/release_steps.txt Wed Jul 18 09:27:22 2007 -0500 +++ b/doc/release_steps.txt Wed Jul 18 08:06:43 2007 -0700 @@ -9,7 +9,7 @@ 3. add current version of waf script fro - svn checkout http://waf.googlecode.com/svn/tags/ns3/ waf - build waf script and put it into top of ns-3-dev 4. cd ns-3-dev; ./waf configure; ./waf dist -5. test tarball on release platforms (run-tests and simple-p2p) +5. test tarball on release platforms (run-tests and simple-point-to-point) 6. tag ns-3-dev with "release ns-3.0.X" - hg tag "release ns-3.0.x" - hg push diff -r 7a81f1ef8c74 -r 421c3d971423 examples/simple-p2p.cc --- a/examples/simple-p2p.cc Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,191 +0,0 @@ -/* -*- 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 - * - * ns-2 simple.tcl script (ported from ns-2) - * Originally authored by Steve McCanne, 12/19/1996 - */ - -// Port of ns-2/tcl/ex/simple.tcl to ns-3 -// -// Network topology -// -// n0 -// \ 5 Mb/s, 2ms -// \ 1.5Mb/s, 10ms -// n2 -------------------------n3 -// / -// / 5 Mb/s, 2ms -// n1 -// -// - all links are p2p links with indicated one-way BW/delay -// - CBR/UDP flows from n0 to n3, and from n3 to n1 -// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. -// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. -// (i.e., DataRate of 448,000 bps) -// - DropTail queues -// - Tracing of queues and packet receptions to file "simple-p2p.tr" - -#include -#include -#include -#include - -#include "ns3/command-line.h" -#include "ns3/default-value.h" -#include "ns3/ptr.h" -#include "ns3/random-variable.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/p2p-channel.h" -#include "ns3/p2p-net-device.h" -#include "ns3/mac-address.h" -#include "ns3/ipv4-address.h" -#include "ns3/ipv4.h" -#include "ns3/socket.h" -#include "ns3/ipv4-route.h" -#include "ns3/p2p-topology.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("Object"); - DebugComponentEnable("Queue"); - DebugComponentEnable("DropTailQueue"); - DebugComponentEnable("Channel"); - DebugComponentEnable("PointToPointChannel"); - DebugComponentEnable("PointToPointNetDevice"); -#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 - Bind ("Queue", "DropTailQueue"); - - Bind ("OnOffApplicationPacketSize", "210"); - Bind ("OnOffApplicationDataRate", "448kb/s"); - - //Bind ("DropTailQueue::m_maxPackets", 30); - - // 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 n0 = Create (); - Ptr n1 = Create (); - Ptr n2 = Create (); - Ptr n3 = Create (); - - // We create the channels first without any IP addressing information - Ptr channel0 = - PointToPointTopology::AddPointToPointLink ( - n0, n2, DataRate(5000000), MilliSeconds(2)); - - Ptr channel1 = - PointToPointTopology::AddPointToPointLink ( - n1, n2, DataRate(5000000), MilliSeconds(2)); - - Ptr channel2 = - PointToPointTopology::AddPointToPointLink ( - n2, n3, DataRate(1500000), MilliSeconds(10)); - - // Later, we add IP addresses. - PointToPointTopology::AddIpv4Addresses ( - channel0, n0, Ipv4Address("10.1.1.1"), - n2, Ipv4Address("10.1.1.2")); - - PointToPointTopology::AddIpv4Addresses ( - channel1, n1, Ipv4Address("10.1.2.1"), - n2, Ipv4Address("10.1.2.2")); - - PointToPointTopology::AddIpv4Addresses ( - channel2, n2, Ipv4Address("10.1.3.1"), - n3, Ipv4Address("10.1.3.2")); - - // Finally, we add static routes. These three steps (Channel and - // NetDevice creation, IP Address assignment, and routing) are - // separated because there may be a need to postpone IP Address - // assignment (emulation) or modify to use dynamic routing - PointToPointTopology::AddIpv4Routes(n0, n2, channel0); - PointToPointTopology::AddIpv4Routes(n1, n2, channel1); - PointToPointTopology::AddIpv4Routes(n2, n3, channel2); - - - // Create the OnOff application to send UDP datagrams of size - // 210 bytes at a rate of 448 Kb/s - Ptr ooff = Create ( - n0, - Ipv4Address("10.1.3.2"), - 80, - "Udp", - ConstantVariable(1), - ConstantVariable(0)); - // Start the application - ooff->Start(Seconds(1.0)); - ooff->Stop (Seconds(10.0)); - - // Create a similar flow from n3 to n1, starting at time 1.1 seconds - ooff = Create ( - n3, - Ipv4Address("10.1.2.1"), - 80, - "Udp", - ConstantVariable(1), - ConstantVariable(0)); - // Start the application - ooff->Start(Seconds(1.1)); - ooff->Stop (Seconds(10.0)); - - // Here, finish off packet routing configuration - // This will likely set by some global StaticRouting object in the future - Ptr ipv4; - ipv4 = n0->QueryInterface (Ipv4::iid); - ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); - ipv4 = n3->QueryInterface (Ipv4::iid); - ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); - - // Configure tracing of all enqueue, dequeue, and NetDevice receive events - // Trace output will be sent to the simple-p2p.tr file - AsciiTrace asciitrace ("simple-p2p.tr"); - asciitrace.TraceAllQueues (); - asciitrace.TraceAllNetDeviceRx (); - - // Also configure some tcpdump traces; each interface will be traced - // The output files will be named simple-p2p.pcap-- - // and can be read by the "tcpdump -r" command (use "-tt" option to - // display timestamps correctly) - PcapTrace pcaptrace ("simple-p2p.pcap"); - pcaptrace.TraceAllIp (); - - Simulator::Run (); - - Simulator::Destroy (); -} diff -r 7a81f1ef8c74 -r 421c3d971423 examples/simple-point-to-point.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/simple-point-to-point.cc Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,192 @@ +/* -*- 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 + * + * ns-2 simple.tcl script (ported from ns-2) + * Originally authored by Steve McCanne, 12/19/1996 + */ + +// Port of ns-2/tcl/ex/simple.tcl to ns-3 +// +// Network topology +// +// n0 +// \ 5 Mb/s, 2ms +// \ 1.5Mb/s, 10ms +// n2 -------------------------n3 +// / +// / 5 Mb/s, 2ms +// n1 +// +// - all links are point-to-point links with indicated one-way BW/delay +// - CBR/UDP flows from n0 to n3, and from n3 to n1 +// - FTP/TCP flow from n0 to n3, starting at time 1.2 to time 1.35 sec. +// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec. +// (i.e., DataRate of 448,000 bps) +// - DropTail queues +// - Tracing of queues and packet receptions to file "simple-point-to-point.tr" + +#include +#include +#include +#include + +#include "ns3/command-line.h" +#include "ns3/default-value.h" +#include "ns3/ptr.h" +#include "ns3/random-variable.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/point-to-point-channel.h" +#include "ns3/point-to-point-net-device.h" +#include "ns3/mac-address.h" +#include "ns3/ipv4-address.h" +#include "ns3/ipv4.h" +#include "ns3/socket.h" +#include "ns3/ipv4-route.h" +#include "ns3/point-to-point-topology.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("Object"); + DebugComponentEnable("Queue"); + DebugComponentEnable("DropTailQueue"); + DebugComponentEnable("Channel"); + DebugComponentEnable("PointToPointChannel"); + DebugComponentEnable("PointToPointNetDevice"); +#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 + Bind ("Queue", "DropTailQueue"); + + Bind ("OnOffApplicationPacketSize", "210"); + Bind ("OnOffApplicationDataRate", "448kb/s"); + + //Bind ("DropTailQueue::m_maxPackets", 30); + + // 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 n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + + // We create the channels first without any IP addressing information + Ptr channel0 = + PointToPointTopology::AddPointToPointLink ( + n0, n2, DataRate(5000000), MilliSeconds(2)); + + Ptr channel1 = + PointToPointTopology::AddPointToPointLink ( + n1, n2, DataRate(5000000), MilliSeconds(2)); + + Ptr channel2 = + PointToPointTopology::AddPointToPointLink ( + n2, n3, DataRate(1500000), MilliSeconds(10)); + + // Later, we add IP addresses. + PointToPointTopology::AddIpv4Addresses ( + channel0, n0, Ipv4Address("10.1.1.1"), + n2, Ipv4Address("10.1.1.2")); + + PointToPointTopology::AddIpv4Addresses ( + channel1, n1, Ipv4Address("10.1.2.1"), + n2, Ipv4Address("10.1.2.2")); + + PointToPointTopology::AddIpv4Addresses ( + channel2, n2, Ipv4Address("10.1.3.1"), + n3, Ipv4Address("10.1.3.2")); + + // Finally, we add static routes. These three steps (Channel and + // NetDevice creation, IP Address assignment, and routing) are + // separated because there may be a need to postpone IP Address + // assignment (emulation) or modify to use dynamic routing + PointToPointTopology::AddIpv4Routes(n0, n2, channel0); + PointToPointTopology::AddIpv4Routes(n1, n2, channel1); + PointToPointTopology::AddIpv4Routes(n2, n3, channel2); + + + // Create the OnOff application to send UDP datagrams of size + // 210 bytes at a rate of 448 Kb/s + Ptr ooff = Create ( + n0, + Ipv4Address("10.1.3.2"), + 80, + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.0)); + ooff->Stop (Seconds(10.0)); + + // Create a similar flow from n3 to n1, starting at time 1.1 seconds + ooff = Create ( + n3, + Ipv4Address("10.1.2.1"), + 80, + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.1)); + ooff->Stop (Seconds(10.0)); + + // Here, finish off packet routing configuration + // This will likely set by some global StaticRouting object in the future + Ptr ipv4; + ipv4 = n0->QueryInterface (Ipv4::iid); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); + ipv4 = n3->QueryInterface (Ipv4::iid); + ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); + + // Configure tracing of all enqueue, dequeue, and NetDevice receive events + // Trace output will be sent to the simple-point-to-point.tr file + AsciiTrace asciitrace ("simple-point-to-point.tr"); + asciitrace.TraceAllQueues (); + asciitrace.TraceAllNetDeviceRx (); + + // Also configure some tcpdump traces; each interface will be traced + // The output files will be named + // simple-point-to-point.pcap-- + // and can be read by the "tcpdump -r" command (use "-tt" option to + // display timestamps correctly) + PcapTrace pcaptrace ("simple-point-to-point.pcap"); + pcaptrace.TraceAllIp (); + + Simulator::Run (); + + Simulator::Destroy (); +} diff -r 7a81f1ef8c74 -r 421c3d971423 examples/wscript --- a/examples/wscript Wed Jul 18 09:27:22 2007 -0500 +++ b/examples/wscript Wed Jul 18 08:06:43 2007 -0700 @@ -9,5 +9,5 @@ def build(bld): obj.source = source return obj - obj = create_ns_prog('simple-p2p', 'simple-p2p.cc', deps=['p2p', 'internet-node']) + obj = create_ns_prog('simple-point-to-point', 'simple-point-to-point.cc', deps=['point-to-point', 'internet-node']) diff -r 7a81f1ef8c74 -r 421c3d971423 samples/wscript --- a/samples/wscript Wed Jul 18 09:27:22 2007 -0500 +++ b/samples/wscript Wed Jul 18 08:06:43 2007 -0700 @@ -18,7 +18,6 @@ def build(bld): obj = create_ns_prog('main-test', 'main-test.cc') obj = create_ns_prog('main-simple', 'main-simple.cc', deps=['node', 'internet-node', 'applications']) - #obj = create_ns_prog('main-simple-p2p', 'main-simple-p2p.cc', deps=['node', 'p2p']) obj = create_ns_prog('main-default-value', 'main-default-value.cc', - deps=['core', 'simulator', 'node', 'p2p']) + deps=['core', 'simulator', 'node']) diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/p2p-channel.cc --- a/src/devices/p2p/p2p-channel.cc Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 University of Washington - * 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: Craig Dowell - */ - -#include "p2p-channel.h" -#include "p2p-net-device.h" -#include "ns3/packet.h" -#include "ns3/simulator.h" -#include "ns3/debug.h" - -NS_DEBUG_COMPONENT_DEFINE ("PointToPointChannel"); - -namespace ns3 { - -// -// By default, you get a channel with the name "PointToPoint Channel" that -// has an "infitely" fast transmission speed and zero delay. -PointToPointChannel::PointToPointChannel() -: - Channel ("PointToPoint Channel"), - m_bps (DataRate(0xffffffff)), - m_delay (Seconds(0)), - m_nDevices(0) -{ - NS_DEBUG("PointToPointChannel::PointToPointChannel ()"); -} - -PointToPointChannel::PointToPointChannel( - const DataRate& bps, - const Time& delay) -: - Channel ("PointToPoint Channel"), - m_bps (bps), - m_delay (delay), - m_nDevices(0) -{ - NS_DEBUG("PointToPointChannel::PointToPointChannel (" << Channel::GetName() - << ", " << bps.GetBitRate() << ", " << delay << ")"); -} - -PointToPointChannel::PointToPointChannel( - const std::string& name, - const DataRate& bps, - const Time& delay) -: - Channel (name), - m_bps (bps), - m_delay (delay), - m_nDevices(0) -{ - NS_DEBUG("PointToPointChannel::PointToPointChannel (" << name << ", " << - bps.GetBitRate() << ", " << delay << ")"); -} - - void -PointToPointChannel::Attach(Ptr device) -{ - NS_DEBUG("PointToPointChannel::Attach (" << device << ")"); - NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); - NS_ASSERT(device != 0); - - m_link[m_nDevices++].m_src = device; -// -// If we have both devices connected to the channel, then finish introducing -// the two halves and set the links to IDLE. -// - if (m_nDevices == N_DEVICES) - { - m_link[0].m_dst = m_link[1].m_src; - m_link[1].m_dst = m_link[0].m_src; - m_link[0].m_state = IDLE; - m_link[1].m_state = IDLE; - } -} - -bool PointToPointChannel::TransmitStart(Packet& p, - Ptr src, - const Time& txTime) -{ - NS_DEBUG ("PointToPointChannel::TransmitStart (" << &p << ", " << src << - ")"); - NS_DEBUG ("PointToPointChannel::TransmitStart (): UID is " << - p.GetUid () << ")"); - - NS_ASSERT(m_link[0].m_state != INITIALIZING); - NS_ASSERT(m_link[1].m_state != INITIALIZING); - - uint32_t wire = src == m_link[0].m_src ? 0 : 1; - - // Here we schedule the packet receive event at the receiver, - // which simplifies this model quite a bit. The channel just - // adds the propagation delay time - Simulator::Schedule (txTime + m_delay, - &PointToPointNetDevice::Receive, - m_link[wire].m_dst, p); - return true; -} - -uint32_t -PointToPointChannel::GetNDevices (void) const -{ - return m_nDevices; -} - -Ptr -PointToPointChannel::GetDevice (uint32_t i) const -{ - NS_ASSERT(i < 2); - return m_link[i].m_src; -} - -const DataRate& -PointToPointChannel::GetDataRate (void) -{ - return m_bps; -} - -const Time& -PointToPointChannel::GetDelay (void) -{ - return m_delay; -} - - -} // namespace ns3 diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/p2p-channel.h --- a/src/devices/p2p/p2p-channel.h Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 University of Washington - * - * 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 POINT_TO_POINT_CHANNEL_H -#define POINT_TO_POINT_CHANNEL_H - -#include -#include "ns3/channel.h" -#include "ns3/ptr.h" -#include "ns3/packet.h" -#include "ns3/nstime.h" -#include "ns3/data-rate.h" - -namespace ns3 { - -class PointToPointNetDevice; - -/** - * \brief Simple Point To Point Channel. - * - * This class represents a very simple point to point channel. Think full - * duplex RS-232 or RS-422 with null modem and no handshaking. There is no - * multi-drop capability on this channel -- there can be a maximum of two - * point-to-point net devices connected. Once we start talking about multi- - * drop, or CSMA, or some other sharing mechanism, things begin getting - * complicated quickly. Rather than invent some ad-hoc mechanism, we just - * Keep It Simple everywhere. - * - * When the channel is instaniated, the constructor takes parameters for - * a single speed, in bits per second, and a speed-of-light delay time as a - * Time object. Both directions use the same speed and delay time. - * - * There are two "wires" in the channel. The first device connected gets the - * [0] wire to transmit on. The second device gets the [1] wire. There is a - * state (IDLE, TRANSMITTING) associated with each wire. - */ -class PointToPointChannel : public Channel { -public: -// Each point to point link has exactly two net devices - static const int N_DEVICES = 2; - /** - * \brief Create a PointToPointChannel - * - * By default, you get a channel with the name "PointToPoint Channel" that - * has an "infitely" fast transmission speed and zero delay. - */ - PointToPointChannel (); - - /** - * \brief Create a PointToPointChannel - * - * \param bps The maximum bitrate of the channel - * \param delay Transmission delay through the channel - */ - PointToPointChannel (const DataRate& bps, const Time& delay); - - /** - * \brief Create a PointToPointChannel - * - * \param name the name of the channel for identification purposes - * \param bps The maximum bitrate of the channel - * \param delay Transmission delay through the channel - */ - PointToPointChannel (const std::string& name, - const DataRate& bps, const Time& delay); - - /** - * \brief Attach a given netdevice to this channel - * \param device pointer to the netdevice to attach to the channel - */ - void Attach (Ptr device); - bool TransmitStart (Packet& p, Ptr src, - const Time& txTime); - // Below two not needed - //bool TransmitEnd (Packet &p, Ptr src); - //void PropagationCompleteEvent(Packet p, Ptr src); - - - virtual uint32_t GetNDevices (void) const; - virtual Ptr GetDevice (uint32_t i) const; - - virtual const DataRate& GetDataRate (void); - virtual const Time& GetDelay (void); - -private: - DataRate m_bps; - Time m_delay; - int32_t m_nDevices; - - enum WireState - { - INITIALIZING, - IDLE, - TRANSMITTING, - PROPAGATING - }; - - class Link - { - public: - Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {} - WireState m_state; - Ptr m_src; - Ptr m_dst; - }; - - Link m_link[N_DEVICES]; -}; - -} // namespace ns3 - -#endif /* POINT_TO_POINT_CHANNEL_H */ diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/p2p-net-device.cc --- a/src/devices/p2p/p2p-net-device.cc Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,275 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005,2006 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Craig Dowell - * Revised: George Riley - */ - -#include -#include -#include "ns3/debug.h" -#include "ns3/queue.h" -#include "ns3/simulator.h" -#include "ns3/composite-trace-resolver.h" -#include "p2p-net-device.h" -#include "p2p-channel.h" - -NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice"); - -namespace ns3 { - -DataRateDefaultValue PointToPointNetDevice::g_defaultRate( - "PointToPointLinkDataRate", - "The default data rate for point to point links", - DataRate ("10Mb/s")); - - PointToPointNetDevice::PointToPointNetDevice (Ptr node, - const DataRate& rate) -: - NetDevice(node, MacAddress (6)), - m_txMachineState (READY), - m_bps (rate), - m_tInterframeGap (Seconds(0)), - m_channel (0), - m_queue (0), - m_rxTrace () -{ - NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << node << ")"); - - // BUGBUG FIXME - // - // You _must_ support broadcast to get any sort of packet from the ARP layer. - EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff")); - EnableMulticast(); - EnablePointToPoint(); -} - -PointToPointNetDevice::~PointToPointNetDevice() -{ - NS_DEBUG ("PointToPointNetDevice::~PointToPointNetDevice ()"); - m_queue = 0; -} - -// -// Copy constructor for PointToPointNetDevice. -// -// We use the underlying NetDevice copy constructor to get the base class -// copied. These just remain as is (e.g. you get the same name, the same -// MAC address). If you need to fix them up, YOU, the copier need to do -// that. -// -// The things we need to be careful of are the channel, the queue and the -// trace callback. If the channel pointer is non-zero, we copy the pointer -// and add a reference. If the queue is non-zero, we copy it using the queue -// assignment operator. We don't mess with the trace -- we just reset it. -// We're assuming that the tracing will be set up after the topology creation -// phase and this won't actually matter. -// -// GFR Comments. Don't see where the "copy the pointer and add reference" -// stated above is done. Can original author please comment and/or fix. -// Shouldn't the queue pointer also bump the refcount? -PointToPointNetDevice::PointToPointNetDevice (const PointToPointNetDevice& nd) -: - NetDevice(nd), - m_txMachineState(READY), - m_bps (nd.m_bps), - m_tInterframeGap (nd.m_tInterframeGap), - m_channel(nd.m_channel), - m_queue(0), - m_rxTrace () -{ - NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << &nd << ")"); - - if (nd.m_queue) - { - m_queue = nd.m_queue; - } - -} - - // GFR COmments...shouldn't this decrement the refcount instead - // of just nil-ing out the pointer? Don't understand this. -void PointToPointNetDevice::DoDispose() -{ - m_channel = 0; - NetDevice::DoDispose (); -} - -// -// Assignment operator for PointToPointNetDevice. -// -// -PointToPointNetDevice& -PointToPointNetDevice::operator= (const PointToPointNetDevice& nd) -{ - NS_DEBUG ("PointToPointNetDevice::operator= (" << &nd << ")"); - // FIXME. Not sure what to do here - // GFR Note. I would suggest dis-allowing netdevice assignment, - // as well as pass-by-value (ie. copy constructor). - // This resolves some of the questions above about copy constructors. - // Why should we ever copy or assign a net device? - return *this; -} - -void PointToPointNetDevice::SetDataRate(const DataRate& bps) -{ - m_bps = bps; -} - -void PointToPointNetDevice::SetInterframeGap(const Time& t) -{ - m_tInterframeGap = t; -} - -bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest) -{ - NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")"); - NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")"); - - // GFR Comment. Why is this an assertion? Can't a link legitimately - // "go down" during the simulation? Shouldn't we just wait for it - // to come back up? - NS_ASSERT (IsLinkUp ()); - -// -// This class simulates a point to point device. In the case of a serial -// link, this means that we're simulating something like a UART. -// -// -// If there's a transmission in progress, we enque the packet for later -// trnsmission; otherwise we send it now. - if (m_txMachineState == READY) - { - return TransmitStart (p); - } - else - { - return m_queue->Enqueue(p); - } -} - - bool -PointToPointNetDevice::TransmitStart (Packet &p) -{ - NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")"); - NS_DEBUG ( - "PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")"); -// -// This function is called to start the process of transmitting a packet. -// We need to tell the channel that we've started wiggling the wire and -// schedule an event that will be executed when the transmission is complete. -// - NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit"); - m_txMachineState = BUSY; - Time txTime = Seconds (m_bps.CalculateTxTime(p.GetSize())); - Time txCompleteTime = txTime + m_tInterframeGap; - - NS_DEBUG ("PointToPointNetDevice::TransmitStart (): " << - "Schedule TransmitCompleteEvent in " << - txCompleteTime.GetSeconds () << "sec"); - // Schedule the tx complete event - Simulator::Schedule (txCompleteTime, - &PointToPointNetDevice::TransmitComplete, - this); - return m_channel->TransmitStart(p, this, txTime); -} - -void PointToPointNetDevice::TransmitComplete (void) -{ - NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent ()"); -// -// This function is called to finish the process of transmitting a packet. -// We need to tell the channel that we've stopped wiggling the wire and -// get the next packet from the queue. If the queue is empty, we are -// done, otherwise transmit the next packet. -// - NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting"); - m_txMachineState = READY; - Packet p; - if (!m_queue->Dequeue(p)) return; // Nothing to do at this point - TransmitStart(p); -} - -TraceResolver* PointToPointNetDevice::DoCreateTraceResolver ( - TraceContext const &context) -{ - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue)), - PointToPointNetDevice::QUEUE); - resolver->Add ("rx", - m_rxTrace, - PointToPointNetDevice::RX); - return resolver; -} - -bool PointToPointNetDevice::Attach (Ptr ch) -{ - NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")"); - - m_channel = ch; - - m_channel->Attach(this); - m_bps = m_channel->GetDataRate (); - // GFR Comment. Below is definitely wrong. Interframe gap - // is unrelated to channel delay. - //m_tInterframeGap = m_channel->GetDelay (); - - /* - * For now, this device is up whenever a channel is attached to it. - * In fact, it should become up only when the second device - * is attached to the channel. So, there should be a way for - * a PointToPointChannel to notify both of its attached devices - * that the channel is 'complete', hence that the devices are - * up, hence that they can call NotifyLinkUp. - */ - NotifyLinkUp (); - return true; -} - -void PointToPointNetDevice::AddQueue (Ptr q) -{ - NS_DEBUG ("PointToPointNetDevice::AddQueue (" << q << ")"); - - m_queue = q; -} - -void PointToPointNetDevice::Receive (Packet& p) -{ - NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")"); - - m_rxTrace (p); - ForwardUp (p); -} - -Ptr PointToPointNetDevice::GetQueue(void) const -{ - return m_queue; -} - -Ptr PointToPointNetDevice::DoGetChannel(void) const -{ - return m_channel; -} - -bool PointToPointNetDevice::DoNeedsArp (void) const -{ - return false; -} - -} // namespace ns3 diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/p2p-net-device.h --- a/src/devices/p2p/p2p-net-device.h Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2007 University of Washington - * - * 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: Craig Dowell - */ - -#ifndef POINT_TO_POINT_NET_DEVICE_H -#define POINT_TO_POINT_NET_DEVICE_H - -#include -#include "ns3/mac-address.h" -#include "ns3/node.h" -#include "ns3/net-device.h" -#include "ns3/callback.h" -#include "ns3/packet.h" -#include "ns3/callback-trace-source.h" -#include "ns3/nstime.h" -#include "ns3/data-rate.h" -#include "ns3/default-value.h" -#include "ns3/ptr.h" - -namespace ns3 { - -class Queue; -class PointToPointChannel; - -/** - * \class PointToPointNetDevice - * \brief A Device for a Point to Point Network Link. - * - * Ns-3 takes a four-layer view of a protocol stack. This is the same model - * that TCP uses. In this view, layers 5-7 of the OSI reference model are - * grouped together into an application layer; layer four (transport / TCP) is - * broken out; layer three (network / IP) is broken out; and layers 1-2 are - * grouped together. We call this grouping of layers one and two a NetDevice - * and represent it as a class in the system. - * - * The NetDevice class is specialized according to the needs of the specific - * kind of network link. In this case, the link is a PointToPoint link. The - * PointToPoint link is a family of classes that includes this class, the - * PointToPointNetDevice, a PointToPointChannel class that represents the - * actual medium across which bits are sent, a PointToPointIpv4Interface class - * that provides the hook to tie a general purpose node to this specific - * link, and finally, a PointToPointTopology object that is responsible for - * putting all of the pieces together. - * - * This is the PointToPointNetDevice class that represents, essentially, the - * PC card that is used to connect to the PointToPoint network. - */ -class PointToPointNetDevice : public NetDevice { -public: - /** - * Enumeration of the types of traces supported in the class. - * - */ - enum TraceType { - QUEUE, /**< Trace queue events on the attached queue */ - RX, /**< Trace packet reception events (from the channel) */ - }; - /** - * Construct a PointToPointNetDevice - * - * This is the constructor for the PointToPointNetDevice. It takes as a - * parameter the Node to which this device is connected. Ownership of the - * Node pointer is not implied and the node must not be deleded. - * - * @see PointToPointTopology::AddPointToPointLink () - * @param node the Node to which this device is connected. - */ - PointToPointNetDevice (Ptr node, - const DataRate& = g_defaultRate.GetValue()); - /** - * Copy Construct a PointToPointNetDevice - * - * This is the copy constructor for the PointToPointNetDevice. This is - * primarily used in topology creation. - * - * @see PointToPointTopology::AddPointToPointLink () - * @param nd the object to be copied - */ - PointToPointNetDevice (const PointToPointNetDevice& nd); - /** - * Destroy a PointToPointNetDevice - * - * This is the destructor for the PointToPointNetDevice. - */ - virtual ~PointToPointNetDevice(); - /** - * Assignment Operator for a PointToPointNetDevice - * - * This is the assignment operator for the PointToPointNetDevice. This is - * to allow - * - * @param nd the object to be copied - */ - PointToPointNetDevice& operator= (const PointToPointNetDevice& nd); - /** - * Set the Data Rate used for transmission of packets. The data rate is - * set in the Attach () method from the corresponding field in the channel - * to which the device is attached. It can be overridden using this method. - * - * @see Attach () - * @param bps the data rate at which this object operates - */ - void SetDataRate(const DataRate& bps); - /** - * Set the inteframe gap used to separate packets. The interframe gap - * defines the minimum space required between packets sent by this device. - * It is usually set in the Attach () method based on the speed of light - * delay of the channel to which the device is attached. It can be - * overridden using this method if desired. - * - * @see Attach () - * @param t the interframe gap time - */ - void SetInterframeGap(const Time& t); - /** - * Attach the device to a channel. - * - * The PointToPointTopology object creates a PointToPointChannel and two - * PointtoPointNetDevices. In order to introduce these components to each - * other, the topology object calls Attach () on each PointToPointNetDevice. - * Inside this method, the Net Device calls out to the PointToPointChannel - * to introduce itself. - * - * @see PointToPointTopology::AddPointToPointLink () - * @see SetDataRate () - * @see SetInterframeGap () - * @param ch a pointer to the channel to which this object is being attached. - */ - bool Attach(Ptr ch); - /** - * Attach a queue to the PointToPointNetDevice. - * - * The PointToPointNetDevice "owns" a queue. This queue is created by the - * PointToPointTopology object and implements a queueing method such as - * DropTail or RED. The PointToPointNetDevice assumes ownership of this - * queue and must delete it when the device is destroyed. - * - * @see PointToPointTopology::AddPointToPointLink () - * @see Queue - * @see DropTailQueue - * @param queue a pointer to the queue for which object is assuming - * ownership. - */ - void AddQueue(Ptr queue); - /** - * Receive a packet from a connected PointToPointChannel. - * - * The PointToPointNetDevice receives packets from its connected channel - * and forwards them up the protocol stack. This is the public method - * used by the channel to indicate that the last bit of a packet has - * arrived at the device. - * - * @see PointToPointChannel - * @param p a reference to the received packet - */ - void Receive (Packet& p); -protected: - virtual void DoDispose (void); - /** - * Get a copy of the attached Queue. - * - * This method is provided for any derived class that may need to get - * direct access to the underlying queue. - * - * @see PointToPointTopology - * @returns a pointer to the queue. - */ - Ptr GetQueue(void) const; - /** - * Get a copy of the attached Channel - * - * This method is provided for any derived class that may need to get - * direct access to the connected channel - * - * @see PointToPointChannel - * @returns a pointer to the channel - */ - virtual Ptr DoGetChannel(void) const; - /** - * Set a new default data rate - * @param Data rate to set for new default - */ - static void SetDefaultRate(const DataRate&); - - /** - * Get the current default rate. - * @returns a const reference to current default - */ - - static const DataRate& GetDefaultRate(); - -private: - /** - * Send a Packet Down the Wire. - * - * The SendTo method is defined as the standard way that the level three - * protocol uses to tell a NetDevice to send a packet. SendTo is declared - * as abstract in the NetDevice class and we declare it here. - * - * @see NetDevice - * @param p a reference to the packet to send - * @param dest a reference to the MacAddress of the destination device - * @returns true if success, false on failure - */ - virtual bool SendTo (Packet& p, const MacAddress& dest); - /** - * Start Sending a Packet Down the Wire. - * - * The TransmitStart method is the method that is used internally in the - * PointToPointNetDevice to begin the process of sending a packet out on - * the channel. The corresponding method is called on the channel to let - * it know that the physical device this class represents has virually - * started sending signals. An event is scheduled for the time at which - * the bits have been completely transmitted. - * - * @see PointToPointChannel::TransmitStart () - * @see TransmitCompleteEvent () - * @param p a reference to the packet to send - * @returns true if success, false on failure - */ - bool TransmitStart (Packet &p); - /** - * Stop Sending a Packet Down the Wire and Begin the Interframe Gap. - * - * The TransmitComplete method is used internally to finish the process - * of sending a packet out on the channel. - * - */ - void TransmitComplete(void); - /** - * Create a Trace Resolver for events in the net device. - * - * @see class TraceResolver - */ - virtual TraceResolver* DoCreateTraceResolver (TraceContext const &context); - virtual bool DoNeedsArp (void) const; - /** - * Enumeration of the states of the transmit machine of the net device. - */ - enum TxMachineState - { - READY, /**< The transmitter is ready to begin transmission of a packet */ - BUSY /**< The transmitter is busy transmitting a packet */ - }; - /** - * The state of the Net Device transmit state machine. - * @see TxMachineState - */ - TxMachineState m_txMachineState; - /** - * The data rate that the Net Device uses to simulate packet transmission - * timing. - * @see class DataRate - */ - DataRate m_bps; - /** - * The interframe gap that the Net Device uses to throttle packet - * transmission - * @see class Time - */ - Time m_tInterframeGap; - /** - * The PointToPointChannel to which this PointToPointNetDevice has been - * attached. - * @see class PointToPointChannel - */ - Ptr m_channel; - /** - * The Queue which this PointToPointNetDevice uses as a packet source. - * Management of this Queue has been delegated to the PointToPointNetDevice - * and it has the responsibility for deletion. - * @see class Queue - * @see class DropTailQueue - */ - Ptr m_queue; - /** - * The trace source for the packet reception events that the device can - * fire. - * - * @see class CallBackTraceSource - * @see class TraceResolver - */ - CallbackTraceSource m_rxTrace; - /** - * Default data rate. Used for all newly created p2p net devices - */ - static DataRateDefaultValue g_defaultRate; - -}; - -}; // namespace ns3 - -#endif // POINT_TO_POINT_NET_DEVICE_H - diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/p2p-topology.cc --- a/src/devices/p2p/p2p-topology.cc Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +0,0 @@ -/* -*- 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 -// -// Author: George F. Riley -// - -// -// Topology helper for ns3. -// George F. Riley, Georgia Tech, Spring 2007 - -#include -#include "ns3/assert.h" -#include "ns3/debug.h" -#include "ns3/fatal-error.h" -#include "ns3/nstime.h" -#include "ns3/internet-node.h" -#include "ns3/ipv4-address.h" -#include "ns3/ipv4.h" -#include "ns3/queue.h" - -#include "p2p-channel.h" -#include "p2p-net-device.h" -#include "p2p-topology.h" - -namespace ns3 { - -Ptr -PointToPointTopology::AddPointToPointLink( - Ptr n1, - Ptr n2, - const DataRate& bps, - const Time& delay) -{ - Ptr channel = Create (bps, delay); - - Ptr net1 = Create (n1); - - Ptr q = Queue::CreateDefault (); - net1->AddQueue(q); - net1->Attach (channel); - - Ptr net2 = Create (n2); - - q = Queue::CreateDefault (); - net2->AddQueue(q); - net2->Attach (channel); - - return channel; -} - -void -PointToPointTopology::AddIpv4Addresses( - Ptr chan, - Ptr n1, const Ipv4Address& addr1, - Ptr n2, const Ipv4Address& addr2) -{ - - // Duplex link is assumed to be subnetted as a /30 - // May run this unnumbered in the future? - Ipv4Mask netmask("255.255.255.252"); - NS_ASSERT (netmask.IsMatch(addr1,addr2)); - - // The PointToPoint channel is used to find the relevant NetDevices - NS_ASSERT (chan->GetNDevices () == 2); - Ptr nd1 = chan->GetDevice (0); - Ptr nd2 = chan->GetDevice (1); - // Make sure that nd1 belongs to n1 and nd2 to n2 - if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && - (nd2->GetNode ()->GetId () == n1->GetId () ) ) - { - std::swap(nd1, nd2); - } - NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ()); - NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ()); - - Ptr ip1 = n1->QueryInterface (Ipv4::iid); - uint32_t index1 = ip1->AddInterface (nd1); - - ip1->SetAddress (index1, addr1); - ip1->SetNetworkMask (index1, netmask); - ip1->SetUp (index1); - - Ptr ip2 = n2->QueryInterface (Ipv4::iid); - uint32_t index2 = ip2->AddInterface (nd2); - - ip2->SetAddress (index2, addr2); - ip2->SetNetworkMask (index2, netmask); - ip2->SetUp (index2); - -} - -void -PointToPointTopology::AddIpv4Routes ( - Ptr n1, Ptr n2, Ptr chan) -{ - // The PointToPoint channel is used to find the relevant NetDevices - NS_ASSERT (chan->GetNDevices () == 2); - Ptr nd1 = chan->GetDevice (0); - Ptr nd2 = chan->GetDevice (1); - - // Assert that n1 is the Node owning one of the two NetDevices - // and make sure that nd1 corresponds to it - if (nd1->GetNode ()->GetId () == n1->GetId ()) - { - ; // Do nothing - } - else if (nd2->GetNode ()->GetId () == n1->GetId ()) - { - std::swap(nd1, nd2); - } - else - { - NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); - } - - // Assert that n2 is the Node owning one of the two NetDevices - // and make sure that nd2 corresponds to it - if (nd2->GetNode ()->GetId () != n2->GetId ()) - { - NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); - } - - // Assert that both are Ipv4 nodes - Ptr ip1 = nd1->GetNode ()->QueryInterface (Ipv4::iid); - Ptr ip2 = nd2->GetNode ()->QueryInterface (Ipv4::iid); - NS_ASSERT(ip1 != 0 && ip2 != 0); - - // Get interface indexes for both nodes corresponding to the right channel - uint32_t index1 = 0; - bool found = false; - for (uint32_t i = 0; i < ip1->GetNInterfaces (); i++) - { - if (ip1 ->GetNetDevice (i) == nd1) - { - index1 = i; - found = true; - } - } - NS_ASSERT(found); - - uint32_t index2 = 0; - found = false; - for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++) - { - if (ip2 ->GetNetDevice (i) == nd2) - { - index2 = i; - found = true; - } - } - NS_ASSERT(found); - - ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1); - ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); -} - -} // namespace ns3 - diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/p2p-topology.h --- a/src/devices/p2p/p2p-topology.h Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* -*- 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 -// -// Author: George F. Riley -// -// Topology helper for ns3. -// George F. Riley, Georgia Tech, Spring 2007 -#ifndef __POINT_TO_POINT_TOPOLOGY_H__ -#define __POINT_TO_POINT_TOPOLOGY_H__ - -#include "ns3/ptr.h" - -// The topology class consists of only static methods thar are used to -// create the topology and data flows for an ns3 simulation - -namespace ns3 { - -class PointToPointChannel; -class Node; -class IPAddr; -class DataRate; -class Queue; - -/** - * \brief A helper class to create Topologies based on the - * ns3::PointToPointNetDevice and ns3::PointToPointChannel objects. - */ -class PointToPointTopology { -public: - /** - * \param n1 Node - * \param n2 Node - * \param dataRate Maximum transmission link rate - * \param delay one-way propagation delay - * \return Pointer to the underlying PointToPointChannel - * - * Add a full-duplex point-to-point link between two nodes - * and attach PointToPointNetDevices to the resulting - * PointToPointChannel. - */ - static Ptr AddPointToPointLink( - Ptr n1, Ptr n2, const DataRate& dataRate, const Time& delay); - - /** - * \param chan PointToPointChannel to use - * \param n1 Node - * \param addr1 Ipv4 Address for n1 - * \param n2 Node - * \param addr2 Ipv4 Address for n2 - * - * Add Ipv4Addresses to the Ipv4 interfaces associated with the - * two PointToPointNetDevices on the provided PointToPointChannel - */ - static void AddIpv4Addresses( - Ptr chan, - Ptr n1, const Ipv4Address& addr1, - Ptr n2, const Ipv4Address& addr2); - - /** - * \param channel PointToPointChannel to use - * \param n1 Node - * \param n2 Node - * - * For the given PointToPointChannel, for each Node, add an - * IPv4 host route to the IPv4 address of the peer node. - */ - static void AddIpv4Routes (Ptr n1, Ptr n2, Ptr channel); -}; - -} // namespace ns3 - -#endif - diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/p2p/wscript --- a/src/devices/p2p/wscript Wed Jul 18 09:27:22 2007 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- - - -def build(bld): - p2p = bld.create_obj('cpp', 'shlib') - p2p.name = 'ns3-p2p' - p2p.target = p2p.name - p2p.uselib_local = ['ns3-node'] - p2p.source = [ - 'p2p-net-device.cc', - 'p2p-channel.cc', - 'p2p-topology.cc', - ] - headers = bld.create_obj('ns3header') - headers.source = [ - 'p2p-net-device.h', - 'p2p-channel.h', - 'p2p-topology.h', - ] - diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/point-to-point-channel.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/point-to-point-channel.cc Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,142 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * 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: Craig Dowell + */ + +#include "p2p-channel.h" +#include "p2p-net-device.h" +#include "ns3/packet.h" +#include "ns3/simulator.h" +#include "ns3/debug.h" + +NS_DEBUG_COMPONENT_DEFINE ("PointToPointChannel"); + +namespace ns3 { + +// +// By default, you get a channel with the name "PointToPoint Channel" that +// has an "infitely" fast transmission speed and zero delay. +PointToPointChannel::PointToPointChannel() +: + Channel ("PointToPoint Channel"), + m_bps (DataRate(0xffffffff)), + m_delay (Seconds(0)), + m_nDevices(0) +{ + NS_DEBUG("PointToPointChannel::PointToPointChannel ()"); +} + +PointToPointChannel::PointToPointChannel( + const DataRate& bps, + const Time& delay) +: + Channel ("PointToPoint Channel"), + m_bps (bps), + m_delay (delay), + m_nDevices(0) +{ + NS_DEBUG("PointToPointChannel::PointToPointChannel (" << Channel::GetName() + << ", " << bps.GetBitRate() << ", " << delay << ")"); +} + +PointToPointChannel::PointToPointChannel( + const std::string& name, + const DataRate& bps, + const Time& delay) +: + Channel (name), + m_bps (bps), + m_delay (delay), + m_nDevices(0) +{ + NS_DEBUG("PointToPointChannel::PointToPointChannel (" << name << ", " << + bps.GetBitRate() << ", " << delay << ")"); +} + + void +PointToPointChannel::Attach(Ptr device) +{ + NS_DEBUG("PointToPointChannel::Attach (" << device << ")"); + NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); + NS_ASSERT(device != 0); + + m_link[m_nDevices++].m_src = device; +// +// If we have both devices connected to the channel, then finish introducing +// the two halves and set the links to IDLE. +// + if (m_nDevices == N_DEVICES) + { + m_link[0].m_dst = m_link[1].m_src; + m_link[1].m_dst = m_link[0].m_src; + m_link[0].m_state = IDLE; + m_link[1].m_state = IDLE; + } +} + +bool PointToPointChannel::TransmitStart(Packet& p, + Ptr src, + const Time& txTime) +{ + NS_DEBUG ("PointToPointChannel::TransmitStart (" << &p << ", " << src << + ")"); + NS_DEBUG ("PointToPointChannel::TransmitStart (): UID is " << + p.GetUid () << ")"); + + NS_ASSERT(m_link[0].m_state != INITIALIZING); + NS_ASSERT(m_link[1].m_state != INITIALIZING); + + uint32_t wire = src == m_link[0].m_src ? 0 : 1; + + // Here we schedule the packet receive event at the receiver, + // which simplifies this model quite a bit. The channel just + // adds the propagation delay time + Simulator::Schedule (txTime + m_delay, + &PointToPointNetDevice::Receive, + m_link[wire].m_dst, p); + return true; +} + +uint32_t +PointToPointChannel::GetNDevices (void) const +{ + return m_nDevices; +} + +Ptr +PointToPointChannel::GetDevice (uint32_t i) const +{ + NS_ASSERT(i < 2); + return m_link[i].m_src; +} + +const DataRate& +PointToPointChannel::GetDataRate (void) +{ + return m_bps; +} + +const Time& +PointToPointChannel::GetDelay (void) +{ + return m_delay; +} + + +} // namespace ns3 diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/point-to-point-channel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/point-to-point-channel.h Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,127 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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 POINT_TO_POINT_CHANNEL_H +#define POINT_TO_POINT_CHANNEL_H + +#include +#include "ns3/channel.h" +#include "ns3/ptr.h" +#include "ns3/packet.h" +#include "ns3/nstime.h" +#include "ns3/data-rate.h" + +namespace ns3 { + +class PointToPointNetDevice; + +/** + * \brief Simple Point To Point Channel. + * + * This class represents a very simple point to point channel. Think full + * duplex RS-232 or RS-422 with null modem and no handshaking. There is no + * multi-drop capability on this channel -- there can be a maximum of two + * point-to-point net devices connected. Once we start talking about multi- + * drop, or CSMA, or some other sharing mechanism, things begin getting + * complicated quickly. Rather than invent some ad-hoc mechanism, we just + * Keep It Simple everywhere. + * + * When the channel is instaniated, the constructor takes parameters for + * a single speed, in bits per second, and a speed-of-light delay time as a + * Time object. Both directions use the same speed and delay time. + * + * There are two "wires" in the channel. The first device connected gets the + * [0] wire to transmit on. The second device gets the [1] wire. There is a + * state (IDLE, TRANSMITTING) associated with each wire. + */ +class PointToPointChannel : public Channel { +public: +// Each point to point link has exactly two net devices + static const int N_DEVICES = 2; + /** + * \brief Create a PointToPointChannel + * + * By default, you get a channel with the name "PointToPoint Channel" that + * has an "infitely" fast transmission speed and zero delay. + */ + PointToPointChannel (); + + /** + * \brief Create a PointToPointChannel + * + * \param bps The maximum bitrate of the channel + * \param delay Transmission delay through the channel + */ + PointToPointChannel (const DataRate& bps, const Time& delay); + + /** + * \brief Create a PointToPointChannel + * + * \param name the name of the channel for identification purposes + * \param bps The maximum bitrate of the channel + * \param delay Transmission delay through the channel + */ + PointToPointChannel (const std::string& name, + const DataRate& bps, const Time& delay); + + /** + * \brief Attach a given netdevice to this channel + * \param device pointer to the netdevice to attach to the channel + */ + void Attach (Ptr device); + bool TransmitStart (Packet& p, Ptr src, + const Time& txTime); + // Below two not needed + //bool TransmitEnd (Packet &p, Ptr src); + //void PropagationCompleteEvent(Packet p, Ptr src); + + + virtual uint32_t GetNDevices (void) const; + virtual Ptr GetDevice (uint32_t i) const; + + virtual const DataRate& GetDataRate (void); + virtual const Time& GetDelay (void); + +private: + DataRate m_bps; + Time m_delay; + int32_t m_nDevices; + + enum WireState + { + INITIALIZING, + IDLE, + TRANSMITTING, + PROPAGATING + }; + + class Link + { + public: + Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {} + WireState m_state; + Ptr m_src; + Ptr m_dst; + }; + + Link m_link[N_DEVICES]; +}; + +} // namespace ns3 + +#endif /* POINT_TO_POINT_CHANNEL_H */ diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/point-to-point-net-device.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/point-to-point-net-device.cc Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,275 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2005,2006 INRIA + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Craig Dowell + * Revised: George Riley + */ + +#include +#include +#include "ns3/debug.h" +#include "ns3/queue.h" +#include "ns3/simulator.h" +#include "ns3/composite-trace-resolver.h" +#include "p2p-net-device.h" +#include "p2p-channel.h" + +NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice"); + +namespace ns3 { + +DataRateDefaultValue PointToPointNetDevice::g_defaultRate( + "PointToPointLinkDataRate", + "The default data rate for point to point links", + DataRate ("10Mb/s")); + + PointToPointNetDevice::PointToPointNetDevice (Ptr node, + const DataRate& rate) +: + NetDevice(node, MacAddress (6)), + m_txMachineState (READY), + m_bps (rate), + m_tInterframeGap (Seconds(0)), + m_channel (0), + m_queue (0), + m_rxTrace () +{ + NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << node << ")"); + + // BUGBUG FIXME + // + // You _must_ support broadcast to get any sort of packet from the ARP layer. + EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff")); + EnableMulticast(); + EnablePointToPoint(); +} + +PointToPointNetDevice::~PointToPointNetDevice() +{ + NS_DEBUG ("PointToPointNetDevice::~PointToPointNetDevice ()"); + m_queue = 0; +} + +// +// Copy constructor for PointToPointNetDevice. +// +// We use the underlying NetDevice copy constructor to get the base class +// copied. These just remain as is (e.g. you get the same name, the same +// MAC address). If you need to fix them up, YOU, the copier need to do +// that. +// +// The things we need to be careful of are the channel, the queue and the +// trace callback. If the channel pointer is non-zero, we copy the pointer +// and add a reference. If the queue is non-zero, we copy it using the queue +// assignment operator. We don't mess with the trace -- we just reset it. +// We're assuming that the tracing will be set up after the topology creation +// phase and this won't actually matter. +// +// GFR Comments. Don't see where the "copy the pointer and add reference" +// stated above is done. Can original author please comment and/or fix. +// Shouldn't the queue pointer also bump the refcount? +PointToPointNetDevice::PointToPointNetDevice (const PointToPointNetDevice& nd) +: + NetDevice(nd), + m_txMachineState(READY), + m_bps (nd.m_bps), + m_tInterframeGap (nd.m_tInterframeGap), + m_channel(nd.m_channel), + m_queue(0), + m_rxTrace () +{ + NS_DEBUG ("PointToPointNetDevice::PointToPointNetDevice (" << &nd << ")"); + + if (nd.m_queue) + { + m_queue = nd.m_queue; + } + +} + + // GFR COmments...shouldn't this decrement the refcount instead + // of just nil-ing out the pointer? Don't understand this. +void PointToPointNetDevice::DoDispose() +{ + m_channel = 0; + NetDevice::DoDispose (); +} + +// +// Assignment operator for PointToPointNetDevice. +// +// +PointToPointNetDevice& +PointToPointNetDevice::operator= (const PointToPointNetDevice& nd) +{ + NS_DEBUG ("PointToPointNetDevice::operator= (" << &nd << ")"); + // FIXME. Not sure what to do here + // GFR Note. I would suggest dis-allowing netdevice assignment, + // as well as pass-by-value (ie. copy constructor). + // This resolves some of the questions above about copy constructors. + // Why should we ever copy or assign a net device? + return *this; +} + +void PointToPointNetDevice::SetDataRate(const DataRate& bps) +{ + m_bps = bps; +} + +void PointToPointNetDevice::SetInterframeGap(const Time& t) +{ + m_tInterframeGap = t; +} + +bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest) +{ + NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")"); + NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")"); + + // GFR Comment. Why is this an assertion? Can't a link legitimately + // "go down" during the simulation? Shouldn't we just wait for it + // to come back up? + NS_ASSERT (IsLinkUp ()); + +// +// This class simulates a point to point device. In the case of a serial +// link, this means that we're simulating something like a UART. +// +// +// If there's a transmission in progress, we enque the packet for later +// trnsmission; otherwise we send it now. + if (m_txMachineState == READY) + { + return TransmitStart (p); + } + else + { + return m_queue->Enqueue(p); + } +} + + bool +PointToPointNetDevice::TransmitStart (Packet &p) +{ + NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")"); + NS_DEBUG ( + "PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")"); +// +// This function is called to start the process of transmitting a packet. +// We need to tell the channel that we've started wiggling the wire and +// schedule an event that will be executed when the transmission is complete. +// + NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit"); + m_txMachineState = BUSY; + Time txTime = Seconds (m_bps.CalculateTxTime(p.GetSize())); + Time txCompleteTime = txTime + m_tInterframeGap; + + NS_DEBUG ("PointToPointNetDevice::TransmitStart (): " << + "Schedule TransmitCompleteEvent in " << + txCompleteTime.GetSeconds () << "sec"); + // Schedule the tx complete event + Simulator::Schedule (txCompleteTime, + &PointToPointNetDevice::TransmitComplete, + this); + return m_channel->TransmitStart(p, this, txTime); +} + +void PointToPointNetDevice::TransmitComplete (void) +{ + NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent ()"); +// +// This function is called to finish the process of transmitting a packet. +// We need to tell the channel that we've stopped wiggling the wire and +// get the next packet from the queue. If the queue is empty, we are +// done, otherwise transmit the next packet. +// + NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting"); + m_txMachineState = READY; + Packet p; + if (!m_queue->Dequeue(p)) return; // Nothing to do at this point + TransmitStart(p); +} + +TraceResolver* PointToPointNetDevice::DoCreateTraceResolver ( + TraceContext const &context) +{ + CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + resolver->Add ("queue", + MakeCallback (&Queue::CreateTraceResolver, PeekPointer (m_queue)), + PointToPointNetDevice::QUEUE); + resolver->Add ("rx", + m_rxTrace, + PointToPointNetDevice::RX); + return resolver; +} + +bool PointToPointNetDevice::Attach (Ptr ch) +{ + NS_DEBUG ("PointToPointNetDevice::Attach (" << &ch << ")"); + + m_channel = ch; + + m_channel->Attach(this); + m_bps = m_channel->GetDataRate (); + // GFR Comment. Below is definitely wrong. Interframe gap + // is unrelated to channel delay. + //m_tInterframeGap = m_channel->GetDelay (); + + /* + * For now, this device is up whenever a channel is attached to it. + * In fact, it should become up only when the second device + * is attached to the channel. So, there should be a way for + * a PointToPointChannel to notify both of its attached devices + * that the channel is 'complete', hence that the devices are + * up, hence that they can call NotifyLinkUp. + */ + NotifyLinkUp (); + return true; +} + +void PointToPointNetDevice::AddQueue (Ptr q) +{ + NS_DEBUG ("PointToPointNetDevice::AddQueue (" << q << ")"); + + m_queue = q; +} + +void PointToPointNetDevice::Receive (Packet& p) +{ + NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")"); + + m_rxTrace (p); + ForwardUp (p); +} + +Ptr PointToPointNetDevice::GetQueue(void) const +{ + return m_queue; +} + +Ptr PointToPointNetDevice::DoGetChannel(void) const +{ + return m_channel; +} + +bool PointToPointNetDevice::DoNeedsArp (void) const +{ + return false; +} + +} // namespace ns3 diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/point-to-point-net-device.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/point-to-point-net-device.h Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,310 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 University of Washington + * + * 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: Craig Dowell + */ + +#ifndef POINT_TO_POINT_NET_DEVICE_H +#define POINT_TO_POINT_NET_DEVICE_H + +#include +#include "ns3/mac-address.h" +#include "ns3/node.h" +#include "ns3/net-device.h" +#include "ns3/callback.h" +#include "ns3/packet.h" +#include "ns3/callback-trace-source.h" +#include "ns3/nstime.h" +#include "ns3/data-rate.h" +#include "ns3/default-value.h" +#include "ns3/ptr.h" + +namespace ns3 { + +class Queue; +class PointToPointChannel; + +/** + * \class PointToPointNetDevice + * \brief A Device for a Point to Point Network Link. + * + * Ns-3 takes a four-layer view of a protocol stack. This is the same model + * that TCP uses. In this view, layers 5-7 of the OSI reference model are + * grouped together into an application layer; layer four (transport / TCP) is + * broken out; layer three (network / IP) is broken out; and layers 1-2 are + * grouped together. We call this grouping of layers one and two a NetDevice + * and represent it as a class in the system. + * + * The NetDevice class is specialized according to the needs of the specific + * kind of network link. In this case, the link is a PointToPoint link. The + * PointToPoint link is a family of classes that includes this class, the + * PointToPointNetDevice, a PointToPointChannel class that represents the + * actual medium across which bits are sent, a PointToPointIpv4Interface class + * that provides the hook to tie a general purpose node to this specific + * link, and finally, a PointToPointTopology object that is responsible for + * putting all of the pieces together. + * + * This is the PointToPointNetDevice class that represents, essentially, the + * PC card that is used to connect to the PointToPoint network. + */ +class PointToPointNetDevice : public NetDevice { +public: + /** + * Enumeration of the types of traces supported in the class. + * + */ + enum TraceType { + QUEUE, /**< Trace queue events on the attached queue */ + RX, /**< Trace packet reception events (from the channel) */ + }; + /** + * Construct a PointToPointNetDevice + * + * This is the constructor for the PointToPointNetDevice. It takes as a + * parameter the Node to which this device is connected. Ownership of the + * Node pointer is not implied and the node must not be deleded. + * + * @see PointToPointTopology::AddPointToPointLink () + * @param node the Node to which this device is connected. + */ + PointToPointNetDevice (Ptr node, + const DataRate& = g_defaultRate.GetValue()); + /** + * Copy Construct a PointToPointNetDevice + * + * This is the copy constructor for the PointToPointNetDevice. This is + * primarily used in topology creation. + * + * @see PointToPointTopology::AddPointToPointLink () + * @param nd the object to be copied + */ + PointToPointNetDevice (const PointToPointNetDevice& nd); + /** + * Destroy a PointToPointNetDevice + * + * This is the destructor for the PointToPointNetDevice. + */ + virtual ~PointToPointNetDevice(); + /** + * Assignment Operator for a PointToPointNetDevice + * + * This is the assignment operator for the PointToPointNetDevice. This is + * to allow + * + * @param nd the object to be copied + */ + PointToPointNetDevice& operator= (const PointToPointNetDevice& nd); + /** + * Set the Data Rate used for transmission of packets. The data rate is + * set in the Attach () method from the corresponding field in the channel + * to which the device is attached. It can be overridden using this method. + * + * @see Attach () + * @param bps the data rate at which this object operates + */ + void SetDataRate(const DataRate& bps); + /** + * Set the inteframe gap used to separate packets. The interframe gap + * defines the minimum space required between packets sent by this device. + * It is usually set in the Attach () method based on the speed of light + * delay of the channel to which the device is attached. It can be + * overridden using this method if desired. + * + * @see Attach () + * @param t the interframe gap time + */ + void SetInterframeGap(const Time& t); + /** + * Attach the device to a channel. + * + * The PointToPointTopology object creates a PointToPointChannel and two + * PointtoPointNetDevices. In order to introduce these components to each + * other, the topology object calls Attach () on each PointToPointNetDevice. + * Inside this method, the Net Device calls out to the PointToPointChannel + * to introduce itself. + * + * @see PointToPointTopology::AddPointToPointLink () + * @see SetDataRate () + * @see SetInterframeGap () + * @param ch a pointer to the channel to which this object is being attached. + */ + bool Attach(Ptr ch); + /** + * Attach a queue to the PointToPointNetDevice. + * + * The PointToPointNetDevice "owns" a queue. This queue is created by the + * PointToPointTopology object and implements a queueing method such as + * DropTail or RED. The PointToPointNetDevice assumes ownership of this + * queue and must delete it when the device is destroyed. + * + * @see PointToPointTopology::AddPointToPointLink () + * @see Queue + * @see DropTailQueue + * @param queue a pointer to the queue for which object is assuming + * ownership. + */ + void AddQueue(Ptr queue); + /** + * Receive a packet from a connected PointToPointChannel. + * + * The PointToPointNetDevice receives packets from its connected channel + * and forwards them up the protocol stack. This is the public method + * used by the channel to indicate that the last bit of a packet has + * arrived at the device. + * + * @see PointToPointChannel + * @param p a reference to the received packet + */ + void Receive (Packet& p); +protected: + virtual void DoDispose (void); + /** + * Get a copy of the attached Queue. + * + * This method is provided for any derived class that may need to get + * direct access to the underlying queue. + * + * @see PointToPointTopology + * @returns a pointer to the queue. + */ + Ptr GetQueue(void) const; + /** + * Get a copy of the attached Channel + * + * This method is provided for any derived class that may need to get + * direct access to the connected channel + * + * @see PointToPointChannel + * @returns a pointer to the channel + */ + virtual Ptr DoGetChannel(void) const; + /** + * Set a new default data rate + * @param Data rate to set for new default + */ + static void SetDefaultRate(const DataRate&); + + /** + * Get the current default rate. + * @returns a const reference to current default + */ + + static const DataRate& GetDefaultRate(); + +private: + /** + * Send a Packet Down the Wire. + * + * The SendTo method is defined as the standard way that the level three + * protocol uses to tell a NetDevice to send a packet. SendTo is declared + * as abstract in the NetDevice class and we declare it here. + * + * @see NetDevice + * @param p a reference to the packet to send + * @param dest a reference to the MacAddress of the destination device + * @returns true if success, false on failure + */ + virtual bool SendTo (Packet& p, const MacAddress& dest); + /** + * Start Sending a Packet Down the Wire. + * + * The TransmitStart method is the method that is used internally in the + * PointToPointNetDevice to begin the process of sending a packet out on + * the channel. The corresponding method is called on the channel to let + * it know that the physical device this class represents has virually + * started sending signals. An event is scheduled for the time at which + * the bits have been completely transmitted. + * + * @see PointToPointChannel::TransmitStart () + * @see TransmitCompleteEvent () + * @param p a reference to the packet to send + * @returns true if success, false on failure + */ + bool TransmitStart (Packet &p); + /** + * Stop Sending a Packet Down the Wire and Begin the Interframe Gap. + * + * The TransmitComplete method is used internally to finish the process + * of sending a packet out on the channel. + * + */ + void TransmitComplete(void); + /** + * Create a Trace Resolver for events in the net device. + * + * @see class TraceResolver + */ + virtual TraceResolver* DoCreateTraceResolver (TraceContext const &context); + virtual bool DoNeedsArp (void) const; + /** + * Enumeration of the states of the transmit machine of the net device. + */ + enum TxMachineState + { + READY, /**< The transmitter is ready to begin transmission of a packet */ + BUSY /**< The transmitter is busy transmitting a packet */ + }; + /** + * The state of the Net Device transmit state machine. + * @see TxMachineState + */ + TxMachineState m_txMachineState; + /** + * The data rate that the Net Device uses to simulate packet transmission + * timing. + * @see class DataRate + */ + DataRate m_bps; + /** + * The interframe gap that the Net Device uses to throttle packet + * transmission + * @see class Time + */ + Time m_tInterframeGap; + /** + * The PointToPointChannel to which this PointToPointNetDevice has been + * attached. + * @see class PointToPointChannel + */ + Ptr m_channel; + /** + * The Queue which this PointToPointNetDevice uses as a packet source. + * Management of this Queue has been delegated to the PointToPointNetDevice + * and it has the responsibility for deletion. + * @see class Queue + * @see class DropTailQueue + */ + Ptr m_queue; + /** + * The trace source for the packet reception events that the device can + * fire. + * + * @see class CallBackTraceSource + * @see class TraceResolver + */ + CallbackTraceSource m_rxTrace; + /** + * Default data rate. Used for all newly created p2p net devices + */ + static DataRateDefaultValue g_defaultRate; + +}; + +}; // namespace ns3 + +#endif // POINT_TO_POINT_NET_DEVICE_H + diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/point-to-point-topology.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/point-to-point-topology.cc Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,172 @@ +/* -*- 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 +// +// Author: George F. Riley +// + +// +// Topology helper for ns3. +// George F. Riley, Georgia Tech, Spring 2007 + +#include +#include "ns3/assert.h" +#include "ns3/debug.h" +#include "ns3/fatal-error.h" +#include "ns3/nstime.h" +#include "ns3/internet-node.h" +#include "ns3/ipv4-address.h" +#include "ns3/ipv4.h" +#include "ns3/queue.h" + +#include "p2p-channel.h" +#include "p2p-net-device.h" +#include "p2p-topology.h" + +namespace ns3 { + +Ptr +PointToPointTopology::AddPointToPointLink( + Ptr n1, + Ptr n2, + const DataRate& bps, + const Time& delay) +{ + Ptr channel = Create (bps, delay); + + Ptr net1 = Create (n1); + + Ptr q = Queue::CreateDefault (); + net1->AddQueue(q); + net1->Attach (channel); + + Ptr net2 = Create (n2); + + q = Queue::CreateDefault (); + net2->AddQueue(q); + net2->Attach (channel); + + return channel; +} + +void +PointToPointTopology::AddIpv4Addresses( + Ptr chan, + Ptr n1, const Ipv4Address& addr1, + Ptr n2, const Ipv4Address& addr2) +{ + + // Duplex link is assumed to be subnetted as a /30 + // May run this unnumbered in the future? + Ipv4Mask netmask("255.255.255.252"); + NS_ASSERT (netmask.IsMatch(addr1,addr2)); + + // The PointToPoint channel is used to find the relevant NetDevices + NS_ASSERT (chan->GetNDevices () == 2); + Ptr nd1 = chan->GetDevice (0); + Ptr nd2 = chan->GetDevice (1); + // Make sure that nd1 belongs to n1 and nd2 to n2 + if ( (nd1->GetNode ()->GetId () == n2->GetId () ) && + (nd2->GetNode ()->GetId () == n1->GetId () ) ) + { + std::swap(nd1, nd2); + } + NS_ASSERT (nd1->GetNode ()->GetId () == n1->GetId ()); + NS_ASSERT (nd2->GetNode ()->GetId () == n2->GetId ()); + + Ptr ip1 = n1->QueryInterface (Ipv4::iid); + uint32_t index1 = ip1->AddInterface (nd1); + + ip1->SetAddress (index1, addr1); + ip1->SetNetworkMask (index1, netmask); + ip1->SetUp (index1); + + Ptr ip2 = n2->QueryInterface (Ipv4::iid); + uint32_t index2 = ip2->AddInterface (nd2); + + ip2->SetAddress (index2, addr2); + ip2->SetNetworkMask (index2, netmask); + ip2->SetUp (index2); + +} + +void +PointToPointTopology::AddIpv4Routes ( + Ptr n1, Ptr n2, Ptr chan) +{ + // The PointToPoint channel is used to find the relevant NetDevices + NS_ASSERT (chan->GetNDevices () == 2); + Ptr nd1 = chan->GetDevice (0); + Ptr nd2 = chan->GetDevice (1); + + // Assert that n1 is the Node owning one of the two NetDevices + // and make sure that nd1 corresponds to it + if (nd1->GetNode ()->GetId () == n1->GetId ()) + { + ; // Do nothing + } + else if (nd2->GetNode ()->GetId () == n1->GetId ()) + { + std::swap(nd1, nd2); + } + else + { + NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); + } + + // Assert that n2 is the Node owning one of the two NetDevices + // and make sure that nd2 corresponds to it + if (nd2->GetNode ()->GetId () != n2->GetId ()) + { + NS_FATAL_ERROR("P2PTopo: Node does not contain an interface on Channel"); + } + + // Assert that both are Ipv4 nodes + Ptr ip1 = nd1->GetNode ()->QueryInterface (Ipv4::iid); + Ptr ip2 = nd2->GetNode ()->QueryInterface (Ipv4::iid); + NS_ASSERT(ip1 != 0 && ip2 != 0); + + // Get interface indexes for both nodes corresponding to the right channel + uint32_t index1 = 0; + bool found = false; + for (uint32_t i = 0; i < ip1->GetNInterfaces (); i++) + { + if (ip1 ->GetNetDevice (i) == nd1) + { + index1 = i; + found = true; + } + } + NS_ASSERT(found); + + uint32_t index2 = 0; + found = false; + for (uint32_t i = 0; i < ip2->GetNInterfaces (); i++) + { + if (ip2 ->GetNetDevice (i) == nd2) + { + index2 = i; + found = true; + } + } + NS_ASSERT(found); + + ip1->AddHostRouteTo (ip2-> GetAddress (index2), index1); + ip2->AddHostRouteTo (ip1-> GetAddress (index1), index2); +} + +} // namespace ns3 + diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/point-to-point-topology.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/point-to-point-topology.h Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,87 @@ +/* -*- 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 +// +// Author: George F. Riley +// +// Topology helper for ns3. +// George F. Riley, Georgia Tech, Spring 2007 +#ifndef __POINT_TO_POINT_TOPOLOGY_H__ +#define __POINT_TO_POINT_TOPOLOGY_H__ + +#include "ns3/ptr.h" + +// The topology class consists of only static methods thar are used to +// create the topology and data flows for an ns3 simulation + +namespace ns3 { + +class PointToPointChannel; +class Node; +class IPAddr; +class DataRate; +class Queue; + +/** + * \brief A helper class to create Topologies based on the + * ns3::PointToPointNetDevice and ns3::PointToPointChannel objects. + */ +class PointToPointTopology { +public: + /** + * \param n1 Node + * \param n2 Node + * \param dataRate Maximum transmission link rate + * \param delay one-way propagation delay + * \return Pointer to the underlying PointToPointChannel + * + * Add a full-duplex point-to-point link between two nodes + * and attach PointToPointNetDevices to the resulting + * PointToPointChannel. + */ + static Ptr AddPointToPointLink( + Ptr n1, Ptr n2, const DataRate& dataRate, const Time& delay); + + /** + * \param chan PointToPointChannel to use + * \param n1 Node + * \param addr1 Ipv4 Address for n1 + * \param n2 Node + * \param addr2 Ipv4 Address for n2 + * + * Add Ipv4Addresses to the Ipv4 interfaces associated with the + * two PointToPointNetDevices on the provided PointToPointChannel + */ + static void AddIpv4Addresses( + Ptr chan, + Ptr n1, const Ipv4Address& addr1, + Ptr n2, const Ipv4Address& addr2); + + /** + * \param channel PointToPointChannel to use + * \param n1 Node + * \param n2 Node + * + * For the given PointToPointChannel, for each Node, add an + * IPv4 host route to the IPv4 address of the peer node. + */ + static void AddIpv4Routes (Ptr n1, Ptr n2, Ptr channel); +}; + +} // namespace ns3 + +#endif + diff -r 7a81f1ef8c74 -r 421c3d971423 src/devices/point-to-point/wscript --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/devices/point-to-point/wscript Wed Jul 18 08:06:43 2007 -0700 @@ -0,0 +1,20 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + + +def build(bld): + pointtopoint = bld.create_obj('cpp', 'shlib') + pointtopoint.name = 'ns3-point-to-point' + pointtopoint.target = pointtopoint.name + pointtopoint.uselib_local = ['ns3-node'] + pointtopoint.source = [ + 'point-to-point-net-device.cc', + 'point-to-point-channel.cc', + 'point-to-point-topology.cc', + ] + headers = bld.create_obj('ns3header') + headers.source = [ + 'point-to-point-net-device.h', + 'point-to-point-channel.h', + 'point-to-point-topology.h', + ] + diff -r 7a81f1ef8c74 -r 421c3d971423 src/wscript --- a/src/wscript Wed Jul 18 09:27:22 2007 -0500 +++ b/src/wscript Wed Jul 18 08:06:43 2007 -0700 @@ -15,7 +15,7 @@ all_modules = [ 'simulator', 'node', 'internet-node', - 'devices/p2p', + 'devices/point-to-point', 'applications', ]