examples/csma-multicast.cc
author Craig Dowell <craigdo@ee.washington.edu>
Wed, 12 Sep 2007 16:54:21 -0700
changeset 1499 93d51d757afa
parent 1455 d1dc9446655d
child 1501 665e07dbd919
permissions -rw-r--r--
working one way echo app
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.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    30
// - Node n4 listens for the data (actual listener not yet implementted)
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
#include "ns3/command-line.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
#include "ns3/default-value.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
#include "ns3/ptr.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
#include "ns3/random-variable.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
#include "ns3/debug.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
#include "ns3/simulator.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
#include "ns3/nstime.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
#include "ns3/data-rate.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
#include "ns3/ascii-trace.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
#include "ns3/pcap-trace.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
#include "ns3/internet-node.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
#include "ns3/csma-channel.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
#include "ns3/csma-net-device.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
#include "ns3/csma-topology.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
#include "ns3/csma-ipv4-topology.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
#include "ns3/eui48-address.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
#include "ns3/ipv4-address.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
#include "ns3/inet-socket-address.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
#include "ns3/ipv4.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
#include "ns3/socket.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
#include "ns3/ipv4-route.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
#include "ns3/onoff-application.h"
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
using namespace ns3;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    57
NS_DEBUG_COMPONENT_DEFINE ("CsmaMulticast");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    58
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
int 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
main (int argc, char *argv[])
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
{
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    62
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    63
// Users may find it convenient to turn on explicit debugging
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    64
// for selected modules; the below lines suggest how to do this
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    65
//
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
    66
#if 0
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    67
  DebugComponentEnable("CsmaMulticast");
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    68
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    69
  DebugComponentEnable("Object");
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    70
  DebugComponentEnable("Queue");
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    71
  DebugComponentEnable("DropTailQueue");
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    72
  DebugComponentEnable("Channel");
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    73
  DebugComponentEnable("CsmaChannel");
1435
a70de165a25a set source IP address in udp-socket packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 1434
diff changeset
    74
  DebugComponentEnable("NetDevice");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
  DebugComponentEnable("CsmaNetDevice");
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
  DebugComponentEnable("Ipv4L3Protocol");
1435
a70de165a25a set source IP address in udp-socket packets
Craig Dowell <craigdo@ee.washington.edu>
parents: 1434
diff changeset
    77
  DebugComponentEnable("OnOffApplication");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
  DebugComponentEnable("PacketSocket");
1499
93d51d757afa working one way echo app
Craig Dowell <craigdo@ee.washington.edu>
parents: 1455
diff changeset
    79
  DebugComponentEnable("Socket");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    80
  DebugComponentEnable("UdpSocket");
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    81
  DebugComponentEnable("UdpL4Protocol");
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    82
  DebugComponentEnable("Ipv4L3Protocol");
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    83
  DebugComponentEnable("Ipv4StaticRouting");
1430
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    84
  DebugComponentEnable("Ipv4Interface");
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    85
  DebugComponentEnable("ArpIpv4Interface");
25fa26a6533e many debug prints
Craig Dowell <craigdo@ee.washington.edu>
parents: 1429
diff changeset
    86
  DebugComponentEnable("Ipv4LoopbackInterface");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
#endif
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
    88
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    89
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    90
// Set up default values for the simulation.  Use the DefaultValue::Bind()
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    91
// technique to tell the system what subclass of Queue to use.  The Bind
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    92
// command command tells the queue factory which class to instantiate when the
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    93
// queue factory is invoked in the topology code
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    94
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
  DefaultValue::Bind ("Queue", "DropTailQueue");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    96
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    97
// Allow the user to override any of the defaults and the above Bind() at
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    98
// run-time, via command-line arguments
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    99
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
  CommandLine::Parse (argc, argv);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   101
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   102
// Explicitly create the nodes required by the topology (shown above).
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   103
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   104
  NS_DEBUG("Create nodes.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
  Ptr<Node> n0 = Create<InternetNode> ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
  Ptr<Node> n1 = Create<InternetNode> (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
  Ptr<Node> n2 = Create<InternetNode> (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
  Ptr<Node> n3 = Create<InternetNode> ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   109
  Ptr<Node> n4 = Create<InternetNode> ();
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   111
  NS_DEBUG("Create channels.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   112
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   113
// Explicitly create the channels required by the topology (shown above).
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   114
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   115
  Ptr<CsmaChannel> lan0 = 
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1433
diff changeset
   116
    CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   117
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   118
  Ptr<CsmaChannel> lan1 = 
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1433
diff changeset
   119
    CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   121
  NS_DEBUG("Build Topology.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   122
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   123
// Now fill out the topology by creating the net devices required to connect
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   124
// the nodes to the channels and hooking them up.  AddIpv4CsmaNetDevice will
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   125
// create a net device, add a MAC address (in memory of the pink flamingo) and
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   126
// connect the net device to a nodes and also to a channel. the 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   127
// AddIpv4CsmaNetDevice method returns a net device index for the net device
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   128
// created on the node.  Interpret nd0 as the net device we created for node
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   129
// zero.  Interpret nd2Lan0 as the net device we created for node two to
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   130
// connect to Lan0. 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   131
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   132
  uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan0, 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   133
    Eui48Address("08:00:2e:00:00:00"));
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   134
  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan0, 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   135
    Eui48Address("08:00:2e:00:00:01"));
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   136
  uint32_t nd2Lan0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan0, 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   137
    Eui48Address("08:00:2e:00:00:02"));
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   138
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   139
  uint32_t nd2Lan1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1, 
1437
1d32949ae397 fix non-unique ethernet addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1436
diff changeset
   140
    Eui48Address("08:00:2e:00:00:03"));
1455
d1dc9446655d variable unused in optimized build -- fixed via attribute
Craig Dowell <craigdo@ee.washington.edu>
parents: 1452
diff changeset
   141
  uint32_t nd3 __attribute__ ((unused)) = 
d1dc9446655d variable unused in optimized build -- fixed via attribute
Craig Dowell <craigdo@ee.washington.edu>
parents: 1452
diff changeset
   142
    CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1, 
1437
1d32949ae397 fix non-unique ethernet addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1436
diff changeset
   143
    Eui48Address("08:00:2e:00:00:04"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   144
  uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan1, 
1437
1d32949ae397 fix non-unique ethernet addresses
Craig Dowell <craigdo@ee.washington.edu>
parents: 1436
diff changeset
   145
    Eui48Address("08:00:2e:00:00:05"));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   147
  NS_DEBUG ("nd0 = " << nd0);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   148
  NS_DEBUG ("nd1 = " << nd1);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   149
  NS_DEBUG ("nd2Lan0 = " << nd2Lan0);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   150
  NS_DEBUG ("nd2Lan1 = " << nd2Lan1);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   151
  NS_DEBUG ("nd3 = " << nd3);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   152
  NS_DEBUG ("nd4 = " << nd3);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   153
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   154
// We've got the "hardware" in place.  Now we need to add IP addresses.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   155
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   156
  NS_DEBUG("Assign IP Addresses.");
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
   157
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
   158
  CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address ("10.1.1.1"), 
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
   159
    Ipv4Mask ("255.255.255.0"));
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
   160
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
   161
  CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address ("10.1.1.2"), 
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
   162
    Ipv4Mask ("255.255.255.0"));
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
   163
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   164
//
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
   165
