From aaa8a45658edaaebc9410f96d56c549b39be1b3c Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Thu, 9 Aug 2007 15:56:28 -0700 Subject: [PATCH] rename to csma --- examples/csma-one-subnet.cc | 166 ++++++++++++++++++ ...packet-socket.cc => csma-packet-socket.cc} | 28 +-- examples/wscript | 16 +- src/devices/csma-cd/wscript | 21 --- src/devices/{csma-cd => csma}/backoff.cc | 0 src/devices/{csma-cd => csma}/backoff.h | 0 .../csma-channel.cc} | 120 ++++++------- .../csma-cd-channel.h => csma/csma-channel.h} | 48 ++--- .../csma-ipv4-topology.cc} | 43 +++-- .../csma-ipv4-topology.h} | 60 +++---- .../csma-net-device.cc} | 132 +++++++------- .../csma-net-device.h} | 94 +++++----- .../csma-topology.cc} | 36 ++-- .../csma-topology.h} | 34 ++-- src/devices/csma/wscript | 19 ++ src/wscript | 2 +- 16 files changed, 492 insertions(+), 327 deletions(-) create mode 100644 examples/csma-one-subnet.cc rename examples/{csma-cd-packet-socket.cc => csma-packet-socket.cc} (81%) delete mode 100644 src/devices/csma-cd/wscript rename src/devices/{csma-cd => csma}/backoff.cc (100%) rename src/devices/{csma-cd => csma}/backoff.h (100%) rename src/devices/{csma-cd/csma-cd-channel.cc => csma/csma-channel.cc} (63%) rename src/devices/{csma-cd/csma-cd-channel.h => csma/csma-channel.h} (90%) rename src/devices/{csma-cd/csma-cd-ipv4-topology.cc => csma/csma-ipv4-topology.cc} (73%) rename src/devices/{csma-cd/csma-cd-ipv4-topology.h => csma/csma-ipv4-topology.h} (61%) rename src/devices/{csma-cd/csma-cd-net-device.cc => csma/csma-net-device.cc} (75%) rename src/devices/{csma-cd/csma-cd-net-device.h => csma/csma-net-device.h} (84%) rename src/devices/{csma-cd/csma-cd-topology.cc => csma/csma-topology.cc} (67%) rename src/devices/{csma-cd/csma-cd-topology.h => csma/csma-topology.h} (80%) create mode 100644 src/devices/csma/wscript diff --git a/examples/csma-one-subnet.cc b/examples/csma-one-subnet.cc new file mode 100644 index 000000000..dc1bd58c0 --- /dev/null +++ b/examples/csma-one-subnet.cc @@ -0,0 +1,166 @@ +/* -*- 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 + */ + +// Port of ns-2/tcl/ex/simple.tcl to ns-3 +// +// Network topology +// +// n0 n1 n2 n3 +// | | | | +// ===================== +// +// - CBR/UDP flows from n0 to n1, and from n3 to n0 +// - 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 "csma-one-subnet.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/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 n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + + // We create the channels first without any IP addressing information + Ptr channel0 = + CsmaTopology::CreateCsmaChannel( + DataRate(5000000), MilliSeconds(2)); + + uint32_t n0ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n0, channel0, + Eui48Address("10:54:23:54:23:50")); + uint32_t n1ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n1, channel0, + Eui48Address("10:54:23:54:23:51")); + uint32_t n2ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n2, channel0, + Eui48Address("10:54:23:54:23:52")); + uint32_t n3ifIndex = CsmaIpv4Topology::AddIpv4CsmaNode (n3, channel0, + Eui48Address("10:54:23:54:23:53")); + + // Later, we add IP addresses. + CsmaIpv4Topology::AddIpv4Address ( + n0, n0ifIndex, Ipv4Address("10.1.1.1"), Ipv4Mask("255.255.255.0")); + + CsmaIpv4Topology::AddIpv4Address ( + n1, n1ifIndex, Ipv4Address("10.1.1.2"), Ipv4Mask("255.255.255.0")); + + CsmaIpv4Topology::AddIpv4Address ( + n2, n2ifIndex, Ipv4Address("10.1.1.3"), Ipv4Mask("255.255.255.0")); + + CsmaIpv4Topology::AddIpv4Address ( + n3, n3ifIndex, Ipv4Address("10.1.1.4"), 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 ooff = Create ( + n0, + InetSocketAddress ("10.1.1.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 n0, starting at time 1.1 seconds + ooff = Create ( + n3, + InetSocketAddress ("10.1.1.1", 80), + "Udp", + ConstantVariable(1), + ConstantVariable(0)); + // Start the application + ooff->Start(Seconds(1.1)); + ooff->Stop (Seconds(10.0)); + + // Configure tracing of all enqueue, dequeue, and NetDevice receive events + // Trace output will be sent to the csma-one-subnet.tr file + AsciiTrace asciitrace ("csma-one-subnet.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-- + // and can be read by the "tcpdump -r" command (use "-tt" option to + // display timestamps correctly) + PcapTrace pcaptrace ("csma-one-subnet.pcap"); + pcaptrace.TraceAllIp (); + + Simulator::Run (); + + Simulator::Destroy (); +} diff --git a/examples/csma-cd-packet-socket.cc b/examples/csma-packet-socket.cc similarity index 81% rename from examples/csma-cd-packet-socket.cc rename to examples/csma-packet-socket.cc index ed1976645..9db207fbe 100644 --- a/examples/csma-cd-packet-socket.cc +++ b/examples/csma-packet-socket.cc @@ -26,7 +26,7 @@ // - 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 "csma-cd-one-subnet.tr" +// - Tracing of queues and packet receptions to file "csma-one-subnet.tr" #include #include @@ -46,8 +46,8 @@ #include "ns3/ascii-trace.h" #include "ns3/pcap-trace.h" #include "ns3/internet-node.h" -#include "ns3/csma-cd-channel.h" -#include "ns3/csma-cd-net-device.h" +#include "ns3/csma-channel.h" +#include "ns3/csma-net-device.h" #include "ns3/eui48-address.h" #include "ns3/packet-socket-address.h" #include "ns3/socket.h" @@ -56,10 +56,10 @@ using namespace ns3; -static Ptr -CreateCsmaCdDevice (Ptr node, Ptr channel) +static Ptr +CreateCsmaDevice (Ptr node, Ptr channel) { - Ptr device = Create (node); + Ptr device = Create (node); device->Attach (channel); Ptr queue = Queue::CreateDefault (); device->AddQueue (queue); @@ -78,14 +78,14 @@ int main (int argc, char *argv[]) Ptr n2 = Create (); Ptr n3 = Create (); - // create the shared medium used by all csma/cd devices. - Ptr channel = Create (DataRate(5000000), MilliSeconds(2)); + // create the shared medium used by all csma devices. + Ptr channel = Create (DataRate(5000000), MilliSeconds(2)); // use a helper function to connect our nodes to the shared channel. - Ptr n0If = CreateCsmaCdDevice (n0, channel); - Ptr n1If = CreateCsmaCdDevice (n1, channel); - Ptr n2If = CreateCsmaCdDevice (n2, channel); - Ptr n3If = CreateCsmaCdDevice (n3, channel); + Ptr n0If = CreateCsmaDevice (n0, channel); + Ptr n1If = CreateCsmaDevice (n1, channel); + Ptr n2If = CreateCsmaDevice (n2, channel); + Ptr n3If = CreateCsmaDevice (n3, channel); // create the address which identifies n1 from n0 @@ -125,8 +125,8 @@ int main (int argc, char *argv[]) ooff->Stop (Seconds(10.0)); // Configure tracing of all enqueue, dequeue, and NetDevice receive events - // Trace output will be sent to the csma-cd-packet-socket.tr file - AsciiTrace asciitrace ("csma-cd-packet-socket.tr"); + // Trace output will be sent to the csma-packet-socket.tr file + AsciiTrace asciitrace ("csma-packet-socket.tr"); asciitrace.TraceAllNetDeviceRx (); asciitrace.TraceAllQueues (); diff --git a/examples/wscript b/examples/wscript index 93e8f83d6..e7559756f 100644 --- a/examples/wscript +++ b/examples/wscript @@ -3,15 +3,17 @@ def build(bld): obj = bld.create_ns3_program('simple-global-routing', - ['point-to-point', 'internet-node', 'global-routing']) + ['point-to-point', 'internet-node', 'global-routing']) obj.source = 'simple-global-routing.cc' - obj = bld.create_ns3_program('simple-point-to-point', ['point-to-point', 'internet-node']) + obj = bld.create_ns3_program('simple-point-to-point', + ['point-to-point', 'internet-node']) obj.source = 'simple-point-to-point.cc' - obj = bld.create_ns3_program('csma-cd-one-subnet', ['csma-cd', 'internet-node']) - obj.source = 'csma-cd-one-subnet.cc' - - obj = bld.create_ns3_program('csma-cd-packet-socket', ['csma-cd', 'internet-node']) - obj.source = 'csma-cd-packet-socket.cc' + obj = bld.create_ns3_program('csma-one-subnet', + ['csma', 'internet-node']) + obj.source = 'csma-one-subnet.cc' + obj = bld.create_ns3_program('csma-packet-socket', + ['csma', 'internet-node']) + obj.source = 'csma-packet-socket.cc' diff --git a/src/devices/csma-cd/wscript b/src/devices/csma-cd/wscript deleted file mode 100644 index e82c41b58..000000000 --- a/src/devices/csma-cd/wscript +++ /dev/null @@ -1,21 +0,0 @@ -## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- - - -def build(bld): - obj = bld.create_ns3_module('csma-cd', ['node']) - obj.source = [ - 'backoff.cc', - 'csma-cd-net-device.cc', - 'csma-cd-channel.cc', - 'csma-cd-topology.cc', - 'csma-cd-ipv4-topology.cc', - ] - headers = bld.create_obj('ns3header') - headers.source = [ - 'backoff.h', - 'csma-cd-net-device.h', - 'csma-cd-channel.h', - 'csma-cd-topology.h', - 'csma-cd-ipv4-topology.h', - ] - diff --git a/src/devices/csma-cd/backoff.cc b/src/devices/csma/backoff.cc similarity index 100% rename from src/devices/csma-cd/backoff.cc rename to src/devices/csma/backoff.cc diff --git a/src/devices/csma-cd/backoff.h b/src/devices/csma/backoff.h similarity index 100% rename from src/devices/csma-cd/backoff.h rename to src/devices/csma/backoff.h diff --git a/src/devices/csma-cd/csma-cd-channel.cc b/src/devices/csma/csma-channel.cc similarity index 63% rename from src/devices/csma-cd/csma-cd-channel.cc rename to src/devices/csma/csma-channel.cc index 30c84deda..9ba42d854 100644 --- a/src/devices/csma-cd/csma-cd-channel.cc +++ b/src/devices/csma/csma-channel.cc @@ -19,60 +19,60 @@ * Author: Emmanuelle Laprise */ -#include "csma-cd-channel.h" -#include "csma-cd-net-device.h" +#include "csma-channel.h" +#include "csma-net-device.h" #include "ns3/packet.h" #include "ns3/simulator.h" #include "ns3/debug.h" -NS_DEBUG_COMPONENT_DEFINE ("CsmaCdChannel"); +NS_DEBUG_COMPONENT_DEFINE ("CsmaChannel"); namespace ns3 { -CsmaCdDeviceRec::CsmaCdDeviceRec() +CsmaDeviceRec::CsmaDeviceRec() { active = false; } -CsmaCdDeviceRec::CsmaCdDeviceRec(Ptr device) +CsmaDeviceRec::CsmaDeviceRec(Ptr device) { devicePtr = device; active = true; } bool -CsmaCdDeviceRec::IsActive() { +CsmaDeviceRec::IsActive() { return active; } // -// By default, you get a channel with the name "CsmaCd Channel" that +// By default, you get a channel with the name "Csma Channel" that // has an "infitely" fast transmission speed and zero delay. -CsmaCdChannel::CsmaCdChannel() +CsmaChannel::CsmaChannel() : - Channel ("CsmaCd Channel"), + Channel ("Csma Channel"), m_bps (DataRate(0xffffffff)), m_delay (Seconds(0)) { - NS_DEBUG("CsmaCdChannel::CsmaCdChannel ()"); + NS_DEBUG("CsmaChannel::CsmaChannel ()"); Init(); } -CsmaCdChannel::CsmaCdChannel( +CsmaChannel::CsmaChannel( const DataRate& bps, const Time& delay) : - Channel ("CsmaCd Channel"), + Channel ("Csma Channel"), m_bps (bps), m_delay (delay) { - NS_DEBUG("CsmaCdChannel::CsmaCdChannel (" << Channel::GetName() + NS_DEBUG("CsmaChannel::CsmaChannel (" << Channel::GetName() << ", " << bps.GetBitRate() << ", " << delay << ")"); Init(); } -CsmaCdChannel::CsmaCdChannel( +CsmaChannel::CsmaChannel( const std::string& name, const DataRate& bps, const Time& delay) @@ -81,35 +81,35 @@ CsmaCdChannel::CsmaCdChannel( m_bps (bps), m_delay (delay) { - NS_DEBUG("CsmaCdChannel::CsmaCdChannel (" << name << ", " << + NS_DEBUG("CsmaChannel::CsmaChannel (" << name << ", " << bps.GetBitRate() << ", " << delay << ")"); Init(); } -void CsmaCdChannel::Init() { +void CsmaChannel::Init() { m_state = IDLE; m_deviceList.clear(); } int32_t -CsmaCdChannel::Attach(Ptr device) +CsmaChannel::Attach(Ptr device) { - NS_DEBUG("CsmaCdChannel::Attach (" << device << ")"); + NS_DEBUG("CsmaChannel::Attach (" << device << ")"); NS_ASSERT(device != 0); - CsmaCdDeviceRec rec(device); + CsmaDeviceRec rec(device); m_deviceList.push_back(rec); return (m_deviceList.size() - 1); } bool -CsmaCdChannel::Reattach(Ptr device) +CsmaChannel::Reattach(Ptr device) { - NS_DEBUG("CsmaCdChannel::Reattach (" << device << ")"); + NS_DEBUG("CsmaChannel::Reattach (" << device << ")"); NS_ASSERT(device != 0); - std::vector::iterator it; + std::vector::iterator it; for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) { if (it->devicePtr == device) @@ -129,9 +129,9 @@ CsmaCdChannel::Reattach(Ptr device) } bool -CsmaCdChannel::Reattach(uint32_t deviceId) +CsmaChannel::Reattach(uint32_t deviceId) { - NS_DEBUG("CsmaCdChannel::Reattach (" << deviceId << ")"); + NS_DEBUG("CsmaChannel::Reattach (" << deviceId << ")"); if (deviceId < m_deviceList.size()) { return false; @@ -149,15 +149,15 @@ CsmaCdChannel::Reattach(uint32_t deviceId) } bool -CsmaCdChannel::Detach(uint32_t deviceId) +CsmaChannel::Detach(uint32_t deviceId) { - NS_DEBUG("CsmaCdChannel::Detach (" << deviceId << ")"); + NS_DEBUG("CsmaChannel::Detach (" << deviceId << ")"); if (deviceId < m_deviceList.size()) { if (!m_deviceList[deviceId].active) { - NS_DEBUG("CsmaCdChannel::Detach Device is already detached (" + NS_DEBUG("CsmaChannel::Detach Device is already detached (" << deviceId << ")"); return false; } @@ -165,7 +165,7 @@ CsmaCdChannel::Detach(uint32_t deviceId) m_deviceList[deviceId].active = false; if ((m_state == TRANSMITTING) && (m_currentSrc == deviceId)) { - NS_DEBUG("CsmaCdChannel::Detach Device is currently" + NS_DEBUG("CsmaChannel::Detach Device is currently" << "transmitting (" << deviceId << ")"); // Here we will need to place a warning in the packet } @@ -179,12 +179,12 @@ CsmaCdChannel::Detach(uint32_t deviceId) } bool -CsmaCdChannel::Detach(Ptr device) +CsmaChannel::Detach(Ptr device) { - NS_DEBUG("CsmaCdChannel::Detach (" << device << ")"); + NS_DEBUG("CsmaChannel::Detach (" << device << ")"); NS_ASSERT(device != 0); - std::vector::iterator it; + std::vector::iterator it; for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) { if ((it->devicePtr == device) && (it->active)) @@ -197,27 +197,27 @@ CsmaCdChannel::Detach(Ptr device) } bool -CsmaCdChannel::TransmitStart(Packet& p, uint32_t srcId) +CsmaChannel::TransmitStart(Packet& p, uint32_t srcId) { - NS_DEBUG ("CsmaCdChannel::TransmitStart (" << &p << ", " << srcId + NS_DEBUG ("CsmaChannel::TransmitStart (" << &p << ", " << srcId << ")"); - NS_DEBUG ("CsmaCdChannel::TransmitStart (): UID is " << + NS_DEBUG ("CsmaChannel::TransmitStart (): UID is " << p.GetUid () << ")"); if (m_state != IDLE) { - NS_DEBUG("CsmaCdChannel::TransmitStart (): state is not IDLE"); + NS_DEBUG("CsmaChannel::TransmitStart (): state is not IDLE"); return false; } if (!IsActive(srcId)) { - NS_DEBUG("CsmaCdChannel::TransmitStart (): ERROR: Seclected " + NS_DEBUG("CsmaChannel::TransmitStart (): ERROR: Seclected " << "source is not currently attached to network"); return false; } - NS_DEBUG("CsmaCdChannel::TransmitStart (): switch to TRANSMITTING"); + NS_DEBUG("CsmaChannel::TransmitStart (): switch to TRANSMITTING"); m_currentPkt = p; m_currentSrc = srcId; m_state = TRANSMITTING; @@ -225,17 +225,17 @@ CsmaCdChannel::TransmitStart(Packet& p, uint32_t srcId) } bool -CsmaCdChannel::IsActive(uint32_t deviceId) +CsmaChannel::IsActive(uint32_t deviceId) { return (m_deviceList[deviceId].active); } bool -CsmaCdChannel::TransmitEnd() +CsmaChannel::TransmitEnd() { - NS_DEBUG("CsmaCdChannel::TransmitEnd (" << &m_currentPkt << ", " + NS_DEBUG("CsmaChannel::TransmitEnd (" << &m_currentPkt << ", " << m_currentSrc << ")"); - NS_DEBUG("CsmaCdChannel::TransmitEnd (): UID is " << + NS_DEBUG("CsmaChannel::TransmitEnd (): UID is " << m_currentPkt.GetUid () << ")"); NS_ASSERT(m_state == TRANSMITTING); @@ -244,33 +244,33 @@ CsmaCdChannel::TransmitEnd() bool retVal = true; if (!IsActive(m_currentSrc)) { - NS_DEBUG("CsmaCdChannel::TransmitEnd (): ERROR: Seclected source " + NS_DEBUG("CsmaChannel::TransmitEnd (): ERROR: Seclected source " << "was detached before the end of the transmission"); retVal = false; } - NS_DEBUG ("CsmaCdChannel::TransmitEnd (): Schedule event in " << + NS_DEBUG ("CsmaChannel::TransmitEnd (): Schedule event in " << m_delay.GetSeconds () << "sec"); Simulator::Schedule (m_delay, - &CsmaCdChannel::PropagationCompleteEvent, + &CsmaChannel::PropagationCompleteEvent, this); return retVal; } void -CsmaCdChannel::PropagationCompleteEvent() +CsmaChannel::PropagationCompleteEvent() { - NS_DEBUG("CsmaCdChannel::PropagationCompleteEvent (" + NS_DEBUG("CsmaChannel::PropagationCompleteEvent (" << &m_currentPkt << ")"); - NS_DEBUG ("CsmaCdChannel::PropagationCompleteEvent (): UID is " << + NS_DEBUG ("CsmaChannel::PropagationCompleteEvent (): UID is " << m_currentPkt.GetUid () << ")"); NS_ASSERT(m_state == PROPAGATING); - NS_DEBUG ("CsmaCdChannel::PropagationCompleteEvent (): Receive"); + NS_DEBUG ("CsmaChannel::PropagationCompleteEvent (): Receive"); - std::vector::iterator it; + std::vector::iterator it; for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) { if (it->IsActive()) @@ -283,10 +283,10 @@ CsmaCdChannel::PropagationCompleteEvent() uint32_t -CsmaCdChannel::GetNumActDevices (void) +CsmaChannel::GetNumActDevices (void) { int numActDevices = 0; - std::vector::iterator it; + std::vector::iterator it; for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) { if (it->active) @@ -300,24 +300,24 @@ CsmaCdChannel::GetNumActDevices (void) // This is not the number of active devices. This is the total number // of devices even if some were detached after. uint32_t -CsmaCdChannel::GetNDevices (void) const +CsmaChannel::GetNDevices (void) const { return (m_deviceList.size()); } Ptr -CsmaCdChannel::GetDevice (uint32_t i) const +CsmaChannel::GetDevice (uint32_t i) const { - Ptr< CsmaCdNetDevice > netDevice; + Ptr< CsmaNetDevice > netDevice; netDevice = m_deviceList[i].devicePtr; return netDevice; } int32_t -CsmaCdChannel::GetDeviceNum (Ptr device) +CsmaChannel::GetDeviceNum (Ptr device) { - std::vector::iterator it; + std::vector::iterator it; int i = 0; for (it = m_deviceList.begin(); it < m_deviceList.end(); it++) { @@ -338,7 +338,7 @@ CsmaCdChannel::GetDeviceNum (Ptr device) } bool -CsmaCdChannel::IsBusy (void) +CsmaChannel::IsBusy (void) { if (m_state == IDLE) { @@ -351,19 +351,19 @@ CsmaCdChannel::IsBusy (void) } DataRate -CsmaCdChannel::GetDataRate (void) +CsmaChannel::GetDataRate (void) { return m_bps; } Time -CsmaCdChannel::GetDelay (void) +CsmaChannel::GetDelay (void) { return m_delay; } WireState -CsmaCdChannel::GetState(void) +CsmaChannel::GetState(void) { return m_state; } diff --git a/src/devices/csma-cd/csma-cd-channel.h b/src/devices/csma/csma-channel.h similarity index 90% rename from src/devices/csma-cd/csma-cd-channel.h rename to src/devices/csma/csma-channel.h index fafb5b6ad..0efabf77e 100644 --- a/src/devices/csma-cd/csma-cd-channel.h +++ b/src/devices/csma/csma-channel.h @@ -18,8 +18,8 @@ * Author: Emmanuelle Laprise */ -#ifndef CSMA_CD_CHANNEL_H -#define CSMA_CD_CHANNEL_H +#ifndef CSMA_CHANNEL_H +#define CSMA_CHANNEL_H #include "ns3/channel.h" #include "ns3/ptr.h" @@ -29,21 +29,21 @@ namespace ns3 { -class CsmaCdNetDevice; +class CsmaNetDevice; /** - * \brief CsmaCdNetDevice Record + * \brief CsmaNetDevice Record * * Stores the information related to each net device that is * connected to the channel. */ - class CsmaCdDeviceRec { + class CsmaDeviceRec { public: - Ptr< CsmaCdNetDevice > devicePtr; /// Pointer to the net device + Ptr< CsmaNetDevice > devicePtr; /// Pointer to the net device bool active; /// Is net device enabled to TX/RX - CsmaCdDeviceRec(); - CsmaCdDeviceRec(Ptr< CsmaCdNetDevice > device); + CsmaDeviceRec(); + CsmaDeviceRec(Ptr< CsmaNetDevice > device); /* * \return If the net device pointed to by the devicePtr is active * and ready to RX/TX. @@ -65,9 +65,9 @@ class CsmaCdNetDevice; }; /** - * \brief CsmaCd Channel. + * \brief Csma Channel. * - * This class represents a simple Csma/Cd channel that can be used + * This class represents a simple Csma channel that can be used * when many nodes are connected to one wire. It uses a single busy * flag to indicate if the channel is currently in use. It does not * take into account the distances between stations or the speed of @@ -84,32 +84,32 @@ class CsmaCdNetDevice; * packet to the channel is really connected to this channel * */ -class CsmaCdChannel : public Channel { +class CsmaChannel : public Channel { public: /** - * \brief Create a CsmaCdChannel + * \brief Create a CsmaChannel * - * By default, you get a channel with the name "CsmaCd Channel" that + * By default, you get a channel with the name "Csma Channel" that * has an "infitely" fast transmission speed and zero delay. */ - CsmaCdChannel (); + CsmaChannel (); /** - * \brief Create a CsmaCdChannel + * \brief Create a CsmaChannel * * \param bps The bitrate of the channel * \param delay Transmission delay through the channel */ - CsmaCdChannel (const DataRate& bps, const Time& delay); + CsmaChannel (const DataRate& bps, const Time& delay); /** - * \brief Create a CsmaCdChannel + * \brief Create a CsmaChannel * * \param name the name of the channel for identification purposes * \param bps The bitrate of the channel * \param delay Transmission delay through the channel */ - CsmaCdChannel (const std::string& name, + CsmaChannel (const std::string& name, const DataRate& bps, const Time& delay); /** @@ -118,7 +118,7 @@ public: * \param device Device pointer to the netdevice to attach to the channel * \return The assigned device number */ - int32_t Attach (Ptr device); + int32_t Attach (Ptr device); /** * \brief Detach a given netdevice from this channel * @@ -130,7 +130,7 @@ public: * false if the device is not currently connected to the channel or * can't be found. */ - bool Detach (Ptr device); + bool Detach (Ptr device); /** * \brief Detach a given netdevice from this channel * @@ -170,7 +170,7 @@ public: * channel, false if the device is currently connected to the * channel or can't be found. */ - bool Reattach(Ptr device); + bool Reattach(Ptr device); /** * \brief Start transmitting a packet over the channel * @@ -216,7 +216,7 @@ public: * \param device Device pointer to the netdevice for which the device * number is needed */ - int32_t GetDeviceNum (Ptr device); + int32_t GetDeviceNum (Ptr device); /** * \return Returns the state of the channel (IDLE -- free, * TRANSMITTING -- busy, PROPAGATING - busy ) @@ -278,7 +278,7 @@ private: * whole list does not have to be searched when making sure that a * source is attached to a channel when it is transmitting data. */ - std::vector< CsmaCdDeviceRec > m_deviceList; + std::vector< CsmaDeviceRec > m_deviceList; /** * Packet that is currently being transmitted on the channel (or last * packet to have been transmitted on the channel if the channel is @@ -304,4 +304,4 @@ private: } // namespace ns3 -#endif /* CSMA_CD_CHANNEL_H */ +#endif /* CSMA_CHANNEL_H */ diff --git a/src/devices/csma-cd/csma-cd-ipv4-topology.cc b/src/devices/csma/csma-ipv4-topology.cc similarity index 73% rename from src/devices/csma-cd/csma-cd-ipv4-topology.cc rename to src/devices/csma/csma-ipv4-topology.cc index 923f89dc4..02cd0e487 100644 --- a/src/devices/csma-cd/csma-cd-ipv4-topology.cc +++ b/src/devices/csma/csma-ipv4-topology.cc @@ -28,23 +28,22 @@ #include "ns3/ipv4.h" #include "ns3/queue.h" -#include "csma-cd-channel.h" -#include "csma-cd-net-device.h" -#include "csma-cd-ipv4-topology.h" +#include "csma-channel.h" +#include "csma-net-device.h" +#include "csma-ipv4-topology.h" namespace ns3 { - uint32_t -CsmaCdIpv4Topology::AddIpv4CsmaCdNode(Ptr n1, - Ptr ch, +CsmaIpv4Topology::AddIpv4CsmaNode(Ptr n1, + Ptr ch, Eui48Address addr) { Ptr q = Queue::CreateDefault (); // assume full-duplex - Ptr nd0 = Create (n1, addr, - ns3::CsmaCdNetDevice::IP_ARP, + Ptr nd0 = Create (n1, addr, + ns3::CsmaNetDevice::IP_ARP, true, true); nd0->AddQueue(q); nd0->Attach (ch); @@ -53,47 +52,47 @@ CsmaCdIpv4Topology::AddIpv4CsmaCdNode(Ptr n1, void -CsmaCdIpv4Topology::AddIpv4LlcCsmaCdNode(Ptr n1, - Ptr ch, +CsmaIpv4Topology::AddIpv4LlcCsmaNode(Ptr n1, + Ptr ch, Eui48Address addr) { Ptr q = Queue::CreateDefault (); - Ptr nd0 = Create (n1, addr, - ns3::CsmaCdNetDevice::LLC, + Ptr nd0 = Create (n1, addr, + ns3::CsmaNetDevice::LLC, true, false); nd0->AddQueue(q); nd0->Attach (ch); - Ptr nd1 = Create (n1, addr, - ns3::CsmaCdNetDevice::LLC, + Ptr nd1 = Create (n1, addr, + ns3::CsmaNetDevice::LLC, false, true); nd1->AddQueue(q); nd1->Attach (ch); } void -CsmaCdIpv4Topology::AddIpv4RawCsmaCdNode(Ptr n1, - Ptr ch, +CsmaIpv4Topology::AddIpv4RawCsmaNode(Ptr n1, + Ptr ch, Eui48Address addr) { Ptr q = Queue::CreateDefault (); - Ptr nd0 = Create (n1, addr, - ns3::CsmaCdNetDevice::RAW, + Ptr nd0 = Create (n1, addr, + ns3::CsmaNetDevice::RAW, true, false); nd0->AddQueue(q); nd0->Attach (ch); - Ptr nd1 = Create (n1, addr, - ns3::CsmaCdNetDevice::RAW, + Ptr nd1 = Create (n1, addr, + ns3::CsmaNetDevice::RAW, false, true); nd1->AddQueue(q); nd1->Attach (ch); } void -CsmaCdIpv4Topology::AddIpv4Address(Ptr n1, +CsmaIpv4Topology::AddIpv4Address(Ptr n1, int ndNum, const Ipv4Address& addr1, const Ipv4Mask& netmask1) @@ -115,7 +114,7 @@ CsmaCdIpv4Topology::AddIpv4Address(Ptr n1, } void -CsmaCdIpv4Topology::AddIpv4Routes ( +CsmaIpv4Topology::AddIpv4Routes ( Ptr nd1, Ptr nd2) { // Assert that both are Ipv4 nodes diff --git a/src/devices/csma-cd/csma-cd-ipv4-topology.h b/src/devices/csma/csma-ipv4-topology.h similarity index 61% rename from src/devices/csma-cd/csma-cd-ipv4-topology.h rename to src/devices/csma/csma-ipv4-topology.h index 84a769880..37f546118 100644 --- a/src/devices/csma-cd/csma-cd-ipv4-topology.h +++ b/src/devices/csma/csma-ipv4-topology.h @@ -18,22 +18,22 @@ // Author: Emmanuelle Laprise // -#ifndef __CSMA_CD_IPV4_TOPOLOGY_H__ -#define __CSMA_CD_IPV4_TOPOLOGY_H__ +#ifndef __CSMA_IPV4_TOPOLOGY_H__ +#define __CSMA_IPV4_TOPOLOGY_H__ #include "ns3/ptr.h" #include "ns3/ipv4-address.h" #include "ns3/ipv4.h" #include "ns3/ipv4-route.h" #include "ns3/internet-node.h" -#include "ns3/csma-cd-net-device.h" +#include "ns3/csma-net-device.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 CsmaCdIpv4Channel; +class CsmaIpv4Channel; class Node; class IPAddr; class DataRate; @@ -41,54 +41,54 @@ class Queue; /** * \brief A helper class to create Topologies based on the - * InternetNodes and CsmaCdChannels. Either the - * SimpleCsmaCdNetDevice or the LLCCsmaCdNetDevice can be used + * InternetNodes and CsmaChannels. Either the + * SimpleCsmaNetDevice or the LLCCsmaNetDevice can be used * when constructing these topologies. */ -class CsmaCdIpv4Topology { +class CsmaIpv4Topology { public: /** - * \param n1 Node to be attached to the Csma/Cd channel - * \param ch CsmaCdChannel to which node n1 should be attached + * \param n1 Node to be attached to the Csma channel + * \param ch CsmaChannel to which node n1 should be attached * \param addr Mac address of the node * - * Add a Csma/Cd node to a Csma/Cd channel. This function adds - * a EthernetCsmaCdNetDevice to the nodes so that they can - * connect to a CsmaCdChannel. This means that Ethernet headers + * Add a Csma node to a Csma channel. This function adds + * a EthernetCsmaNetDevice to the nodes so that they can + * connect to a CsmaChannel. This means that Ethernet headers * and trailers will be added to the packet before sending out on * the net device. * * \return ifIndex of the device */ - static uint32_t AddIpv4CsmaCdNode( Ptr n1, - Ptr ch, + static uint32_t AddIpv4CsmaNode( Ptr n1, + Ptr ch, Eui48Address addr); /** - * \param n1 Node to be attached to the Csma/Cd channel - * \param ch CsmaCdChannel to which node n1 should be attached + * \param n1 Node to be attached to the Csma channel + * \param ch CsmaChannel to which node n1 should be attached * \param addr Mac address of the node * - * Add a Csma/Cd node to a Csma/Cd channel. This function adds - * a RawCsmaCdNetDevice to the nodes so that they can connect - * to a CsmaCdChannel. + * Add a Csma node to a Csma channel. This function adds + * a RawCsmaNetDevice to the nodes so that they can connect + * to a CsmaChannel. */ - static void AddIpv4RawCsmaCdNode( Ptr n1, - Ptr ch, + static void AddIpv4RawCsmaNode( Ptr n1, + Ptr ch, Eui48Address addr); /** - * \param n1 Node to be attached to the Csma/Cd channel - * \param ch CsmaCdChannel to which node n1 should be attached + * \param n1 Node to be attached to the Csma channel + * \param ch CsmaChannel to which node n1 should be attached * \param addr Mac address of the node * - * Add a Csma/Cd node to a Csma/Cd channel. This function adds - * a LlcCsmaCdNetDevice to the nodes so that they can connect - * to a CsmaCdChannel. + * Add a Csma node to a Csma channel. This function adds + * a LlcCsmaNetDevice to the nodes so that they can connect + * to a CsmaChannel. */ - static void AddIpv4LlcCsmaCdNode( Ptr n1, - Ptr ch, + static void AddIpv4LlcCsmaNode( Ptr n1, + Ptr ch, Eui48Address addr); @@ -100,8 +100,8 @@ public: * \param network network mask for ndNum of node n1 * * Add an Ipv4Address to the Ipv4 interface associated with the - * ndNum CsmaCdIpv4NetDevices on the provided - * CsmaCdIpv4Channel + * ndNum CsmaIpv4NetDevices on the provided + * CsmaIpv4Channel */ static void AddIpv4Address(Ptr n1, int ndNum, const Ipv4Address& addr1, diff --git a/src/devices/csma-cd/csma-cd-net-device.cc b/src/devices/csma/csma-net-device.cc similarity index 75% rename from src/devices/csma-cd/csma-cd-net-device.cc rename to src/devices/csma/csma-net-device.cc index d5dfc8501..e3346c3bb 100644 --- a/src/devices/csma-cd/csma-cd-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -25,24 +25,24 @@ #include "ns3/queue.h" #include "ns3/simulator.h" #include "ns3/composite-trace-resolver.h" -#include "csma-cd-net-device.h" -#include "csma-cd-channel.h" +#include "csma-net-device.h" +#include "csma-channel.h" #include "ns3/ethernet-header.h" #include "ns3/ethernet-trailer.h" #include "ns3/llc-snap-header.h" -NS_DEBUG_COMPONENT_DEFINE ("CsmaCdNetDevice"); +NS_DEBUG_COMPONENT_DEFINE ("CsmaNetDevice"); namespace ns3 { -CsmaCdTraceType::CsmaCdTraceType (enum Type type) +CsmaTraceType::CsmaTraceType (enum Type type) : m_type (type) {} -CsmaCdTraceType::CsmaCdTraceType () +CsmaTraceType::CsmaTraceType () : m_type (RX) {} void -CsmaCdTraceType::Print (std::ostream &os) const +CsmaTraceType::Print (std::ostream &os) const { switch (m_type) { case RX: @@ -54,60 +54,60 @@ CsmaCdTraceType::Print (std::ostream &os) const } } uint16_t -CsmaCdTraceType::GetUid (void) +CsmaTraceType::GetUid (void) { - static uint16_t uid = AllocateUid ("CsmaCdTraceType"); + static uint16_t uid = AllocateUid ("CsmaTraceType"); return uid; } -CsmaCdNetDevice::CsmaCdNetDevice (Ptr node) +CsmaNetDevice::CsmaNetDevice (Ptr node) : NetDevice (node, Eui48Address::Allocate ()), m_bps (DataRate (0xffffffff)) { - NS_DEBUG ("CsmaCdNetDevice::CsmaCdNetDevice (" << node << ")"); + NS_DEBUG ("CsmaNetDevice::CsmaNetDevice (" << node << ")"); m_encapMode = IP_ARP; Init(true, true); } -CsmaCdNetDevice::CsmaCdNetDevice (Ptr node, Eui48Address addr, - CsmaCdEncapsulationMode encapMode) +CsmaNetDevice::CsmaNetDevice (Ptr node, Eui48Address addr, + CsmaEncapsulationMode encapMode) : NetDevice(node, addr), m_bps (DataRate (0xffffffff)) { - NS_DEBUG ("CsmaCdNetDevice::CsmaCdNetDevice (" << node << ")"); + NS_DEBUG ("CsmaNetDevice::CsmaNetDevice (" << node << ")"); m_encapMode = encapMode; Init(true, true); } -CsmaCdNetDevice::CsmaCdNetDevice (Ptr node, Eui48Address addr, - CsmaCdEncapsulationMode encapMode, +CsmaNetDevice::CsmaNetDevice (Ptr node, Eui48Address addr, + CsmaEncapsulationMode encapMode, bool sendEnable, bool receiveEnable) : NetDevice(node, addr), m_bps (DataRate (0xffffffff)) { - NS_DEBUG ("CsmaCdNetDevice::CsmaCdNetDevice (" << node << ")"); + NS_DEBUG ("CsmaNetDevice::CsmaNetDevice (" << node << ")"); m_encapMode = encapMode; Init(sendEnable, receiveEnable); } -CsmaCdNetDevice::~CsmaCdNetDevice() +CsmaNetDevice::~CsmaNetDevice() { - NS_DEBUG ("CsmaCdNetDevice::~CsmaCdNetDevice ()"); + NS_DEBUG ("CsmaNetDevice::~CsmaNetDevice ()"); m_queue = 0; } void -CsmaCdNetDevice::DoDispose () +CsmaNetDevice::DoDispose () { m_channel = 0; NetDevice::DoDispose (); } // -// Assignment operator for CsmaCdNetDevice. +// Assignment operator for CsmaNetDevice. // // This uses the non-obvious trick of taking the source net device passed by // value instead of by reference. This causes the copy constructor to be @@ -115,16 +115,16 @@ CsmaCdNetDevice::DoDispose () // here is to return the newly constructed net device. // /* -CsmaCdNetDevice& -CsmaCdNetDevice::operator= (const CsmaCdNetDevice nd) +CsmaNetDevice& +CsmaNetDevice::operator= (const CsmaNetDevice nd) { - NS_DEBUG ("CsmaCdNetDevice::operator= (" << &nd << ")"); + NS_DEBUG ("CsmaNetDevice::operator= (" << &nd << ")"); return *this; } */ void -CsmaCdNetDevice::Init(bool sendEnable, bool receiveEnable) +CsmaNetDevice::Init(bool sendEnable, bool receiveEnable) { m_txMachineState = READY; m_tInterframeGap = Seconds(0); @@ -140,42 +140,42 @@ CsmaCdNetDevice::Init(bool sendEnable, bool receiveEnable) } void -CsmaCdNetDevice::SetSendEnable (bool sendEnable) +CsmaNetDevice::SetSendEnable (bool sendEnable) { m_sendEnable = sendEnable; } void -CsmaCdNetDevice::SetReceiveEnable (bool receiveEnable) +CsmaNetDevice::SetReceiveEnable (bool receiveEnable) { m_receiveEnable = receiveEnable; } bool -CsmaCdNetDevice::IsSendEnabled (void) +CsmaNetDevice::IsSendEnabled (void) { return (m_sendEnable); } bool -CsmaCdNetDevice::IsReceiveEnabled (void) +CsmaNetDevice::IsReceiveEnabled (void) { return (m_receiveEnable); } void -CsmaCdNetDevice::SetDataRate (DataRate bps) +CsmaNetDevice::SetDataRate (DataRate bps) { m_bps = bps; } void -CsmaCdNetDevice::SetInterframeGap (Time t) +CsmaNetDevice::SetInterframeGap (Time t) { m_tInterframeGap = t; } void -CsmaCdNetDevice::SetBackoffParams (Time slotTime, uint32_t minSlots, +CsmaNetDevice::SetBackoffParams (Time slotTime, uint32_t minSlots, uint32_t maxSlots, uint32_t ceiling, uint32_t maxRetries) { @@ -186,7 +186,7 @@ CsmaCdNetDevice::SetBackoffParams (Time slotTime, uint32_t minSlots, m_backoff.m_maxRetries = maxRetries; } void -CsmaCdNetDevice::AddHeader (Packet& p, Eui48Address dest, +CsmaNetDevice::AddHeader (Packet& p, Eui48Address dest, uint16_t protocolNumber) { if (m_encapMode == RAW) @@ -223,7 +223,7 @@ CsmaCdNetDevice::AddHeader (Packet& p, Eui48Address dest, p.AddTrailer(trailer); } bool -CsmaCdNetDevice::ProcessHeader (Packet& p, uint16_t & param) +CsmaNetDevice::ProcessHeader (Packet& p, uint16_t & param) { if (m_encapMode == RAW) { @@ -261,7 +261,7 @@ CsmaCdNetDevice::ProcessHeader (Packet& p, uint16_t & param) } bool -CsmaCdNetDevice::DoNeedsArp (void) const +CsmaNetDevice::DoNeedsArp (void) const { if ((m_encapMode == IP_ARP) || (m_encapMode == LLC)) { @@ -274,10 +274,10 @@ CsmaCdNetDevice::DoNeedsArp (void) const } bool -CsmaCdNetDevice::SendTo (Packet& p, const Address& dest, uint16_t protocolNumber) +CsmaNetDevice::SendTo (Packet& p, const Address& dest, uint16_t protocolNumber) { - NS_DEBUG ("CsmaCdNetDevice::SendTo (" << &p << ")"); - NS_DEBUG ("CsmaCdNetDevice::SendTo (): UID is " << p.GetUid () << ")"); + NS_DEBUG ("CsmaNetDevice::SendTo (" << &p << ")"); + NS_DEBUG ("CsmaNetDevice::SendTo (): UID is " << p.GetUid () << ")"); NS_ASSERT (IsLinkUp ()); @@ -308,10 +308,10 @@ CsmaCdNetDevice::SendTo (Packet& p, const Address& dest, uint16_t protocolNumber } void -CsmaCdNetDevice::TransmitStart () +CsmaNetDevice::TransmitStart () { - NS_DEBUG ("CsmaCdNetDevice::TransmitStart (" << &m_currentPkt << ")"); - NS_DEBUG ("CsmaCdNetDevice::TransmitStart (): UID is " + NS_DEBUG ("CsmaNetDevice::TransmitStart (" << &m_currentPkt << ")"); + NS_DEBUG ("CsmaNetDevice::TransmitStart (): UID is " << m_currentPkt.GetUid () << ")"); // // This function is called to start the process of transmitting a packet. @@ -339,12 +339,12 @@ CsmaCdNetDevice::TransmitStart () m_backoff.IncrNumRetries(); Time backoffTime = m_backoff.GetBackoffTime(); - NS_DEBUG ("CsmaCdNetDevice::TransmitStart (): " + NS_DEBUG ("CsmaNetDevice::TransmitStart (): " << "Channel busy, backing off for " << backoffTime.GetSeconds () << "sec"); Simulator::Schedule (backoffTime, - &CsmaCdNetDevice::TransmitStart, + &CsmaNetDevice::TransmitStart, this); } } @@ -354,16 +354,16 @@ CsmaCdNetDevice::TransmitStart () m_txMachineState = BUSY; Time tEvent = Seconds (m_bps.CalculateTxTime(m_currentPkt.GetSize())); - NS_DEBUG ("CsmaCdNetDevice::TransmitStart (): " << + NS_DEBUG ("CsmaNetDevice::TransmitStart (): " << "Schedule TransmitCompleteEvent in " << tEvent.GetSeconds () << "sec"); Simulator::Schedule (tEvent, - &CsmaCdNetDevice::TransmitCompleteEvent, + &CsmaNetDevice::TransmitCompleteEvent, this); if (!m_channel->TransmitStart (m_currentPkt, m_deviceId)) { - NS_DEBUG ("CsmaCdNetDevice::TransmitStart (): " << + NS_DEBUG ("CsmaNetDevice::TransmitStart (): " << "Channel transmit start did not work at " << tEvent.GetSeconds () << "sec"); m_txMachineState = READY; @@ -378,11 +378,11 @@ CsmaCdNetDevice::TransmitStart () void -CsmaCdNetDevice::TransmitAbort (void) +CsmaNetDevice::TransmitAbort (void) { - NS_DEBUG ("CsmaCdNetDevice::TransmitAbort ()"); + NS_DEBUG ("CsmaNetDevice::TransmitAbort ()"); - NS_DEBUG ("CsmaCdNetDevice::TransmitAbort (): Pkt UID is " << + NS_DEBUG ("CsmaNetDevice::TransmitAbort (): Pkt UID is " << m_currentPkt.GetUid () << ")"); // Try to transmit a new packet @@ -395,9 +395,9 @@ CsmaCdNetDevice::TransmitAbort (void) } void -CsmaCdNetDevice::TransmitCompleteEvent (void) +CsmaNetDevice::TransmitCompleteEvent (void) { - NS_DEBUG ("CsmaCdNetDevice::TransmitCompleteEvent ()"); + NS_DEBUG ("CsmaNetDevice::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 @@ -409,24 +409,24 @@ CsmaCdNetDevice::TransmitCompleteEvent (void) NS_ASSERT(m_channel->GetState() == TRANSMITTING); m_txMachineState = GAP; - NS_DEBUG ("CsmaCdNetDevice::TransmitCompleteEvent (): Pkt UID is " << + NS_DEBUG ("CsmaNetDevice::TransmitCompleteEvent (): Pkt UID is " << m_currentPkt.GetUid () << ")"); m_channel->TransmitEnd (); NS_DEBUG ( - "CsmaCdNetDevice::TransmitCompleteEvent (): " << + "CsmaNetDevice::TransmitCompleteEvent (): " << "Schedule TransmitReadyEvent in " << m_tInterframeGap.GetSeconds () << "sec"); Simulator::Schedule (m_tInterframeGap, - &CsmaCdNetDevice::TransmitReadyEvent, + &CsmaNetDevice::TransmitReadyEvent, this); } void -CsmaCdNetDevice::TransmitReadyEvent (void) +CsmaNetDevice::TransmitReadyEvent (void) { - NS_DEBUG ("CsmaCdNetDevice::TransmitReadyEvent ()"); + NS_DEBUG ("CsmaNetDevice::TransmitReadyEvent ()"); // // This function is called to enable the transmitter after the interframe // gap has passed. If there are pending transmissions, we use this opportunity @@ -450,7 +450,7 @@ CsmaCdNetDevice::TransmitReadyEvent (void) } TraceResolver * -CsmaCdNetDevice::DoCreateTraceResolver (TraceContext const &context) +CsmaNetDevice::DoCreateTraceResolver (TraceContext const &context) { CompositeTraceResolver *resolver = new CompositeTraceResolver (context); resolver->Add ("queue", @@ -458,17 +458,17 @@ CsmaCdNetDevice::DoCreateTraceResolver (TraceContext const &context) PeekPointer (m_queue))); resolver->Add ("rx", m_rxTrace, - CsmaCdTraceType (CsmaCdTraceType::RX)); + CsmaTraceType (CsmaTraceType::RX)); resolver->Add ("drop", m_dropTrace, - CsmaCdTraceType (CsmaCdTraceType::DROP)); + CsmaTraceType (CsmaTraceType::DROP)); return resolver; } bool -CsmaCdNetDevice::Attach (Ptr ch) +CsmaNetDevice::Attach (Ptr ch) { - NS_DEBUG ("CsmaCdNetDevice::Attach (" << &ch << ")"); + NS_DEBUG ("CsmaNetDevice::Attach (" << &ch << ")"); m_channel = ch; @@ -484,15 +484,15 @@ CsmaCdNetDevice::Attach (Ptr ch) } void -CsmaCdNetDevice::AddQueue (Ptr q) +CsmaNetDevice::AddQueue (Ptr q) { - NS_DEBUG ("CsmaCdNetDevice::AddQueue (" << q << ")"); + NS_DEBUG ("CsmaNetDevice::AddQueue (" << q << ")"); m_queue = q; } void -CsmaCdNetDevice::Receive (const Packet& packet) +CsmaNetDevice::Receive (const Packet& packet) { EthernetHeader header (false); EthernetTrailer trailer; @@ -500,7 +500,7 @@ CsmaCdNetDevice::Receive (const Packet& packet) Eui48Address destination; Packet p = packet; - NS_DEBUG ("CsmaCdNetDevice::Receive UID is (" << p.GetUid() << ")"); + NS_DEBUG ("CsmaNetDevice::Receive UID is (" << p.GetUid() << ")"); // Only receive if send side of net device is enabled if (!IsReceiveEnabled()) @@ -556,13 +556,13 @@ CsmaCdNetDevice::Receive (const Packet& packet) } Ptr -CsmaCdNetDevice::GetQueue(void) const +CsmaNetDevice::GetQueue(void) const { return m_queue; } Ptr -CsmaCdNetDevice::DoGetChannel(void) const +CsmaNetDevice::DoGetChannel(void) const { return m_channel; } diff --git a/src/devices/csma-cd/csma-cd-net-device.h b/src/devices/csma/csma-net-device.h similarity index 84% rename from src/devices/csma-cd/csma-cd-net-device.h rename to src/devices/csma/csma-net-device.h index 36a555339..40595f22e 100644 --- a/src/devices/csma-cd/csma-cd-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -19,8 +19,8 @@ * Derived from the p2p net device file */ -#ifndef CSMA_CD_NET_DEVICE_H -#define CSMA_CD_NET_DEVICE_H +#ifndef CSMA_NET_DEVICE_H +#define CSMA_NET_DEVICE_H #include #include "ns3/node.h" @@ -39,17 +39,17 @@ namespace ns3 { class Queue; -class CsmaCdChannel; +class CsmaChannel; -class CsmaCdTraceType : public TraceContextElement +class CsmaTraceType : public TraceContextElement { public: enum Type { RX, DROP }; - CsmaCdTraceType (enum Type type); - CsmaCdTraceType (); + CsmaTraceType (enum Type type); + CsmaTraceType (); void Print (std::ostream &os) const; static uint16_t GetUid (void); private: @@ -57,59 +57,59 @@ private: }; /** - * \class CsmaCdNetDevice - * \brief A Device for a CsmaCd Network Link. + * \class CsmaNetDevice + * \brief A Device for a Csma Network Link. * - * The Csma/Cd net device class is analogous to layer 1 and 2 of the + * The Csma net device class is analogous to layer 1 and 2 of the * TCP stack. The NetDevice takes a raw packet of bytes and creates a - * protocol specific packet from them. The Csma/Cd net device class + * protocol specific packet from them. The Csma net device class * takes this packet and adds and processes the headers/trailers that * are associated with EthernetV1, EthernetV2, RAW or LLC * protocols. The EthernetV1 packet type adds and removes Ethernet * destination and source addresses. The LLC packet type adds and * removes LLC snap headers. The raw packet type does not add or - * remove any headers. Each Csma/Cd net device will receive all - * packets written to the Csma/Cd link. The ProcessHeader function can + * remove any headers. Each Csma net device will receive all + * packets written to the Csma link. The ProcessHeader function can * be used to filter out the packets such that higher level layers * only receive packets that are addressed to their associated net * devices * */ -class CsmaCdNetDevice : public NetDevice { +class CsmaNetDevice : public NetDevice { public: /** * Enumeration of the types of packets supported in the class. * */ -enum CsmaCdEncapsulationMode { +enum CsmaEncapsulationMode { ETHERNET_V1, /**< Version one ethernet packet, length field */ IP_ARP, /**< Ethernet packet encapsulates IP/ARP packet */ RAW, /**< Packet that contains no headers */ LLC, /**< LLC packet encapsulation */ }; - CsmaCdNetDevice (Ptr node); + CsmaNetDevice (Ptr node); /** - * Construct a CsmaCdNetDevice + * Construct a CsmaNetDevice * - * This is the constructor for the CsmaCdNetDevice. It takes as a + * This is the constructor for the CsmaNetDevice. 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 deleted. * * \param node the Node to which this device is connected. * \param addr The source MAC address of the net device. */ - CsmaCdNetDevice (Ptr node, Eui48Address addr, CsmaCdEncapsulationMode pktType); - CsmaCdNetDevice (Ptr node, Eui48Address addr, - CsmaCdEncapsulationMode pktType, + CsmaNetDevice (Ptr node, Eui48Address addr, CsmaEncapsulationMode pktType); + CsmaNetDevice (Ptr node, Eui48Address addr, + CsmaEncapsulationMode pktType, bool sendEnable, bool receiveEnable); /** - * Destroy a CsmaCdNetDevice + * Destroy a CsmaNetDevice * - * This is the destructor for the CsmaCdNetDevice. + * This is the destructor for the CsmaNetDevice. */ - virtual ~CsmaCdNetDevice(); + virtual ~CsmaNetDevice(); /** * 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 @@ -146,23 +146,23 @@ enum CsmaCdEncapsulationMode { /** * Attach the device to a channel. * - * The function Attach is used to add a CsmaCdNetDevice to a - * CsmaCdChannel. + * The function Attach is used to add a CsmaNetDevice to a + * CsmaChannel. * * @see SetDataRate () * @see SetInterframeGap () * \param ch a pointer to the channel to which this object is being attached. */ - bool Attach (Ptr ch); + bool Attach (Ptr ch); /** - * Attach a queue to the CsmaCdNetDevice. + * Attach a queue to the CsmaNetDevice. * - * The CsmaCdNetDevice "owns" a queue. This queue is created by the - * CsmaCdTopology object and implements a queueing method such as - * DropTail or RED. The CsmaCdNetDevice assumes ownership of this + * The CsmaNetDevice "owns" a queue. This queue is created by the + * CsmaTopology object and implements a queueing method such as + * DropTail or RED. The CsmaNetDevice assumes ownership of this * queue and must delete it when the device is destroyed. * - * @see CsmaCdTopology::AddCsmaCdLink () + * @see CsmaTopology::AddCsmaLink () * @see Queue * @see DropTailQueue * \param queue a pointer to the queue for which object is assuming @@ -170,14 +170,14 @@ enum CsmaCdEncapsulationMode { */ void AddQueue (Ptr queue); /** - * Receive a packet from a connected CsmaCdChannel. + * Receive a packet from a connected CsmaChannel. * - * The CsmaCdNetDevice receives packets from its connected channel + * The CsmaNetDevice 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 CsmaCdChannel + * @see CsmaChannel * \param p a reference to the received packet */ void Receive (const Packet& p); @@ -234,14 +234,14 @@ protected: private: // disable copy constructor and operator = - CsmaCdNetDevice &operator = (const CsmaCdNetDevice &o); - CsmaCdNetDevice (const CsmaCdNetDevice &o); + CsmaNetDevice &operator = (const CsmaNetDevice &o); + CsmaNetDevice (const CsmaNetDevice &o); /** * Initializes variablea when construction object. */ void Init (bool sendEnable, bool receiveEnable); /** - * Send a Packet on the Csma/Cd network + * Send a Packet on the Csma network * * This method does not use a destination address since all packets * are broadcast to all NetDevices attached to the channel. Packet @@ -261,7 +261,7 @@ private: * Start Sending a Packet Down the Wire. * * The TransmitStart method is the method that is used internally in - * the CsmaCdNetDevice to begin the process of sending a packet + * the CsmaNetDevice 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, this causes the @@ -270,7 +270,7 @@ private: * is busy, the method reschedules itself for a later time (within * the backoff period) * - * @see CsmaCdChannel::TransmitStart () + * @see CsmaChannel::TransmitStart () * @see TransmitCompleteEvent () */ void TransmitStart (); @@ -287,7 +287,7 @@ private: * also schedules the TransmitReadyEvent at which time the transmitter * becomes ready to send the next packet. * - * @see CsmaCdChannel::TransmitEnd () + * @see CsmaChannel::TransmitEnd () * @see TransmitReadyEvent () */ void TransmitCompleteEvent (void); @@ -359,7 +359,7 @@ private: * function and that should be processed by the ProcessHeader * function. */ - CsmaCdEncapsulationMode m_encapMode; + CsmaEncapsulationMode m_encapMode; /** * The data rate that the Net Device uses to simulate packet transmission * timing. @@ -385,14 +385,14 @@ private: */ Packet m_currentPkt; /** - * The CsmaCdChannel to which this CsmaCdNetDevice has been + * The CsmaChannel to which this CsmaNetDevice has been * attached. - * @see class CsmaCdChannel + * @see class CsmaChannel */ - Ptr m_channel; + Ptr m_channel; /** - * The Queue which this CsmaCdNetDevice uses as a packet source. - * Management of this Queue has been delegated to the CsmaCdNetDevice + * The Queue which this CsmaNetDevice uses as a packet source. + * Management of this Queue has been delegated to the CsmaNetDevice * and it has the responsibility for deletion. * @see class Queue * @see class DropTailQueue @@ -413,5 +413,5 @@ private: }; // namespace ns3 -#endif // CSMA_CD_NET_DEVICE_H +#endif // CSMA_NET_DEVICE_H diff --git a/src/devices/csma-cd/csma-cd-topology.cc b/src/devices/csma/csma-topology.cc similarity index 67% rename from src/devices/csma-cd/csma-cd-topology.cc rename to src/devices/csma/csma-topology.cc index e4af1a309..27e4e9e29 100644 --- a/src/devices/csma-cd/csma-cd-topology.cc +++ b/src/devices/csma/csma-topology.cc @@ -19,38 +19,38 @@ // // -// Topology helper for CsmaCd channels in ns3. +// Topology helper for Csma channels in ns3. #include "ns3/assert.h" #include "ns3/debug.h" #include "ns3/queue.h" -#include "csma-cd-channel.h" -#include "csma-cd-net-device.h" -#include "csma-cd-topology.h" +#include "csma-channel.h" +#include "csma-net-device.h" +#include "csma-topology.h" #include "ns3/socket-factory.h" namespace ns3 { -Ptr -CsmaCdTopology::CreateCsmaCdChannel( +Ptr +CsmaTopology::CreateCsmaChannel( const DataRate& bps, const Time& delay) { - Ptr channel = Create (bps, delay); + Ptr channel = Create (bps, delay); return channel; } #if 0 -Ptr -CsmaCdTopology::AddCsmaCdEthernetNode( +Ptr +CsmaTopology::AddCsmaEthernetNode( Ptr n1, - Ptr ch, + Ptr ch, MacAddress addr) { - Ptr nd1 = Create (n1, addr, - ns3::CsmaCdNetDevice::ETHERNET_V1); + Ptr nd1 = Create (n1, addr, + ns3::CsmaNetDevice::ETHERNET_V1); Ptr q = Queue::CreateDefault (); nd1->AddQueue(q); @@ -60,9 +60,9 @@ CsmaCdTopology::AddCsmaCdEthernetNode( } Ptr -CsmaCdTopology::ConnectPacketSocket(Ptr app, - Ptr ndSrc, - Ptr ndDest) +CsmaTopology::ConnectPacketSocket(Ptr app, + Ptr ndSrc, + Ptr ndDest) { Ptr socket = Create (); socket->Bind(ndSrc); @@ -73,8 +73,8 @@ CsmaCdTopology::ConnectPacketSocket(Ptr app, } Ptr -CsmaCdTopology::ConnectPacketSocket(Ptr app, - Ptr ndSrc, +CsmaTopology::ConnectPacketSocket(Ptr app, + Ptr ndSrc, MacAddress macAddr) { Ptr socket = Create (); @@ -86,7 +86,7 @@ CsmaCdTopology::ConnectPacketSocket(Ptr app, } Ptr -CsmaCdTopology::CreatePacketSocket(Ptr n1, std::string iid_name) +CsmaTopology::CreatePacketSocket(Ptr n1, std::string iid_name) { InterfaceId iid = InterfaceId::LookupByName (iid_name); diff --git a/src/devices/csma-cd/csma-cd-topology.h b/src/devices/csma/csma-topology.h similarity index 80% rename from src/devices/csma-cd/csma-cd-topology.h rename to src/devices/csma/csma-topology.h index 46c54a022..9f39b73ef 100644 --- a/src/devices/csma-cd/csma-cd-topology.h +++ b/src/devices/csma/csma-topology.h @@ -19,11 +19,11 @@ // // Topology helper for multipoint channels in ns3. // -#ifndef CSMA_CD_TOPOLOGY_H -#define CSMA_CD_TOPOLOGY_H +#ifndef CSMA_TOPOLOGY_H +#define CSMA_TOPOLOGY_H #include "ns3/ptr.h" -#include "ns3/csma-cd-net-device.h" +#include "ns3/csma-net-device.h" #include "ns3/node.h" // The topology class consists of only static methods thar are used to @@ -31,16 +31,16 @@ namespace ns3 { -class CsmaCdChannel; +class CsmaChannel; class Node; class DataRate; class Queue; /** - * \brief A helper class to create CsmaCd Topologies + * \brief A helper class to create Csma Topologies * - * CsmaCd topologies are created based on the - * ns3::CsmaCdNetDevice subclasses and ns3::CsmaCdChannel + * Csma topologies are created based on the + * ns3::CsmaNetDevice subclasses and ns3::CsmaChannel * objects. This class uses the EthernetNetDevice and * PacketSocket classes in order to create logical connections between * net devices. The PacketSocket class generates the data and the @@ -49,30 +49,30 @@ class Queue; * EthernetNetDevice class filters received data packets * according to its destination Mac addresses. */ -class CsmaCdTopology { +class CsmaTopology { public: /** * \param dataRate Maximum transmission link rate * \param delay propagation delay between any two nodes - * \return Pointer to the created CsmaCdChannel + * \return Pointer to the created CsmaChannel * - * Create a CsmaCdChannel. All nodes connected to a multipoint + * Create a CsmaChannel. All nodes connected to a multipoint * channels will receive all packets written to that channel */ - static Ptr CreateCsmaCdChannel( + static Ptr CreateCsmaChannel( const DataRate& dataRate, const Time& delay); #if 0 /** * \param n1 Node to be attached to the multipoint channel - * \param ch CsmaCdChannel to which node n1 should be attached + * \param ch CsmaChannel to which node n1 should be attached * \param addr MacAddress that should be assigned to the * EthernetNetDevice that will be added to the node. * * Add a multipoint node to a multipoint channel */ - static Ptr AddCsmaCdEthernetNode(Ptr n1, - Ptr ch, + static Ptr AddCsmaEthernetNode(Ptr n1, + Ptr ch, MacAddress addr); /** @@ -86,8 +86,8 @@ public: * two net devices */ static Ptr ConnectPacketSocket(Ptr app, - Ptr ndSrc, - Ptr ndDest); + Ptr ndSrc, + Ptr ndDest); /** * \param app Application that will be sending data to the agent @@ -101,7 +101,7 @@ static Ptr ConnectPacketSocket(Ptr app, * net device to a destination MacAddress */ static Ptr ConnectPacketSocket(Ptr app, - Ptr ndSrc, + Ptr ndSrc, MacAddress macAddr); /** diff --git a/src/devices/csma/wscript b/src/devices/csma/wscript new file mode 100644 index 000000000..8257c06dc --- /dev/null +++ b/src/devices/csma/wscript @@ -0,0 +1,19 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +def build(bld): + obj = bld.create_ns3_module('csma', ['node']) + obj.source = [ + 'backoff.cc', + 'csma-net-device.cc', + 'csma-channel.cc', + 'csma-topology.cc', + 'csma-ipv4-topology.cc', + ] + headers = bld.create_obj('ns3header') + headers.source = [ + 'backoff.h', + 'csma-net-device.h', + 'csma-channel.h', + 'csma-topology.h', + 'csma-ipv4-topology.h', + ] diff --git a/src/wscript b/src/wscript index 0d50d0889..1e20fb75c 100644 --- a/src/wscript +++ b/src/wscript @@ -17,7 +17,7 @@ all_modules = ( 'node', 'internet-node', 'devices/point-to-point', - 'devices/csma-cd', + 'devices/csma', 'applications', 'routing/global-routing', 'mobility',