This commit is contained in:
Mathieu Lacage
2007-07-30 10:35:03 +02:00
60 changed files with 4579 additions and 299 deletions

59
src/node/address-utils.cc Normal file
View File

@@ -0,0 +1,59 @@
/* -*- 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, const Address &ad)
{
uint8_t mac[Address::MAX_SIZE];
ad.CopyTo (mac);
i.Write (mac, ad.GetLength ());
}
void WriteTo (Buffer::Iterator &i, Eui48Address ad)
{
uint8_t mac[6];
ad.CopyTo (mac);
i.Write (mac, 6);
}
void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad)
{
ad.SetHostOrder (i.ReadNtohU32 ());
}
void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len)
{
uint8_t mac[Address::MAX_SIZE];
i.Read (mac, len);
ad.CopyFrom (mac, len);
}
void ReadFrom (Buffer::Iterator &i, Eui48Address &ad)
{
uint8_t mac[6];
i.Read (mac, 6);
ad.CopyFrom (mac);
}
} // namespace ns3

41
src/node/address-utils.h Normal file
View File

@@ -0,0 +1,41 @@
/* -*- 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 "ipv4-address.h"
#include "address.h"
#include "eui48-address.h"
namespace ns3 {
void WriteTo (Buffer::Iterator &i, Ipv4Address ad);
void WriteTo (Buffer::Iterator &i, const Address &ad);
void WriteTo (Buffer::Iterator &i, Eui48Address ad);
void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad);
void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len);
void ReadFrom (Buffer::Iterator &i, Eui48Address &ad);
};
#endif /* ADDRESS_UTILS_H */

163
src/node/ethernet-header.cc Normal file
View File

@@ -0,0 +1,163 @@
/* -*- 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 {
EthernetHeader::EthernetHeader (bool hasPreamble)
: m_enPreambleSfd (hasPreamble),
m_lengthType (0)
{}
EthernetHeader::EthernetHeader ()
: m_enPreambleSfd (false),
m_lengthType (0)
{}
EthernetHeader::~EthernetHeader ()
{}
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 (Eui48Address source)
{
m_source = source;
}
Eui48Address
EthernetHeader::GetSource (void) const
{
return m_source;
}
void
EthernetHeader::SetDestination (Eui48Address dst)
{
m_destination = dst;
}
Eui48Address
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);
}
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);
ReadFrom (i, m_source);
m_lengthType = i.ReadU16 ();
return GetSerializedSize ();
}
} // namespace ns3

127
src/node/ethernet-header.h Normal file
View File

@@ -0,0 +1,127 @@
/* -*- 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/eui48-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
* \param hasPreamble if true, insert and remove an ethernet preamble from the
* packet, if false, does not insert and remove it.
*/
EthernetHeader (bool hasPreamble);
/**
* \brief Construct a null ethernet header
* By default, does not add or remove an ethernet preamble
*/
EthernetHeader ();
virtual ~EthernetHeader ();
/**
* \param size The size of the payload in bytes
*/
void SetLengthType (uint16_t size);
/**
* \param source The source address of this packet
*/
void SetSource (Eui48Address source);
/**
* \param destination The destination address of this packet.
*/
void SetDestination (Eui48Address 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
*/
Eui48Address GetSource (void) const;
/**
* \return The destination address of this packet
*/
Eui48Address 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);
/**
* If false, the preamble/sfd are not serialised/deserialised.
*/
bool m_enPreambleSfd;
uint64_t m_preambleSfd; /// Value of the Preamble/SFD fields
uint16_t m_lengthType; /// Length or type of the packet
Eui48Address m_source; /// Source address
Eui48Address m_destination; /// Destination address
};
}; // namespace ns3
#endif /* ETHERNET_HEADER_H */

View File

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

104
src/node/ethernet-trailer.h Normal file
View File

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

View File

