merge
This commit is contained in:
commit
fda49d72c1
35 files changed
+3115
-67
No files matched your search
@@ -0,0 +1,49 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 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 "address-utils.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
void WriteTo (Buffer::Iterator &i, Ipv4Address ad)
|
||||
{
|
||||
i.WriteHtonU32 (ad.GetHostOrder ());
|
||||
}
|
||||
void WriteTo (Buffer::Iterator &i, MacAddress ad)
|
||||
{
|
||||
uint8_t mac[MacAddress::MAX_LEN];
|
||||
ad.Peek (mac);
|
||||
i.Write (mac, ad.GetLength ());
|
||||
}
|
||||
|
||||
void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
|
||||
{
|
||||
ad.SetHostOrder (i.ReadNtohU32 ());
|
||||
}
|
||||
void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len)
|
||||
{
|
||||
uint8_t mac[MacAddress::MAX_LEN];
|
||||
i.Read (mac, len);
|
||||
ad.Set (mac, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}; // namespace ns3
|
||||
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 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>
|
||||
*/
|
||||
#ifndef ADDRESS_UTILS_H
|
||||
#define ADDRESS_UTILS_H
|
||||
|
||||
#include "ns3/buffer.h"
|
||||
#include "ns3/ipv4-address.h"
|
||||
#include "ns3/mac-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
void WriteTo (Buffer::Iterator &i, Ipv4Address ad);
|
||||
void WriteTo (Buffer::Iterator &i, MacAddress ad);
|
||||
|
||||
void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad);
|
||||
void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len);
|
||||
|
||||
};
|
||||
|
||||
#endif /* ADDRESS_UTILS_H */
|
||||
@@ -0,0 +1,173 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
|
||||
*/
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/debug.h"
|
||||
#include "ns3/header.h"
|
||||
#include "ethernet-header.h"
|
||||
#include "address-utils.h"
|
||||
|
||||
NS_DEBUG_COMPONENT_DEFINE ("EthernetHeader");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
bool EthernetHeader::m_enPreambleSfd = false;
|
||||
|
||||
EthernetHeader::EthernetHeader ()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
EthernetHeader::~EthernetHeader ()
|
||||
{}
|
||||
|
||||
void
|
||||
EthernetHeader::Init()
|
||||
{
|
||||
m_preambleSfd = 0;
|
||||
m_lengthType = 0x0;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::EnablePreambleSfd (bool enable)
|
||||
{
|
||||
m_enPreambleSfd = enable;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::SetLengthType (uint16_t lengthType)
|
||||
{
|
||||
m_lengthType = lengthType;
|
||||
}
|
||||
uint16_t
|
||||
EthernetHeader::GetLengthType (void) const
|
||||
{
|
||||
return m_lengthType;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::SetPreambleSfd (uint64_t preambleSfd)
|
||||
{
|
||||
m_preambleSfd = preambleSfd;
|
||||
}
|
||||
uint64_t
|
||||
EthernetHeader::GetPreambleSfd (void) const
|
||||
{
|
||||
return m_preambleSfd;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::SetSource (MacAddress source)
|
||||
{
|
||||
m_source = source;
|
||||
}
|
||||
MacAddress
|
||||
EthernetHeader::GetSource (void) const
|
||||
{
|
||||
return m_source;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::SetDestination (MacAddress dst)
|
||||
{
|
||||
m_destination = dst;
|
||||
}
|
||||
MacAddress
|
||||
EthernetHeader::GetDestination (void) const
|
||||
{
|
||||
return m_destination;
|
||||
}
|
||||
|
||||
ethernet_header_t
|
||||
EthernetHeader::GetPacketType (void) const
|
||||
{
|
||||
return LENGTH;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
EthernetHeader::GetHeaderSize (void) const
|
||||
{
|
||||
return GetSerializedSize();
|
||||
}
|
||||
|
||||
std::string
|
||||
EthernetHeader::DoGetName (void) const
|
||||
{
|
||||
return "ETHERNET";
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::PrintTo (std::ostream &os) const
|
||||
{
|
||||
// ethernet, right ?
|
||||
os << "(ethernet)";
|
||||
if (m_enPreambleSfd)
|
||||
{
|
||||
os << " preamble/sfd=" << m_preambleSfd << ",";
|
||||
}
|
||||
os << " length/type=" << m_lengthType
|
||||
<< ", source=" << m_source
|
||||
<< ", destination=" << m_destination;
|
||||
}
|
||||
uint32_t
|
||||
EthernetHeader::GetSerializedSize (void) const
|
||||
{
|
||||
if (m_enPreambleSfd)
|
||||
{
|
||||
return PREAMBLE_SIZE + LENGTH_SIZE + 2*MAC_ADDR_SIZE;
|
||||
} else {
|
||||
return LENGTH_SIZE + 2*MAC_ADDR_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EthernetHeader::SerializeTo (Buffer::Iterator start) const
|
||||
{
|
||||
Buffer::Iterator i = start;
|
||||
|
||||
if (m_enPreambleSfd)
|
||||
{
|
||||
i.WriteU64(m_preambleSfd);
|
||||
}
|
||||
NS_ASSERT (m_destination.GetLength () == MAC_ADDR_SIZE);
|
||||
NS_ASSERT (m_source.GetLength () == MAC_ADDR_SIZE);
|
||||
WriteTo (i, m_destination);
|
||||
WriteTo (i, m_source);
|
||||
i.WriteU16 (m_lengthType);
|
||||
}
|
||||
uint32_t
|
||||
EthernetHeader::DeserializeFrom (Buffer::Iterator start)
|
||||
{
|
||||
Buffer::Iterator i = start;
|
||||
|
||||
if (m_enPreambleSfd)
|
||||
{
|
||||
m_enPreambleSfd = i.ReadU64 ();
|
||||
}
|
||||
|
||||
ReadFrom (i, m_destination, MAC_ADDR_SIZE);
|
||||
ReadFrom (i, m_source, MAC_ADDR_SIZE);
|
||||
m_lengthType = i.ReadU16 ();
|
||||
|
||||
return GetSerializedSize ();
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
@@ -0,0 +1,128 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 Emmanuelle Laprise
|
||||
* 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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
|
||||
*/
|
||||
|
||||
#ifndef ETHERNET_HEADER_H
|
||||
#define ETHERNET_HEADER_H
|
||||
|
||||
#include "ns3/header.h"
|
||||
#include "ns3/mac-address.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
/**
|
||||
* Types of ethernet packets. Indicates the type of the current
|
||||
* header.
|
||||
*/
|
||||
enum ethernet_header_t {
|
||||
LENGTH, /**< Basic ethernet packet, no tags, type/length field
|
||||
indicates packet length or IP/ARP packet */
|
||||
VLAN, /**< Single tagged packet. Header includes VLAN tag */
|
||||
QINQ /**< Double tagged packet. Header includes two VLAN tags */
|
||||
};
|
||||
/**
|
||||
* \brief Packet header for Ethernet
|
||||
*
|
||||
* This class can be used to add a header to an ethernet packet that
|
||||
* will specify the source and destination addresses and the length of
|
||||
* the packet. Eventually the class will be improved to also support
|
||||
* VLAN tags in packet headers.
|
||||
*/
|
||||
class EthernetHeader : public Header {
|
||||
public:
|
||||
static const int PREAMBLE_SIZE = 8; /// size of the preamble_sfd header field
|
||||
static const int LENGTH_SIZE = 2; /// size of the length_type header field
|
||||
static const int MAC_ADDR_SIZE = 6; /// size of src/dest addr header fields
|
||||
|
||||
/**
|
||||
* \brief Construct a null ethernet header
|
||||
*/
|
||||
EthernetHeader ();
|
||||
virtual ~EthernetHeader ();
|
||||
/**
|
||||
* \brief Enable or disabled the serialisation of the preamble and
|
||||
* Sfd header fields
|
||||
*/
|
||||
static void EnablePreambleSfd (bool enable);
|
||||
/**
|
||||
* \param size The size of the payload in bytes
|
||||
*/
|
||||
void SetLengthType (uint16_t size);
|
||||
/**
|
||||
* \param source The source address of this packet
|
||||
*/
|
||||
void SetSource (MacAddress source);
|
||||
/**
|
||||
* \param destination The destination address of this packet.
|
||||
*/
|
||||
void SetDestination (MacAddress destination);
|
||||
/**
|
||||
* \param preambleSfd The value that the preambleSfd field should take
|
||||
*/
|
||||
void SetPreambleSfd (uint64_t preambleSfd);
|
||||
/**
|
||||
* \return The size of the payload in bytes
|
||||
*/
|
||||
uint16_t GetLengthType (void) const;
|
||||
/**
|
||||
* \return The type of packet (only basic Ethernet is currently supported)
|
||||
*/
|
||||
ethernet_header_t GetPacketType (void) const;
|
||||
/**
|
||||
* \return The source address of this packet
|
||||
*/
|
||||
MacAddress GetSource (void) const;
|
||||
/**
|
||||
* \return The destination address of this packet
|
||||
*/
|
||||
MacAddress GetDestination (void) const;
|
||||
/**
|
||||
* \return The value of the PreambleSfd field
|
||||
*/
|
||||
uint64_t GetPreambleSfd () const;
|
||||
/**
|
||||
* \return The size of the header
|
||||
*/
|
||||
uint32_t GetHeaderSize() const;
|
||||
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
virtual void PrintTo (std::ostream &os) const;
|
||||
virtual uint32_t GetSerializedSize (void) const;
|
||||
virtual void SerializeTo (Buffer::Iterator start) const;
|
||||
virtual uint32_t DeserializeFrom (Buffer::Iterator start);
|
||||
|
||||
void Init (void);
|
||||
|
||||
/**
|
||||
* If false, the preamble/sfd are not serialised/deserialised.
|
||||
*/
|
||||
static bool m_enPreambleSfd;
|
||||
|
||||
uint64_t m_preambleSfd; /// Value of the Preamble/SFD fields
|
||||
uint16_t m_lengthType : 16; /// Length or type of the packet
|
||||
MacAddress m_source; /// Source address
|
||||
MacAddress m_destination; /// Destination address
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
|
||||
#endif /* ETHERNET_HEADER_H */
|
||||
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
|
||||
*/
|
||||
|
||||
#include "ns3/assert.h"
|
||||
#include "ns3/debug.h"
|
||||
#include "ns3/trailer.h"
|
||||
#include "ethernet-trailer.h"
|
||||
|
||||
NS_DEBUG_COMPONENT_DEFINE ("EthernetTrailer");
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
bool EthernetTrailer::m_calcFcs = false;
|
||||
|
||||
EthernetTrailer::EthernetTrailer ()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
EthernetTrailer::~EthernetTrailer ()
|
||||
{}
|
||||
|
||||
void EthernetTrailer::Init()
|
||||
{
|
||||
m_fcs = 0;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTrailer::EnableFcs (bool enable)
|
||||
{
|
||||
m_calcFcs = enable;
|
||||
}
|
||||
|
||||
bool
|
||||
EthernetTrailer::CheckFcs (const Packet& p) const
|
||||
{
|
||||
if (!m_calcFcs)
|
||||
{
|
||||
return true;
|
||||
} else {
|
||||
NS_DEBUG("FCS calculation is not yet enabled" << std::endl);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTrailer::CalcFcs (const Packet& p)
|
||||
{
|
||||
NS_DEBUG("FCS calculation is not yet enabled" << std::endl);
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTrailer::SetFcs (uint32_t fcs)
|
||||
{
|
||||
m_fcs = fcs;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
EthernetTrailer::GetFcs (void)
|
||||
{
|
||||
return m_fcs;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
EthernetTrailer::GetTrailerSize (void) const
|
||||
{
|
||||
return GetSerializedSize();
|
||||
}
|
||||
std::string
|
||||
EthernetTrailer::DoGetName (void) const
|
||||
{
|
||||
return "ETHERNET";
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTrailer::PrintTo (std::ostream &os) const
|
||||
{
|
||||
os << " fcs=" << m_fcs;
|
||||
}
|
||||
uint32_t
|
||||
EthernetTrailer::GetSerializedSize (void) const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
void
|
||||
EthernetTrailer::SerializeTo (Buffer::Iterator end) const
|
||||
{
|
||||
Buffer::Iterator i = end;
|
||||
i.Prev(GetSerializedSize());
|
||||
|
||||
i.WriteU32 (m_fcs);
|
||||
}
|
||||
uint32_t
|
||||
EthernetTrailer::DeserializeFrom (Buffer::Iterator end)
|
||||
{
|
||||
Buffer::Iterator i = end;
|
||||
uint32_t size = GetSerializedSize();
|
||||
i.Prev(size);
|
||||
|
||||
m_fcs = i.ReadU32 ();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2007 Emmanuelle Laprise
|
||||
* 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: Emmanuelle Laprise <emmanuelle.laprise@bluekazoo.ca>
|
||||
*/
|
||||
|
||||
#ifndef ETHERNET_TRAILER_H
|
||||
#define ETHERNET_TRAILER_H
|
||||
|
||||
#include "ns3/trailer.h"
|
||||
#include "ns3/packet.h"
|
||||
|
||||
namespace ns3 {
|
||||
/**
|
||||
* \brief Packet trailer for Ethernet
|
||||
*
|
||||
* This class can be used to add and verify the FCS at the end of an
|
||||
* ethernet packet. The actual FCS functionality is not yet coded and
|
||||
* so this acts more as a placeholder.
|
||||
*/
|
||||
class EthernetTrailer : public Trailer {
|
||||
public:
|
||||
/**
|
||||
* \brief Construct a null ethernet trailer
|
||||
*/
|
||||
EthernetTrailer ();
|
||||
virtual ~EthernetTrailer ();
|
||||
/**
|
||||
* \brief Enable or disabled FCS checking and calculations
|
||||
* \param enable If true, enables FCS calculations.
|
||||
*/
|
||||
static void EnableFcs (bool enable);
|
||||
/**
|
||||
* \brief Updates the Fcs Field to the correct FCS
|
||||
* \param p Reference to a packet on which the FCS should be
|
||||
* calculated. The packet should not currently contain an FCS
|
||||
* trailer.
|
||||
*/
|
||||
void CalcFcs (const Packet& p);
|
||||
/**
|
||||
* \brief Sets the FCS to a new value
|
||||
* \param fcs New FCS value
|
||||
*/
|
||||
void SetFcs (uint32_t fcs);
|
||||
/**
|
||||
* \return the FCS contained in this trailer
|
||||
*/
|
||||
uint32_t GetFcs ();
|
||||
|
||||
/**
|
||||
* \param p Reference to the packet on which the FCS should be
|
||||
* calculated. The packet should not contain an FCS trailer.
|
||||
* \return Returns true if the packet fcs is correct, false otherwise.
|
||||
*
|
||||
* If FCS checking is disabled, this method will always
|
||||
* return true.
|
||||
*/
|
||||
bool CheckFcs (const Packet& p) const;
|
||||
|
||||
/**
|
||||
*\return Returns the size of the trailer
|
||||
*/
|
||||
uint32_t GetTrailerSize() const;
|
||||
|
||||
private:
|
||||
virtual std::string DoGetName (void) const;
|
||||
virtual void PrintTo (std::ostream &os) const;
|
||||
virtual uint32_t GetSerializedSize (void) const;
|
||||
virtual void SerializeTo (Buffer::Iterator end) const;
|
||||
virtual uint32_t DeserializeFrom (Buffer::Iterator end);
|
||||
|
||||
/**
|
||||
* Initializes the trailer parameters during construction.
|
||||
*/
|
||||
void Init (void);
|
||||
|
||||
/**
|
||||
* Enabled FCS calculations. If false, fcs is set to 0 and checkFCS
|
||||
* returns true.
|
||||
*/
|
||||
static bool m_calcFcs;
|
||||
uint32_t m_fcs; /// Value of the fcs contained in the trailer
|
||||
|
||||
};
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
|
||||
#endif /* ETHERNET_TRAILER_H */
|
||||
+17
-11
@@ -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
|
||||
|
||||
+10
-4
@@ -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
|
||||
|
||||
@@ -10,7 +10,10 @@ def build(bld):
|
||||
'ipv4-address.cc',
|
||||
'net-device.cc',
|
||||
'mac-address.cc',
|
||||
'address-utils.cc',
|
||||
'llc-snap-header.cc',
|
||||
'ethernet-header.cc',
|
||||
'ethernet-trailer.cc',
|
||||
'ipv4-route.cc',
|
||||
'queue.cc',
|
||||
'drop-tail-queue.cc',
|
||||
@@ -30,10 +33,13 @@ def build(bld):
|
||||
'ipv4-address.h',
|
||||
'net-device.h',
|
||||
'mac-address.h',
|
||||
'address-utils.h',
|
||||
'ipv4-route.h',
|
||||
'queue.h',
|
||||
'drop-tail-queue.h',
|
||||
'llc-snap-header.h',
|
||||
'ethernet-header.h',
|
||||
'ethernet-trailer.h',
|
||||
'channel.h',
|
||||
'node-list.h',
|
||||
'socket.h',
|
||||
|
||||
Reference in new issue
Block a user