25 #include "ns3/abort.h"
26 #include "ns3/names.h"
27 #include "ns3/ipv4-list-routing.h"
44 .AddConstructor<Ipv4NixVectorRouting> ()
50 : m_totalNeighbors (0)
104 rp->FlushNixCache ();
105 rp->FlushIpv4RouteCache ();
143 if (source == destNode)
152 std::vector< Ptr<Node> > parentVector;
175 NixMap_t::iterator iter =
m_nixCache.find (address);
215 for (uint32_t i = 0; i < numberOfDevices; i++)
241 if (parentVector.at (dest) == 0)
246 Ptr<Node> parentNode = parentVector.at (dest);
248 uint32_t numberOfDevices = parentNode->
GetNDevices ();
250 uint32_t totalNeighbors = 0;
254 for (uint32_t i = 0; i < numberOfDevices; i++)
260 if (localNetDevice->IsBridge ())
283 Ptr<Node> remoteNode = (*iter)->GetNode ();
285 if (remoteNode->
GetId () == dest)
287 destId = totalNeighbors + offset;
292 totalNeighbors += netDeviceContainer.
GetN ();
295 << nixVector->
BitCount (totalNeighbors) <<
" bits, for node " << parentNode->
GetId ());
300 BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixVector);
309 for (uint32_t i = 0; i < channel->GetNDevices (); i++)
312 if (remoteDevice != netDevice)
319 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bd);
320 for (uint32_t j = 0; j < bd->GetNBridgePorts (); ++j)
323 if (ndBridged == remoteDevice)
325 NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
338 netDeviceContainer.
Add (channel->GetDevice (i));
356 if (ipv4->GetInterfaceForAddress (dest) != -1)
365 NS_LOG_ERROR (
"Couldn't find dest node given the IP" << dest);
376 uint32_t totalNeighbors = 0;
380 for (uint32_t i = 0; i < numberOfDevices; i++)
397 totalNeighbors += netDeviceContainer.
GetN ();
400 return totalNeighbors;
417 for (uint32_t i = 0; i < nDevices; ++i)
422 if (ndTest->IsBridge ())
424 NS_LOG_LOGIC (
"device " << i <<
" is a bridge net device");
426 NS_ABORT_MSG_UNLESS (bnd,
"Ipv4NixVectorRouting::NetDeviceIsBridged (): GetObject for <BridgeNetDevice> failed");
428 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
430 NS_LOG_LOGIC (
"Examine bridge port " << j <<
" " << bnd->GetBridgePort (j));
431 if (bnd->GetBridgePort (j) == nd)
433 NS_LOG_LOGIC (
"Net device " << nd <<
" is bridged by " << bnd);
439 NS_LOG_LOGIC (
"Net device " << nd <<
" is not bridged");
448 uint32_t totalNeighbors = 0;
452 for (uint32_t i = 0; i < numberOfDevices; i++)
470 if (nodeIndex < (totalNeighbors + netDeviceContainer.
GetN ()))
474 Ptr<NetDevice> gatewayDevice = netDeviceContainer.
Get (nodeIndex-totalNeighbors);
475 Ptr<Node> gatewayNode = gatewayDevice->GetNode ();
478 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (gatewayDevice);
483 totalNeighbors += netDeviceContainer.
GetN ();
504 if (!nixVectorInCache)
516 if (nixVectorInCache)
518 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache);
522 nixVectorForPacket = Create<NixVector> ();
523 nixVectorForPacket = nixVectorInCache->
Copy ();
535 uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits);
556 int32_t interfaceIndex = 0;
564 interfaceIndex = (
m_ipv4)->GetInterfaceForDevice (oif);
567 NS_ASSERT_MSG (interfaceIndex != -1,
"Interface index not found for device");
572 rtentry = Create<Ipv4Route> ();
593 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache <<
" : Remaining bits: " << nixVectorForPacket->GetRemainingBits ());
599 NS_LOG_LOGIC (
"Adding Nix-vector to packet: " << *nixVectorForPacket);
649 rtentry = Create<Ipv4Route> ();
661 " bits from Nix-vector: " << nixVector <<
" : " << *nixVector);
667 ucb (rtentry, p, header);
679 *os <<
"NixCache:" << std::endl;
682 *os <<
"Destination NixVector" << std::endl;
685 std::ostringstream dest;
687 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
688 *os << *(it->second) << std::endl;
691 *os <<
"Ipv4RouteCache:" << std::endl;
694 *os <<
"Destination Gateway Source OutputDevice" << std::endl;
697 std::ostringstream dest, gw, src;
698 dest << it->second->GetDestination ();
699 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
700 gw << it->second->GetGateway ();
701 *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
702 src << it->second->GetSource ();
703 *os << std::setiosflags (std::ios::left) << std::setw (16) << src.str ();
711 *os << it->second->GetOutputDevice ()->GetIfIndex ();
748 std::queue< Ptr<Node> > greyNodeList;
751 parentVector.clear ();
752 parentVector.reserve (
sizeof (
Ptr<Node>)*numberOfNodes);
753 parentVector.insert (parentVector.begin (),
sizeof (
Ptr<Node>)*numberOfNodes, 0);
756 greyNodeList.push (source);
757 parentVector.at (source->
GetId ()) = source;
760 while (greyNodeList.size () != 0)
762 Ptr<Node> currNode = greyNodeList.front ();
765 if (currNode == dest)
774 if (currNode == source && oif)
779 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (oif);
780 if (!(ipv4->IsUp (interfaceIndex)))
786 if (!(oif->IsLinkUp ()))
808 Ptr<Node> remoteNode = (*iter)->GetNode ();
814 if (parentVector.at (remoteNode->
GetId ()) == 0)
816 parentVector.at (remoteNode->
GetId ()) = currNode;
817 greyNodeList.push (remoteNode);
825 for (uint32_t i = 0; i < (currNode->
GetNDevices ()); i++)
835 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (currNode->
GetDevice (i));
836 if (!(ipv4->IsUp (interfaceIndex)))
842 if (!(localNetDevice->IsLinkUp ()))
864 Ptr<Node> remoteNode = (*iter)->GetNode ();
870 if (parentVector.at (remoteNode->
GetId ()) == 0)
872 parentVector.at (remoteNode->
GetId ()) = currNode;
873 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< 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)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
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)