large checkin-- bringing in serial device code

This commit is contained in:
Tom Henderson committed 2007-02-15 23:55:15 -08:00
1 parent 780a1a22b9
commit a4ea5fa5ab
12 files changed
+654 -3

No files matched your search

+48
View File
@@ -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<riley@ece.gatech.edu>
//
// 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
+66
View File
@@ -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 <craigdo@ee.washingon.edu>
*
* 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<PhysicalLayer *>(&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
+57
View File
@@ -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 <craigdo@ee.washingon.edu>
*
* Wed Feb 14 16:05:46 PST 2007 craigdo: Created
*/
#include <list>
#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<PhysicalLayer *> PhysicalLayerList;
PhysicalLayerList m_physList;
private:
};
}; // namespace ns3
#endif /* SERIAL_PHY_H */
+62
View File
@@ -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<riley@ece.gatech.edu>
//
// 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 <map>
#include "capability.h"
#include "l3-protocol.h"
namespace ns3 {
// Use a map structure for l3 protocol lookup
typedef std::map<int, L3Protocol*> 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
+141
View File
@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#include <iostream>
#include <cassert>
#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
+67
View File
@@ -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 <craigdo@ee.washington.edu>
*/
#ifndef SERIAL_NET_DEVICE_H
#define SERIAL_NET_DEVICE_H
#include <string.h>
#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
+49
View File
@@ -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 <craigdo@ee.washingon.edu>
*
* 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<Packet *>(&p);}
Packet *m_packet;
private:
};
}; // namespace ns3
#endif /* SERIAL_PHY_H */
+46
View File
@@ -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<riley@ece.gatech.edu>
//
// 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
+45
View File
@@ -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
+47
View File
@@ -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 <list>
#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<SerialNetDevice *> NetDevices;
typedef std::list<SerialNetDevice *>::const_iterator NetDevicesCI;
NetDevices m_devices;
};
} // namespace ns3
#endif /* CHANNEL_SERIAL__H */