diff --git a/SConstruct b/SConstruct index 30bdf87a9..7a6250d4a 100644 --- a/SConstruct +++ b/SConstruct @@ -19,7 +19,8 @@ core.add_sources([ 'reference-list-test.cc', 'callback-test.cc', 'ptr.cc', - 'test.cc' + 'test.cc', + 'debug.cc' ]) env = Environment() if env['PLATFORM'] == 'posix' or env['PLATFORM'] == 'darwin': @@ -39,7 +40,8 @@ core.add_inst_headers([ 'reference-list.h', 'callback.h', 'ptr.h', - 'test.h' + 'test.h', + 'debug.h' ]) @@ -153,6 +155,7 @@ node.add_sources ([ 'ipv4-address.cc', 'internet-node.cc', 'net-device.cc', + 'net-device-serial.cc', 'mac-address.cc', 'ipv4-header.cc', 'udp-header.cc', @@ -174,7 +177,10 @@ node.add_sources ([ 'ipv4-loopback-interface.cc', 'llc-snap-header.cc', 'header-utils.cc', - 'net-device-list.cc' + 'net-device-list.cc', + 'serial-channel.cc', + 'queue.cc', + 'drop-tail.cc', ]) node.add_headers ([ 'ipv4-header.h', @@ -193,8 +199,14 @@ node.add_headers ([ 'l3-protocol.h', 'ipv4-l4-demux.h', 'net-device-list.h', + 'net-device-serial.h', 'llc-snap-header.h', 'header-utils.h', + 'protocol.h', + 'demux.h', + 'serial-channel.h', + 'queue.h', + 'drop-tail.h' ]) node.add_inst_headers ([ 'node.h', @@ -209,6 +221,9 @@ node.add_inst_headers ([ 'mac-address.h', 'ipv4.h', 'ipv4-route.h', + 'serial-channel.h', + 'queue.h', + 'net-device-serial.h' ]) diff --git a/samples/ns-2/simple.tcl.cc b/samples/ns-2/simple.tcl.cc index 644b3d822..b1300f0d5 100644 --- a/samples/ns-2/simple.tcl.cc +++ b/samples/ns-2/simple.tcl.cc @@ -24,9 +24,15 @@ #include "ns3/simulator.h" #include "ns3/nstime.h" #include "ns3/internet-node.h" +#include "ns3/serial-channel.h" using namespace ns3; +static SerialChannel* AddDuplexLink(InternetNode* a, InternetNode* b) { + SerialChannel* channel = new SerialChannel(); + return channel; +} + int main (int argc, char *argv[]) { // set ns [new Simulator] @@ -54,6 +60,8 @@ int main (int argc, char *argv[]) // $ns duplex-link $n1 $n2 5Mb 2ms DropTail // $ns duplex-link $n2 $n3 1.5Mb 10ms DropTail // ** part of topology creation object? ** + SerialChannel* ch = AddDuplexLink(n0,n1); + delete ch; // $ns duplex-link-op $n0 $n2 orient right-up // $ns duplex-link-op $n1 $n2 orient right-down diff --git a/src/node/capability.h b/src/node/capability.h new file mode 100644 index 000000000..ffd5dbe11 --- /dev/null +++ b/src/node/capability.h @@ -0,0 +1,48 @@ +// -*- Mode:NS3 -*- +// +// 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 +// +// Define the base class for all node capabilities. +// George F. Riley, Georgia Tech, Fall 2006 + +#ifndef __CAPABILITY_H__ +#define __CAPABILITY_H__ + +// All capabilities must implement a copy method, to allow node subclasses +// to have a pointer to any subclass of the capability and still copy +// correctly. + +namespace ns3 { + +const int nil=0; + +class Node; + +class Capability +{ +public: + Capability() : pNode(nil) {} + virtual ~Capability() {} + virtual Capability* Copy() const = 0; + Node* pNode; // Node on which this capability is assigned +}; + +}; // namespace ns3 + +#endif diff --git a/src/node/channel.cc b/src/node/channel.cc new file mode 100644 index 000000000..788aff27e --- /dev/null +++ b/src/node/channel.cc @@ -0,0 +1,66 @@ +/* -*- 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 + * + * Thu Feb 15 14:50:46 PST 2007 craigdo: Created. + */ + +#include "ns3/debug.h" +#include "channel.h" + +namespace ns3 { + +namespace { + int chDebug = 1; +}; + +Channel::Channel () +{ + NS3_TRACE(chDebug, "Channel::Channel ()") +} + +Channel::~Channel () +{ + NS3_TRACE(chDebug, "Channel::~Channel ()") +} + + bool +Channel::Connect (PhysicalLayer &phys) +{ + NS3_TRACE(chDebug, "Channel::Connect (" << &phys << ")") + m_physList.push_back(static_cast(&phys)); + return true; +} + + bool +Channel::Propagate (Propagator &propagator) +{ + NS3_TRACE(chDebug, "Channel::Propagate (" << &propagator << ")") + + for (PhysicalLayerList::const_iterator i = m_physList.begin (); + i != m_physList.end (); + i++) + { + (*i)->Receive (propagator); + } + + return true; +} + +} // namespace ns3 diff --git a/src/node/channel.h b/src/node/channel.h new file mode 100644 index 000000000..25fc32d3e --- /dev/null +++ b/src/node/channel.h @@ -0,0 +1,57 @@ +/* -*- 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 + * + * Wed Feb 14 16:05:46 PST 2007 craigdo: Created + */ + +#include +#include "physical-layer.h" + +#ifndef CHANNEL_H +#define CHANNEL_H + +namespace ns3 { + +class Propagator; + +class Channel +{ +public: + Channel (); + virtual ~Channel (); + + // called by the builderto introduce the channel and the physical layer + // of the node. + bool Connect (PhysicalLayer &phys); + + // Called by the physical layer to cause bits to propagate along the channel + // The channel will call Receive on each of the phys. + bool Propagate (Propagator &p); + +protected: + typedef std::list PhysicalLayerList; + PhysicalLayerList m_physList; + +private: +}; + +}; // namespace ns3 + +#endif /* SERIAL_PHY_H */ diff --git a/src/node/demux.h b/src/node/demux.h new file mode 100644 index 000000000..a75a4d3e7 --- /dev/null +++ b/src/node/demux.h @@ -0,0 +1,62 @@ +// -*- Mode:NS3 -*- +// +// 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 +// +// Define the Protocols capability for ns3. +// George F. Riley, Georgia Tech, Fall 2006 + +// This object manages the different layer 3 protocols for any ns3 +// node that has this capability. + +// Note; changed class name to Demux-- tomh + +#ifndef __DEMUX_H__ +#define __DEMUX_H__ + +#include + +#include "capability.h" +#include "l3-protocol.h" + +namespace ns3 { + +// Use a map structure for l3 protocol lookup +typedef std::map DemuxMap_t; + +class Demux : public Capability +{ +public: + Demux() {} + Demux(const Demux&); + virtual ~Demux(); + virtual Demux* Copy() const; + + // Insert a new protocol + void Insert(L3Protocol*, int proto); + // Look up a protocol by protocol number + L3Protocol* Lookup(int); + +private: + DemuxMap_t Protocols; +}; + +}; // namespace ns3 + +#endif + diff --git a/src/node/net-device-serial.cc b/src/node/net-device-serial.cc new file mode 100644 index 000000000..1ceb3f8c7 --- /dev/null +++ b/src/node/net-device-serial.cc @@ -0,0 +1,141 @@ +/* -*- 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 "protocol.h" +#include "demux.h" +#include "queue.h" +#include "net-device-serial.h" +#include "serial-channel.h" + +namespace ns3 { + +const int IPv4ProtocolNumber = 4; + +namespace { + int sndDebug = 0; +} + +SerialNetDevice::SerialNetDevice(Node* node, const MacAddress& addr) : + NetDevice(node, addr) +{ + NS3_TRACE(sndDebug, + "SerialNetDevice::SerialNetDevice (" << node << ", " << &addr << ")") + + // 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 +} + +SerialNetDevice::~SerialNetDevice() +{ + NS3_TRACE(sndDebug, + "SerialNetDevice::~SerialNetDevice ()") +} + + + bool +SerialNetDevice::SendTo (Packet& p, const MacAddress& dest) +{ + NS3_TRACE(sndDebug, + "SerialNetDevice::SendTo (" << &p << ", " << &dest << ")") + + assert (IsLinkUp ()); + +#ifdef NOTYET + struct NetDevicePacketDestAddress tag; + tag.address = address; + p.AddTag (tag); +#endif + if (m_queue->Enque(p) ) + { + NotifyDataAvailable (); + return true; + } + return false; +} + + bool +SerialNetDevice::Attach (SerialChannel* ch) +{ + NS3_TRACE(sndDebug, + "SerialNetDevice::Attach (" << &ch << ")") + + m_channel = ch; + /* + * 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) +{ + NS3_TRACE(sndDebug, + "SerialNetDevice::AddQueue (" << q << ")") + + m_queue = q; +} + +void +SerialNetDevice::Receive (Packet& p) +{ + // ignore return value for now. + NS3_TRACE(sndDebug, + "SerialNetDevice::Receive (" << &p << ")") + + ForwardUp (p); +} + +void +SerialNetDevice::NotifyDataAvailable(void) +{ + NS3_TRACE(sndDebug, + "SerialNetDevice::NotifyDataAvailable ()") + + Packet p; + bool found = GetQueue ()->Deque (p); + if (found) + { +#ifdef NOTYET + struct NetDevicePacketDestAddress tag; + p.PeekTag (tag); + // send packet to address tag.address +#endif + NS3_TRACE(sndDebug, + "SerialNetDevice::NotifyDataAvailable (): Dequeued") + m_channel->Send(p, this); + } +} + +} // namespace ns3 diff --git a/src/node/net-device-serial.h b/src/node/net-device-serial.h new file mode 100644 index 000000000..d3dd40d0d --- /dev/null +++ b/src/node/net-device-serial.h @@ -0,0 +1,67 @@ +/* -*- 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 + */ + +#ifndef SERIAL_NET_DEVICE_H +#define SERIAL_NET_DEVICE_H + +#include +#include "mac-address.h" +#include "internet-node.h" +#include "net-device.h" +#include "ns3/callback.h" +#include "ns3/packet.h" + +namespace ns3 { + +class SerialChannel; +class Queue; + +class SerialNetDevice : public NetDevice { +public: + SerialNetDevice(Node* node, const MacAddress& addr); + 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 ChannelSerial + void Receive (Packet& p); + +protected: + Queue* GetQueue(void) const { return m_queue;}; + +private: + virtual void NotifyDataAvailable (void); + virtual bool SendTo (Packet& p, const MacAddress& dest); + + SerialChannel* m_channel; + Queue* m_queue; +}; + +}; // namespace ns3 + +#endif // SERIAL_NET_DEVICE_H + diff --git a/src/node/propagator.h b/src/node/propagator.h new file mode 100644 index 000000000..e7ae002bb --- /dev/null +++ b/src/node/propagator.h @@ -0,0 +1,49 @@ +/* -*- 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 + * + * Thu Feb 15 15:06:15 PST 2007 craigdo: Created + */ + +#ifndef PROPAGATOR_H +#define PROPAGATOR_H + +#include "ns3/packet.h" + +namespace ns3 { + +class Propagator +{ +public: + Propagator () : m_packet(0) {} + virtual ~Propagator () {} + + void SetPacket (Packet &p) {DoSetPacket(p);} + +protected: + virtual void DoSetPacket (Packet &p) {m_packet = static_cast(&p);} + + Packet *m_packet; +private: +}; + + +}; // namespace ns3 + +#endif /* SERIAL_PHY_H */ diff --git a/src/node/protocol.h b/src/node/protocol.h new file mode 100644 index 000000000..e9f918505 --- /dev/null +++ b/src/node/protocol.h @@ -0,0 +1,46 @@ +// -*- Mode:NS3 -*- +// +// 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 +// + +// NS3 - Layer 3 Protocol base class +// George F. Riley, Georgia Tech, Summer 2006 + +// Note: class name tentatively moved to Protocol-- tomh + +#ifndef __protocol_h__ +#define __protocol_h__ + +namespace ns3 { + +class InternetNode; + +class Protocol { +public: +Protocol(InternetNode* n) : m_node(n) {} +Protocol* Copy() const { return new Protocol(*this); } +InternetNode *GetNode (void) const { return m_node; } + +private: + InternetNode* m_node; +}; + +}; + +#endif diff --git a/src/node/serial-channel.cc b/src/node/serial-channel.cc new file mode 100644 index 000000000..6e51c8b0b --- /dev/null +++ b/src/node/serial-channel.cc @@ -0,0 +1,45 @@ +/* -*- 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 + */ + +#include "serial-channel.h" +#include "net-device-serial.h" +#include "ns3/packet.h" + +namespace ns3 { + +void +SerialChannel::Attach(SerialNetDevice* nd) +{ + nd->Attach(this); + m_devices.push_back (nd); +} + +bool +SerialChannel::Send(Packet& p, SerialNetDevice* caller) +{ + for (NetDevicesCI i = m_devices.begin (); i != m_devices.end (); i++) { + if (caller != (*i)) { + (*i)->Receive (p); + return true; + } + } + return false; +} + +} // namespace ns3 diff --git a/src/node/serial-channel.h b/src/node/serial-channel.h new file mode 100644 index 000000000..f0bb04926 --- /dev/null +++ b/src/node/serial-channel.h @@ -0,0 +1,47 @@ +/* -*- 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 + */ + +// The queue base class does not have any limit based on the number +// of packets or number of bytes. It is, conceptually, infinite +// by default. Only subclasses define limitations. +// The base class implements tracing and basic statistics calculations. + +#ifndef CHANNEL_SERIAL_H +#define CHANNEL_SERIAL_H + +#include +#include "net-device-serial.h" +#include "ns3/packet.h" + +namespace ns3 { + +// Simple SerialChannel class +class SerialChannel { +public: + bool Send(Packet& p, SerialNetDevice *caller); + void Attach (SerialNetDevice* nd); +private: + typedef std::list NetDevices; + typedef std::list::const_iterator NetDevicesCI; + NetDevices m_devices; +}; + +} // namespace ns3 + +#endif /* CHANNEL_SERIAL__H */