code from all trees.

This commit is contained in:
Mathieu Lacage
2007-02-08 15:37:48 +01:00
parent e73ac88cf2
commit 9609fe68f0
23 changed files with 1879 additions and 4 deletions

33
src/node/capability.cc Normal file
View File

@@ -0,0 +1,33 @@
// -*- 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>
//
// Define the base class for all node capabilities.
// George F. Riley, Georgia Tech, Fall 2006
#include "capability.h"
namespace ns3 {
Capability::~Capability ()
{}
}//namespace ns3

43
src/node/capability.h Normal file
View File

@@ -0,0 +1,43 @@
// -*- 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>
//
// Define the base class for all node capabilities.
// George F. Riley, Georgia Tech, Fall 2006
#ifndef CAPABILITY_H
#define CAPABILITY_H
// All capabilities must implement a copy method, to allow node subclasses
// to have a pointer to any subclass of the capability and still copy
// correctly.
namespace ns3 {
class Node;
class Capability
{
public:
virtual ~Capability();
virtual Capability* Copy() const = 0;
};
}//namespace ns3
#endif

81
src/node/internet-node.cc Normal file
View File

@@ -0,0 +1,81 @@
// -*- 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 the InternetNode class for ns3.
// George F. Riley, Georgia Tech, Fall 2006
#include "net-device-list.h"
#include "l3-demux.h"
#include "ipv4-l4-demux.h"
#include "internet-node.h"
namespace ns3 {
InternetNode::InternetNode()
{
// Instantiate the capabilities
m_netDevices = new NetDeviceList();
m_l3Demux = new L3Demux();
m_ipv4L4Demux = new Ipv4L4Demux();
// Configure the capabilities
// Insert an IPv4 protocol at layer 3
//m_l3Protocols->Insert(ns3::IPV4());
// L4 protocols (instances of TCP or UDP layer 4 objects)
// are inserted as created by process socket creations
// or bind calls.
}
InternetNode::InternetNode(const InternetNode& rhs)
{ // Copy constructor
// Note we do not copy the contents of the process list or
// the interfaces list, as these are added later.
m_netDevices = new NetDeviceList();
// Make a copy of each capability
m_l3Demux = rhs.GetL3Demux()->Copy();
m_ipv4L4Demux = rhs.GetIpv4L4Demux()->Copy();
}
// Copy this node
InternetNode*
InternetNode::Copy() const
{
return new InternetNode(*this);
}
NetDeviceList*
InternetNode::GetNetDevices() const
{
return m_netDevices;
}
L3Demux*
InternetNode::GetL3Demux() const
{
return m_l3Demux;
}
Ipv4L4Demux*
InternetNode::GetIpv4L4Demux() const
{
return m_ipv4L4Demux;
}
}//namespace ns3

54
src/node/internet-node.h Normal file
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>
//
// Define a basic "Internet" node, with a protocol stack (l3 and l4),
// network device list, process list, and routing.
#ifndef INTERNET_NODE_H
#define INTERNET_NODE_H
#include <list>
#include "node.h"
namespace ns3 {
class InternetNode : public Node
{
public:
InternetNode();
InternetNode(const InternetNode&); // Copy constructor
virtual InternetNode* Copy() const;// Make a copy of this node
// Capability access
virtual NetDeviceList* GetNetDevices() const;
virtual L3Demux* GetL3Demux() const;
virtual Ipv4L4Demux* GetIpv4L4Demux() const;
private:
// Capabilities
NetDeviceList* m_netDevices;
L3Demux* m_l3Demux;
Ipv4L4Demux* m_ipv4L4Demux;
};
}//namespace ns3
#endif /* INTERNET_NODE_H */

231
src/node/ipv4-address.cc Normal file
View File

