Move LLC encapsulation from NetDevice to subclasses.

This commit is contained in:
Emmanuelle Laprise
2007-07-27 20:45:18 +02:00
parent b078d91894
commit 718ec64593
4 changed files with 69 additions and 25 deletions

View File

@@ -28,6 +28,7 @@
#include "ns3/composite-trace-resolver.h"
#include "point-to-point-net-device.h"
#include "point-to-point-channel.h"
#include "ns3/llc-snap-header.h"
NS_DEBUG_COMPONENT_DEFINE ("PointToPointNetDevice");
@@ -65,13 +66,30 @@ PointToPointNetDevice::~PointToPointNetDevice()
m_queue = 0;
}
void PointToPointNetDevice::AddHeader(Packet& p, const MacAddress& dest,
uint16_t protocolNumber)
{
LlcSnapHeader llc;
llc.SetType (protocolNumber);
p.AddHeader (llc);
}
bool PointToPointNetDevice::ProcessHeader(Packet& p, int& param)
{
LlcSnapHeader llc;
p.RemoveHeader (llc);
param = llc.GetType ();
return true;
}
void PointToPointNetDevice::DoDispose()
{
m_channel = 0;
NetDevice::DoDispose ();
}
void PointToPointNetDevice::SetDataRate(const DataRate& bps)
{
m_bps = bps;
@@ -82,7 +100,8 @@ void PointToPointNetDevice::SetInterframeGap(const Time& t)
m_tInterframeGap = t;
}
bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest)
bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest,
uint16_t protocolNumber)
{
NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")");
NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")");
@@ -91,6 +110,7 @@ bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest)
// "go down" during the simulation? Shouldn't we just wait for it
// to come back up?
NS_ASSERT (IsLinkUp ());
AddHeader(p, dest, protocolNumber);
//
// This class simulates a point to point device. In the case of a serial
@@ -198,9 +218,12 @@ void PointToPointNetDevice::AddQueue (Ptr<Queue> q)
void PointToPointNetDevice::Receive (Packet& p)
{
NS_DEBUG ("PointToPointNetDevice::Receive (" << &p << ")");
int param = 0;
Packet packet = p;
m_rxTrace (p);
ForwardUp (p);
ProcessHeader(packet, param);
m_rxTrace (packet);
ForwardUp (packet, param);
}
Ptr<Queue> PointToPointNetDevice::GetQueue(void) const

View File

@@ -187,11 +187,18 @@ protected:
static const DataRate& GetDefaultRate();
private:
// unimplemented methods to make it impossible
// to copy these objects.
PointToPointNetDevice (const PointToPointNetDevice& nd);
PointToPointNetDevice& operator = (const PointToPointNetDevice&o);
/**
* Adds the necessary headers and trailers to a packet of data in order to
* respect the protocol implemented by the agent.
*/
void AddHeader(Packet& p, const MacAddress& dest, uint16_t protocolNumber);
/**
* Removes, from a packet of data, all headers and trailers that
* relate to the protocol implemented by the agent
* \return Returns true if the packet should be forwarded up the
* protocol stack.
*/
bool ProcessHeader(Packet& p, int& param);
/**
* Send a Packet Down the Wire.
*
@@ -202,9 +209,11 @@ private:
* @see NetDevice
* @param p a reference to the packet to send
* @param dest a reference to the MacAddress of the destination device
* @param protocolNumber Protocol Number used to find protocol touse
* @returns true if success, false on failure
*/
virtual bool SendTo (Packet& p, const MacAddress& dest);
virtual bool SendTo (Packet& p, const MacAddress& dest,
uint16_t protocolNumber);
/**
* Start Sending a Packet Down the Wire.
*

View File

@@ -22,12 +22,15 @@
#include <iostream>
#include "ns3/assert.h"
#include "ns3/object.h"
#include "ns3/debug.h"
#include "channel.h"
#include "net-device.h"
#include "llc-snap-header.h"
#include "node.h"
NS_DEBUG_COMPONENT_DEFINE ("NetDevice");
namespace ns3 {
const InterfaceId NetDevice::iid = MakeInterfaceId ("NetDevice", Object::iid);
@@ -172,10 +175,7 @@ NetDevice::Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber)
{
if (m_isUp)
{
LlcSnapHeader llc;
llc.SetType (protocolNumber);
p.AddHeader (llc);
return SendTo(p, dest);
return SendTo(p, dest, protocolNumber);
}
else
{
@@ -195,18 +195,24 @@ NetDevice::GetChannel (void) const
return DoGetChannel ();
}
// Receive packet from below
// Receive packets from below
bool
NetDevice::ForwardUp (Packet& packet)
NetDevice::ForwardUp(Packet& p, uint32_t param)
{
bool retval = false;
LlcSnapHeader llc;
packet.RemoveHeader (llc);
Packet packet = p;
NS_DEBUG ("NetDevice::ForwardUp: UID is " << packet.GetUid()
<< " device is: " << GetName());
if (!m_receiveCallback.IsNull ())
{
retval = m_receiveCallback (this, packet, llc.GetType ());
retval = m_receiveCallback (this, packet, param);
} else {
NS_DEBUG ("NetDevice::Receive call back is NULL");
}
return retval;
return retval;
}
void

View File

@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Modified by Emmanuelle Laprise to remove dependance on LLC headers
*/
#ifndef NET_DEVICE_H
#define NET_DEVICE_H
@@ -227,6 +228,8 @@ public:
/**
* \param p packet sent from below up to Network Device
* \param param Extra parameter extracted from header and needed by
* some protocols
* \returns true if the packet was forwarded successfully,
* false otherwise.
*
@@ -234,7 +237,8 @@ public:
* forwards it to the higher layers by calling this method
* which is responsible for passing it up to the Rx callback.
*/
bool ForwardUp (Packet& p);
bool ForwardUp (Packet& p, uint32_t param);
/**
* The dispose method for this NetDevice class.
@@ -244,10 +248,13 @@ public:
*/
virtual void DoDispose (void);
Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t> m_receiveCallback;
private:
/**
* \param p packet to send
* \param dest address of destination to which packet must be sent
* \param protocolNumber Number of the protocol (used with some protocols)
* \returns true if the packet could be sent successfully, false
* otherwise.
*
@@ -255,7 +262,7 @@ public:
* method. When the link is Up, this method is invoked to ask
* subclasses to forward packets. Subclasses MUST override this method.
*/
virtual bool SendTo (Packet& p, const MacAddress& dest) = 0;
virtual bool SendTo (Packet& p, const MacAddress &dest, uint16_t protocolNumber) = 0;
/**
* \returns true if this NetDevice needs the higher-layers
* to perform ARP over it, false otherwise.
@@ -279,7 +286,7 @@ public:
*/
virtual Ptr<Channel> DoGetChannel (void) const = 0;
Ptr<Node> m_node;
Ptr<Node> m_node;
std::string m_name;
uint16_t m_ifIndex;
MacAddress m_address;
@@ -290,7 +297,6 @@ public:
bool m_isMulticast;
bool m_isPointToPoint;
Callback<void> m_linkChangeCallback;
Callback<bool,Ptr<NetDevice>,const Packet &,uint16_t> m_receiveCallback;
};
}; // namespace ns3