examples/csma-multicast.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Fri, 26 Oct 2007 14:14:20 +0200
changeset 2036 0cb3c7151e89
parent 1515 e87ff7b66737
child 2230 9f13ac3291e0
permissions -rw-r--r--
add missing copyright headers
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"
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    36
#include "ns3/log.h"
1428
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"
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
    47
#include "ns3/mac48-address.h"
1428
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"
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
    54
#include "ns3/packet-sink.h"
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
using namespace ns3;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    58
NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    59
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
int 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
main (int argc, char *argv[])
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
{
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    63
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    64
// 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
    65
// 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
    66
//
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
    67
#if 0
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    68
  LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    69
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    70
  LogComponentEnable("Object", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    71
  LogComponentEnable("Queue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    72
  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    73
  LogComponentEnable("Channel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    74
  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    75
  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    76
  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    77
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    78
  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    79
  LogComponentEnable("Socket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    80
  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    81
  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    82
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    83
  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    84
  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    85
  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    86
  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    87
  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    88
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    89
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    90
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
    91
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
#endif
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    93
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    94
// 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
    95
// 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
    96
// 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
    97
// queue factory is invoked in the topology code
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    98
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  DefaultValue::Bind ("Queue", "DropTailQueue");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   100
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   101
// 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
   102
// run-time, via command-line arguments
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   103
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
  CommandLine::Parse (argc, argv);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   105
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   106
// 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
   107
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   108
  NS_LOG_INFO ("Create nodes.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
  Ptr<Node> n0 = Create<InternetNode> ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
  Ptr<Node> n1 = Create<InternetNode> (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
  Ptr<Node> n2 = Create<InternetNode> (); 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
  Ptr<Node> n3 = Create<InternetNode> ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   113
  Ptr<Node> n4 = Create<InternetNode> ();
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   115
  NS_LOG_INFO ("Create channels.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   116
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   117
// 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
   118
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   119
  Ptr<CsmaChannel> lan0 = 
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1433
diff changeset
   120
    CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   121
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   122
  Ptr<CsmaChannel> lan1 = 
1434
2b63aafb050b set source address in socket
Craig Dowell <craigdo@ee.washington.edu>
parents: 1433
diff changeset
   123
    CsmaTopology::CreateCsmaChannel(DataRate(5000000), MilliSeconds(2));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   125
  NS_LOG_INFO ("Build Topology.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   126
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   127
// 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
   128
// 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
   129
// 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
   130
// 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
   131
// 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
   132
// 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
   133
// 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
   134
// connect to Lan0. 
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   135
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   136
  uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan0, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   137
    Mac48Address("08:00:2e:00:00:00"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   138
  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan0, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   139
    Mac48Address("08:00:2e:00:00:01"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   140
  uint32_t nd2Lan0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan0, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   141
    Mac48Address("08:00:2e:00:00:02"));
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   142
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   143
  uint32_t nd2Lan1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan1, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   144
    Mac48Address("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
   145
  uint32_t nd3 __attribute__ ((unused)) = 
d1dc9446655d variable unused in optimized build -- fixed via attribute
Craig Dowell <craigdo@ee.washington.edu>
parents: 1452
diff changeset
   146
    CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan1, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   147
    Mac48Address("08:00:2e:00:00:04"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   148
  uint32_t nd4 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n4, lan1, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   149
    Mac48Address("08:00:2e:00:00:05"));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   151
  NS_LOG_INFO ("nd0 = " << nd0);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   152
  NS_LOG_INFO ("nd1 = " << nd1);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   153
  NS_LOG_INFO ("nd2Lan0 = " << nd2Lan0);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   154
  NS_LOG_INFO ("nd2Lan1 = " << nd2Lan1);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   155
  NS_LOG_INFO ("nd3 = " << nd3);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   156
  NS_LOG_INFO ("nd4 = " << nd3);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   157
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   158
// 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
   159
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   160
  NS_LOG_INFO ("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
   161
  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
   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
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
   164
  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
   165
    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
   166
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   167
//
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
   168
// We'll need these addresses later
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
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
  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
   171
  Ipv4Address n2Lan1Addr ("10.1.2.1");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   172
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
   173
  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
   174
    Ipv4Mask ("255.255.255.0"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   175
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   176
// 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
   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 (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
   179
    Ipv4Mask ("255.255.255.0"));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
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
   181
  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
   182
    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
   183
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
   184
  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
   185
    Ipv4Mask ("255.255.255.0"));
1436
9f9fe7919c89 Silliness for optimized version
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   186
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   187
  NS_LOG_INFO ("Configure multicasting.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   188
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   189
// 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
   190
// 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
   191
// 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
   192
// 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
   193
// (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
   194
// 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
   195
// 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
   196
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
  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
   198
  Ipv4Address multicastGroup ("225.1.2.4");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   199
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   200
// 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
   201
// 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
   202
// 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
   203
// 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
   204
// 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
   205
//
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
// 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
   207
// 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
   208
// 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
   209
// 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
   210
// 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
   211
// 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
   212
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
  Ptr<Ipv4> ipv4;
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   214
  ipv4 = n2->QueryInterface<Ipv4> (Ipv4::iid);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   216
  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
   217
  uint32_t ifIndexLan1 = ipv4->FindInterfaceForAddr (n2Lan1Addr);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   218
//
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
   219
// 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
   220
// 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
   221
// 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
   222
// 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
   223
// 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
   224
// 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
   225
// true in this case).
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
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
  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
   228
  outputInterfaces[0] = ifIndexLan1;
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
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
   230
  ipv4->AddMulticastRoute (multicastSource, multicastGroup, ifIndexLan0,
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   231
    outputInterfaces);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   232
//
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   233
// 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
   234
// 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
   235
// 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
   236
// 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
   237
// 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
   238
// 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
   239
// 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
   240
// 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
   241
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   242
// 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
   243
// 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
   244
// 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
   245
// 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
   246
// 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
   247
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   248
// 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
   249
// 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
   250
// 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
   251
// 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
   252
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   253
// 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
   254
// 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
   255
// 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
   256
// SetDefaultRoute ().
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   257
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   258
// 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
   259
// 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
   260
// 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
   261
// 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
   262
// 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
   263
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   264
  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
   265
  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
   266
  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
   267
//
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   268
// 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
   269
// 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
   270
// 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
   271
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   272
  ipv4 = n4->QueryInterface<Ipv4> (Ipv4::iid);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   273
  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   274
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   275
// 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
   276
// multicast group (node four will be listening).
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   277
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   278
  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
   279
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   280
  uint16_t port = 9;   // Discard port (RFC 863)
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   281
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   282
  // Configure a multicast packet generator that generates a packet
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   283
  // every few seconds
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
  Ptr<OnOffApplication> ooff = Create<OnOffApplication> (
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
    n0, 
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
   286
    InetSocketAddress (multicastGroup, port), 
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
    "Udp",
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
    ConstantVariable(1), 
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   289
    ConstantVariable(0),
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   290
    DataRate ("255b/s"),
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   291
    128);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   292
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   293
// Tell the application when to start and stop.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   294
//
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   295
  ooff->Start(Seconds(1.));
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   296
  ooff->Stop (Seconds(10.));
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   297
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   298
  // Create an optional packet sink to receive these packets
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   299
  // If you enable logging on this (above) it will print a log statement
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   300
  // for every packet received
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   301
  Ptr<PacketSink> sink = Create<PacketSink> (
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   302
    n4,
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   303
    InetSocketAddress (Ipv4Address::GetAny (), port),
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   304
    "Udp");
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   305
  // Start the sink
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   306
  sink->Start (Seconds (1.0));
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   307
  sink->Stop (Seconds (10.0));
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   308
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   309
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   310
// 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
   311
// 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
   312
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   313
  NS_LOG_INFO ("Configure Tracing.");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   314
  AsciiTrace asciitrace ("csma-multicast.tr");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
  asciitrace.TraceAllNetDeviceRx ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
  asciitrace.TraceAllQueues ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   317
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   318
// 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
   319
// The output files will be named:
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   320
//     csma-multicast.pcap-<nodeId>-<interfaceId>
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   321
// 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
   322
// display timestamps correctly)
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   323
//
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   324
  PcapTrace pcaptrace ("csma-multicast.pcap");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
  pcaptrace.TraceAllIp ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   326
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   327
// Now, do the actual simulation.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   328
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   329
  NS_LOG_INFO ("Run Simulation.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
  Simulator::Run ();
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
  Simulator::Destroy ();
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   332
  NS_LOG_INFO ("Done.");
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
}