@@ -0,0 +1,231 @@
/* -*- 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "ipv4-address.h"
namespace ns3 {
#define ASCII_DOT (0x2e)
#define ASCII_ZERO (0x30)
static uint32_t
AsciiToIpv4Host (char const *address)
{
uint32_t host = 0;
while (true) {
uint8_t byte = 0;
while (*address != ASCII_DOT &&
*address != 0) {
byte *= 10;
byte += *address - ASCII_ZERO;
address++;
}
host <<= 8;
host |= byte;
if (*address == 0) {
break;
}
address++;
}
return host;
}
}//namespace ns3
namespace ns3 {
Ipv4Mask::Ipv4Mask ()
: m_mask (0x66666666)
{}
Ipv4Mask::Ipv4Mask (uint32_t mask)
: m_mask (mask)
{}
Ipv4Mask::Ipv4Mask (char const *mask)
{
m_mask = AsciiToIpv4Host (mask);
}
bool
Ipv4Mask::IsEqual (Ipv4Mask other) const
{
if (other.m_mask == m_mask) {
return true;
} else {
return false;
}
}
bool
Ipv4Mask::IsMatch (Ipv4Address a, Ipv4Address b) const
{
if ((a.GetHostOrder () & m_mask) == (b.GetHostOrder () & m_mask)) {
return true;
} else {
return false;
}
}
uint32_t
Ipv4Mask::GetHostOrder (void) const
{
return m_mask;
}
void
Ipv4Mask::SetHostOrder (uint32_t value)
{
m_mask = value;
}
void
Ipv4Mask::Print (std::ostream *os) const
{
*os << ((m_mask >> 24) & 0xff) << "."
<< ((m_mask >> 16) & 0xff) << "."
<< ((m_mask >> 8) & 0xff) << "."
<< ((m_mask >> 0) & 0xff);
}
Ipv4Mask
Ipv4Mask::GetLoopback (void)
{
static Ipv4Mask loopback = Ipv4Mask ("255.0.0.0");
return loopback;
}
Ipv4Mask
Ipv4Mask::GetZero (void)
{
static Ipv4Mask zero = Ipv4Mask ("0.0.0.0");
return zero;
}
Ipv4Address::Ipv4Address ()
: m_address (0x66666666)
{}
Ipv4Address::Ipv4Address (uint32_t address)
{
m_address = address;
}
Ipv4Address::Ipv4Address (char const *address)
{
m_address = AsciiToIpv4Host (address);
}
bool
Ipv4Address::IsEqual (Ipv4Address other) const
{
if (other.m_address == m_address) {
return true;
} else {
return false;
}
}
bool
Ipv4Address::IsMulticast (void)
{
// XXX
return false;
}
uint32_t
Ipv4Address::GetHostOrder (void) const
{
return m_address;
}
void
Ipv4Address::SetHostOrder (uint32_t ip)
{
m_address = ip;
}
void
Ipv4Address::Serialize (uint8_t buf[4]) const
{
buf[0] = (m_address >> 24) & 0xff;
buf[1] = (m_address >> 16) & 0xff;
buf[2] = (m_address >> 8) & 0xff;
buf[3] = (m_address >> 0) & 0xff;
}
void
Ipv4Address::Print (std::ostream *os) const
{
*os << ((m_address >> 24) & 0xff) << "."
<< ((m_address >> 16) & 0xff) << "."
<< ((m_address >> 8) & 0xff) << "."
<< ((m_address >> 0) & 0xff);
}
Ipv4Address
Ipv4Address::GetZero (void)
{
static Ipv4Address zero ("0.0.0.0");
return zero;
}
Ipv4Address
Ipv4Address::GetAny (void)
{
static Ipv4Address any ("0.0.0.0");
return any;
}
Ipv4Address
Ipv4Address::GetBroadcast (void)
{
static Ipv4Address broadcast ("255.255.255.255");
return broadcast;
}
Ipv4Address
Ipv4Address::GetLoopback (void)
{
Ipv4Address loopback ("127.0.0.1");
return loopback;
}
bool operator == (Ipv4Address const &a, Ipv4Address const &b)
{
return a.IsEqual (b);
}
bool operator != (Ipv4Address const &a, Ipv4Address const &b)
{
return !a.IsEqual (b);
}
size_t Ipv4AddressHash::operator()(Ipv4Address const &x) const
{
return x.GetHostOrder ();
}
std::ostream& operator<< (std::ostream& os, Ipv4Address const& address)
{
address.Print (&os);
return os;
}
std::ostream& operator<< (std::ostream& os, Ipv4Mask const& mask)
{
mask.Print (&os);
return os;
}
}; // namespace ns3

107
src/node/ipv4-address.h Normal file
View File

@@ -0,0 +1,107 @@
/* -*- 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef IPV4_ADDRESS_H
#define IPV4_ADDRESS_H
#include <stdint.h>
#include <ostream>
namespace ns3 {
/* Ipv4 addresses are stored in host order in
* this class.
*/
class Ipv4Address {
public:
Ipv4Address ();
/* input address is in host order. */
Ipv4Address (uint32_t address);
/* input address is in format:
* hhh.xxx.xxx.lll
* where h is the high byte and l the
* low byte
*/
Ipv4Address (char const *address);
bool IsEqual (Ipv4Address other) const;
/* Using this method is frowned upon.
* Please, do _not_ use this method.
* It is there only for chunk-ipv4.
*/
uint32_t GetHostOrder (void) const;
void SetHostOrder (uint32_t ip);
void Serialize (uint8_t buf[4]) const;
void Print (std::ostream *os) const;
bool IsBroadcast (void);
bool IsMulticast (void);
static Ipv4Address GetZero (void);
static Ipv4Address GetAny (void);
static Ipv4Address GetBroadcast (void);
static Ipv4Address GetLoopback (void);
private:
uint32_t m_address;
};
class Ipv4Mask {
public:
Ipv4Mask ();
Ipv4Mask (uint32_t mask);
Ipv4Mask (char const *mask);
bool IsMatch (Ipv4Address a, Ipv4Address b) const;
bool IsEqual (Ipv4Mask other) const;
/* Using this method is frowned upon.
* Please, do _not_ use this method.
*/
uint32_t GetHostOrder (void) const;
void SetHostOrder (uint32_t value);
void Print (std::ostream *os) const;
static Ipv4Mask GetLoopback (void);
static Ipv4Mask GetZero (void);
private:
uint32_t m_mask;
};
std::ostream& operator<< (std::ostream& os, Ipv4Address const& address);
std::ostream& operator<< (std::ostream& os, Ipv4Mask const& mask);
bool operator == (Ipv4Address const &a, Ipv4Address const &b);
bool operator != (Ipv4Address const &a, Ipv4Address const &b);
class Ipv4AddressHash : public std::unary_function<Ipv4Address, size_t> {
public:
size_t operator()(Ipv4Address const &x) const;
};
bool operator != (Ipv4Address const &a, Ipv4Address const &b);
}; // namespace ns3
#endif /* IPV4_ADDRESS_H */

