add in the helpers
authorCraig Dowell <craigdo@ee.washington.edu>
Mon Oct 27 23:05:57 2008 -0700 (15 months ago)
changeset 3828337b244e6d8f
parent 3827 4b603cd4ee42
child 3829 97ae21d8caca
add in the helpers
src/helper/emu-helper.cc
src/helper/emu-helper.h
src/helper/tap-helper.cc
src/helper/tap-helper.h
src/helper/wscript
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/helper/emu-helper.cc	Mon Oct 27 23:05:57 2008 -0700
     1.3 @@ -0,0 +1,273 @@
     1.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     1.5 +/*
     1.6 + * Copyright (c) 2008 University of Washington
     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 +
    1.22 +#include <string>
    1.23 +
    1.24 +#include "ns3/log.h"
    1.25 +#include "ns3/simulator.h"
    1.26 +#include "ns3/object-factory.h"
    1.27 +#include "ns3/queue.h"
    1.28 +#include "ns3/emulated-net-device.h"
    1.29 +#include "ns3/pcap-writer.h"
    1.30 +#include "ns3/config.h"
    1.31 +#include "ns3/packet.h"
    1.32 +
    1.33 +#include "emu-helper.h"
    1.34 +
    1.35 +NS_LOG_COMPONENT_DEFINE ("EmuHelper");
    1.36 +
    1.37 +namespace ns3 {
    1.38 +
    1.39 +EmuHelper::EmuHelper ()
    1.40 +{
    1.41 +  NS_LOG_FUNCTION_NOARGS ();
    1.42 +  m_queueFactory.SetTypeId ("ns3::DropTailQueue");
    1.43 +  m_deviceFactory.SetTypeId ("ns3::EmulatedNetDevice");
    1.44 +}
    1.45 +
    1.46 +  void 
    1.47 +EmuHelper::SetQueue (
    1.48 +  std::string type,
    1.49 +  std::string n1, const AttributeValue &v1,
    1.50 +  std::string n2, const AttributeValue &v2,
    1.51 +  std::string n3, const AttributeValue &v3,
    1.52 +  std::string n4, const AttributeValue &v4)
    1.53 +{
    1.54 +  NS_LOG_FUNCTION_NOARGS ();
    1.55 +  m_queueFactory.SetTypeId (type);
    1.56 +  m_queueFactory.Set (n1, v1);
    1.57 +  m_queueFactory.Set (n2, v2);
    1.58 +  m_queueFactory.Set (n3, v3);
    1.59 +  m_queueFactory.Set (n4, v4);
    1.60 +}
    1.61 +
    1.62 +  void 
    1.63 +EmuHelper::SetAttribute (std::string n1, const AttributeValue &v1)
    1.64 +{
    1.65 +  NS_LOG_FUNCTION_NOARGS ();
    1.66 +  m_deviceFactory.Set (n1, v1);
    1.67 +}
    1.68 +
    1.69 +  void 
    1.70 +EmuHelper::EnablePcap (
    1.71 +  std::string filename, 
    1.72 +  uint32_t nodeid, 
    1.73 +  uint32_t deviceid)
    1.74 +{
    1.75 +  NS_LOG_FUNCTION (filename << nodeid << deviceid);
    1.76 +  std::ostringstream oss;
    1.77 +  oss << filename << "-" << nodeid << "-" << deviceid << ".pcap";
    1.78 +  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
    1.79 +  pcap->Open (oss.str ());
    1.80 +  pcap->WriteEthernetHeader ();
    1.81 +
    1.82 +  oss.str ("");
    1.83 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
    1.84 +    "/$ns3::EmulatedNetDevice/Rx";
    1.85 +  Config::ConnectWithoutContext (oss.str (), 
    1.86 +    MakeBoundCallback (&EmuHelper::RxEvent, pcap));
    1.87 +
    1.88 +  oss.str ("");
    1.89 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
    1.90 +    "/$ns3::EmulatedNetDevice/TxQueue/Enqueue";
    1.91 +  Config::ConnectWithoutContext (oss.str (), 
    1.92 +    MakeBoundCallback (&EmuHelper::EnqueueEvent, pcap));
    1.93 +}
    1.94 +
    1.95 +  void 
    1.96 +EmuHelper::EnablePcap (std::string filename, NetDeviceContainer d)
    1.97 +{
    1.98 +  NS_LOG_FUNCTION (filename << &d);
    1.99 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   1.100 +    {
   1.101 +      Ptr<NetDevice> dev = *i;
   1.102 +      EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   1.103 +    }
   1.104 +}
   1.105 +
   1.106 +  void
   1.107 +EmuHelper::EnablePcap (std::string filename, NodeContainer n)
   1.108 +{
   1.109 +  NS_LOG_FUNCTION (filename << &n);
   1.110 +  NetDeviceContainer devs;
   1.111 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
   1.112 +    {
   1.113 +      Ptr<Node> node = *i;
   1.114 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
   1.115 +	{
   1.116 +	  devs.Add (node->GetDevice (j));
   1.117 +	}
   1.118 +    }
   1.119 +  EnablePcap (filename, devs);
   1.120 +}
   1.121 +
   1.122 +  void
   1.123 +EmuHelper::EnablePcapAll (std::string filename)
   1.124 +{
   1.125 +  NS_LOG_FUNCTION (filename);
   1.126 +  EnablePcap (filename, NodeContainer::GetGlobal ());
   1.127 +}
   1.128 +
   1.129 +  void 
   1.130 +EmuHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
   1.131 +{
   1.132 +  NS_LOG_FUNCTION (&os << nodeid << deviceid);
   1.133 +  Packet::EnablePrinting ();
   1.134 +  std::ostringstream oss;
   1.135 +
   1.136 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
   1.137 +    "/$ns3::EmulatedNetDevice/Rx";
   1.138 +  Config::Connect (oss.str (), 
   1.139 +    MakeBoundCallback (&EmuHelper::AsciiRxEvent, &os));
   1.140 +
   1.141 +  oss.str ("");
   1.142 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
   1.143 +    "/$ns3::EmulatedNetDevice/TxQueue/Enqueue";
   1.144 +  Config::Connect (oss.str (), 
   1.145 +    MakeBoundCallback (&EmuHelper::AsciiEnqueueEvent, &os));
   1.146 +
   1.147 +  oss.str ("");
   1.148 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
   1.149 +    "/$ns3::EmulatedNetDevice/TxQueue/Dequeue";
   1.150 +  Config::Connect (oss.str (), 
   1.151 +    MakeBoundCallback (&EmuHelper::AsciiDequeueEvent, &os));
   1.152 +
   1.153 +  oss.str ("");
   1.154 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << 
   1.155 +    "/$ns3::EmulatedNetDevice/TxQueue/Drop";
   1.156 +  Config::Connect (oss.str (), 
   1.157 +    MakeBoundCallback (&EmuHelper::AsciiDropEvent, &os));
   1.158 +}
   1.159 +
   1.160 +  void 
   1.161 +EmuHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
   1.162 +{
   1.163 +  NS_LOG_FUNCTION (&os << &d);
   1.164 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   1.165 +    {
   1.166 +      Ptr<NetDevice> dev = *i;
   1.167 +      EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   1.168 +    }
   1.169 +}
   1.170 +
   1.171 +void
   1.172 +EmuHelper::EnableAscii (std::ostream &os, NodeContainer n)
   1.173 +{
   1.174 +  NS_LOG_FUNCTION (&os << &n);
   1.175 +  NetDeviceContainer devs;
   1.176 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
   1.177 +    {
   1.178 +      Ptr<Node> node = *i;
   1.179 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
   1.180 +	{
   1.181 +	  devs.Add (node->GetDevice (j));
   1.182 +	}
   1.183 +    }
   1.184 +  EnableAscii (os, devs);
   1.185 +}
   1.186 +
   1.187 +  void
   1.188 +EmuHelper::EnableAsciiAll (std::ostream &os)
   1.189 +{
   1.190 +  NS_LOG_FUNCTION (&os);
   1.191 +  EnableAscii (os, NodeContainer::GetGlobal ());
   1.192 +}
   1.193 +
   1.194 +  NetDeviceContainer 
   1.195 +EmuHelper::Install (const NodeContainer &c)
   1.196 +{
   1.197 +  NS_LOG_FUNCTION (&c);
   1.198 +  NetDeviceContainer container;
   1.199 +  for (NodeContainer::Iterator i = c.Begin (); i != c.End (); i++)
   1.200 +    {
   1.201 +      Ptr<Node> node = *i;
   1.202 +
   1.203 +      Ptr<EmulatedNetDevice> device = m_deviceFactory.Create<EmulatedNetDevice> ();
   1.204 +      //
   1.205 +      // This is a mac address used for ns-3 internal things.  It cannot override the real MAC address on the NIC in
   1.206 +      // question.
   1.207 +      //
   1.208 +      device->SetAddress (Mac48Address::Allocate ());
   1.209 +      node->AddDevice (device);
   1.210 +
   1.211 +      Ptr<Queue> queue = m_queueFactory.Create<Queue> ();
   1.212 +      device->SetQueue (queue);
   1.213 +      container.Add (device);
   1.214 +    }
   1.215 +  return container;
   1.216 +}
   1.217 +
   1.218 +  void 
   1.219 +EmuHelper::EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
   1.220 +{
   1.221 +  NS_LOG_FUNCTION (writer << packet);
   1.222 +  writer->WritePacket (packet);
   1.223 +}
   1.224 +
   1.225 +  void 
   1.226 +EmuHelper::RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
   1.227 +{
   1.228 +  NS_LOG_FUNCTION (writer << packet);
   1.229 +  writer->WritePacket (packet);
   1.230 +}
   1.231 +
   1.232 +  void 
   1.233 +EmuHelper::AsciiEnqueueEvent (
   1.234 +  std::ostream *os, 
   1.235 +  std::string path, 
   1.236 +  Ptr<const Packet> packet)
   1.237 +{
   1.238 +  NS_LOG_FUNCTION (&os << path << packet);
   1.239 +  *os << "+ " << Simulator::Now ().GetSeconds () << " ";
   1.240 +  *os << path << " " << *packet << std::endl;
   1.241 +}
   1.242 +
   1.243 +  void 
   1.244 +EmuHelper::AsciiDequeueEvent (
   1.245 +  std::ostream *os, 
   1.246 +  std::string path, 
   1.247 +  Ptr<const Packet> packet)
   1.248 +{
   1.249 +  NS_LOG_FUNCTION (&os << path << packet);
   1.250 +  *os << "- " << Simulator::Now ().GetSeconds () << " ";
   1.251 +  *os << path << " " << *packet << std::endl;
   1.252 +}
   1.253 +
   1.254 +  void 
   1.255 +EmuHelper::AsciiDropEvent (
   1.256 +  std::ostream *os, 
   1.257 +  std::string path, 
   1.258 +  Ptr<const Packet> packet)
   1.259 +{
   1.260 +  NS_LOG_FUNCTION (&os << path << packet);
   1.261 +  *os << "d " << Simulator::Now ().GetSeconds () << " ";
   1.262 +  *os << path << " " << *packet << std::endl;
   1.263 +}
   1.264 +
   1.265 +  void 
   1.266 +EmuHelper::AsciiRxEvent (
   1.267 +  std::ostream *os, 
   1.268 +  std::string path, 
   1.269 +  Ptr<const Packet> packet)
   1.270 +{
   1.271 +  NS_LOG_FUNCTION (&os << path << packet);
   1.272 +  *os << "r " << Simulator::Now ().GetSeconds () << " ";
   1.273 +  *os << path << " " << *packet << std::endl;
   1.274 +}
   1.275 +
   1.276 +} // namespace ns3
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/helper/emu-helper.h	Mon Oct 27 23:05:57 2008 -0700
     2.3 @@ -0,0 +1,181 @@
     2.4 +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     2.5 +/*
     2.6 + * Copyright (c) 2008 University of Washington
     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 +
    2.22 +#ifndef EMU_HELPER_H
    2.23 +#define EMU_HELPER_H
    2.24 +
    2.25 +#include <string>
    2.26 +#include <ostream>
    2.27 +#include "ns3/attribute.h"
    2.28 +#include "ns3/object-factory.h"
    2.29 +#include "ns3/net-device-container.h"
    2.30 +#include "ns3/node-container.h"
    2.31 +#include "ns3/emulated-net-device.h"
    2.32 +
    2.33 +namespace ns3 {
    2.34 +
    2.35 +class Packet;
    2.36 +class PcapWriter;
    2.37 +
    2.38 +/**
    2.39 + * \brief build a set of EmuNetDevice objects
    2.40 + */
    2.41 +class EmuHelper
    2.42 +{
    2.43 +public:
    2.44 +  EmuHelper ();
    2.45 +
    2.46 +  /**
    2.47 +   * \param type the type of queue
    2.48 +   * \param n1 the name of the attribute to set on the queue
    2.49 +   * \param v1 the value of the attribute to set on the queue
    2.50 +   * \param n2 the name of the attribute to set on the queue
    2.51 +   * \param v2 the value of the attribute to set on the queue
    2.52 +   * \param n3 the name of the attribute to set on the queue
    2.53 +   * \param v3 the value of the attribute to set on the queue
    2.54 +   * \param n4 the name of the attribute to set on the queue
    2.55 +   * \param v4 the value of the attribute to set on the queue
    2.56 +   *
    2.57 +   * Set the type of queue to create and associated to each
    2.58 +   * EmuNetDevice created through EmuHelper::Install.
    2.59 +   */
    2.60 +  void SetQueue (std::string type,
    2.61 +    std::string n1 = "", const AttributeValue &v1 = EmptyAttributeValue (),
    2.62 +    std::string n2 = "", const AttributeValue &v2 = EmptyAttributeValue (),
    2.63 +    std::string n3 = "", const AttributeValue &v3 = EmptyAttributeValue (),
    2.64 +    std::string n4 = "", const AttributeValue &v4 = EmptyAttributeValue ());
    2.65 +
    2.66 +  /**
    2.67 +   * \param n1 the name of the attribute to set
    2.68 +   * \param v1 the value of the attribute to set
    2.69 +   *
    2.70 +   * Set these attributes on each ns3::EmuNetDevice created
    2.71 +   * by EmuHelper::Install
    2.72 +   */
    2.73 +  void SetAttribute (std::string n1, const AttributeValue &v1);
    2.74 +
    2.75 +  /**
    2.76 +   * \param filename filename prefix to use for pcap files.
    2.77 +   * \param nodeid the id of the node to generate pcap output for.
    2.78 +   * \param deviceid the id of the device to generate pcap output for.
    2.79 +   *
    2.80 +   * Generate a pcap file which contains the link-level data observed
    2.81 +   * by the specified deviceid within the specified nodeid. The pcap
    2.82 +   * data is stored in the file prefix-nodeid-deviceid.pcap.
    2.83 +   *
    2.84 +   * This method should be invoked after the network topology has 
    2.85 +   * been fully constructed.
    2.86 +   */
    2.87 +  static void EnablePcap (std::string filename, uint32_t nodeid, 
    2.88 +    uint32_t deviceid);
    2.89 +
    2.90 +  /**
    2.91 +   * \param filename filename prefix to use for pcap files.
    2.92 +   * \param d container of devices of type ns3::EmuNetDevice
    2.93 +   *
    2.94 +   * Enable pcap output on each input device which is of the
    2.95 +   * ns3::EmuNetDevice type.
    2.96 +   */
    2.97 +  static void EnablePcap (std::string filename, NetDeviceContainer d);
    2.98 +
    2.99 +  /**
   2.100 +   * \param filename filename prefix to use for pcap files.
   2.101 +   * \param n container of nodes.
   2.102 +   *
   2.103 +   * Enable pcap output on each device which is of the
   2.104 +   * ns3::EmuNetDevice type and which is located in one of the 
   2.105 +   * input nodes.
   2.106 +   */
   2.107 +  static void EnablePcap (std::string filename, NodeContainer n);
   2.108 +
   2.109 +  /**
   2.110 +   * \param filename filename prefix to use for pcap files.
   2.111 +   *
   2.112 +   * Enable pcap output on each device which is of the
   2.113 +   * ns3::EmuNetDevice type
   2.114 +   */
   2.115 +  static void EnablePcapAll (std::string filename);
   2.116 +
   2.117 +  /**
   2.118 +   * \param os output stream
   2.119 +   * \param nodeid the id of the node to generate ascii output for.
   2.120 +   * \param deviceid the id of the device to generate ascii output for.
   2.121 +   *
   2.122 +   * Enable ascii output on the specified deviceid within the
   2.123 +   * specified nodeid if it is of type ns3::EmuNetDevice and dump 
   2.124 +   * that to the specified stdc++ output stream.
   2.125 +   */
   2.126 +  static void EnableAscii (std::ostream &os, uint32_t nodeid, 
   2.127 +    uint32_t deviceid);
   2.128 +
   2.129 +  /**
   2.130 +   * \param os output stream
   2.131 +   * \param d device container
   2.132 +   *
   2.133 +   * Enable ascii output on each device which is of the
   2.134 +   * ns3::EmuNetDevice type and which is located in the input
   2.135 +   * device container and dump that to the specified
   2.136 +   * stdc++ output stream.
   2.137 +   */
   2.138 +  static void EnableAscii (std::ostream &os, NetDeviceContainer d);
   2.139 +
   2.140 +  /**
   2.141 +   * \param os output stream
   2.142 +   * \param n node container
   2.143 +   *
   2.144 +   * Enable ascii output on each device which is of the
   2.145 +   * ns3::EmuNetDevice type and which is located in one
   2.146 +   * of the input node and dump that to the specified
   2.147 +   * stdc++ output stream.
   2.148 +   */
   2.149 +  static void EnableAscii (std::ostream &os, NodeContainer n);
   2.150 +
   2.151 +  /**
   2.152 +   * \param os output stream
   2.153 +   *
   2.154 +   * Enable ascii output on each device which is of the
   2.155 +   * ns3::EmuNetDevice type and dump that to the specified
   2.156 +   * stdc++ output stream.
   2.157 +   */
   2.158 +  static void EnableAsciiAll (std::ostream &os);
   2.159 +
   2.160 +  /**
   2.161 +   * \param c a set of nodes
   2.162 +   */
   2.163 +  NetDeviceContainer Install (const NodeContainer &c);
   2.164 +
   2.165 +private:
   2.166 +  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
   2.167 +  static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
   2.168 +  static void AsciiEnqueueEvent (std::ostream *os, std::string path, 
   2.169 +    Ptr<const Packet> packet);
   2.170 +  static void AsciiDequeueEvent (std::ostream *os, std::string path, 
   2.171 +    Ptr<const Packet> packet);
   2.172 +  static void AsciiDropEvent (std::ostream *os, std::string path, 
   2.173 +    Ptr<const Packet> packet);
   2.174 +  static void AsciiRxEvent (std::ostream *os, std::string path, 
   2.175 +    Ptr<const Packet> packet);
   2.176 +
   2.177 +  ObjectFactory m_queueFactory;
   2.178 +  ObjectFactory m_deviceFactory;
   2.179 +};
   2.180 +
   2.181 +
   2.182 +} // namespace ns3
   2.183 +
   2.184 +#endif /* EMU_HELPER_H */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/helper/tap-helper.cc	Mon Oct 27 23:05:57 2008 -0700
     3.3 @@ -0,0 +1,109 @@
     3.4 +#include "tap-helper.h"
     3.5 +#include "ns3/tap-net-device.h"
     3.6 +#include "ns3/host-tap-net-device.h"
     3.7 +#include "ns3/tap-channel.h"
     3.8 +#include "ns3/pcap-writer.h"
     3.9 +#include "ns3/config.h"
    3.10 +#include "ns3/packet.h"
    3.11 +#include "ns3/callback.h"
    3.12 +#include "ns3/log.h"
    3.13 +
    3.14 +namespace ns3 {
    3.15 +
    3.16 +NS_LOG_COMPONENT_DEFINE ("TapHelper");
    3.17 +
    3.18 +NetDeviceContainer
    3.19 +TapHelper::Install (NodeContainer hosts, NodeContainer taps)
    3.20 +{
    3.21 +  NS_ASSERT (hosts.GetN () == 1 && taps.GetN () == 1);
    3.22 +  NetDeviceContainer devices;
    3.23 +
    3.24 +  Ptr<TapChannel> channel = CreateObject<TapChannel> ();
    3.25 +
    3.26 +  // the host.
    3.27 +  Ptr<Node> host = hosts.Get (0);
    3.28 +  Ptr<HostTapNetDevice> hostDev = CreateObject<HostTapNetDevice> ();
    3.29 +  hostDev->SetChannel (channel);
    3.30 +  hostDev->SetAddress (Mac48Address::Allocate ());
    3.31 +  host->AddDevice (hostDev);
    3.32 +  devices.Add (hostDev);
    3.33 +
    3.34 +  // the tap
    3.35 +  Ptr<Node> tap = taps.Get (0);
    3.36 +  Ptr<TapNetDevice> tapDev = CreateObject<TapNetDevice> ();
    3.37 +  tapDev->SetChannel (channel);
    3.38 +  tapDev->SetAddress (Mac48Address::Allocate ());
    3.39 +  tap->AddDevice (tapDev);
    3.40 +  devices.Add (tapDev);
    3.41 +
    3.42 +  return devices;
    3.43 +}
    3.44 +
    3.45 +void 
    3.46 +TapHelper::SetupHost (NetDeviceContainer dev, Ipv4Address ad, Ipv4Mask mask, Ipv4Address gateway)
    3.47 +{
    3.48 +  NS_ASSERT (dev.GetN () == 2);
    3.49 +  Ptr<TapNetDevice> tap = dev.Get (1)->GetObject<TapNetDevice> ();
    3.50 +  tap->SetupHost (ad, mask, gateway);
    3.51 +}
    3.52 +
    3.53 +static void TxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet, Mac48Address from, Mac48Address to)
    3.54 +{
    3.55 +  NS_LOG_FUNCTION (writer << packet << from << to);
    3.56 +  writer->WritePacket (packet);
    3.57 +}
    3.58 +static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet, Mac48Address from, Mac48Address to)
    3.59 +{
    3.60 +  NS_LOG_FUNCTION (writer << packet << from << to);
    3.61 +  writer->WritePacket (packet);
    3.62 +}
    3.63 +
    3.64 +
    3.65 +void 
    3.66 +TapHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
    3.67 +{
    3.68 +  std::ostringstream oss;
    3.69 +  oss << filename << "-" << nodeid << "-" << deviceid << ".pcap";
    3.70 +  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
    3.71 +  pcap->Open (oss.str ());
    3.72 +  pcap->WriteEthernetHeader ();
    3.73 +  oss.str ("");
    3.74 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::TapNetDevice/Rx";
    3.75 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&RxEvent, pcap));
    3.76 +  oss.str ("");
    3.77 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::TapNetDevice/Tx";
    3.78 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&TxEvent, pcap));
    3.79 +}
    3.80 +
    3.81 +void 
    3.82 +TapHelper::EnablePcap (std::string filename, NetDeviceContainer d)
    3.83 +{
    3.84 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
    3.85 +    {
    3.86 +      Ptr<NetDevice> dev = *i;
    3.87 +      EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ());
    3.88 +    }
    3.89 +}
    3.90 +void
    3.91 +TapHelper::EnablePcap (std::string filename, NodeContainer n)
    3.92 +{
    3.93 +  NetDeviceContainer devs;
    3.94 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
    3.95 +    {
    3.96 +      Ptr<Node> node = *i;
    3.97 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
    3.98 +	{
    3.99 +	  devs.Add (node->GetDevice (j));
   3.100 +	}
   3.101 +    }
   3.102 +  EnablePcap (filename, devs);
   3.103 +}
   3.104 +
   3.105 +void
   3.106 +TapHelper::EnablePcapAll (std::string filename)
   3.107 +{
   3.108 +  EnablePcap (filename, NodeContainer::GetGlobal ());
   3.109 +}
   3.110 +
   3.111 +
   3.112 +} // namespace ns3
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/helper/tap-helper.h	Mon Oct 27 23:05:57 2008 -0700
     4.3 @@ -0,0 +1,32 @@
     4.4 +#ifndef TAP_HELPER_H
     4.5 +#define TAP_HELPER_H
     4.6 +
     4.7 +#include "ns3/ipv4-address.h"
     4.8 +#include "node-container.h"
     4.9 +#include "net-device-container.h"
    4.10 +
    4.11 +namespace ns3 {
    4.12 +
    4.13 +class PcapWriter;
    4.14 +class Packet;
    4.15 +
    4.16 +class TapHelper 
    4.17 +{
    4.18 +public:
    4.19 +  /**
    4.20 +   * \param host a node which represents the host which our tap is connected to
    4.21 +   * \param tap the simulation node which should get a tap connected to the host.
    4.22 +   */
    4.23 +  NetDeviceContainer Install (NodeContainer host, NodeContainer tap);
    4.24 +  void SetupHost (NetDeviceContainer dev, Ipv4Address ad, Ipv4Mask mask, Ipv4Address gateway);
    4.25 +
    4.26 +  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
    4.27 +  static void EnablePcap (std::string filename, NetDeviceContainer d);
    4.28 +  static void EnablePcap (std::string filename, NodeContainer n);
    4.29 +  static void EnablePcapAll (std::string filename);
    4.30 +};
    4.31 +
    4.32 +
    4.33 +} // namespace ns3
    4.34 +
    4.35 +#endif /* TAP_HELPER_H */
     5.1 --- a/src/helper/wscript	Mon Oct 27 22:01:24 2008 -0700
     5.2 +++ b/src/helper/wscript	Mon Oct 27 23:05:57 2008 -0700
     5.3 @@ -10,6 +10,8 @@
     5.4          'static-multicast-route-helper.cc',
     5.5          'point-to-point-helper.cc',
     5.6          'csma-helper.cc',
     5.7 +        'emu-helper.cc',
     5.8 +        'tap-helper.cc',
     5.9          'mobility-helper.cc',
    5.10          'ns2-mobility-helper.cc',
    5.11          'ipv4-address-helper.cc',
    5.12 @@ -33,6 +35,8 @@
    5.13          'static-multicast-route-helper.h',
    5.14          'point-to-point-helper.h',
    5.15          'csma-helper.h',
    5.16 +        'emu-helper.h',
    5.17 +        'tap-helper.h',
    5.18          'mobility-helper.h',
    5.19          'ns2-mobility-helper.h',
    5.20          'ipv4-address-helper.h',