Mathieu Lacage 2007-03-30 13:02:11 +02:00
commit cf2e2f54c7
6 changed files with 259 additions and 234 deletions

View File

@ -145,7 +145,6 @@ common.add_sources([
'packet.cc',
'tags.cc',
'pcap-writer.cc',
'trace-writer.cc',
'variable-tracer-test.cc',
'trace-context.cc',
'trace-resolver.cc',
@ -166,7 +165,6 @@ common.add_inst_headers([
'uv-trace-source.h',
'sv-trace-source.h',
'fv-trace-source.h',
'trace-writer.h',
'pcap-writer.h',
'callback-trace-source.h',
'trace-context.h',

View File

@ -17,10 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if 0
#include <list>
#include <cassert>
#endif
#include <fstream>
#include "ns3/debug.h"
#include "ns3/internet-node.h"
@ -29,7 +26,6 @@
#include "ns3/ipv4-address.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"
#include "ns3/ipv4.h"
@ -42,23 +38,13 @@
using namespace ns3;
class Logger : public TraceWriter{
class Logger {
public:
Logger ()
{
NS_DEBUG_UNCOND("**** Logger()");
}
Logger (std::string const &filename)
{
m_filestr.open (filename.c_str ());
NS_DEBUG_UNCOND("**** Logger(string const &)");
Open(filename);
}
Logger (char const *filename) : m_tracer(filename)
{
NS_DEBUG_UNCOND("**** Logger(char const *)");
Open(filename);
}
~Logger () {}
@ -89,7 +75,7 @@ public:
}
protected:
TraceWriter m_tracer;
std::ofstream m_filestr;;
};
static void

View File

@ -1,112 +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.washingon.edu>
*
* Thu Feb 8 10:42:52 PST 2007 craigdo: Created from pcap-writer.c
*/
#include "ns3/debug.h"
#include "trace-writer.h"
NS_DEBUG_COMPONENT_DEFINE ("TraceWriter");
namespace ns3 {
TraceWriter::TraceWriter () :
m_filestr()
{
NS_DEBUG ("TraceWriter()::TraceWriter()");
std::streambuf *sb = m_filestr.rdbuf();
NS_DEBUG ("TraceWriter()::TraceWriter(): rdbuf ()");
rdbuf(sb);
NS_DEBUG ("TraceWriter()::TraceWriter(): done");
}
TraceWriter::TraceWriter (std::string const &filename) :
m_filestr()
{
NS_DEBUG ("TraceWriter()::TraceWriter (\"" << filename << "\")");
m_filestr.open (filename.c_str(), std::ios::out | std::ios::app);
std::streambuf *sb = m_filestr.rdbuf();
NS_DEBUG ("TraceWriter()::TraceWriter(): rdbuf ()");
rdbuf(sb);
NS_DEBUG ("TraceWriter()::TraceWriter(): done");
}
TraceWriter::TraceWriter (char const *filename) :
m_filestr()
{
NS_DEBUG ("TraceWriter()::TraceWriter (\"" << filename << "\")");
m_filestr.open (filename, std::ios::out | std::ios::app);
std::streambuf *sb = m_filestr.rdbuf();
NS_DEBUG ("TraceWriter()::TraceWriter(): rdbuf ()");
rdbuf(sb);
NS_DEBUG ("TraceWriter()::TraceWriter(): done");
}
TraceWriter::~TraceWriter ()
{
NS_DEBUG ("TraceWriter()::~TraceWriter()");
}
void
TraceWriter::Open (std::string const &filename)
{
NS_DEBUG ("TraceWriter()::Open (\"" << filename << "\")");
m_filestr.open (filename.c_str(), std::ios::out);
}
void
TraceWriter::Open (char const *filename)
{
NS_DEBUG ("TraceWriter()::Open (\"" << filename << "\")");
m_filestr.open (filename, std::ios::out);
}
void
TraceWriter::Close ()
{
NS_DEBUG ("TraceWriter()::Close ()");
m_filestr.close ();
}
void
TraceWriter::Write (std::string const &str)
{
NS_DEBUG ("TraceWriter()::Write (\"" << str << "\")");
m_filestr << str;
}
}; // namespace ns3

View File

@ -1,59 +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.washingon.edu>
*
* Thu Feb 8 10:41:40 PST 2007 craigdo: Created
*/
#ifndef TRACE_WRITER_H
#define TRACE_WRITER_H
#include <iostream>
#include <fstream>
#include <streambuf>
#include <string>
#include "ns3/callback.h"
namespace ns3 {
class TraceWriter : public std::ostream {
public:
TraceWriter ();
TraceWriter (std::string const &filename);
TraceWriter (char const *filename);
~TraceWriter ();
void Open (std::string const &filename);
void Open (char const *filename);
void Close ();
/**
* \param String to write to output file
*/
void Write (std::string const &str);
protected:
std::ofstream m_filestr;
void Init (const char *filename);
};
}; // namespace ns3
#endif /* TRACE_WRITER_H */

View File

@ -61,6 +61,9 @@ PointToPointNetDevice::~PointToPointNetDevice()
m_channel->Unref ();
m_channel = 0;
}
delete m_queue;
m_queue = 0;
}
//
@ -136,7 +139,7 @@ PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest)
NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")");
assert (IsLinkUp ());
NS_ASSERT (IsLinkUp ());
#ifdef NOTYET
struct NetDevicePacketDestAddress tag;
@ -206,14 +209,15 @@ PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest)
PointToPointNetDevice::TransmitStart (Packet &p)
{
NS_DEBUG ("PointToPointNetDevice::TransmitStart (" << &p << ")");
NS_DEBUG ("PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")");
NS_DEBUG (
"PointToPointNetDevice::TransmitStart (): UID is " << p.GetUid () << ")");
//
// This function is called to start the process of transmitting a packet.
// We need to tell the channel that we've started wiggling the wire and
// schedule an event that will be executed when it's time to tell the
// channel that we're done wiggling the wire.
//
NS_ASSERT(m_txMachineState == READY && "Must be READY to transmit");
NS_ASSERT_MSG(m_txMachineState == READY, "Must be READY to transmit");
m_txMachineState = BUSY;
Time tEvent = Seconds (m_bps.CalculateTxTime(p.GetSize()));
@ -237,12 +241,12 @@ PointToPointNetDevice::TransmitCompleteEvent (void)
// schedule an event that will be executed when it's time to re-enable
// the transmitter after the interframe gap.
//
NS_ASSERT(m_txMachineState == BUSY && "Must be BUSY if transmitting");
NS_ASSERT_MSG(m_txMachineState == BUSY, "Must be BUSY if transmitting");
m_txMachineState = GAP;
Packet p;
bool found;
found = m_queue->Dequeue (p);
NS_ASSERT(found && "Packet must be on queue if transmitted");
NS_ASSERT_MSG(found, "Packet must be on queue if transmitted");
NS_DEBUG ("PointToPointNetDevice::TransmitCompleteEvent (): Pkt UID is " <<
p.GetUid () << ")");
m_channel->TransmitEnd (p, this);
@ -266,7 +270,7 @@ PointToPointNetDevice::TransmitReadyEvent (void)
// gap has passed. If there are pending transmissions, we use this opportunity
// to start the next transmit.
//
NS_ASSERT(m_txMachineState == GAP && "Must be in interframe gap");
NS_ASSERT_MSG(m_txMachineState == GAP, "Must be in interframe gap");
m_txMachineState = READY;
if (m_queue->IsEmpty())
@ -278,7 +282,7 @@ PointToPointNetDevice::TransmitReadyEvent (void)
Packet p;
bool found;
found = m_queue->Peek (p);
NS_ASSERT(found && "IsEmpty false but no Packet on queue?");
NS_ASSERT_MSG(found, "IsEmpty false but no Packet on queue?");
TransmitStart (p);
}
}