74
src/node/ipv4-l4-demux.cc Normal file
View File

@@ -0,0 +1,74 @@
// -*- 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>
//
// Define the layer 4 demultiplexer object for ns3.
// George F. Riley, Georgia Tech, Fall 2006
#include "ipv4-l4-demux.h"
#include "ipv4-l4-protocol.h"
namespace ns3 {
Ipv4L4Demux::Ipv4L4Demux ()
{}
Ipv4L4Demux::Ipv4L4Demux(Ipv4L4Demux const &o)
{
for (L4List_t::const_iterator i = o.m_protocols.begin(); i != o.m_protocols.end(); ++i)
{
Insert(*(*i));
}
}
Ipv4L4Demux::~Ipv4L4Demux()
{}
Ipv4L4Demux*
Ipv4L4Demux::Copy() const
{
return new Ipv4L4Demux(*this);
}
Ipv4L4Protocol*
Ipv4L4Demux::Insert(const Ipv4L4Protocol&protocol)
{
Ipv4L4Protocol* copy = protocol.Copy(); // Make a copy of the protocol
m_protocols.push_back (copy);
return copy;
}
Ipv4L4Protocol*
Ipv4L4Demux::Lookup(int protocolNumber)
{
for (L4List_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
if ((*i)->GetProtocolNumber () == protocolNumber)
{
return *i;
}
}
return 0;
}
void
Ipv4L4Demux::Erase(Ipv4L4Protocol*protocol)
{
m_protocols.remove (protocol);
}
}//namespace ns3

50
src/node/ipv4-l4-demux.h Normal file
View File

@@ -0,0 +1,50 @@
// -*- 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>
//
// Define the layer 4 demultiplexer object for ns3.
// George F. Riley, Georgia Tech, Fall 2006
#ifndef IPV4_L4_DEMUX_H
#define IPV4_L4_DEMUX_H
#include <list>
namespace ns3 {
class Ipv4L4Protocol;
class Ipv4L4Demux {
public:
Ipv4L4Demux ();
Ipv4L4Demux(Ipv4L4Demux const&o);
virtual ~Ipv4L4Demux();
virtual Ipv4L4Demux* Copy() const;
Ipv4L4Protocol* Insert(const Ipv4L4Protocol&);
Ipv4L4Protocol* Lookup(int protocolNumber);
void Erase(Ipv4L4Protocol*);
private:
typedef std::list<Ipv4L4Protocol*> L4List_t;
L4List_t m_protocols;
};
} //namespace ns3
#endif

59
src/node/ipv4-l4-protocol.h Executable file
View File

