examples/csma/csma-multicast.cc
author Tom Henderson <tomh@tomh.org>
Fri, 20 Aug 2010 12:17:19 -0700
changeset 6589 9c325569fb01
parent 6014 d251d4a44fde
permissions -rw-r--r--
Help waf to guess release versions of nsc and pybindgen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
// Network topology
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
//
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    19
//                     Lan1
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    20
//                 ===========
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    21
//                 |    |    | 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    22
//       n0   n1   n2   n3   n4
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    23
//       |    |    |
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    24
//       ===========
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    25
//           Lan0
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
//
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    27
// - Multicast source is at node n0;
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    28
// - Multicast forwarded by node n2 onto LAN1;
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    29
// - Nodes n0, n1, n2, n3, and n4 receive the multicast frame.
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    30
// - Node n4 listens for the data 
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
2800
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
    32
#include <iostream>
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
    33
#include <fstream>
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
    34
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    35
#include "ns3/core-module.h"
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
    36
#include "ns3/simulator-module.h"
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
    37
#include "ns3/node-module.h"
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    38
#include "ns3/helper-module.h"
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
using namespace ns3;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    42
NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    43
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
int 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
main (int argc, char *argv[])
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
{
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    47
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    48
  // Users may find it convenient to turn on explicit debugging
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    49
  // for selected modules; the below lines suggest how to do this
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    50
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    51
  // LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    52
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    53
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    54
  // Set up default values for the simulation.  
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    55
  //
3630
0aa446f659d9 MTU, encap mode cleanup for csma
craigdo@ee.washington.edu
parents: 3381
diff changeset
    56
  // Select DIX/Ethernet II-style encapsulation (no LLC/Snap header)
0aa446f659d9 MTU, encap mode cleanup for csma
craigdo@ee.washington.edu
parents: 3381
diff changeset
    57
  Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("Dix"));  
2533
80cdc3eec057 do not use Queue::CreateDefault
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    58
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    59
  // Allow the user to override any of the defaults at
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    60
  // run-time, via command-line arguments
2575
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2533
diff changeset
    61
  CommandLine cmd;
1aae382e65e2 rewrite CommandLine to not handle DefaultValues anymore.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2533
diff changeset
    62
  cmd.Parse (argc, argv);
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
    63
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    64
  NS_LOG_INFO ("Create nodes.");
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    65
  NodeContainer c;
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    66
  c.Create (5);
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    67
  // We will later want two subcontainers of these nodes, for the two LANs
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    68
  NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    69
  NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    70
  
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    71
  NS_LOG_INFO ("Build Topology.");
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    72
  CsmaHelper csma;
3381
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
    73
  csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
3cdd9d60f7c7 bug 232, references to Parameter obsolete
Craig Dowell <craigdo@ee.washington.edu>
parents: 3257
diff changeset
    74
  csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    75
 
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    76
  // We will use these NetDevice containers later, for IP addressing
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    77
  NetDeviceContainer nd0 = csma.Install (c0);  // First LAN
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
    78
  NetDeviceContainer nd1 = csma.Install (c1);  // Second LAN
1440
c77745b2731c add ipv4 methods, remove source multicast route requirement, fix udp socket source address prob
Craig Dowell <craigdo@ee.washington.edu>
parents: 1437
diff changeset
    79
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    80
  NS_LOG_INFO ("Add IP Stack.");
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    81
  InternetStackHelper internet;
2902
9c2cfada5e72 make duplicate aggregations fail; avoid duplicate aggregations
Craig Dowell <craigdo@ee.washington.edu>
parents: 2890
diff changeset
    82
  internet.Install (c);
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    83
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    84
  NS_LOG_INFO ("Assign IP Addresses.");
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    85
  Ipv4AddressHelper ipv4Addr;
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    86
  ipv4Addr.SetBase ("10.1.1.0", "255.255.255.0");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    87
  ipv4Addr.Assign (nd0);
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    88
  ipv4Addr.SetBase ("10.1.2.0", "255.255.255.0");
2888
872dc8466352 Ipv4AddressHelper::Allocate -> Ipv4AddressHelper::Assign
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2887
diff changeset
    89
  ipv4Addr.Assign (nd1);
1436
9f9fe7919c89 Silliness for optimized version
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
    90
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    91
  NS_LOG_INFO ("Configure multicasting.");
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    92
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    93
  // Now we can configure multicasting.  As described above, the multicast 
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    94
  // source is at node zero, which we assigned the IP address of 10.1.1.1 
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    95
  // earlier.  We need to define a multicast group to send packets to.  This
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    96
  // can be any multicast address from 224.0.0.0 through 239.255.255.255
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    97
  // (avoiding the reserved routing protocol addresses).  
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    98
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
    99
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  Ipv4Address multicastSource ("10.1.1.1");
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1440
diff changeset
   101
  Ipv4Address multicastGroup ("225.1.2.4");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   103
  // Now, we will set up multicast routing.  We need to do three things:
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   104
  // 1) Configure a (static) multicast route on node n2
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   105
  // 2) Set up a default multicast route on the sender n0 
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   106
  // 3) Have node n4 join the multicast group
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   107
  // We have a helper that can help us with static multicast
