25 #include "ns3/abort.h"
26 #include "ns3/names.h"
27 #include "ns3/ipv4-list-routing.h"
43 .AddConstructor<Ipv4NixVectorRouting> ()
49 : m_totalNeighbors (0)
103 rp->FlushNixCache ();
104 rp->FlushIpv4RouteCache ();
142 if (source == destNode)
151 std::vector< Ptr<Node> > parentVector;
172 NixMap_t::iterator iter =
m_nixCache.find (address);
210 for (uint32_t i = 0; i < numberOfDevices; i++)
236 if (parentVector.at (dest) == 0)
241 Ptr<Node> parentNode = parentVector.at (dest);
243 uint32_t numberOfDevices = parentNode->
GetNDevices ();
245 uint32_t totalNeighbors = 0;
249 for (uint32_t i = 0; i < numberOfDevices; i++)
255 if (localNetDevice->IsBridge ())
278 Ptr<Node> remoteNode = (*iter)->GetNode ();
280 if (remoteNode->
GetId () == dest)
282 destId = totalNeighbors + offset;
287 totalNeighbors += netDeviceContainer.
GetN ();
290 << nixVector->
BitCount (totalNeighbors) <<
" bits, for node " << parentNode->
GetId ());
295 BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixVector);
304 for (uint32_t i = 0; i < channel->GetNDevices (); i++)
307 if (remoteDevice != netDevice)
314 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bd);
315 for (uint32_t j = 0; j < bd->GetNBridgePorts (); ++j)
318 if (ndBridged == remoteDevice)
320 NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
333 netDeviceContainer.
Add (channel->GetDevice (i));
351 if (ipv4->GetInterfaceForAddress (dest) != -1)
360 NS_LOG_ERROR (
"Couldn't find dest node given the IP" << dest);
371 uint32_t totalNeighbors = 0;
375 for (uint32_t i = 0; i < numberOfDevices; i++)
392 totalNeighbors += netDeviceContainer.
GetN ();
395 return totalNeighbors;
412 for (uint32_t i = 0; i < nDevices; ++i)
417 if (ndTest->IsBridge ())
419 NS_LOG_LOGIC (
"device " << i <<
" is a bridge net device");
421 NS_ABORT_MSG_UNLESS (bnd,
"Ipv4NixVectorRouting::NetDeviceIsBridged (): GetObject for <BridgeNetDevice> failed");
423 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
425 NS_LOG_LOGIC (
"Examine bridge port " << j <<
" " << bnd->GetBridgePort (j));
426 if (bnd->GetBridgePort (j) == nd)
428 NS_LOG_LOGIC (
"Net device " << nd <<
" is bridged by " << bnd);
434 NS_LOG_LOGIC (
"Net device " << nd <<
" is not bridged");
443 uint32_t totalNeighbors = 0;
447 for (uint32_t i = 0; i < numberOfDevices; i++)
465 if (nodeIndex < (totalNeighbors + netDeviceContainer.
GetN ()))
469 Ptr<NetDevice> gatewayDevice = netDeviceContainer.
Get (nodeIndex-totalNeighbors);
470 Ptr<Node> gatewayNode = gatewayDevice->GetNode ();
473 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (gatewayDevice);
478 totalNeighbors += netDeviceContainer.
GetN ();
497 if (!nixVectorInCache)
509 if (nixVectorInCache)
511 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache);
515 nixVectorForPacket = Create<NixVector> ();
516 nixVectorForPacket = nixVectorInCache->
Copy ();
528 uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits);
549 int32_t interfaceIndex = 0;
557 interfaceIndex = (
m_ipv4)->GetInterfaceForDevice (oif);
560 NS_ASSERT_MSG (interfaceIndex != -1,
"Interface index not found for device");
565 rtentry = Create<Ipv4Route> ();
586 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache <<
" : Remaining bits: " << nixVectorForPacket->GetRemainingBits ());
592 NS_LOG_LOGIC (
"Adding Nix-vector to packet: " << *nixVectorForPacket);
640 rtentry = Create<Ipv4Route> ();
652 " bits from Nix-vector: " << nixVector <<
" : " << *nixVector);
658 ucb (rtentry, p, header);
668 *os <<
"NixCache:" << std::endl;
671 *os <<
"Destination NixVector" << std::endl;
674 std::ostringstream dest;
676 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
677 *os << *(it->second) << std::endl;
680 *os <<
"Ipv4RouteCache:" << std::endl;
683 *os <<
"Destination Gateway Source OutputDevice" << std::endl;
686 std::ostringstream dest, gw, src;
687 dest << it->second->GetDestination ();
688 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
689 gw << it->second->GetGateway ();
690 *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
691 src << it->second->GetSource ();
692 *os << std::setiosflags (std::ios::left) << std::setw (16) << src.str ();
700 *os << it->second->GetOutputDevice ()->GetIfIndex ();
737 std::queue< Ptr<Node> > greyNodeList;
740 parentVector.clear ();
741 parentVector.reserve (
sizeof (
Ptr<Node>)*numberOfNodes);
742 parentVector.insert (parentVector.begin (),
sizeof (
Ptr<Node>)*numberOfNodes, 0);
745 greyNodeList.push (source);
746 parentVector.at (source->
GetId ()) = source;
749 while (greyNodeList.size () != 0)
751 Ptr<Node> currNode = greyNodeList.front ();
754 if (currNode == dest)
763 if (currNode == source && oif)
768 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (oif);
769 if (!(ipv4->IsUp (interfaceIndex)))
775 if (!(oif->IsLinkUp ()))
797 Ptr<Node> remoteNode = (*iter)->GetNode ();
803 if (parentVector.at (remoteNode->
GetId ()) == 0)
805 parentVector.at (remoteNode->
GetId ()) = currNode;
806 greyNodeList.push (remoteNode);
814 for (uint32_t i = 0; i < (currNode->
GetNDevices ()); i++)
824 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (currNode->
GetDevice (i));
825 if (!(ipv4->IsUp (interfaceIndex)))
831 if (!(localNetDevice->IsLinkUp ()))
853 Ptr<Node> remoteNode = (*iter)->GetNode ();
859 if (parentVector.at (remoteNode->
GetId ()) == 0)
861 parentVector.at (remoteNode->
GetId ()) = currNode;
862 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)
static uint32_t GetNNodes(void)
std::vector< Ptr< Node > >::const_iterator 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)
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
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)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
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 Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
void SetGateway(Ipv4Address gw)
void SetNixVector(Ptr< NixVector >)
Set the packet nix-vector.
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)
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
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)
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.
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
#define NS_LOG_DEBUG(msg)
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)
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.
NS_LOG_COMPONENT_DEFINE("Ipv4NixVectorRouting")
void SetDestination(Ipv4Address dest)
bool BFS(uint32_t numberOfNodes, Ptr< Node > source, Ptr< Node > dest, std::vector< Ptr< Node > > &parentVector, Ptr< NetDevice > oif)