@@ -0,0 +1,59 @@
// -*- 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>
//
// NS3 - Layer 4 Protocol base class
// George F. Riley, Georgia Tech, Spring 2007
#ifndef IPV4_L4_PROTOCOL_H
#define IPV4_L4_PROTOCOL_H
namespace ns3 {
class Node;
class Packet;
class Ipv4Address;
class Ipv4L4Protocol {
public:
Ipv4L4Protocol(int protocolNumber, int version, int layer);
virtual ~Ipv4L4Protocol ();
int GetProtocolNumber (void) const;
int GetVersion() const;
virtual Ipv4L4Protocol* Copy() const = 0;
/**
* Called from lower-level layers to send the packet up
* in the stack.
*/
virtual void Receive(Packet& p,
Ipv4Address const &source,
Ipv4Address const &destination) = 0;
private:
int m_protocolNumber;
int m_version;
};
} // Namespace ns3
#endif

65
src/node/l3-demux.cc Normal file
View File

@@ -0,0 +1,65 @@
// -*- 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>
//
// Implement the L3Protocols capability for ns3.
// George F. Riley, Georgia Tech, Fall 2006
#include "l3-demux.h"
#include "l3-protocol.h"
namespace ns3 {
L3Demux::~L3Demux()
{ // Delete each protocol in the map
for (L3Map_t::iterator i = m_protocols.begin(); i != m_protocols.end(); ++i)
{
delete i->second;
}
}
L3Demux::L3Demux(const L3Demux& rhs)
{ // Copy constructor, copy each protocol
for (L3Map_t::const_iterator i = rhs.m_protocols.begin(); i != rhs.m_protocols.end(); ++i)
{
Insert(*i->second);
}
}
L3Demux* L3Demux::Copy() const
{ // Return a copy of this protocol manager
return new L3Demux(*this);
}
L3Protocol* L3Demux::Insert(const L3Protocol& l3p)
{
L3Protocol* l = l3p.Copy(); // Make a copy of the protocol
m_protocols.insert(L3Map_t::value_type(l3p.GetProtocolNumber (), l));
return l;
}
L3Protocol* L3Demux::Lookup(int p)
{ // Look up a protocol by protocol number
L3Map_t::iterator i = m_protocols.find(p);
if (i == m_protocols.end()) return 0; // Not found
return i->second; // Return the protocol
}
} //namespace ns3

58
src/node/l3-demux.h Normal file
View File

@@ -0,0 +1,58 @@
// -*- 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>
//
// Define the L3Protocols capability for ns3.
// George F. Riley, Georgia Tech, Fall 2006
// This object manages the different layer 3 protocols for any ns3
// node that has this capability.
#ifndef L3_DEMUX_H
#define L3_DEMUX_H
#include <map>
namespace ns3 {
class L3Protocol;
class L3Demux
{
public:
L3Demux() {};
L3Demux(const L3Demux&);
virtual ~L3Demux();
virtual L3Demux* Copy() const;
// Insert a new protocol
ns3::L3Protocol* Insert(const ns3::L3Protocol&);
// Look up a protocol by protocol number
ns3::L3Protocol* Lookup(int);
// Erase an entry
void Erase(ns3::L3Protocol*);
private:
typedef std::map<int, ns3::L3Protocol*> L3Map_t;
L3Map_t m_protocols;
};
} //namespace ns3
#endif

48
src/node/l3-protocol.cc Normal file
View File

@@ -0,0 +1,48 @@
// -*- 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>
//
// NS3 - Layer 3 Protocol base class
// George F. Riley, Georgia Tech, Spring 2007
#include "l3-protocol.h"
namespace ns3 {
L3Protocol::L3Protocol(int protocolNumber, int version)
: m_protocolNumber (protocolNumber),
m_version (version)
{}
L3Protocol::~L3Protocol ()
{}
int
L3Protocol::GetProtocolNumber (void) const
{
return m_protocolNumber;
}
int
L3Protocol::GetVersion() const
{
return m_version;
}
}//namespace ns3

62
src/node/l3-protocol.h Normal file
View File

@@ -0,0 +1,62 @@
// -*- 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>
//
// NS3 - Layer 3 Protocol base class
// George F. Riley, Georgia Tech, Spring 2007
#ifndef L3_PROTOCOL_H
#define L3_PROTOCOL_H
namespace ns3 {
class Packet;
class NetDevice;
/**
* ::Send is always defined in subclasses.
*/
class L3Protocol {
public:
L3Protocol(int protocolNumber, int version);
virtual ~L3Protocol ();
int GetProtocolNumber (void) const;
int GetVersion() const;
virtual L3Protocol* Copy() const = 0;
/**
* Lower layer calls this method after calling L3Demux::Lookup
* The ARP subclass needs to know from which NetDevice this
* packet is coming to:
* - implement a per-NetDevice ARP cache
* - send back arp replies on the right device
*/
virtual void Receive(Packet& p, NetDevice &device) = 0;
private:
int m_protocolNumber;
int m_version;
};
} // Namespace ns3
#endif