View File

@ -37,63 +37,271 @@ class Queue;
class PointToPointChannel;
/**
* \brief A duplex link
* \class PointToPointNetDevice
* \brief A Device for a Point to Point Network Link.
*
* XXX: Add small description of model implemented in this subclass of NetDevice.
* Ns-3 takes a four-layer view of a protocol stack. This is the same model
* that TCP uses. In this view, layers 5-7 of the OSI reference model are
* grouped together into an application layer; layer four (transport / TCP) is
* broken out; layer three (network / IP) is broken out; and layers 1-2 are
* grouped together. We call this grouping of layers one and two a NetDevice
* and represent it as a class in the system.
*
* The NetDevice class is specialized according to the needs of the specific
* kind of network link. In this case, the link is a PointToPoint link. The
* PointToPoint link is a family of classes that includes this class, the
* PointToPointNetDevice, a PointToPointChannel class that represents the
* actual medium across which bits are sent, a PointToPointIpv4Interface class
* that provides the hook to tie a general purpose node to this specific
* link, and finally, a PointToPointTopology object that is responsible for
* putting all of the pieces together.
*
* This is the PointToPointNetDevice class that represents, essentially, the
* PC card that is used to connect to the PointToPoint network.
*/
class PointToPointNetDevice : public NetDevice {
public:
enum TraceType {
QUEUE,
RX,
};
PointToPointNetDevice (Node* node);
PointToPointNetDevice (const PointToPointNetDevice& nd);
virtual ~PointToPointNetDevice();
PointToPointNetDevice& operator= (PointToPointNetDevice nd);
/**
* \param bps the number of bits per second
* which this interface can achieve.
* Enumeration of the types of traces supported in the class.
*
*/
enum TraceType {
QUEUE, /**< Trace queue events on the attached queue */
RX, /**< Trace packet reception events (from the channel) */
};
/**
* Construct a PointToPointNetDevice
*
* This is the constructor for the PointToPointNetDevice. It takes as a
* parameter the Node to which this device is connected. Ownership of the
* Node pointer is not implied and the node must not be deleded.
*
* @see PointToPointTopology::AddPointToPointLink ()
* @param node the Node to which this device is connected.
*/
PointToPointNetDevice (Node* node);
/**
* Copy Construct a PointToPointNetDevice
*
* This is the copy constructor for the PointToPointNetDevice. This is
* primarily used in topology creation.
*
* @see PointToPointTopology::AddPointToPointLink ()
* @param nd the object to be copied
*/
PointToPointNetDevice (const PointToPointNetDevice& nd);
/**
* Destroy a PointToPointNetDevice
*
* This is the destructor for the PointToPointNetDevice.
*/
virtual ~PointToPointNetDevice();
/**
* Assignment Operator for a PointToPointNetDevice
*
* This is the assignment operator for the PointToPointNetDevice. This is
* to allow
*
* @param nd the object to be copied
*/
PointToPointNetDevice& operator= (PointToPointNetDevice nd);
/**
* Set the Data Rate used for transmission of packets. The data rate is
* set in the Attach () method from the corresponding field in the channel
* to which the device is attached. It can be overridden using this method.
*
* @see Attach ()
* @param bps the data rate at which this object operates
*/
void SetDataRate(DataRate bps);
/**
* Set the inteframe gap used to separate packets. The interframe gap
* defines the minimum space required between packets sent by this device.
* It is usually set in the Attach () method based on the speed of light
* delay of the channel to which the device is attached. It can be
* overridden using this method if desired.
*
* @see Attach ()
* @param t the interframe gap time
*/
void SetInterframeGap(Time t);
public:
/**
* Attach the device to a channel.
*
* The PointToPointTopology object creates a PointToPointChannel and two
* PointtoPointNetDevices. In order to introduce these components to each
* other, the topology object calls Attach () on each PointToPointNetDevice.
* Inside this method, the Net Device calls out to the PointToPointChannel
* to introduce itself.
*
* @see PointToPointTopology::AddPointToPointLink ()
* @see SetDataRate ()
* @see SetInterframeGap ()
* @param ch a pointer to the channel to which this object is being attached.
*/
bool Attach(PointToPointChannel* ch);
void AddQueue(Queue*);
/**
* Attach a queue to the PointToPointNetDevice.
*
* The PointToPointNetDevice "owns" a queue. This queue is created by the
* PointToPointTopology object and implements a queueing method such as
* DropTail or RED. The PointToPointNetDevice assumes ownership of this
* queue and must delete it when the device is destroyed.
*
* @see PointToPointTopology::AddPointToPointLink ()
* @see Queue
* @see DropTailQueue
* @param queue a pointer to the queue for which object is assuming
* ownership.
*/
void AddQueue(Queue* queue);
/**
* Receive a packet from a connected PointToPointChannel.
*
* The PointToPointNetDevice receives packets from its connected channel
* and forwards them up the protocol stack. This is the public method
* used by the channel to indicate that the last bit of a packet has
* arrived at the device.
*
* @see PointToPointChannel
* @param p a reference to the received packet
*/
void Receive (Packet& p);
protected:
/**
* Get a copy of the attached Queue.
*
* This method is provided for any derived class that may need to get
* direct access to the underlying queue.
*
* @see PointToPointTopology
* @returns a pointer to the queue.
*/
Queue* GetQueue(void) const;
private:
virtual bool SendTo (Packet& p, const MacAddress& dest);
bool TransmitStart (Packet &p);
void TransmitCompleteEvent (void);
void TransmitReadyEvent (void);
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
/**
* Get a copy of the attached Channel
*
* This method is provided for any derived class that may need to get
* direct access to the connected channel
*
* @see PointToPointChannel
* @returns a pointer to the channel
*/
virtual Channel *DoGetChannel(void) const;
private:
/**
* Send a Packet Down the Wire.
*
* The SendTo method is defined as the standard way that the level three
* protocol uses to tell a NetDevice to send a packet. SendTo is declared
* as abstract in the NetDevice class and we declare it here.
*
* @see NetDevice
* @param p a reference to the packet to send
* @param dest a reference to the MacAddress of the destination device
* @returns true if success, false on failure
*/
virtual bool SendTo (Packet& p, const MacAddress& dest);
/**
* Start Sending a Packet Down the Wire.
*
* The TransmitStart method is the method that is used internally in the
* PointToPointNetDevice to begin the process of sending a packet out on
* the channel. The corresponding method is called on the channel to let
* it know that the physical device this class represents has virually
* started sending signals. An event is scheduled for the time at which
* the bits have been completely transmitted.
*
* @see PointToPointChannel::TransmitStart ()
* @see TransmitCompleteEvent ()
* @param p a reference to the packet to send
* @returns true if success, false on failure
*/
bool TransmitStart (Packet &p);
/**
* Stop Sending a Packet Down the Wire and Begin the Interframe Gap.
*
* The TransmitCompleteEvent method is used internally to finish the process
* of sending a packet out on the channel. During execution of this method
* the TransmitEnd method is called on the channel to let it know that the
* physical device this class represents has virually finished sending
* signals. The channel uses this event to begin its speed of light delay
* timer after which it notifies the Net Device at the other end of the
* link that the bits have arrived. During this method, the net device
* also schedules the TransmitReadyEvent at which time the transmitter
* becomes ready to send the next packet.
*
* @see PointToPointChannel::TransmitEnd ()
* @see TransmitReadyEvent ()
* @param p a reference to the packet to send
* @returns true if success, false on failure
*/
void TransmitCompleteEvent (void);
/**
* Cause the Transmitter to Become Ready to Send Another Packet.
*
* The TransmitReadyEvent method is used internally to re-enable the
* transmit machine of the net device. It is scheduled after a suitable
* interframe gap after the completion of the previous transmission.
* The queue is checked at this time, and if there is a packet waiting on
* the queue, the transmission process is begun.
*
* @see TransmitStart ()
*/
void TransmitReadyEvent (void);
/**
* Create a Trace Resolver for events in the net device.
*
* @see class TraceResolver
*/
virtual TraceResolver *DoCreateTraceResolver (TraceContext const &context);
/**
* Enumeration of the states of the transmit machine of the net device.
*/
enum TxMachineState
{
READY,
BUSY,
GAP
READY, /**< The transmitter is ready to begin transmission of a packet */
BUSY, /**< The transmitter is busy transmitting a packet */
GAP /**< The transmitter is in the interframe gap time */
};
/**
* The state of the Net Device transmit state machine.
* @see TxMachineState
*/
TxMachineState m_txMachineState;
/**
* The data rate that the Net Device uses to simulate packet transmission
* timing.
* @see class DataRate
*/
DataRate m_bps;
/**
* The interframe gap that the Net Device uses to throttle packet
* transmission
* @see class Time
*/
Time m_tInterframeGap;
/**
* The PointToPointChannel to which this PointToPointNetDevice has been
* attached.
* @see class PointToPointChannel
*/
PointToPointChannel* m_channel;
/**
* The Queue which this PointToPointNetDevice uses as a packet source.
* Management of this Queue has been delegated to the PointToPointNetDevice
* and it has the responsibility for deletion.
* @see class Queue
* @see class DropTailQueue
*/
Queue* m_queue;
/**
* The trace source for the packet reception events that the device can
* fire.
*
* @see class CallBackTraceSource
* @see class TraceResolver
*/
CallbackTraceSource<Packet &> m_rxTrace;
};