examples/csma-multicast.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun, 02 Mar 2008 21:57:28 +0100
changeset 2533 80cdc3eec057
parent 2502 50d0da37f02f
child 2575 1aae382e65e2
permissions -rw-r--r--
do not use Queue::CreateDefault
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"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
    55
#include "ns3/uinteger.h"
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
using namespace ns3;
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    59
NS_LOG_COMPONENT_DEFINE ("CsmaMulticastExample");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
    60
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
int 
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
main (int argc, char *argv[])
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
{
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    64
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    65
// 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
    66
// 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
    67
//
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
    68
#if 0
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    69
  LogComponentEnable ("CsmaMulticastExample", LOG_LEVEL_INFO);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    70
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    71
  LogComponentEnable("Object", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    72
  LogComponentEnable("Queue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    73
  LogComponentEnable("DropTailQueue", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    74
  LogComponentEnable("Channel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    75
  LogComponentEnable("CsmaChannel", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    76
  LogComponentEnable("NetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    77
  LogComponentEnable("CsmaNetDevice", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    78
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    79
  LogComponentEnable("PacketSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    80
  LogComponentEnable("Socket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    81
  LogComponentEnable("UdpSocket", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    82
  LogComponentEnable("UdpL4Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    83
  LogComponentEnable("Ipv4L3Protocol", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    84
  LogComponentEnable("Ipv4StaticRouting", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    85
  LogComponentEnable("Ipv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    86
  LogComponentEnable("ArpIpv4Interface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    87
  LogComponentEnable("Ipv4LoopbackInterface", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    88
  LogComponentEnable("OnOffApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    89
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    90
  LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_ALL);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
    91
  LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_ALL);
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
    92
  LogComponentEnable("PacketSinkApplication", LOG_LEVEL_ALL);
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
#endif
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    94
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
    95
// Set up default values for the simulation.  Use the DefaultValue::Bind()
2533
80cdc3eec057 do not use Queue::CreateDefault
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2502
diff changeset
    96
1433
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
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   104
  NS_LOG_INFO ("Create nodes.");
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1515
diff changeset
   105
  Ptr<Node> n0 = CreateObject<InternetNode> ();
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1515
diff changeset
   106
  Ptr<Node> n1 = CreateObject<InternetNode> (); 
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1515
diff changeset
   107
  Ptr<Node> n2 = CreateObject<InternetNode> (); 
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1515
diff changeset
   108
  Ptr<Node> n3 = CreateObject<InternetNode> ();
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1515
diff changeset
   109
  Ptr<Node> n4 = CreateObject<InternetNode> ();
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   111
  NS_LOG_INFO ("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
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   121
  NS_LOG_INFO ("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, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   133
    Mac48Address("08:00:2e:00:00:00"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   134
  uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan0, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   135
    Mac48Address("08:00:2e:00:00:01"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   136
  uint32_t nd2Lan0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, 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: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, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   140
    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
   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, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   143
    Mac48Address("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, 
1494
c2985e1cd091 rename Euixx to Macxx
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1455
diff changeset
   145
    Mac48Address("08:00:2e:00:00:05"));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   147
  NS_LOG_INFO ("nd0 = " << nd0);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   148
  NS_LOG_INFO ("nd1 = " << nd1);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   149
  NS_LOG_INFO ("nd2Lan0 = " << nd2Lan0);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   150
  NS_LOG_INFO ("nd2Lan1 = " << nd2Lan1);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   151
  NS_LOG_INFO ("nd3 = " << nd3);
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   152
  NS_LOG_INFO ("nd4 = " << nd3);
1433
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
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   156
  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
   157
  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
   158
    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
   159
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
  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
   161
    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
   162
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   163
//
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
   164
// We'll need these addresses later
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   165
//
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
   166
  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
   167
  Ipv4Address n2Lan1Addr ("10.1.2.1");
1429
31cb0668defd debug prints to make validation easier
Craig Dowell <craigdo@ee.washington.edu>
parents: 1428
diff changeset
   168
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
   169
  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
   170
    Ipv4Mask ("255.255.255.0"));
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   171
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   172
// 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
   173
//
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
   174
  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
   175
    Ipv4Mask ("255.255.255.0"));
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
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
   177
  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
   178
    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
   179
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
  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
   181
    Ipv4Mask ("255.255.255.0"));
1436
9f9fe7919c89 Silliness for optimized version
Craig Dowell <craigdo@ee.washington.edu>
parents: 1435
diff changeset
   182
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   183
  NS_LOG_INFO ("Configure multicasting.");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   184
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   185
// 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
   186
// 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
   187
// 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
   188
// 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
   189
// (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
   190
// 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
   191
// 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
   192
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
  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
   194
  Ipv4Address multicastGroup ("225.1.2.4");
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   195
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   196
// 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
   197
// 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
   198
// 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
   199
// 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
   200
// 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
   201
//
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
// 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
   203
// 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
   204
// 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
   205
// 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
   206
// 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
   207
// 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
   208
//
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  Ptr<Ipv4> ipv4;
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
   210
  ipv4 = n2->GetObject<Ipv4> ();
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   212
  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
   213
  uint32_t ifIndexLan1 = ipv4->FindInterfaceForAddr (n2Lan1Addr);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   214
//
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
   215
// 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
   216
// 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
   217
// 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
   218
// 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
   219
// 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
   220
// 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
   221
// true in this case).
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   222
//
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
   223
  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
   224
  outputInterfaces[0] = ifIndexLan1;
1428
a8f3d01d4a2c untested multicast support
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
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
   226
  ipv4->AddMulticastRoute (multicastSource, multicastGroup, ifIndexLan0,
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   227
    outputInterfaces);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   228
//
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   229
// 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
   230
// 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
   231
// 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
   232
// 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
   233
// 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
   234
// 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
   235
// 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
   236
// 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
   237
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   238
// 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
   239
// 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
   240
// 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
   241
// 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
   242
// 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
   243
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   244
// 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
   245
// 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
   246
// 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
   247
// 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
   248
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   249
// 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
   250
// 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
   251
// 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
   252
// SetDefaultRoute ().
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   253
//
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   254
// 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
   255
// 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
   256
// 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
   257
// 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
   258
// 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
   259
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
   260
  ipv4 = n0->GetObject<Ipv4> ();
1446
f9bc98cbe5fe clarify use of wildcards in multicast routes versus default mulicast routes.
Craig Dowell <craigdo@ee.washington.edu>
parents: 1442
diff changeset
   261
  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
   262
  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
   263
//
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   264
// 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
   265
// 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
   266
// 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
   267
//
2257
71a58e70c671 QueryInterface -> GetObject
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2231
diff changeset
   268
  ipv4 = n4->GetObject<Ipv4> ();
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   269
  ipv4->JoinMulticastGroup (multicastSource, multicastGroup);
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   270
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   271
// 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
   272
// multicast group (node four will be listening).
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   273
//
1504
36ecc970ba96 checkpoint debug to log
Craig Dowell <craigdo@ee.washington.edu>
parents: 1501
diff changeset
   274
  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
   275
addb79f47ba5 change port number used by example scripts to 'discard' or 'echo' instead of '80'
Tom Henderson <tomh@tomh.org>
parents: 1509
diff changeset
   276
  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
   277
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   278
  // Configure a multicast packet generator that generates a packet
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   279
  // every few seconds
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   280
  Ptr<OnOffApplication> ooff = 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   281
    CreateObjectWith<OnOffApplication> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   282
                                        "Node", n0, 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   283
                                        "Remote", Address (InetSocketAddress (multicastGroup, port)), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   284
                                        "Protocol", TypeId::LookupByName ("Udp"),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   285
                                        "OnTime", ConstantVariable(1), 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   286
                                        "OffTime", ConstantVariable(0),
2502
50d0da37f02f introduce the ns3::String class, get rid of the string -> Attribute implicit conversion, and get rid of MakeDataRate, port PointToPointNetDevice to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2494
diff changeset
   287
                                        "DataRate", DataRate ("255b/s"),
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   288
                                        "PacketSize", Uinteger (128));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   289
  n0->AddApplication (ooff);
1433
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   290
//
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   291
// Tell the application when to start and stop.
a6fb891b59fd cleanup. more complex multicast example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1432
diff changeset
   292
//
1432
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   293
  ooff->Start(Seconds(1.));
3aef7d7a71c2 more multicast plumbing
Craig Dowell <craigdo@ee.washington.edu>
parents: 1430
diff changeset
   294
  ooff->Stop (Seconds(10.));
1515
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   295
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   296
  // Create an optional packet sink to receive these packets
e87ff7b66737 Add PacketSink to receive multicast
Tom Henderson <tomh@tomh.org>
parents: 1514
diff changeset
   297
  // 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
   298
  // for every packet received
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   299
  Ptr<PacketSink> sink = 
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   300
    CreateObjectWith<PacketSink> (
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   301
                                  "Node", n4,
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   302
                                  "Local", Address (InetSocketAddress (Ipv4Address::GetAny (), port)),
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   303
                                  "Protocol", TypeId::LookupByName ("Udp"));
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2257
diff changeset
   304
  n4->AddApplication (sink);
1515
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
}