View File

@@ -0,0 +1,89 @@
/* -*- 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include <cassert>
#include "llc-snap-header.h"
#define noTRACE_LLC_SNAP_HEADER 1
#ifdef TRACE_LLC_SNAP_HEADER
#include <iostream>
#include "ns3/simulator.h"
# define TRACE(x) \
std::cout << "LLCSNAP HEAD TRACE " << Simulator::Now () << " " << x << std::endl;
#else /* TRACE_LLC_SNAP_HEADER */
# define TRACE(format,...)
#endif /* TRACE_LLC_SNAP_HEADER */
namespace ns3 {
LlcSnapHeader::LlcSnapHeader ()
{}
LlcSnapHeader::~LlcSnapHeader ()
{}
void
LlcSnapHeader::SetType (uint16_t type)
{
m_etherType = type;
}
uint16_t
LlcSnapHeader::GetType (void)
{
return m_etherType;
}
uint32_t
LlcSnapHeader::GetSerializedSize (void) const
{
return 1 + 1 + 1 + 3 + 2;
}
void
LlcSnapHeader::PrintTo (std::ostream &os) const
{
os << "(mac)"
<< " EtherType: ";
os.setf (std::ios::hex, std::ios::basefield);
os << m_etherType;
os.setf (std::ios::dec, std::ios::basefield);
}
void
LlcSnapHeader::SerializeTo (Buffer::Iterator start) const
{
Buffer::Iterator i = start;
uint8_t buf[] = {0xaa, 0xaa, 0x03, 0, 0, 0};
i.Write (buf, 6);
i.WriteHtonU16 (m_etherType);
}
void
LlcSnapHeader::DeserializeFrom (Buffer::Iterator start)
{
Buffer::Iterator i = start;
i.Next (5+1);
m_etherType = i.ReadNtohU16 ();
}
}; // namespace ns3

View File

@@ -0,0 +1,49 @@
/* -*- 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef LLC_SNAP_HEADER_H
#define LLC_SNAP_HEADER_H
#include <stdint.h>
#include "ns3/header.h"
namespace ns3 {
class LlcSnapHeader : public Header {
public:
LlcSnapHeader ();
virtual ~LlcSnapHeader ();
void SetType (uint16_t type);
uint16_t GetType (void);
private:
virtual void PrintTo (std::ostream &os) const;
virtual uint32_t GetSerializedSize (void) const;
virtual void SerializeTo (Buffer::Iterator start) const;
virtual void DeserializeFrom (Buffer::Iterator start);
uint16_t m_etherType;
};
}; // namespace ns3
#endif /* LLC_SNAP_HEADER_H */

188
src/node/mac-address.cc Normal file
View File

