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 ();
140 if (source == destNode)
149 std::vector< Ptr<Node> > parentVector;
170 NixMap_t::iterator iter =
m_nixCache.find (address);
208 for (uint32_t i = 0; i < numberOfDevices; i++)
234 if (parentVector.at (dest) == 0)
239 Ptr<Node> parentNode = parentVector.at (dest);
241 uint32_t numberOfDevices = parentNode->
GetNDevices ();
243 uint32_t totalNeighbors = 0;
247 for (uint32_t i = 0; i < numberOfDevices; i++)
276 Ptr<Node> remoteNode = (*iter)->GetNode ();
278 if (remoteNode->
GetId () == dest)
280 destId = totalNeighbors + offset;
285 totalNeighbors += netDeviceContainer.
GetN ();
288 << nixVector->
BitCount (totalNeighbors) <<
" bits, for node " << parentNode->
GetId ());
293 BuildNixVector (parentVector, source, (parentVector.at (dest))->GetId (), nixVector);
302 for (uint32_t i = 0; i < channel->
GetNDevices (); i++)
305 if (remoteDevice != netDevice)
312 NS_LOG_LOGIC (
"Looking through bridge ports of bridge net device " << bd);
313 for (uint32_t j = 0; j < bd->GetNBridgePorts (); ++j)
316 if (ndBridged == remoteDevice)
318 NS_LOG_LOGIC (
"That bridge port is me, don't walk backward");
358 NS_LOG_ERROR (
"Couldn't find dest node given the IP" << dest);
369 uint32_t totalNeighbors = 0;
373 for (uint32_t i = 0; i < numberOfDevices; i++)
390 totalNeighbors += netDeviceContainer.
GetN ();
393 return totalNeighbors;
410 for (uint32_t i = 0; i < nDevices; ++i)
417 NS_LOG_LOGIC (
"device " << i <<
" is a bridge net device");
419 NS_ABORT_MSG_UNLESS (bnd,
"Ipv4NixVectorRouting::NetDeviceIsBridged (): GetObject for <BridgeNetDevice> failed");
421 for (uint32_t j = 0; j < bnd->GetNBridgePorts (); ++j)
423 NS_LOG_LOGIC (
"Examine bridge port " << j <<
" " << bnd->GetBridgePort (j));
424 if (bnd->GetBridgePort (j) == nd)
426 NS_LOG_LOGIC (
"Net device " << nd <<
" is bridged by " << bnd);
432 NS_LOG_LOGIC (
"Net device " << nd <<
" is not bridged");
441 uint32_t totalNeighbors = 0;
445 for (uint32_t i = 0; i < numberOfDevices; i++)
463 if (nodeIndex < (totalNeighbors + netDeviceContainer.
GetN ()))
467 Ptr<NetDevice> gatewayDevice = netDeviceContainer.
Get (nodeIndex-totalNeighbors);
471 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (gatewayDevice);
476 totalNeighbors += netDeviceContainer.
GetN ();
495 if (!nixVectorInCache)
507 if (nixVectorInCache)
509 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache);
513 nixVectorForPacket = Create<NixVector> ();
514 nixVectorForPacket = nixVectorInCache->
Copy ();
526 uint32_t nodeIndex = nixVectorForPacket->ExtractNeighborIndex (numberOfBits);
547 int32_t interfaceIndex = 0;
555 interfaceIndex = (
m_ipv4)->GetInterfaceForDevice (oif);
558 NS_ASSERT_MSG (interfaceIndex != -1,
"Interface index not found for device");
563 rtentry = Create<Ipv4Route> ();
584 NS_LOG_LOGIC (
"Nix-vector contents: " << *nixVectorInCache <<
" : Remaining bits: " << nixVectorForPacket->GetRemainingBits ());
590 NS_LOG_LOGIC (
"Adding Nix-vector to packet: " << *nixVectorForPacket);
638 rtentry = Create<Ipv4Route> ();
650 " bits from Nix-vector: " << nixVector <<
" : " << *nixVector);
656 ucb (rtentry, p, header);
666 *os <<
"NixCache:" << std::endl;
669 *os <<
"Destination NixVector" << std::endl;
672 std::ostringstream dest;
674 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
675 *os << *(it->second) << std::endl;
678 *os <<
"Ipv4RouteCache:" << std::endl;
681 *os <<
"Destination Gateway Source OutputDevice" << std::endl;
684 std::ostringstream dest, gw, src;
685 dest << it->second->GetDestination ();
686 *os << std::setiosflags (std::ios::left) << std::setw (16) << dest.str ();
687 gw << it->second->GetGateway ();
688 *os << std::setiosflags (std::ios::left) << std::setw (16) << gw.str ();
689 src << it->second->GetSource ();
690 *os << std::setiosflags (std::ios::left) << std::setw (16) << src.str ();
698 *os << it->second->GetOutputDevice ()->GetIfIndex ();
735 std::queue< Ptr<Node> > greyNodeList;
738 parentVector.clear ();
739 parentVector.reserve (
sizeof (
Ptr<Node>)*numberOfNodes);
740 parentVector.insert (parentVector.begin (),
sizeof (
Ptr<Node>)*numberOfNodes, 0);
743 greyNodeList.push (source);
744 parentVector.at (source->
GetId ()) = source;
747 while (greyNodeList.size () != 0)
749 Ptr<Node> currNode = greyNodeList.front ();
752 if (currNode == dest)
761 if (currNode == source && oif)
766 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (oif);
767 if (!(ipv4->
IsUp (interfaceIndex)))
795 Ptr<Node> remoteNode = (*iter)->GetNode ();
801 if (parentVector.at (remoteNode->
GetId ()) == 0)
803 parentVector.at (remoteNode->
GetId ()) = currNode;
804 greyNodeList.push (remoteNode);
812 for (uint32_t i = 0; i < (currNode->
GetNDevices ()); i++)
822 uint32_t interfaceIndex = (ipv4)->GetInterfaceForDevice (currNode->
GetDevice (i));
823 if (!(ipv4->
IsUp (interfaceIndex)))
851 Ptr<Node> remoteNode = (*iter)->GetNode ();
857 if (parentVector.at (remoteNode->
GetId ()) == 0)
859 parentVector.at (remoteNode->
GetId ()) = currNode;
860 greyNodeList.push (remoteNode);