4473
39ac17168023 examples/ changes for IPv4 routing rework
Tom Henderson <tomh@tomh.org>
parents: 4435
diff changeset
   108
  Ipv4StaticRoutingHelper multicast;
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   109
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   110
  // 1) Configure a (static) multicast route on node n2 (multicastRouter)
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   111
  Ptr<Node> multicastRouter = c.Get (2);  // The node in question
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   112
  Ptr<NetDevice> inputIf = nd0.Get (2);  // The input NetDevice
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   113
  NetDeviceContainer outputDevices;  // A container of output NetDevices
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   114
  outputDevices.Add (nd1.Get (0));  // (we only need one NetDevice here)
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   116
  multicast.AddMulticastRoute (multicastRouter, multicastSource, 
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   117
    multicastGroup, inputIf, outputDevices);
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   118
  
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   119
  // 2) Set up a default multicast route on the sender n0 
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   120
  Ptr<Node> sender = c.Get (0);
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   121
  Ptr<NetDevice> senderIf = nd0.Get(0);
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   122
  multicast.SetDefaultMulticastRoute (sender, senderIf);
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   123
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   124
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   125
  // Create an OnOff application to send UDP datagrams from node zero to the
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   126
  // multicast group (node four will be listening).
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   127
  //
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   128
  NS_LOG_INFO ("Create Applications.");
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   129
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   130
  uint16_t multicastPort = 9;   // Discard port (RFC 863)
1514
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   131
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   132
  // Configure a multicast packet generator that generates a packet
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   133
  // every few seconds
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 2997
diff changeset
   134
  OnOffHelper onoff ("ns3::UdpSocketFactory", 
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   135
    Address (InetSocketAddress (multicastGroup, multicastPort)));
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2890
diff changeset
   136
  onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2890
diff changeset
   137
  onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2890
diff changeset
   138
  onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/s")));
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2890
diff changeset
   139
  onoff.SetAttribute ("PacketSize", UintegerValue (128));
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   140
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   141
  ApplicationContainer srcC = onoff.Install (c0.Get (0));
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   142
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   143
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   144
  // Tell the application when to start and stop.
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   145
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   146
  srcC.Start(Seconds(1.));
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   147
  srcC.Stop (Seconds(10.));
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   148
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   149
  // Create an optional packet sink to receive these packets
3125
d2d8a36cfd23 s/ns3::Udp/ns3::UdpSocketFactory
Tom Henderson <tomh@tomh.org>
parents: 2997
diff changeset
   150
  PacketSinkHelper sink ("ns3::UdpSocketFactory",
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2890
diff changeset
   151
                         InetSocketAddress (Ipv4Address::GetAny(), multicastPort));
2890
172baa5960ff rework app constructors
Craig Dowell <craigdo@ee.washington.edu>
parents: 2889
diff changeset
   152
2887
9a637e6daee0 Build -> Install
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2860
diff changeset
   153
  ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   154
  // Start the sink
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   155
  sinkC.Start (Seconds (1.0));
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   156
  sinkC.Stop (Seconds (10.0));
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   157
2800
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
   158
  NS_LOG_INFO ("Configure Tracing.");
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
   159
  //
6014
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   160
  // Configure tracing of all enqueue, dequeue, and NetDevice receive events.
2800
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
   161
  // Ascii trace output will be sent to the file "csma-multicast.tr"
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   162
  //
6014
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   163
  AsciiTraceHelper ascii;
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   164
  csma.EnableAsciiAll (ascii.CreateFileStream ("csma-multicast.tr"));
2800
b3e87b8fa9d2 move csma-multicast to new tracing helpers
Tom Henderson <tomh@tomh.org>
parents: 2798
diff changeset
   165
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   166
  // Also configure some tcpdump traces; each interface will be traced.
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   167
  // The output files will be named:
4264
9d2e96c4e6e4 Piles of changes for tracing rework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4225
diff changeset
   168
  //     csma-multicast-<nodeId>-<interfaceId>.pcap
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   169
  // and can be read by the "tcpdump -r" command (use "-tt" option to
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   170
  // display timestamps correctly)
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents: 5369
diff changeset
   171
  csma.EnablePcapAll ("csma-multicast", false);
6014
d251d4a44fde checkpoint
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   172
2798
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   173
  //
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   174
  // Now, do the actual simulation.
143e2e1c5167 csma-multicast helper-ized (w/o tracing cutover yet)
Tom Henderson <tomh@tomh.org>
parents: 2602
diff changeset
   175
  //
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   176
  NS_LOG_INFO ("Run Simulation.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
  Simulator::Run ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
  Simulator::Destroy ();
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   179
  NS_LOG_INFO ("Done.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
}