branch merge
authorCraig Dowell <craigdo@ee.washington.edu>
Mon Mar 31 13:54:57 2008 -0700 (24 months ago)
changeset 28543d483112bbdf
parent 2853 1cff5dd98f63
parent 2824 2bbedac578b1
child 2855 e1063ecd1585
branch merge
examples/tcp-large-transfer-errors.cc
examples/tcp-nonlistening-server.cc
examples/tcp-small-transfer-oneloss.cc
examples/tcp-small-transfer.cc
tutorial/ipv4-address-generator.cc
tutorial/ipv4-address-generator.h
tutorial/ipv4-bus-network.cc
tutorial/ipv4-bus-network.h
     1.1 --- a/examples/csma-broadcast.cc	Mon Mar 31 13:54:41 2008 -0700
     1.2 +++ b/examples/csma-broadcast.cc	Mon Mar 31 13:54:57 2008 -0700
     1.3 @@ -34,7 +34,6 @@
     1.4  
     1.5  #include "ns3/core-module.h"
     1.6  #include "ns3/helper-module.h"
     1.7 -#include "ns3/internet-node-module.h"
     1.8  #include "ns3/simulator-module.h"
     1.9  
    1.10  using namespace ns3;
    1.11 @@ -86,14 +85,6 @@
    1.12  
    1.13    NS_LOG_INFO ("Build Topology.");
    1.14    CsmaHelper csma;
    1.15 -  // Also configure some tcpdump traces; each interface will be traced
    1.16 -  // The output files will be named 
    1.17 -  // csma-broadcast.pcap-<nodeId>-<interfaceId>
    1.18 -  // and can be read by the "tcpdump -tt -r" command 
    1.19 -  csma.EnablePcap ("csma-broadcast.pcap");
    1.20 -  std::ofstream ascii;
    1.21 -  ascii.open ("csma-broadcast.tr");
    1.22 -  csma.EnableAscii (ascii);
    1.23    csma.SetChannelParameter ("BitRate", DataRate(5000000));
    1.24    csma.SetChannelParameter ("Delay", MilliSeconds(2));
    1.25  
    1.26 @@ -138,6 +129,14 @@
    1.27    sink.Build (c1.Get (1));
    1.28  
    1.29  
    1.30 +  // Also configure some tcpdump traces; each interface will be traced
    1.31 +  // The output files will be named 
    1.32 +  // csma-broadcast.pcap-<nodeId>-<interfaceId>
    1.33 +  // and can be read by the "tcpdump -tt -r" command 
    1.34 +  CsmaHelper::EnablePcap ("csma-broadcast.pcap");
    1.35 +  std::ofstream ascii;
    1.36 +  ascii.open ("csma-broadcast.tr");
    1.37 +  CsmaHelper::EnableAscii (ascii);
    1.38  
    1.39    NS_LOG_INFO ("Run Simulation.");
    1.40    Simulator::Run ();    
     2.1 --- a/examples/csma-multicast.cc	Mon Mar 31 13:54:41 2008 -0700
     2.2 +++ b/examples/csma-multicast.cc	Mon Mar 31 13:54:57 2008 -0700
     2.3 @@ -27,31 +27,14 @@
     2.4  // - Multicast source is at node n0;
     2.5  // - Multicast forwarded by node n2 onto LAN1;
     2.6  // - Nodes n0, n1, n2, n3, and n4 receive the multicast frame.
     2.7 -// - Node n4 listens for the data (actual listener not yet implementted)
     2.8 +// - Node n4 listens for the data 
     2.9  
    2.10 -#include "ns3/command-line.h"
    2.11 -#include "ns3/ptr.h"
    2.12 -#include "ns3/random-variable.h"
    2.13 -#include "ns3/log.h"
    2.14 -#include "ns3/simulator.h"
    2.15 -#include "ns3/nstime.h"
    2.16 -#include "ns3/data-rate.h"
    2.17 -#include "ns3/ascii-trace.h"
    2.18 -#include "ns3/pcap-trace.h"
    2.19 -#include "ns3/internet-node.h"
    2.20 -#include "ns3/csma-channel.h"
    2.21 -#include "ns3/csma-net-device.h"
    2.22 -#include "ns3/csma-topology.h"
    2.23 -#include "ns3/csma-ipv4-topology.h"
    2.24 -#include "ns3/mac48-address.h"
    2.25 -#include "ns3/ipv4-address.h"
    2.26 -#include "ns3/inet-socket-address.h"
    2.27 -#include "ns3/ipv4.h"
    2.28 -#include "ns3/socket.h"
    2.29 -#include "ns3/ipv4-route.h"
    2.30 -#include "ns3/onoff-application.h"
    2.31 -#include "ns3/packet-sink.h"
    2.32 -#include "ns3/uinteger.h"
    2.33 +#include <iostream>
    2.34 +#include <fstream>
    2.35 +
    2.36 +#include "ns3/core-module.h"
    2.37 +#include "ns3/helper-module.h"
    2.38 +#include "ns3/simulator-module.h"
    2.39  
    2.40  using namespace ns3;
    2.41  
    2.42 @@ -60,268 +43,140 @@
    2.43  int 
    2.44  main (int argc, char *argv[])
    2.45  {
    2.46 -//
    2.47 -// Users may find it convenient to turn on explicit debugging
    2.48 -// for selected modules; the below lines suggest how to do this
    2.49 -//
    2.50 -#if 0
    2.51 -  LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
    2.52 +  //
    2.53 +  // Users may find it convenient to turn on explicit debugging
    2.54 +  // for selected modules; the below lines suggest how to do this
    2.55 +  //
    2.56 +  // LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
    2.57  
    2.58 -  LogComponentEnable("Object", LOG_LEVEL_ALL);
    2.59 -  LogComponentEnable("Queue", LOG_LEVEL_ALL);
    2.60 -  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
    2.61 -  LogComponentEnable("Channel", LOG_LEVEL_ALL);
    2.62 -  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
    2.63 -  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
    2.64 -  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
    2.65 -  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
    2.66 -  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
    2.67 -  LogComponentEnable("Socket", LOG_LEVEL_ALL);
    2.68 -  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
    2.69 -  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
    2.70 -  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
    2.71 -  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
    2.72 -  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
    2.73 -  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
    2.74 -  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
    2.75 -  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
    2.76 -  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
    2.77 -  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
    2.78 -  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
    2.79 -  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
    2.80 -#endif
    2.81 -//
    2.82 -// Set up default values for the simulation.  Use the DefaultValue::Bind()
    2.83 +  //
    2.84 +  // Set up default values for the simulation.  
    2.85 +  //
    2.86 +  // Select Ethernet II-style encapsulation (no LLC/Snap header)
    2.87 +  Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", String ("IpArp"));  
    2.88  
    2.89 -// Allow the user to override any of the defaults and the above Bind() at
    2.90 -// run-time, via command-line arguments
    2.91 -//
    2.92 +  // Allow the user to override any of the defaults at
    2.93 +  // run-time, via command-line arguments
    2.94    CommandLine cmd;
    2.95    cmd.Parse (argc, argv);
    2.96 -//
    2.97 -// Explicitly create the nodes required by the topology (shown above).
    2.98 -//
    2.99 +
   2.100    NS_LOG_INFO ("Create nodes.");
   2.101 -  Ptr<Node> n0 = CreateObject<InternetNode> ();
   2.102 -  Ptr<Node> n1 = CreateObject<InternetNode> (); 
   2.103 -  Ptr<Node> n2 = CreateObject<InternetNode> (); 
   2.104 -  Ptr<Node> n3 = CreateObject<InternetNode> ();
   2.105 -  Ptr<Node> n4 = CreateObject<InternetNode> ();
   2.106 +  NodeContainer c;
   2.107 +  c.Create (5);
   2.108 +  // We will later want two subcontainers of these nodes, for the two LANs
   2.109 +  NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
   2.110 +  NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
   2.111 +  
   2.112 +  NS_LOG_INFO ("Build Topology.");
   2.113 +  CsmaHelper csma;
   2.114 +  csma.SetChannelParameter ("BitRate", DataRate (5000000));
   2.115 +  csma.SetChannelParameter ("Delay", MilliSeconds (2));
   2.116 + 
   2.117 +  // We will use these NetDevice containers later, for IP addressing
   2.118 +  NetDeviceContainer nd0 = csma.Build (c0);  // First LAN
   2.119 +  NetDeviceContainer nd1 = csma.Build (c1);  // Second LAN
   2.120  
   2.121 -  NS_LOG_INFO ("Create channels.");
   2.122 -//
   2.123 -// Explicitly create the channels required by the topology (shown above).
   2.124 -//
   2.125 -  Ptr<CsmaChannel> lan0 = 
   2.126 -    CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
   2.127 +  NS_LOG_INFO ("Add IP Stack.");
   2.128 +  InternetStackHelper internet;
   2.129 +  internet.Build (c0);
   2.130 +  internet.Build (c1);
   2.131  
   2.132 -  Ptr<CsmaChannel> lan1 = 
   2.133 -    CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
   2.134 -
   2.135 -  NS_LOG_INFO ("Build Topology.");
   2.136 -//
   2.137 -// Now fill out the topology by creating the net devices required to connect
   2.138 -// the nodes to the channels and hooking them up.  AddIpv4CsmaNetDevice will
   2.139 -// create a net device, add a MAC address (in memory of the pink flamingo) and
   2.140 -// connect the net device to a nodes and also to a channel. the 
   2.141 -// AddIpv4CsmaNetDevice method returns a net device index for the net device
   2.142 -// created on the node.  Interpret nd0 as the net device we created for node
   2.143 -// zero.  Interpret nd2Lan0 as the net device we created for node two to
   2.144 -// connect to Lan0. 
   2.145 -//
   2.146 -  uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan0, 
   2.147 -    Mac48Address("08:00:2e:00:00:00"));
   2.148 -  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan0, 
   2.149 -    Mac48Address("08:00:2e:00:00:01"));
   2.150 -  uint32_t nd2Lan0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan0, 
   2.151 -    Mac48Address("08:00:2e:00:00:02"));
   2.152 -
   2.153 -  uint32_t nd2Lan1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1, 
   2.154 -    Mac48Address("08:00:2e:00:00:03"));
   2.155 -  uint32_t nd3 __attribute__ ((unused)) = 
   2.156 -    CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1, 
   2.157 -    Mac48Address("08:00:2e:00:00:04"));
   2.158 -  uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan1, 
   2.159 -    Mac48Address("08:00:2e:00:00:05"));
   2.160 -
   2.161 -  NS_LOG_INFO ("nd0 = " << nd0);
   2.162 -  NS_LOG_INFO ("nd1 = " << nd1);
   2.163 -  NS_LOG_INFO ("nd2Lan0 = " << nd2Lan0);
   2.164 -  NS_LOG_INFO ("nd2Lan1 = " << nd2Lan1);
   2.165 -  NS_LOG_INFO ("nd3 = " << nd3);
   2.166 -  NS_LOG_INFO ("nd4 = " << nd3);
   2.167 -//
   2.168 -// We've got the "hardware" in place.  Now we need to add IP addresses.
   2.169 -//
   2.170    NS_LOG_INFO ("Assign IP Addresses.");
   2.171 -  CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address ("10.1.1.1"), 
   2.172 -    Ipv4Mask ("255.255.255.0"));
   2.173 -
   2.174 -  CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address ("10.1.1.2"), 
   2.175 -    Ipv4Mask ("255.255.255.0"));
   2.176 -
   2.177 -//
   2.178 -// We'll need these addresses later
   2.179 -//
   2.180 -  Ipv4Address n2Lan0Addr ("10.1.1.3");
   2.181 -  Ipv4Address n2Lan1Addr ("10.1.2.1");
   2.182 -
   2.183 -  CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan0, n2Lan0Addr, 
   2.184 -    Ipv4Mask ("255.255.255.0"));
   2.185 -//
   2.186 -// Assign IP addresses to the net devices and associated interfaces on Lan1
   2.187 -//
   2.188 -  CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan1, n2Lan1Addr, 
   2.189 -    Ipv4Mask ("255.255.255.0"));
   2.190 -
   2.191 -  CsmaIpv4Topology::AddIpv4Address (n3, nd1, Ipv4Address ("10.1.2.2"), 
   2.192 -    Ipv4Mask ("255.255.255.0"));
   2.193 -
   2.194 -  CsmaIpv4Topology::AddIpv4Address (n4, nd4, Ipv4Address ("10.1.2.3"), 
   2.195 -    Ipv4Mask ("255.255.255.0"));
   2.196 +  Ipv4AddressHelper ipv4Addr;
   2.197 +  ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0");
   2.198 +  ipv4Addr.Allocate (nd0);
   2.199 +  ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0");
   2.200 +  ipv4Addr.Allocate (nd1);
   2.201  
   2.202    NS_LOG_INFO ("Configure multicasting.");
   2.203 -//
   2.204 -// Now we can configure multicasting.  As described above, the multicast 
   2.205 -// source is at node zero, which we assigned the IP address of 10.1.1.1 
   2.206 -// earlier.  We need to define a multicast group to send packets to.  This
   2.207 -// can be any multicast address from 224.0.0.0 through 239.255.255.255
   2.208 -// (avoiding the reserved routing protocol addresses).  We just pick a
   2.209 -// convenient number (225.0.0.0) and or in some bits to let us verify that
   2.210 -// correct Ethernet multicast addresses are constructed down in the system. 
   2.211 -//
   2.212 +  //
   2.213 +  // Now we can configure multicasting.  As described above, the multicast 
   2.214 +  // source is at node zero, which we assigned the IP address of 10.1.1.1 
   2.215 +  // earlier.  We need to define a multicast group to send packets to.  This
   2.216 +  // can be any multicast address from 224.0.0.0 through 239.255.255.255
   2.217 +  // (avoiding the reserved routing protocol addresses).  
   2.218 +  //
   2.219 +
   2.220    Ipv4Address multicastSource ("10.1.1.1");
   2.221    Ipv4Address multicastGroup ("225.1.2.4");
   2.222 -//
   2.223 -// We are going to manually configure multicast routing.  This means telling
   2.224 -// node two that it should expect multicast data coming from IP address 
   2.225 -// 10.1.1.1 originally.  It should expect these data coming in over its IP 
   2.226 -// interface connected to Lan0.  When node two receives these packets, they
   2.227 -// should be forwarded out the interface that connects it to Lan1.
   2.228 -//
   2.229 -// We're going to need the interface indices on node two corresponding to 
   2.230 -// these interfaces, which we call ifIndexLan0 and ifIndexLan1.  The most
   2.231 -// general way to get these interfaces is to look them up by IP address.
   2.232 -// Looking back to the topology creation calls above, we saved the addresses
   2.233 -// assigned to the interface connecting node two to Lan0 and Lan1.  Now is
   2.234 -// a fine time to find the interface indices on node two.
   2.235 -//
   2.236 -  Ptr<Ipv4> ipv4;
   2.237 -  ipv4 = n2->GetObject<Ipv4> ();
   2.238  
   2.239 -  uint32_t ifIndexLan0 = ipv4->FindInterfaceForAddr (n2Lan0Addr);
   2.240 -  uint32_t ifIndexLan1 = ipv4->FindInterfaceForAddr (n2Lan1Addr);
   2.241 -//
   2.242 -// Now, we need to do is to call the AddMulticastRoute () method on node 
   2.243 -// two's Ipv4 interface and tell it that whenever it receives a packet on
   2.244 -// the interface from Lan0, with the packet from the multicast source, 
   2.245 -// destined for the multicast group, it should forward these packets down
   2.246 -// the interface connecting it to Lan1.  (Note: the vector of output
   2.247 -// interfaces is in case there are multiple net devices on a node -- not
   2.248 -// true in this case).
   2.249 -//
   2.250 -  std::vector<uint32_t> outputInterfaces (1);
   2.251 -  outputInterfaces[0] = ifIndexLan1;
   2.252 +  // Now, we will set up multicast routing.  We need to do three things:
   2.253 +  // 1) Configure a (static) multicast route on node n2
   2.254 +  // 2) Set up a default multicast route on the sender n0 
   2.255 +  // 3) Have node n4 join the multicast group
   2.256 +  // We have a helper that can help us with static multicast
   2.257 +  StaticMulticastRouteHelper multicast;
   2.258  
   2.259 -  ipv4->AddMulticastRoute (multicastSource, multicastGroup, ifIndexLan0,
   2.260 -    outputInterfaces);
   2.261 -//
   2.262 -// We need to specify how the source node handles multicasting.  There are a
   2.263 -// number of ways we can deal with this, we just need to pick one.  The first
   2.264 -// method is to add an explicit route out of the source node, just as we did
   2.265 -// for the forwarding node.  Use this method when you want to send packets out
   2.266 -// multiple interfaces or send packets out different interfaces based on the
   2.267 -// differing multicast groups.  Since the source is local, there will be no 
   2.268 -// input interface over which packets are received, so use  
   2.269 -// Ipv4RoutingProtocol::IF_INDEX_ANY as a wildcard.
   2.270 -//
   2.271 -// A second way is to specify a multicast route using wildcards.  If you 
   2.272 -// want to send multicasts out differing sets of interfaces based on the 
   2.273 -// multicast group, you can use AddMulticastRoute () but specify the origin 
   2.274 -// as a wildcard.  If you want all multicasts to go out a single set of 
   2.275 -// interfaces, you can make both the origin and group a wildcard.
   2.276 -//
   2.277 -// If you have a simple system, where the source has a single interface, this
   2.278 -// can be done via the SetDefaultMulticastRoute () method on the Ipv4 
   2.279 -// interface.  This tells the system to send all multicasts out a single
   2.280 -// specified network interface index.
   2.281 -//
   2.282 -// A last way is to specify a (or use an existing) default unicast route.  The
   2.283 -// multicast routing code uses the unicast default route as a multicast "route
   2.284 -// of last resort."  this method for is also on Ipv4 and is called 
   2.285 -// SetDefaultRoute ().
   2.286 -//
   2.287 -// Since this is a simple multicast example, we use the 
   2.288 -// SetDefaultMulticastRoute () approach.  We are going to first need the 
   2.289 -// Ipv4 interface for node 0 which is the multicast source.  We use this
   2.290 -// interface to find the output interface index, and tell node zero to send
   2.291 -// its multicast traffic out that interface.
   2.292 -//
   2.293 -  ipv4 = n0->GetObject<Ipv4> ();
   2.294 -  uint32_t ifIndexSrc = ipv4->FindInterfaceForAddr (multicastSource);
   2.295 -  ipv4->SetDefaultMulticastRoute (ifIndexSrc);
   2.296 -//
   2.297 -// As described above, node four will be the only node listening for the
   2.298 -// multicast data.  To enable forwarding bits up the protocol stack, we need
   2.299 -// to tell the stack to join the multicast group.
   2.300 -//
   2.301 -  ipv4 = n4->GetObject<Ipv4> ();
   2.302 -  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
   2.303 -//
   2.304 -// Create an OnOff application to send UDP datagrams from node zero to the
   2.305 -// multicast group (node four will be listening).
   2.306 -//
   2.307 +  // 1) Configure a (static) multicast route on node n2 (multicastRouter)
   2.308 +  Ptr<Node> multicastRouter = c.Get (2);  // The node in question
   2.309 +  Ptr<NetDevice> inputIf = nd0.Get (2);  // The input NetDevice
   2.310 +  NetDeviceContainer outputDevices;  // A container of output NetDevices
   2.311 +  outputDevices.Add (nd1.Get (0));  // (we only need one NetDevice here)
   2.312 +
   2.313 +  multicast.AddMulticastRoute (multicastRouter, multicastSource, 
   2.314 +    multicastGroup, inputIf, outputDevices);
   2.315 +  
   2.316 +  // 2) Set up a default multicast route on the sender n0 
   2.317 +  Ptr<Node> sender = c.Get (0);
   2.318 +  Ptr<NetDevice> senderIf = nd0.Get(0);
   2.319 +  multicast.SetDefaultMulticastRoute (sender, senderIf);
   2.320 +
   2.321 +  // 3) Have node n4 join the multicast group
   2.322 +  Ptr<Node> receiver = c.Get (4);
   2.323 +  multicast.JoinMulticastGroup (receiver, multicastSource, multicastGroup);
   2.324 +  
   2.325 +  //
   2.326 +  // Create an OnOff application to send UDP datagrams from node zero to the
   2.327 +  // multicast group (node four will be listening).
   2.328 +  //
   2.329    NS_LOG_INFO ("Create Applications.");
   2.330  
   2.331 -  uint16_t port = 9;   // Discard port (RFC 863)
   2.332 +  uint16_t multicastPort = 9;   // Discard port (RFC 863)
   2.333  
   2.334    // Configure a multicast packet generator that generates a packet
   2.335    // every few seconds
   2.336 -  Ptr<OnOffApplication> ooff = 
   2.337 -    CreateObject<OnOffApplication> ("Remote", Address (InetSocketAddress (multicastGroup, port)), 
   2.338 -                                    "Protocol", TypeId::LookupByName ("ns3::Udp"),
   2.339 -                                    "OnTime", ConstantVariable(1), 
   2.340 -                                    "OffTime", ConstantVariable(0),
   2.341 -                                    "DataRate", DataRate ("255b/s"),
   2.342 -                                    "PacketSize", Uinteger (128));
   2.343 -  n0->AddApplication (ooff);
   2.344 -//
   2.345 -// Tell the application when to start and stop.
   2.346 -//
   2.347 -  ooff->Start(Seconds(1.));
   2.348 -  ooff->Stop (Seconds(10.));
   2.349 +  OnOffHelper onoff;
   2.350 +  onoff.SetUdpRemote (multicastGroup, multicastPort);
   2.351 +  onoff.SetAppAttribute ("OnTime", ConstantVariable (1));
   2.352 +  onoff.SetAppAttribute ("OffTime", ConstantVariable (0));
   2.353 +  onoff.SetAppAttribute ("DataRate", DataRate ("255b/s"));
   2.354 +  onoff.SetAppAttribute ("PacketSize", Uinteger (128));
   2.355 +
   2.356 +  ApplicationContainer srcC = onoff.Build (c0.Get (0));
   2.357 +
   2.358 +  //
   2.359 +  // Tell the application when to start and stop.
   2.360 +  //
   2.361 +  srcC.Start(Seconds(1.));
   2.362 +  srcC.Stop (Seconds(10.));
   2.363  
   2.364    // Create an optional packet sink to receive these packets
   2.365 -  // If you enable logging on this (above) it will print a log statement
   2.366 -  // for every packet received
   2.367 -  Ptr<PacketSink> sink = 
   2.368 -    CreateObject<PacketSink> ("Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
   2.369 -                              "Protocol", TypeId::LookupByName ("ns3::Udp"));
   2.370 -  n4->AddApplication (sink);
   2.371 +  PacketSinkHelper sink;
   2.372 +  sink.SetupUdp (Ipv4Address::GetAny(), multicastPort);
   2.373 +  ApplicationContainer sinkC = sink.Build (c1.Get (2)); // Node n4 
   2.374    // Start the sink
   2.375 -  sink->Start (Seconds (1.0));
   2.376 -  sink->Stop (Seconds (10.0));
   2.377 +  sinkC.Start (Seconds (1.0));
   2.378 +  sinkC.Stop (Seconds (10.0));
   2.379  
   2.380 -//
   2.381 -// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
   2.382 -// Trace output will be sent to the file "csma-multicast.tr"
   2.383 -//
   2.384 +  //
   2.385 +  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
   2.386    NS_LOG_INFO ("Configure Tracing.");
   2.387 -  AsciiTrace asciitrace ("csma-multicast.tr");
   2.388 -  asciitrace.TraceAllNetDeviceRx ();
   2.389 -  asciitrace.TraceAllQueues ();
   2.390 -//
   2.391 -// Also configure some tcpdump traces; each interface will be traced.
   2.392 -// The output files will be named:
   2.393 -//     csma-multicast.pcap-<nodeId>-<interfaceId>
   2.394 -// and can be read by the "tcpdump -r" command (use "-tt" option to
   2.395 -// display timestamps correctly)
   2.396 -//
   2.397 -  PcapTrace pcaptrace ("csma-multicast.pcap");
   2.398 -  pcaptrace.TraceAllIp ();
   2.399 -//
   2.400 -// Now, do the actual simulation.
   2.401 -//
   2.402 +  //
   2.403 +  // Ascii trace output will be sent to the file "csma-multicast.tr"
   2.404 +  //
   2.405 +  std::ofstream ascii;
   2.406 +  ascii.open ("csma-multicast.tr");
   2.407 +  CsmaHelper::EnableAscii (ascii);
   2.408 +
   2.409 +  // Also configure some tcpdump traces; each interface will be traced.
   2.410 +  // The output files will be named:
   2.411 +  //     csma-multicast.pcap-<nodeId>-<interfaceId>
   2.412 +  // and can be read by the "tcpdump -r" command (use "-tt" option to
   2.413 +  // display timestamps correctly)
   2.414 +  CsmaHelper::EnablePcap ("csma-multicast.pcap");
   2.415 +  //
   2.416 +  // Now, do the actual simulation.
   2.417 +  //
   2.418    NS_LOG_INFO ("Run Simulation.");
   2.419    Simulator::Run ();
   2.420    Simulator::Destroy ();
     3.1 --- a/examples/csma-one-subnet.cc	Mon Mar 31 13:54:41 2008 -0700
     3.2 +++ b/examples/csma-one-subnet.cc	Mon Mar 31 13:54:57 2008 -0700
     3.3 @@ -25,27 +25,12 @@
     3.4  // - DropTail queues 
     3.5  // - Tracing of queues and packet receptions to file "csma-one-subnet.tr"
     3.6  
     3.7 -#include "ns3/command-line.h"
     3.8 -#include "ns3/ptr.h"
     3.9 -#include "ns3/random-variable.h"
    3.10 -#include "ns3/log.h"
    3.11 -#include "ns3/simulator.h"
    3.12 -#include "ns3/nstime.h"
    3.13 -#include "ns3/data-rate.h"
    3.14 -#include "ns3/ascii-trace.h"
    3.15 -#include "ns3/pcap-trace.h"
    3.16 -#include "ns3/internet-node.h"
    3.17 -#include "ns3/csma-channel.h"
    3.18 -#include "ns3/csma-net-device.h"
    3.19 -#include "ns3/csma-topology.h"
    3.20 -#include "ns3/csma-ipv4-topology.h"
    3.21 -#include "ns3/mac48-address.h"
    3.22 -#include "ns3/ipv4-address.h"
    3.23 -#include "ns3/inet-socket-address.h"
    3.24 -#include "ns3/ipv4.h"
    3.25 -#include "ns3/socket.h"
    3.26 -#include "ns3/ipv4-route.h"
    3.27 -#include "ns3/onoff-application.h"
    3.28 +#include <iostream>
    3.29 +#include <fstream>
    3.30 +
    3.31 +#include "ns3/simulator-module.h"
    3.32 +#include "ns3/core-module.h"
    3.33 +#include "ns3/helper-module.h"
    3.34  
    3.35  using namespace ns3;
    3.36  
    3.37 @@ -60,28 +45,6 @@
    3.38  //
    3.39  #if 0 
    3.40    LogComponentEnable ("CsmaOneSubnetExample", LOG_LEVEL_INFO);
    3.41 -
    3.42 -  LogComponentEnable("Object", LOG_LEVEL_ALL);
    3.43 -  LogComponentEnable("Queue", LOG_LEVEL_ALL);
    3.44 -  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
    3.45 -  LogComponentEnable("Channel", LOG_LEVEL_ALL);
    3.46 -  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
    3.47 -  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
    3.48 -  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
    3.49 -  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
    3.50 -  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
    3.51 -  LogComponentEnable("Socket", LOG_LEVEL_ALL);
    3.52 -  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
    3.53 -  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
    3.54 -  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
    3.55 -  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
    3.56 -  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
    3.57 -  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
    3.58 -  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
    3.59 -  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
    3.60 -  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
    3.61 -  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
    3.62 -  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
    3.63  #endif
    3.64  //
    3.65  //
    3.66 @@ -94,19 +57,13 @@
    3.67  // Explicitly create the nodes required by the topology (shown above).
    3.68  //
    3.69    NS_LOG_INFO ("Create nodes.");
    3.70 -  Ptr<Node> n0 = CreateObject<InternetNode> ();
    3.71 -  Ptr<Node> n1 = CreateObject<InternetNode> (); 
    3.72 -  Ptr<Node> n2 = CreateObject<InternetNode> (); 
    3.73 -  Ptr<Node> n3 = CreateObject<InternetNode> ();
    3.74 +  NodeContainer c;
    3.75 +  c.Create (4);
    3.76  
    3.77 -  NS_LOG_INFO ("Create channels.");
    3.78 -//
    3.79 -// Explicitly create the channels required by the topology (shown above).
    3.80 -//
    3.81 -  Ptr<CsmaChannel> lan = CsmaTopology::CreateCsmaChannel(
    3.82 -    DataRate(5000000), MilliSeconds(2));
    3.83 -
    3.84 -  NS_LOG_INFO ("Build Topology.");
    3.85 +  NS_LOG_INFO ("Build Topology");
    3.86 +  CsmaHelper csma;
    3.87 +  csma.SetChannelParameter ("BitRate", DataRate (5000000));
    3.88 +  csma.SetChannelParameter ("Delay", MilliSeconds (2));
    3.89  //
    3.90  // Now fill out the topology by creating the net devices required to connect
    3.91  // the nodes to the channels and hooking them up.  AddIpv4CsmaNetDevice will
    3.92 @@ -116,80 +73,57 @@
    3.93  // created on the node.  Interpret nd0 as the net device we created for node
    3.94  // zero.
    3.95  //
    3.96 -  uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, 
    3.97 -    Mac48Address("08:00:2e:00:00:00"));
    3.98 +  NetDeviceContainer nd0 = csma.Build (c);
    3.99  
   3.100 -  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, 
   3.101 -    Mac48Address("08:00:2e:00:00:01"));
   3.102 +  InternetStackHelper internet;
   3.103 +  internet.Build (c);
   3.104  
   3.105 -  uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, 
   3.106 -    Mac48Address("08:00:2e:00:00:02"));
   3.107 -
   3.108 -  uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, 
   3.109 -    Mac48Address("08:00:2e:00:00:03"));
   3.110 -//
   3.111  // We've got the "hardware" in place.  Now we need to add IP addresses.
   3.112  //
   3.113    NS_LOG_INFO ("Assign IP Addresses.");
   3.114 -//
   3.115 -// XXX BUGBUG
   3.116 -// Need a better way to get the interface index.  The point-to-point topology
   3.117 -// as implemented can't return the index since it creates interfaces on both
   3.118 -// sides (i.e., it does AddIpv4Addresses, not AddIpv4Address).  We need a
   3.119 -// method on Ipv4 to find the interface index corresponding to a given ipv4 
   3.120 -// address.
   3.121 -//
   3.122 -// Assign IP addresses to the net devices and associated interfaces
   3.123 -// on the lan.  The AddIpv4Address method returns an Ipv4 interface index
   3.124 -// which we do not need here.
   3.125 -//
   3.126 -  CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address("10.1.1.1"), 
   3.127 -    Ipv4Mask("255.255.255.0"));
   3.128 +  Ipv4AddressHelper ipv4;
   3.129 +  ipv4.SetBase ("10.1.1.0", "255.255.255.0");
   3.130 +  ipv4.Allocate (nd0);
   3.131  
   3.132 -  CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address("10.1.1.2"), 
   3.133 -    Ipv4Mask("255.255.255.0"));
   3.134 -
   3.135 -  CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address("10.1.1.3"), 
   3.136 -    Ipv4Mask("255.255.255.0"));
   3.137 -  
   3.138 -  CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address("10.1.1.4"), 
   3.139 -    Ipv4Mask("255.255.255.0"));
   3.140  //
   3.141  // Create an OnOff application to send UDP datagrams from node zero to node 1.
   3.142  //
   3.143    NS_LOG_INFO ("Create Applications.");
   3.144    uint16_t port = 9;   // Discard port (RFC 863)
   3.145 -  Ptr<OnOffApplication> ooff = 
   3.146 -    CreateObject<OnOffApplication> ("Remote", Address (InetSocketAddress ("10.1.1.2", port)), 
   3.147 -                                    "Protocol", TypeId::LookupByName ("ns3::Udp"),
   3.148 -                                    "OnTime", ConstantVariable(1), 
   3.149 -                                    "OffTime", ConstantVariable(0));
   3.150 -  n0->AddApplication (ooff);
   3.151  
   3.152 -//
   3.153 -// Tell the application when to start and stop.
   3.154 -//
   3.155 -  ooff->Start(Seconds(1.0));
   3.156 -  ooff->Stop (Seconds(10.0));
   3.157 +  OnOffHelper onoff;
   3.158 +  onoff.SetUdpRemote (Ipv4Address ("10.1.1.2"), port);
   3.159 +  onoff.SetAppAttribute ("OnTime", ConstantVariable (1));
   3.160 +  onoff.SetAppAttribute ("OffTime", ConstantVariable (0));
   3.161 +
   3.162 +  ApplicationContainer app = onoff.Build (c.Get (0));
   3.163 +  // Start the application
   3.164 +  app.Start (Seconds (1.0));
   3.165 +  app.Stop (Seconds (10.0));
   3.166 +
   3.167 +  // Create an optional packet sink to receive these packets
   3.168 +  PacketSinkHelper sink;
   3.169 +  sink.SetupUdp (Ipv4Address::GetAny (), port);
   3.170 +  sink.Build (c.Get (1));
   3.171 +
   3.172  // 
   3.173  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
   3.174  //
   3.175 -  ooff = CreateObject<OnOffApplication> ("Remote", Address (InetSocketAddress ("10.1.1.1", port)), 
   3.176 -                                         "Protocol", TypeId::LookupByName ("ns3::Udp"),
   3.177 -                                         "OnTime", ConstantVariable(1), 
   3.178 -                                         "OffTime", ConstantVariable(0));
   3.179 -  n3->AddApplication (ooff);
   3.180 +  onoff.SetUdpRemote (Ipv4Address("10.1.1.1"), port);
   3.181 +  ApplicationContainer app2 = onoff.Build (c.Get (3));
   3.182  
   3.183 -  ooff->Start(Seconds(1.1));
   3.184 -  ooff->Stop (Seconds(10.0));
   3.185 +  sink.Build (c.Get (0));
   3.186 +
   3.187 +  app2.Start(Seconds (1.1));
   3.188 +  app2.Stop (Seconds (10.0));
   3.189  //
   3.190  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
   3.191  // Trace output will be sent to the file "csma-one-subnet.tr"
   3.192  //
   3.193 -   NS_LOG_INFO ("Configure Tracing.");
   3.194 -  AsciiTrace asciitrace ("csma-one-subnet.tr");
   3.195 -  asciitrace.TraceAllNetDeviceRx ();
   3.196 -  asciitrace.TraceAllQueues ();
   3.197 +  NS_LOG_INFO ("Configure Tracing.");
   3.198 +  std::ofstream ascii;
   3.199 +  ascii.open ("csma-one-subnet.tr");
   3.200 +  CsmaHelper::EnableAscii (ascii);
   3.201  //
   3.202  // Also configure some tcpdump traces; each interface will be traced.
   3.203  // The output files will be named:
   3.204 @@ -197,8 +131,7 @@
   3.205  // and can be read by the "tcpdump -r" command (use "-tt" option to
   3.206  // display timestamps correctly)
   3.207  //
   3.208 -  PcapTrace pcaptrace ("csma-one-subnet.pcap");
   3.209 -  pcaptrace.TraceAllIp ();
   3.210 +  CsmaHelper::EnablePcap ("csma-one-subnet.pcap");
   3.211  //
   3.212  // Now, do the actual simulation.
   3.213  //
     4.1 --- a/examples/mixed-global-routing.cc	Mon Mar 31 13:54:41 2008 -0700
     4.2 +++ b/examples/mixed-global-routing.cc	Mon Mar 31 13:54:57 2008 -0700
     4.3 @@ -152,19 +152,13 @@
     4.4    apps.Start (Seconds (1.0));
     4.5    apps.Stop (Seconds (10.0));
     4.6  
     4.7 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
     4.8 -  // Trace output will be sent to the simple-global-routing.tr file
     4.9 -  NS_LOG_INFO ("Configure Tracing.");
    4.10 -  AsciiTrace asciitrace ("mixed-global-routing.tr");
    4.11 -  asciitrace.TraceAllQueues ();
    4.12 -  asciitrace.TraceAllNetDeviceRx ();
    4.13 +  std::ofstream ascii;
    4.14 +  ascii.open ("mixed-global-routing.tr");
    4.15 +  PointToPointHelper::EnablePcap ("mixed-global-routing.pcap");
    4.16 +  PointToPointHelper::EnableAscii (ascii);
    4.17 +  CsmaHelper::EnablePcap ("mixed-global-routing.pcap");
    4.18 +  CsmaHelper::EnableAscii (ascii);
    4.19  
    4.20 -  // Also configure some tcpdump traces; each interface will be traced
    4.21 -  // The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId>
    4.22 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
    4.23 -  // display timestamps correctly)
    4.24 -  PcapTrace pcaptrace ("mixed-global-routing.pcap");
    4.25 -  pcaptrace.TraceAllIp ();
    4.26  
    4.27    NS_LOG_INFO ("Run Simulation.");
    4.28    Simulator::Run ();
     5.1 --- a/examples/simple-alternate-routing.cc	Mon Mar 31 13:54:41 2008 -0700
     5.2 +++ b/examples/simple-alternate-routing.cc	Mon Mar 31 13:54:57 2008 -0700
     5.3 @@ -41,8 +41,6 @@
     5.4  #include "ns3/simulator-module.h"
     5.5  #include "ns3/helper-module.h"
     5.6  #include "ns3/global-route-manager.h"
     5.7 -#include "ns3/ascii-trace.h"
     5.8 -#include "ns3/pcap-trace.h"
     5.9  
    5.10  using namespace ns3;
    5.11  
    5.12 @@ -177,19 +175,11 @@
    5.13    apps.Start (Seconds (1.1));
    5.14    apps.Stop (Seconds (10.0));
    5.15  
    5.16 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
    5.17 -  // Trace output will be sent to the simple-alternate-routing.tr file
    5.18 -  NS_LOG_INFO ("Configure Tracing.");
    5.19 -  AsciiTrace asciitrace ("simple-alternate-routing.tr");
    5.20 -  asciitrace.TraceAllQueues ();
    5.21 -  asciitrace.TraceAllNetDeviceRx ();
    5.22 +  std::ofstream ascii;
    5.23 +  ascii.open ("simple-alternate-routing.tr");
    5.24 +  PointToPointHelper::EnablePcap ("simple-alternate-routing.pcap");
    5.25 +  PointToPointHelper::EnableAscii (ascii);
    5.26  
    5.27 -  // Also configure some tcpdump traces; each interface will be traced
    5.28 -  // The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId>
    5.29 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
    5.30 -  // display timestamps correctly)
    5.31 -  PcapTrace pcaptrace ("simple-alternate-routing.pcap");
    5.32 -  pcaptrace.TraceAllIp ();
    5.33  
    5.34    NS_LOG_INFO ("Run Simulation.");
    5.35    Simulator::Run ();
     6.1 --- a/examples/simple-error-model.cc	Mon Mar 31 13:54:41 2008 -0700
     6.2 +++ b/examples/simple-error-model.cc	Mon Mar 31 13:54:57 2008 -0700
     6.3 @@ -38,12 +38,11 @@
     6.4  // - Tracing of queues and packet receptions to file 
     6.5  //   "simple-error-model.tr"
     6.6  
     6.7 +#include <fstream>
     6.8  #include "ns3/core-module.h"
     6.9  #include "ns3/common-module.h"
    6.10  #include "ns3/simulator-module.h"
    6.11  #include "ns3/helper-module.h"
    6.12 -#include "ns3/ascii-trace.h"
    6.13 -#include "ns3/pcap-trace.h"
    6.14  #include "ns3/global-route-manager.h"
    6.15  
    6.16  using namespace ns3;
    6.17 @@ -162,12 +161,10 @@
    6.18    pem->SetList (sampleList);
    6.19    d0d2.Get (1)->SetAttribute ("ReceiveErrorModel", pem);
    6.20  
    6.21 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
    6.22 -  // Trace output will be sent to the simple-error-model.tr file
    6.23 -  NS_LOG_INFO ("Configure Tracing.");
    6.24 -  AsciiTrace asciitrace ("simple-error-model.tr");
    6.25 -  asciitrace.TraceAllQueues ();
    6.26 -  asciitrace.TraceAllNetDeviceRx ();
    6.27 +  std::ofstream ascii;
    6.28 +  ascii.open ("simple-error-model.tr");
    6.29 +  PointToPointHelper::EnablePcap ("simple-error-model.pcap");
    6.30 +  PointToPointHelper::EnableAscii (ascii);
    6.31  
    6.32    NS_LOG_INFO ("Run Simulation.");
    6.33    Simulator::Run ();    
     7.1 --- a/examples/simple-global-routing.cc	Mon Mar 31 13:54:41 2008 -0700
     7.2 +++ b/examples/simple-global-routing.cc	Mon Mar 31 13:54:57 2008 -0700
     7.3 @@ -45,8 +45,6 @@
     7.4  #include "ns3/core-module.h"
     7.5  #include "ns3/simulator-module.h"
     7.6  #include "ns3/helper-module.h"
     7.7 -#include "ns3/ascii-trace.h"
     7.8 -#include "ns3/pcap-trace.h"
     7.9  #include "ns3/global-route-manager.h"
    7.10  
    7.11  using namespace ns3;
    7.12 @@ -95,6 +93,9 @@
    7.13    CommandLine cmd;
    7.14    cmd.Parse (argc, argv);
    7.15  
    7.16 +  std::ofstream ascii;
    7.17 +  ascii.open ("simple-global-routing.tr");
    7.18 +
    7.19    // Here, we will explicitly create four nodes.  In more sophisticated
    7.20    // topologies, we could configure a node factory.
    7.21    NS_LOG_INFO ("Create nodes.");
    7.22 @@ -110,6 +111,8 @@
    7.23    // We create the channels first without any IP addressing information
    7.24    NS_LOG_INFO ("Create channels.");
    7.25    PointToPointHelper p2p;
    7.26 +  p2p.EnablePcap ("simple-global-routing.pcap");
    7.27 +  p2p.EnableAscii (ascii);
    7.28    p2p.SetChannelParameter ("BitRate", DataRate (5000000));
    7.29    p2p.SetChannelParameter ("Delay", MilliSeconds (2));
    7.30    NetDeviceContainer d0d2 = p2p.Build (n0n2);
    7.31 @@ -167,19 +170,6 @@
    7.32    apps.Start (Seconds (1.1));
    7.33    apps.Stop (Seconds (10.0));
    7.34  
    7.35 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
    7.36 -  // Trace output will be sent to the simple-global-routing.tr file
    7.37 -  NS_LOG_INFO ("Configure Tracing.");
    7.38 -  AsciiTrace asciitrace ("simple-global-routing.tr");
    7.39 -  asciitrace.TraceAllQueues ();
    7.40 -  asciitrace.TraceAllNetDeviceRx ();
    7.41 -
    7.42 -  // Also configure some tcpdump traces; each interface will be traced
    7.43 -  // The output files will be named simple-p2p.pcap-<nodeId>-<interfaceId>
    7.44 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
    7.45 -  // display timestamps correctly)
    7.46 -  PcapTrace pcaptrace ("simple-global-routing.pcap");
    7.47 -  pcaptrace.TraceAllIp ();
    7.48  
    7.49    NS_LOG_INFO ("Run Simulation.");
    7.50    Simulator::Run ();
     8.1 --- a/examples/tcp-large-transfer-errors.cc	Mon Mar 31 13:54:41 2008 -0700
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,245 +0,0 @@
     8.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
     8.5 -/*
     8.6 - * This program is free software; you can redistribute it and/or modify
     8.7 - * it under the terms of the GNU General Public License version 2 as
     8.8 - * published by the Free Software Foundation;
     8.9 - *
    8.10 - * This program is distributed in the hope that it will be useful,
    8.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.13 - * GNU General Public License for more details.
    8.14 - *
    8.15 - * You should have received a copy of the GNU General Public License
    8.16 - * along with this program; if not, write to the Free Software
    8.17 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.18 - *
    8.19 - */
    8.20 -
    8.21 -//
    8.22 -// Network topology
    8.23 -//
    8.24 -//           10Mb/s, 10ms       10Mb/s, 10ms
    8.25 -//       n0-----------------n1-----------------n2
    8.26 -//
    8.27 -//
    8.28 -// - Tracing of queues and packet receptions to file 
    8.29 -//   "tcp-large-transfer-errors.tr"
    8.30 -// - pcap traces also generated in the following files
    8.31 -//   "tcp-large-transfer-errors.pcap-$n-$i" where n and i represent node and interface numbers respectively
    8.32 -//  Usage (e.g.): ./waf --run tcp-large-transfer-errors
    8.33 -
    8.34 -#include <ctype.h>
    8.35 -#include <iostream>
    8.36 -#include <fstream>
    8.37 -#include <string>
    8.38 -#include <cassert>
    8.39 -
    8.40 -#include "ns3/command-line.h"
    8.41 -#include "ns3/ptr.h"
    8.42 -#include "ns3/random-variable.h"
    8.43 -#include "ns3/log.h"
    8.44 -
    8.45 -#include "ns3/simulator.h"
    8.46 -#include "ns3/nstime.h"
    8.47 -#include "ns3/data-rate.h"
    8.48 -
    8.49 -#include "ns3/ascii-trace.h"
    8.50 -#include "ns3/pcap-trace.h"
    8.51 -#include "ns3/internet-node.h"
    8.52 -#include "ns3/point-to-point-channel.h"
    8.53 -#include "ns3/point-to-point-net-device.h"
    8.54 -#include "ns3/ipv4-address.h"
    8.55 -#include "ns3/inet-socket-address.h"
    8.56 -#include "ns3/ipv4.h"
    8.57 -#include "ns3/socket.h"
    8.58 -#include "ns3/ipv4-route.h"
    8.59 -#include "ns3/point-to-point-topology.h"
    8.60 -#include "ns3/onoff-application.h"
    8.61 -#include "ns3/packet-sink.h"
    8.62 -#include "ns3/error-model.h"
    8.63 -#include "ns3/node-list.h"
    8.64 -#include "ns3/config.h"
    8.65 -
    8.66 -#include "ns3/tcp.h"
    8.67 -
    8.68 -using namespace ns3;
    8.69 -
    8.70 -NS_LOG_COMPONENT_DEFINE ("TcpLargeTransferErrors");
    8.71 -
    8.72 -void 
    8.73 -ApplicationTraceSink (Ptr<const Packet> packet,
    8.74 -                      const Address &addr)
    8.75 -{
    8.76 -// g_log is not declared in optimized builds
    8.77 -// should convert this to use of some other flag than the logging system
    8.78 -#ifdef NS3_LOG_ENABLE
    8.79 -  if (!g_log.IsNoneEnabled ()) {
    8.80 -    if (InetSocketAddress::IsMatchingType (addr) )
    8.81 -      {
    8.82 -      InetSocketAddress address = InetSocketAddress::ConvertFrom (addr);
    8.83 -        std::cout << "PacketSink received size " << 
    8.84 -        packet->GetSize () << " at time " << 
    8.85 -        Simulator::Now ().GetSeconds () << " from address: " << 
    8.86 -        address.GetIpv4 () << std::endl;
    8.87 -        char buf[2000]; 
    8.88 -        memcpy(buf, packet->PeekData (), packet->GetSize ());
    8.89 -        for (uint32_t i=0; i < packet->GetSize (); i++)
    8.90 -          {
    8.91 -            std::cout << buf[i];
    8.92 -            if (i && i % 60 == 0) 
    8.93 -              std::cout << std::endl; 
    8.94 -          }
    8.95 -        std::cout << std::endl << std::endl;
    8.96 -    }
    8.97 -  }
    8.98 -#endif
    8.99 -}
   8.100 -
   8.101 -void CloseConnection (Ptr<Socket> localSocket)
   8.102 -{
   8.103 -  //localSocket->Close ();
   8.104 -}
   8.105 -
   8.106 -void StartFlow(Ptr<Socket> localSocket, uint32_t nBytes, 
   8.107 -  uint16_t servPort)
   8.108 -{
   8.109 - // NS_LOG_LOGIC("Starting flow at time " <<  Simulator::Now ().GetSeconds ());
   8.110 -  localSocket->Connect (InetSocketAddress ("10.1.2.2", servPort));//connect
   8.111 -  localSocket->SetConnectCallback (MakeCallback (&CloseConnection),
   8.112 -                                   Callback<void, Ptr<Socket> > (),
   8.113 -                                   Callback<void, Ptr<Socket> > ());
   8.114 -  //we want to close as soon as the connection is established
   8.115 -  //the tcp state machine and outgoing buffer will assure that
   8.116 -  //all of the data is delivered
   8.117 -
   8.118 -  // Perform series of 1040 byte writes (this is a multiple of 26 since
   8.119 -  // we want to detect data splicing in the output stream)
   8.120 -  uint32_t writeSize = 1040;
   8.121 -  uint8_t data[writeSize];
   8.122 -  while (nBytes > 0) {
   8.123 -    uint32_t curSize= nBytes > writeSize ? writeSize : nBytes;
   8.124 -    for(uint32_t i = 0; i < curSize; ++i)
   8.125 -    {
   8.126 -      char m = toascii (97 + i % 26);
   8.127 -      data[i] = m;
   8.128 -    }
   8.129 -    localSocket->Send (data, curSize);
   8.130 -    nBytes -= curSize;
   8.131 -  }
   8.132 -}
   8.133 -
   8.134 -int main (int argc, char *argv[])
   8.135 -{
   8.136 -
   8.137 -  // Users may find it convenient to turn on explicit debugging
   8.138 -  // for selected modules; the below lines suggest how to do this
   8.139 -//  LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
   8.140 -//  LogComponentEnable("TcpSocket", LOG_LEVEL_ALL);
   8.141 -//  LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
   8.142 -  //LogComponentEnable("TcpLargeTransferErrors", LOG_LEVEL_ALL);
   8.143 -
   8.144 -  // Allow the user to override any of the defaults and the above
   8.145 -  // Bind()s at run-time, via command-line arguments
   8.146 -  CommandLine cmd;
   8.147 -  cmd.Parse (argc, argv);
   8.148 -
   8.149 -  // Here, we will explicitly create three nodes.  In more sophisticated
   8.150 -  // topologies, we could configure a node factory.
   8.151 -  Ptr<Node> n0 = Create<InternetNode> ();
   8.152 -  Ptr<Node> n1 = Create<InternetNode> (); 
   8.153 -  Ptr<Node> n2 = Create<InternetNode> ();
   8.154 -
   8.155 -  // We create the channels first without any IP addressing information
   8.156 -  Ptr<PointToPointChannel> channel0 = 
   8.157 -    PointToPointTopology::AddPointToPointLink (
   8.158 -    n0, n1, DataRate(10000000), MilliSeconds(10));
   8.159 -  
   8.160 -  // Later, we add IP addresses.  
   8.161 -  PointToPointTopology::AddIpv4Addresses (
   8.162 -      channel0, n0, Ipv4Address("10.1.3.1"),
   8.163 -      n1, Ipv4Address("10.1.3.2"));
   8.164 -
   8.165 -  Ptr<PointToPointChannel> channel1 = 
   8.166 -      PointToPointTopology::AddPointToPointLink (
   8.167 -      n1, n2, DataRate(10000000), MilliSeconds(10));
   8.168 -  
   8.169 -  PointToPointTopology::AddIpv4Addresses (
   8.170 -      channel1, n1, Ipv4Address("10.1.2.1"),
   8.171 -      n2, Ipv4Address("10.1.2.2"));
   8.172 -  
   8.173 -  // Finally, we add static routes.  These three steps (Channel and
   8.174 -  // NetDevice creation, IP Address assignment, and routing) are 
   8.175 -  // separated because there may be a need to postpone IP Address
   8.176 -  // assignment (emulation) or modify to use dynamic routing
   8.177 -  PointToPointTopology::AddIpv4Routes(n0, n1, channel0);
   8.178 -  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
   8.179 -  Ptr<Ipv4> ipv4;
   8.180 -  ipv4 = n0->GetObject<Ipv4> ();
   8.181 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.2"), 1);
   8.182 -  ipv4 = n2->GetObject<Ipv4> ();
   8.183 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.2.1"), 1);
   8.184 -
   8.185 -
   8.186 -  ///////////////////////////////////////////////////////////////////////////
   8.187 -  // Simulation 1
   8.188 -  // 
   8.189 -  // Send 2000000 bytes over a connection to server port 50000 at time 0
   8.190 -  // Should observe SYN exchange, a lot of data segments, and FIN exchange
   8.191 -  //
   8.192 -  ///////////////////////////////////////////////////////////////////////////
   8.193 -
   8.194 -  int nBytes = 2000000;
   8.195 -  uint16_t servPort = 50000;
   8.196 -
   8.197 -  Ptr<SocketFactory> socketFactory = 
   8.198 -    n0->GetObject<SocketFactory> ();
   8.199 -  Ptr<Socket> localSocket = socketFactory->CreateSocket ();
   8.200 -  localSocket->Bind ();
   8.201 -
   8.202 -  // Create a packet sink to receive these packets
   8.203 -  Ptr<PacketSink> sink = 
   8.204 -    CreateObject<PacketSink> ("Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
   8.205 -                              "Protocol", TypeId::LookupByName ("ns3::Tcp"));
   8.206 -  n2->AddApplication (sink);
   8.207 -  sink->Start (Seconds (0.0));
   8.208 -  sink->Stop (Seconds (10000.0));
   8.209 -
   8.210 - //
   8.211 -  // Error models
   8.212 -  //
   8.213 -  // We want to add an error model to node 2's NetDevice
   8.214 -  // We can obtain a handle to the NetDevice via the channel and node 
   8.215 -  // pointers
   8.216 -  Ptr<PointToPointNetDevice> nd2 = PointToPointTopology::GetNetDevice
   8.217 -    (n2, channel1);
   8.218 -  Ptr<RateErrorModel> rem = Create<RateErrorModel> ();
   8.219 -  // The first data segment for this flow is packet uid=4
   8.220 -  rem->SetRandomVariable (UniformVariable ());
   8.221 -  rem->SetUnit (EU_PKT);
   8.222 -  rem->SetRate (0.05);
   8.223 -  nd2->AddReceiveErrorModel (rem);
   8.224 -
   8.225 -  Simulator::Schedule(Seconds(0), &StartFlow, localSocket, nBytes,
   8.226 -    servPort);
   8.227 -
   8.228 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
   8.229 -  // Trace output will be sent to the simple-examples.tr file
   8.230 -  AsciiTrace asciitrace ("tcp-large-transfer-errors.tr");
   8.231 -  asciitrace.TraceAllQueues ();
   8.232 -  asciitrace.TraceAllNetDeviceRx ();
   8.233 -
   8.234 -  
   8.235 -  // Also configure some tcpdump traces; each interface will be traced
   8.236 -  // The output files will be named 
   8.237 -  // simple-examples.pcap-<nodeId>-<interfaceId>
   8.238 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
   8.239 -  // display timestamps correctly)
   8.240 -  PcapTrace pcaptrace ("tcp-large-transfer-errors.pcap");
   8.241 -  pcaptrace.TraceAllIp ();
   8.242 -
   8.243 -  Config::ConnectWithoutContext ("/NodeList/*/ApplicationList/*/Rx", MakeCallback (&ApplicationTraceSink));
   8.244 -
   8.245 -  Simulator::StopAt (Seconds(10000));
   8.246 -  Simulator::Run ();
   8.247 -  Simulator::Destroy ();
   8.248 -}
     9.1 --- a/examples/tcp-large-transfer.cc	Mon Mar 31 13:54:41 2008 -0700
     9.2 +++ b/examples/tcp-large-transfer.cc	Mon Mar 31 13:54:57 2008 -0700
     9.3 @@ -40,9 +40,6 @@
     9.4  #include "ns3/global-route-manager.h"
     9.5  #include "ns3/simulator-module.h"
     9.6  
     9.7 -#include "ns3/ascii-trace.h"
     9.8 -#include "ns3/pcap-trace.h"
     9.9 -
    9.10  using namespace ns3;
    9.11  
    9.12  NS_LOG_COMPONENT_DEFINE ("TcpLargeTransfer");
    9.13 @@ -180,24 +177,15 @@
    9.14    Simulator::ScheduleNow (&StartFlow, localSocket, nBytes,
    9.15                            ipInterfs.GetAddress (1), servPort);
    9.16  
    9.17 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
    9.18 -  // Trace output will be sent to the simple-examples.tr file
    9.19 -  AsciiTrace asciitrace ("tcp-large-transfer.tr");
    9.20 -  asciitrace.TraceAllQueues ();
    9.21 -  asciitrace.TraceAllNetDeviceRx ();
    9.22 -
    9.23 -  
    9.24 -  // Also configure some tcpdump traces; each interface will be traced
    9.25 -  // The output files will be named 
    9.26 -  // simple-examples.pcap-<nodeId>-<interfaceId>
    9.27 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
    9.28 -  // display timestamps correctly)
    9.29 -  PcapTrace pcaptrace ("tcp-large-transfer.pcap");
    9.30 -  pcaptrace.TraceAllIp ();
    9.31 -
    9.32    Config::ConnectWithoutContext ("/NodeList/*/ApplicationList/*/Rx", 
    9.33                     MakeCallback (&ApplicationTraceSink));
    9.34  
    9.35 +  std::ofstream ascii;
    9.36 +  ascii.open ("tcp-large-transfer.tr");
    9.37 +  PointToPointHelper::EnablePcap ("tcp-large-transfer.pcap");
    9.38 +  PointToPointHelper::EnableAscii (ascii);
    9.39 +
    9.40 +
    9.41    Simulator::StopAt (Seconds(1000));
    9.42    Simulator::Run ();
    9.43    Simulator::Destroy ();
    10.1 --- a/examples/tcp-nonlistening-server.cc	Mon Mar 31 13:54:41 2008 -0700
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,191 +0,0 @@
    10.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    10.5 -/*
    10.6 - * This program is free software; you can redistribute it and/or modify
    10.7 - * it under the terms of the GNU General Public License version 2 as
    10.8 - * published by the Free Software Foundation;
    10.9 - *
   10.10 - * This program is distributed in the hope that it will be useful,
   10.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.13 - * GNU General Public License for more details.
   10.14 - *
   10.15 - * You should have received a copy of the GNU General Public License
   10.16 - * along with this program; if not, write to the Free Software
   10.17 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.18 - *
   10.19 - */
   10.20 -
   10.21 -//
   10.22 -// Network topology
   10.23 -//
   10.24 -//           100Kb/s, 10ms       1Mb/s, 10ms
   10.25 -//       n0-----------------n1-----------------n2
   10.26 -//
   10.27 -//
   10.28 -// - Tracing of queues and packet receptions to file 
   10.29 -//   "tcp-nonlistening-server.tr"
   10.30 -// - pcap traces also generated in the following files
   10.31 -//   "tcp-nonlistening-server.pcap-$n-$i" where n and i represent node and interface numbers respectively
   10.32 -//  Usage (e.g.): ./waf --run tcp-nonlistening-server
   10.33 -
   10.34 -#include <iostream>
   10.35 -#include <fstream>
   10.36 -#include <string>
   10.37 -#include <cassert>
   10.38 -
   10.39 -#include "ns3/command-line.h"
   10.40 -#include "ns3/ptr.h"
   10.41 -#include "ns3/random-variable.h"
   10.42 -#include "ns3/log.h"
   10.43 -
   10.44 -#include "ns3/simulator.h"
   10.45 -#include "ns3/nstime.h"
   10.46 -#include "ns3/data-rate.h"
   10.47 -
   10.48 -#include "ns3/ascii-trace.h"
   10.49 -#include "ns3/pcap-trace.h"
   10.50 -#include "ns3/internet-node.h"
   10.51 -#include "ns3/point-to-point-channel.h"
   10.52 -#include "ns3/point-to-point-net-device.h"
   10.53 -#include "ns3/ipv4-address.h"
   10.54 -#include "ns3/inet-socket-address.h"
   10.55 -#include "ns3/ipv4.h"
   10.56 -#include "ns3/socket.h"
   10.57 -#include "ns3/ipv4-route.h"
   10.58 -#include "ns3/point-to-point-topology.h"
   10.59 -#include "ns3/onoff-application.h"
   10.60 -#include "ns3/packet-sink.h"
   10.61 -#include "ns3/error-model.h"
   10.62 -
   10.63 -#include "ns3/tcp.h"
   10.64 -
   10.65 -using namespace ns3;
   10.66 -
   10.67 -NS_LOG_COMPONENT_DEFINE ("TcpNonListeningServer");
   10.68 -
   10.69 -void ConnectionSucceededCallback (Ptr<Socket> localSocket) 
   10.70 -{
   10.71 -  uint32_t nBytes = 2000;
   10.72 -  uint8_t data[nBytes];
   10.73 -  for(uint32_t i = 0; i < nBytes; ++i)
   10.74 -  {
   10.75 -    char m = 'A';
   10.76 -    data[i] = m;
   10.77 -  } //put something interesting in the packets ABCDEF...
   10.78 -  localSocket->Send (data, nBytes);
   10.79 -}
   10.80 -
   10.81 -void ConnectionFailedCallback (Ptr<Socket> localSocket) 
   10.82 -{
   10.83 -  NS_LOG_ERROR("Connection failed at time " << Simulator::Now ().GetSeconds ());
   10.84 -}
   10.85 -
   10.86 -void StartFlow(Ptr<Socket> localSocket, uint16_t servPort)
   10.87 -{
   10.88 -  NS_LOG_LOGIC(std::endl << "Connection attempt at time " <<  
   10.89 -    Simulator::Now ().GetSeconds () << std::endl);
   10.90 -  localSocket->Connect (InetSocketAddress ("10.1.2.2", servPort));
   10.91 -  localSocket->SetConnectCallback (
   10.92 -    MakeCallback (&ConnectionSucceededCallback),
   10.93 -    MakeCallback (&ConnectionFailedCallback), 
   10.94 -    MakeNullCallback<void, Ptr<Socket> > () );
   10.95 -}
   10.96 -
   10.97 -int main (int argc, char *argv[])
   10.98 -{
   10.99 -
  10.100 -  // Users may find it convenient to turn on explicit debugging
  10.101 -  // for selected modules; the below lines suggest how to do this
  10.102 -  //LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
  10.103 -  //LogComponentEnable("TcpSocket", LOG_LEVEL_ALL);
  10.104 -  LogComponentEnable("TcpNonListeningServer", LOG_LEVEL_ALL);
  10.105 -
  10.106 -  // Allow the user to override any of the defaults and the above
  10.107 -  // Bind()s at run-time, via command-line arguments
  10.108 -  CommandLine cmd;
  10.109 -  cmd.Parse (argc, argv);
  10.110 -
  10.111 -  // Here, we will explicitly create three nodes.  In more sophisticated
  10.112 -  // topologies, we could configure a node factory.
  10.113 -  Ptr<Node> n0 = Create<InternetNode> ();
  10.114 -  Ptr<Node> n1 = Create<InternetNode> (); 
  10.115 -  Ptr<Node> n2 = Create<InternetNode> ();
  10.116 -
  10.117 -  // We create the channels first without any IP addressing information
  10.118 -  Ptr<PointToPointChannel> channel0 = 
  10.119 -    PointToPointTopology::AddPointToPointLink (
  10.120 -    n0, n1, DataRate(1000000), MilliSeconds(10));
  10.121 -  
  10.122 -  // Later, we add IP addresses.  
  10.123 -  PointToPointTopology::AddIpv4Addresses (
  10.124 -      channel0, n0, Ipv4Address("10.1.3.1"),
  10.125 -      n1, Ipv4Address("10.1.3.2"));
  10.126 -
  10.127 -  Ptr<PointToPointChannel> channel1 = 
  10.128 -      PointToPointTopology::AddPointToPointLink (
  10.129 -      n1, n2, DataRate(100000), MilliSeconds(10));
  10.130 -  
  10.131 -  PointToPointTopology::AddIpv4Addresses (
  10.132 -      channel1, n1, Ipv4Address("10.1.2.1"),
  10.133 -      n2, Ipv4Address("10.1.2.2"));
  10.134 -  
  10.135 -  // Finally, we add static routes.  These three steps (Channel and
  10.136 -  // NetDevice creation, IP Address assignment, and routing) are 
  10.137 -  // separated because there may be a need to postpone IP Address
  10.138 -  // assignment (emulation) or modify to use dynamic routing
  10.139 -  PointToPointTopology::AddIpv4Routes(n0, n1, channel0);
  10.140 -  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
  10.141 -  Ptr<Ipv4> ipv4;
  10.142 -  ipv4 = n0->GetObject<Ipv4> ();
  10.143 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.2"), 1);
  10.144 -  ipv4 = n2->GetObject<Ipv4> ();
  10.145 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.2.1"), 1);
  10.146 -
  10.147 -
  10.148 -  ///////////////////////////////////////////////////////////////////////////
  10.149 -  // Simulation 1
  10.150 -  // 
  10.151 -  // Send 2000 bytes over a connection to server port 500 at time 0
  10.152 -  // Should observe SYN exchange, two data segments, and FIN exchange
  10.153 -  //
  10.154 -  ///////////////////////////////////////////////////////////////////////////
  10.155 -
  10.156 -  uint16_t servPort = 500;
  10.157 -
  10.158 -  Ptr<SocketFactory> socketFactory = 
  10.159 -    n0->GetObject<SocketFactory> ();
  10.160 -  Ptr<Socket> localSocket = socketFactory->CreateSocket ();
  10.161 -  localSocket->Bind ();
  10.162 -
  10.163 -#ifdef NOTFORTHISSCRIPT
  10.164 -  // Create an optional packet sink to receive these packets
  10.165 -  Ptr<PacketSink> sink = Create<PacketSink> (
  10.166 -    n2,
  10.167 -    InetSocketAddress (Ipv4Address::GetAny (), servPort),
  10.168 -    "ns3::Tcp");
  10.169 -  // Start the sink
  10.170 -  sink->Start (Seconds (0.0));
  10.171 -  sink->Stop (Seconds (10.0));
  10.172 -#endif
  10.173 -
  10.174 -  Simulator::Schedule(Seconds(0), &StartFlow, localSocket, servPort);
  10.175 -
  10.176 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
  10.177 -  // Trace output will be sent to the simple-examples.tr file
  10.178 -  AsciiTrace asciitrace ("tcp-nonlistening-server.tr");
  10.179 -  asciitrace.TraceAllQueues ();
  10.180 -  asciitrace.TraceAllNetDeviceRx ();
  10.181 -
  10.182 -  // Also configure some tcpdump traces; each interface will be traced
  10.183 -  // The output files will be named 
  10.184 -  // simple-examples.pcap-<nodeId>-<interfaceId>
  10.185 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
  10.186 -  // display timestamps correctly)
  10.187 -  PcapTrace pcaptrace ("tcp-nonlistening-server.pcap");
  10.188 -  pcaptrace.TraceAllIp ();
  10.189 -
  10.190 -
  10.191 -  Simulator::StopAt (Seconds(1000));
  10.192 -  Simulator::Run ();
  10.193 -  Simulator::Destroy ();
  10.194 -}
    11.1 --- a/examples/tcp-small-transfer-oneloss.cc	Mon Mar 31 13:54:41 2008 -0700
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,227 +0,0 @@
    11.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    11.5 -/*
    11.6 - * This program is free software; you can redistribute it and/or modify
    11.7 - * it under the terms of the GNU General Public License version 2 as
    11.8 - * published by the Free Software Foundation;
    11.9 - *
   11.10 - * This program is distributed in the hope that it will be useful,
   11.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.13 - * GNU General Public License for more details.
   11.14 - *
   11.15 - * You should have received a copy of the GNU General Public License
   11.16 - * along with this program; if not, write to the Free Software
   11.17 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.18 - *
   11.19 - */
   11.20 -
   11.21 -//
   11.22 -// Network topology
   11.23 -//
   11.24 -//           100Kb/s, 10ms       1Mb/s, 10ms
   11.25 -//       n0-----------------n1-----------------n2
   11.26 -//
   11.27 -//
   11.28 -// - Tracing of queues and packet receptions to file 
   11.29 -//   "tcp-small-transfer-oneloss.tr"
   11.30 -// - pcap traces also generated in the following files
   11.31 -//   "tcp-small-transfer-oneloss.pcap-$n-$i" where n and i represent node and interface numbers respectively
   11.32 -//  Usage (e.g.): ./waf --run tcp-small-transfer-oneloss
   11.33 -
   11.34 -#include <ctype.h>
   11.35 -#include <iostream>
   11.36 -#include <fstream>
   11.37 -#include <string>
   11.38 -#include <cassert>
   11.39 -
   11.40 -#include "ns3/command-line.h"
   11.41 -#include "ns3/ptr.h"
   11.42 -#include "ns3/random-variable.h"
   11.43 -#include "ns3/log.h"
   11.44 -
   11.45 -#include "ns3/simulator.h"
   11.46 -#include "ns3/nstime.h"
   11.47 -#include "ns3/data-rate.h"
   11.48 -
   11.49 -#include "ns3/ascii-trace.h"
   11.50 -#include "ns3/pcap-trace.h"
   11.51 -#include "ns3/internet-node.h"
   11.52 -#include "ns3/point-to-point-channel.h"
   11.53 -#include "ns3/point-to-point-net-device.h"
   11.54 -#include "ns3/ipv4-address.h"
   11.55 -#include "ns3/inet-socket-address.h"
   11.56 -#include "ns3/ipv4.h"
   11.57 -#include "ns3/socket.h"
   11.58 -#include "ns3/ipv4-route.h"
   11.59 -#include "ns3/point-to-point-topology.h"
   11.60 -#include "ns3/onoff-application.h"
   11.61 -#include "ns3/packet-sink.h"
   11.62 -#include "ns3/error-model.h"
   11.63 -#include "ns3/node-list.h"
   11.64 -#include "ns3/config.h"
   11.65 -
   11.66 -#include "ns3/tcp.h"
   11.67 -
   11.68 -using namespace ns3;
   11.69 -
   11.70 -NS_LOG_COMPONENT_DEFINE ("TcpSmallTransferOneloss");
   11.71 -
   11.72 -void 
   11.73 -ApplicationTraceSink (Ptr<const Packet> packet,
   11.74 -                      const Address &addr)
   11.75 -{
   11.76 -// g_log is not declared in optimized builds
   11.77 -// should convert this to use of some other flag than the logging system
   11.78 -#ifdef NS3_LOG_ENABLE
   11.79 -  if (!g_log.IsNoneEnabled ()) {
   11.80 -    if (InetSocketAddress::IsMatchingType (addr) )
   11.81 -      {
   11.82 -      InetSocketAddress address = InetSocketAddress::ConvertFrom (addr);
   11.83 -        std::cout << "PacketSink received size " << 
   11.84 -        packet->GetSize () << " at time " << 
   11.85 -        Simulator::Now ().GetSeconds () << " from address: " << 
   11.86 -        address.GetIpv4 () << std::endl;
   11.87 -        char buf[2000]; 
   11.88 -        memcpy(buf, packet->PeekData (), packet->GetSize ());
   11.89 -        for (uint32_t i=0; i < packet->GetSize (); i++)
   11.90 -          {
   11.91 -            std::cout << buf[i];
   11.92 -            if (i && i % 60 == 0) 
   11.93 -              std::cout << std::endl; 
   11.94 -          }
   11.95 -        std::cout << std::endl << std::endl;
   11.96 -    }
   11.97 -  }
   11.98 -#endif
   11.99 -}
  11.100 -
  11.101 -void StartFlow(Ptr<Socket> localSocket, uint32_t nBytes, 
  11.102 -  uint16_t servPort)
  11.103 -{
  11.104 - // NS_LOG_LOGIC("Starting flow at time " <<  Simulator::Now ().GetSeconds ());
  11.105 -  localSocket->Connect (InetSocketAddress ("10.1.2.2", servPort));
  11.106 -  uint8_t data[nBytes];
  11.107 -  for(uint32_t i = 0; i < nBytes; ++i)
  11.108 -  {
  11.109 -    char m = toascii (97 + i % 26);
  11.110 -    data[i] = m;
  11.111 -  } 
  11.112 -  localSocket->Send (data, nBytes);
  11.113 -}
  11.114 -
  11.115 -int main (int argc, char *argv[])
  11.116 -{
  11.117 -
  11.118 -  // Users may find it convenient to turn on explicit debugging
  11.119 -  // for selected modules; the below lines suggest how to do this
  11.120 -// LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
  11.121 -// LogComponentEnable("TcpSocket", LOG_LEVEL_ALL);
  11.122 -// LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
  11.123 - LogComponentEnable("TcpSmallTransferOneloss", LOG_LEVEL_ALL);
  11.124 -
  11.125 -  // Allow the user to override any of the defaults and the above
  11.126 -  // Bind()s at run-time, via command-line arguments
  11.127 - CommandLine cmd;
  11.128 - cmd.Parse (argc, argv);
  11.129 -
  11.130 -  // Here, we will explicitly create three nodes.  In more sophisticated
  11.131 -  // topologies, we could configure a node factory.
  11.132 -  Ptr<Node> n0 = Create<InternetNode> ();
  11.133 -  Ptr<Node> n1 = Create<InternetNode> (); 
  11.134 -  Ptr<Node> n2 = Create<InternetNode> ();
  11.135 -
  11.136 -  // We create the channels first without any IP addressing information
  11.137 -  Ptr<PointToPointChannel> channel0 = 
  11.138 -    PointToPointTopology::AddPointToPointLink (
  11.139 -    n0, n1, DataRate(1000000), MilliSeconds(10));
  11.140 -  
  11.141 -  // Later, we add IP addresses.  
  11.142 -  PointToPointTopology::AddIpv4Addresses (
  11.143 -      channel0, n0, Ipv4Address("10.1.3.1"),
  11.144 -      n1, Ipv4Address("10.1.3.2"));
  11.145 -
  11.146 -  Ptr<PointToPointChannel> channel1 = 
  11.147 -      PointToPointTopology::AddPointToPointLink (
  11.148 -      n1, n2, DataRate(100000), MilliSeconds(10));
  11.149 -  
  11.150 -  PointToPointTopology::AddIpv4Addresses (
  11.151 -      channel1, n1, Ipv4Address("10.1.2.1"),
  11.152 -      n2, Ipv4Address("10.1.2.2"));
  11.153 -  
  11.154 -  // Finally, we add static routes.  These three steps (Channel and
  11.155 -  // NetDevice creation, IP Address assignment, and routing) are 
  11.156 -  // separated because there may be a need to postpone IP Address
  11.157 -  // assignment (emulation) or modify to use dynamic routing
  11.158 -  PointToPointTopology::AddIpv4Routes(n0, n1, channel0);
  11.159 -  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
  11.160 -  Ptr<Ipv4> ipv4;
  11.161 -  ipv4 = n0->GetObject<Ipv4> ();
  11.162 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.2"), 1);
  11.163 -  ipv4 = n2->GetObject<Ipv4> ();
  11.164 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.2.1"), 1);
  11.165 -
  11.166 -
  11.167 -  ///////////////////////////////////////////////////////////////////////////
  11.168 -  // Simulation 1
  11.169 -  // 
  11.170 -  // Send 2000 bytes over a connection to server port 500 at time 0
  11.171 -  // Should observe SYN exchange, two data segments, and FIN exchange
  11.172 -  // Force the loss of the first data segment
  11.173 -  //
  11.174 -  ///////////////////////////////////////////////////////////////////////////
  11.175 -
  11.176 -  int nBytes = 2000;
  11.177 -  uint16_t servPort = 500;
  11.178 -
  11.179 -  Ptr<SocketFactory> socketFactory = 
  11.180 -    n0->GetObject<SocketFactory> ();
  11.181 -  Ptr<Socket> localSocket = socketFactory->CreateSocket ();
  11.182 -  localSocket->Bind ();
  11.183 -
  11.184 -  // Create a packet sink to receive these packets
  11.185 -  Ptr<PacketSink> sink = 
  11.186 -    CreateObject<PacketSink> ("Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
  11.187 -                              "Protocol", TypeId::LookupByName ("ns3::Tcp"));
  11.188 -  n2->AddApplication (sink);
  11.189 -  sink->Start (Seconds (0.0));
  11.190 -  sink->Stop (Seconds (100.0));
  11.191 -
  11.192 -  //
  11.193 -  // Error models
  11.194 -  //
  11.195 -  // We want to add an error model to node 2's NetDevice
  11.196 -  // We can obtain a handle to the NetDevice via the channel and node 
  11.197 -  // pointers
  11.198 -  Ptr<PointToPointNetDevice> nd2 = PointToPointTopology::GetNetDevice
  11.199 -    (n2, channel1);
  11.200 -  Ptr<ListErrorModel> pem = Create<ListErrorModel> ();
  11.201 -  std::list<uint32_t> sampleList;
  11.202 -  // The first data segment for this flow is packet uid=4
  11.203 -  sampleList.push_back (4);
  11.204 -  pem->SetList (sampleList);
  11.205 -  nd2->AddReceiveErrorModel (pem);
  11.206 -
  11.207 -  Simulator::Schedule(Seconds(0), &StartFlow, localSocket, nBytes,
  11.208 -    servPort);
  11.209 -
  11.210 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
  11.211 -  // Trace output will be sent to the simple-examples.tr file
  11.212 -  AsciiTrace asciitrace ("tcp-small-transfer-oneloss.tr");
  11.213 -  asciitrace.TraceAllQueues ();
  11.214 -  asciitrace.TraceAllNetDeviceRx ();
  11.215 -
  11.216 -  
  11.217 -  // Also configure some tcpdump traces; each interface will be traced
  11.218 -  // The output files will be named 
  11.219 -  // simple-examples.pcap-<nodeId>-<interfaceId>
  11.220 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
  11.221 -  // display timestamps correctly)
  11.222 -  PcapTrace pcaptrace ("tcp-small-transfer-oneloss.pcap");
  11.223 -  pcaptrace.TraceAllIp ();
  11.224 -
  11.225 -  Config::ConnectWithoutContext ("/NodeList/*/ApplicationList/*/Rx", MakeCallback (&ApplicationTraceSink));
  11.226 -
  11.227 -  Simulator::StopAt (Seconds(1000));
  11.228 -  Simulator::Run ();
  11.229 -  Simulator::Destroy ();
  11.230 -}
    12.1 --- a/examples/tcp-small-transfer.cc	Mon Mar 31 13:54:41 2008 -0700
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,222 +0,0 @@
    12.4 -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
    12.5 -/*
    12.6 - * This program is free software; you can redistribute it and/or modify
    12.7 - * it under the terms of the GNU General Public License version 2 as
    12.8 - * published by the Free Software Foundation;
    12.9 - *
   12.10 - * This program is distributed in the hope that it will be useful,
   12.11 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.12 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.13 - * GNU General Public License for more details.
   12.14 - *
   12.15 - * You should have received a copy of the GNU General Public License
   12.16 - * along with this program; if not, write to the Free Software
   12.17 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.18 - *
   12.19 - */
   12.20 -
   12.21 -//
   12.22 -// Network topology
   12.23 -//
   12.24 -//           100Kb/s, 10ms       1Mb/s, 10ms
   12.25 -//       n0-----------------n1-----------------n2
   12.26 -//
   12.27 -//
   12.28 -// - Tracing of queues and packet receptions to file 
   12.29 -//   "tcp-small-transfer.tr"
   12.30 -// - pcap traces also generated in the following files
   12.31 -//   "tcp-small-transfer.pcap-$n-$i" where n and i represent node and interface numbers respectively
   12.32 -//  Usage (e.g.): ./waf --run tcp-small-transfer
   12.33 -
   12.34 -#include <ctype.h>
   12.35 -#include <iostream>
   12.36 -#include <fstream>
   12.37 -#include <string>
   12.38 -#include <cassert>
   12.39 -
   12.40 -#include "ns3/command-line.h"
   12.41 -#include "ns3/ptr.h"
   12.42 -#include "ns3/random-variable.h"
   12.43 -#include "ns3/log.h"
   12.44 -
   12.45 -#include "ns3/simulator.h"
   12.46 -#include "ns3/nstime.h"
   12.47 -#include "ns3/data-rate.h"
   12.48 -
   12.49 -#include "ns3/ascii-trace.h"
   12.50 -#include "ns3/pcap-trace.h"
   12.51 -#include "ns3/internet-node.h"
   12.52 -#include "ns3/point-to-point-channel.h"
   12.53 -#include "ns3/point-to-point-net-device.h"
   12.54 -#include "ns3/ipv4-address.h"
   12.55 -#include "ns3/inet-socket-address.h"
   12.56 -#include "ns3/ipv4.h"
   12.57 -#include "ns3/socket.h"
   12.58 -#include "ns3/ipv4-route.h"
   12.59 -#include "ns3/point-to-point-topology.h"
   12.60 -#include "ns3/onoff-application.h"
   12.61 -#include "ns3/packet-sink.h"
   12.62 -#include "ns3/error-model.h"
   12.63 -#include "ns3/node-list.h"
   12.64 -#include "ns3/config.h"
   12.65 -
   12.66 -#include "ns3/tcp.h"
   12.67 -
   12.68 -using namespace ns3;
   12.69 -
   12.70 -NS_LOG_COMPONENT_DEFINE ("TcpSmallTransfer");
   12.71 -
   12.72 -void 
   12.73 -ApplicationTraceSink (Ptr<const Packet> packet,
   12.74 -                      const Address &addr)
   12.75 -{
   12.76 -// g_log is not declared in optimized builds
   12.77 -// should convert this to use of some other flag than the logging system
   12.78 -#ifdef NS3_LOG_ENABLE
   12.79 -  if (!g_log.IsNoneEnabled ()) {
   12.80 -    if (InetSocketAddress::IsMatchingType (addr) )
   12.81 -      {
   12.82 -      InetSocketAddress address = InetSocketAddress::ConvertFrom (addr);
   12.83 -        std::cout << "PacketSink received size " << 
   12.84 -        packet->GetSize () << " at time " << 
   12.85 -        Simulator::Now ().GetSeconds () << " from address: " << 
   12.86 -        address.GetIpv4 () << std::endl;
   12.87 -        char buf[2000]; 
   12.88 -        memcpy(buf, packet->PeekData (), packet->GetSize ());
   12.89 -        for (uint32_t i=0; i < packet->GetSize (); i++)
   12.90 -          {
   12.91 -            std::cout << buf[i];
   12.92 -            if (i && i % 60 == 0) 
   12.93 -              std::cout << std::endl; 
   12.94 -          }
   12.95 -        std::cout << std::endl << std::endl;
   12.96 -    }
   12.97 -  }
   12.98 -#endif
   12.99 -}
  12.100 -
  12.101 -void CloseConnection (Ptr<Socket> localSocket)
  12.102 -{
  12.103 -  localSocket->Close ();
  12.104 -}
  12.105 -
  12.106 -void StartFlow(Ptr<Socket> localSocket, uint32_t nBytes, 
  12.107 -  uint16_t servPort)
  12.108 -{
  12.109 - // NS_LOG_LOGIC("Starting flow at time " <<  Simulator::Now ().GetSeconds ());
  12.110 -  localSocket->Connect (InetSocketAddress ("10.1.2.2", servPort));//connect
  12.111 -  localSocket->SetConnectCallback (MakeCallback (&CloseConnection),
  12.112 -                                   MakeNullCallback<void, Ptr<Socket> > (),
  12.113 -                                   MakeNullCallback<void, Ptr<Socket> > ());
  12.114 -  //we want to close as soon as the connection is established
  12.115 -  //the tcp state machine and outgoing buffer will assure that
  12.116 -  //all of the data is delivered
  12.117 -  uint8_t data[nBytes];
  12.118 -  for(uint32_t i = 0; i < nBytes; ++i)
  12.119 -  {
  12.120 -    char m = toascii (97 + i % 26);
  12.121 -    data[i] = m;
  12.122 -  }
  12.123 -  localSocket->Send (data, nBytes);
  12.124 -}
  12.125 -
  12.126 -int main (int argc, char *argv[])
  12.127 -{
  12.128 -
  12.129 -  // Users may find it convenient to turn on explicit debugging
  12.130 -  // for selected modules; the below lines suggest how to do this
  12.131 -//  LogComponentEnable("TcpL4Protocol", LOG_LEVEL_ALL);
  12.132 -  // LogComponentEnable("TcpSocket", LOG_LEVEL_ALL);
  12.133 -//  LogComponentEnable("PacketSink", LOG_LEVEL_ALL);
  12.134 -  LogComponentEnable("TcpSmallTransfer", LOG_LEVEL_ALL);
  12.135 -
  12.136 -  // Allow the user to override any of the defaults and the above
  12.137 -  // Bind()s at run-time, via command-line arguments
  12.138 -  CommandLine cmd;
  12.139 -  cmd.Parse (argc, argv);
  12.140 -
  12.141 -  // Here, we will explicitly create three nodes.  In more sophisticated
  12.142 -  // topologies, we could configure a node factory.
  12.143 -  Ptr<Node> n0 = Create<InternetNode> ();
  12.144 -  Ptr<Node> n1 = Create<InternetNode> (); 
  12.145 -  Ptr<Node> n2 = Create<InternetNode> ();
  12.146 -
  12.147 -  // We create the channels first without any IP addressing information
  12.148 -  Ptr<PointToPointChannel> channel0 = 
  12.149 -    PointToPointTopology::AddPointToPointLink (
  12.150 -    n0, n1, DataRate(1000000), MilliSeconds(10));
  12.151 -  
  12.152 -  // Later, we add IP addresses.  
  12.153 -  PointToPointTopology::AddIpv4Addresses (
  12.154 -      channel0, n0, Ipv4Address("10.1.3.1"),
  12.155 -      n1, Ipv4Address("10.1.3.2"));
  12.156 -
  12.157 -  Ptr<PointToPointChannel> channel1 = 
  12.158 -      PointToPointTopology::AddPointToPointLink (
  12.159 -      n1, n2, DataRate(100000), MilliSeconds(10));
  12.160 -  
  12.161 -  PointToPointTopology::AddIpv4Addresses (
  12.162 -      channel1, n1, Ipv4Address("10.1.2.1"),
  12.163 -      n2, Ipv4Address("10.1.2.2"));
  12.164 -  
  12.165 -  // Finally, we add static routes.  These three steps (Channel and
  12.166 -  // NetDevice creation, IP Address assignment, and routing) are 
  12.167 -  // separated because there may be a need to postpone IP Address
  12.168 -  // assignment (emulation) or modify to use dynamic routing
  12.169 -  PointToPointTopology::AddIpv4Routes(n0, n1, channel0);
  12.170 -  PointToPointTopology::AddIpv4Routes(n1, n2, channel1);
  12.171 -  Ptr<Ipv4> ipv4;
  12.172 -  ipv4 = n0->GetObject<Ipv4> ();
  12.173 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.3.2"), 1);
  12.174 -  ipv4 = n2->GetObject<Ipv4> ();
  12.175 -  ipv4->SetDefaultRoute (Ipv4Address ("10.1.2.1"), 1);
  12.176 -
  12.177 -
  12.178 -  ///////////////////////////////////////////////////////////////////////////
  12.179 -  // Simulation 1
  12.180 -  // 
  12.181 -  // Send 2000 bytes over a connection to server port 500 at time 0
  12.182 -  // Should observe SYN exchange, two data segments, and FIN exchange
  12.183 -  //
  12.184 -  ///////////////////////////////////////////////////////////////////////////
  12.185 -
  12.186 -  int nBytes = 2000;
  12.187 -  uint16_t servPort = 500;
  12.188 -
  12.189 -  Ptr<SocketFactory> socketFactory = 
  12.190 -    n0->GetObject<SocketFactory> ();
  12.191 -  Ptr<Socket> localSocket = socketFactory->CreateSocket ();
  12.192 -  localSocket->Bind ();
  12.193 -
  12.194 -  // Create a packet sink to receive these packets
  12.195 -  Ptr<PacketSink> sink = 
  12.196 -    CreateObject<PacketSink> ("Local", Address (InetSocketAddress (Ipv4Address::GetAny (), servPort)),
  12.197 -                              "Protocol", TypeId::LookupByName ("ns3::Tcp"));
  12.198 -  n2->AddApplication (sink);
  12.199 -  sink->Start (Seconds (0.0));
  12.200 -  sink->Stop (Seconds (100.0));
  12.201 -
  12.202 -  Simulator::Schedule(Seconds(0), &StartFlow, localSocket, nBytes,
  12.203 -    servPort);
  12.204 -
  12.205 -  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
  12.206 -  // Trace output will be sent to the simple-examples.tr file
  12.207 -  AsciiTrace asciitrace ("tcp-small-transfer.tr");
  12.208 -  asciitrace.TraceAllQueues ();
  12.209 -  asciitrace.TraceAllNetDeviceRx ();
  12.210 -
  12.211 -  
  12.212 -  // Also configure some tcpdump traces; each interface will be traced
  12.213 -  // The output files will be named 
  12.214 -  // simple-examples.pcap-<nodeId>-<interfaceId>
  12.215 -  // and can be read by the "tcpdump -r" command (use "-tt" option to
  12.216 -  // display timestamps correctly)
  12.217 -  PcapTrace pcaptrace ("tcp-small-transfer.pcap");
  12.218 -  pcaptrace.TraceAllIp ();
  12.219 -
  12.220 -  Config::ConnectWithoutContext ("/NodeList/*/ApplicationList/*/Rx", MakeCallback (&ApplicationTraceSink));
  12.221 -
  12.222 -  Simulator::StopAt (Seconds(1000));
  12.223 -  Simulator::Run ();
  12.224 -  Simulator::Destroy ();
  12.225 -}
    13.1 --- a/examples/udp-echo.cc	Mon Mar 31 13:54:41 2008 -0700
    13.2 +++ b/examples/udp-echo.cc	Mon Mar 31 13:54:57 2008 -0700
    13.3 @@ -25,11 +25,10 @@
    13.4  // - DropTail queues 
    13.5  // - Tracing of queues and packet receptions to file "udp-echo.tr"
    13.6  
    13.7 +#include <fstream>
    13.8  #include "ns3/core-module.h"
    13.9  #include "ns3/simulator-module.h"
   13.10  #include "ns3/helper-module.h"
   13.11 -#include "ns3/ascii-trace.h"
   13.12 -#include "ns3/pcap-trace.h"
   13.13  
   13.14  using namespace ns3;
   13.15  
   13.16 @@ -127,23 +126,11 @@
   13.17    apps.Start (Seconds (2.0));
   13.18    apps.Stop (Seconds (10.0));
   13.19  
   13.20 -//
   13.21 -// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
   13.22 -// Trace output will be sent to the file "udp-echo.tr"
   13.23 -//
   13.24 -  NS_LOG_INFO ("Configure Tracing.");
   13.25 -  AsciiTrace asciitrace ("udp-echo.tr");
   13.26 -  asciitrace.TraceAllNetDeviceRx ();
   13.27 -  asciitrace.TraceAllQueues ();
   13.28 -//
   13.29 -// Also configure some tcpdump traces; each interface will be traced.
   13.30 -// The output files will be named:
   13.31 -//     udp-echo.pcap-<nodeId>-<interfaceId>
   13.32 -// and can be read by the "tcpdump -r" command (use "-tt" option to
   13.33 -// display timestamps correctly)
   13.34 -//
   13.35 -  PcapTrace pcaptrace ("udp-echo.pcap");
   13.36 -  pcaptrace.TraceAllIp ();
   13.37 +  std::ofstream ascii;
   13.38 +  ascii.open ("udp-echo.tr");
   13.39 +  CsmaHelper::EnablePcap ("udp-echo.pcap");
   13.40 +  CsmaHelper::EnableAscii (ascii);
   13.41 +
   13.42  //
   13.43  // Now, do the actual simulation.
   13.44  //
    14.1 --- a/examples/wscript	Mon Mar 31 13:54:41 2008 -0700
    14.2 +++ b/examples/wscript	Mon Mar 31 13:54:57 2008 -0700
    14.3 @@ -50,22 +50,6 @@
    14.4          ['point-to-point', 'internet-node'])
    14.5      obj.source = 'tcp-large-transfer.cc'
    14.6  
    14.7 -    obj = bld.create_ns3_program('tcp-large-transfer-errors',
    14.8 -        ['point-to-point', 'internet-node'])
    14.9 -    obj.source = 'tcp-large-transfer-errors.cc'
   14.10 -
   14.11 -    obj = bld.create_ns3_program('tcp-nonlistening-server',
   14.12 -        ['point-to-point', 'internet-node'])
   14.13 -    obj.source = 'tcp-nonlistening-server.cc'
   14.14 -
   14.15 -    obj = bld.create_ns3_program('tcp-small-transfer',
   14.16 -        ['point-to-point', 'internet-node'])
   14.17 -    obj.source = 'tcp-small-transfer.cc'
   14.18 -
   14.19 -    obj = bld.create_ns3_program('tcp-small-transfer-oneloss',
   14.20 -        ['point-to-point', 'internet-node'])
   14.21 -    obj.source = 'tcp-small-transfer-oneloss.cc'
   14.22 -
   14.23      obj = bld.create_ns3_program('wifi-adhoc',
   14.24                                   ['core', 'simulator', 'mobility', 'wifi'])
   14.25      obj.source = 'wifi-adhoc.cc'
    15.1 --- a/src/common/buffer.cc	Mon Mar 31 13:54:41 2008 -0700
    15.2 +++ b/src/common/buffer.cc	Mon Mar 31 13:54:57 2008 -0700
    15.3 @@ -762,6 +762,33 @@
    15.4    WriteU8 (data & 0xff);
    15.5  }
    15.6  void 
    15.7 +Buffer::Iterator::WriteHtolsbU16 (uint16_t data)
    15.8 +{
    15.9 +  WriteU8 ((data >> 0) & 0xff);
   15.10 +  WriteU8 ((data >> 8) & 0xff);
   15.11 +}
   15.12 +void 
   15.13 +Buffer::Iterator::WriteHtolsbU32 (uint32_t data)
   15.14 +{
   15.15 +  WriteU8 ((data >> 0) & 0xff);
   15.16 +  WriteU8 ((data >> 8) & 0xff);
   15.17 +  WriteU8 ((data >> 16) & 0xff);
   15.18 +  WriteU8 ((data >> 24) & 0xff);
   15.19 +}
   15.20 +void 
   15.21 +Buffer::Iterator::WriteHtolsbU64 (uint64_t data)
   15.22 +{
   15.23 +  WriteU8 ((data >> 0) & 0xff);
   15.24 +  WriteU8 ((data >> 8) & 0xff);
   15.25 +  WriteU8 ((data >> 16) & 0xff);
   15.26 +  WriteU8 ((data >> 24) & 0xff);
   15.27 +  WriteU8 ((data >> 32) & 0xff);
   15.28 +  WriteU8 ((data >> 40) & 0xff);
   15.29 +  WriteU8 ((data >> 48) & 0xff);
   15.30 +  WriteU8 ((data >> 54) & 0xff);
   15.31 +}
   15.32 +
   15.33 +void 
   15.34  Buffer::Iterator::WriteHtonU16 (uint16_t data)
   15.35  {
   15.36    WriteU8 ((data >> 8) & 0xff);
   15.37 @@ -895,6 +922,61 @@
   15.38    retval |= ReadU8 ();
   15.39    return retval;
   15.40  }
   15.41 +uint16_t 
   15.42 +Buffer::Iterator::ReadLsbtohU16 (void)
   15.43 +{
   15.44 +  uint8_t byte0 = ReadU8 ();
   15.45 +  uint8_t byte1 = ReadU8 ();
   15.46 +  uint16_t data = byte1;
   15.47 +  data <<= 8;
   15.48 +  data |= byte0;
   15.49 +  return data;
   15.50 +}
   15.51 +uint32_t 
   15.52 +Buffer::Iterator::ReadLsbtohU32 (void)
   15.53 +{
   15.54 +  uint8_t byte0 = ReadU8 ();
   15.55 +  uint8_t byte1 = ReadU8 ();
   15.56 +  uint8_t byte2 = ReadU8 ();
   15.57 +  uint8_t byte3 = ReadU8 ();
   15.58 +  uint32_t data = byte3;
   15.59 +  data <<= 8;
   15.60 +  data |= byte2;
   15.61 +  data <<= 8;
   15.62 +  data |= byte1;
   15.63 +  data <<= 8;
   15.64 +  data |= byte0;
   15.65 +  return data;
   15.66 +}
   15.67 +uint64_t 
   15.68 +Buffer::Iterator::ReadLsbtohU64 (void)
   15.69 +{
   15.70 +  uint8_t byte0 = ReadU8 ();
   15.71 +  uint8_t byte1 = ReadU8 ();
   15.72 +  uint8_t byte2 = ReadU8 ();
   15.73 +  uint8_t byte3 = ReadU8 ();
   15.74 +  uint8_t byte4 = ReadU8 ();
   15.75 +  uint8_t byte5 = ReadU8 ();
   15.76 +  uint8_t byte6 = ReadU8 ();
   15.77 +  uint8_t byte7 = ReadU8 ();
   15.78 +  uint32_t data = byte7;
   15.79 +  data <<= 8;
   15.80 +  data |= byte6;
   15.81 +  data <<= 8;
   15.82 +  data |= byte5;
   15.83 +  data <<= 8;
   15.84 +  data |= byte4;
   15.85 +  data <<= 8;
   15.86 +  data |= byte3;
   15.87 +  data <<= 8;
   15.88 +  data |= byte2;
   15.89 +  data <<= 8;
   15.90 +  data |= byte1;
   15.91 +  data <<= 8;
   15.92 +  data |= byte0;
   15.93 +
   15.94 +  return data;
   15.95 +}
   15.96  void 
   15.97  Buffer::Iterator::Read (uint8_t *buffer, uint32_t size)
   15.98  {
    16.1 --- a/src/common/buffer.h	Mon Mar 31 13:54:41 2008 -0700
    16.2 +++ b/src/common/buffer.h	Mon Mar 31 13:54:57 2008 -0700
    16.3 @@ -91,12 +91,14 @@
    16.4   *
    16.5   * A simple state invariant is that m_start <= m_zeroStart <= m_zeroEnd <= m_end
    16.6   */
    16.7 -class Buffer {
    16.8 +class Buffer 
    16.9 +{
   16.10  public:
   16.11    /**
   16.12     * \brief iterator in a Buffer instance
   16.13     */
   16.14 -  class Iterator {
   16.15 +  class Iterator 
   16.16 +  {
   16.17    public:
   16.18        Iterator ();
   16.19        /**
   16.20 @@ -188,6 +190,30 @@
   16.21         * by two bytes. The data is written in network order and the
   16.22         * input data is expected to be in host order.
   16.23         */
   16.24 +      void WriteHtolsbU16 (uint16_t data);
   16.25 +      /**
   16.26 +       * \param data data to write in buffer
   16.27 +       *
   16.28 +       * Write the data in buffer and avance the iterator position
   16.29 +       * by four bytes. The data is written in least significant byte order and the
   16.30 +       * input data is expected to be in host order.
   16.31 +       */
   16.32 +      void WriteHtolsbU32 (uint32_t data);
   16.33 +      /**
   16.34 +       * \param data data to write in buffer
   16.35 +       *
   16.36 +       * Write the data in buffer and avance the iterator position
   16.37 +       * by eight bytes. The data is written in least significant byte order and the
   16.38 +       * input data is expected to be in host order.
   16.39 +       */
   16.40 +      void WriteHtolsbU64 (uint64_t data);
   16.41 +      /**
   16.42 +       * \param data data to write in buffer
   16.43 +       *
   16.44 +       * Write the data in buffer and avance the iterator position
   16.45 +       * by two bytes. The data is written in least significant byte order and the
   16.46 +       * input data is expected to be in host order.
   16.47 +       */
   16.48        void WriteHtonU16 (uint16_t data);
   16.49        /**
   16.50         * \param data data to write in buffer
   16.51 @@ -282,6 +308,30 @@
   16.52         */
   16.53        uint64_t ReadNtohU64 (void);
   16.54        /**
   16.55 +       * \return the two bytes read in the buffer.
   16.56 +       *
   16.57 +       * Read data and advance the Iterator by the number of bytes
   16.58 +       * read.
   16.59 +       * The data is read in network format and return in host format.
   16.60 +       */
   16.61 +      uint16_t ReadLsbtohU16 (void);
   16.62 +      /**
   16.63 +       * \return the four bytes read in the buffer.
   16.64 +       *
   16.65 +       * Read data and advance the Iterator by the number of bytes
   16.66 +       * read.
   16.67 +       * The data is read in network format and return in host format.
   16.68 +       */
   16.69 +      uint32_t ReadLsbtohU32 (void);
   16.70 +      /**
   16.71 +       * \return the eight bytes read in the buffer.
   16.72 +       *
   16.73 +       * Read data and advance the Iterator by the number of bytes
   16.74 +       * read.
   16.75 +       * The data is read in network format and return in host format.
   16.76 +       */
   16.77 +      uint64_t ReadLsbtohU64 (void);
   16.78 +      /**
   16.79         * \param buffer buffer to copy data into
   16.80         * \param size number of bytes to copy
   16.81         *
    17.1 --- a/src/common/packet.cc	Mon Mar 31 13:54:41 2008 -0700
    17.2 +++ b/src/common/packet.cc	Mon Mar 31 13:54:57 2008 -0700
    17.3 @@ -257,6 +257,7 @@
    17.4                NS_ASSERT (chunk != 0);
    17.5                chunk->Deserialize (item.current);
    17.6                chunk->Print (os);
    17.7 +              delete chunk;
    17.8              }
    17.9              os << ")";
   17.10              break;
    18.1 --- a/src/core/log.cc	Mon Mar 31 13:54:41 2008 -0700
    18.2 +++ b/src/core/log.cc	Mon Mar 31 13:54:57 2008 -0700
    18.3 @@ -91,7 +91,10 @@
    18.4         i != components->end ();
    18.5         i++)
    18.6      {
    18.7 -      NS_ASSERT (i->first != name);
    18.8 +      if (i->first == name)
    18.9 +        {
   18.10 +          NS_FATAL_ERROR ("Log component \""<<name<<"\" has already been registered once.");
   18.11 +        }
   18.12      }
   18.13    components->push_back (std::make_pair (name, this));
   18.14  }
    19.1 --- a/src/core/rng-stream.h	Mon Mar 31 13:54:41 2008 -0700
    19.2 +++ b/src/core/rng-stream.h	Mon Mar 31 13:54:57 2008 -0700
    19.3 @@ -22,8 +22,20 @@
    19.4  #include <string>
    19.5  #include <stdint.h>
    19.6  
    19.7 -namespace ns3{
    19.8 +namespace ns3 {
    19.9  
   19.10 +/**
   19.11 + * \ingroup core
   19.12 + * \ingroup randomvariable 
   19.13 + *
   19.14 + * \brief Combined Multiple-Recursive Generator MRG32k3a
   19.15 + *
   19.16 + * This class is the combined multiple-recursive random number
   19.17 + * generator called MRG32k3a.  The ns3::RandomVariableBase class
   19.18 + * holds a static instance of this class.  The details of this
   19.19 + * class are explained in:  
   19.20 + * http://www.iro.umontreal.ca/~lecuyer/myftp/papers/streams00.pdf
   19.21 + */
   19.22  class RngStream {
   19.23  public:  //public api
   19.24    RngStream ();
   19.25 @@ -52,7 +64,7 @@
   19.26    static double nextSeed[6];
   19.27  };
   19.28  
   19.29 -};//namespace ns3
   19.30 +} //namespace ns3
   19.31  
   19.32  #endif
   19.33   
    20.1 --- a/src/devices/csma/csma-net-device.cc	Mon Mar 31 13:54:41 2008 -0700
    20.2 +++ b/src/devices/csma/csma-net-device.cc	Mon Mar 31 13:54:57 2008 -0700
    20.3 @@ -601,7 +601,7 @@
    20.4  bool 
    20.5  CsmaNetDevice::IsMulticast (void) const
    20.6  {
    20.7 -  return false;
    20.8 +  return true;
    20.9  }
   20.10  Address 
   20.11  CsmaNetDevice::GetMulticast (void) const
    21.1 --- a/src/devices/wifi/mac-low.cc	Mon Mar 31 13:54:41 2008 -0700
    21.2 +++ b/src/devices/wifi/mac-low.cc	Mon Mar 31 13:54:57 2008 -0700
    21.3 @@ -841,6 +841,7 @@
    21.4    rts.SetType (WIFI_MAC_CTL_RTS);
    21.5    rts.SetDsNotFrom ();
    21.6    rts.SetDsNotTo ();
    21.7 +  rts.SetNoMoreFragments ();
    21.8    rts.SetAddr1 (m_currentHdr.GetAddr1 ());
    21.9    rts.SetAddr2 (m_mac->GetAddress ());
   21.10    WifiMode rtsTxMode = GetRtsTxMode (m_currentPacket, &m_currentHdr);
   21.11 @@ -984,6 +985,7 @@
   21.12    cts.SetType (WIFI_MAC_CTL_CTS);
   21.13    cts.SetDsNotFrom ();
   21.14    cts.SetDsNotTo ();
   21.15 +  cts.SetNoMoreFragments ();
   21.16    cts.SetAddr1 (source);
   21.17    duration -= GetCtsDuration (source, rtsTxMode);
   21.18    duration -= GetSifs ();
   21.19 @@ -1058,6 +1060,7 @@
   21.20    ack.SetType (WIFI_MAC_CTL_ACK);
   21.21    ack.SetDsNotFrom ();
   21.22    ack.SetDsNotTo ();
   21.23 +  ack.SetNoMoreFragments ();
   21.24    ack.SetAddr1 (source);
   21.25    duration -= GetAckDuration (source, dataTxMode);
   21.26    duration -= GetSifs ();
    22.1 --- a/src/devices/wifi/wifi-channel.h	Mon Mar 31 13:54:41 2008 -0700
    22.2 +++ b/src/devices/wifi/wifi-channel.h	Mon Mar 31 13:54:57 2008 -0700
    22.3 @@ -39,11 +39,10 @@
    22.4   *
    22.5   * This channel subclass can be used to connect together a set of 
    22.6   * ns3::WifiNetDevice network interfaces. A WifiChannel contains
    22.7 - * a PropagationLossModel and a PropagationDelayModel which can
    22.8 + * a ns3::PropagationLossModel and a ns3::PropagationDelayModel which can
    22.9   * be overriden by the WifiChannel::SetPropagationLossModel
   22.10   * and the WifiChannel::SetPropagationDelayModel methods. By default,
   22.11 - * The PropagationDelayModel is a ns3::ConstantSpeedPropagationModel,
   22.12 - * and the PropagationLossModel is a ns3::PathLossPropagationModel.
   22.13 + * no propagation models are set.
   22.14   */
   22.15  class WifiChannel : public Channel
   22.16  {
    23.1 --- a/src/devices/wifi/wifi-mac-header.cc	Mon Mar 31 13:54:41 2008 -0700
    23.2 +++ b/src/devices/wifi/wifi-mac-header.cc	Mon Mar 31 13:54:57 2008 -0700
    23.3 @@ -51,6 +51,7 @@
    23.4  };
    23.5  
    23.6  WifiMacHeader::WifiMacHeader ()
    23.7 +  : m_ctrlMoreData (0)
    23.8  {}
    23.9  WifiMacHeader::~WifiMacHeader ()
   23.10  {}
   23.11 @@ -879,14 +880,14 @@
   23.12  void 
   23.13  WifiMacHeader::Serialize (Buffer::Iterator i) const
   23.14  {
   23.15 -  i.WriteHtonU16 (GetFrameControl ());
   23.16 -  i.WriteHtonU16 (m_duration);
   23.17 +  i.WriteHtolsbU16 (GetFrameControl ());
   23.18 +  i.WriteHtolsbU16 (m_duration);
   23.19    WriteTo (i, m_addr1);
   23.20    switch (m_ctrlType) {
   23.21    case TYPE_MGT:
   23.22      WriteTo (i, m_addr2);
   23.23      WriteTo (i, m_addr3);
   23.24 -    i.WriteHtonU16 (GetSequenceControl ());
   23.25 +    i.WriteHtolsbU16 (GetSequenceControl ());
   23.26      break;
   23.27    case TYPE_CTL:
   23.28      switch (m_ctrlSubtype) {
   23.29 @@ -910,12 +911,12 @@
   23.30    case TYPE_DATA: {
   23.31      WriteTo (i, m_addr2);
   23.32      WriteTo (i, m_addr3);
   23.33 -    i.WriteHtonU16 (GetSequenceControl ());
   23.34 +    i.WriteHtolsbU16 (GetSequenceControl ());
   23.35      if (m_ctrlToDs && m_ctrlFromDs) {
   23.36        WriteTo (i, m_addr4);
   23.37      }
   23.38      if (m_ctrlSubtype & 0x08) {
   23.39 -      i.WriteHtonU16 (GetQosControl ());
   23.40 +      i.WriteHtolsbU16 (GetQosControl ());
   23.41      }
   23.42      } break;
   23.43    default:
   23.44 @@ -928,15 +929,15 @@
   23.45  WifiMacHeader::Deserialize (Buffer::Iterator start)
   23.46  {
   23.47    Buffer::Iterator i = start;
   23.48 -  uint16_t frame_control = i.ReadNtohU16 ();
   23.49 +  uint16_t frame_control = i.ReadLsbtohU16 ();
   23.50    SetFrameControl (frame_control);
   23.51 -  m_duration = i.ReadNtohU16 ();
   23.52 +  m_duration = i.ReadLsbtohU16 ();
   23.53    ReadFrom (i, m_addr1);
   23.54    switch (m_ctrlType) {
   23.55    case TYPE_MGT:
   23.56      ReadFrom (i, m_addr2);
   23.57      ReadFrom (i, m_addr3);
   23.58 -    SetSequenceControl (i.ReadNtohU16 ());
   23.59 +    SetSequenceControl (i.ReadLsbtohU16 ());
   23.60      break;
   23.61    case TYPE_CTL:
   23.62      switch (m_ctrlSubtype) {
   23.63 @@ -956,12 +957,12 @@
   23.64    case TYPE_DATA:
   23.65      ReadFrom (i, m_addr2);
   23.66      ReadFrom (i, m_addr3);
   23.67 -    SetSequenceControl (i.ReadNtohU16 ());
   23.68 +    SetSequenceControl (i.ReadLsbtohU16 ());
   23.69      if (m_ctrlToDs && m_ctrlFromDs) {
   23.70        ReadFrom (i, m_addr4);
   23.71      }
   23.72      if (m_ctrlSubtype & 0x08) {
   23.73 -      SetQosControl (i.ReadNtohU16 ());
   23.74 +      SetQosControl (i.ReadLsbtohU16 ());
   23.75      }
   23.76      break;
   23.77    }
    24.1 --- a/src/helper/csma-helper.cc	Mon Mar 31 13:54:41 2008 -0700
    24.2 +++ b/src/helper/csma-helper.cc	Mon Mar 31 13:54:57 2008 -0700
    24.3 @@ -1,4 +1,5 @@
    24.4  #include "csma-helper.h"
    24.5 +#include "ns3/simulator.h"
    24.6  #include "ns3/object-factory.h"
    24.7  #include "ns3/queue.h"
    24.8  #include "ns3/csma-net-device.h"
    24.9 @@ -11,8 +12,6 @@
   24.10  namespace ns3 {
   24.11  
   24.12  CsmaHelper::CsmaHelper ()
   24.13 -  : m_pcap (false), 
   24.14 -    m_ascii (false)
   24.15  {
   24.16    m_queueFactory.SetTypeId ("ns3::DropTailQueue");
   24.17    m_deviceFactory.SetTypeId ("ns3::CsmaNetDevice");
   24.18 @@ -46,27 +45,95 @@
   24.19  }
   24.20  
   24.21  void 
   24.22 +CsmaHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
   24.23 +{
   24.24 +  std::ostringstream oss;
   24.25 +  oss << filename << "-" << nodeid << "-" << deviceid;
   24.26 +  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
   24.27 +  pcap->Open (oss.str ());
   24.28 +  pcap->WriteEthernetHeader ();
   24.29 +  oss.str ("");
   24.30 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Rx";
   24.31 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::RxEvent, pcap));
   24.32 +  oss.str ("");
   24.33 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
   24.34 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
   24.35 +}
   24.36 +void 
   24.37 +CsmaHelper::EnablePcap (std::string filename, NetDeviceContainer d)
   24.38 +{
   24.39 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   24.40 +    {
   24.41 +      Ptr<NetDevice> dev = *i;
   24.42 +      EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   24.43 +    }
   24.44 +}
   24.45 +void
   24.46 +CsmaHelper::EnablePcap (std::string filename, NodeContainer n)
   24.47 +{
   24.48 +  NetDeviceContainer devs;
   24.49 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
   24.50 +    {
   24.51 +      Ptr<Node> node = *i;
   24.52 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
   24.53 +	{
   24.54 +	  devs.Add (node->GetDevice (j));
   24.55 +	}
   24.56 +    }
   24.57 +  EnablePcap (filename, devs);
   24.58 +}
   24.59 +
   24.60 +void
   24.61  CsmaHelper::EnablePcap (std::string filename)
   24.62  {
   24.63 -  m_pcap = true;
   24.64 -  m_pcapFilename = filename;
   24.65 -}
   24.66 -void 
   24.67 -CsmaHelper::DisablePcap (void)
   24.68 -{
   24.69 -  m_pcap = false;
   24.70 +  EnablePcap (filename, NodeContainer::GetGlobal ());
   24.71  }
   24.72  
   24.73  void 
   24.74 +CsmaHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
   24.75 +{
   24.76 +  Packet::EnableMetadata ();
   24.77 +  std::ostringstream oss;
   24.78 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/Rx";
   24.79 +  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiRxEvent, &os));
   24.80 +  oss.str ("");
   24.81 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Enqueue";
   24.82 +  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEnqueueEvent, &os));
   24.83 +  oss.str ("");
   24.84 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Dequeue";
   24.85 +  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDequeueEvent, &os));
   24.86 +  oss.str ("");
   24.87 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::CsmaNetDevice/TxQueue/Drop";
   24.88 +  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiDropEvent, &os));
   24.89 +}
   24.90 +void 
   24.91 +CsmaHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
   24.92 +{
   24.93 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   24.94 +    {
   24.95 +      Ptr<NetDevice> dev = *i;
   24.96 +      EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   24.97 +    }
   24.98 +}
   24.99 +void
  24.100 +CsmaHelper::EnableAscii (std::ostream &os, NodeContainer n)
  24.101 +{
  24.102 +  NetDeviceContainer devs;
  24.103 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
  24.104 +    {
  24.105 +      Ptr<Node> node = *i;
  24.106 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
  24.107 +	{
  24.108 +	  devs.Add (node->GetDevice (j));
  24.109 +	}
  24.110 +    }
  24.111 +  EnableAscii (os, devs);
  24.112 +}
  24.113 +
  24.114 +void
  24.115  CsmaHelper::EnableAscii (std::ostream &os)
  24.116  {
  24.117 -  m_ascii = true;
  24.118 -  m_asciiOs = &os;
  24.119 -}
  24.120 -void 
  24.121 -CsmaHelper::DisableAscii (void)
  24.122 -{
  24.123 -  m_ascii = false;
  24.124 +  EnableAscii (os, NodeContainer::GetGlobal ());
  24.125  }
  24.126  
  24.127  
  24.128 @@ -90,31 +157,6 @@
  24.129        Ptr<Queue> queue = m_queueFactory.Create<Queue> ();
  24.130        device->AddQueue (queue);
  24.131        device->Attach (channel);
  24.132 -      if (m_pcap)
  24.133 -	{
  24.134 -	  std::ostringstream oss;
  24.135 -	  oss << m_pcapFilename << "-" << node->GetId () << "-" << device->GetIfIndex ();
  24.136 -	  std::string filename = oss.str ();
  24.137 -	  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
  24.138 -	  pcap->Open (filename);
  24.139 -	  pcap->WriteEthernetHeader ();
  24.140 -	  device->TraceConnectWithoutContext ("Rx", MakeBoundCallback (&CsmaHelper::RxEvent, pcap));
  24.141 -	  queue->TraceConnectWithoutContext ("Enqueue", MakeBoundCallback (&CsmaHelper::EnqueueEvent, pcap));
  24.142 -	}
  24.143 -      if (m_ascii)
  24.144 -	{
  24.145 -	  Packet::EnableMetadata ();
  24.146 -	  std::ostringstream oss;
  24.147 -	  oss << "/NodeList/" << node->GetId () << "/DeviceList/" << device->GetIfIndex () << "/Rx";
  24.148 -	  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEvent, m_asciiOs));
  24.149 -	  oss.str ("");
  24.150 -	  oss << "/NodeList/" << node->GetId () << "/DeviceList/" << device->GetIfIndex () << "/TxQueue/Enqueue";
  24.151 -	  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEvent, m_asciiOs));
  24.152 -	  oss.str ("");
  24.153 -	  oss << "/NodeList/" << node->GetId () << "/DeviceList/" << device->GetIfIndex () << "/TxQueue/Dequeue";
  24.154 -	  Config::Connect (oss.str (), MakeBoundCallback (&CsmaHelper::AsciiEvent, m_asciiOs));
  24.155 -	  
  24.156 -	}
  24.157        container.Add (device);
  24.158      }
  24.159    return container;
  24.160 @@ -131,10 +173,31 @@
  24.161    writer->WritePacket (packet);
  24.162  }
  24.163  void 
  24.164 -CsmaHelper::AsciiEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  24.165 +CsmaHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  24.166  {
  24.167 +  *os << "+ " << Simulator::Now ().GetSeconds () << " ";
  24.168    *os << path << " " << *packet << std::endl;
  24.169  }
  24.170  
  24.171 +void 
  24.172 +CsmaHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  24.173 +{
  24.174 +  *os << "- " << Simulator::Now ().GetSeconds () << " ";
  24.175 +  *os << path << " " << *packet << std::endl;
  24.176 +}
  24.177 +
  24.178 +void 
  24.179 +CsmaHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  24.180 +{
  24.181 +  *os << "d " << Simulator::Now ().GetSeconds () << " ";
  24.182 +  *os << path << " " << *packet << std::endl;
  24.183 +}
  24.184 +
  24.185 +void 
  24.186 +CsmaHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  24.187 +{
  24.188 +  *os << "r " << Simulator::Now ().GetSeconds () << " ";
  24.189 +  *os << path << " " << *packet << std::endl;
  24.190 +}
  24.191  
  24.192  } // namespace ns3
    25.1 --- a/src/helper/csma-helper.h	Mon Mar 31 13:54:41 2008 -0700
    25.2 +++ b/src/helper/csma-helper.h	Mon Mar 31 13:54:57 2008 -0700
    25.3 @@ -61,22 +61,81 @@
    25.4    void SetChannelParameter (std::string n1, Attribute v1);
    25.5  
    25.6    /**
    25.7 -   * \param filename file template to dump pcap traces in.
    25.8 +   * \param filename filename prefix to use for pcap files.
    25.9 +   * \param nodeid the id of the node to generate pcap output for.
   25.10 +   * \param deviceid the id of the device to generate pcap output for.
   25.11     *
   25.12 -   * Every ns3::CsmaNetDevice created through subsequent calls
   25.13 -   * to CsmaHelper::Build will be configured to dump
   25.14 -   * pcap output in a file named filename-nodeid-deviceid.
   25.15 +   * Generate a pcap file which contains the link-level data observed
   25.16 +   * by the specified deviceid within the specified nodeid. The pcap
   25.17 +   * data is stored in the file prefix-nodeid-deviceid.
   25.18 +   *
   25.19 +   * This method should be invoked after the network topology has 
   25.20 +   * been fully constructed.
   25.21     */
   25.22 -  void EnablePcap (std::string filename);
   25.23 +  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
   25.24    /**
   25.25 -   * Every ns3::CsmaNetDevice created through subsequent calls
   25.26 -   * to CsmaHelper::Build will be configured to not dump any pcap
   25.27 -   * output.
   25.28 +   * \param filename filename prefix to use for pcap files.
   25.29 +   * \param d container of devices of type ns3::CsmaNetDevice
   25.30 +   *
   25.31 +   * Enable pcap output on each input device which is of the
   25.32 +   * ns3::CsmaNetDevice type.
   25.33     */
   25.34 -  void DisablePcap (void);
   25.35 +  static void EnablePcap (std::string filename, NetDeviceContainer d);
   25.36 +  /**
   25.37 +   * \param filename filename prefix to use for pcap files.
   25.38 +   * \param n container of nodes.
   25.39 +   *
   25.40 +   * Enable pcap output on each device which is of the
   25.41 +   * ns3::CsmaNetDevice type and which is located in one of the 
   25.42 +   * input nodes.
   25.43 +   */
   25.44 +  static void EnablePcap (std::string filename, NodeContainer n);
   25.45 +  /**
   25.46 +   * \param filename filename prefix to use for pcap files.
   25.47 +   *
   25.48 +   * Enable pcap output on each device which is of the
   25.49 +   * ns3::CsmaNetDevice type
   25.50 +   */
   25.51 +  static void EnablePcap (std::string filename);
   25.52  
   25.53 -  void EnableAscii (std::ostream &os);
   25.54 -  void DisableAscii (void);
   25.55 +  /**
   25.56 +   * \param os output stream
   25.57 +   * \param nodeid the id of the node to generate ascii output for.
   25.58 +   * \param deviceid the id of the device to generate ascii output for.
   25.59 +   *
   25.60 +   * Enable ascii output on the specified deviceid within the
   25.61 +   * specified nodeid if it is of type ns3::CsmaNetDevice and dump 
   25.62 +   * that to the specified stdc++ output stream.
   25.63 +   */
   25.64 +  static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
   25.65 +  /**
   25.66 +   * \param os output stream
   25.67 +   * \param d device container
   25.68 +   *
   25.69 +   * Enable ascii output on each device which is of the
   25.70 +   * ns3::CsmaNetDevice type and which is located in the input
   25.71 +   * device container and dump that to the specified
   25.72 +   * stdc++ output stream.
   25.73 +   */
   25.74 +  static void EnableAscii (std::ostream &os, NetDeviceContainer d);
   25.75 +  /**
   25.76 +   * \param os output stream
   25.77 +   * \param n node container
   25.78 +   *
   25.79 +   * Enable ascii output on each device which is of the
   25.80 +   * ns3::CsmaNetDevice type and which is located in one
   25.81 +   * of the input node and dump that to the specified
   25.82 +   * stdc++ output stream.
   25.83 +   */
   25.84 +  static void EnableAscii (std::ostream &os, NodeContainer n);
   25.85 +  /**
   25.86 +   * \param os output stream
   25.87 +   *
   25.88 +   * Enable ascii output on each device which is of the
   25.89 +   * ns3::CsmaNetDevice type and dump that to the specified
   25.90 +   * stdc++ output stream.
   25.91 +   */
   25.92 +  static void EnableAscii (std::ostream &os);
   25.93  
   25.94    /**
   25.95     * \param c a set of nodes
   25.96 @@ -100,14 +159,13 @@
   25.97  private:
   25.98    static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
   25.99    static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
  25.100 -  static void AsciiEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  25.101 +  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  25.102 +  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  25.103 +  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  25.104 +  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  25.105    ObjectFactory m_queueFactory;
  25.106    ObjectFactory m_deviceFactory;
  25.107    ObjectFactory m_channelFactory;
  25.108 -  bool m_pcap;
  25.109 -  std::string m_pcapFilename;
  25.110 -  bool m_ascii;
  25.111 -  std::ostream *m_asciiOs;
  25.112  };
  25.113  
  25.114  
    26.1 --- a/src/helper/point-to-point-helper.cc	Mon Mar 31 13:54:41 2008 -0700
    26.2 +++ b/src/helper/point-to-point-helper.cc	Mon Mar 31 13:54:57 2008 -0700
    26.3 @@ -1,7 +1,12 @@
    26.4  #include "point-to-point-helper.h"
    26.5 +#include "ns3/simulator.h"
    26.6  #include "ns3/point-to-point-net-device.h"
    26.7  #include "ns3/point-to-point-channel.h"
    26.8  #include "ns3/queue.h"
    26.9 +#include "ns3/pcap-writer.h"
   26.10 +#include "ns3/config.h"
   26.11 +#include "ns3/packet.h"
   26.12 +
   26.13  
   26.14  namespace ns3 {
   26.15  
   26.16 @@ -39,6 +44,97 @@
   26.17    m_channelFactory.Set (n1, v1);
   26.18  }
   26.19  
   26.20 +void 
   26.21 +PointToPointHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
   26.22 +{
   26.23 +  std::ostringstream oss;
   26.24 +  oss << filename << "-" << nodeid << "-" << deviceid;
   26.25 +  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
   26.26 +  pcap->Open (oss.str ());
   26.27 +  pcap->WriteEthernetHeader ();
   26.28 +  oss.str ("");
   26.29 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/Rx";
   26.30 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::RxEvent, pcap));
   26.31 +  oss.str ("");
   26.32 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
   26.33 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PointToPointHelper::EnqueueEvent, pcap));
   26.34 +}
   26.35 +void 
   26.36 +PointToPointHelper::EnablePcap (std::string filename, NetDeviceContainer d)
   26.37 +{
   26.38 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   26.39 +    {
   26.40 +      Ptr<NetDevice> dev = *i;
   26.41 +      EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   26.42 +    }
   26.43 +}
   26.44 +void
   26.45 +PointToPointHelper::EnablePcap (std::string filename, NodeContainer n)
   26.46 +{
   26.47 +  NetDeviceContainer devs;
   26.48 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
   26.49 +    {
   26.50 +      Ptr<Node> node = *i;
   26.51 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
   26.52 +	{
   26.53 +	  devs.Add (node->GetDevice (j));
   26.54 +	}
   26.55 +    }
   26.56 +  EnablePcap (filename, devs);
   26.57 +}
   26.58 +
   26.59 +void
   26.60 +PointToPointHelper::EnablePcap (std::string filename)
   26.61 +{
   26.62 +  EnablePcap (filename, NodeContainer::GetGlobal ());
   26.63 +}
   26.64 +
   26.65 +void 
   26.66 +PointToPointHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
   26.67 +{
   26.68 +  Packet::EnableMetadata ();
   26.69 +  std::ostringstream oss;
   26.70 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/Rx";
   26.71 +  Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiRxEvent, &os));
   26.72 +  oss.str ("");
   26.73 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Enqueue";
   26.74 +  Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiEnqueueEvent, &os));
   26.75 +  oss.str ("");
   26.76 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Dequeue";
   26.77 +  Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDequeueEvent, &os));
   26.78 +  oss.str ("");
   26.79 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::PointToPointNetDevice/TxQueue/Drop";
   26.80 +  Config::Connect (oss.str (), MakeBoundCallback (&PointToPointHelper::AsciiDropEvent, &os));
   26.81 +}
   26.82 +void 
   26.83 +PointToPointHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
   26.84 +{
   26.85 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   26.86 +    {
   26.87 +      Ptr<NetDevice> dev = *i;
   26.88 +      EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   26.89 +    }
   26.90 +}
   26.91 +void
   26.92 +PointToPointHelper::EnableAscii (std::ostream &os, NodeContainer n)
   26.93 +{
   26.94 +  NetDeviceContainer devs;
   26.95 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
   26.96 +    {
   26.97 +      Ptr<Node> node = *i;
   26.98 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
   26.99 +	{
  26.100 +	  devs.Add (node->GetDevice (j));
  26.101 +	}
  26.102 +    }
  26.103 +  EnableAscii (os, devs);
  26.104 +}
  26.105 +
  26.106 +void
  26.107 +PointToPointHelper::EnableAscii (std::ostream &os)
  26.108 +{
  26.109 +  EnableAscii (os, NodeContainer::GetGlobal ());
  26.110 +}
  26.111  
  26.112  NetDeviceContainer 
  26.113  PointToPointHelper::Build (NodeContainer c)
  26.114 @@ -70,5 +166,40 @@
  26.115    return container;
  26.116  }
  26.117  
  26.118 +void 
  26.119 +PointToPointHelper::EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
  26.120 +{
  26.121 +  writer->WritePacket (packet);
  26.122 +}
  26.123 +void 
  26.124 +PointToPointHelper::RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet)
  26.125 +{
  26.126 +  writer->WritePacket (packet);
  26.127 +}
  26.128 +void 
  26.129 +PointToPointHelper::AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  26.130 +{
  26.131 +  *os << "+ " << Simulator::Now ().GetSeconds () << " ";
  26.132 +  *os << path << " " << *packet << std::endl;
  26.133 +}
  26.134 +void 
  26.135 +PointToPointHelper::AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  26.136 +{
  26.137 +  *os << "- " << Simulator::Now ().GetSeconds () << " ";
  26.138 +  *os << path << " " << *packet << std::endl;
  26.139 +}
  26.140 +void 
  26.141 +PointToPointHelper::AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  26.142 +{
  26.143 +  *os << "d " << Simulator::Now ().GetSeconds () << " ";
  26.144 +  *os << path << " " << *packet << std::endl;
  26.145 +}
  26.146 +void 
  26.147 +PointToPointHelper::AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet)
  26.148 +{
  26.149 +  *os << "r " << Simulator::Now ().GetSeconds () << " ";
  26.150 +  *os << path << " " << *packet << std::endl;
  26.151 +}
  26.152 +
  26.153  
  26.154  } // namespace ns3
    27.1 --- a/src/helper/point-to-point-helper.h	Mon Mar 31 13:54:41 2008 -0700
    27.2 +++ b/src/helper/point-to-point-helper.h	Mon Mar 31 13:54:57 2008 -0700
    27.3 @@ -8,6 +8,11 @@
    27.4  
    27.5  namespace ns3 {
    27.6  
    27.7 +class Queue;
    27.8 +class NetDevice;
    27.9 +class Node;
   27.10 +class PcapWriter;
   27.11 +
   27.12  /**
   27.13   * \brief build a set of PointToPointNetDevice objects
   27.14   */
   27.15 @@ -55,6 +60,83 @@
   27.16    void SetChannelParameter (std::string name, Attribute value);
   27.17  
   27.18    /**
   27.19 +   * \param filename filename prefix to use for pcap files.
   27.20 +   * \param nodeid the id of the node to generate pcap output for.
   27.21 +   * \param deviceid the id of the device to generate pcap output for.
   27.22 +   *
   27.23 +   * Generate a pcap file which contains the link-level data observed
   27.24 +   * by the specified deviceid within the specified nodeid. The pcap
   27.25 +   * data is stored in the file prefix-nodeid-deviceid.
   27.26 +   *
   27.27 +   * This method should be invoked after the network topology has 
   27.28 +   * been fully constructed.
   27.29 +   */
   27.30 +  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
   27.31 +  /**
   27.32 +   * \param filename filename prefix to use for pcap files.
   27.33 +   * \param d container of devices of type ns3::PointToPointNetDevice
   27.34 +   *
   27.35 +   * Enable pcap output on each input device which is of the
   27.36 +   * ns3::PointToPointNetDevice type.
   27.37 +   */
   27.38 +  static void EnablePcap (std::string filename, NetDeviceContainer d);
   27.39 +  /**
   27.40 +   * \param filename filename prefix to use for pcap files.
   27.41 +   * \param n container of nodes.
   27.42 +   *
   27.43 +   * Enable pcap output on each device which is of the
   27.44 +   * ns3::PointToPointNetDevice type and which is located in one of the 
   27.45 +   * input nodes.
   27.46 +   */
   27.47 +  static void EnablePcap (std::string filename, NodeContainer n);
   27.48 +  /**
   27.49 +   * \param filename filename prefix to use for pcap files.
   27.50 +   *
   27.51 +   * Enable pcap output on each device which is of the
   27.52 +   * ns3::PointToPointNetDevice type
   27.53 +   */
   27.54 +  static void EnablePcap (std::string filename);
   27.55 +
   27.56 +  /**
   27.57 +   * \param os output stream
   27.58 +   * \param nodeid the id of the node to generate ascii output for.
   27.59 +   * \param deviceid the id of the device to generate ascii output for.
   27.60 +   *
   27.61 +   * Enable ascii output on the specified deviceid within the
   27.62 +   * specified nodeid if it is of type ns3::PointToPointNetDevice and dump 
   27.63 +   * that to the specified stdc++ output stream.
   27.64 +   */
   27.65 +  static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
   27.66 +  /**
   27.67 +   * \param os output stream
   27.68 +   * \param d device container
   27.69 +   *
   27.70 +   * Enable ascii output on each device which is of the
   27.71 +   * ns3::PointToPointNetDevice type and which is located in the input
   27.72 +   * device container and dump that to the specified
   27.73 +   * stdc++ output stream.
   27.74 +   */
   27.75 +  static void EnableAscii (std::ostream &os, NetDeviceContainer d);
   27.76 +  /**
   27.77 +   * \param os output stream
   27.78 +   * \param n node container
   27.79 +   *
   27.80 +   * Enable ascii output on each device which is of the
   27.81 +   * ns3::PointToPointNetDevice type and which is located in one
   27.82 +   * of the input node and dump that to the specified
   27.83 +   * stdc++ output stream.
   27.84 +   */
   27.85 +  static void EnableAscii (std::ostream &os, NodeContainer n);
   27.86 +  /**
   27.87 +   * \param os output stream
   27.88 +   *
   27.89 +   * Enable ascii output on each device which is of the
   27.90 +   * ns3::PointToPointNetDevice type and dump that to the specified
   27.91 +   * stdc++ output stream.
   27.92 +   */
   27.93 +  static void EnableAscii (std::ostream &os);
   27.94 +
   27.95 +  /**
   27.96     * \param c a set of nodes
   27.97     *
   27.98     * This method creates a ns3::PointToPointChannel with the
   27.99 @@ -74,6 +156,14 @@
  27.100    NetDeviceContainer Build (Ptr<Node> a, Ptr<Node> b);
  27.101  
  27.102  private:
  27.103 +  void EnablePcap (Ptr<Node> node, Ptr<NetDevice> device, Ptr<Queue> queue);
  27.104 +  void EnableAscii (Ptr<Node> node, Ptr<NetDevice> device);
  27.105 +  static void RxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
  27.106 +  static void EnqueueEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet);
  27.107 +  static void AsciiEnqueueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  27.108 +  static void AsciiDequeueEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  27.109 +  static void AsciiDropEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  27.110 +  static void AsciiRxEvent (std::ostream *os, std::string path, Ptr<const Packet> packet);
  27.111    ObjectFactory m_queueFactory;
  27.112    ObjectFactory m_channelFactory;
  27.113    ObjectFactory m_deviceFactory;
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/helper/static-multicast-route-helper.cc	Mon Mar 31 13:54:57 2008 -0700
    28.3 @@ -0,0 +1,58 @@
    28.4 +
    28.5 +#include <vector>
    28.6 +#include "ns3/ptr.h"
    28.7 +#include "ns3/assert.h"
    28.8 +#include "ns3/ipv4-address.h"
    28.9 +#include "ns3/ipv4.h"
   28.10 +#include "static-multicast-route-helper.h"
   28.11 +
   28.12 +namespace ns3 {
   28.13 +
   28.14 +StaticMulticastRouteHelper::StaticMulticastRouteHelper ()
   28.15 +{
   28.16 +}
   28.17 +
   28.18 +void  
   28.19 +StaticMulticastRouteHelper::AddMulticastRoute (
   28.20 +  Ptr<Node> n,
   28.21 +  Ipv4Address source, 
   28.22 +  Ipv4Address group,  
   28.23 +  Ptr<NetDevice> input, 
   28.24 +  NetDeviceContainer output)
   28.25 +{
   28.26 +  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
   28.27 +
   28.28 +  // We need to convert the NetDeviceContainer to an array of ifIndex
   28.29 +  std::vector<uint32_t> outputInterfaces;
   28.30 +  for (NetDeviceContainer::Iterator i = output.Begin (); i != output.End (); ++i)
   28.31 +    {
   28.32 +      Ptr<NetDevice> nd = *i;
   28.33 +      uint32_t oifIndex = ipv4->FindInterfaceForDevice (nd);
   28.34 +      outputInterfaces.push_back(oifIndex);
   28.35 +    }
   28.36 +  uint32_t iifIndex = ipv4->FindInterfaceForDevice (input);
   28.37 +  ipv4->AddMulticastRoute (source, group, iifIndex, outputInterfaces);
   28.38 +}
   28.39 +
   28.40 +void
   28.41 +StaticMulticastRouteHelper::SetDefaultMulticastRoute (
   28.42 +  Ptr<Node> n, 
   28.43 +  Ptr<NetDevice> nd)
   28.44 +{
   28.45 +  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
   28.46 +  uint32_t ifIndexSrc = ipv4->FindInterfaceForDevice (nd);
   28.47 +  ipv4->SetDefaultMulticastRoute (ifIndexSrc);
   28.48 +}
   28.49 +
   28.50 +void
   28.51 +StaticMulticastRouteHelper::JoinMulticastGroup (
   28.52 +  Ptr<Node> n, 
   28.53 +  Ipv4Address source, 
   28.54 +  Ipv4Address group)
   28.55 +{
   28.56 +  Ptr<Ipv4> ipv4 = n->GetObject<Ipv4> ();
   28.57 +  ipv4->JoinMulticastGroup (source, group);
   28.58 +}
   28.59 +
   28.60 +} // namespace ns3
   28.61 +
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/src/helper/static-multicast-route-helper.h	Mon Mar 31 13:54:57 2008 -0700
    29.3 @@ -0,0 +1,29 @@
    29.4 +#ifndef STATIC_MULTICAST_ROUTE_HELPER_H
    29.5 +#define STATIC_MULTICAST_ROUTE_HELPER_H
    29.6 +
    29.7 +#include "ns3/ptr.h"
    29.8 +#include "ns3/ipv4-address.h"
    29.9 +#include "ns3/node.h"
   29.10 +#include "ns3/net-device.h"
   29.11 +#include "node-container.h"
   29.12 +#include "net-device-container.h"
   29.13 +
   29.14 +namespace ns3 {
   29.15 +
   29.16 +class StaticMulticastRouteHelper
   29.17 +{
   29.18 +public:
   29.19 +  StaticMulticastRouteHelper ();
   29.20 +
   29.21 +  void AddMulticastRoute (Ptr<Node>, Ipv4Address source, Ipv4Address group,  
   29.22 +    Ptr<NetDevice> input, NetDeviceContainer output);
   29.23 +
   29.24 +  void SetDefaultMulticastRoute (Ptr<Node> n, Ptr<NetDevice> nd);
   29.25 +
   29.26 +  void JoinMulticastGroup (Ptr<Node> n, Ipv4Address source, Ipv4Address group);
   29.27 +
   29.28 +};
   29.29 +
   29.30 +} // namespace ns3
   29.31 +
   29.32 +#endif /* STATIC_MULTICAST_ROUTE_HELPER_H */
    30.1 --- a/src/helper/wifi-helper.cc	Mon Mar 31 13:54:41 2008 -0700
    30.2 +++ b/src/helper/wifi-helper.cc	Mon Mar 31 13:54:57 2008 -0700
    30.3 @@ -8,11 +8,47 @@
    30.4  #include "ns3/propagation-loss-model.h"
    30.5  #include "ns3/mobility-model.h"
    30.6  #include "ns3/log.h"
    30.7 +#include "ns3/pcap-writer.h"
    30.8 +#include "ns3/wifi-mode.h"
    30.9 +#include "ns3/wifi-preamble.h"
   30.10 +#include "ns3/config.h"
   30.11 +
   30.12 +
   30.13  
   30.14  NS_LOG_COMPONENT_DEFINE ("WifiHelper");
   30.15  
   30.16  namespace ns3 {
   30.17  
   30.18 +static void PcapPhyTxEvent (Ptr<PcapWriter> writer, Ptr<const Packet> packet,
   30.19 +			    WifiMode mode, WifiPreamble preamble, 
   30.20 +			    uint8_t txLevel)
   30.21 +{
   30.22 +  writer->WritePacket (packet);
   30.23 +}
   30.24 +
   30.25 +static void PcapPhyRxEvent (Ptr<PcapWriter> writer, 
   30.26 +			    Ptr<const Packet> packet, double snr, WifiMode mode, 
   30.27 +			    enum WifiPreamble preamble)
   30.28 +{
   30.29 +  writer->WritePacket (packet);
   30.30 +}
   30.31 +
   30.32 +static void AsciiPhyTxEvent (std::ostream *os, std::string context, 
   30.33 +			     Ptr<const Packet> packet,
   30.34 +			     WifiMode mode, WifiPreamble preamble, 
   30.35 +			     uint8_t txLevel)
   30.36 +{
   30.37 +  *os << context << " " << *packet << std::endl;
   30.38 +}
   30.39 +
   30.40 +static void AsciiPhyRxOkEvent (std::ostream *os, std::string context, 
   30.41 +			       Ptr<const Packet> packet, double snr, WifiMode mode, 
   30.42 +			       enum WifiPreamble preamble)
   30.43 +{
   30.44 +  *os << context << " " << *packet << std::endl;
   30.45 +}
   30.46 +
   30.47 +
   30.48  WifiHelper::WifiHelper ()
   30.49  {
   30.50    m_stationManager.SetTypeId ("ns3::ArfWifiManager");
   30.51 @@ -89,6 +125,91 @@
   30.52    m_phy.Set (n7, v7);
   30.53  }
   30.54  
   30.55 +void 
   30.56 +WifiHelper::EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid)
   30.57 +{
   30.58 +  std::ostringstream oss;
   30.59 +  oss << filename << "-" << nodeid << "-" << deviceid;
   30.60 +  Ptr<PcapWriter> pcap = Create<PcapWriter> ();
   30.61 +  pcap->Open (oss.str ());
   30.62 +  pcap->WriteWifiHeader ();
   30.63 +  oss.str ("");
   30.64 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx";
   30.65 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyTxEvent, pcap));
   30.66 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk";
   30.67 +  Config::ConnectWithoutContext (oss.str (), MakeBoundCallback (&PcapPhyRxEvent, pcap));
   30.68 +}
   30.69 +void 
   30.70 +WifiHelper::EnablePcap (std::string filename, NetDeviceContainer d)
   30.71 +{
   30.72 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
   30.73 +    {
   30.74 +      Ptr<NetDevice> dev = *i;
   30.75 +      EnablePcap (filename, dev->GetNode ()->GetId (), dev->GetIfIndex ());
   30.76 +    }
   30.77 +}
   30.78 +void
   30.79 +WifiHelper::EnablePcap (std::string filename, NodeContainer n)
   30.80 +{
   30.81 +  NetDeviceContainer devs;
   30.82 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
   30.83 +    {
   30.84 +      Ptr<Node> node = *i;
   30.85 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
   30.86 +	{
   30.87 +	  devs.Add (node->GetDevice (j));
   30.88 +	}
   30.89 +    }
   30.90 +  EnablePcap (filename, devs);
   30.91 +}
   30.92 +
   30.93 +void
   30.94 +WifiHelper::EnablePcap (std::string filename)
   30.95 +{
   30.96 +  EnablePcap (filename, NodeContainer::GetGlobal ());
   30.97 +}
   30.98 +
   30.99 +void 
  30.100 +WifiHelper::EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid)
  30.101 +{
  30.102 +    Packet::EnableMetadata ();
  30.103 +  std::ostringstream oss;
  30.104 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/RxOk";
  30.105 +  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyRxOkEvent, &os));
  30.106 +  oss.str ("");
  30.107 +  oss << "/NodeList/" << nodeid << "/DeviceList/" << deviceid << "/$ns3::WifiNetDevice/Phy/Tx";
  30.108 +  Config::Connect (oss.str (), MakeBoundCallback (&AsciiPhyTxEvent, &os));
  30.109 +}
  30.110 +void 
  30.111 +WifiHelper::EnableAscii (std::ostream &os, NetDeviceContainer d)
  30.112 +{
  30.113 +  for (NetDeviceContainer::Iterator i = d.Begin (); i != d.End (); ++i)
  30.114 +    {
  30.115 +      Ptr<NetDevice> dev = *i;
  30.116 +      EnableAscii (os, dev->GetNode ()->GetId (), dev->GetIfIndex ());
  30.117 +    }
  30.118 +}
  30.119 +void
  30.120 +WifiHelper::EnableAscii (std::ostream &os, NodeContainer n)
  30.121 +{
  30.122 +  NetDeviceContainer devs;
  30.123 +  for (NodeContainer::Iterator i = n.Begin (); i != n.End (); ++i)
  30.124 +    {
  30.125 +      Ptr<Node> node = *i;
  30.126 +      for (uint32_t j = 0; j < node->GetNDevices (); ++j)
  30.127 +	{
  30.128 +	  devs.Add (node->GetDevice (j));
  30.129 +	}
  30.130 +    }
  30.131 +  EnableAscii (os, devs);
  30.132 +}
  30.133 +
  30.134 +void
  30.135 +WifiHelper::EnableAscii (std::ostream &os)
  30.136 +{
  30.137 +  EnableAscii (os, NodeContainer::GetGlobal ());
  30.138 +}
  30.139 +
  30.140  NetDeviceContainer
  30.141  WifiHelper::Build (NodeContainer c) const
  30.142  {
  30.143 @@ -121,4 +242,5 @@
  30.144      }
  30.145    return devices;
  30.146  }
  30.147 +
  30.148  } // namespace ns3
    31.1 --- a/src/helper/wifi-helper.h	Mon Mar 31 13:54:41 2008 -0700
    31.2 +++ b/src/helper/wifi-helper.h	Mon Mar 31 13:54:57 2008 -0700
    31.3 @@ -119,6 +119,85 @@
    31.4  	       std::string n6 = "", Attribute v6 = Attribute (),
    31.5  	       std::string n7 = "", Attribute v7 = Attribute ());
    31.6  
    31.7 +
    31.8 +
    31.9 +  /**
   31.10 +   * \param filename filename prefix to use for pcap files.
   31.11 +   * \param nodeid the id of the node to generate pcap output for.
   31.12 +   * \param deviceid the id of the device to generate pcap output for.
   31.13 +   *
   31.14 +   * Generate a pcap file which contains the link-level data observed
   31.15 +   * by the specified deviceid within the specified nodeid. The pcap
   31.16 +   * data is stored in the file prefix-nodeid-deviceid.
   31.17 +   *
   31.18 +   * This method should be invoked after the network topology has 
   31.19 +   * been fully constructed.
   31.20 +   */
   31.21 +  static void EnablePcap (std::string filename, uint32_t nodeid, uint32_t deviceid);
   31.22 +  /**
   31.23 +   * \param filename filename prefix to use for pcap files.
   31.24 +   * \param d container of devices of type ns3::WifiNetDevice
   31.25 +   *
   31.26 +   * Enable pcap output on each input device which is of the
   31.27 +   * ns3::WifiNetDevice type.
   31.28 +   */
   31.29 +  static void EnablePcap (std::string filename, NetDeviceContainer d);
   31.30 +  /**
   31.31 +   * \param filename filename prefix to use for pcap files.
   31.32 +   * \param n container of nodes.
   31.33 +   *
   31.34 +   * Enable pcap output on each device which is of the
   31.35 +   * ns3::WifiNetDevice type and which is located in one of the 
   31.36 +   * input nodes.
   31.37 +   */
   31.38 +  static void EnablePcap (std::string filename, NodeContainer n);
   31.39 +  /**
   31.40 +   * \param filename filename prefix to use for pcap files.
   31.41 +   *
   31.42 +   * Enable pcap output on each device which is of the
   31.43 +   * ns3::WifiNetDevice type
   31.44 +   */
   31.45 +  static void EnablePcap (std::string filename);
   31.46 +
   31.47 +  /**
   31.48 +   * \param os output stream
   31.49 +   * \param nodeid the id of the node to generate ascii output for.
   31.50 +   * \param deviceid the id of the device to generate ascii output for.
   31.51 +   *
   31.52 +   * Enable ascii output on the specified deviceid within the
   31.53 +   * specified nodeid if it is of type ns3::WifiNetDevice and dump 
   31.54 +   * that to the specified stdc++ output stream.
   31.55 +   */
   31.56 +  static void EnableAscii (std::ostream &os, uint32_t nodeid, uint32_t deviceid);
   31.57 +  /**
   31.58 +   * \param os output stream
   31.59 +   * \param d device container
   31.60 +   *
   31.61 +   * Enable ascii output on each device which is of the
   31.62 +   * ns3::WifiNetDevice type and which is located in the input
   31.63 +   * device container and dump that to the specified
   31.64 +   * stdc++ output stream.
   31.65 +   */
   31.66 +  static void EnableAscii (std::ostream &os, NetDeviceContainer d);
   31.67 +  /**
   31.68 +   * \param os output stream
   31.69 +   * \param n node container
   31.70 +   *
   31.71 +   * Enable ascii output on each device which is of the
   31.72 +   * ns3::WifiNetDevice type and which is located in one
   31.73 +   * of the input node and dump that to the specified
   31.74 +   * stdc++ output stream.
   31.75 +   */
   31.76 +  static void EnableAscii (std::ostream &os, NodeContainer n);
   31.77 +  /**
   31.78 +   * \param os output stream
   31.79 +   *
   31.80 +   * Enable ascii output on each device which is of the
   31.81 +   * ns3::WifiNetDevice type and dump that to the specified
   31.82 +   * stdc++ output stream.
   31.83 +   */
   31.84 +  static void EnableAscii (std::ostream &os);
   31.85 +
   31.86    /**
   31.87     * \param c a set of nodes
   31.88     *
    32.1 --- a/src/helper/wscript	Mon Mar 31 13:54:41 2008 -0700
    32.2 +++ b/src/helper/wscript	Mon Mar 31 13:54:57 2008 -0700
    32.3 @@ -7,6 +7,7 @@
    32.4          'net-device-container.cc',
    32.5          'wifi-helper.cc',
    32.6          'olsr-helper.cc',
    32.7 +        'static-multicast-route-helper.cc',
    32.8          'point-to-point-helper.cc',
    32.9          'csma-helper.cc',
   32.10          'mobility-helper.cc',
   32.11 @@ -28,6 +29,7 @@
   32.12          'net-device-container.h',
   32.13          'wifi-helper.h',
   32.14          'olsr-helper.h',
   32.15 +        'static-multicast-route-helper.h',
   32.16          'point-to-point-helper.h',
   32.17          'csma-helper.h',
   32.18          'mobility-helper.h',
    33.1 --- a/src/internet-node/ipv4-l3-protocol.cc	Mon Mar 31 13:54:41 2008 -0700
    33.2 +++ b/src/internet-node/ipv4-l3-protocol.cc	Mon Mar 31 13:54:57 2008 -0700
    33.3 @@ -456,7 +456,7 @@
    33.4    NS_LOG_FUNCTION;
    33.5    NS_LOG_PARAMS (this << &device << packet << protocol <<  from);
    33.6  
    33.7 -  NS_LOG_LOGIC ("Packet from " << from);
    33.8 +  NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ());
    33.9  
   33.10    uint32_t index = 0;
   33.11    Ptr<Ipv4Interface> ipv4Interface;
   33.12 @@ -485,7 +485,6 @@
   33.13        return;
   33.14      }
   33.15  
   33.16 -  NS_LOG_LOGIC ("Forward up");
   33.17    ForwardUp (packet, ipHeader, ipv4Interface);
   33.18  }
   33.19  
   33.20 @@ -584,6 +583,7 @@
   33.21  {
   33.22    NS_LOG_FUNCTION;
   33.23    NS_LOG_PARAMS (ifIndex << packet << &ipHeader<< device);
   33.24 +  NS_LOG_LOGIC ("Forwarding logic for node: " << m_node->GetId ());
   33.25  
   33.26    for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin ();
   33.27         i != m_interfaces.end (); i++) 
   33.28 @@ -632,26 +632,29 @@
   33.29      }
   33.30    ipHeader.SetTtl (ipHeader.GetTtl () - 1);
   33.31  
   33.32 -  NS_LOG_LOGIC ("Forwarding packet.");
   33.33 -  Lookup (ifIndex, ipHeader, packet,
   33.34 -          MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
   33.35 -//
   33.36 +//  
   33.37  // If this is a to a multicast address and this node is a member of the 
   33.38  // indicated group we need to return false so the multicast is forwarded up.
   33.39 -// Note that we may have just forwarded this packet too.
   33.40 -//
   33.41 +//        
   33.42    for (Ipv4MulticastGroupList::const_iterator i = m_multicastGroups.begin ();
   33.43 -       i != m_multicastGroups.end (); i++) 
   33.44 +       i != m_multicastGroups.end (); i++)
   33.45      {
   33.46        if ((*i).first.IsEqual (ipHeader.GetSource ()) &&
   33.47            (*i).second.IsEqual (ipHeader.GetDestination ()))
   33.48          {
   33.49            NS_LOG_LOGIC ("For me (Joined multicast group)");
   33.50 +          // We forward with a packet copy, since forwarding may change
   33.51 +          // the packet, affecting our local delivery
   33.52 +          NS_LOG_LOGIC ("Forwarding (multicast).");
   33.53 +          Lookup (ifIndex, ipHeader, packet->Copy (),
   33.54 +          MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
   33.55            return false;
   33.56 -        }
   33.57 -    }
   33.58 +        }   
   33.59 +    }     
   33.60 +  NS_LOG_LOGIC ("Not for me, forwarding.");
   33.61 +  Lookup (ifIndex, ipHeader, packet,
   33.62 +  MakeCallback (&Ipv4L3Protocol::SendRealOut, this));
   33.63    
   33.64 -  NS_LOG_LOGIC("Not for me.");
   33.65    return true;
   33.66  }
   33.67  
    34.1 --- a/src/internet-node/tcp-socket.cc	Mon Mar 31 13:54:41 2008 -0700
    34.2 +++ b/src/internet-node/tcp-socket.cc	Mon Mar 31 13:54:57 2008 -0700
    34.3 @@ -733,7 +733,7 @@
    34.4          {
    34.5            NS_LOG_LOGIC ("TCP " << this 
    34.6                << " calling AppCloseRequest");
    34.7 -          NotifyHalfClose ();
    34.8 +          NotifyCloseRequested(); 
    34.9            m_closeRequestNotified = true;
   34.10          }
   34.11        NS_LOG_LOGIC ("TcpSocket " << this 
   34.12 @@ -741,7 +741,7 @@
   34.13        if (m_state == saveState)
   34.14          { // Need to ack, the application will close later
   34.15            SendEmptyPacket (TcpHeader::ACK);
   34.16 -              // Also need to re-tx the ack if we
   34.17 +//               // Also need to re-tx the ack if we
   34.18          }
   34.19        if (m_state == LAST_ACK)
   34.20          {
   34.21 @@ -851,10 +851,11 @@
   34.22            return -1;
   34.23          }
   34.24  
   34.25 -      Time rto = m_rtt->RetransmitTimeout ();
   34.26 +      
   34.27        if (m_retxEvent.IsExpired () ) //go ahead and schedule the retransmit
   34.28          {
   34.29 -          NS_LOG_LOGIC ("Schedule retransmission timeout at time " << 
   34.30 +            Time rto = m_rtt->RetransmitTimeout (); 
   34.31 +            NS_LOG_LOGIC ("Schedule retransmission timeout at time " << 
   34.32                Simulator::Now ().GetSeconds () << " to expire at time " <<
   34.33                (Simulator::Now () + rto).GetSeconds () );
   34.34            m_retxEvent = Simulator::Schedule (rto,&TcpSocket::ReTxTimeout,this);
   34.35 @@ -1042,11 +1043,17 @@
   34.36    // and MUST be called by any subclass, from the NewAck function
   34.37    // Always cancel any pending re-tx timer on new acknowledgement
   34.38    NS_LOG_FUNCTION;
   34.39 -  NS_LOG_PARAMS (this << ack << skipTimer);
   34.40 +  NS_LOG_PARAMS (this << ack << skipTimer); 
   34.41    //DEBUG(1,(cout << "TCP " << this << "Cancelling retx timer " << endl));
   34.42    if (!skipTimer)
   34.43      {
   34.44 -      m_retxEvent.Cancel ();
   34.45 +      m_retxEvent.Cancel ();  
   34.46 +      //On recieving a "New" ack we restart retransmission timer .. RFC 2988
   34.47 +      Time rto = m_rtt->RetransmitTimeout ();
   34.48 +      NS_LOG_LOGIC ("Schedule retransmission timeout at time " 
   34.49 +          << Simulator::Now ().GetSeconds () << " to expire at time " 
   34.50 +          << (Simulator::Now () + rto).GetSeconds ());
   34.51 +    m_retxEvent = Simulator::Schedule (rto, &TcpSocket::ReTxTimeout, this);
   34.52      }
   34.53    NS_LOG_LOGIC ("TCP " << this << " NewAck " << ack 
   34.54             << " numberAck " << (ack - m_highestRxAck)); // Number bytes ack'ed
    35.1 --- a/tutorial/ipv4-address-generator.cc	Mon Mar 31 13:54:41 2008 -0700
    35.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.3 @@ -1,255 +0,0 @@
    35.4 -/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
    35.5 -/*
    35.6 - * Copyright (c) 2007 University of Washington
    35.7 - *
    35.8 - * This program is free software; you can redistribute it and/or modify
    35.9 - * it under the terms of the GNU General Public License version 2 as
   35.10 - * published by the Free Software Foundation;
   35.11 - *
   35.12 - * This program is distributed in the hope that it will be useful,
   35.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   35.15 - * GNU General Public License for more details.
   35.16 - *
   35.17 - * You should have received a copy of the GNU General Public License
   35.18 - * along with this program; if not, write to the Free Software
   35.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   35.20 - */
   35.21 -
   35.22 -#include "ns3/assert.h"
   35.23 -#include "ns3/log.h"
   35.24 -#include "ns3/simulation-singleton.h"
   35.25 -#include "ipv4-address-generator.h"
   35.26 -
   35.27 -NS_LOG_COMPONENT_DEFINE("Ipv4AddressGenerator");
   35.28 -
   35.29 -namespace ns3 {
   35.30 -
   35.31 -class Ipv4NetworkGeneratorImpl
   35.32 -{
   35.33 -public:
   35.34 -  Ipv4NetworkGeneratorImpl ();
   35.35 -  virtual ~Ipv4NetworkGeneratorImpl ();
   35.36 -
   35.37 -  Ipv4Address Allocate (const Ipv4Mask mask);
   35.38 -  void Seed (const Ipv4Mask mask, const Ipv4Address network);
   35.39 -
   35.40 -private:
   35.41 -  static const uint32_t N_BITS = 32;
   35.42 -  class State
   35.43 -  {
   35.44 -  public:
   35.45 -    uint32_t mask;
   35.46 -    uint32_t network;
   35.47 -  };
   35.48 -  State m_state[N_BITS];
   35.49 -};
   35.50 -
   35.51 -Ipv4NetworkGeneratorImpl::Ipv4NetworkGeneratorImpl () 
   35.52 -{
   35.53 -  NS_LOG_FUNCTION;
   35.54 -
   35.55 -  uint32_t mask = 0;
   35.56 -
   35.57 -  for (uint32_t i = 0; i < N_BITS; ++i)
   35.58 -    {
   35.59 -      m_state[i].mask = mask;
   35.60 -      mask >>= 1;
   35.61 -      mask |= 0x80000000;
   35.62 -      m_state[i].network = 0;
   35.63 -      NS_LOG_LOGIC ("m_state[" << i << "]");
   35.64 -      NS_LOG_LOGIC ("mask = " << std::hex << m_state[i].mask);
   35.65 -      NS_LOG_LOGIC ("network = " << std::hex << m_state[i].network);
   35.66 -    }
   35.67 -}
   35.68 -
   35.69 -Ipv4NetworkGeneratorImpl::~Ipv4NetworkGeneratorImpl ()
   35.70 -{
   35.71 -  NS_LOG_FUNCTION;
   35.72 -}
   35.73 -
   35.74 -  void
   35.75 -Ipv4NetworkGeneratorImpl::Seed (
   35.76 -  const Ipv4Mask mask, 
   35.77 -  const Ipv4Address network)
   35.78 -{
   35.79 -  NS_LOG_FUNCTION;
   35.80 -
   35.81 -  uint32_t maskBits = mask.GetHostOrder ();
   35.82 -  uint32_t networkBits = network.GetHostOrder ();
   35.83 -
   35.84 -  for (uint32_t i = 0; i < N_BITS; ++i)
   35.85 -    {
   35.86 -      if (maskBits & 1)
   35.87 -        {
   35.88 -          uint32_t nMaskBits = N_BITS - i;
   35.89 -          NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS);
   35.90 -          m_state[nMaskBits].network = networkBits >> (N_BITS - i);
   35.91 -          return;
   35.92 -        }
   35.93 -      maskBits >>= 1;
   35.94 -    }
   35.95 -  NS_ASSERT_MSG(false, "Impossible");
   35.96 -  return;
   35.97 -}
   35.98 -
   35.99 -  Ipv4Address
  35.100 -Ipv4NetworkGeneratorImpl::Allocate (const Ipv4Mask mask)
  35.101 -{
  35.102 -  NS_LOG_FUNCTION;
  35.103 -
  35.104 -  uint32_t bits = mask.GetHostOrder ();
  35.105 -
  35.106 -  for (uint32_t i = 0; i < N_BITS; ++i)
  35.107 -    {
  35.108 -      if (bits & 1)
  35.109 -        {
  35.110 -          uint32_t nBits = N_BITS - i;
  35.111 -          NS_ASSERT(nBits >= 0 && nBits < N_BITS);
  35.112 -          Ipv4Address addr (m_state[nBits].network << i);
  35.113 -          ++m_state[nBits].network;
  35.114 -          return addr;
  35.115 -        }
  35.116 -      bits >>= 1;
  35.117 -    }
  35.118 -  NS_ASSERT_MSG(false, "Impossible");
  35.119 -  return Ipv4Address (bits);
  35.120 -}
  35.121 -
  35.122 -class Ipv4AddressGeneratorImpl
  35.123 -{
  35.124 -public:
  35.125 -  Ipv4AddressGeneratorImpl ();
  35.126 -  virtual ~Ipv4AddressGeneratorImpl ();
  35.127 -
  35.128 -  Ipv4Address Allocate (const Ipv4Mask mask, const Ipv4Address network);
  35.129 -  void Seed (const Ipv4Mask mask, const Ipv4Address address);
  35.130 -
  35.131 -private:
  35.132 -  static const uint32_t N_BITS = 32;
  35.133 -  class State
  35.134 -  {
  35.135 -  public:
  35.136 -    uint32_t mask;
  35.137 -    uint32_t address;
  35.138 -  };
  35.139 -  State m_state[N_BITS];
  35.140 -};
  35.141 -
  35.142 -Ipv4AddressGeneratorImpl::Ipv4AddressGeneratorImpl () 
  35.143 -{
  35.144 -  NS_LOG_FUNCTION;
  35.145 -
  35.146 -  uint32_t mask = 0;
  35.147 -
  35.148 -  for (uint32_t i = 0; i < N_BITS; ++i)
  35.149 -    {
  35.150 -      m_state[i].mask = mask;
  35.151 -      mask >>= 1;
  35.152 -      mask |= 0x80000000;
  35.153 -      m_state[i].address = 0;
  35.154 -      NS_LOG_LOGIC ("m_state[" << i << "]");
  35.155 -      NS_LOG_LOGIC ("mask = " << std::hex << m_state[i].mask);
  35.156 -      NS_LOG_LOGIC ("address = " << std::hex << m_state[i].address);
  35.157 -    }
  35.158 -}
  35.159 -
  35.160 -Ipv4AddressGeneratorImpl::~Ipv4AddressGeneratorImpl ()
  35.161 -{
  35.162 -  NS_LOG_FUNCTION;
  35.163 -}
  35.164 -
  35.165 -  void
  35.166 -Ipv4AddressGeneratorImpl::Seed (
  35.167 -  const Ipv4Mask mask, 
  35.168 -  const Ipv4Address address)
  35.169 -{
  35.170 -  NS_LOG_FUNCTION;
  35.171 -
  35.172 -  uint32_t maskBits = mask.GetHostOrder ();
  35.173 -  uint32_t addressBits = address.GetHostOrder ();
  35.174 -
  35.175 -  for (uint32_t i = 0; i < N_BITS; ++i)
  35.176 -    {
  35.177 -      if (maskBits & 1)
  35.178 -        {
  35.179 -          uint32_t nMaskBits = N_BITS - i;
  35.180 -          NS_ASSERT(nMaskBits >= 0 && nMaskBits < N_BITS);
  35.181 -          m_state[nMaskBits].address = addressBits;
  35.182 -          return;
  35.183 -        }
  35.184 -      maskBits >>= 1;
  35.185 -    }
  35.186 -  NS_ASSERT_MSG(false, "Impossible");
  35.187 -  return;
  35.188 -}
  35.189 -
  35.190 -  Ipv4Address
  35.191 -Ipv4AddressGeneratorImpl::Allocate (
  35.192 -  const Ipv4Mask mask,
  35.193 -  const Ipv4Address network)
  35.194 -{
  35.195 -  NS_LOG_FUNCTION;
  35.196 -
  35.197 -  uint32_t bits = mask.GetHostOrder ();
  35.198 -  uint32_t net = network.GetHostOrder ();
  35.199 -
  35.200 -  for (uint32_t i = 0; i < N_BITS; ++i)
  35.201 -    {
  35.202 -      if (bits & 1)
  35.203 -        {
  35.204 -          uint32_t nBits = N_BITS - i;
  35.205 -          NS_ASSERT(nBits >= 0 && nBits < N_BITS);
  35.206 -          Ipv4Address addr (net | m_state[nBits].address);
  35.207 -          ++m_state[nBits].address;
  35.208 -          NS_ASSERT_MSG((m_state[nBits].mask & m_state[nBits].address) == 0, 
  35.209 -            "Ipv4AddressGeneratorImpl::Allocate(): Overflow");
  35.210 -          return addr;
  35.211 -        }
  35.212 -      bits >>= 1;
  35.213 -    }
  35.214 -  NS_ASSERT_MSG(false, "Impossible");
  35.215 -  return Ipv4Address (bits);
  35.216 -}
  35.217 -
  35.218 -  void
  35.219 -Ipv4AddressGenerator::SeedAddress (
  35.220 -  const Ipv4Mask mask, 
  35.221 -  const Ipv4Address address)
  35.222 -{
  35.223 -  NS_LOG_FUNCTION;
  35.224 -
  35.225 -  SimulationSingleton<Ipv4AddressGeneratorImpl>::Get ()->Seed (mask, address);
  35.226 -}
  35.227 -
  35.228 -  Ipv4Address
  35.229 -Ipv4AddressGenerator::AllocateAddress (
  35.230 -  const Ipv4Mask mask, 
  35.231 -  const Ipv4Address network)
  35.232 -{
  35.233 -  NS_LOG_FUNCTION;
  35.234 -
  35.235 -  return SimulationSingleton<Ipv4AddressGeneratorImpl>::Get ()->
  35.236 -    Allocate (mask, network);
  35.237 -}
  35.238 -
  35.239 -  void
  35.240 -Ipv4AddressGenerator::SeedNetwork (
  35.241 -  const Ipv4Mask mask,
  35.242 -  const Ipv4Address address)
  35.243 -{
  35.244 -  NS_LOG_FUNCTION;
  35.245 -
  35.246 -  SimulationSingleton<Ipv4NetworkGeneratorImpl>::Get ()->Seed (mask, address);
  35.247 -}
  35.248 -
  35.249 -  Ipv4Address
  35.250 -Ipv4AddressGenerator::AllocateNetwork (const Ipv4Mask mask)
  35.251 -{
  35.252 -  NS_LOG_FUNCTION;
  35.253 -
  35.254 -  return SimulationSingleton<Ipv4NetworkGeneratorImpl>::Get ()->
  35.255 -    Allocate (mask);
  35.256 -}
  35.257 -
  35.258 -}; // namespace ns3
    36.1 --- a/tutorial/ipv4-address-generator.h	Mon Mar 31 13:54:41 2008 -0700
    36.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.3 @@ -1,45 +0,0 @@
    36.4 -/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
    36.5 -/*
    36.6 - * Copyright (c) 2007 University of Washington
    36.7 - *
    36.8 - * This program is free software; you can redistribute it and/or modify
    36.9 - * it under the terms of the GNU General Public License version 2 as
   36.10 - * published by the Free Software Foundation;
   36.11 - *
   36.12 - * This program is distributed in the hope that it will be useful,
   36.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   36.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   36.15 - * GNU General Public License for more details.
   36.16 - *
   36.17 - * You should have received a copy of the GNU General Public License
   36.18 - * along with this program; if not, write to the Free Software
   36.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   36.20 - */
   36.21 -
   36.22 -#ifndef IPV4_ADDRESS_GENERATOR_H
   36.23 -#define IPV4_ADDRESS_GENERATOR_H
   36.24 -
   36.25 -#include <stdint.h>
   36.26 -#include <ostream>
   36.27 -
   36.28 -#include "ns3/ipv4-address.h"
   36.29 -
   36.30 -namespace ns3 {
   36.31 -
   36.32 -class Ipv4AddressGenerator {
   36.33 -public:
   36.34 -  static void SeedAddress (const Ipv4Mask mask, 
   36.35 -    const Ipv4Address address);
   36.36 -
   36.37 -  static Ipv4Address AllocateAddress (const Ipv4Mask mask, 
   36.38 -    const Ipv4Address network);
   36.39 -
   36.40 -  static void SeedNetwork (const Ipv4Mask mask, 
   36.41 -    const Ipv4Address address);
   36.42 -
   36.43 -  static Ipv4Address AllocateNetwork (const Ipv4Mask mask);
   36.44 -};
   36.45 -
   36.46 -}; // namespace ns3
   36.47 -
   36.48 -#endif /* IPV4_ADDRESS_GENERATOR_H */
    37.1 --- a/tutorial/ipv4-bus-network.cc	Mon Mar 31 13:54:41 2008 -0700
    37.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.3 @@ -1,79 +0,0 @@
    37.4 -/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
    37.5 -/*
    37.6 - * Copyright (c) 2007 University of Washington
    37.7 - *
    37.8 - * This program is free software; you can redistribute it and/or modify
    37.9 - * it under the terms of the GNU General Public License version 2 as
   37.10 - * published by the Free Software Foundation;
   37.11 - *
   37.12 - * This program is distributed in the hope that it will be useful,
   37.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   37.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   37.15 - * GNU General Public License for more details.
   37.16 - *
   37.17 - * You should have received a copy of the GNU General Public License
   37.18 - * along with this program; if not, write to the Free Software
   37.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   37.20 - */
   37.21 -
   37.22 -#include "ns3/mac48-address.h"
   37.23 -#include "ns3/csma-net-device.h"
   37.24 -#include "ns3/csma-topology.h"
   37.25 -#include "ns3/csma-ipv4-topology.h"
   37.26 -
   37.27 -#include "ipv4-bus-network.h"
   37.28 -#include "ipv4-address-generator.h"
   37.29 -
   37.30 -namespace ns3 {
   37.31 -
   37.32 -Ipv4Network::Ipv4Network (
   37.33 -  Ipv4Address   network, 
   37.34 -  Ipv4Mask      mask, 
   37.35 -  Ipv4Address   address)
   37.36 -: 
   37.37 -  m_network (network), m_mask (mask), m_baseAddress (address)
   37.38 -{
   37.39 -}
   37.40 -
   37.41 -Ipv4Network::~Ipv4Network ()
   37.42 -{
   37.43 -}
   37.44 -
   37.45 -Ipv4BusNetwork::Ipv4BusNetwork (
   37.46 -  Ipv4Address   network, 
   37.47 -  Ipv4Mask      mask, 
   37.48 -  Ipv4Address   baseAddress, 
   37.49 -  DataRate      bps, 
   37.50 -  Time          delay, 
   37.51 -  uint32_t      n)
   37.52 -: 
   37.53 -  Ipv4Network (network, mask, baseAddress)
   37.54 -{
   37.55 -  Ipv4AddressGenerator::SeedNetwork (mask, network);
   37.56 -  Ipv4AddressGenerator::SeedAddress (mask, baseAddress);
   37.57 -
   37.58 -  m_channel = CsmaTopology::CreateCsmaChannel (bps, delay);
   37.59 -
   37.60 -  for (uint32_t i = 0; i < n; ++i)
   37.61 -    {
   37.62 -      Ptr<Node> node = CreateObject<InternetNode> ();
   37.63 -      uint32_t nd = CsmaIpv4Topology::AddIpv4CsmaNetDevice (node, m_channel, 
   37.64 -        Mac48Address::Allocate ());
   37.65 -      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask, 
   37.66 -        network);
   37.67 -      CsmaIpv4Topology::AddIpv4Address (node, nd, address, mask);
   37.68 -      m_nodes.push_back (node);
   37.69 -    }
   37.70 -}
   37.71 -
   37.72 -Ipv4BusNetwork::~Ipv4BusNetwork ()
   37.73 -{
   37.74 -}
   37.75 -
   37.76 -  Ptr<Node>
   37.77 -Ipv4BusNetwork::GetNode (uint32_t n)
   37.78 -{
   37.79 -  return m_nodes[n];
   37.80 -}
   37.81 -
   37.82 -}; // namespace ns3
    38.1 --- a/tutorial/ipv4-bus-network.h	Mon Mar 31 13:54:41 2008 -0700
    38.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.3 @@ -1,64 +0,0 @@
    38.4 -/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
    38.5 -/*
    38.6 - * Copyright (c) 2007 University of Washington
    38.7 - *
    38.8 - * This program is free software; you can redistribute it and/or modify
    38.9 - * it under the terms of the GNU General Public License version 2 as
   38.10 - * published by the Free Software Foundation;
   38.11 - *
   38.12 - * This program is distributed in the hope that it will be useful,
   38.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   38.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   38.15 - * GNU General Public License for more details.
   38.16 - *
   38.17 - * You should have received a copy of the GNU General Public License
   38.18 - * along with this program; if not, write to the Free Software
   38.19 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   38.20 - */
   38.21 -
   38.22 -#ifndef IPV4_BUS_NETWORK_H
   38.23 -#define IPV4_BUS_NETWORK_H
   38.24 -
   38.25 -#include <list>
   38.26 -#include "ns3/ptr.h"
   38.27 -#include "ns3/node.h"
   38.28 -#include "ns3/ipv4-address.h"
   38.29 -#include "ns3/data-rate.h"
   38.30 -#include "ns3/csma-channel.h"
   38.31 -
   38.32 -namespace ns3 {
   38.33 -
   38.34 -class Ipv4Network
   38.35 -{
   38.36 -public:
   38.37 -  Ipv4Network (Ipv4Address network, Ipv4Mask mask, Ipv4Address address);
   38.38 -  virtual ~Ipv4Network ();
   38.39 -
   38.40 -  Ipv4Address m_network;
   38.41 -  Ipv4Mask m_mask;
   38.42 -  Ipv4Address m_baseAddress;
   38.43 -};
   38.44 -
   38.45 -class Ipv4BusNetwork : public Ipv4Network
   38.46 -{
   38.47 -public:
   38.48 -  Ipv4BusNetwork (
   38.49 -    Ipv4Address   network, 
   38.50 -    Ipv4Mask      mask, 
   38.51 -    Ipv4Address   baseAddress, 
   38.52 -    DataRate      bps, 
   38.53 -    Time          delay, 
   38.54 -    uint32_t      n);
   38.55 -
   38.56 -  virtual ~Ipv4BusNetwork ();
   38.57 -
   38.58 -  Ptr<Node> GetNode (uint32_t n);
   38.59 -
   38.60 -private:
   38.61 -  std::vector<Ptr<Node> > m_nodes;
   38.62 -  Ptr<CsmaChannel> m_channel;
   38.63 -};
   38.64 -
   38.65 -}; // namespace ns3
   38.66 -
   38.67 -#endif /* IPV4_BUS_NETWORK_H */
    39.1 --- a/tutorial/testipv4.cc	Mon Mar 31 13:54:41 2008 -0700
    39.2 +++ b/tutorial/testipv4.cc	Mon Mar 31 13:54:57 2008 -0700
    39.3 @@ -15,7 +15,7 @@
    39.4   */
    39.5  
    39.6  #include "ns3/log.h"
    39.7 -#include "ipv4-address-generator.h"
    39.8 +#include "ns3/ipv4-address-generator.h"
    39.9  
   39.10  NS_LOG_COMPONENT_DEFINE ("TestIpv4");
   39.11  
   39.12 @@ -32,21 +32,19 @@
   39.13  
   39.14    for (uint32_t i = 0; i < 10; ++i)
   39.15      {
   39.16 -      Ipv4Address network = Ipv4AddressGenerator::AllocateNetwork (mask1);
   39.17 -      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask1, 
   39.18 -        network);
   39.19 +      Ipv4Address network = Ipv4AddressGenerator::NextNetwork (mask1);
   39.20 +      Ipv4Address address = Ipv4AddressGenerator::NextAddress (mask1);
   39.21        NS_LOG_INFO ("address = " << address);
   39.22      }
   39.23  
   39.24    Ipv4Mask mask2 ("255.255.0.0");
   39.25 -  Ipv4AddressGenerator::SeedNetwork (mask2, "192.168.0.0");
   39.26 -  Ipv4AddressGenerator::SeedAddress (mask2, "0.0.0.3");
   39.27 +  Ipv4AddressGenerator::Init (Ipv4Address ("192.168.0.0"), mask2);
   39.28 +  Ipv4AddressGenerator::InitAddress (Ipv4Address ("0.0.0.3"), mask2);
   39.29  
   39.30 -  Ipv4Address network1 = Ipv4AddressGenerator::AllocateNetwork (mask2);
   39.31 +  Ipv4Address network1 = Ipv4AddressGenerator::NextNetwork (mask2);
   39.32    for (uint32_t i = 0; i < 10; ++i)
   39.33      {
   39.34 -      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask2, 
   39.35 -        network1);
   39.36 +      Ipv4Address address = Ipv4AddressGenerator::NextAddress (mask2);
   39.37        NS_LOG_INFO ("address = " << address);
   39.38      }
   39.39  
   39.40 @@ -54,9 +52,8 @@
   39.41  
   39.42    for (uint32_t i = 0; i < 10; ++i)
   39.43      {
   39.44 -      Ipv4Address network = Ipv4AddressGenerator::AllocateNetwork (mask3);
   39.45 -      Ipv4Address address = Ipv4AddressGenerator::AllocateAddress (mask3, 
   39.46 -        network);
   39.47 +      Ipv4Address network = Ipv4AddressGenerator::NextNetwork (mask3);
   39.48 +      Ipv4Address address = Ipv4AddressGenerator::NextAddress (mask3);
   39.49        NS_LOG_INFO ("address = " << address);
   39.50      }
   39.51  }
    40.1 --- a/tutorial/tutorial-bus-network.cc	Mon Mar 31 13:54:41 2008 -0700
    40.2 +++ b/tutorial/tutorial-bus-network.cc	Mon Mar 31 13:54:57 2008 -0700
    40.3 @@ -14,17 +14,13 @@
    40.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    40.5   */
    40.6  
    40.7 -#include "ns3/log.h"
    40.8 -#include "ns3/ipv4-address.h"
    40.9 -#include "ns3/udp-echo-client.h"
   40.10 -#include "ns3/udp-echo-server.h"
   40.11 -#include "ns3/simulator.h"
   40.12 -#include "ns3/nstime.h"
   40.13 -#include "ns3/ascii-trace.h"
   40.14 -#include "ns3/inet-socket-address.h"
   40.15 -#include "ns3/uinteger.h"
   40.16 +#include <fstream>
   40.17  
   40.18 -#include "ipv4-bus-network.h"
   40.19 +#include "ns3/core-module.h"
   40.20 +#include "ns3/node-module.h"
   40.21 +#include "ns3/helper-module.h"
   40.22 +#include "ns3/simulator-module.h"
   40.23 +#include "ns3/global-route-manager.h"
   40.24  
   40.25  NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation");
   40.26  
   40.27 @@ -37,34 +33,42 @@
   40.28  
   40.29    NS_LOG_INFO ("Bus Network Simulation");
   40.30  
   40.31 -  Ipv4BusNetwork bus ("10.1.0.0", "255.255.0.0", "0.0.0.3",
   40.32 -    DataRate(10000000), MilliSeconds(20), 10);
   40.33 +  NodeContainer n;
   40.34 +  n.Create (10);
   40.35 +
   40.36 +  InternetStackHelper internet;
   40.37 +  internet.Build (n);
   40.38 +
   40.39 +  CsmaHelper csma;
   40.40 +  csma.SetChannelParameter ("BitRate", DataRate(10000000));
   40.41 +  csma.SetChannelParameter ("Delay", MilliSeconds(20));
   40.42 +  NetDeviceContainer nd = csma.Build (n);
   40.43 +
   40.44 +  Ipv4AddressHelper ipv4;
   40.45 +  ipv4.SetBase ("10.1.0.0", "255.255.0.0", "0.0.0.3");
   40.46 +  Ipv4InterfaceContainer i = ipv4.Allocate (nd);
   40.47  
   40.48    uint32_t port = 7;
   40.49 +  UdpEchoClientHelper client;
   40.50 +  client.SetRemote (i.GetAddress (1), port);
   40.51 +  client.SetAppAttribute ("MaxPackets", Uinteger (1));
   40.52 +  client.SetAppAttribute ("Interval", Seconds (1.0));
   40.53 +  client.SetAppAttribute ("PacketSize", Uinteger (1024));
   40.54 +  ApplicationContainer apps = client.Build (n.Get (0));
   40.55 +  apps.Start (Seconds (2.0));
   40.56 +  apps.Stop (Seconds (10.0));
   40.57  
   40.58 -  Ptr<Node> n0 = bus.GetNode (0);
   40.59 -  Ptr<UdpEchoClient> client =  
   40.60 -    CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.0.1"),
   40.61 -				 "RemotePort", Uinteger (port),
   40.62 -				 "MaxPackets", Uinteger (1), 
   40.63 -				 "Interval", Seconds(1.), 
   40.64 -				 "PacketSize", Uinteger (1024));
   40.65 -  n0->AddApplication (client);
   40.66 +  UdpEchoServerHelper server;
   40.67 +  server.SetPort (port);
   40.68 +  apps = server.Build (n.Get (1));
   40.69 +  apps.Start (Seconds (1.0));
   40.70 +  apps.Stop (Seconds (10.0));
   40.71  
   40.72 -  Ptr<Node> n1 = bus.GetNode (1);
   40.73 -  Ptr<UdpEchoServer> server = 
   40.74 -    CreateObject<UdpEchoServer> ("Port", Uinteger (port));
   40.75 -  n1->AddApplication (server);
   40.76 +  GlobalRouteManager::PopulateRoutingTables ();
   40.77  
   40.78 -  server->Start(Seconds(1.));
   40.79 -  client->Start(Seconds(2.));
   40.80 -
   40.81 -  server->Stop (Seconds(10.));
   40.82 -  client->Stop (Seconds(10.));
   40.83 -
   40.84 -  AsciiTrace asciitrace ("tutorial.tr");
   40.85 -  asciitrace.TraceAllQueues ();
   40.86 -  asciitrace.TraceAllNetDeviceRx ();
   40.87 +  std::ofstream ascii;
   40.88 +  ascii.open ("tutorial.tr");
   40.89 +  CsmaHelper::EnableAscii (ascii);
   40.90  
   40.91    Simulator::Run ();
   40.92    Simulator::Destroy ();
    41.1 --- a/tutorial/tutorial-star-routing.cc	Mon Mar 31 13:54:41 2008 -0700
    41.2 +++ b/tutorial/tutorial-star-routing.cc	Mon Mar 31 13:54:57 2008 -0700
    41.3 @@ -14,23 +14,13 @@
    41.4   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    41.5   */
    41.6  
    41.7 -#include "ns3/log.h"
    41.8 -#include "ns3/ptr.h"
    41.9 -#include "ns3/internet-node.h"
   41.10 -#include "ns3/point-to-point-channel.h"
   41.11 -#include "ns3/mac48-address.h"
   41.12 -#include "ns3/point-to-point-net-device.h"
   41.13 -#include "ns3/udp-echo-client.h"
   41.14 -#include "ns3/udp-echo-server.h"
   41.15 -#include "ns3/simulator.h"
   41.16 -#include "ns3/nstime.h"
   41.17 -#include "ns3/ascii-trace.h"
   41.18 -#include "ns3/pcap-trace.h"
   41.19 +#include <fstream>
   41.20 +
   41.21 +#include "ns3/core-module.h"
   41.22 +#include "ns3/node-module.h"
   41.23 +#include "ns3/helper-module.h"
   41.24 +#include "ns3/simulator-module.h"
   41.25  #include "ns3/global-route-manager.h"
   41.26 -#include "ns3/inet-socket-address.h"
   41.27 -#include "ns3/uinteger.h"
   41.28 -
   41.29 -#include "point-to-point-ipv4-topology.h"
   41.30  
   41.31  NS_LOG_COMPONENT_DEFINE ("StarRoutingSimulation");
   41.32  
   41.33 @@ -53,124 +43,66 @@
   41.34  
   41.35    NS_LOG_INFO ("Star Topology with Routing Simulation");
   41.36  
   41.37 -  Ptr<Node> n0 = CreateObject<InternetNode> ();
   41.38 -  Ptr<Node> n1 = CreateObject<InternetNode> ();
   41.39 -  Ptr<Node> n2 = CreateObject<InternetNode> ();
   41.40 -  Ptr<Node> n3 = CreateObject<InternetNode> ();
   41.41 -  Ptr<Node> n4 = CreateObject<InternetNode> ();
   41.42 -  Ptr<Node> n5 = CreateObject<InternetNode> ();
   41.43 -  Ptr<Node> n6 = CreateObject<InternetNode> ();
   41.44 +  NodeContainer n;
   41.45 +  n.Create (7);
   41.46 +  NodeContainer n01 = NodeContainer (n.Get (0), n.Get (1));
   41.47 +  NodeContainer n02 = NodeContainer (n.Get (0), n.Get (2));
   41.48 +  NodeContainer n03 = NodeContainer (n.Get (0), n.Get (3));
   41.49 +  NodeContainer n04 = NodeContainer (n.Get (0), n.Get (4));
   41.50 +  NodeContainer n05 = NodeContainer (n.Get (0), n.Get (5));
   41.51 +  NodeContainer n06 = NodeContainer (n.Get (0), n.Get (6));
   41.52  
   41.53 -  Ptr<PointToPointChannel> link01 = 
   41.54 -    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
   41.55 -    MilliSeconds (20));
   41.56 +  InternetStackHelper internet;
   41.57 +  internet.Build (n);
   41.58  
   41.59 -  uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0,
   41.60 -    link01);
   41.61 +  PointToPointHelper p2p;
   41.62 +  p2p.SetChannelParameter ("BitRate", DataRate (38400));
   41.63 +  p2p.SetChannelParameter ("Delay", MilliSeconds (20));
   41.64  
   41.65 -  Ptr<PointToPointChannel> link02 = 
   41.66 -    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
   41.67 -    MilliSeconds (20));
   41.68 +  NetDeviceContainer d01 = p2p.Build (n01);
   41.69 +  NetDeviceContainer d02 = p2p.Build (n02);
   41.70 +  NetDeviceContainer d03 = p2p.Build (n03);
   41.71 +  NetDeviceContainer d04 = p2p.Build (n04);
   41.72 +  NetDeviceContainer d05 = p2p.Build (n05);
   41.73 +  NetDeviceContainer d06 = p2p.Build (n06);
   41.74  
   41.75 -  uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0,
   41.76 -    link02);
   41.77 -
   41.78 -  Ptr<PointToPointChannel> link03 = 
   41.79 -    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
   41.80 -    MilliSeconds (20));
   41.81 -
   41.82 -  uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0,
   41.83 -    link03);
   41.84 -
   41.85 -  Ptr<PointToPointChannel> link04 = 
   41.86 -    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
   41.87 -    MilliSeconds (20));
   41.88 -
   41.89 -  uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, 
   41.90 -    link04);
   41.91 -
   41.92 -  Ptr<PointToPointChannel> link05 = 
   41.93 -    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
   41.94 -    MilliSeconds (20));
   41.95 -
   41.96 -  uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0,
   41.97 -    link05);
   41.98 -
   41.99 -  Ptr<PointToPointChannel> link06 = 
  41.100 -    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
  41.101 -    MilliSeconds (20));
  41.102 -
  41.103 -  uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, link06);
  41.104 -
  41.105 -  uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, link01);
  41.106 -  uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, link02);
  41.107 -  uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, link03);
  41.108 -  uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, link04);
  41.109 -  uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, link05);
  41.110 -  uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, link06);
  41.111 -
  41.112 -  PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", 
  41.113 -    "255.255.255.252");
  41.114 -
  41.115 -  PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", 
  41.116 -    "255.255.255.252");
  41.117 -
  41.118 -  PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", 
  41.119 -    "255.255.255.252");
  41.120 -
  41.121 -  PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", 
  41.122 -    "255.255.255.252");
  41.123 -
  41.124 -  PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", 
  41.125 -    "255.255.255.252");
  41.126 -
  41.127 -  PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", 
  41.128 -    "255.255.255.252");
  41.129 -
  41.130 -  PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", 
  41.131 -    "255.255.255.252");
  41.132 -
  41.133 -  PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", 
  41.134 -    "255.255.255.252");
  41.135 -
  41.136 -  PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", 
  41.137 -    "255.255.255.252");
  41.138 -
  41.139 -  PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", 
  41.140 -    "255.255.255.252");
  41.141 -
  41.142 -  PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", 
  41.143 -    "255.255.255.252");
  41.144 -
  41.145 -  PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", 
  41.146 -    "255.255.255.252");
  41.147 +  Ipv4AddressHelper ipv4;
  41.148 +  ipv4.SetBase ("10.1.1.0", "255.255.255.252");
  41.149 +  Ipv4InterfaceContainer i01 = ipv4.Allocate (d01);
  41.150 +  ipv4.SetBase ("10.1.2.0", "255.255.255.252");
  41.151 +  Ipv4InterfaceContainer i02 = ipv4.Allocate (d02);
  41.152 +  ipv4.SetBase ("10.1.3.0", "255.255.255.252");
  41.153 +  Ipv4InterfaceContainer i03 = ipv4.Allocate (d03);
  41.154 +  ipv4.SetBase ("10.1.4.0", "255.255.255.252");
  41.155 +  Ipv4InterfaceContainer i04 = ipv4.Allocate (d04);
  41.156 +  ipv4.SetBase ("10.1.5.0", "255.255.255.252");
  41.157 +  Ipv4InterfaceContainer i05 = ipv4.Allocate (d05);
  41.158 +  ipv4.SetBase ("10.1.6.0", "255.255.255.252");
  41.159 +  Ipv4InterfaceContainer i06 = ipv4.Allocate (d06);
  41.160  
  41.161    uint16_t port = 7;
  41.162  
  41.163 -  Ptr<UdpEchoClient> client = 
  41.164 -    CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.1.2"),
  41.165 -                                     "RemotePort", Uinteger (port), 
  41.166 -                                     "MaxPackets", Uinteger (1), 
  41.167 -                                     "Interval", Seconds(1.), 
  41.168 -                                     "PacketSize", Uinteger (1024));
  41.169 -  n0->AddApplication (client);
  41.170 +  UdpEchoServerHelper server;
  41.171 +  server.SetPort (port);
  41.172 +  ApplicationContainer apps = server.Build (n.Get (1));
  41.173 +  apps.Start (Seconds (1.0));
  41.174 +  apps.Stop (Seconds (10.0));
  41.175  
  41.176 -  Ptr<UdpEchoServer> server = 
  41.177 -    CreateObject<UdpEchoServer> ("Port", Uinteger (port));
  41.178 -  n1->AddApplication (server);
  41.179 -
  41.180 -  server->Start(Seconds(1.));
  41.181 -  client->Start(Seconds(2.));
  41.182 -
  41.183 -  server->Stop (Seconds(10.));
  41.184 -  client->Stop (Seconds(10.));
  41.185 -
  41.186 -  AsciiTrace asciitrace ("tutorial.tr");
  41.187 -  asciitrace.TraceAllQueues ();
  41.188 -  asciitrace.TraceAllNetDeviceRx ();
  41.189 +  UdpEchoClientHelper client;
  41.190 +  client.SetRemote (i01.GetAddress (1), port);
  41.191 +  client.SetAppAttribute ("MaxPackets", Uinteger (1));
  41.192 +  client.SetAppAttribute ("Interval", Seconds (1.0));
  41.193 +  client.SetAppAttribute ("PacketSize", Uinteger (1024));
  41.194 +  apps = client.Build (n.Get (0));
  41.195 +  apps.Start (Seconds (2.0));
  41.196 +  apps.Stop (Seconds (10.0));
  41.197  
  41.198    GlobalRouteManager::PopulateRoutingTables ();
  41.199  
  41.200 +  std::ofstream ascii;
  41.201 +  ascii.open ("tutorial.tr");
  41.202 +  PointToPointHelper::EnableAscii (ascii);
  41.203 +
  41.204    Simulator::Run ();
  41.205    Simulator::Destroy ();
  41.206  }
    42.1 --- a/tutorial/wscript	Mon Mar 31 13:54:41 2008 -0700
    42.2 +++ b/tutorial/wscript	Mon Mar 31 13:54:57 2008 -0700
    42.3 @@ -28,9 +28,7 @@
    42.4      obj.source = 'tutorial-linear-dumbbell.cc'
    42.5  
    42.6      obj = bld.create_ns3_program('testipv4', ['node'])
    42.7 -    obj.source = ['testipv4.cc', 'ipv4-address-generator.cc']
    42.8 +    obj.source = ['testipv4.cc']
    42.9  
   42.10      obj = bld.create_ns3_program('tutorial-bus-network', ['internet-node'])