@@ -1,6 +1,7 @@
#include "eui48-address.h"
#include "address.h"
#include "ns3/assert.h"
#include <iomanip>
namespace ns3 {
@@ -58,6 +59,17 @@ Eui48Address::Eui48Address (const char *str)
}
NS_ASSERT (i == 6);
}
void
Eui48Address::CopyFrom (const uint8_t buffer[6])
{
memcpy (m_address, buffer, 6);
}
void
Eui48Address::CopyTo (uint8_t buffer[6]) const
{
memcpy (buffer, m_address, 6);
}
Address
Eui48Address::ConvertTo (void) const
{
@@ -92,5 +104,36 @@ Eui48Address::GetType (void)
return type;
}
bool operator == (const Eui48Address &a, const Eui48Address &b)
{
uint8_t ada[6];
uint8_t adb[6];
a.CopyTo (ada);
b.CopyTo (adb);
return memcmp (ada, adb, 6) == 0;
}
bool operator != (const Eui48Address &a, const Eui48Address &b)
{
return ! (a == b);
}
std::ostream& operator<< (std::ostream& os, const Eui48Address & address)
{
uint8_t ad[6];
address.CopyTo (ad);
os.setf (std::ios::hex, std::ios::basefield);
std::cout.fill('0');
for (uint8_t i=0; i < 5; i++)
{
os << std::setw(2) << (uint32_t)ad[i] << ":";
}
// Final byte not suffixed by ":"
os << std::setw(2) << (uint32_t)ad[5];
os.setf (std::ios::dec, std::ios::basefield);
std::cout.fill(' ');
return os;
}
} // namespace ns3

View File

