25 #include "ns3/abort.h" 
   26 #include "ns3/names.h" 
   27 #include "ns3/ipv4-list-routing.h" 
   44     .SetGroupName (
"NixVectorRouting")
 
   51   : m_totalNeighbors (0)
 
  105       rp->FlushNixCache ();
 
  106       rp->FlushIpv4RouteCache ();
 
  144   if (source == destNode)
 
  153       std::vector< Ptr<Node> > parentVector;
 
  176   NixMap_t::iterator iter = 
m_nixCache.find (address);
 
  216   for (uint32_t i = 0; i < numberOfDevices; i++)
 
  242   if (parentVector.at (dest) == 0)
 
  247   Ptr<Node> parentNode = parentVector.at (dest);
 
  249   uint32_t numberOfDevices = parentNode->
GetNDevices ();
 
  251   uint32_t totalNeighbors = 0;
 
  255   for (uint32_t i = 0; i < numberOfDevices; i++)
 
  261       if (localNetDevice->IsBridge ())
 
  284           Ptr<Node> remoteNode = (*iter)->GetNode ();
 
  286           if (remoteNode->
GetId () == dest)
 
  288               destId = totalNeighbors + offset;
 
  293       totalNeighbors += netDeviceContainer.
GetN ();
 
  296                                << nixVector->
BitCount (totalNeighbors) << 
" bits, for node " << parentNode->
GetId ());
 
  301   BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixVector);
 
  310   for (uint32_t i = 0; i < channel->GetNDevices (); i++)
 
  313       if (remoteDevice != netDevice)
 
  320               NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bd);
 
  321               for (uint32_t j = 0; j < bd->GetNBridgePorts (); ++j)
 
  324                   if (ndBridged == remoteDevice)
 
  326                       NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
 
  339               netDeviceContainer.
Add (channel->GetDevice (i));
 
  357       if (ipv4->GetInterfaceForAddress (dest) != -1)
 
  366       NS_LOG_ERROR (
"Couldn't find dest node given the IP" << dest);
 
  377   uint32_t totalNeighbors = 0;
 
  381   for (uint32_t i = 0; i < numberOfDevices; i++)
 
  398       totalNeighbors += netDeviceContainer.
GetN ();
 
  401   return totalNeighbors;
 
  418   for (uint32_t i = 0; i < nDevices; ++i)
 
  423       if (ndTest->IsBridge ())
 
  425           NS_LOG_LOGIC (
"device " << i << 
" is a bridge net device");
 
  427           NS_ABORT_MSG_UNLESS (bnd, 
"Ipv4NixVectorRouting::NetDeviceIsBridged (): GetObject for <BridgeNetDevice> failed");
 
  429           for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
 
  431               NS_LOG_LOGIC (
"Examine bridge port " << j << 
" " << bnd->GetBridgePort (j));
 
  432               if (bnd->GetBridgePort (j) == nd)
 
  434                   NS_LOG_LOGIC (
"Net device " << nd << 
" is bridged by " << bnd);
 
  440   NS_LOG_LOGIC (
"Net device " << nd << 
" is not bridged");
 
  449   uint32_t totalNeighbors = 0;
 
  453   for (uint32_t i = 0; i < numberOfDevices; i++)
 
  471       if (nodeIndex < (totalNeighbors + netDeviceContainer.
GetN ()))
 
  475           Ptr<NetDevice> gatewayDevice = netDeviceContainer.
Get (nodeIndex-totalNeighbors);
 
  476           Ptr<Node> gatewayNode = gatewayDevice->GetNode ();
 
  479           uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (gatewayDevice);
 
  484       totalNeighbors += netDeviceContainer.
GetN ();
 
  505   if (!nixVectorInCache)
 
  517   if (nixVectorInCache)
 
  519       NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache);
 
  523       nixVectorForPacket = Create<NixVector> ();
 
  524       nixVectorForPacket = nixVectorInCache->
Copy (); 
 
  536       uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits);
 
  557           int32_t interfaceIndex = 0;
 
  565               interfaceIndex = (
m_ipv4)->GetInterfaceForDevice (oif);
 
  568           NS_ASSERT_MSG (interfaceIndex != -1, 
"Interface index not found for device");
 
  573           rtentry = Create<Ipv4Route> ();
 
  594       NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache << 
" : Remaining bits: " << nixVectorForPacket->GetRemainingBits ());
 
  600           NS_LOG_LOGIC (
"Adding Nix-vector to packet: " << *nixVectorForPacket);
 
  650       rtentry = Create<Ipv4Route> ();
 
  662                 " bits from Nix-vector: " << nixVector << 
