Rename file names from serial to p2p

This commit is contained in:
Tom Henderson
2007-03-25 06:59:11 -07:00
parent f62c2ad8e5
commit 00960518d3
22 changed files with 747 additions and 747 deletions

View File

@@ -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()

View File

@@ -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 ();

View File

@@ -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));

View File

@@ -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<riley@ece.gatech.edu>
//
// 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

View File

@@ -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<riley@ece.gatech.edu>
//
// 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

View File

@@ -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<riley@ece.gatech.edu>
//
// 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

View File

@@ -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<riley@ece.gatech.edu>
//
// 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 */

View File

@@ -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<riley@ece.gatech.edu>
//
/* -*- 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>
*/
// 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<double> (p.GetSize() * 8) /
static_cast<double> (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

View File

@@ -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<riley@ece.gatech.edu>
//
/* -*- 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 <list>
#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 */

View File

@@ -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<riley@ece.gatech.edu>
//
/* -*- 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>
*/
// Implementation of a point-to-point network device
// George F. Riley, Georgia Tech, Spring 2007
#include "ns3/empty-trace-resolver.h"
#include <iostream>
#include <cassert>
#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

View File

@@ -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<riley@ece.gatech.edu>
//
/* -*- 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 <craigdo@ee.washington.edu>
*/
// 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 <string.h>
#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<Packet &> m_rxTrace;
};
}//namespace ns3
}; // namespace ns3
#endif /* P2P_NET_DEVICE_H */
#endif // SERIAL_NET_DEVICE_H

View File

@@ -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");

View File

@@ -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

View File

@@ -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(

View File

@@ -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 <craigdo@ee.washington.edu>
*/
#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<double> (p.GetSize() * 8) /
static_cast<double> (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

View File

@@ -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 <list>
#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 */

View File

@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#include <iostream>
#include <cassert>
#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

View File

@@ -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 <craigdo@ee.washington.edu>
*/
#ifndef SERIAL_NET_DEVICE_H
#define SERIAL_NET_DEVICE_H
#include <string.h>
#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<Packet &> m_rxTrace;
};
}; // namespace ns3
#endif // SERIAL_NET_DEVICE_H