@@ -0,0 +1,188 @@
/* -*- 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include <iostream>
#include <iomanip>
#include <cassert>
#include "mac-address.h"
#define ASCII_a (0x41)
#define ASCII_z (0x5a)
#define ASCII_A (0x61)
#define ASCII_Z (0x7a)
#define ASCII_COLON (0x3a)
#define ASCII_ZERO (0x30)
namespace ns3 {
static char
AsciiToLowCase (char c)
{
if (c >= ASCII_a && c <= ASCII_z) {
return c;
} else if (c >= ASCII_A && c <= ASCII_Z) {
return c + (ASCII_a - ASCII_A);
} else {
return c;
}
}
MacAddress::MacAddress () : m_len(0)
{
for (int i=0; i < MAX_ADDR_LEN; i++)
{
m_address[i] = 0;
}
}
MacAddress::MacAddress (uint8_t const *address, uint8_t len)
{
assert(len <= MAX_ADDR_LEN);
for (int i=0; i < len; i++)
{
m_address[i] = address[i];
}
for (int i=len; i < MAX_ADDR_LEN; i++)
{
m_address[i] = 0;
}
m_len = len;
}
MacAddress::MacAddress (char const *str)
{
int i = 0;
while (*str != 0 && i < MAX_ADDR_LEN) {
uint8_t byte = 0;
while (*str != ASCII_COLON && *str != 0) {
byte <<= 4;
char low = AsciiToLowCase (*str);
if (low >= ASCII_a) {
byte |= low - ASCII_a + 10;
} else {
byte |= low - ASCII_ZERO;
}
str++;
}
m_address[i] = byte;
i++;
if (*str == 0) {
break;
}
str++;
}
m_len = i;
}
MacAddress::~MacAddress ()
{}
bool
MacAddress::IsEqual (MacAddress other) const
{
if (memcmp(other.m_address, m_address, m_len))
{
return false;
}
else
{
return true;
}
}
void
MacAddress::Print (std::ostream &os) const
{
int i;
if (m_len == 0)
{
os << "NULL-ADDRESS";
return;
}
os.setf (std::ios::hex, std::ios::basefield);
std::cout.fill('0');
for (i=0; i< (m_len-1); i++)
{
os << std::setw(2) << (uint32_t)m_address[i] << ":";
}
// Final byte not suffixed by ":"
os << std::setw(2) << (uint32_t)m_address[i];
os.setf (std::ios::dec, std::ios::basefield);
std::cout.fill(' ');
}
uint8_t
MacAddress::GetLength () const
{
return m_len;
}
void
MacAddress::Peek (uint8_t ad[MAX_ADDR_LEN]) const
{
memcpy (ad, m_address, MAX_ADDR_LEN);
}
void
MacAddress::Set (uint8_t const ad[MAX_ADDR_LEN])
{
memcpy (m_address, ad, MAX_ADDR_LEN);
}
bool operator == (MacAddress const&a, MacAddress const&b)
{
return a.IsEqual (b);
}
bool operator != (MacAddress const&a, MacAddress const&b)
{
return !a.IsEqual (b);
}
bool operator < (MacAddress const&a, MacAddress const&b)
{
uint8_t a_p[MAX_ADDR_LEN];
uint8_t b_p[MAX_ADDR_LEN];
a.Peek (a_p);
b.Peek (b_p);
assert(a.GetLength() == b.GetLength());
for (uint8_t i = 0; i < a.GetLength(); i++)
{
if (a_p[i] < b_p[i])
{
return true;
}
else if (a_p[i] > b_p[i])
{
return false;
}
}
return false;
}
std::ostream& operator<< (std::ostream& os, MacAddress const& address)
{
address.Print (os);
return os;
}
}; // namespace ns3

79
src/node/mac-address.h Normal file
View File

@@ -0,0 +1,79 @@
/* -*- 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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
/*
* This implementation borrowed from yans
*/
#ifndef MAC_ADDRESS_H
#define MAC_ADDRESS_H
#include <stdint.h>
#include <ostream>
namespace ns3 {
const int MAX_ADDR_LEN = 32;
/**
* \brief base class for Network Device addresses
*
* This class is a base class for different types of Network
* Device addresses. It generically stores an address of
* MAX_ADDR_LEN bytes, and provides methods to compare, print, and set
* the address.
*/
class MacAddress {
public:
MacAddress (void);
/*
* low byte should be first.
*/
MacAddress (uint8_t const *address, uint8_t len);
/* The string should look like this:
* hh:xx:xx:xx:xx:ll
* where hh is the high byte and ll is
* the low byte.
*/
MacAddress (char const *address);
~MacAddress ();
bool IsEqual (MacAddress other) const;
void Print (std::ostream &os) const;
uint8_t GetLength() const;
void Peek (uint8_t ad[MAX_ADDR_LEN]) const;
void Set (uint8_t const ad[MAX_ADDR_LEN]);
private:
uint8_t m_address[MAX_ADDR_LEN];
uint8_t m_len;
};
bool operator == (MacAddress const&a, MacAddress const&b);
bool operator != (MacAddress const&a, MacAddress const&b);
bool operator < (MacAddress const&a, MacAddress const&b);
std::ostream& operator<< (std::ostream& os, MacAddress const& address);
}; // namespace ns3
#endif /* MAC_ADDRESS_H */

View File

@@ -0,0 +1,52 @@
// -*- Mode:NS3 -*-
//
// 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>
//
// Manages the list of network device interfaces associated with a node.
// George F. Riley, Georgia Tech, Spring 2007
#ifndef NET_DEVICE_LIST_H
#define NET_DEVICE_LIST_H
#include <vector>
#include "capability.h"
namespace ns3{
class NetDevice;
class NetDeviceList : public Capability {
public:
typedef std::vector<NetDevice *>::iterator Iterator;
NetDeviceList();
~NetDeviceList();
NetDeviceList* Copy() const;
// Manage the list
NetDevice* Add(const NetDevice&); // Add a new netdevice
NetDeviceList::Iterator Begin () const;
NetDeviceList::Iterator End () const;
public:
typedef std::vector<NetDevice *>::iterator NetDevices_t;
NetDevices_t m_netdevices;
};
} //namespace ns3
#endif

213
src/node/net-device.cc Normal file
View File

