changed RouteInput to handle cases where nix vector is lost; this is happening
authorJosh Pelkey <jpelkey@ece.gatech.edu>
Mon Jul 06 11:34:43 2009 -0400 (7 months ago)
changeset 45304cca63c6aea1
parent 4529 b3a594bbcbb0
child 4670 dee60180af91
changed RouteInput to handle cases where nix vector is lost; this is happening
during distributed sims right now
src/routing/nix-vector-routing/nix-vector-routing.cc
     1.1 --- a/src/routing/nix-vector-routing/nix-vector-routing.cc	Tue Jun 23 15:56:56 2009 -0400
     1.2 +++ b/src/routing/nix-vector-routing/nix-vector-routing.cc	Mon Jul 06 11:34:43 2009 -0400
     1.3 @@ -150,6 +150,7 @@
     1.4      if (ifAddr.GetLocal() == loopback)
     1.5      {
     1.6        NS_LOG_LOGIC ("Adding loopback to nix.");
     1.7 +      NS_LOG_LOGIC ("Adding Nix: " << i << " with " << nixVector->BitCount (numberOfDevices) << " bits, for node " << m_node->GetId());
     1.8        nixVector->AddNeighborIndex (i, nixVector->BitCount (numberOfDevices));
     1.9        return true;
    1.10      }
    1.11 @@ -254,7 +255,7 @@
    1.12  
    1.13    if (!destNode)
    1.14    {
    1.15 -    NS_LOG_ERROR ("Couldn't find dest node given the IP.");
    1.16 +    NS_LOG_ERROR ("Couldn't find dest node given the IP" << dest);
    1.17      return 0;
    1.18    }
    1.19  
    1.20 @@ -355,8 +356,79 @@
    1.21    // went wrong
    1.22    if (!nixVector)
    1.23    {
    1.24 -    NS_LOG_ERROR ("Nix-vector wasn't in the packet! Can't route.");
    1.25 -    return false;
    1.26 +    NS_LOG_ERROR ("Nix-vector wasn't in the packet! Rebuild.");
    1.27 +
    1.28 +    Ptr<NixVector> nixVectorInCache;
    1.29 +
    1.30 +    NS_LOG_DEBUG ("Dest IP from header: " << header.GetDestination());
    1.31 +
    1.32 +    // check if cache
    1.33 +    nixVectorInCache = GetNixVectorInCache(header.GetDestination());
    1.34 +
    1.35 +    // not in cache
    1.36 +    if (!nixVectorInCache)
    1.37 +    {
    1.38 +      NS_LOG_LOGIC ("RouteInput(): Nix-vector not in cache, build: ");
    1.39 +
    1.40 +      // Build the nix-vector, given this node and the
    1.41 +      // dest IP address
    1.42 +      nixVectorInCache = GetNixVector (m_node, header.GetDestination());
    1.43 +    }
    1.44 +
    1.45 +    // path exists
    1.46 +    if (nixVectorInCache)
    1.47 +    {
    1.48 +      NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache);
    1.49 +
    1.50 +      // cache it
    1.51 +      m_cache.insert(NixMap_t::value_type(header.GetDestination(), nixVectorInCache));
    1.52 +
    1.53 +      // create a new nix vector to be used, 
    1.54 +      // we want to keep the cached version clean
    1.55 +      Ptr<NixVector> nixVectorForPacket;
    1.56 +      nixVectorForPacket = CreateObject<NixVector> ();
    1.57 +      nixVectorForPacket = nixVectorInCache->Copy(); 
    1.58 +
    1.59 +      // Get the interface number that we go out of, by extracting
    1.60 +      // from the nix-vector
    1.61 +      uint32_t numberOfBits = nixVectorForPacket->BitCount (m_node->GetNDevices ());
    1.62 +      uint32_t index = nixVectorForPacket->ExtractNeighborIndex (numberOfBits);
    1.63 +      uint32_t interfaceIndex = (m_ipv4)->GetInterfaceForDevice(m_node->GetDevice(index));
    1.64 +      NS_LOG_LOGIC ("Nix-vector contents: " << *nixVectorInCache << " : Remaining bits: " << nixVectorForPacket->RemainingBits());
    1.65 +
    1.66 +      Ipv4InterfaceAddress ifAddr = m_ipv4->GetAddress (interfaceIndex, 0);
    1.67 +
    1.68 +      // start filling in the Ipv4Route info
    1.69 +      rtentry = Create<Ipv4Route> ();
    1.70 +      rtentry->SetSource (ifAddr.GetLocal ());
    1.71 +
    1.72 +      // Have to set a gateway here (defaulting to zero)
    1.73 +      // otherwise RouteOutput gets called twice
    1.74 +      rtentry->SetGateway (Ipv4Address((uint32_t)0));
    1.75 +      rtentry->SetDestination (header.GetDestination ());
    1.76 +      rtentry->SetOutputDevice (m_ipv4->GetNetDevice (interfaceIndex));
    1.77 +
    1.78 +      // Add  nix-vector in the packet class 
    1.79 +      // have to copy the packet first b/c 
    1.80 +      // it is const
    1.81 +      Ptr<Packet> newPacket = Create<Packet> ();
    1.82 +      newPacket = p->Copy();
    1.83 +
    1.84 +      NS_LOG_LOGIC ("Adding Nix-vector to packet: " << *nixVectorForPacket);
    1.85 +      newPacket->SetNixVector(nixVectorForPacket);
    1.86 +
    1.87 +      // call the unicast callback
    1.88 +      // local deliver is handled by Ipv4StaticRoutingImpl
    1.89 +      // so this code is never even called if the packet is
    1.90 +      // destined for this node.
    1.91 +      ucb (rtentry, newPacket, header);
    1.92 +      return true;
    1.93 +    }
    1.94 +    else // path doesn't exist
    1.95 +    {
    1.96 +      NS_LOG_ERROR ("No path to the dest: " << header.GetDestination());
    1.97 +      return false;
    1.98 +    }
    1.99    }
   1.100    else
   1.101    {