@@ -2,6 +2,7 @@
#define EUI48_ADDRESS_H
#include <stdint.h>
#include <ostream>
namespace ns3 {
@@ -22,6 +23,19 @@ public:
* The format of the string is "xx:xx:xx:xx:xx:xx"
*/
Eui48Address (const char *str);
/**
* \param buffer address in network order
*
* Copy the input address to our internal buffer.
*/
void CopyFrom (const uint8_t buffer[6]);
/**
* \param buffer address in network order
*
* Copy the internal address to the input buffer.
*/
void CopyTo (uint8_t buffer[6]) const;
/**
* \returns a new Address instance
*
@@ -42,9 +56,12 @@ public:
private:
static uint8_t GetType (void);
uint8_t m_address[6];
};
bool operator == (const Eui48Address &a, const Eui48Address &b);
bool operator != (const Eui48Address &a, const Eui48Address &b);
std::ostream& operator<< (std::ostream& os, const Eui48Address & address);
} // namespace ns3
#endif /* EUI48_ADDRESS_H */

View File

@@ -145,8 +145,20 @@ Ipv4Address::IsEqual (Ipv4Address other) const
}
}
Ipv4Address
Ipv4Address::CombineMask (Ipv4Mask const &mask) const
{
return Ipv4Address (GetHostOrder () & mask.GetHostOrder ());
}
bool
Ipv4Address::IsBroadcast (void) const
{
return (m_address == 0xffffffffU);
}
bool
Ipv4Address::IsMulticast (void)
Ipv4Address::IsMulticast (void) const
{
// XXX
return false;

View File

@@ -28,6 +28,8 @@
namespace ns3 {
class Ipv4Mask;
/** Ipv4 addresses are stored in host order in
* this class.
*/
@@ -89,8 +91,18 @@ public:
*/
void Print (std::ostream &os) const;
bool IsBroadcast (void);
bool IsMulticast (void);
bool IsBroadcast (void) const;
bool IsMulticast (void) const;
/**
* \brief Combine this address with a network mask
*
* This method returns an IPv4 address that is this address combined
* (bitwise and) with a network mask, yielding an IPv4 network
* address.
*
* \param a network mask
*/
Ipv4Address CombineMask (Ipv4Mask const &mask) const;
Address ConvertTo (void) const;
static Ipv4Address ConvertFrom (const Address &address);

View File

@@ -24,6 +24,7 @@
#include <stdint.h>
#include "ns3/ipv4-address.h"
#include "ns3/object.h"
#include "ns3/callback.h"
#include "ipv4-route.h"
namespace ns3 {
@@ -31,6 +32,78 @@ namespace ns3 {
class NetDevice;
class Packet;
class Ipv4Route;
class Ipv4Header; // FIXME: ipv4-header.h needs to move from module
// "internet-node" to module "node"
/**
* \brief Base class for IPv4 routing protocols.
*
* This class represents the interface between the IPv4 routing core
* and a specific IPv4 routing protocol. The interface is
* asynchronous (callback based) in order to support reactive routing
* protocols (e.g. AODV).
*/
class Ipv4RoutingProtocol : public Object
{
public:
// void (*RouteReply) (bool found, Ipv4Route route, Packet packet, Ipv4Header const &ipHeader);
/**
* \brief Callback to be invoked when route discovery is completed
*
* \param bool flag indicating whether a route was actually found;
* when this is false, the Ipv4Route parameter is ignored
*
* \param Ipv4Route the route found
*
* \param Packet the packet for which a route was requested; can be
* modified by the routing protocol
*
* \param Ipv4Header the IP header supplied to the route request
* method (possibly modified in case a new routing header is
* inserted and consequently the protocol type has to change).
*
*/
typedef Callback<void, bool, const Ipv4Route&, Packet, const Ipv4Header&> RouteReplyCallback;
/**
* \brief Asynchronously requests a route for a given packet and IP header
*
* \param ipHeader IP header of the packet
* \param packet packet that is being sent or forwarded
* \param routeReply callback that will receive the route reply
*
* \returns true if the routing protocol should be able to get the
* route, false otherwise.
*
* This method is called whenever a node's IPv4 forwarding engine
* needs to lookup a route for a given packet and IP header.
*
* The routing protocol implementation may determine immediately it
* should not be handling this particular the route request. For
* instance, a routing protocol may decline to search for routes for
* certain classes of addresses, like link-local. In this case,
* RequestRoute() should return false and the routeReply callback
* must not be invoked.
*
* If the routing protocol implementations assumes it can provide
* the requested route, then it should return true, and the
* routeReply callback must be invoked, either immediately before
* returning true (synchronously), or in the future (asynchronous).
* The routing protocol may use any information available in the IP
* header and packet as routing key, although most routing protocols
* use only the destination address (as given by
* ipHeader.GetDestination ()). The routing protocol is also
* allowed to add a new header to the packet, which will appear
* immediately after the IP header, although most routing do not
* insert any extra header.
*/
virtual bool RequestRoute (const Ipv4Header &ipHeader,
Packet packet,
RouteReplyCallback routeReply) = 0;
};
/**
* \brief Access to the Ipv4 forwarding table and to the ipv4 interfaces
*
@@ -47,7 +120,20 @@ public:
static const InterfaceId iid;
Ipv4 ();
virtual ~Ipv4 ();
/**
* \brief Register a new routing protocol to be used in this IPv4 stack
*
* \param routingProtocol new routing protocol implementation object
* \param priority priority to give to this routing protocol.
* Values may range between -32768 and +32767. The priority 0
* corresponds to static routing table lookups, higher values have
* more priority. The order by which routing protocols with the
* same priority value are consulted is undefined.
*/
virtual void AddRoutingProtocol (Ptr<Ipv4RoutingProtocol> routingProtocol,
int16_t priority) = 0;
/**
* \param dest destination address
* \param nextHop address of next hop.

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 Address& 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 Address& dest) = 0;
virtual bool SendTo (Packet& p, const Address &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;
Address 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

View File

@@ -12,7 +12,10 @@ def build(bld):
'node.cc',
'ipv4-address.cc',
'net-device.cc',
'address-utils.cc',
'llc-snap-header.cc',
'ethernet-header.cc',
'ethernet-trailer.cc',
'ipv4-route.cc',
'queue.cc',
'drop-tail-queue.cc',
@@ -24,7 +27,6 @@ def build(bld):
'ipv4.cc',
'application.cc',
]
node.includes = '.'
headers = bld.create_obj('ns3header')
headers.source = [
@@ -34,10 +36,13 @@ def build(bld):
'node.h',
'ipv4-address.h',
'net-device.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',