@@ -0,0 +1,213 @@
/* -*- 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 "net-device.h"
#include "l3-demux.h"
#include "l3-protocol.h"
#include "llc-snap-header.h"
#include "node.h"
namespace ns3 {
NetDevice::NetDevice(Node& node, const MacAddress& addr) :
m_node (node),
m_name(""),
m_ifIndex (0),
m_address (addr),
m_mtu (0),
m_isUp (false),
m_isBroadcast (false),
m_isMulticast (false),
m_isPointToPoint (false)
{
}
MacAddress
NetDevice::GetAddress (void) const
{
return m_address;
}
bool
NetDevice::SetMtu (const uint16_t mtu)
{
m_mtu = mtu;
return true;
}
uint16_t
NetDevice::GetMtu (void) const
{
return m_mtu;
}
void
NetDevice::SetName(const std::string name)
{
m_name = name;
}
std::string
NetDevice::GetName(void) const
{
return m_name;
}
bool
NetDevice::IsLinkUp (void) const
{
return m_isUp;
}
void
NetDevice::SetLinkChangeCallback (Callback<void> callback)
{
m_linkChangeCallback = callback;
}
bool
NetDevice::IsBroadcast (void) const
{
return m_isBroadcast;
}
MacAddress const &
NetDevice::GetBroadcast (void) const
{
assert (m_isBroadcast);
return m_broadcast;
}
void
NetDevice::EnableBroadcast (MacAddress broadcast)
{
m_isBroadcast = true;
m_broadcast = broadcast;
}
void
NetDevice::DisableBroadcast (void)
{
m_isBroadcast = false;
}
bool
NetDevice::IsMulticast (void) const
{
return m_isMulticast;
}
void
NetDevice::EnableMulticast (void)
{
m_isMulticast = true;
}
void
NetDevice::DisableMulticast (void)
{
m_isMulticast = false;
}
bool
NetDevice::IsPointToPoint (void) const
{
return m_isPointToPoint;
}
void
NetDevice::EnablePointToPoint (void)
{
m_isPointToPoint = true;
}
void
NetDevice::DisablePointToPoint (void)
{
m_isPointToPoint = false;
}
// Receive packet from above
bool
NetDevice::Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber)
{
if (m_isUp)
{
LlcSnapHeader llc;
llc.SetType (protocolNumber);
p.Add (llc);
return SendTo(p, dest);
}
else
{
return false;
}
}
// Receive packet from below
bool
NetDevice::ForwardUp (Packet& packet)
{
LlcSnapHeader llc;
packet.Peek (llc);
packet.Remove (llc);
if (GetNode().GetL3Demux() != 0)
{
L3Protocol *target = GetNode().GetL3Demux()->Lookup(llc.GetType ());
if (target != 0)
{
target->Receive(packet, *this);
return true;
}
}
return false;
}
void
NetDevice::NotifyLinkUp (void)
{
m_isUp = true;
if (!m_linkChangeCallback.IsNull ())
{
m_linkChangeCallback ();
}
}
void
NetDevice::NotifyLinkDown (void)
{
m_isUp = false;
if (!m_linkChangeCallback.IsNull ())
{
m_linkChangeCallback ();
}
}
Node&
NetDevice::GetNode (void) const
{
return m_node;
}
}; // namespace ns3

221
src/node/net-device.h Normal file
View File

@@ -0,0 +1,221 @@
/* -*- 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>
*/
#ifndef NET_DEVICE_H
#define NET_DEVICE_H
#include <string>
#include <stdint.h>
#include "ns3/callback.h"
#include "ns3/packet.h"
#include "mac-address.h"
namespace ns3 {
class Ipv4L4Demux;
class Node;
/**
* \brief Network layer to device interface
*
* This interface defines the API which the IP and ARP
* layers need to access to manage an instance of a network device
* layer. It currently does not support MAC-level
* multicast but this should not be too hard to add by adding
* extra methods to register MAC multicast addresses to
* filter out unwanted packets before handing them to the
* higher layers.
*
* In Linux, this interface is analogous to the interface
* just above dev_queue_xmit() (i.e., IP packet is fully
* constructed with destination MAC address already selected).
*
* If you want to write a new MAC layer, you need to subclass
* this base class and implement your own version of the
* NetDevice::SendTo method.
*/
class NetDevice {
public:
/**
* \param node base class node pointer of device's node
*/
NetDevice(Node& node, const MacAddress& addr);
virtual ~NetDevice() {}
/**
* \return the current MacAddress of this interface.
*/
MacAddress GetAddress (void) const;
/**
* \param mtu MTU value, in bytes, to set for the device
* \return whether the MTU value was within legal bounds
*
* Override for default MTU defined on a per-type basis.
*/
bool SetMtu (const uint16_t mtu);
/**
* \return the link-level MTU in bytes for this interface.
*
* This value is typically used by the IP layer to perform
* IP fragmentation when needed.
*/
uint16_t GetMtu (void) const;
/**
* \param name name of the device (e.g. "eth0")
*/
void SetName(const std::string name);
/**
* \return name name of the device (e.g. "eth0")
*/
std::string GetName(void) const;
/**
* \return true if link is up; false otherwise
*/
bool IsLinkUp (void) const;
/**
* \param callback the callback to invoke
*
* Register a callback invoked whenever the link
* status changes to UP. This callback is typically used
* by the IP/ARP layer to flush the ARP cache
* whenever the link goes up.
*/
void SetLinkChangeCallback (Callback<void> callback);
/**
* \return true if this interface supports a broadcast address,
* false otherwise.
*/
bool IsBroadcast (void) const;
/**
* \return the broadcast address supported by
* this netdevice.
*
* Calling this method is invalid if IsBroadcast returns
* not true.
*/
MacAddress const &GetBroadcast (void) const;
/**
* \return value of m_isMulticast flag
*/
bool IsMulticast (void) const;
/**
* \return value of m_isPointToPoint flag
*/
bool IsPointToPoint (void) const;
/**
* \param p packet sent from above down to Network Device
* \param dest mac address of the destination (already resolved)
* \param protocolNumber identifies the type of payload contained in
* this packet. Used to call the right L3Protocol when the packet
* is received.
*
* Called from higher layer to send packet into Network Device
* to the specified destination MacAddress
*
* \return whether the Send operation succeeded
*/
bool Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber);
protected:
/**
* Enable broadcast support. This method should be
* called by subclasses from their constructor
*/
void EnableBroadcast (MacAddress broadcast);
/**
* Set m_isBroadcast flag to false
*/
void DisableBroadcast (void);
/**
* Set m_isMulticast flag to true
*/
void EnableMulticast (void);
/**
* Set m_isMulticast flag to false
*/
void DisableMulticast (void);
/**
* Set m_isPointToPoint flag to true
*/
void EnablePointToPoint (void);
/**
* Set m_isPointToPoint flag to false
*/
void DisablePointToPoint (void);
/**
* When a subclass notices that the link status has changed to up,
* it notifies its parent class by calling this method. This method
* is responsible for notifying any LinkUp callbacks.
*/
void NotifyLinkUp (void);
/**
* When a subclass notices that the link status has changed to
* down, it notifies its parent class by calling this method.
*/
void NotifyLinkDown (void);
/**
* \returns the node base class which contains this network
* interface.
*
* When a subclass needs to get access to the underlying node
* base class to print the nodeid for example, it can invoke
* this method.
*/
Node& GetNode (void) const;
/**
* \param p packet sent from below up to Network Device
* \param from source mac address of the sender
* \returns true if the packet was forwarded successfully,
* false otherwise.
*
* When a subclass gets a packet from the PHY layer, it
* 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);
private:
/**
* \param p packet to send
* \param dest address of destination to which packet must be sent
* \returns true if the packet could be sent successfully, false
* otherwise.
*
* This is the private virtual target function of the public Send()
* method. When the link is Up, this method is invoked to ask
* subclasses to forward packets down to the PHY layer. Subclasses
* MUST override this method.
*/
virtual bool SendTo (Packet& p, const MacAddress& dest) = 0;
Node& m_node;
std::string m_name;
uint16_t m_ifIndex;
MacAddress m_address;
MacAddress m_broadcast;
uint16_t m_mtu;
bool m_isUp;
bool m_isBroadcast;
bool m_isMulticast;
bool m_isPointToPoint;
Callback<void> m_linkChangeCallback;
};
}; // namespace ns3
#endif

View File

@@ -50,8 +50,8 @@ Node::GetL3Demux() const
{
return 0;
}
L4Demux*
Node::GetL4Demux() const
Ipv4L4Demux*
Node::GetIpv4L4Demux() const
{
return 0;
}

View File

@@ -94,7 +94,7 @@
namespace ns3 {
class L3Demux;
class L4Demux;
class Ipv4L4Demux;
class NetDeviceList;
class Node {
@@ -116,7 +116,7 @@ public:
// of the correct type if one exists, or the nil pointer if no
// null capability exists.
virtual L3Demux* GetL3Demux() const;
virtual L4Demux* GetL4Demux() const;
virtual Ipv4L4Demux* GetIpv4L4Demux() const;
virtual NetDeviceList* GetNetDeviceList() const;
private: