From 00960518d341e9befebf6660e0e4a38bc1bbe6c1 Mon Sep 17 00:00:00 2001 From: Tom Henderson Date: Sun, 25 Mar 2007 06:59:11 -0700 Subject: [PATCH] Rename file names from serial to p2p --- SConstruct | 48 ++-- examples/{simple-serial.cc => simple-p2p.cc} | 10 +- ...device-if.cc => main-p2p-net-device-if.cc} | 6 +- src/devices/p2p-gfr/p2p-channel.cc | 98 ++++++++ src/devices/p2p-gfr/p2p-channel.h | 56 +++++ src/devices/p2p-gfr/p2p-net-device.cc | 80 +++++++ src/devices/p2p-gfr/p2p-net-device.h | 54 +++++ .../{serial => p2p}/layer-connector.cc | 0 src/devices/{serial => p2p}/layer-connector.h | 0 src/devices/p2p/p2p-channel.cc | 218 +++++++++++------- src/devices/p2p/p2p-channel.h | 128 ++++++---- src/devices/p2p/p2p-net-device.cc | 186 ++++++++++----- src/devices/p2p/p2p-net-device.h | 98 +++++--- .../{serial/serial-phy.cc => p2p/p2p-phy.cc} | 6 +- .../{serial/serial-phy.h => p2p/p2p-phy.h} | 0 .../p2p-topology.cc} | 6 +- .../serial-topology.h => p2p/p2p-topology.h} | 2 +- src/devices/{serial => p2p}/propagator.h | 0 src/devices/serial/serial-channel.cc | 160 ------------- src/devices/serial/serial-channel.h | 102 -------- src/devices/serial/serial-net-device.cc | 160 ------------- src/devices/serial/serial-net-device.h | 76 ------ 22 files changed, 747 insertions(+), 747 deletions(-) rename examples/{simple-serial.cc => simple-p2p.cc} (97%) rename samples/{main-serial-net-device-if.cc => main-p2p-net-device-if.cc} (98%) create mode 100644 src/devices/p2p-gfr/p2p-channel.cc create mode 100644 src/devices/p2p-gfr/p2p-channel.h create mode 100644 src/devices/p2p-gfr/p2p-net-device.cc create mode 100644 src/devices/p2p-gfr/p2p-net-device.h rename src/devices/{serial => p2p}/layer-connector.cc (100%) rename src/devices/{serial => p2p}/layer-connector.h (100%) rename src/devices/{serial/serial-phy.cc => p2p/p2p-phy.cc} (95%) rename src/devices/{serial/serial-phy.h => p2p/p2p-phy.h} (100%) rename src/devices/{serial/serial-topology.cc => p2p/p2p-topology.cc} (98%) rename src/devices/{serial/serial-topology.h => p2p/p2p-topology.h} (96%) rename src/devices/{serial => p2p}/propagator.h (100%) delete mode 100644 src/devices/serial/serial-channel.cc delete mode 100644 src/devices/serial/serial-channel.h delete mode 100644 src/devices/serial/serial-net-device.cc delete mode 100644 src/devices/serial/serial-net-device.h diff --git a/SConstruct b/SConstruct index 326ca4925..4df5d829f 100644 --- a/SConstruct +++ b/SConstruct @@ -274,24 +274,24 @@ p2p.add_inst_headers ([ 'p2p-channel.h', ]) -serial = build.Ns3Module ('serial', 'src/devices/serial') -ns3.add (serial) -serial.add_deps (['node']) -serial.add_sources ([ - 'serial-net-device.cc', - 'serial-channel.cc', - 'serial-topology.cc', - 'serial-phy.cc', +p2p = build.Ns3Module ('p2p', 'src/devices/p2p') +ns3.add (p2p) +p2p.add_deps (['node']) +p2p.add_sources ([ + 'p2p-net-device.cc', + 'p2p-channel.cc', + 'p2p-topology.cc', + 'p2p-phy.cc', 'layer-connector.cc', ]) -serial.add_headers ([ +p2p.add_headers ([ 'propagator.h', ]) -serial.add_inst_headers ([ - 'serial-net-device.h', - 'serial-channel.h', - 'serial-topology.h', - 'serial-phy.h', +p2p.add_inst_headers ([ + 'p2p-net-device.h', + 'p2p-channel.h', + 'p2p-topology.h', + 'p2p-phy.h', 'layer-connector.h', ]) @@ -366,11 +366,11 @@ ns3.add(sample_test) sample_test.add_dep('core') sample_test.add_source('main-test.cc') -sample_serial_net_device_if = build.Ns3Module ('sample-serial-net-device-if', 'samples') -sample_serial_net_device_if.set_executable () -ns3.add (sample_serial_net_device_if) -sample_serial_net_device_if.add_deps (['common', 'node', 'serial']) -sample_serial_net_device_if.add_source ('main-serial-net-device-if.cc') +sample_p2p_net_device_if = build.Ns3Module ('sample-p2p-net-device-if', 'samples') +sample_p2p_net_device_if.set_executable () +ns3.add (sample_p2p_net_device_if) +sample_p2p_net_device_if.add_deps (['common', 'node', 'p2p']) +sample_p2p_net_device_if.add_source ('main-p2p-net-device-if.cc') sample_simple = build.Ns3Module('sample-simple', 'samples') sample_simple.set_executable() @@ -385,10 +385,10 @@ sample_sp2p.add_deps(['core', 'simulator', 'node', 'p2p']) sample_sp2p.add_source('main-simple-p2p.cc') # examples -example_simple_serial = build.Ns3Module('simple-serial', 'examples') -example_simple_serial.set_executable() -ns3.add(example_simple_serial) -example_simple_serial.add_deps(['core', 'simulator', 'node', 'serial']) -example_simple_serial.add_source('simple-serial.cc') +example_simple_p2p = build.Ns3Module('simple-p2p', 'examples') +example_simple_p2p.set_executable() +ns3.add(example_simple_p2p) +example_simple_p2p.add_deps(['core', 'simulator', 'node', 'p2p']) +example_simple_p2p.add_source('simple-p2p.cc') ns3.generate_dependencies() diff --git a/examples/simple-serial.cc b/examples/simple-p2p.cc similarity index 97% rename from examples/simple-serial.cc rename to examples/simple-p2p.cc index e8277a875..56769f855 100644 --- a/examples/simple-serial.cc +++ b/examples/simple-p2p.cc @@ -29,7 +29,7 @@ // / 5 Mb/s, 2ms // n1 // -// - all links are serial links with indicated one-way BW/delay +// - 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. @@ -48,8 +48,8 @@ #include "ns3/trace-writer.h" #include "ns3/internet-node.h" -#include "ns3/serial-channel.h" -#include "ns3/serial-net-device.h" +#include "ns3/p2p-channel.h" +#include "ns3/p2p-net-device.h" #include "ns3/mac-address.h" #include "ns3/ipv4-address.h" #include "ns3/arp-ipv4-interface.h" @@ -65,7 +65,7 @@ #include "ns3/node-list.h" #include "ns3/trace-root.h" #include "ns3/object-container.h" -#include "ns3/serial-topology.h" +#include "ns3/p2p-topology.h" #include "ns3/onoff-application.h" #include "ns3/random-variable.h" @@ -276,7 +276,7 @@ int main (int argc, char *argv[]) n0->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.1.2"), 1); n3->GetIpv4()->SetDefaultRoute (Ipv4Address ("10.1.3.1"), 1); - AsciiTrace trace ("simple-serial.tr"); + AsciiTrace trace ("simple-p2p.tr"); trace.TraceAllQueues (); trace.TraceAllNetDeviceRx (); diff --git a/samples/main-serial-net-device-if.cc b/samples/main-p2p-net-device-if.cc similarity index 98% rename from samples/main-serial-net-device-if.cc rename to samples/main-p2p-net-device-if.cc index d3bc27e45..6e6a7464f 100644 --- a/samples/main-serial-net-device-if.cc +++ b/samples/main-p2p-net-device-if.cc @@ -27,8 +27,8 @@ #include "ns3/packet.h" #include "ns3/arp-ipv4-interface.h" #include "ns3/ipv4-address.h" -#include "ns3/serial-channel.h" -#include "ns3/serial-net-device.h" +#include "ns3/p2p-channel.h" +#include "ns3/p2p-net-device.h" #include "ns3/trace-writer.h" #include "ns3/drop-tail.h" #include "ns3/arp-ipv4-interface.h" @@ -222,7 +222,7 @@ int main (int argc, char *argv[]) sink->Bind (80); source->SetDefaultDestination (Ipv4Address ("10.1.1.2"), 80); - Logger logger("serial-net-test.log"); + Logger logger("p2p-net-test.log"); TraceRoot::Connect ("/nodes/*/ipv4/interfaces/*/netdevice/queue/*", MakeCallback (&Logger::Log, &logger)); diff --git a/src/devices/p2p-gfr/p2p-channel.cc b/src/devices/p2p-gfr/p2p-channel.cc new file mode 100644 index 000000000..09e338cdc --- /dev/null +++ b/src/devices/p2p-gfr/p2p-channel.cc @@ -0,0 +1,98 @@ +// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- +// +// Copyright (c) 2006 Georgia Tech Research Corporation +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Author: George F. Riley +// + +// Implementation of simple point-to-point channel +// George F. Riley, Georgia Tech, Spring 2007 + +#include "ns3/simulator.h" +#include "ns3/packet.h" +#include "ns3/node.h" +#include "p2p-channel.h" +#include "p2p-net-device.h" + +namespace ns3 { + +P2PChannel::P2PChannel(const Time& delay, double maxRate) + : m_nd1(0), m_nd2(0), + m_delay (delay), + m_maxRate (maxRate) +{ +} + +P2PChannel::~P2PChannel () +{} + +// Channels create compatible net devices +P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address) +{ + // Create a new point-to-point network device + P2PNetDevice* nd = new P2PNetDevice(node, address); + nd->Connect (this); + // Add to list of peers + if (!m_nd1) m_nd1 = nd; + else m_nd2 = nd; + return nd; +} + +void P2PChannel::RemoveNetDevice(NetDevice* nd) +{ + if (nd == m_nd1) m_nd1 = 0; + if (nd == m_nd2) m_nd2 = 0; + // Now if all removed, remove the channel as well + if (!m_nd1 && !m_nd2) + { + delete this; + } +} + +void P2PChannel::Send(P2PNetDevice *device, Packet& p, double rate) +{ // Schedule a receive event at receiver + // First calculate time in future + double maxRate; + if (rate < m_maxRate) + { + maxRate = rate; + } + else + { + maxRate = m_maxRate; + } + Time txTime = Seconds (p.GetSize() * 8 / maxRate); + Time rxTime = m_delay + txTime; + P2PNetDevice *to, *from; + if (device == m_nd1) + { + from = m_nd1; + to = m_nd2; + } + else + { + from = m_nd2; + to = m_nd1; + } + // Schedule the receive event at receiver + Simulator::Schedule(rxTime, &P2PNetDevice::Receive, to, p); + // Schedule the link free event + Simulator::Schedule(txTime, &P2PNetDevice::TxComplete, from); + +} + +}//namespace ns3 diff --git a/src/devices/p2p-gfr/p2p-channel.h b/src/devices/p2p-gfr/p2p-channel.h new file mode 100644 index 000000000..891d3826f --- /dev/null +++ b/src/devices/p2p-gfr/p2p-channel.h @@ -0,0 +1,56 @@ +// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- +// +// Copyright (c) 2006 Georgia Tech Research Corporation +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Author: George F. Riley +// + +// Definition of a simple point-to-point channel +// George F. Riley, Georgia Tech, Spring 2007 + +#ifndef P2P_CHANNEL_H +#define P2P_CHANNEL_H + +#include "ns3/nstime.h" +#include "ns3/mac-address.h" + +namespace ns3 { + +class P2PNetDevice; +class NetDevice; +class Node; +class Packet; + +class P2PChannel { +public: + P2PChannel(const Time& delay, double maxRate /* bits/s */); + ~P2PChannel(); + + P2PNetDevice* CreateNetDevice(Node *node, MacAddress address); + void RemoveNetDevice (NetDevice *device); + void Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */); +private: + // The two endpoints of this channel + P2PNetDevice* m_nd1; + P2PNetDevice* m_nd2; + Time m_delay; + double m_maxRate; +}; + +}//namespace ns3 + +#endif diff --git a/src/devices/p2p-gfr/p2p-net-device.cc b/src/devices/p2p-gfr/p2p-net-device.cc new file mode 100644 index 000000000..fe81c2f64 --- /dev/null +++ b/src/devices/p2p-gfr/p2p-net-device.cc @@ -0,0 +1,80 @@ +// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- +// +// Copyright (c) 2006 Georgia Tech Research Corporation +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Author: George F. Riley +// + +// Implementation of a point-to-point network device +// George F. Riley, Georgia Tech, Spring 2007 + +#include "ns3/empty-trace-resolver.h" +#include "p2p-net-device.h" +#include "p2p-channel.h" + +namespace ns3 { + +P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr) + : NetDevice (node, addr), + m_rate (1000000) +{ + SetMtu (2300); + EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff")); +} + +P2PNetDevice::~P2PNetDevice() +{ // Inform channel that we are destroyed + m_channel->RemoveNetDevice(this); +} + +void +P2PNetDevice::SetRate (double rate) +{ + m_rate = rate; +} + +void +P2PNetDevice::Connect (P2PChannel *channel) +{ + m_channel = channel; + NotifyLinkUp (); +} + +bool +P2PNetDevice::SendTo (Packet& p, const MacAddress&) +{ + m_channel->Send (this, p, m_rate); + return true; +} + +TraceResolver * +P2PNetDevice::DoCreateTraceResolver (TraceContext const &context) +{ + return new EmptyTraceResolver (context); +} + +void +P2PNetDevice::Receive(Packet p) +{ + ForwardUp (p); +} + +void +P2PNetDevice::TxComplete (void) +{} + +}//namespace ns3 diff --git a/src/devices/p2p-gfr/p2p-net-device.h b/src/devices/p2p-gfr/p2p-net-device.h new file mode 100644 index 000000000..4809ea738 --- /dev/null +++ b/src/devices/p2p-gfr/p2p-net-device.h @@ -0,0 +1,54 @@ +// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- +// +// Copyright (c) 2006 Georgia Tech Research Corporation +// All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation; +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// Author: George F. Riley +// + +// Definition for a Point-to-Point network device +// George F. Riley, Georgia Tech, Spring 2007 + +#ifndef P2P_NET_DEVICE_H +#define P2P_NET_DEVICE_H + +#include "ns3/net-device.h" + +namespace ns3 { + +class P2PChannel; + +class P2PNetDevice : public NetDevice { +public: + P2PNetDevice(Node *node, MacAddress const &addr); + virtual ~P2PNetDevice(); + + void SetRate (double rate); + void Connect (P2PChannel *channel); + void Receive(Packet p); + void TxComplete (void); + private: + virtual bool SendTo (Packet& p, const MacAddress& dest); + virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); + + double m_rate; + P2PChannel *m_channel; +}; + +}//namespace ns3 + +#endif /* P2P_NET_DEVICE_H */ + diff --git a/src/devices/serial/layer-connector.cc b/src/devices/p2p/layer-connector.cc similarity index 100% rename from src/devices/serial/layer-connector.cc rename to src/devices/p2p/layer-connector.cc diff --git a/src/devices/serial/layer-connector.h b/src/devices/p2p/layer-connector.h similarity index 100% rename from src/devices/serial/layer-connector.h rename to src/devices/p2p/layer-connector.h diff --git a/src/devices/p2p/p2p-channel.cc b/src/devices/p2p/p2p-channel.cc index 09e338cdc..a803b40c0 100644 --- a/src/devices/p2p/p2p-channel.cc +++ b/src/devices/p2p/p2p-channel.cc @@ -1,98 +1,160 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2 as -// published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Author: George F. Riley -// +/* -*- 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 + */ -// Implementation of simple point-to-point channel -// George F. Riley, Georgia Tech, Spring 2007 - -#include "ns3/simulator.h" -#include "ns3/packet.h" -#include "ns3/node.h" #include "p2p-channel.h" #include "p2p-net-device.h" +#include "p2p-phy.h" +#include "ns3/packet.h" +#include "ns3/simulator.h" +#include "ns3/debug.h" + +NS_DEBUG_COMPONENT_DEFINE ("SerialChannel"); namespace ns3 { -P2PChannel::P2PChannel(const Time& delay, double maxRate) - : m_nd1(0), m_nd2(0), - m_delay (delay), - m_maxRate (maxRate) +// +// By default, you get a channel with the name "Serial Channel" that has an +// "infitely" fast transmission speed and zero delay. +// XXX: this does not work because m_bps = 0 results in infinitely slow transmission +// speed. +SerialChannel::SerialChannel() +: + Channel ("Serial Channel"), + m_bps (0), + m_delay (Seconds(0)), + m_nDevices(0) { + NS_DEBUG("SerialChannel::SerialChannel ()"); } -P2PChannel::~P2PChannel () -{} - -// Channels create compatible net devices -P2PNetDevice* P2PChannel::CreateNetDevice(Node *node, MacAddress address) +SerialChannel::SerialChannel( + const DataRate& bps, + const Time& delay) +: + Channel ("Serial Channel"), + m_bps (bps), + m_delay (delay), + m_nDevices(0) { - // Create a new point-to-point network device - P2PNetDevice* nd = new P2PNetDevice(node, address); - nd->Connect (this); - // Add to list of peers - if (!m_nd1) m_nd1 = nd; - else m_nd2 = nd; - return nd; + NS_DEBUG("SerialChannel::SerialChannel (" << Channel::GetName() << ", " << bps << ", " << + delay << ")"); } -void P2PChannel::RemoveNetDevice(NetDevice* nd) +SerialChannel::SerialChannel( + const std::string& name, + const DataRate& bps, + const Time& delay) +: + Channel (name), + m_bps (bps), + m_delay (delay), + m_nDevices(0) { - if (nd == m_nd1) m_nd1 = 0; - if (nd == m_nd2) m_nd2 = 0; - // Now if all removed, remove the channel as well - if (!m_nd1 && !m_nd2) + NS_DEBUG("SerialChannel::SerialChannel (" << name << ", " << bps << ", " << + delay << ")"); +} + + void +SerialChannel::Attach(SerialPhy *phy) +{ + NS_DEBUG("SerialChannel::Attach (" << phy << ")"); + NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); + NS_ASSERT(phy); + + m_link[m_nDevices].m_src = phy; + ++m_nDevices; +// +// 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) { - delete this; + 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; } } -void P2PChannel::Send(P2PNetDevice *device, Packet& p, double rate) -{ // Schedule a receive event at receiver - // First calculate time in future - double maxRate; - if (rate < m_maxRate) - { - maxRate = rate; - } - else - { - maxRate = m_maxRate; - } - Time txTime = Seconds (p.GetSize() * 8 / maxRate); - Time rxTime = m_delay + txTime; - P2PNetDevice *to, *from; - if (device == m_nd1) - { - from = m_nd1; - to = m_nd2; - } - else - { - from = m_nd2; - to = m_nd1; - } - // Schedule the receive event at receiver - Simulator::Schedule(rxTime, &P2PNetDevice::Receive, to, p); - // Schedule the link free event - Simulator::Schedule(txTime, &P2PNetDevice::TxComplete, from); +void +SerialChannel::TransmitCompleteEvent(Packet p, SerialPhy *src) +{ + NS_DEBUG("SerialChannel::TransmitCompleteEvent (" << &p << ", " << + src << ")"); + 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; + NS_ASSERT(m_link[wire].m_state == TRANSMITTING); + + m_link[wire].m_state = IDLE; + + NS_DEBUG("SerialChannel::TransmitCompleteEvent (): Receive()"); + + m_link[wire].m_dst->Receive (p); } -}//namespace ns3 +bool +SerialChannel::Propagate(Packet& p, SerialPhy* src) +{ + NS_DEBUG("SerialChannel::DoPropagate (" << &p << ", " << src << ")"); + + 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; + + if (m_link[wire].m_state == TRANSMITTING) + { + NS_DEBUG("SerialChannel::DoPropagate (): TRANSMITTING, return"); + return false; + } + + m_link[wire].m_state = TRANSMITTING; + +// +// I believe Raj has a method in the DataRate class to do this. Should use +// it when it is available. +// + Time tEvent = Seconds (static_cast (p.GetSize() * 8) / + static_cast (m_bps)) + m_delay; + + NS_DEBUG("SerialChannel::DoSend (): Schedule Receive delay " << tEvent); + + Packet packet = p; + Simulator::Schedule (tEvent, &SerialChannel::TransmitCompleteEvent, this, + p, src); + return true; +} + +uint32_t +SerialChannel::GetNDevices (void) const +{ + return m_nDevices; +} +NetDevice * +SerialChannel::GetDevice (uint32_t i) const +{ + return m_link[i].m_src->GetDevice (); +} + + +} // namespace ns3 diff --git a/src/devices/p2p/p2p-channel.h b/src/devices/p2p/p2p-channel.h index 891d3826f..4840447f8 100644 --- a/src/devices/p2p/p2p-channel.h +++ b/src/devices/p2p/p2p-channel.h @@ -1,56 +1,102 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2 as -// published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Author: George F. Riley -// +/* -*- 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 + */ -// Definition of a simple point-to-point channel -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef P2P_CHANNEL_H -#define P2P_CHANNEL_H +#ifndef SERIAL_CHANNEL_H +#define SERIAL_CHANNEL_H +#include +#include "ns3/channel.h" +#include "ns3/packet.h" #include "ns3/nstime.h" -#include "ns3/mac-address.h" namespace ns3 { -class P2PNetDevice; +// temporary until Raj's code makes it into the dev tree +typedef uint64_t DataRate; +class SerialPhy; class NetDevice; -class Node; -class Packet; -class P2PChannel { +/** + * \brief Simple Point To Point Channel. + * + * This class represents a very simple serial 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 serial + * 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 channel speed, in bits per second, and a 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 SerialChannel : public Channel { public: - P2PChannel(const Time& delay, double maxRate /* bits/s */); - ~P2PChannel(); +// +// This is really kidding myself, since just setting N_DEVICES to 3 isn't +// going to come close to magically creating a multi-drop link, but I can't +// bring myself to just type 2 in the code (even though I type 0 and 1 :-). +// + static const int N_DEVICES = 2; + + SerialChannel (); + SerialChannel (const DataRate& bps, const Time& delay); + SerialChannel (const std::string& name, + const DataRate& bps, const Time& delay); + + void Attach (SerialPhy* phy); + bool Propagate (Packet& p, SerialPhy *src); + + virtual uint32_t GetNDevices (void) const; + virtual NetDevice *GetDevice (uint32_t i) const; + - P2PNetDevice* CreateNetDevice(Node *node, MacAddress address); - void RemoveNetDevice (NetDevice *device); - void Send (P2PNetDevice *device, Packet&p, double rate /* bits/s */); private: - // The two endpoints of this channel - P2PNetDevice* m_nd1; - P2PNetDevice* m_nd2; + void TransmitCompleteEvent (Packet p, SerialPhy *src); + + DataRate m_bps; Time m_delay; - double m_maxRate; + + int32_t m_nDevices; + + enum WireState + { + INITIALIZING, + IDLE, + TRANSMITTING + }; + + class Link + { + public: + Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {} + WireState m_state; + SerialPhy *m_src; + SerialPhy *m_dst; + }; + + Link m_link[N_DEVICES]; }; -}//namespace ns3 +} // namespace ns3 -#endif +#endif /* SERIAL_CHANNEL_H */ diff --git a/src/devices/p2p/p2p-net-device.cc b/src/devices/p2p/p2p-net-device.cc index fe81c2f64..62470bb6e 100644 --- a/src/devices/p2p/p2p-net-device.cc +++ b/src/devices/p2p/p2p-net-device.cc @@ -1,80 +1,160 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2 as -// published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Author: George F. Riley -// +/* -*- 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: Mathieu Lacage + */ -// Implementation of a point-to-point network device -// George F. Riley, Georgia Tech, Spring 2007 - -#include "ns3/empty-trace-resolver.h" +#include +#include +#include "ns3/debug.h" +#include "ns3/queue.h" +#include "ns3/composite-trace-resolver.h" #include "p2p-net-device.h" #include "p2p-channel.h" +#include "p2p-phy.h" + +NS_DEBUG_COMPONENT_DEFINE ("SerialNetDevice"); namespace ns3 { -P2PNetDevice::P2PNetDevice (Node *node, MacAddress const &addr) - : NetDevice (node, addr), - m_rate (1000000) + +SerialNetDevice::SerialNetDevice(Node* node) : + NetDevice(node, MacAddress("00:00:00:00:00:00")) { - SetMtu (2300); + NS_DEBUG ("SerialNetDevice::SerialNetDevice (" << 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(); + SetMtu(512); // bytes + + m_phy = new SerialPhy(node, this); } -P2PNetDevice::~P2PNetDevice() -{ // Inform channel that we are destroyed - m_channel->RemoveNetDevice(this); -} - -void -P2PNetDevice::SetRate (double rate) +SerialNetDevice::~SerialNetDevice() { - m_rate = rate; + NS_DEBUG ("SerialNetDevice::~SerialNetDevice ()"); + delete m_phy; } -void -P2PNetDevice::Connect (P2PChannel *channel) -{ - m_channel = channel; - NotifyLinkUp (); -} -bool -P2PNetDevice::SendTo (Packet& p, const MacAddress&) +bool +SerialNetDevice::SendTo (Packet& p, const MacAddress& dest) { - m_channel->Send (this, p, m_rate); - return true; + NS_DEBUG ("SerialNetDevice::SendTo (" << &p << ", " << &dest << ")"); + + assert (IsLinkUp ()); + +#ifdef NOTYET + struct NetDevicePacketDestAddress tag; + tag.address = address; + p.AddTag (tag); +#endif + if (m_queue->Enqueue(p) ) + { + NotifyDataAvailable (); + return true; + } + return false; } TraceResolver * -P2PNetDevice::DoCreateTraceResolver (TraceContext const &context) +SerialNetDevice::DoCreateTraceResolver (TraceContext const &context) { - return new EmptyTraceResolver (context); + CompositeTraceResolver *resolver = new CompositeTraceResolver (context); + resolver->Add ("queue", + MakeCallback (&Queue::CreateTraceResolver, m_queue), + SerialNetDevice::QUEUE); + resolver->Add ("rx", + m_rxTrace, + SerialNetDevice::RX); + return resolver; +} + +bool +SerialNetDevice::Attach (SerialChannel* ch) +{ + NS_DEBUG ("SerialNetDevice::Attach (" << &ch << ")"); + + m_channel = ch; + m_phy->Attach (m_channel); + /* + * 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 SerialChannel 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 -P2PNetDevice::Receive(Packet p) +SerialNetDevice::AddQueue (Queue* q) { + NS_DEBUG ("SerialNetDevice::AddQueue (" << q << ")"); + + m_queue = q; +} + +void +SerialNetDevice::Receive (Packet& p) +{ + // ignore return value for now. + NS_DEBUG ("SerialNetDevice::Receive (" << &p << ")"); + + m_rxTrace (p); ForwardUp (p); } -void -P2PNetDevice::TxComplete (void) -{} +void +SerialNetDevice::NotifyDataAvailable(void) +{ + NS_DEBUG ("SerialNetDevice::NotifyDataAvailable ()"); -}//namespace ns3 + Packet p; + bool found = GetQueue ()->Dequeue (p); + if (found) + { +#ifdef NOTYET + struct NetDevicePacketDestAddress tag; + p.PeekTag (tag); + // send packet to address tag.address +#endif + NS_DEBUG ("SerialNetDevice::NotifyDataAvailable (): Dequeued"); + m_phy->Send(p); + } +} + +Queue* +SerialNetDevice::GetQueue(void) const +{ + return m_queue; +} + +SerialChannel* +SerialNetDevice::GetChannel(void) const +{ + return m_channel; +} + +} // namespace ns3 diff --git a/src/devices/p2p/p2p-net-device.h b/src/devices/p2p/p2p-net-device.h index 4809ea738..f3f4cf921 100644 --- a/src/devices/p2p/p2p-net-device.h +++ b/src/devices/p2p/p2p-net-device.h @@ -1,54 +1,76 @@ -// -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- -// -// Copyright (c) 2006 Georgia Tech Research Corporation -// All rights reserved. -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License version 2 as -// published by the Free Software Foundation; -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// Author: George F. Riley -// +/* -*- 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 + */ -// Definition for a Point-to-Point network device -// George F. Riley, Georgia Tech, Spring 2007 - -#ifndef P2P_NET_DEVICE_H -#define P2P_NET_DEVICE_H +#ifndef SERIAL_NET_DEVICE_H +#define SERIAL_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" namespace ns3 { -class P2PChannel; +class SerialChannel; +class SerialPhy; +class Queue; -class P2PNetDevice : public NetDevice { +class SerialNetDevice : public NetDevice { public: - P2PNetDevice(Node *node, MacAddress const &addr); - virtual ~P2PNetDevice(); + enum TraceType { + QUEUE, + RX, + }; + SerialNetDevice(Node* node); + virtual ~SerialNetDevice(); - void SetRate (double rate); - void Connect (P2PChannel *channel); - void Receive(Packet p); - void TxComplete (void); - private: +private: + // Don't let the compiler slip in copy and assignment construction + SerialNetDevice(const SerialNetDevice&); + SerialNetDevice&operator=(const SerialNetDevice&); + +public: + bool Attach(SerialChannel* ch); + void AddQueue(Queue*); + // called by SerialPhy + void Receive (Packet& p); + +protected: + Queue* GetQueue(void) const; + SerialChannel* GetChannel(void) const; + +private: + virtual void NotifyDataAvailable (void); virtual bool SendTo (Packet& p, const MacAddress& dest); virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - double m_rate; - P2PChannel *m_channel; + SerialPhy* m_phy; + SerialChannel* m_channel; + Queue* m_queue; + CallbackTraceSource m_rxTrace; }; -}//namespace ns3 +}; // namespace ns3 -#endif /* P2P_NET_DEVICE_H */ +#endif // SERIAL_NET_DEVICE_H diff --git a/src/devices/serial/serial-phy.cc b/src/devices/p2p/p2p-phy.cc similarity index 95% rename from src/devices/serial/serial-phy.cc rename to src/devices/p2p/p2p-phy.cc index 274e11cbe..d69a093d8 100644 --- a/src/devices/serial/serial-phy.cc +++ b/src/devices/p2p/p2p-phy.cc @@ -21,9 +21,9 @@ #include "ns3/debug.h" #include "ns3/queue.h" -#include "serial-phy.h" -#include "serial-net-device.h" -#include "serial-channel.h" +#include "p2p-phy.h" +#include "p2p-net-device.h" +#include "p2p-channel.h" NS_DEBUG_COMPONENT_DEFINE ("SerialPhy"); diff --git a/src/devices/serial/serial-phy.h b/src/devices/p2p/p2p-phy.h similarity index 100% rename from src/devices/serial/serial-phy.h rename to src/devices/p2p/p2p-phy.h diff --git a/src/devices/serial/serial-topology.cc b/src/devices/p2p/p2p-topology.cc similarity index 98% rename from src/devices/serial/serial-topology.cc rename to src/devices/p2p/p2p-topology.cc index 367e12d56..de6ebcb6d 100644 --- a/src/devices/serial/serial-topology.cc +++ b/src/devices/p2p/p2p-topology.cc @@ -33,9 +33,9 @@ #include "ns3/arp-ipv4-interface.h" #include "ns3/ipv4.h" -#include "serial-channel.h" -#include "serial-net-device.h" -#include "serial-topology.h" +#include "p2p-channel.h" +#include "p2p-net-device.h" +#include "p2p-topology.h" #define nil 0 diff --git a/src/devices/serial/serial-topology.h b/src/devices/p2p/p2p-topology.h similarity index 96% rename from src/devices/serial/serial-topology.h rename to src/devices/p2p/p2p-topology.h index 2f59edd3e..f336a9bab 100644 --- a/src/devices/serial/serial-topology.h +++ b/src/devices/p2p/p2p-topology.h @@ -40,7 +40,7 @@ class SerialTopology { public: // Manage point to point links - // Add a full-duplex point-to-point serial link between two nodes + // Add a full-duplex point-to-point link between two nodes // with the specified IP addresses, with specified maximum transmission rate // and propagation delay. static SerialChannel* AddSerialLink( diff --git a/src/devices/serial/propagator.h b/src/devices/p2p/propagator.h similarity index 100% rename from src/devices/serial/propagator.h rename to src/devices/p2p/propagator.h diff --git a/src/devices/serial/serial-channel.cc b/src/devices/serial/serial-channel.cc deleted file mode 100644 index 2c4945bbc..000000000 --- a/src/devices/serial/serial-channel.cc +++ /dev/null @@ -1,160 +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 "serial-channel.h" -#include "serial-net-device.h" -#include "serial-phy.h" -#include "ns3/packet.h" -#include "ns3/simulator.h" -#include "ns3/debug.h" - -NS_DEBUG_COMPONENT_DEFINE ("SerialChannel"); - -namespace ns3 { - -// -// By default, you get a channel with the name "Serial Channel" that has an -// "infitely" fast transmission speed and zero delay. -// XXX: this does not work because m_bps = 0 results in infinitely slow transmission -// speed. -SerialChannel::SerialChannel() -: - Channel ("Serial Channel"), - m_bps (0), - m_delay (Seconds(0)), - m_nDevices(0) -{ - NS_DEBUG("SerialChannel::SerialChannel ()"); -} - -SerialChannel::SerialChannel( - const DataRate& bps, - const Time& delay) -: - Channel ("Serial Channel"), - m_bps (bps), - m_delay (delay), - m_nDevices(0) -{ - NS_DEBUG("SerialChannel::SerialChannel (" << Channel::GetName() << ", " << bps << ", " << - delay << ")"); -} - -SerialChannel::SerialChannel( - const std::string& name, - const DataRate& bps, - const Time& delay) -: - Channel (name), - m_bps (bps), - m_delay (delay), - m_nDevices(0) -{ - NS_DEBUG("SerialChannel::SerialChannel (" << name << ", " << bps << ", " << - delay << ")"); -} - - void -SerialChannel::Attach(SerialPhy *phy) -{ - NS_DEBUG("SerialChannel::Attach (" << phy << ")"); - NS_ASSERT(m_nDevices < N_DEVICES && "Only two devices permitted"); - NS_ASSERT(phy); - - m_link[m_nDevices].m_src = phy; - ++m_nDevices; -// -// 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; - } -} - -void -SerialChannel::TransmitCompleteEvent(Packet p, SerialPhy *src) -{ - NS_DEBUG("SerialChannel::TransmitCompleteEvent (" << &p << ", " << - src << ")"); - - 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; - NS_ASSERT(m_link[wire].m_state == TRANSMITTING); - - m_link[wire].m_state = IDLE; - - NS_DEBUG("SerialChannel::TransmitCompleteEvent (): Receive()"); - - m_link[wire].m_dst->Receive (p); -} - -bool -SerialChannel::Propagate(Packet& p, SerialPhy* src) -{ - NS_DEBUG("SerialChannel::DoPropagate (" << &p << ", " << src << ")"); - - 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; - - if (m_link[wire].m_state == TRANSMITTING) - { - NS_DEBUG("SerialChannel::DoPropagate (): TRANSMITTING, return"); - return false; - } - - m_link[wire].m_state = TRANSMITTING; - -// -// I believe Raj has a method in the DataRate class to do this. Should use -// it when it is available. -// - Time tEvent = Seconds (static_cast (p.GetSize() * 8) / - static_cast (m_bps)) + m_delay; - - NS_DEBUG("SerialChannel::DoSend (): Schedule Receive delay " << tEvent); - - Packet packet = p; - Simulator::Schedule (tEvent, &SerialChannel::TransmitCompleteEvent, this, - p, src); - return true; -} - -uint32_t -SerialChannel::GetNDevices (void) const -{ - return m_nDevices; -} -NetDevice * -SerialChannel::GetDevice (uint32_t i) const -{ - return m_link[i].m_src->GetDevice (); -} - - -} // namespace ns3 diff --git a/src/devices/serial/serial-channel.h b/src/devices/serial/serial-channel.h deleted file mode 100644 index af809322a..000000000 --- a/src/devices/serial/serial-channel.h +++ /dev/null @@ -1,102 +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 SERIAL_CHANNEL_H -#define SERIAL_CHANNEL_H - -#include -#include "ns3/channel.h" -#include "ns3/packet.h" -#include "ns3/nstime.h" - -namespace ns3 { - -// temporary until Raj's code makes it into the dev tree -typedef uint64_t DataRate; -class SerialPhy; -class NetDevice; - -/** - * \brief Simple Serial Channel. - * - * This class represents a very simple serial 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 serial - * 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 channel speed, in bits per second, and a 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 SerialChannel : public Channel { -public: -// -// This is really kidding myself, since just setting N_DEVICES to 3 isn't -// going to come close to magically creating a multi-drop link, but I can't -// bring myself to just type 2 in the code (even though I type 0 and 1 :-). -// - static const int N_DEVICES = 2; - - SerialChannel (); - SerialChannel (const DataRate& bps, const Time& delay); - SerialChannel (const std::string& name, - const DataRate& bps, const Time& delay); - - void Attach (SerialPhy* phy); - bool Propagate (Packet& p, SerialPhy *src); - - virtual uint32_t GetNDevices (void) const; - virtual NetDevice *GetDevice (uint32_t i) const; - - -private: - void TransmitCompleteEvent (Packet p, SerialPhy *src); - - DataRate m_bps; - Time m_delay; - - int32_t m_nDevices; - - enum WireState - { - INITIALIZING, - IDLE, - TRANSMITTING - }; - - class Link - { - public: - Link() : m_state (INITIALIZING), m_src (0), m_dst (0) {} - WireState m_state; - SerialPhy *m_src; - SerialPhy *m_dst; - }; - - Link m_link[N_DEVICES]; -}; - -} // namespace ns3 - -#endif /* SERIAL_CHANNEL_H */ diff --git a/src/devices/serial/serial-net-device.cc b/src/devices/serial/serial-net-device.cc deleted file mode 100644 index cb5bae1f5..000000000 --- a/src/devices/serial/serial-net-device.cc +++ /dev/null @@ -1,160 +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: Mathieu Lacage - */ - -#include -#include -#include "ns3/debug.h" -#include "ns3/queue.h" -#include "ns3/composite-trace-resolver.h" -#include "serial-net-device.h" -#include "serial-channel.h" -#include "serial-phy.h" - -NS_DEBUG_COMPONENT_DEFINE ("SerialNetDevice"); - -namespace ns3 { - - -SerialNetDevice::SerialNetDevice(Node* node) : - NetDevice(node, MacAddress("00:00:00:00:00:00")) -{ - NS_DEBUG ("SerialNetDevice::SerialNetDevice (" << 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(); - SetMtu(512); // bytes - - m_phy = new SerialPhy(node, this); -} - -SerialNetDevice::~SerialNetDevice() -{ - NS_DEBUG ("SerialNetDevice::~SerialNetDevice ()"); - delete m_phy; -} - - -bool -SerialNetDevice::SendTo (Packet& p, const MacAddress& dest) -{ - NS_DEBUG ("SerialNetDevice::SendTo (" << &p << ", " << &dest << ")"); - - assert (IsLinkUp ()); - -#ifdef NOTYET - struct NetDevicePacketDestAddress tag; - tag.address = address; - p.AddTag (tag); -#endif - if (m_queue->Enqueue(p) ) - { - NotifyDataAvailable (); - return true; - } - return false; -} - -TraceResolver * -SerialNetDevice::DoCreateTraceResolver (TraceContext const &context) -{ - CompositeTraceResolver *resolver = new CompositeTraceResolver (context); - resolver->Add ("queue", - MakeCallback (&Queue::CreateTraceResolver, m_queue), - SerialNetDevice::QUEUE); - resolver->Add ("rx", - m_rxTrace, - SerialNetDevice::RX); - return resolver; -} - -bool -SerialNetDevice::Attach (SerialChannel* ch) -{ - NS_DEBUG ("SerialNetDevice::Attach (" << &ch << ")"); - - m_channel = ch; - m_phy->Attach (m_channel); - /* - * 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 SerialChannel 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 -SerialNetDevice::AddQueue (Queue* q) -{ - NS_DEBUG ("SerialNetDevice::AddQueue (" << q << ")"); - - m_queue = q; -} - -void -SerialNetDevice::Receive (Packet& p) -{ - // ignore return value for now. - NS_DEBUG ("SerialNetDevice::Receive (" << &p << ")"); - - m_rxTrace (p); - ForwardUp (p); -} - -void -SerialNetDevice::NotifyDataAvailable(void) -{ - NS_DEBUG ("SerialNetDevice::NotifyDataAvailable ()"); - - Packet p; - bool found = GetQueue ()->Dequeue (p); - if (found) - { -#ifdef NOTYET - struct NetDevicePacketDestAddress tag; - p.PeekTag (tag); - // send packet to address tag.address -#endif - NS_DEBUG ("SerialNetDevice::NotifyDataAvailable (): Dequeued"); - m_phy->Send(p); - } -} - -Queue* -SerialNetDevice::GetQueue(void) const -{ - return m_queue; -} - -SerialChannel* -SerialNetDevice::GetChannel(void) const -{ - return m_channel; -} - -} // namespace ns3 diff --git a/src/devices/serial/serial-net-device.h b/src/devices/serial/serial-net-device.h deleted file mode 100644 index f3f4cf921..000000000 --- a/src/devices/serial/serial-net-device.h +++ /dev/null @@ -1,76 +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 SERIAL_NET_DEVICE_H -#define SERIAL_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" - -namespace ns3 { - -class SerialChannel; -class SerialPhy; -class Queue; - -class SerialNetDevice : public NetDevice { -public: - enum TraceType { - QUEUE, - RX, - }; - SerialNetDevice(Node* node); - virtual ~SerialNetDevice(); - -private: - // Don't let the compiler slip in copy and assignment construction - SerialNetDevice(const SerialNetDevice&); - SerialNetDevice&operator=(const SerialNetDevice&); - -public: - bool Attach(SerialChannel* ch); - void AddQueue(Queue*); - // called by SerialPhy - void Receive (Packet& p); - -protected: - Queue* GetQueue(void) const; - SerialChannel* GetChannel(void) const; - -private: - virtual void NotifyDataAvailable (void); - virtual bool SendTo (Packet& p, const MacAddress& dest); - virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context); - - SerialPhy* m_phy; - SerialChannel* m_channel; - Queue* m_queue; - CallbackTraceSource m_rxTrace; -}; - -}; // namespace ns3 - -#endif // SERIAL_NET_DEVICE_H -