Adding initial Nix-vector files, unfinished
authorJosh Pelkey <jpelkey@ece.gatech.edu>
Thu Jun 04 09:32:03 2009 -0400 (8 months ago)
changeset 450089befe2747c6
parent 4495 65b647611e9f
child 4501 c59049e93487
Adding initial Nix-vector files, unfinished
src/routing/nix-vector-routing/nix-vector-routing.cc
src/routing/nix-vector-routing/nix-vector-routing.h
src/routing/nix-vector-routing/nix-vector.cc
src/routing/nix-vector-routing/nix-vector.h
src/routing/nix-vector-routing/waf
src/routing/nix-vector-routing/wscript
src/wscript
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/routing/nix-vector-routing/nix-vector-routing.cc	Thu Jun 04 09:32:03 2009 -0400
     1.3 @@ -0,0 +1,228 @@
     1.4 +/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     1.5 +/*
     1.6 + * Copyright (c) 2009 The Georgia Institute of Technology 
     1.7 + *
     1.8 + * This program is free software; you can redistribute it and/or modify
     1.9 + * it under the terms of the GNU General Public License version 2 as
    1.10 + * published by the Free Software Foundation;
    1.11 + *
    1.12 + * This program is distributed in the hope that it will be useful,
    1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.15 + * GNU General Public License for more details.
    1.16 + *
    1.17 + * You should have received a copy of the GNU General Public License
    1.18 + * along with this program; if not, write to the Free Software
    1.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.20 + *
    1.21 + * Authors: Josh Pelkey <jpelkey@gatech.edu>
    1.22 + */
    1.23 +
    1.24 +#include <iostream>
    1.25 +#include <queue>
    1.26 +
    1.27 +#include "ns3/log.h"
    1.28 +#include "ns3/assert.h"
    1.29 +#include "ns3/abort.h"
    1.30 +
    1.31 +#include "nix-vector-routing.h"
    1.32 +
    1.33 +NS_LOG_COMPONENT_DEFINE ("NixVectorRouting");
    1.34 +
    1.35 +namespace ns3 {
    1.36 +
    1.37 +NixVectorRouting::NixVectorRouting()
    1.38 +{
    1.39 +}
    1.40 +
    1.41 +NixVectorRouting::~NixVectorRouting()
    1.42 +{
    1.43 +}
    1.44 +
    1.45 +NixVector
    1.46 +NixVectorRouting::GetNixVector(Ptr<Node> source, Ptr<Node> dest)
    1.47 +{
    1.48 +  NixVector nixVector;
    1.49 +
    1.50 +  // Check if already in cache
    1.51 +  NixMap_t::iterator iter = m_cache.find(dest->GetId());
    1.52 +  if (iter != m_cache.end())
    1.53 +    // in cache
    1.54 +    return iter->second;
    1.55 +  else
    1.56 +  {
    1.57 +    // not in cache, must build the nix vector
    1.58 +    std::vector< Ptr<Node> > parentVector;
    1.59 +    BFS(NodeList::GetNNodes(), source, dest, parentVector);
    1.60 +    if (BuildNixVector(parentVector, source->GetId(), dest->GetId(), nixVector))
    1.61 +      return nixVector;
    1.62 +    else
    1.63 +    {
    1.64 +      std::cout << "No routing path exists" << std::endl;
    1.65 +      exit(1);
    1.66 +    }
    1.67 +
    1.68 +  }
    1.69 +}
    1.70 +
    1.71 +bool
    1.72 +NixVectorRouting::IsNixVectorInCache(int nodeId)
    1.73 +{
    1.74 +  NixMap_t::iterator iter = m_cache.find(nodeId);
    1.75 +    if (iter != m_cache.end())
    1.76 +      return true;
    1.77 +
    1.78 +  // not in cache
    1.79 +  return false;
    1.80 +}
    1.81 +
    1.82 +bool
    1.83 +NixVectorRouting::ValidateNixVector()
    1.84 +{
    1.85 +  return false;
    1.86 +}
    1.87 +
    1.88 +bool 
    1.89 +NixVectorRouting::ReinitializeRoutes()
    1.90 +{
    1.91 +  return false;
    1.92 +}
    1.93 +
    1.94 +bool
    1.95 +NixVectorRouting::BuildNixVector(const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, NixVector & nixVector)
    1.96 +{
    1.97 +  NetDeviceContainer netDeviceContainer;
    1.98 +
    1.99 +  if (source == dest)
   1.100 +    return true;
   1.101 +
   1.102 +  if (parentVector.at(dest) == 0)
   1.103 +    return false;
   1.104 +
   1.105 +  Ptr<Node> parentNode = parentVector.at(dest);
   1.106 +
   1.107 +  // scan through the net devices on the parent node
   1.108 +  // and then look at the nodes adjacent to them
   1.109 +  for (uint32_t i = 0; i < parentNode->GetNDevices(); i++)
   1.110 +  {
   1.111 +    // Get a net device from the node
   1.112 +    // as well as the channel, and figure
   1.113 +    // out the adjacent net devices
   1.114 +    Ptr<NetDevice> localNetDevice = parentNode->GetDevice(i);
   1.115 +    Ptr<Channel> channel = localNetDevice->GetChannel();
   1.116 +    if (channel == 0)
   1.117 +    {
   1.118 +      std::cout << "GetChannel() returned zero." << std::endl;
   1.119 +      exit(1);
   1.120 +    }
   1.121 +    GetAdjacentNetDevices(localNetDevice, channel, netDeviceContainer);
   1.122 +
   1.123 +    // Finally we can get the adjacent nodes
   1.124 +    // and scan through them.  If we find the 
   1.125 +    // node that matches "dest" then we can add 
   1.126 +    // the index of the net device to the nix vector
   1.127 +    for (NetDeviceContainer::Iterator iter = netDeviceContainer.Begin(); iter != netDeviceContainer.End(); iter++)
   1.128 +    {
   1.129 +      Ptr<Node> remoteNode = (*iter)->GetNode();
   1.130 +
   1.131 +      if (remoteNode->GetId() == dest)
   1.132 +      {
   1.133 +      //std::cout << "Adding Nix: " << i << std::endl;
   1.134 +      nixVector.AddNeighborIndex(i);
   1.135 +      continue;
   1.136 +      }
   1.137 +    }
   1.138 +  }
   1.139 +  BuildNixVector(parentVector, source, (parentVector.at(dest))->GetId(), nixVector);
   1.140 +  return true;
   1.141 +}
   1.142 +
   1.143 +void
   1.144 +NixVectorRouting::GetAdjacentNetDevices(Ptr<NetDevice> netDevice, Ptr<Channel> channel, NetDeviceContainer & netDeviceContainer)
   1.145 +{
   1.146 +    for (uint32_t i = 0; i < channel->GetNDevices(); i++)
   1.147 +      if (channel->GetDevice(i) != netDevice)
   1.148 +        netDeviceContainer.Add(channel->GetDevice(i));
   1.149 +}
   1.150 +
   1.151 +Ptr<Ipv4Route> 
   1.152 +NixVectorRouting::RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr)
   1.153 +{
   1.154 +  return 0;
   1.155 +}
   1.156 +
   1.157 +bool 
   1.158 +NixVectorRouting::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
   1.159 +                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
   1.160 +                             LocalDeliverCallback lcb, ErrorCallback ecb)
   1.161 +{
   1.162 +  return 0;
   1.163 +}
   1.164 +
   1.165 +bool
   1.166 +NixVectorRouting::BFS (uint32_t numberOfNodes, Ptr<Node> source, Ptr<Node> dest, std::vector< Ptr<Node> > & parentVector)
   1.167 +{
   1.168 +  NetDeviceContainer netDeviceContainer;
   1.169 +  std::queue< Ptr<Node> > greyNodeList;  // discovered nodes with unexplored children
   1.170 +
   1.171 +  // reset the parent vector
   1.172 +  parentVector.clear ();
   1.173 +  parentVector.reserve(sizeof(Ptr<Node>)*numberOfNodes);
   1.174 +  parentVector.insert(parentVector.begin(), sizeof(Ptr<Node>)*numberOfNodes, 0); // initialize to 0
   1.175 +
   1.176 +  // Add the source node to the queue, set its parent to itself 
   1.177 +  greyNodeList.push(source);
   1.178 +  parentVector.at(source->GetId()) = source;
   1.179 +
   1.180 +  // BFS loop
   1.181 +  while(greyNodeList.size() != 0)
   1.182 +  {
   1.183 +    Ptr<Node> currNode = greyNodeList.front();
   1.184 + 
   1.185 +    if (currNode == dest) return true;
   1.186 +
   1.187 +    // Iterate over the current node's adjacent vertices
   1.188 +    // and push them into the queue
   1.189 +    for (uint32_t i = 0; i < currNode->GetNDevices(); i++)
   1.190 +    {
   1.191 +      // Get a net device from the node
   1.192 +      // as well as the channel, and figure
   1.193 +      // out the adjacent net device
   1.194 +      Ptr<NetDevice> localNetDevice = currNode->GetDevice(i);
   1.195 +      Ptr<Channel> channel = localNetDevice->GetChannel();
   1.196 +      if (channel == 0)
   1.197 +      { 
   1.198 +        std::cout << "GetChannel() returned zero." << std::endl;
   1.199 +        exit(1);
   1.200 +      }
   1.201 +      GetAdjacentNetDevices(localNetDevice, channel, netDeviceContainer);
   1.202 +
   1.203 +      // Finally we can get the adjacent nodes
   1.204 +      // and scan through them.  If we find the 
   1.205 +      // node that matches "dest" then we can add 
   1.206 +      for (NetDeviceContainer::Iterator iter = netDeviceContainer.Begin(); iter != netDeviceContainer.End(); iter++)
   1.207 +      {
   1.208 +        Ptr<Node> remoteNode = (*iter)->GetNode();
   1.209 +
   1.210 +        // check to see if this node has been pushed before
   1.211 +        // by checking to see if it has a parent
   1.212 +        // if it doesn't (null or 0), then set its parent and 
   1.213 +        // push to the queue
   1.214 +        if (parentVector.at(remoteNode->GetId()) == 0)
   1.215 +        {
   1.216 +          parentVector.at(remoteNode->GetId()) = currNode;
   1.217 +          greyNodeList.push(remoteNode);
   1.218 +        }
   1.219 +      }
   1.220 +    }
   1.221 +
   1.222 +    // Pop off the head grey node.  We have all its children.
   1.223 +    // It is now black.
   1.224 +    greyNodeList.pop();
   1.225 +
   1.226 +  }
   1.227 +  
   1.228 +  // Didn't find the dest...
   1.229 +  return false;
   1.230 +}
   1.231 +} // namespace ns3
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/routing/nix-vector-routing/nix-vector-routing.h	Thu Jun 04 09:32:03 2009 -0400
     2.3 @@ -0,0 +1,81 @@
     2.4 +/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     2.5 +/*
     2.6 + * Copyright (c) 2009 The Georgia Institute of Technology 
     2.7 + *
     2.8 + * This program is free software; you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License version 2 as
    2.10 + * published by the Free Software Foundation;
    2.11 + *
    2.12 + * This program is distributed in the hope that it will be useful,
    2.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.15 + * GNU General Public License for more details.
    2.16 + *
    2.17 + * You should have received a copy of the GNU General Public License
    2.18 + * along with this program; if not, write to the Free Software
    2.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.20 + *
    2.21 + * Authors: Josh Pelkey <jpelkey@gatech.edu>
    2.22 + */
    2.23 +
    2.24 +#ifndef __NIX_VECTOR_ROUTING_H__
    2.25 +#define __NIX_VECTOR_ROUTING_H__
    2.26 +
    2.27 +#include <vector>
    2.28 +#include <map>
    2.29 +
    2.30 +#include "nix-vector.h"
    2.31 +
    2.32 +#include "ns3/object.h"
    2.33 +#include "ns3/packet.h"
    2.34 +#include "ns3/channel.h"
    2.35 +#include "ns3/node.h"
    2.36 +#include "ns3/node-list.h"
    2.37 +#include "ns3/net-device-container.h"
    2.38 +#include "ns3/socket.h"
    2.39 +#include "ns3/event-garbage-collector.h"
    2.40 +#include "ns3/timer.h"
    2.41 +#include "ns3/traced-callback.h"
    2.42 +#include "ns3/ipv4.h"
    2.43 +#include "ns3/ipv4-route.h"
    2.44 +
    2.45 +namespace ns3 {
    2.46 +
    2.47 +typedef std::map<int,NixVector> NixMap_t;
    2.48 +
    2.49 +class NixVectorRouting : public Ipv4RoutingProtocol
    2.50 +{
    2.51 +  public:
    2.52 +    NixVectorRouting();
    2.53 +    ~NixVectorRouting();
    2.54 +    NixVector GetNixVector(Ptr<Node>, Ptr<Node>);
    2.55 +    bool IsNixVectorInCache(int);
    2.56 +    bool ReinitializeRoutes();
    2.57 +    bool ValidateNixVector();
    2.58 +    void GetAdjacentNetDevices(Ptr<NetDevice>, Ptr<Channel>, NetDeviceContainer &);
    2.59 +
    2.60 +  private:
    2.61 +    bool BuildNixVector(const std::vector< Ptr<Node> > & parentVector, uint32_t source, uint32_t dest, NixVector & nixVector);
    2.62 +
    2.63 +    // Breadth first search algorithm
    2.64 +    // Param1: Vector containing all nodes in the graph
    2.65 +    // Param2: Source Node
    2.66 +    // Param3: Dest Node
    2.67 +    // Param4: (returned) Parent vector for retracing routes
    2.68 +    // Returns: false if dest not found, true o.w.
    2.69 +    bool BFS (uint32_t numberOfNodes, 
    2.70 +             Ptr<Node> source, 
    2.71 +             Ptr<Node> dest, 
    2.72 +             std::vector< Ptr<Node> > & parentVector);
    2.73 +
    2.74 +    // From Ipv4RoutingProtocol
    2.75 +    virtual Ptr<Ipv4Route> RouteOutput (const Ipv4Header &header, uint32_t oif, Socket::SocketErrno &sockerr);
    2.76 +    virtual bool RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const NetDevice> idev,
    2.77 +                             UnicastForwardCallback ucb, MulticastForwardCallback mcb,
    2.78 +                             LocalDeliverCallback lcb, ErrorCallback ecb);  
    2.79 +
    2.80 +    NixMap_t m_cache;
    2.81 +};
    2.82 +
    2.83 +} // namepace ns3
    2.84 +#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/routing/nix-vector-routing/nix-vector.cc	Thu Jun 04 09:32:03 2009 -0400
     3.3 @@ -0,0 +1,264 @@
     3.4 +/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     3.5 +/*
     3.6 + * Copyright (c) 2009 The Georgia Institute of Technology 
     3.7 + *
     3.8 + * This program is free software; you can redistribute it and/or modify
     3.9 + * it under the terms of the GNU General Public License version 2 as
    3.10 + * published by the Free Software Foundation;
    3.11 + *
    3.12 + * This program is distributed in the hope that it will be useful,
    3.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 + * GNU General Public License for more details.
    3.16 + *
    3.17 + * You should have received a copy of the GNU General Public License
    3.18 + * along with this program; if not, write to the Free Software
    3.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    3.20 + *
    3.21 + * Authors: Josh Pelkey <jpelkey@gatech.edu>
    3.22 + */
    3.23 +
    3.24 +#include <vector>
    3.25 +#include <iostream>
    3.26 +
    3.27 +#include "nix-vector.h"
    3.28 +
    3.29 +namespace ns3 {
    3.30 +
    3.31 +typedef std::vector<uint32_t> NixBits_t;
    3.32 +
    3.33 +NixVector::NixVector()
    3.34 +  : m_nixVector(0),m_used(0),m_currentVectorBitSize(0),m_totalBitSize(0)
    3.35 +{
    3.36 +  m_nixVector.push_back(0);
    3.37 +}
    3.38 +
    3.39 +NixVector::~NixVector()
    3.40 +{
    3.41 +}
    3.42 +
    3.43 +void
    3.44 +NixVector::AddNeighborIndex(uint32_t newBits)
    3.45 +{
    3.46 +  uint32_t numberOfBits = BitCount(newBits);
    3.47 +
    3.48 +  // Check to see if the number
    3.49 +  // of new bits forces the creation of 
    3.50 +  // a new entry into the NixVector vector
    3.51 +  // i.e., we will overflow int o.w.
    3.52 +  if (m_currentVectorBitSize + numberOfBits > (sizeof(uint32_t)*8)) 
    3.53 +  {
    3.54 +    // Put what we can in the remaining portion of the 
    3.55 +    // vector entry
    3.56 +    uint32_t tempBits = newBits;
    3.57 +    tempBits = newBits << m_currentVectorBitSize;
    3.58 +    tempBits |= m_nixVector.back();
    3.59 +    m_nixVector.back() = tempBits;
    3.60 +
    3.61 +    // Now start a new vector entry
    3.62 +    // and push the remaining bits 
    3.63 +    // there
    3.64 +    newBits = newBits >> ((sizeof(uint32_t)*8) - m_currentVectorBitSize);
    3.65 +    m_nixVector.push_back(newBits);
    3.66 +    
    3.67 +    // also reset number of bits in
    3.68 +    // m_currentVectoBitSize
    3.69 +    // because we are working with a new 
    3.70 +    // entry in the vector
    3.71 +    m_currentVectorBitSize = (numberOfBits - ((sizeof(uint32_t)*8) - m_currentVectorBitSize));
    3.72 +    m_totalBitSize += numberOfBits;
    3.73 +  }
    3.74 +  else
    3.75 +  {
    3.76 +    // Shift over the newbits by the
    3.77 +    // number of current bits.  This allows 
    3.78 +    // us to logically OR with the present 
    3.79 +    // NixVector, resulting in the new 
    3.80 +    // NixVector
    3.81 +    newBits = newBits << m_currentVectorBitSize;
    3.82 +    newBits |= m_nixVector.back();
    3.83 +  
    3.84 +    // Now insert the new NixVector and 
    3.85 +    // increment number of bits for
    3.86 +    // m_currentVectorBitSize and m_totalBitSize
    3.87 +    // accordingly 
    3.88 +    m_nixVector.back() = newBits;
    3.89 +    m_currentVectorBitSize += numberOfBits;
    3.90 +    m_totalBitSize += numberOfBits;
    3.91 +  }
    3.92 +}
    3.93 +
    3.94 +uint32_t
    3.95 +NixVector::ExtractNeighborIndex(uint32_t numberOfBits)
    3.96 +{
    3.97 +  uint32_t vectorIndex = 0;
    3.98 +  uint32_t extractedBits = 0;
    3.99 +  uint32_t totalRemainingBits = RemainingBits();
   3.100 +  uint32_t sizeOfInt = SizeOfInt();
   3.101 +
   3.102 +  if (numberOfBits > totalRemainingBits)
   3.103 +  {
   3.104 +    std::cout << "You've tried to extract too many bits of the Nix-vector." << std::endl;
   3.105 +    exit(1);
   3.106 +  }
   3.107 +
   3.108 +  if (numberOfBits <= 0)
   3.109 +  {
   3.110 +    std::cout << "You've specified a number of bits for Nix-vector <= 0!" << std::endl;
   3.111 +    exit(1);
   3.112 +  }
   3.113 +
   3.114 +  //std::cout << "m_totalBitSize: " << m_totalBitSize << std::endl;
   3.115 +
   3.116 +  // First determine where in the NixVector 
   3.117 +  // vector we need to extract which depends
   3.118 +  // on the number of used bits and the total
   3.119 +  // number of bits
   3.120 +  vectorIndex = ((totalRemainingBits-1) / sizeOfInt );
   3.121 +
   3.122 +  //std::cout << "Vector Index: " << vectorIndex << std::endl;
   3.123 +  //std::cout << "totalRemainingBits: " << totalRemainingBits << std::endl;
   3.124 +  //std::cout << "totalRemainingBits mod 32: " << totalRemainingBits % sizeOfInt << std::endl;
   3.125 +
   3.126 +  // Next, determine if this extraction will
   3.127 +  // span multiple vector entries
   3.128 +  if (vectorIndex > 0) // we could span more than one
   3.129 +  {
   3.130 +    if (numberOfBits > (totalRemainingBits % sizeOfInt)) // we do span more than one
   3.131 +    {
   3.132 +
   3.133 +      extractedBits = m_nixVector.at(vectorIndex) << (sizeOfInt - (totalRemainingBits % sizeOfInt));
   3.134 +      extractedBits = extractedBits >> ((sizeOfInt - (totalRemainingBits % sizeOfInt)) - (numberOfBits - (totalRemainingBits % sizeOfInt)));
   3.135 +
   3.136 +      //std::cout << "Spanning more than one vector entry" << std::endl;
   3.137 +      //std::cout << "First Shift Gives: " << extractedBits << std::endl;
   3.138 +      //std::cout << "Shift Up By: " << (sizeOfInt - (totalRemainingBits % sizeOfInt)) << std::endl;
   3.139 +      //std::cout << "Shift Down By: " << ((sizeOfInt - (totalRemainingBits % sizeOfInt)) - (numberOfBits - (totalRemainingBits % sizeOfInt))) << std::endl;
   3.140 +      extractedBits |= (m_nixVector.at(vectorIndex-1) >> (sizeOfInt - (numberOfBits - (totalRemainingBits % sizeOfInt))));
   3.141 +      m_used += numberOfBits;
   3.142 +
   3.143 +      return extractedBits;
   3.144 +    }
   3.145 +  }
   3.146 +
   3.147 +  // we don't span more than one
   3.148 +  
   3.149 +  extractedBits = m_nixVector.at(vectorIndex) << (sizeOfInt - (totalRemainingBits % sizeOfInt));
   3.150 +
   3.151 +  //std::cout << "First Shift Gives: " << extractedBits << std::endl;
   3.152 +  //std::cout << "Shift Up By: " << (sizeOfInt - (totalRemainingBits % sizeOfInt)) << std::endl;
   3.153 +  //std::cout << "Shift Down By: " << sizeOfInt - ((numberOfBits - (totalRemainingBits % sizeOfInt))+1) << std::endl;
   3.154 +
   3.155 +  extractedBits = extractedBits >> (sizeOfInt - (numberOfBits));
   3.156 +  m_used += numberOfBits;
   3.157 +
   3.158 +  return extractedBits;
   3.159 +
   3.160 +}
   3.161 +
   3.162 +void
   3.163 +NixVector::DumpNixVector()
   3.164 +{
   3.165 +  uint32_t i = m_nixVector.size();
   3.166 +  std::vector<uint32_t>::iterator iter = m_nixVector.end();
   3.167 +  do
   3.168 +  {
   3.169 +    iter--;
   3.170 +    
   3.171 +    // all this work just to get the nix 
   3.172 +    // vector to print out neat
   3.173 +    if (m_totalBitSize > ((sizeof(uint32_t)*8) * i))
   3.174 +      PrintDec2BinNix(*iter,BitCount(*iter));
   3.175 +    else
   3.176 +      PrintDec2BinNixFill(*iter,m_totalBitSize%32);
   3.177 +
   3.178 +    i--;
   3.179 +
   3.180 +    if (iter != m_nixVector.begin())
   3.181 +      std::cout << "--";
   3.182 +
   3.183 +  } while(iter != m_nixVector.begin());
   3.184 +
   3.185 +  std::cout << std::endl;
   3.186 +}
   3.187 +
   3.188 +uint32_t 
   3.189 +NixVector::RemainingBits()
   3.190 +{
   3.191 +  return (m_totalBitSize - m_used);
   3.192 +}
   3.193 +
   3.194 +uint32_t
   3.195 +NixVector::SizeOfInt()
   3.196 +{
   3.197 +  return (sizeof(uint32_t) * 8);
   3.198 +}
   3.199 +
   3.200 +uint32_t
   3.201 +NixVector::BitCount(uint32_t numberOfNeighbors)
   3.202 +{
   3.203 +  // Given the numberOfNeighbors, return the number 
   3.204 +  // of bits needed (essentailly, log2(numberOfNeighbors)
   3.205 +  uint32_t bitCount = 0;
   3.206 +  
   3.207 +  if (numberOfNeighbors < 2) 
   3.208 +    return 1;
   3.209 +  else
   3.210 +  {
   3.211 +    for (; numberOfNeighbors != 0; numberOfNeighbors >>= 1)
   3.212 +      bitCount++;
   3.213 +
   3.214 +    return bitCount;
   3.215 +  }
   3.216 +}
   3.217 +
   3.218 +void
   3.219 +NixVector::PrintDec2BinNixFill (uint32_t decimalNum, uint32_t bitCount)
   3.220 +{
   3.221 +  if(decimalNum == 0)
   3.222 +  {
   3.223 +    std::cout << 0;
   3.224 +    return;
   3.225 +  }
   3.226 +  if(decimalNum == 1)
   3.227 +  {
   3.228 +    for (; bitCount > 1; bitCount--)
   3.229 +      std::cout << 0;
   3.230 +
   3.231 +    std::cout << 1;
   3.232 +  }
   3.233 +  else
   3.234 +  {
   3.235 +    PrintDec2BinNixFill(decimalNum / 2,bitCount-1);
   3.236 +    std::cout << decimalNum % 2;
   3.237 +  }
   3.238 +}
   3.239 +
   3.240 +void
   3.241 +NixVector::PrintDec2BinNix (uint32_t decimalNum, uint32_t bitCount)
   3.242 +{
   3.243 +  if(decimalNum == 0)
   3.244 +  {
   3.245 +    std::cout << 0;
   3.246 +    return;
   3.247 +  }
   3.248 +  if(decimalNum == 1)
   3.249 +  {
   3.250 +    // check to see if we need to 
   3.251 +    // print out some zeros at the 
   3.252 +    // beginning of the nix vector
   3.253 +    if ((uint32_t)(sizeof(uint32_t)*8) > bitCount)
   3.254 +    {
   3.255 +      for (uint32_t i = ((sizeof(uint32_t)*8)-bitCount); i > 0; i--)
   3.256 +        std::cout << 0;
   3.257 +    }
   3.258 +
   3.259 +    std::cout << 1;
   3.260 +  }
   3.261 +  else
   3.262 +  {
   3.263 +    PrintDec2BinNix(decimalNum / 2, bitCount);
   3.264 +    std::cout << decimalNum % 2;
   3.265 +  }
   3.266 +}
   3.267 +} // namespace ns3
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/routing/nix-vector-routing/nix-vector.h	Thu Jun 04 09:32:03 2009 -0400
     4.3 @@ -0,0 +1,62 @@
     4.4 +/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
     4.5 +/*
     4.6 + * Copyright (c) 2009 The Georgia Institute of Technology 
     4.7 + *
     4.8 + * This program is free software; you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License version 2 as
    4.10 + * published by the Free Software Foundation;
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU General Public License for more details.
    4.16 + *
    4.17 + * You should have received a copy of the GNU General Public License
    4.18 + * along with this program; if not, write to the Free Software
    4.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.20 + *
    4.21 + * Authors: Josh Pelkey <jpelkey@gatech.edu>
    4.22 + */
    4.23 +
    4.24 +#ifndef __NIX_VECTOR_H__
    4.25 +#define __NIX_VECTOR_H__
    4.26 +
    4.27 +#include <vector>
    4.28 +
    4.29 +namespace ns3 {
    4.30 +
    4.31 +typedef std::vector<uint32_t> NixBits_t;
    4.32 +
    4.33 +class NixVector
    4.34 +{
    4.35 +  public:
    4.36 +    NixVector();
    4.37 +    ~NixVector();
    4.38 +    void AddNeighborIndex(uint32_t);
    4.39 +    uint32_t ExtractNeighborIndex(uint32_t);
    4.40 +    void DumpNixVector();
    4.41 +
    4.42 +  private:
    4.43 +    NixBits_t m_nixVector;
    4.44 +    uint32_t RemainingBits();
    4.45 +    uint32_t SizeOfInt();
    4.46 +    uint32_t m_used;                   // for tracking where we are in 
    4.47 +                                           // the nix vector
    4.48 +                                  
    4.49 +    uint32_t m_currentVectorBitSize;   // for tracking how many bits we 
    4.50 +                                           // have used in the current vector
    4.51 +                                           // entry.  need this in order to 
    4.52 +                                           // expand the nix vector passed 32 bits
    4.53 +    uint32_t m_totalBitSize;
    4.54 +
    4.55 +    uint32_t BitCount(uint32_t);
    4.56 +    void PrintDec2BinNixFill(uint32_t, uint32_t);
    4.57 +    void PrintDec2BinNix(uint32_t, uint32_t);
    4.58 +
    4.59 +
    4.60 +};
    4.61 +
    4.62 +
    4.63 +} // namespace ns3
    4.64 +
    4.65 +#endif
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/routing/nix-vector-routing/waf	Thu Jun 04 09:32:03 2009 -0400
     5.3 @@ -0,0 +1,1 @@
     5.4 +exec "`dirname "$0"`"/../../../waf "$@"
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/routing/nix-vector-routing/wscript	Thu Jun 04 09:32:03 2009 -0400
     6.3 @@ -0,0 +1,17 @@
     6.4 +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
     6.5 +
     6.6 +def build(bld):
     6.7 +    module = bld.create_ns3_module('nix-vector-routing', ['node'])
     6.8 +    module.includes = '.'
     6.9 +    module.source = [
    6.10 +        'nix-vector.cc',
    6.11 +        'nix-vector-routing.cc',
    6.12 +        ]
    6.13 +
    6.14 +    headers = bld.new_task_gen('ns3header')
    6.15 +    headers.module = 'nix-vector-routing'
    6.16 +    headers.source = [
    6.17 +        'nix-vector.h',
    6.18 +        'nix-vector-routing.h',
    6.19 +        ]
    6.20 +
     7.1 --- a/src/wscript	Wed Jun 03 13:19:06 2009 +0200
     7.2 +++ b/src/wscript	Thu Jun 04 09:32:03 2009 -0400
     7.3 @@ -26,6 +26,7 @@
     7.4      'applications/onoff',
     7.5      'applications/packet-sink',
     7.6      'applications/udp-echo',
     7.7 +    'routing/nix-vector-routing',
     7.8      'routing/olsr',
     7.9      'routing/global-routing',
    7.10      'mobility',