apply quagga patchset to frederic's repo
authorHajime Tazaki <tazaki@nict.go.jp>
Thu, 21 Jun 2012 17:26:37 +0900
changeset 237f0e375f8523
parent 22 ed0d8cc18421
child 24 02787e1dfd96
apply quagga patchset to frederic's repo
120406-dce-quagga-support.patch
series
     1.1 --- a/120406-dce-quagga-support.patch	Sat Jun 02 00:29:00 2012 +0900
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1670 +0,0 @@
     1.4 -support ns-3-dce-quagga
     1.5 -
     1.6 -diff -r 071d721c2713 example/dce-zebra-simple.cc
     1.7 ---- a/example/dce-zebra-simple.cc	Wed May 30 10:21:32 2012 +0200
     1.8 -+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.9 -@@ -1,114 +0,0 @@
    1.10 --/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    1.11 --/*
    1.12 -- * Copyright (c) 2011 UCLA
    1.13 -- *
    1.14 -- * This program is free software; you can redistribute it and/or modify
    1.15 -- * it under the terms of the GNU General Public License version 2 as
    1.16 -- * published by the Free Software Foundation;
    1.17 -- *
    1.18 -- * This program is distributed in the hope that it will be useful,
    1.19 -- * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.20 -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.21 -- * GNU General Public License for more details.
    1.22 -- *
    1.23 -- * You should have received a copy of the GNU General Public License
    1.24 -- * along with this program; if not, write to the Free Software
    1.25 -- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.26 -- *
    1.27 -- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
    1.28 -- */
    1.29 --
    1.30 --#include "ns3/network-module.h"
    1.31 --#include "ns3/core-module.h"
    1.32 --#include "ns3/internet-module.h"
    1.33 --#include "ns3/ipv4-global-routing-helper.h"
    1.34 --#include "ns3/dce-module.h"
    1.35 --#include "ns3/quagga-helper.h"
    1.36 --#include "ns3/point-to-point-grid.h"
    1.37 --#include "../helper/ipv4-dce-routing-helper.h"
    1.38 --
    1.39 --using namespace ns3;
    1.40 --
    1.41 --NS_LOG_COMPONENT_DEFINE ("quagga");
    1.42 --
    1.43 --void
    1.44 --procExit (std::string path, uint16_t pid, int retcode)
    1.45 --{
    1.46 --  std::cout << "Process exit path=" << path << " pid=" << pid << " retcode=" << retcode << std::endl;
    1.47 --}
    1.48 --
    1.49 --// Parameters
    1.50 --uint32_t nNodes = 2;
    1.51 --uint32_t stopTime = 60;
    1.52 --std::string netStack = "ns3";
    1.53 --
    1.54 --void TestDisable (Ptr<Node> node)
    1.55 --{
    1.56 --  NS_LOG_FUNCTION (node->GetId ());
    1.57 --  
    1.58 --  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
    1.59 --  NS_ASSERT_MSG (ipv4 != 0, "ipv4 should not be null");
    1.60 --
    1.61 --  // The thing I didn't know is that interface status (isUp/isDown) and device status (isLinkUp) are two totally different things.  It is possible to set interface up and down, but there is not an easy way to alter status of device. This similar to reality: it is possible to programmatically disable interface, but to actually disable a link one needs to physically cut the cable
    1.62 --  ipv4->SetDown (2);
    1.63 --}
    1.64 --
    1.65 --int main (int argc, char *argv[])
    1.66 --{
    1.67 --  CommandLine cmd;
    1.68 --  cmd.AddValue ("nNodes", "Number of Router nodes", nNodes);
    1.69 --  cmd.AddValue ("stopTime", "Time to stop(seconds)", stopTime);
    1.70 --  cmd.AddValue ("netStack", "What network stack", netStack);
    1.71 --  cmd.Parse (argc, argv);
    1.72 --
    1.73 --  PointToPointHelper p2p;
    1.74 --  InternetStackHelper stack;
    1.75 --  Ipv4DceRoutingHelper ipv4RoutingHelper;
    1.76 --  
    1.77 --  stack.SetRoutingHelper (ipv4RoutingHelper);
    1.78 --
    1.79 --  PointToPointGridHelper grid (nNodes, nNodes, p2p);
    1.80 --  grid.InstallStack (stack);
    1.81 --
    1.82 --  grid.AssignIpv4Addresses (
    1.83 --                            Ipv4AddressHelper("10.1.0.0", "255.255.255.0"),
    1.84 --                            Ipv4AddressHelper("10.2.0.0", "255.255.255.0")
    1.85 --                            );
    1.86 --
    1.87 --  Ptr<DceManagerHelper> dceManager = CreateObject<DceManagerHelper> ();
    1.88 --  dceManager->SetNetworkStack("ns3::Ns3SocketFdFactory");
    1.89 --
    1.90 --  QuaggaHelper quagga;
    1.91 --  
    1.92 --  ApplicationContainer apps;
    1.93 --
    1.94 --  for (int i=0; i<nNodes; i++)
    1.95 --    for (int j=0; j<nNodes; j++)
    1.96 --      {
    1.97 --        Ptr<Node> node = grid.GetNode (i,j);
    1.98 --        dceManager->Install (node);
    1.99 --        quagga.EnableOspf (node);
   1.100 --        quagga.EnableOspfDebug (node);
   1.101 --        quagga.EnableZebraDebug (node);
   1.102 --        apps.Add (quagga.Install (node));
   1.103 --      }
   1.104 --
   1.105 --  apps.Stop (Seconds(150.0));
   1.106 --
   1.107 --  Simulator::ScheduleWithContext (grid.GetNode (0,0)->GetId (),
   1.108 --                                  Seconds (80.0), TestDisable, grid.GetNode (0,0));
   1.109 --
   1.110 --  Config::Connect ("/NodeList/*/$ns3::DceManager/Exit", MakeCallback (&procExit));
   1.111 --
   1.112 --  // Trace routing tables 
   1.113 --  Ptr<OutputStreamWrapper> routingStream = Create<OutputStreamWrapper> ("routes.log", std::ios::out);
   1.114 --  ipv4RoutingHelper.PrintRoutingTableAllEvery (Seconds (10), routingStream);
   1.115 --
   1.116 --  Simulator::Stop (Seconds(160.0));
   1.117 --  Simulator::Run ();
   1.118 --  Simulator::Destroy ();
   1.119 --
   1.120 --  NS_LOG_INFO ("End of experiment");
   1.121 --
   1.122 --  return 0;
   1.123 --}
   1.124 -diff -r 071d721c2713 helper/quagga-helper.cc
   1.125 ---- a/helper/quagga-helper.cc	Wed May 30 10:21:32 2012 +0200
   1.126 -+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   1.127 -@@ -1,596 +0,0 @@
   1.128 --/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
   1.129 --/*
   1.130 -- * Copyright (c) 2010 Hajime Tazaki
   1.131 -- *
   1.132 -- * This program is free software; you can redistribute it and/or modify
   1.133 -- * it under the terms of the GNU General Public License version 2 as
   1.134 -- * published by the Free Software Foundation;
   1.135 -- *
   1.136 -- * This program is distributed in the hope that it will be useful,
   1.137 -- * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.138 -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.139 -- * GNU General Public License for more details.
   1.140 -- *
   1.141 -- * You should have received a copy of the GNU General Public License
   1.142 -- * along with this program; if not, write to the Free Software
   1.143 -- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   1.144 -- *
   1.145 -- * Author: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   1.146 -- */
   1.147 --
   1.148 --#include "ns3/object-factory.h"
   1.149 --#include "quagga-helper.h"
   1.150 --#include "ns3/names.h"
   1.151 --#include "ns3/ipv4-l3-protocol.h"
   1.152 --//#include "ns3/utils.h"
   1.153 --#include <fstream>
   1.154 --#include <map>
   1.155 --#include <sys/stat.h>
   1.156 --#include "ns3/log.h"
   1.157 --
   1.158 --NS_LOG_COMPONENT_DEFINE ("QuaggaHelper");
   1.159 --
   1.160 --namespace ns3 {
   1.161 --
   1.162 --class QuaggaConfig: public Object
   1.163 --{
   1.164 --private:
   1.165 --  static int index;
   1.166 --  std::string router_id;
   1.167 --  std::map<std::string, uint32_t> *networks;
   1.168 --public:
   1.169 --  QuaggaConfig ()
   1.170 --    : m_tdpenable (false),
   1.171 --      m_zebradebug (false),
   1.172 --      m_usemanualconf (false)
   1.173 --  {
   1.174 --    m_radvd_if = new std::vector<std::string> ();
   1.175 --    m_egress_if = new std::vector<std::string> ();
   1.176 --    m_haflag_if = new std::vector<std::string> ();
   1.177 --  }
   1.178 --  virtual ~QuaggaConfig ()
   1.179 --  {
   1.180 --  }
   1.181 --
   1.182 --  static TypeId 
   1.183 --  GetTypeId (void)
   1.184 --  {
   1.185 --    static TypeId tid = TypeId ("ns3::QuaggaConfig")
   1.186 --      .SetParent<Object> ()
   1.187 --      .AddConstructor<QuaggaConfig> ()
   1.188 --      ;
   1.189 --    return tid;
   1.190 --  }
   1.191 --  TypeId 
   1.192 --  GetInstanceTypeId (void) const
   1.193 --  {
   1.194 --    return GetTypeId ();
   1.195 --  }
   1.196 --
   1.197 --  void
   1.198 --  SetFilename (const std::string &filename)
   1.199 --  {
   1.200 --    m_filename = filename;
   1.201 --  }
   1.202 --  
   1.203 --  std::string
   1.204 --  GetFilename () const 
   1.205 --  {
   1.206 --    return m_filename;
   1.207 --  }
   1.208 --
   1.209 --  bool m_tdpenable;
   1.210 --  bool m_zebradebug;
   1.211 --  bool m_usemanualconf;
   1.212 --  std::vector<std::string> *m_radvd_if;
   1.213 --  std::vector<std::string> *m_egress_if;
   1.214 --  std::vector<std::string> *m_haflag_if;
   1.215 --
   1.216 --  std::string m_filename;
   1.217 --
   1.218 --  std::vector<uint32_t> iflist;
   1.219 --
   1.220 --  virtual void
   1.221 --  Print (std::ostream& os) const
   1.222 --  {
   1.223 --    os << "hostname zebra" << std::endl
   1.224 --       << "password zebra" << std::endl
   1.225 --       << "log stdout" << std::endl;
   1.226 --  }
   1.227 --};
   1.228 --std::ostream& operator << (std::ostream& os, QuaggaConfig const& config)
   1.229 --{
   1.230 --  config.Print (os);
   1.231 --  return os;
   1.232 --}
   1.233 --
   1.234 --class OspfConfig : public Object
   1.235 --{
   1.236 --private:
   1.237 --  std::map<std::string, uint32_t> *networks;
   1.238 --public:
   1.239 --  OspfConfig ()
   1.240 --    : m_ospfdebug (false)
   1.241 --  {
   1.242 --    networks = new std::map<std::string, uint32_t> ();
   1.243 --    iflist = new std::vector<uint32_t> ();
   1.244 --  }
   1.245 --  ~OspfConfig ()
   1.246 --  {
   1.247 --    delete networks;
   1.248 --    delete iflist;
   1.249 --  }
   1.250 --
   1.251 --  bool m_ospfdebug;
   1.252 --
   1.253 --  static TypeId 
   1.254 --  GetTypeId (void)
   1.255 --  {
   1.256 --    static TypeId tid = TypeId ("ns3::OspfConfig")
   1.257 --      .SetParent<Object> ()
   1.258 --      .AddConstructor<OspfConfig> ()
   1.259 --      ;
   1.260 --    return tid;
   1.261 --  }
   1.262 --  TypeId 
   1.263 --  GetInstanceTypeId (void) const
   1.264 --  {
   1.265 --    return GetTypeId ();
   1.266 --  }
   1.267 --
   1.268 --  void
   1.269 --  addNetwork (Ipv4Address prefix, uint32_t plen, uint32_t area)
   1.270 --  {
   1.271 --    std::stringstream net;
   1.272 --    net << prefix << "/" << plen;
   1.273 --    networks->insert (std::map<std::string, uint32_t>::value_type (net.str (), area));
   1.274 --  }
   1.275 --
   1.276 --  void
   1.277 --  SetFilename (const std::string &filename)
   1.278 --  {
   1.279 --    m_filename = filename;
   1.280 --  }
   1.281 --  
   1.282 --  std::string
   1.283 --  GetFilename () const 
   1.284 --  {
   1.285 --    return m_filename;
   1.286 --  }
   1.287 --
   1.288 --  virtual void
   1.289 --  Print (std::ostream& os) const
   1.290 --  {
   1.291 --    os << "hostname zebra" << std::endl
   1.292 --       << "password zebra" << std::endl
   1.293 --       << "log stdout" << std::endl;
   1.294 --    if (m_ospfdebug)
   1.295 --      {
   1.296 --        //os << "log trap errors" << std::endl;
   1.297 --        os << "debug ospf event " << std::endl;
   1.298 --        os << "debug ospf nsm " << std::endl;
   1.299 --        os << "debug ospf ism " << std::endl;
   1.300 --        os << "debug ospf packet all " << std::endl;
   1.301 --      }
   1.302 --
   1.303 --    for (std::vector<uint32_t>::iterator i = iflist->begin (); 
   1.304 --         i != iflist->end (); ++i)
   1.305 --      {
   1.306 --        os << "interface ns3-device" << (*i) << std::endl;
   1.307 --      }
   1.308 --
   1.309 --    os << "router ospf " << std::endl; 
   1.310 --    //    os << "  ospf router-id " << m_routerId << std::endl;
   1.311 --    for (std::map<std::string, uint32_t>::iterator i = networks->begin (); 
   1.312 --         i != networks->end (); ++i)
   1.313 --      {
   1.314 --        os << "  network " << (*i).first << " area " << (*i).second << std::endl;
   1.315 --      }
   1.316 --    os << "!" << std::endl;
   1.317 --  }
   1.318 --  std::vector<uint32_t> *iflist;
   1.319 --  std::string m_filename;
   1.320 --  uint32_t m_routerId;
   1.321 --};
   1.322 --
   1.323 --
   1.324 --QuaggaHelper::QuaggaHelper ()
   1.325 --{
   1.326 --}
   1.327 --
   1.328 --void 
   1.329 --QuaggaHelper::SetAttribute (std::string name, const AttributeValue &value)
   1.330 --{
   1.331 --}
   1.332 --
   1.333 --// OSPF
   1.334 --void
   1.335 --QuaggaHelper::EnableOspf (NodeContainer nodes)
   1.336 --{
   1.337 --  //  for (uint32_t i = 0; i < nodes.GetN (); i++)
   1.338 --  for (uint32_t i = 0; i < nodes.GetN (); i ++)
   1.339 --    {
   1.340 --      Ptr<OspfConfig> ospf_conf = CreateObject<OspfConfig> ();
   1.341 --      nodes.Get (i)->AggregateObject (ospf_conf);
   1.342 --
   1.343 --      for (uint32_t j = 0; j < nodes.Get (i)->GetNDevices (); j ++)
   1.344 --        {
   1.345 --          // Use primary address, if multiple
   1.346 --          //      Ipv4Address addr = interfaces->GetAddress (i, 0).GetLocal ();
   1.347 --          // uint32_t ifindex = interfaces.Get (i).second;
   1.348 --          // g_ospf_conf->iflist->insert (std::map<Ptr<Node>, uint32_t>::value_type (nodes.Get (i), ifindex));
   1.349 --        }
   1.350 --    }
   1.351 --
   1.352 --  return;
   1.353 --}
   1.354 --
   1.355 --void
   1.356 --QuaggaHelper::EnableOspfDebug (NodeContainer nodes)
   1.357 --{
   1.358 --  for (uint32_t i = 0; i < nodes.GetN (); i ++)
   1.359 --    {
   1.360 --      Ptr<OspfConfig> ospf_conf = nodes.Get (i)->GetObject<OspfConfig>();
   1.361 --      if (!ospf_conf)
   1.362 --        {
   1.363 --          ospf_conf = new OspfConfig ();
   1.364 --          nodes.Get (i)->AggregateObject (ospf_conf);
   1.365 --        }
   1.366 --      ospf_conf->m_ospfdebug = true;
   1.367 --    }
   1.368 --  return;
   1.369 --}
   1.370 --
   1.371 --void
   1.372 --QuaggaHelper::EnableTdpNina (NodeContainer nodes)
   1.373 --{
   1.374 --  for (uint32_t i = 0; i < nodes.GetN (); i ++)
   1.375 --    {
   1.376 --      Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig>();
   1.377 --      if (!zebra_conf)
   1.378 --        {
   1.379 --          zebra_conf = new QuaggaConfig ();
   1.380 --          nodes.Get (i)->AggregateObject (zebra_conf);
   1.381 --        }
   1.382 --      zebra_conf->m_tdpenable = true;
   1.383 --    }
   1.384 --  return;
   1.385 --}
   1.386 --
   1.387 --void
   1.388 --QuaggaHelper::EnableZebraDebug (NodeContainer nodes)
   1.389 --{
   1.390 --  for (uint32_t i = 0; i < nodes.GetN (); i ++)
   1.391 --    {
   1.392 --      Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig>();
   1.393 --      if (!zebra_conf)
   1.394 --        {
   1.395 --          zebra_conf = new QuaggaConfig ();
   1.396 --          nodes.Get (i)->AggregateObject (zebra_conf);
   1.397 --        }
   1.398 --      zebra_conf->m_zebradebug = true;
   1.399 --    }
   1.400 --  return;
   1.401 --}
   1.402 --
   1.403 --void
   1.404 --QuaggaHelper::EnableRadvd (Ptr<Node> node, const char *ifname)
   1.405 --{
   1.406 --  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>();
   1.407 --  if (!zebra_conf)
   1.408 --    {
   1.409 --      zebra_conf = new QuaggaConfig ();
   1.410 --      node->AggregateObject (zebra_conf);
   1.411 --    }
   1.412 --
   1.413 --  zebra_conf->m_radvd_if->push_back (std::string(ifname));
   1.414 --
   1.415 --  return;
   1.416 --}
   1.417 --
   1.418 --void
   1.419 --QuaggaHelper::EnableEgressIF (Ptr<Node> node, const char *ifname)
   1.420 --{
   1.421 --  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>();
   1.422 --  if (!zebra_conf)
   1.423 --    {
   1.424 --      zebra_conf = new QuaggaConfig ();
   1.425 --      node->AggregateObject (zebra_conf);
   1.426 --    }
   1.427 --
   1.428 --  zebra_conf->m_egress_if->push_back (std::string(ifname));
   1.429 --
   1.430 --  return;
   1.431 --}
   1.432 --
   1.433 --void
   1.434 --QuaggaHelper::EnableHomeAgentFlag (Ptr<Node> node, const char *ifname)
   1.435 --{
   1.436 --  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>();
   1.437 --  if (!zebra_conf)
   1.438 --    {
   1.439 --      zebra_conf = new QuaggaConfig ();
   1.440 --      node->AggregateObject (zebra_conf);
   1.441 --    }
   1.442 --
   1.443 --  zebra_conf->m_haflag_if->push_back (std::string(ifname));
   1.444 --
   1.445 --  return;
   1.446 --}
   1.447 --
   1.448 --void
   1.449 --QuaggaHelper::UseManualConfig (NodeContainer nodes)
   1.450 --{
   1.451 --  for (uint32_t i = 0; i < nodes.GetN (); i ++)
   1.452 --    {
   1.453 --      Ptr<QuaggaConfig> zebra_conf = nodes.Get (i)->GetObject<QuaggaConfig>();
   1.454 --      if (!zebra_conf)
   1.455 --        {
   1.456 --          zebra_conf = new QuaggaConfig ();
   1.457 --          nodes.Get (i)->AggregateObject (zebra_conf);
   1.458 --        }
   1.459 --      zebra_conf->m_usemanualconf = true;
   1.460 --    }
   1.461 --  return;
   1.462 --}
   1.463 --
   1.464 --
   1.465 --void
   1.466 --QuaggaHelper::GenerateConfigZebra (Ptr<Node> node)
   1.467 --{
   1.468 --  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>();
   1.469 --  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
   1.470 --
   1.471 --  if (zebra_conf->m_usemanualconf)
   1.472 --    {
   1.473 --      return;
   1.474 --    }
   1.475 --
   1.476 --  NS_LOG_DEBUG ("ipv4->GetNInterfaces () = " << ipv4->GetNInterfaces ());
   1.477 --
   1.478 --//   for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
   1.479 --//     {
   1.480 --//       Ipv4Address addr = ipv4->GetAddress (i, 0).GetLocal ();
   1.481 --//       Ipv4Mask mask = ipv4->GetAddress (i, 0).GetMask ();
   1.482 --//       Ipv4Address prefix = addr.CombineMask (mask);
   1.483 --// 
   1.484 --//       NS_LOG_DEBUG ("address: " << addr);
   1.485 --// 
   1.486 --//       if (addr.IsEqual (Ipv4Address::GetLoopback()))
   1.487 --//         {
   1.488 --//           continue;
   1.489 --//         }
   1.490 --//       
   1.491 --//       zebra_conf->iflist.push_back (i);
   1.492 --//     }
   1.493 --
   1.494 --  // config generation
   1.495 --  std::stringstream conf_dir, conf_file;
   1.496 --  // FIXME XXX
   1.497 --  conf_dir << "files-" << node->GetId () << "";
   1.498 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.499 --  conf_dir << "/usr/";
   1.500 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.501 --  conf_dir << "/local/";
   1.502 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.503 --  conf_dir << "/etc/";
   1.504 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.505 --
   1.506 --  conf_file << conf_dir.str() << "/zebra.conf";
   1.507 --  zebra_conf->SetFilename ("/usr/local/etc/zebra.conf");
   1.508 --
   1.509 --  std::ofstream conf;
   1.510 --  conf.open (conf_file.str ().c_str ());
   1.511 --  conf << *zebra_conf;
   1.512 --  if (zebra_conf->m_zebradebug)
   1.513 --    {
   1.514 --      conf << "debug zebra kernel" << std::endl;
   1.515 --      conf << "debug zebra events" << std::endl;
   1.516 --      // conf << "debug zebra route" << std::endl;
   1.517 --      conf << "debug zebra packet" << std::endl;
   1.518 --    }
   1.519 --
   1.520 --  // radvd
   1.521 --  for (std::vector<std::string>::iterator i = zebra_conf->m_radvd_if->begin (); 
   1.522 --       i != zebra_conf->m_radvd_if->end (); ++i)
   1.523 --    {
   1.524 --      conf << "interface " << (*i) << std::endl;
   1.525 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.526 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.527 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.528 --      conf << "!" << std::endl;
   1.529 --    }
   1.530 --
   1.531 --  // ha flag
   1.532 --  for (std::vector<std::string>::iterator i = zebra_conf->m_haflag_if->begin (); 
   1.533 --       i != zebra_conf->m_haflag_if->end (); ++i)
   1.534 --    {
   1.535 --      conf << "interface " << (*i) << std::endl;
   1.536 --      conf << " ipv6 nd home-agent-config-flag" << std::endl;
   1.537 --      conf << "!" << std::endl;
   1.538 --    }
   1.539 --
   1.540 --  // egress IF
   1.541 --  for (std::vector<std::string>::iterator i = zebra_conf->m_egress_if->begin (); 
   1.542 --       i != zebra_conf->m_egress_if->end (); ++i)
   1.543 --    {
   1.544 --      conf << "interface " << (*i) << std::endl;
   1.545 --      conf << " ipv6 nd td egress" << std::endl;
   1.546 --      conf << "!" << std::endl;
   1.547 --    }
   1.548 --
   1.549 --  for (std::vector<uint32_t>::iterator i = zebra_conf->iflist.begin ();
   1.550 --       i != zebra_conf->iflist.end ();
   1.551 --       i++)
   1.552 --    {
   1.553 --      conf << "interface eth" << *i << std::endl;
   1.554 --    }
   1.555 --
   1.556 --#if 0
   1.557 --  if (zebra_conf->m_tdpenable)
   1.558 --    {
   1.559 --      conf << "interface sim0" << std::endl;
   1.560 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.561 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.562 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.563 --      conf << " ipv6 nd home-agent-config-flag" << std::endl;
   1.564 --      conf << "!" << std::endl;
   1.565 --
   1.566 --      conf << "interface sim1" << std::endl;
   1.567 --      //      conf << " ipv6 nd td ingress" << std::endl;
   1.568 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.569 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.570 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.571 --      conf << " ipv6 nd home-agent-config-flag" << std::endl;
   1.572 --      conf << "!" << std::endl;
   1.573 --
   1.574 --      conf << "interface sim2" << std::endl;
   1.575 --      //      conf << " ipv6 nd td ingress" << std::endl;
   1.576 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.577 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.578 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.579 --      conf << " ipv6 nd home-agent-config-flag" << std::endl;
   1.580 --      conf << "!" << std::endl;
   1.581 --
   1.582 --      conf << "interface sim3" << std::endl;
   1.583 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.584 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.585 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.586 --      conf << " ipv6 nd home-agent-config-flag" << std::endl;
   1.587 --      conf << "!" << std::endl;
   1.588 --
   1.589 --      conf << "interface sim4" << std::endl;
   1.590 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.591 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.592 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.593 --      conf << "!" << std::endl;
   1.594 --
   1.595 --      conf << "interface sim5" << std::endl;
   1.596 --      conf << " ipv6 nd ra-interval 5" << std::endl;
   1.597 --      conf << " ipv6 nd prefix-advertisement" << std::endl;
   1.598 --      conf << " no ipv6 nd suppress-ra" << std::endl;
   1.599 --      conf << "!" << std::endl;
   1.600 --    }
   1.601 --#endif
   1.602 --
   1.603 --  conf.close ();
   1.604 --
   1.605 --}
   1.606 --
   1.607 --void
   1.608 --QuaggaHelper::GenerateConfigOspf (Ptr<Node> node)
   1.609 --{
   1.610 --  NS_LOG_FUNCTION (node);
   1.611 --
   1.612 --  Ptr<OspfConfig> ospf_conf = node->GetObject<OspfConfig>();
   1.613 --  Ptr<Ipv4> ipv4 = node->GetObject<Ipv4> ();
   1.614 --  
   1.615 --  ospf_conf->m_routerId = 1+node->GetId ();
   1.616 --
   1.617 --  NS_LOG_DEBUG ("ipv4->GetNInterfaces () = " << ipv4->GetNInterfaces ());
   1.618 --
   1.619 --  for (uint32_t i = 0; i < ipv4->GetNInterfaces (); i ++)
   1.620 --    {
   1.621 --      Ipv4Address addr = ipv4->GetAddress (i, 0).GetLocal ();
   1.622 --      Ipv4Mask mask = ipv4->GetAddress (i, 0).GetMask ();
   1.623 --      Ipv4Address prefix = addr.CombineMask (mask);
   1.624 --      
   1.625 --      NS_LOG_DEBUG ("address: " << addr);
   1.626 --
   1.627 --      if (addr.IsEqual (Ipv4Address::GetLoopback()))
   1.628 --        {
   1.629 --          continue;
   1.630 --        }
   1.631 --
   1.632 --      ospf_conf->iflist->push_back (i);
   1.633 --      ospf_conf->addNetwork (prefix, mask.GetPrefixLength (), 0);
   1.634 --    }
   1.635 --
   1.636 --  // config generation
   1.637 --  std::stringstream conf_dir, conf_file;
   1.638 --  // FIXME XXX
   1.639 --  conf_dir << "files-" << node->GetId () << "";
   1.640 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.641 --  conf_dir << "/usr/";
   1.642 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.643 --  conf_dir << "/local/";
   1.644 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.645 --  conf_dir << "/etc/";
   1.646 --  ::mkdir (conf_dir.str ().c_str (), S_IRWXU | S_IRWXG);
   1.647 --
   1.648 --  conf_file << conf_dir.str() << "/ospfd.conf";
   1.649 --  ospf_conf->SetFilename ("/usr/local/etc/ospfd.conf");
   1.650 --
   1.651 --  std::ofstream conf;
   1.652 --  conf.open (conf_file.str ().c_str ());
   1.653 --  ospf_conf->Print (conf);
   1.654 --  conf.close ();
   1.655 --
   1.656 --}
   1.657 --
   1.658 --
   1.659 --ApplicationContainer
   1.660 --QuaggaHelper::Install (Ptr<Node> node)
   1.661 --{
   1.662 --  return ApplicationContainer (InstallPriv (node));
   1.663 --}
   1.664 --
   1.665 --ApplicationContainer
   1.666 --QuaggaHelper::Install (std::string nodeName)
   1.667 --{
   1.668 --  Ptr<Node> node = Names::Find<Node> (nodeName);
   1.669 --  return ApplicationContainer (InstallPriv (node));
   1.670 --}
   1.671 --
   1.672 --ApplicationContainer
   1.673 --QuaggaHelper::Install (NodeContainer c)
   1.674 --{
   1.675 --  ApplicationContainer apps;
   1.676 --  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); ++i)
   1.677 --    {
   1.678 --      apps.Add (InstallPriv (*i));
   1.679 --    }
   1.680 --
   1.681 --  return apps;
   1.682 --}
   1.683 --
   1.684 --ApplicationContainer
   1.685 --QuaggaHelper::InstallPriv (Ptr<Node> node) 
   1.686 --{
   1.687 --  DceApplicationHelper process;
   1.688 --  ApplicationContainer apps;
   1.689 --
   1.690 --  Ptr<QuaggaConfig> zebra_conf = node->GetObject<QuaggaConfig>();
   1.691 --  if (!zebra_conf)
   1.692 --    {
   1.693 --      zebra_conf = new QuaggaConfig ();
   1.694 --      node->AggregateObject (zebra_conf);
   1.695 --    }
   1.696 --  GenerateConfigZebra (node);
   1.697 --  process.SetBinary ("zebra");
   1.698 --  process.AddArguments ("-f", zebra_conf->GetFilename ());
   1.699 --  process.AddArguments ("-i", "/usr/local/etc/zebra.pid");
   1.700 --  process.SetStackSize (1<<16);
   1.701 --  apps.Add (process.Install (node));
   1.702 --  apps.Get(0)->SetStartTime (Seconds (1.0 + 0.01 * node->GetId ()));
   1.703 --  node->AddApplication (apps.Get (0));
   1.704 --
   1.705 --  Ptr<OspfConfig> ospf_conf = node->GetObject<OspfConfig>();
   1.706 --  // OSPF
   1.707 --  if (ospf_conf)
   1.708 --    {
   1.709 --      GenerateConfigOspf (node);
   1.710 --      process.ResetArguments ();
   1.711 --
   1.712 --      process.SetBinary ("ospfd");
   1.713 --      process.AddArguments ("-f", ospf_conf->GetFilename ());
   1.714 --      process.AddArguments ("-i", "/usr/local/etc/ospfd.pid");
   1.715 --      apps.Add (process.Install (node));
   1.716 --      apps.Get(1)->SetStartTime (Seconds (2.0 + 0.1 * node->GetId ()));
   1.717 --      node->AddApplication (apps.Get (1));
   1.718 --    }
   1.719 --
   1.720 --  return apps;
   1.721 --}
   1.722 --
   1.723 --} // namespace ns3
   1.724 -diff -r 071d721c2713 helper/quagga-helper.h
   1.725 ---- a/helper/quagga-helper.h	Wed May 30 10:21:32 2012 +0200
   1.726 -+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   1.727 -@@ -1,100 +0,0 @@
   1.728 --/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
   1.729 --/*
   1.730 -- * Copyright (c) 2010 Hajime Tazaki
   1.731 -- *
   1.732 -- * This program is free software; you can redistribute it and/or modify
   1.733 -- * it under the terms of the GNU General Public License version 2 as
   1.734 -- * published by the Free Software Foundation;
   1.735 -- *
   1.736 -- * This program is distributed in the hope that it will be useful,
   1.737 -- * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.738 -- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.739 -- * GNU General Public License for more details.
   1.740 -- *
   1.741 -- * You should have received a copy of the GNU General Public License
   1.742 -- * along with this program; if not, write to the Free Software
   1.743 -- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   1.744 -- *
   1.745 -- * Author: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
   1.746 -- */
   1.747 --#ifndef QUAGGA_HELPER_H
   1.748 --#define QUAGGA_HELPER_H
   1.749 --
   1.750 --#include "dce-manager-helper.h"
   1.751 --#include "dce-application-helper.h"
   1.752 --
   1.753 --namespace ns3 {
   1.754 --
   1.755 --/**
   1.756 -- * \brief create a quagga routing daemon as an application and associate it to a node
   1.757 -- *
   1.758 -- * This class creates one or multiple instances of ns3::Quagga and associates
   1.759 -- * it/them to one/multiple node(s).
   1.760 -- */
   1.761 --class QuaggaHelper
   1.762 --{
   1.763 --public:
   1.764 --  /**
   1.765 --   * Create a QuaggaHelper which is used to make life easier for people wanting
   1.766 --   * to use quagga Applications.
   1.767 --   *
   1.768 --   */
   1.769 --  QuaggaHelper ();
   1.770 --  /**
   1.771 --   * Install a quagga application on each Node in the provided NodeContainer.
   1.772 --   *
   1.773 --   * \param nodes The NodeContainer containing all of the nodes to get a quagga
   1.774 --   *              application via ProcessManager.
   1.775 --   *
   1.776 --   * \returns A list of quagga applications, one for each input node
   1.777 --   */
   1.778 --  ApplicationContainer Install (NodeContainer nodes);
   1.779 --
   1.780 --  /**
   1.781 --   * Install a quagga application on the provided Node.  The Node is specified
   1.782 --   * directly by a Ptr<Node>
   1.783 --   *
   1.784 --   * \param node The node to install the QuaggaApplication on.
   1.785 --   *
   1.786 --   * \returns An ApplicationContainer holding the quagga application created.
   1.787 --   */
   1.788 --  ApplicationContainer Install (Ptr<Node> node);
   1.789 --
   1.790 --  /**
   1.791 --   * Install a quagga application on the provided Node.  The Node is specified
   1.792 --   * by a string that must have previosly been associated with a Node using the
   1.793 --   * Object Name Service.
   1.794 --   *
   1.795 --   * \param nodeName The node to install the ProcessApplication on.
   1.796 --   *
   1.797 --   * \returns An ApplicationContainer holding the quagga application created.
   1.798 --   */
   1.799 --  ApplicationContainer Install (std::string nodeName);
   1.800 --
   1.801 --  /**
   1.802 --   * \brief Configure ping applications attribute 
   1.803 --   * \param name   attribute's name
   1.804 --   * \param value  attribute's value
   1.805 --   */
   1.806 --  void SetAttribute (std::string name, const AttributeValue &value);
   1.807 --
   1.808 --  void EnableOspf (NodeContainer nodes);
   1.809 --  void EnableOspfDebug (NodeContainer nodes);
   1.810 --  void EnableTdpNina (NodeContainer nodes);
   1.811 --  void EnableZebraDebug (NodeContainer nodes);
   1.812 --  void EnableRadvd (Ptr<Node> node, const char *ifname);
   1.813 --  void EnableEgressIF (Ptr<Node> node, const char *ifname);
   1.814 --  void EnableHomeAgentFlag (Ptr<Node> node, const char *ifname);
   1.815 --  void UseManualConfig (NodeContainer nodes);
   1.816 --private:
   1.817 --  /**
   1.818 --   * \internal
   1.819 --   */
   1.820 --  ApplicationContainer InstallPriv (Ptr<Node> node);
   1.821 --  void GenerateConfigZebra (Ptr<Node> node);
   1.822 --  void GenerateConfigOspf (Ptr<Node> node);
   1.823 --};
   1.824 --
   1.825 --} // namespace ns3
   1.826 --
   1.827 --#endif /* QUAGGA_HELPER_H */
   1.828 -diff -r 071d721c2713 model/dce-fd.cc
   1.829 ---- a/model/dce-fd.cc	Wed May 30 10:21:32 2012 +0200
   1.830 -+++ b/model/dce-fd.cc	Sat Jun 02 00:22:49 2012 +0900
   1.831 -@@ -345,12 +345,6 @@
   1.832 - 
   1.833 -   Ptr<SocketFdFactory>  factory = 0;
   1.834 - 
   1.835 --  if ( domain == AF_INET6 )
   1.836 --    {
   1.837 --      current->err = EAFNOSUPPORT;
   1.838 --      return -1;
   1.839 --    }
   1.840 --
   1.841 -   if (domain != AF_UNIX)
   1.842 -     {
   1.843 -       factory = manager->GetObject<SocketFdFactory> ();
   1.844 -diff -r 071d721c2713 model/libc-ns3.h
   1.845 ---- a/model/libc-ns3.h	Wed May 30 10:21:32 2012 +0200
   1.846 -+++ b/model/libc-ns3.h	Sat Jun 02 00:22:49 2012 +0900
   1.847 -@@ -469,7 +469,7 @@
   1.848 - NATIVE (gettext)
   1.849 - 
   1.850 - // PWD.H
   1.851 --DCE (getpwnam)
   1.852 -+NATIVE (getpwnam)
   1.853 - DCE (getpwuid)
   1.854 - DCE (endpwent)
   1.855 - 
   1.856 -diff -r 071d721c2713 model/linux-socket-fd-factory.cc
   1.857 ---- a/model/linux-socket-fd-factory.cc	Wed May 30 10:21:32 2012 +0200
   1.858 -+++ b/model/linux-socket-fd-factory.cc	Sat Jun 02 00:22:49 2012 +0900
   1.859 -@@ -254,6 +254,10 @@
   1.860 - {
   1.861 -   LinuxSocketFdFactory *self = (LinuxSocketFdFactory *)kernel;
   1.862 -   TaskManager *manager = TaskManager::Current ();
   1.863 -+  if (!manager) 
   1.864 -+    {
   1.865 -+      return 1;
   1.866 -+    }
   1.867 -   Task *other = (Task *)self->m_exported->task_get_private (task);
   1.868 -   bool isBlocked = other->IsBlocked ();
   1.869 -   manager->Wakeup (other);
   1.870 -@@ -403,6 +407,10 @@
   1.871 -     {
   1.872 -       flags |= SIM_DEV_BROADCAST;
   1.873 -     }
   1.874 -+  if (!device->NeedsArp ())
   1.875 -+    {
   1.876 -+      flags |= SIM_DEV_NOARP;
   1.877 -+    }
   1.878 -   struct SimDevice *dev = m_exported->dev_create (PeekPointer (device), (enum SimDevFlags)flags);
   1.879 - 
   1.880 -   Ptr<LinuxDeviceStateListener> listener = Create <LinuxDeviceStateListener> (device, this);
   1.881 -diff -r 071d721c2713 model/ns3-socket-fd-factory.cc
   1.882 ---- a/model/ns3-socket-fd-factory.cc	Wed May 30 10:21:32 2012 +0200
   1.883 -+++ b/model/ns3-socket-fd-factory.cc	Sat Jun 02 00:22:49 2012 +0900
   1.884 -@@ -98,6 +98,29 @@
   1.885 -         break;
   1.886 -         }
   1.887 -     }
   1.888 -+  else if (domain == PF_INET6)
   1.889 -+    {
   1.890 -+      switch (type) {
   1.891 -+        case SOCK_RAW: {
   1.892 -+        TypeId tid = TypeId::LookupByName ("ns3::Ipv6RawSocketFactory");
   1.893 -+        Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   1.894 -+        sock = factory->CreateSocket ();
   1.895 -+        sock->SetAttribute ("Protocol", UintegerValue (protocol));
   1.896 -+        socket = new UnixDatagramSocketFd (sock);
   1.897 -+          } break;
   1.898 -+        case SOCK_DGRAM: {
   1.899 -+          } break;
   1.900 -+        case SOCK_STREAM: {
   1.901 -+        TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
   1.902 -+        Ptr<SocketFactory> factory = GetObject<SocketFactory> (tid);
   1.903 -+        sock = factory->CreateSocket ();
   1.904 -+        socket = new UnixStreamSocketFd (sock);
   1.905 -+          } break;
   1.906 -+        default:
   1.907 -+        NS_FATAL_ERROR ("missing socket type");
   1.908 -+        break;
   1.909 -+        }
   1.910 -+    }
   1.911 -   else if (domain == PF_NETLINK)
   1.912 -     {
   1.913 -       switch (type) {
   1.914 -diff -r 071d721c2713 model/unix-socket-fd.cc
   1.915 ---- a/model/unix-socket-fd.cc	Wed May 30 10:21:32 2012 +0200
   1.916 -+++ b/model/unix-socket-fd.cc	Sat Jun 02 00:22:49 2012 +0900
   1.917 -@@ -33,6 +33,7 @@
   1.918 - #include "ns3/boolean.h"
   1.919 - #include "ns3/simulator.h"
   1.920 - #include "ns3/netlink-socket-address.h"
   1.921 -+#include "ns3/inet6-socket-address.h"
   1.922 - #include <fcntl.h>
   1.923 - #include <errno.h>
   1.924 - #include <linux/icmp.h> // need ICMP_FILTER
   1.925 -@@ -634,6 +635,15 @@
   1.926 -       InetSocketAddress inet = InetSocketAddress (ipv4, port);
   1.927 -       return inet;
   1.928 -     }
   1.929 -+  else if (my_addr->sa_family == AF_INET6)
   1.930 -+    {
   1.931 -+      const struct sockaddr_in6 *addr = (const struct sockaddr_in6 *)my_addr;
   1.932 -+      Ipv6Address ipv6;
   1.933 -+      ipv6.Set ((uint8_t *)addr->sin6_addr.s6_addr);
   1.934 -+      uint16_t port = ntohs (addr->sin6_port);
   1.935 -+      Inet6SocketAddress inet = Inet6SocketAddress (ipv6, port);
   1.936 -+      return inet;
   1.937 -+    }
   1.938 -   else if (my_addr->sa_family == AF_NETLINK)
   1.939 -     {
   1.940 -       const struct sockaddr_nl *addr = (const struct sockaddr_nl *)my_addr;
   1.941 -@@ -671,6 +681,19 @@
   1.942 -       inet_addr->sin_addr.s_addr = htonl (ns_inetaddr.GetIpv4 ().Get ());
   1.943 -       *addrlen = sizeof(struct sockaddr_in);
   1.944 -     }
   1.945 -+  else if (Inet6SocketAddress::IsMatchingType (nsaddr))
   1.946 -+    {
   1.947 -+      Inet6SocketAddress ns_inetaddr = Inet6SocketAddress::ConvertFrom (nsaddr);
   1.948 -+      if (*addrlen < sizeof (struct sockaddr_in6))
   1.949 -+        {
   1.950 -+          return -1;
   1.951 -+        }
   1.952 -+      struct sockaddr_in6 *inet_addr = (struct sockaddr_in6 *)addr;
   1.953 -+      inet_addr->sin6_family = AF_INET;
   1.954 -+      inet_addr->sin6_port = htons (ns_inetaddr.GetPort ());
   1.955 -+      ns_inetaddr.GetIpv6 ().GetBytes (inet_addr->sin6_addr.s6_addr);
   1.956 -+      *addrlen = sizeof(struct sockaddr_in6);
   1.957 -+    }
   1.958 -   else if (NetlinkSocketAddress::IsMatchingType(nsaddr))
   1.959 -     {
   1.960 -       NetlinkSocketAddress ns_nladdr = NetlinkSocketAddress::ConvertFrom (nsaddr);
   1.961 -diff -r 071d721c2713 model/utils.cc
   1.962 ---- a/model/utils.cc	Wed May 30 10:21:32 2012 +0200
   1.963 -+++ b/model/utils.cc	Sat Jun 02 00:22:49 2012 +0900
   1.964 -@@ -191,6 +191,11 @@
   1.965 - void UtilsDoSignal (void)
   1.966 - {
   1.967 -   Thread *current = Current ();
   1.968 -+  if (!current)
   1.969 -+    {
   1.970 -+      return;
   1.971 -+    }
   1.972 -+
   1.973 -   // we try to check if we 
   1.974 -   // have pending signals and we deliver them if we have any.
   1.975 -   for (std::vector<SignalHandler>::iterator i = current->process->signalHandlers.begin (); 
   1.976 -diff -r 071d721c2713 test/dce-manager-test.cc
   1.977 ---- a/test/dce-manager-test.cc	Wed May 30 10:21:32 2012 +0200
   1.978 -+++ b/test/dce-manager-test.cc	Sat Jun 02 00:22:49 2012 +0900
   1.979 -@@ -161,13 +161,15 @@
   1.980 -       {  "test-random", 0, "", false },
   1.981 -       {  "test-local-socket", 0, "", false },
   1.982 -       {  "test-poll", 3200, "", true },
   1.983 --      {  "test-tcp-socket", 320, "", true },
   1.984 -+      //      {  "test-tcp-socket", 320, "", true },
   1.985 -       {  "test-exec", 0, "" , false},
   1.986 -       /* {  "test-raw-socket", 320, "", true },*/
   1.987 -       {  "test-iperf", 0, "" , false},
   1.988 -       {  "test-name", 0, "" , false},
   1.989 -       {  "test-pipe", 0, "" , false},
   1.990 -       {  "test-dirent", 0, "" , false},
   1.991 -+      {  "test-socket", 30, "" , true},
   1.992 -+      {  "test-bug-multi-select", 30, "" , true},
   1.993 -   };
   1.994 - 
   1.995 -   // Prepare directories and files for test-stdio
   1.996 -diff -r 071d721c2713 test/test-bug-multi-select.cc
   1.997 ---- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   1.998 -+++ b/test/test-bug-multi-select.cc	Sat Jun 02 00:22:49 2012 +0900
   1.999 -@@ -0,0 +1,199 @@
  1.1000 -+#include <stdio.h>
  1.1001 -+#include <sys/select.h>
  1.1002 -+#include <sys/types.h>
  1.1003 -+#include <sys/socket.h>
  1.1004 -+#include <netinet/ip.h>
  1.1005 -+#include <string.h>
  1.1006 -+#include <unistd.h>
  1.1007 -+#include <fcntl.h>
  1.1008 -+#include <errno.h>
  1.1009 -+
  1.1010 -+#define SND_CNT 50
  1.1011 -+
  1.1012 -+static int
  1.1013 -+sv ()
  1.1014 -+{
  1.1015 -+  int ret;
  1.1016 -+  int accept_sock, sock;
  1.1017 -+  struct sockaddr_in addr, client;
  1.1018 -+  fd_set readfd;
  1.1019 -+  int val;
  1.1020 -+  socklen_t len = sizeof (client);
  1.1021 -+  char buf[1024];
  1.1022 -+  int i = 0;
  1.1023 -+
  1.1024 -+#ifdef DEBUG
  1.1025 -+  printf ("Server Start \n");
  1.1026 -+#endif
  1.1027 -+
  1.1028 -+  accept_sock = socket (AF_INET, SOCK_STREAM, 0);
  1.1029 -+  if (accept_sock < 0) 
  1.1030 -+    {
  1.1031 -+      perror ("socket");
  1.1032 -+      return -1;
  1.1033 -+    }
  1.1034 -+
  1.1035 -+  memset (&addr, 0, sizeof (struct sockaddr_in));
  1.1036 -+  addr.sin_family = AF_INET;
  1.1037 -+  addr.sin_port = htons (10001);
  1.1038 -+  addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  1.1039 -+
  1.1040 -+  ret  = bind (accept_sock, (struct sockaddr *)&addr, 
  1.1041 -+	       sizeof (struct sockaddr_in));
  1.1042 -+  if (ret < 0)
  1.1043 -+    {
  1.1044 -+      perror ("bind");
  1.1045 -+      return -1;
  1.1046 -+    }
  1.1047 -+
  1.1048 -+  ret = listen (accept_sock, 1);
  1.1049 -+  if (ret < 0)
  1.1050 -+    {
  1.1051 -+      perror ("listen");
  1.1052 -+      return -1;
  1.1053 -+    }
  1.1054 -+
  1.1055 -+  sock = accept (accept_sock, (struct sockaddr *) &client, &len);
  1.1056 -+  if (sock < 0)
  1.1057 -+    {
  1.1058 -+      perror ("accept");
  1.1059 -+      return -1;
  1.1060 -+    }
  1.1061 -+
  1.1062 -+#ifdef DEBUG
  1.1063 -+   printf ("accept\n");
  1.1064 -+#endif
  1.1065 -+  val = fcntl (sock, F_GETFL, 0);
  1.1066 -+  fcntl (sock, F_SETFL, (val | O_NONBLOCK));
  1.1067 -+
  1.1068 -+  while (1)
  1.1069 -+    {
  1.1070 -+      struct timeval tv;
  1.1071 -+      memset (&tv, 0, sizeof(tv));
  1.1072 -+      tv.tv_sec = 1;
  1.1073 -+      tv.tv_usec = 0;
  1.1074 -+
  1.1075 -+      i++;
  1.1076 -+      if (i > SND_CNT * 3)
  1.1077 -+        {
  1.1078 -+          printf ("ERR: Giving up to recv data (try=%d)", i);
  1.1079 -+          return -1;
  1.1080 -+        }
  1.1081 -+
  1.1082 -+      //      printf ("select\n");
  1.1083 -+      FD_ZERO (&readfd);
  1.1084 -+      FD_SET (sock, &readfd);
  1.1085 -+      // Multiple fds in readfd
  1.1086 -+      FD_SET (accept_sock, &readfd);
  1.1087 -+      ret = select (FD_SETSIZE, &readfd, NULL, NULL, &tv);
  1.1088 -+      if (ret == 0)
  1.1089 -+        {
  1.1090 -+#ifdef DEBUG
  1.1091 -+          printf ("timeout\n");
  1.1092 -+#endif
  1.1093 -+          continue;
  1.1094 -+        }
  1.1095 -+
  1.1096 -+      if (ret < 0)
  1.1097 -+	{
  1.1098 -+          if (errno == EINTR || errno == EAGAIN)
  1.1099 -+	    continue;
  1.1100 -+
  1.1101 -+	  perror ("select");
  1.1102 -+	  return -1;
  1.1103 -+	}
  1.1104 -+
  1.1105 -+      // To increase read buffer
  1.1106 -+      if (i%3 == 0)
  1.1107 -+        {
  1.1108 -+          i++;
  1.1109 -+          continue;
  1.1110 -+        }
  1.1111 -+
  1.1112 -+      ret = read (sock, buf, sizeof(buf));
  1.1113 -+      if (ret == 0)
  1.1114 -+        return 0;
  1.1115 -+      else if (ret < 0)
  1.1116 -+        {
  1.1117 -+          perror ("read, exit");
  1.1118 -+          return -1;
  1.1119 -+        }
  1.1120 -+#ifdef DEBUG
  1.1121 -+      printf ("recv[%d]: %s\n", i, buf);
  1.1122 -+#endif
  1.1123 -+    }
  1.1124 -+
  1.1125 -+
  1.1126 -+#ifdef DEBUG
  1.1127 -+  printf ("Server Stop \n");
  1.1128 -+#endif
  1.1129 -+  return 0;
  1.1130 -+}
  1.1131 -+
  1.1132 -+
  1.1133 -+static int
  1.1134 -+cl ()
  1.1135 -+{
  1.1136 -+  int ret;
  1.1137 -+  int sock;
  1.1138 -+  struct sockaddr_in addr;
  1.1139 -+  const char buf[512] = "01234567890123456789012345678901234567890123456789\0"; // 50 chars
  1.1140 -+  int i = 0, sndcnt = SND_CNT;
  1.1141 -+
  1.1142 -+#ifdef DEBUG
  1.1143 -+  printf ("Client Start \n");
  1.1144 -+#endif
  1.1145 -+
  1.1146 -+  sock = socket (AF_INET, SOCK_STREAM, 0);
  1.1147 -+  if (sock < 0) 
  1.1148 -+    {
  1.1149 -+      perror ("socket");
  1.1150 -+      return -1;
  1.1151 -+    }
  1.1152 -+
  1.1153 -+  memset (&addr, 0, sizeof (struct sockaddr_in));
  1.1154 -+  addr.sin_family = AF_INET;
  1.1155 -+  addr.sin_port = htons (10001);
  1.1156 -+  addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  1.1157 -+
  1.1158 -+  ret  = connect (sock, (struct sockaddr *)&addr, 
  1.1159 -+                  sizeof (struct sockaddr_in));
  1.1160 -+  if (ret < 0)
  1.1161 -+    {
  1.1162 -+      perror ("connect");
  1.1163 -+      return -1;
  1.1164 -+    }
  1.1165 -+
  1.1166 -+  while (i < sndcnt)
  1.1167 -+    {
  1.1168 -+      ret = write (sock, buf, sizeof(buf));
  1.1169 -+      if (ret < 0)
  1.1170 -+        {
  1.1171 -+          perror ("write");
  1.1172 -+          return -1;
  1.1173 -+        }
  1.1174 -+      //      printf ("write [%d] \n", i);
  1.1175 -+      i++;
  1.1176 -+    }
  1.1177 -+
  1.1178 -+
  1.1179 -+#ifdef DEBUG
  1.1180 -+  printf ("Client Stop \n");
  1.1181 -+#endif
  1.1182 -+  return 0;
  1.1183 -+}
  1.1184 -+
  1.1185 -+int
  1.1186 -+main (int argc, char *argv[])
  1.1187 -+{
  1.1188 -+  if (argc == 1)
  1.1189 -+    {
  1.1190 -+      return sv ();
  1.1191 -+    }
  1.1192 -+  else
  1.1193 -+    {
  1.1194 -+      return cl ();
  1.1195 -+    }
  1.1196 -+
  1.1197 -+  return 0;
  1.1198 -+}
  1.1199 -diff -r 071d721c2713 test/test-socket.cc
  1.1200 ---- /dev/null	Thu Jan 01 00:00:00 1970 +0000
  1.1201 -+++ b/test/test-socket.cc	Sat Jun 02 00:22:49 2012 +0900
  1.1202 -@@ -0,0 +1,395 @@
  1.1203 -+#define _GNU_SOURCE 1
  1.1204 -+#include <sys/types.h>
  1.1205 -+#include <sys/socket.h>
  1.1206 -+#include <netinet/in.h>
  1.1207 -+#include <linux/netlink.h>
  1.1208 -+#include <linux/rtnetlink.h>
  1.1209 -+#include <errno.h>
  1.1210 -+#include <sys/select.h>
  1.1211 -+#include <pthread.h>
  1.1212 -+#include <netinet/ip.h>
  1.1213 -+#include "test-macros.h"
  1.1214 -+
  1.1215 -+#undef OUTPUT
  1.1216 -+#define OUTPUT(s) (std::cout << s << std::endl)
  1.1217 -+
  1.1218 -+void test_raw (void)
  1.1219 -+{
  1.1220 -+  int sock;
  1.1221 -+  const char buf[12] = "0123456789\0";
  1.1222 -+  struct msghdr msg;
  1.1223 -+  struct iovec iov[2];
  1.1224 -+  static struct sockaddr_in dst;
  1.1225 -+  int ret;
  1.1226 -+  int on = 1;
  1.1227 -+
  1.1228 -+  // ICMP Raw sock
  1.1229 -+  sock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
  1.1230 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1231 -+
  1.1232 -+  // sockopt IP_PKTINFO
  1.1233 -+  ret = setsockopt (sock, IPPROTO_IP, IP_PKTINFO, &on, sizeof (on));
  1.1234 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1235 -+
  1.1236 -+  // sendmsg
  1.1237 -+  memset (&dst, 0, sizeof (dst));
  1.1238 -+  dst.sin_family = AF_INET;
  1.1239 -+  dst.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  1.1240 -+
  1.1241 -+  iov[0].iov_base = (void *) buf;
  1.1242 -+  iov[0].iov_len = sizeof (buf);
  1.1243 -+  msg.msg_name = &dst;
  1.1244 -+  msg.msg_namelen = sizeof (dst);
  1.1245 -+  msg.msg_iov = &iov[0];
  1.1246 -+  msg.msg_iovlen = 1;
  1.1247 -+  msg.msg_control = NULL;
  1.1248 -+  msg.msg_controllen = 0;
  1.1249 -+
  1.1250 -+  ret = sendmsg (sock, &msg, 0);
  1.1251 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf));
  1.1252 -+  OUTPUT ("RAW send ret = " << ret);
  1.1253 -+
  1.1254 -+  // recvmsg with MSG_PEEK
  1.1255 -+  iov[0].iov_base = (void *) buf;
  1.1256 -+  iov[0].iov_len = 2;
  1.1257 -+  ret = recvmsg (sock, &msg, MSG_PEEK);
  1.1258 -+  TEST_ASSERT_EQUAL (ret, 2);
  1.1259 -+  OUTPUT ("RAW recv PEEK ret = " << ret);
  1.1260 -+
  1.1261 -+  // recvmsg 
  1.1262 -+  struct in_pktinfo *pktinfo;
  1.1263 -+  struct cmsghdr *cmsg;
  1.1264 -+  char cbuff [sizeof (*cmsg) + sizeof (*pktinfo)];
  1.1265 -+  char buf2[32];
  1.1266 -+  iov[0].iov_base = (void *) buf2;
  1.1267 -+  iov[0].iov_len = sizeof (buf2);
  1.1268 -+  msg.msg_name = NULL;
  1.1269 -+  msg.msg_namelen = 0;
  1.1270 -+  msg.msg_iov = &iov[0];
  1.1271 -+  msg.msg_iovlen = 1;
  1.1272 -+  msg.msg_control = cbuff;
  1.1273 -+  msg.msg_controllen = CMSG_SPACE(sizeof (struct in_pktinfo));
  1.1274 -+  ret = recvmsg (sock, &msg, 0);
  1.1275 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf2));
  1.1276 -+  OUTPUT ("RAW recv ret = " << ret);
  1.1277 -+  //  std::cout <<  "RAW recv ret = " << ret << std::endl;
  1.1278 -+
  1.1279 -+  // RECV interface via PKTINFO
  1.1280 -+  cmsg = CMSG_FIRSTHDR (&msg);
  1.1281 -+  pktinfo = (struct in_pktinfo *)CMSG_DATA(cmsg);
  1.1282 -+  TEST_ASSERT_EQUAL (pktinfo->ipi_ifindex, 1); // Loopback Interface
  1.1283 -+
  1.1284 -+
  1.1285 -+  // sockopt IP_HDRINCL
  1.1286 -+  ret = setsockopt (sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof (on));
  1.1287 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1288 -+
  1.1289 -+  // sendmsg with IP_HDRINCL
  1.1290 -+  struct ip iph;
  1.1291 -+  memset (&iph, 0, sizeof (iph));
  1.1292 -+  iph.ip_hl = sizeof (struct ip) >> 2;
  1.1293 -+  iph.ip_src = dst.sin_addr;
  1.1294 -+  iph.ip_dst = dst.sin_addr;
  1.1295 -+  iph.ip_p = IPPROTO_ICMP;
  1.1296 -+  iph.ip_len = iph.ip_hl*4 + sizeof (buf);
  1.1297 -+  iov[0].iov_base = (char*)&iph;
  1.1298 -+  iov[0].iov_len = iph.ip_hl * 4;
  1.1299 -+  iov[1].iov_base = (void *) buf;
  1.1300 -+  iov[1].iov_len = sizeof (buf);
  1.1301 -+  msg.msg_name = &dst;
  1.1302 -+  msg.msg_namelen = sizeof (dst);
  1.1303 -+  msg.msg_iov = iov;
  1.1304 -+  msg.msg_iovlen = 2;
  1.1305 -+  msg.msg_control = NULL;
  1.1306 -+  msg.msg_controllen = 0;
  1.1307 -+
  1.1308 -+  ret = sendmsg (sock, &msg, 0);
  1.1309 -+  // XXX: FIXME to handle header size
  1.1310 -+  TEST_ASSERT_EQUAL (ret, (int)sizeof (buf) + iph.ip_hl * 4);
  1.1311 -+  //  TEST_ASSERT_EQUAL (ret, (int)sizeof (buf) + );
  1.1312 -+  OUTPUT ("RAW send ret = " << ret);
  1.1313 -+
  1.1314 -+  // recvmsg with long buf
  1.1315 -+  char recvbuf[512];
  1.1316 -+  iov[0].iov_base = (void *) recvbuf;
  1.1317 -+  iov[0].iov_len = sizeof (recvbuf);
  1.1318 -+  ret = recvmsg (sock, &msg, 0);
  1.1319 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf) + 20);
  1.1320 -+  OUTPUT ("RAW recv ret = " << ret);
  1.1321 -+
  1.1322 -+  // close
  1.1323 -+  // FIXME!! close () cause WakeupSend and died cause non-context switching
  1.1324 -+  // close (sock);
  1.1325 -+  // TEST_ASSERT_UNEQUAL (sock, -1);
  1.1326 -+}
  1.1327 -+
  1.1328 -+void test_udp (void)
  1.1329 -+{
  1.1330 -+  int sock;
  1.1331 -+  const char buf[12] = "0123456789\0";
  1.1332 -+  struct msghdr msg;
  1.1333 -+  struct iovec iov;
  1.1334 -+  static struct sockaddr_in dst;
  1.1335 -+  int ret;
  1.1336 -+
  1.1337 -+  // UDP Sock
  1.1338 -+  sock = socket (AF_INET, SOCK_DGRAM, 0);
  1.1339 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1340 -+
  1.1341 -+  memset (&dst, 0, sizeof (dst));
  1.1342 -+  dst.sin_family = AF_INET;
  1.1343 -+  dst.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  1.1344 -+  dst.sin_port = htons (30);
  1.1345 -+
  1.1346 -+  // bind
  1.1347 -+  ret = bind (sock, (struct sockaddr *)&dst, sizeof (dst));
  1.1348 -+  TEST_ASSERT_UNEQUAL (ret, -1);
  1.1349 -+
  1.1350 -+  // sendmsg
  1.1351 -+  iov.iov_base = (void *) buf;
  1.1352 -+  iov.iov_len = sizeof (buf);
  1.1353 -+  msg.msg_name = &dst;
  1.1354 -+  msg.msg_namelen = sizeof (dst);
  1.1355 -+  msg.msg_iov = &iov;
  1.1356 -+  msg.msg_iovlen = 1;
  1.1357 -+  msg.msg_control = NULL;
  1.1358 -+  msg.msg_controllen = 0;
  1.1359 -+
  1.1360 -+  ret = sendmsg (sock, &msg, 0);
  1.1361 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf));
  1.1362 -+  OUTPUT ("UDP send ret = " << ret);
  1.1363 -+
  1.1364 -+  // recvmsg
  1.1365 -+  iov.iov_base = (void *) buf;
  1.1366 -+  iov.iov_len = sizeof (buf);
  1.1367 -+  ret = recvmsg (sock, &msg, 0);
  1.1368 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf));
  1.1369 -+  OUTPUT ("UDP recv ret = " << ret);
  1.1370 -+
  1.1371 -+  // close
  1.1372 -+  close (sock);
  1.1373 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1374 -+}
  1.1375 -+
  1.1376 -+static void *
  1.1377 -+thread_recv (void *arg)
  1.1378 -+{
  1.1379 -+  int accept_sock = -1;
  1.1380 -+  int sock = *(int *)arg;
  1.1381 -+  int ret;
  1.1382 -+  char buf[12];
  1.1383 -+
  1.1384 -+  while (1)
  1.1385 -+    {
  1.1386 -+      fd_set readfd;
  1.1387 -+      struct timeval wait;
  1.1388 -+      FD_ZERO (&readfd);
  1.1389 -+      if (accept_sock == -1)
  1.1390 -+        {
  1.1391 -+          FD_SET (sock, &readfd);
  1.1392 -+        }
  1.1393 -+      else
  1.1394 -+        {
  1.1395 -+          FD_SET (accept_sock, &readfd);
  1.1396 -+        }
  1.1397 -+      wait.tv_sec = 1;
  1.1398 -+
  1.1399 -+      ret = select (FD_SETSIZE, &readfd, NULL, NULL, &wait);
  1.1400 -+      TEST_ASSERT_UNEQUAL (ret, 0);
  1.1401 -+      if (errno == EINTR || errno == EAGAIN)
  1.1402 -+        {
  1.1403 -+          continue;
  1.1404 -+        }
  1.1405 -+      TEST_ASSERT_UNEQUAL (ret, -1);
  1.1406 -+
  1.1407 -+      // accept
  1.1408 -+      if (accept_sock == -1)
  1.1409 -+        {
  1.1410 -+          accept_sock = accept (sock, NULL, 0);
  1.1411 -+          TEST_ASSERT_UNEQUAL (ret, -1);
  1.1412 -+          OUTPUT ("TCP accepted ret = " << ret);
  1.1413 -+        }
  1.1414 -+      else
  1.1415 -+        {
  1.1416 -+          break;
  1.1417 -+        }
  1.1418 -+    }
  1.1419 -+
  1.1420 -+  // recv
  1.1421 -+  ret = recv (accept_sock, &buf, sizeof (buf), 0);
  1.1422 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf));
  1.1423 -+  OUTPUT ("TCP recv ret = " << ret);
  1.1424 -+
  1.1425 -+  pthread_exit (arg);
  1.1426 -+  // never reached.
  1.1427 -+  TEST_ASSERT (false);
  1.1428 -+  return arg;
  1.1429 -+}
  1.1430 -+
  1.1431 -+void test_tcp (void)
  1.1432 -+{
  1.1433 -+  int sock, tx_sock;
  1.1434 -+  const char buf[12] = "0123456789\0";
  1.1435 -+  static struct sockaddr_in dst;
  1.1436 -+  int ret;
  1.1437 -+  pthread_t thread;
  1.1438 -+
  1.1439 -+  // TCP Sock
  1.1440 -+  sock = socket (AF_INET, SOCK_STREAM, 0);
  1.1441 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1442 -+
  1.1443 -+  memset (&dst, 0, sizeof (dst));
  1.1444 -+  dst.sin_family = AF_INET;
  1.1445 -+  dst.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
  1.1446 -+  dst.sin_port = htons (30);
  1.1447 -+
  1.1448 -+  // bind
  1.1449 -+  ret = bind (sock, (struct sockaddr *)&dst, sizeof (dst));
  1.1450 -+  TEST_ASSERT_UNEQUAL (ret, -1);
  1.1451 -+
  1.1452 -+  // listen
  1.1453 -+  ret = listen (sock, 5);
  1.1454 -+  TEST_ASSERT_UNEQUAL (ret, -1);
  1.1455 -+
  1.1456 -+  // recv thread
  1.1457 -+  ret = pthread_create (&thread, NULL, 
  1.1458 -+                        &thread_recv,
  1.1459 -+                        (void*)&sock);
  1.1460 -+
  1.1461 -+  // tx sock
  1.1462 -+  tx_sock = socket (AF_INET, SOCK_STREAM, 0);
  1.1463 -+  TEST_ASSERT_UNEQUAL (tx_sock, -1);
  1.1464 -+  // connect
  1.1465 -+  ret = connect (tx_sock, (struct sockaddr *)&dst, sizeof (dst));
  1.1466 -+  TEST_ASSERT_UNEQUAL (ret, -1);
  1.1467 -+
  1.1468 -+  // send
  1.1469 -+  ret = send (tx_sock, &buf, sizeof (buf), 0);
  1.1470 -+  TEST_ASSERT_EQUAL (ret, sizeof (buf));
  1.1471 -+  OUTPUT ("TCP send ret = " << ret);
  1.1472 -+
  1.1473 -+  void *return_value;
  1.1474 -+  ret = pthread_join (thread, &return_value);
  1.1475 -+
  1.1476 -+  // close
  1.1477 -+  close (sock);
  1.1478 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1479 -+  close (tx_sock);
  1.1480 -+  TEST_ASSERT_UNEQUAL (tx_sock, -1);
  1.1481 -+}
  1.1482 -+
  1.1483 -+void test_netlink (void)
  1.1484 -+{
  1.1485 -+  int sock;
  1.1486 -+  int ret;
  1.1487 -+  struct sockaddr_nl snl;
  1.1488 -+  socklen_t namelen;
  1.1489 -+  int seq = 0;
  1.1490 -+  char buf[4096];
  1.1491 -+  struct iovec iov;
  1.1492 -+  struct msghdr msg;
  1.1493 -+  struct nlmsghdr *h;
  1.1494 -+  struct ifaddrmsg *ifa;
  1.1495 -+
  1.1496 -+  // Netlink sock
  1.1497 -+  sock = socket (AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  1.1498 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1499 -+
  1.1500 -+  // Bind
  1.1501 -+  memset (&snl, 0, sizeof snl);
  1.1502 -+  snl.nl_family = AF_NETLINK;
  1.1503 -+  snl.nl_groups = RTMGRP_LINK|RTMGRP_IPV4_ROUTE|RTMGRP_IPV4_IFADDR;
  1.1504 -+  ret = bind (sock, (struct sockaddr *) &snl, sizeof snl);
  1.1505 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1506 -+
  1.1507 -+  // getsockname
  1.1508 -+  namelen = sizeof (snl);
  1.1509 -+  ret = getsockname (sock, (struct sockaddr *) &snl, &namelen);
  1.1510 -+  TEST_ASSERT_UNEQUAL (ret, -1);
  1.1511 -+  TEST_ASSERT_EQUAL (namelen, sizeof (snl));
  1.1512 -+
  1.1513 -+  // sendto
  1.1514 -+  struct
  1.1515 -+  {
  1.1516 -+    struct nlmsghdr nlh;
  1.1517 -+    struct rtgenmsg g;
  1.1518 -+  } req;
  1.1519 -+
  1.1520 -+  memset (&snl, 0, sizeof snl);
  1.1521 -+  snl.nl_family = AF_NETLINK;
  1.1522 -+
  1.1523 -+  // Get IPv4 Address
  1.1524 -+  req.nlh.nlmsg_len = sizeof (req);
  1.1525 -+  req.nlh.nlmsg_type = RTM_GETADDR;
  1.1526 -+  req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
  1.1527 -+  req.nlh.nlmsg_pid = 0;
  1.1528 -+  req.nlh.nlmsg_seq = ++seq;
  1.1529 -+  req.g.rtgen_family = AF_INET;
  1.1530 -+ 
  1.1531 -+  ret = sendto (sock, (void *) &req, sizeof (req), 0, 
  1.1532 -+                (struct sockaddr *) &snl, sizeof (snl));
  1.1533 -+  TEST_ASSERT_EQUAL (ret, sizeof (req));
  1.1534 -+
  1.1535 -+  // recvmsg
  1.1536 -+  iov.iov_base = (void *) buf;
  1.1537 -+  iov.iov_len = sizeof (buf);
  1.1538 -+  msg.msg_name = (void *)&snl;
  1.1539 -+  msg.msg_namelen = sizeof (snl);
  1.1540 -+  msg.msg_iov = &iov;
  1.1541 -+  msg.msg_iovlen = 1;
  1.1542 -+  msg.msg_control = NULL;
  1.1543 -+  msg.msg_controllen = 0;
  1.1544 -+
  1.1545 -+  ret = recvmsg (sock, &msg, 0);
  1.1546 -+  TEST_ASSERT_UNEQUAL (ret, -1);
  1.1547 -+  TEST_ASSERT_EQUAL (msg.msg_namelen, sizeof (snl));
  1.1548 -+
  1.1549 -+  // Code from zebra/rt_netlink.c
  1.1550 -+  for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, (uint32_t) ret);
  1.1551 -+       h = NLMSG_NEXT (h, ret))
  1.1552 -+    {
  1.1553 -+      if (h->nlmsg_type == NLMSG_DONE)
  1.1554 -+        break;
  1.1555 -+
  1.1556 -+      /* Error handling. */
  1.1557 -+      if (h->nlmsg_type == NLMSG_ERROR)
  1.1558 -+        {
  1.1559 -+          struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA (h);
  1.1560 -+          /* If the error field is zero, then this is an ACK */
  1.1561 -+          if (err->error == 0) 
  1.1562 -+            {
  1.1563 -+              // ACK
  1.1564 -+              /* return if not a multipart message, otherwise continue */  
  1.1565 -+              if (!(h->nlmsg_flags & NLM_F_MULTI)) 
  1.1566 -+                { 
  1.1567 -+                  break;
  1.1568 -+                }
  1.1569 -+              continue; 
  1.1570 -+            }
  1.1571 -+          
  1.1572 -+          TEST_ASSERT (h->nlmsg_len >= NLMSG_LENGTH (sizeof (struct nlmsgerr)));
  1.1573 -+        }
  1.1574 -+
  1.1575 -+      ifa = (struct ifaddrmsg *) NLMSG_DATA (h);
  1.1576 -+      TEST_ASSERT (ifa->ifa_family == AF_INET || ifa->ifa_family == AF_INET6);
  1.1577 -+      OUTPUT ("NL: family =  " << (int)ifa->ifa_family);
  1.1578 -+    
  1.1579 -+      TEST_ASSERT (h->nlmsg_type == RTM_NEWADDR || h->nlmsg_type == RTM_DELADDR);
  1.1580 -+      TEST_ASSERT (h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifaddrmsg) >= 0));
  1.1581 -+
  1.1582 -+      // We didn't get into detail to parse attribute
  1.1583 -+    }
  1.1584 -+
  1.1585 -+  close (sock);
  1.1586 -+  TEST_ASSERT_UNEQUAL (sock, -1);
  1.1587 -+
  1.1588 -+}
  1.1589 -+
  1.1590 -+int main (int argc, char *argv[])
  1.1591 -+{
  1.1592 -+  test_raw ();
  1.1593 -+  test_udp ();
  1.1594 -+  test_tcp ();
  1.1595 -+  test_netlink ();
  1.1596 -+  return 0;
  1.1597 -+}
  1.1598 -diff -r 071d721c2713 test/wscript
  1.1599 ---- a/test/wscript	Wed May 30 10:21:32 2012 +0200
  1.1600 -+++ b/test/wscript	Sat Jun 02 00:22:49 2012 +0900
  1.1601 -@@ -31,6 +31,8 @@
  1.1602 -     new_test(bld, 'test-netdb', '')
  1.1603 -     new_test(bld, 'test-env', '')
  1.1604 -     new_test(bld, 'test-cond', 'PTHREAD')
  1.1605 -+    new_test(bld, 'test-socket', 'PTHREAD')
  1.1606 -+    new_test(bld, 'test-bug-multi-select', 'PTHREAD')
  1.1607 -     new_test(bld, 'test-timer-fd', '')
  1.1608 -     new_test(bld, 'test-stdlib', '')
  1.1609 -     new_test(bld, 'test-select', 'PTHREAD')
  1.1610 -diff -r 071d721c2713 utils/setenv.sh
  1.1611 ---- a/utils/setenv.sh	Wed May 30 10:21:32 2012 +0200
  1.1612 -+++ b/utils/setenv.sh	Sat Jun 02 00:22:49 2012 +0900
  1.1613 -@@ -1,6 +1,6 @@
  1.1614 - #!/bin/bash
  1.1615 - # Set environnement for ns3 dce
  1.1616 --cd `dirname $BASH_SOURCE`/../
  1.1617 -+cd `dirname ${BASH_SOURCE:-$0}`/../
  1.1618 - BASEDCE=$PWD
  1.1619 - cd ..
  1.1620 - BASE=$PWD
  1.1621 -diff -r 071d721c2713 wscript
  1.1622 ---- a/wscript	Wed May 30 10:21:32 2012 +0200
  1.1623 -+++ b/wscript	Sat Jun 02 00:22:49 2012 +0900
  1.1624 -@@ -26,6 +26,7 @@
  1.1625 -     ns3waf.check_modules(conf, ['point-to-point', 'tap-bridge', 'netanim'], mandatory = False)
  1.1626 -     ns3waf.check_modules(conf, ['wifi', 'point-to-point', 'csma', 'mobility'], mandatory = False)
  1.1627 -     ns3waf.check_modules(conf, ['point-to-point-layout'], mandatory = False)
  1.1628 -+    ns3waf.check_modules(conf, ['topology-read', 'applications'], mandatory = False)
  1.1629 -     conf.check_tool('compiler_cc')
  1.1630 -     conf.check(header_name='stdint.h', define_name='HAVE_STDINT_H', mandatory=False)
  1.1631 -     conf.check(header_name='inttypes.h', define_name='HAVE_INTTYPES_H', mandatory=False)
  1.1632 -@@ -163,7 +164,9 @@
  1.1633 -              ['test-iperf', []],
  1.1634 -              ['test-name', []],
  1.1635 -              ['test-pipe', []],
  1.1636 --             ['test-dirent', []]
  1.1637 -+             ['test-dirent', []],
  1.1638 -+             ['test-socket', []],
  1.1639 -+             ['test-bug-multi-select', []],
  1.1640 -              ]
  1.1641 -     for name,uselib in tests:
  1.1642 -         module.add_test(**dce_kw(target='bin_dce/' + name, source = ['test/' + name + '.cc'],
  1.1643 -@@ -235,10 +238,6 @@
  1.1644 -                        target='bin/dce-iperf',
  1.1645 -                        source=['example/dce-iperf.cc', 'example/ccnx/misc-tools.cc'])
  1.1646 -     
  1.1647 --    module.add_example(needed = ['core', 'internet', 'dce', 'point-to-point', 'point-to-point-layout'],
  1.1648 --                       target='bin/dce-zebra-simple',
  1.1649 --                       source=['example/dce-zebra-simple.cc'])
  1.1650 --
  1.1651 -     module.add_example(needed = ['core', 'internet', 'dce' ], 
  1.1652 -                        target='bin/dce-bash-simple',
  1.1653 -                        source=['example/bash/dce-bash-simple.cc'])
  1.1654 -@@ -381,7 +380,6 @@
  1.1655 -         'helper/ipv4-dce-routing-helper.cc',
  1.1656 -         'helper/dce-manager-helper.cc',
  1.1657 -         'helper/dce-application-helper.cc',
  1.1658 --        'helper/quagga-helper.cc',
  1.1659 -         'helper/ccn-client-helper.cc',
  1.1660 -         'helper/ipv4-linux-address-helper.cc'
  1.1661 -         ]
  1.1662 -@@ -395,9 +393,9 @@
  1.1663 -         'model/ipv4-dce-routing.h',
  1.1664 -         'helper/dce-manager-helper.h',
  1.1665 -         'helper/dce-application-helper.h',
  1.1666 --        'helper/quagga-helper.h',
  1.1667 -         'helper/ccn-client-helper.h',
  1.1668 --        'helper/ipv4-linux-address-helper.h'
  1.1669 -+        'helper/ipv4-linux-address-helper.h',
  1.1670 -+        'helper/ipv4-dce-routing-helper.h',
  1.1671 -         ]
  1.1672 -     module_source = module_source + kernel_source
  1.1673 -     module_headers = module_headers + kernel_headers
     2.1 --- a/series	Sat Jun 02 00:29:00 2012 +0900
     2.2 +++ b/series	Thu Jun 21 17:26:37 2012 +0900
     2.3 @@ -1,4 +1,3 @@
     2.4 -120406-dce-quagga-support.patch
     2.5  120410-dce-umip-support.patch
     2.6  dns_unbound.patch
     2.7  dns_bind9.patch