25 #include "ns3/abort.h"
26 #include "ns3/names.h"
27 #include "ns3/ipv4-list-routing.h"
42 .AddConstructor<Ipv4NixVectorRouting> ()
48 : m_totalNeighbors (0)
102 rp->FlushNixCache ();
103 rp->FlushIpv4RouteCache ();
141 if (source == destNode)
150 std::vector< Ptr<Node> > parentVector;
171 NixMap_t::iterator iter =
m_nixCache.find (address);
209 for (uint32_t i = 0; i < numberOfDevices; i++)
235 if (parentVector.at (dest) == 0)
240 Ptr<Node> parentNode = parentVector.at (dest);
242 uint32_t numberOfDevices = parentNode->
GetNDevices ();
244 uint32_t totalNeighbors = 0;
248 for (uint32_t i = 0; i < numberOfDevices; i++)
254 if (localNetDevice->IsBridge ())
277 Ptr<Node> remoteNode = (*iter)->GetNode ();
279 if (remoteNode->
GetId () == dest)
281 destId = totalNeighbors + offset;
286 totalNeighbors += netDeviceContainer.
GetN ();
289 << nixVector->
BitCount (totalNeighbors) <<
" bits, for node " << parentNode->
GetId ());
294 BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixVector);
303 for (uint32_t i = 0; i < channel->GetNDevices (); i++)
306 if (remoteDevice != netDevice)
313 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bd);
314 for (uint32_t j = 0; j < bd->GetNBridgePorts (); ++j)
317 if (ndBridged == remoteDevice)
319 NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
332 netDeviceContainer.
Add (channel->GetDevice (i));
350 if (ipv4->GetInterfaceForAddress (dest) != -1)
359 NS_LOG_ERROR (
"Couldn't find dest node given the IP" << dest);
370 uint32_t totalNeighbors = 0;
374 for (uint32_t i = 0; i < numberOfDevices; i++)
391 totalNeighbors += netDeviceContainer.
GetN ();
394 return totalNeighbors;
411 for (uint32_t i = 0; i < nDevices; ++i)
416 if (ndTest->IsBridge ())
418 NS_LOG_LOGIC (
"device " << i <<
" is a bridge net device");
420 NS_ABORT_MSG_UNLESS (bnd,
"Ipv4NixVectorRouting::NetDeviceIsBridged (): GetObject for <BridgeNetDevice> failed");
422 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
424 NS_LOG_LOGIC (
"Examine bridge port " << j <<
" " << bnd->GetBridgePort (j));
425 if (bnd->GetBridgePort (j) == nd)
427 NS_LOG_LOGIC (
"Net device " << nd <<
" is bridged by " << bnd);
433 NS_LOG_LOGIC (
"Net device " << nd <<
" is not bridged");
442 uint32_t totalNeighbors = 0;
446 for (uint32_t i = 0; i < numberOfDevices; i++)
464 if (nodeIndex < (totalNeighbors + netDeviceContainer.
GetN ()))
468 Ptr<NetDevice> gatewayDevice = netDeviceContainer.
Get (nodeIndex-totalNeighbors);
469 Ptr<Node> gatewayNode = gatewayDevice->GetNode ();
472 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (gatewayDevice);
477 totalNeighbors += netDeviceContainer.
GetN ();
496 if (!nixVectorInCache)
508 if (nixVectorInCache)
510 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache);
514 nixVectorForPacket = Create<NixVector> ();
515 nixVectorForPacket = nixVectorInCache->
Copy ();
527 uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits);
548 int32_t interfaceIndex = 0;
556 interfaceIndex = (
m_ipv4)->GetInterfaceForDevice (oif);
559 NS_ASSERT_MSG (interfaceIndex != -1,
"Interface index not found for device");
564 rtentry = Create<Ipv4Route> ();
585 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache <<
" : Remaining bits: " << nixVectorForPacket->GetRemainingBits ());
591 NS_LOG_LOGIC (
"Adding Nix-vector to packet: " << *nixVectorForPacket);
639 rtentry = Create<Ipv4Route> ();
651 " bits from Nix-vector: " << nixVector <<
" : " << *nixVector);
657 ucb (rtentry, p, header);
667 *os <<
"NixCache:" << std::endl;
670 *os <<
"Destination NixVector" << std::endl;
673 std::ostringstream dest;
675 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
676 *os << *(it->second) << std::endl;
679 *os <<
"Ipv4RouteCache:" << std::endl;
682 *os <<
"Destination Gateway Source OutputDevice" << std::endl;
685 std::ostringstream dest, gw, src;
686 dest << it->second->GetDestination ();
687 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
688 gw << it->second->GetGateway ();
689 *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
690 src << it->second->GetSource ();
691 *os << std::setiosflags (std::ios::left) << std::setw (16) << src.str ();
699 *os << it->second->GetOutputDevice ()->GetIfIndex ();
736 std::queue< Ptr<Node> > greyNodeList;
739 parentVector.clear ();
740 parentVector.reserve (
sizeof (
Ptr<Node>)*numberOfNodes);
741 parentVector.insert (parentVector.begin (),
sizeof (
Ptr<Node>)*numberOfNodes, 0);
744 greyNodeList.push (source);
745 parentVector.at (source->
GetId ()) = source;
748 while (greyNodeList.size () != 0)
750 Ptr<Node> currNode = greyNodeList.front ();
753 if (currNode == dest)
762 if (currNode == source && oif)
767 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (oif);
768 if (!(ipv4->IsUp (interfaceIndex)))
774 if (!(oif->IsLinkUp ()))
796 Ptr<Node> remoteNode = (*iter)->GetNode ();
802 if (parentVector.at (remoteNode->
GetId ()) == 0)
804 parentVector.at (remoteNode->
GetId ()) = currNode;
805 greyNodeList.push (remoteNode);
813 for (uint32_t i = 0; i < (currNode->
GetNDevices ()); i++)
823 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (currNode->
GetDevice (i));
824 if (!(ipv4->IsUp (interfaceIndex)))
830 if (!(localNetDevice->IsLinkUp ()))
852 Ptr<Node> remoteNode = (*iter)->GetNode ();
858 if (parentVector.at (remoteNode->
GetId ()) == 0)
860 parentVector.at (remoteNode->
GetId ()) = currNode;
861 greyNodeList.push (remoteNode);
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 "...
static uint32_t GetNNodes(void)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ipv4Address GetLocal(void) const
Get the local address.
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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
#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)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
a virtual net device that bridges multiple LAN segments
Ptr< NixVector > GetNixVector(void) const
Get the packet nix-vector.
SocketErrno
Enumeration of the possible errors returned by a socket.
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 FlushGlobalNixRoutingCache(void)
Called when run-time link topology change occurs which iterates through the node list and flushes any...
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
Ptr< BridgeNetDevice > NetDeviceIsBridged(Ptr< NetDevice > nd) 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)
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 FlushIpv4RouteCache(void)
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 cond is false.
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)
Ptr< T > GetObject(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
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)