examples/csma-packet-socket.cc
author Craig Dowell <craigdo@ee.washington.edu>
Thu, 13 Sep 2007 17:47:42 -0700
changeset 1504 36ecc970ba96
parent 1494 c2985e1cd091
child 2230 9f13ac3291e0
permissions -rw-r--r--
checkpoint debug to log
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 *
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * GNU General Public License for more details.
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 *
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 */
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
// Port of ns-2/tcl/ex/simple.tcl to ns-3
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
//
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
// Network topology
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
//
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
//       n0    n1   n2   n3
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
//       |     |    |    |
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
//     =====================
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
//
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    25
// - CBR/UDP flows from n0 to n1, and from n3 to n0
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
// - UDP packet size of 210 bytes, with per-packet interval 0.00375 sec.
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
//   (i.e., DataRate of 448,000 bps)
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
// - DropTail queues 
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
    29
// - Tracing of queues and packet receptions to file "csma-one-subnet.tr"
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
#include <iostream>
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
#include <fstream>
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
#include <string>
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
#include <cassert>
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
#include "ns3/command-line.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
#include "ns3/default-value.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
#include "ns3/ptr.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
#include "ns3/random-variable.h"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    40
#include "ns3/log.h"
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
#include "ns3/simulator.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
#include "ns3/nstime.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
#include "ns3/data-rate.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    45
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    46
#include "ns3/ascii-trace.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    47
#include "ns3/pcap-trace.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    48
#include "ns3/internet-node.h"
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
    49
#include "ns3/csma-channel.h"
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
    50
#include "ns3/csma-net-device.h"
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1272
diff changeset
    51
#include "ns3/mac48-address.h"
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    52
#include "ns3/packet-socket-address.h"
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    53
#include "ns3/socket.h"
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
#include "ns3/onoff-application.h"
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    55
#include "ns3/queue.h"
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    57
using namespace ns3;
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    59
NS_LOG_COMPONENT_DEFINE ("CsmaPacketSocketExample");
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    60
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
    61
static Ptr<CsmaNetDevice>
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
    62
CreateCsmaDevice (Ptr<Node> node, Ptr<CsmaChannel> channel)
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    63
{
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
    64
  Ptr<CsmaNetDevice> device = Create<CsmaNetDevice> (node);
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    65
  device->Attach (channel);
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    66
  Ptr<Queue> queue = Queue::CreateDefault ();
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    67
  device->AddQueue (queue);
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    68
  return device;
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    69
}
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
    70
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    71
int
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    72
main (int argc, char *argv[])
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    73
{
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    74
#if 0 
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    75
  LogComponentEnable ("CsmaPacketSocketExample", LOG_LEVEL_INFO);
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    76
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    77
  LogComponentEnable("Object", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    78
  LogComponentEnable("Queue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    79
  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    80
  LogComponentEnable("Channel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    81
  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    82
  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    83
  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    84
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    85
  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    86
  LogComponentEnable("Socket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    87
  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    88
  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    89
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    90
  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    91
  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    92
  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    93
  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    94
  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    95
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    96
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    97
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    98
#endif
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
    99
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
  CommandLine::Parse (argc, argv);
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
  // Here, we will explicitly create four nodes.  In more sophisticated
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
  // topologies, we could configure a node factory.
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   104
  NS_LOG_INFO ("Create nodes.");
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   105
  Ptr<Node> n0 = Create<Node> ();
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   106
  Ptr<Node> n1 = Create<Node> (); 
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   107
  Ptr<Node> n2 = Create<Node> (); 
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   108
  Ptr<Node> n3 = Create<Node> ();
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   110
  // create the shared medium used by all csma devices.
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   111
  NS_LOG_INFO ("Create channels.");
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   112
  Ptr<CsmaChannel> channel = Create<CsmaChannel> (DataRate(5000000), MilliSeconds(2));
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   113
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   114
  // use a helper function to connect our nodes to the shared channel.
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   115
  NS_LOG_INFO ("Build Topology.");
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   116
  Ptr<NetDevice> n0If = CreateCsmaDevice (n0, channel);
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   117
  Ptr<NetDevice> n1If = CreateCsmaDevice (n1, channel);
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   118
  Ptr<NetDevice> n2If = CreateCsmaDevice (n2, channel);
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   119
  Ptr<NetDevice> n3If = CreateCsmaDevice (n3, channel);
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   120
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   121
  // create the address which identifies n1 from n0
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   122
  PacketSocketAddress n0ToN1;
1195
53f1175dbe94 fix tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1193
diff changeset
   123
  n0ToN1.SetSingleDevice (n0If->GetIfIndex ());      // set outgoing interface for outgoing packets
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   124
  n0ToN1.SetPhysicalAddress (n1If->GetAddress ()); // set destination address for outgoing packets
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   125
  n0ToN1.SetProtocol (2);            // set arbitrary protocol for outgoing packets
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   126
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   127
  // create the address which identifies n0 from n3
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   128
  PacketSocketAddress n3ToN0;
1195
53f1175dbe94 fix tracing
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1193
diff changeset
   129
  n3ToN0.SetSingleDevice (n3If->GetIfIndex ());
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   130
  n3ToN0.SetPhysicalAddress (n0If->GetAddress ());
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   131
  n3ToN0.SetProtocol (3);
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   132
  
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   133
  // Create the OnOff application to send raw datagrams of size
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   134
  // 210 bytes at a rate of 448 Kb/s
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   135
  // from n0 to n1
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   136
  NS_LOG_INFO ("Create Applications.");
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   137
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   138
    n0, 
1208
ad83a13631c1 merge implicit conversion tree
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1204 1195
diff changeset
   139
    n0ToN1,
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   140
    "Packet",
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   141
    ConstantVariable(1), 
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   142
    ConstantVariable(0));
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   143
  // Start the application
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   144
  ooff->Start(Seconds(1.0));
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   145
  ooff->Stop (Seconds(10.0));
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   146
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   147
  // Create a similar flow from n3 to n0, starting at time 1.1 seconds
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   148
  ooff = Create<OnOffApplication> (
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   149
    n3, 
1208
ad83a13631c1 merge implicit conversion tree
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1204 1195
diff changeset
   150
    n3ToN0,
1193
ea2185e4e097 example code.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1190
diff changeset
   151
    "Packet",
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   152
    ConstantVariable(1), 
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   153
    ConstantVariable(0));
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   154
  // Start the application
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   155
  ooff->Start(Seconds(1.1));
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   156
  ooff->Stop (Seconds(10.0));
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   157
 
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   158
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   159
  // Trace output will be sent to the csma-packet-socket.tr file
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   160
  NS_LOG_INFO ("Configure Tracing.");
1272
67a2ba1143e0 rename to csma
Craig Dowell <craigdo@ee.washington.edu>
parents: 1208
diff changeset
   161
  AsciiTrace asciitrace ("csma-packet-socket.tr");
991
e05514a93564 fix tracing
Tom Henderson <tomh@tomh.org>
parents: 990
diff changeset
   162
  asciitrace.TraceAllNetDeviceRx ();
e05514a93564 fix tracing
Tom Henderson <tomh@tomh.org>
parents: 990
diff changeset
   163
  asciitrace.TraceAllQueues ();
e05514a93564 fix tracing
Tom Henderson <tomh@tomh.org>
parents: 990
diff changeset
   164
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   165
  NS_LOG_INFO ("Run Simulation.");
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   166
  Simulator::Run ();
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   167
  Simulator::Destroy ();
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1494
diff changeset
   168
  NS_LOG_INFO ("Done.");
987
3f469377ff30 new script for csma-cd
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   169
}