// We'll need these addresses later
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   166
//
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
   167
  Ipv4Address n2Lan0Addr ("10.1.1.3");
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
   168
  Ipv4Address n2Lan1Addr ("10.1.2.1");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   169
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
   170
  CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan0, n2Lan0Addr, 
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
   171
    Ipv4Mask ("255.255.255.0"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   172
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   173
// Assign IP addresses to the net devices and associated interfaces on Lan1
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   174
//
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
   175
  CsmaIpv4Topology::AddIpv4Address (n2, nd2Lan1, n2Lan1Addr, 
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
   176
    Ipv4Mask ("255.255.255.0"));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
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
   178
  CsmaIpv4Topology::AddIpv4Address (n3, nd1, Ipv4Address ("10.1.2.2"), 
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
   179
    Ipv4Mask ("255.255.255.0"));
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
   180
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
   181
  CsmaIpv4Topology::AddIpv4Address (n4, nd4, Ipv4Address ("10.1.2.3"), 
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
   182
    Ipv4Mask ("255.255.255.0"));
1436
9f9fe7919c89 Silliness for optimized version
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   183
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   184
  NS_DEBUG("Configure multicasting.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   185
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   186
// Now we can configure multicasting.  As described above, the multicast 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   187
// source is at node zero, which we assigned the IP address of 10.1.1.1 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   188
// earlier.  We need to define a multicast group to send packets to.  This
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   189
// can be any multicast address from 224.0.0.0 through 239.255.255.255
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   190
// (avoiding the reserved routing protocol addresses).  We just pick a
1442
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1440
diff changeset
   191
// convenient number (225.0.0.0) and or in some bits to let us verify that
bb5cf98c0c64 real multicast enet addr, more source routes, default multicast route
Craig Dowell <craigdo@ee.washington.edu>
parents: 1440
diff changeset
   192
// correct Ethernet multicast addresses are constructed down in the system. 
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   193
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
  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
   195
  Ipv4Address multicastGroup ("225.1.2.4");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   196
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   197
// We are going to manually configure multicast routing.  This means telling
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   198
// node two that it should expect multicast data coming from IP address 
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
   199
// 10.1.1.1 originally.  It should expect these data coming in over its IP 
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
   200
// interface connected to Lan0.  When node two receives these packets, they
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
   201
// should be forwarded out the interface that connects it to Lan1.
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
   202
//
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
   203
// We're going to need the interface indices on node two corresponding to 
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
   204
// these interfaces, which we call ifIndexLan0 and ifIndexLan1.  The most
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
   205
// general way to get these interfaces is to look them up by IP address.
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
   206
// Looking back to the topology creation calls above, we saved the addresses
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
   207
// assigned to the interface connecting node two to Lan0 and Lan1.  Now is
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
   208
// a fine time to find the interface indices on node two.
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   209
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
  Ptr<Ipv4> ipv4;
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   211
  ipv4 = n2->QueryInterface<Ipv4> (Ipv4::iid);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   213
  uint32_t ifIndexLan0 = ipv4->FindInterfaceForAddr (n2Lan0Addr);
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   214
  uint32_t ifIndexLan1 = ipv4->FindInterfaceForAddr (n2Lan1Addr);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   215
//
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
   216
// Now, we need to do is to call the AddMulticastRoute () method on node 
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
   217
// two's Ipv4 interface and tell it that whenever it receives a packet on
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
   218
// the interface from Lan0, with the packet from the multicast source, 
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
   219
// destined for the multicast group, it should forward these packets down
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
   220
// the interface connecting it to Lan1.  (Note: the vector of output
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
   221
// interfaces is in case there are multiple net devices on a node -- not
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
   222
// true in this case).
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   223
//
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
   224
  std::vector<uint32_t> outputInterfaces (1);
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
   225
  outputInterfaces[0] = ifIndexLan1;
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
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
   227
  ipv4->AddMulticastRoute (multicastSource, multicastGroup, ifIndexLan0,
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   228
    outputInterfaces);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   229
//
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   230
// We need to specify how the source node handles multicasting.  There are a
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   231
// number of ways we can deal with this, we just need to pick one.  The first
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   232
// method is to add an explicit route out of the source node, just as we did
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   233
// for the forwarding node.  Use this method when you want to send packets out
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   234
// multiple interfaces or send packets out different interfaces based on the
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   235
// differing multicast groups.  Since the source is local, there will be no 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   236
// input interface over which packets are received, so use  
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   237
// Ipv4RoutingProtocol::IF_INDEX_ANY as a wildcard.
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   238
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   239
// A second way is to specify a multicast route using wildcards.  If you 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   240
// want to send multicasts out differing sets of interfaces based on the 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   241
// multicast group, you can use AddMulticastRoute () but specify the origin 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   242
// as a wildcard.  If you want all multicasts to go out a single set of 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   243
// interfaces, you can make both the origin and group a wildcard.
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   244
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   245
// If you have a simple system, where the source has a single interface, this
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   246
// can be done via the SetDefaultMulticastRoute () method on the Ipv4 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   247
// interface.  This tells the system to send all multicasts out a single
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   248
// specified network interface index.
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   249
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   250
// A last way is to specify a (or use an existing) default unicast route.  The
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   251
// multicast routing code uses the unicast default route as a multicast "route
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   252
// of last resort."  this method for is also on Ipv4 and is called 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   253
// SetDefaultRoute ().
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   254
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   255
// Since this is a simple multicast example, we use the 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   256
// SetDefaultMulticastRoute () approach.  We are going to first need the 
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   257
// Ipv4 interface for node 0 which is the multicast source.  We use this
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   258
// interface to find the output interface index, and tell node zero to send
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   259
// its multicast traffic out that interface.
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   260
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   261
  ipv4 = n0->QueryInterface<Ipv4> (Ipv4::iid);
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   262
  uint32_t ifIndexSrc = ipv4->FindInterfaceForAddr (multicastSource);
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   263
  ipv4->SetDefaultMulticastRoute (ifIndexSrc);
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   264
//
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   265
// As described above, node four will be the only node listening for the
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   266
// multicast data.  To enable forwarding bits up the protocol stack, we need
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   267
// to tell the stack to join the multicast group.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   268
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   269
  ipv4 = n4->QueryInterface<Ipv4> (Ipv4::iid);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   270
  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   271
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   272
// Create an OnOff application to send UDP datagrams from node zero to the
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   273
// multicast group (node four will be listening).
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   274
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   275
  NS_DEBUG("Create Applications.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
    n0, 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   278
    InetSocketAddress (multicastGroup, 80), 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
    "Udp",
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
    ConstantVariable(1), 
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   281
    ConstantVariable(0),
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   282
    DataRate ("255b/s"),
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   283
    128);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   284
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   285
// Tell the application when to start and stop.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   286
//
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   287
  ooff->Start(Seconds(1.));
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   288
  ooff->Stop (Seconds(10.));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   289
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   290
// Configure tracing of all enqueue, dequeue, and NetDevice receive events.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   291
// Trace output will be sent to the file "csma-multicast.tr"
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   292
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   293
  NS_DEBUG("Configure Tracing.");
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   294
  AsciiTrace asciitrace ("csma-multicast.tr");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
  asciitrace.TraceAllNetDeviceRx ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
  asciitrace.TraceAllQueues ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   297
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   298
// Also configure some tcpdump traces; each interface will be traced.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   299
// The output files will be named:
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   300
//     csma-multicast.pcap-<nodeId>-<interfaceId>
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   301
// and can be read by the "tcpdump -r" command (use "-tt" option to
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   302
// display timestamps correctly)
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   303
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   304
  PcapTrace pcaptrace ("csma-multicast.pcap");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
  pcaptrace.TraceAllIp ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   306
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   307
// Now, do the actual simulation.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   308
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   309
  NS_DEBUG("Run Simulation.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   310
  Simulator::Run ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
  Simulator::Destroy ();
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   312
  NS_DEBUG("Done.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
}