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++)
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");
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)
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);
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)))
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)))
852 Ptr<Node> remoteNode = (*iter)->GetNode ();
858 if (parentVector.at (remoteNode->
GetId ()) == 0)
860 parentVector.at (remoteNode->
GetId ()) = currNode;
861 greyNodeList.push (remoteNode);