" : " << *nixVector);
 
  668   ucb (rtentry, p, header);
 
  680   *os << 
"NixCache:" << std::endl;
 
  683       *os << 
"Destination     NixVector" << std::endl;
 
  686           std::ostringstream dest;
 
  688           *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
 
  689           *os << *(it->second) << std::endl;
 
  692   *os << 
"Ipv4RouteCache:" << std::endl;
 
  695       *os << 
"Destination     Gateway         Source            OutputDevice" << std::endl;
 
  698           std::ostringstream dest, gw, src;
 
  699           dest << it->second->GetDestination ();
 
  700           *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
 
  701           gw << it->second->GetGateway ();
 
  702           *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
 
  703           src << it->second->GetSource ();
 
  704           *os << std::setiosflags (std::ios::left) << std::setw (16) << src.str ();
 
  712               *os << it->second->GetOutputDevice ()->GetIfIndex ();
 
  749   std::queue< Ptr<Node> > greyNodeList;  
 
  752   parentVector.clear ();
 
  753   parentVector.reserve (
sizeof (
Ptr<Node>)*numberOfNodes);
 
  754   parentVector.insert (parentVector.begin (), 
sizeof (
Ptr<Node>)*numberOfNodes, 0); 
 
  757   greyNodeList.push (source);
 
  758   parentVector.at (source->
GetId ()) = source;
 
  761   while (greyNodeList.size () != 0)
 
  763       Ptr<Node> currNode = greyNodeList.front ();
 
  766       if (currNode == dest) 
 
  775       if (currNode == source && oif)
 
  780               uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (oif);
 
  781               if (!(ipv4->IsUp (interfaceIndex)))
 
  787           if (!(oif->IsLinkUp ()))
 
  809               Ptr<Node> remoteNode = (*iter)->GetNode ();
 
  815               if (parentVector.at (remoteNode->
GetId ()) == 0)
 
  817                   parentVector.at (remoteNode->
GetId ()) = currNode;
 
  818                   greyNodeList.push (remoteNode);
 
  826           for (uint32_t i = 0; i < (currNode->
GetNDevices ()); i++)
 
  836                   uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (currNode->
GetDevice (i));
 
  837                   if (!(ipv4->IsUp (interfaceIndex)))
 
  843               if (!(localNetDevice->IsLinkUp ()))
 
  865                   Ptr<Node> remoteNode = (*iter)->GetNode ();
 
  871                   if (parentVector.at (remoteNode->
GetId ()) == 0)
 
  873                       parentVector.at (remoteNode->
GetId ()) = currNode;
 
  874                       greyNodeList.push (remoteNode);
 
void FlushGlobalNixRoutingCache(void) const 
Called when run-time link topology change occurs which iterates through the node list and flushes any...
 
Iterator Begin(void) const 
Get an iterator which refers to the first NetDevice in the container. 
 
Smart pointer class similar to boost::intrusive_ptr. 
 
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
 
SocketErrno
Enumeration of the possible errors returned by a socket. 
 
static uint32_t GetNNodes(void)
 
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system. 
 
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator. 
 
Ipv4Address GetLocal(void) const 
Get the local address. 
 
Ptr< T > GetObject(void) const 
Get a pointer to the requested aggregated Object. 
 
Ptr< NetDevice > Get(uint32_t i) const 
Get the Ptr stored in this container at a given index. 
 
bool BuildNixVectorLocal(Ptr< NixVector > nixVector)
 
Ptr< NixVector > Copy(void) const 
 
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
 
void DoDispose(void)
Destructor implementation. 
 
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name. 
 
Iterator End(void) const 
Get an iterator which indicates past-the-last Node in the container. 
 
virtual void DoDispose(void)
Destructor implementation. 
 
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function. 
 
void FlushIpv4RouteCache(void) const 
 
a virtual net device that bridges multiple LAN segments 
 
Ptr< NixVector > GetNixVector(void) const 
Get the packet nix-vector. 
 
uint32_t FindNetDeviceForNixIndex(uint32_t nodeIndex, Ipv4Address &gatewayIp)
 
uint32_t FindTotalNeighbors(void)
 
Ptr< NixVector > GetNixVector(Ptr< Node >, Ipv4Address, Ptr< NetDevice >)
 
void SetSource(Ipv4Address src)
 
uint32_t GetN(void) const 
Get the number of Ptr stored in this container. 
 
Ptr< NetDevice > GetOutputDevice(void) const 
 
Ptr< NixVector > GetNixVectorInCache(Ipv4Address)
 
uint32_t ExtractNeighborIndex(uint32_t numberOfBits)
 
void SetNode(Ptr< Node > node)
Set the Node pointer of the node for which this routing protocol is to be placed. ...
 
void SetNixVector(Ptr< NixVector > nixVector)
Set the packet nix-vector. 
 
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container. 
 
void SetGateway(Ipv4Address gw)
 
static Iterator End(void)
 
Nix-vector routing protocol. 
 
Ptr< Node > GetNodeByIp(Ipv4Address)
 
holds a vector of ns3::NetDevice pointers 
 
Ptr< NetDevice > GetDevice(uint32_t index) const 
Retrieve the index-th NetDevice associated to this node. 
 
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) const 
 
void CheckCacheStateAndFlush(void) const 
 
static TypeId GetTypeId(void)
The Interface ID of the Global Router interface. 
 
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC. 
 
virtual void NotifyInterfaceDown(uint32_t interface)
 
Access to the Ipv4 forwarding table, interfaces, and configuration. 
 
uint32_t GetNDevices(void) const 
 
virtual void NotifyInterfaceUp(uint32_t interface)
 
Every class exported by the ns3 library is enclosed in the ns3 namespace. 
 
keep track of a set of node pointers. 
 
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator. 
 
Iterator Begin(void) const 
Get an iterator which refers to the first Node in the container. 
 
void FlushNixCache(void) const 
 
static bool g_isCacheDirty
 
void SetOutputDevice(Ptr< NetDevice > outputDevice)
Equivalent in Linux to dst_entry.dev. 
 
virtual void NotifyRemoveAddress(uint32_t interface, Ipv4InterfaceAddress address)
 
bool BuildNixVector(const std::vector< Ptr< Node > > &parentVector, uint32_t source, uint32_t dest, Ptr< NixVector > nixVector)
 
void GetAdjacentNetDevices(Ptr< NetDevice >, Ptr< Channel >, NetDeviceContainer &)
 
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
 
static NodeContainer GetGlobal(void)
Create a NodeContainer that contains a list of all nodes created through NodeContainer::Create() and ...
 
virtual Ptr< Ipv4Route > RouteOutput(Ptr< Packet > p, const Ipv4Header &header, Ptr< NetDevice > oif, Socket::SocketErrno &sockerr)
Query routing cache for an existing route, for an outbound packet. 
 
virtual void SetIpv4(Ptr< Ipv4 > ipv4)
 
uint32_t m_totalNeighbors
 
Ipv4 addresses are stored in host order in this class. 
 
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message. 
 
uint32_t GetId(void) const 
 
a class to store IPv4 address information on an interface 
 
static Iterator Begin(void)
 
std::vector< Ptr< NetDevice > >::const_iterator Iterator
NetDevice container iterator. 
 
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG. 
 
Ipv4RouteMap_t m_ipv4RouteCache
 
virtual bool RouteInput(Ptr< const Packet > p, const Ipv4Header &header, Ptr< const NetDevice > idev, UnicastForwardCallback ucb, MulticastForwardCallback mcb, LocalDeliverCallback lcb, ErrorCallback ecb)
Route an input packet (to be forwarded or locally delivered) 
 
static std::string FindName(Ptr< Object > object)
Given a pointer to an object, look to see if that object has a name associated with it and...
 
Abstract base class for IPv4 routing protocols. 
 
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR. 
 
void AddNeighborIndex(uint32_t newBits, uint32_t numberOfBits)
 
Iterator End(void) const 
Get an iterator which indicates past-the-last NetDevice in the container. 
 
virtual void NotifyAddAddress(uint32_t interface, Ipv4InterfaceAddress address)
 
a unique identifier for an interface. 
 
TypeId SetParent(TypeId tid)
Set the parent TypeId. 
 
virtual void PrintRoutingTable(Ptr< OutputStreamWrapper > stream) const 
Print the Routing Table entries. 
 
uint32_t BitCount(uint32_t numberOfNeighbors) const 
 
Ptr< Ipv4Route > GetIpv4RouteInCache(Ipv4Address)
 
std::ostream * GetStream(void)
Return a pointer to an ostream previously set in the wrapper. 
 
void SetDestination(Ipv4Address dest)
 
bool BFS(uint32_t numberOfNodes, Ptr< Node > source, Ptr< Node > dest, std::vector< Ptr< Node > > &parentVector, Ptr< NetDevice > oif)