examples/csma-multicast.cc
changeset 2965 4b28e9740e3b
parent 2890 172baa5960ff
child 2972 d76553495b91
equal deleted inserted replaced
2964:4e8cb1577144 2965:4b28e9740e3b
    57 
    57 
    58   //
    58   //
    59   // Set up default values for the simulation.  
    59   // Set up default values for the simulation.  
    60   //
    60   //
    61   // Select Ethernet II-style encapsulation (no LLC/Snap header)
    61   // Select Ethernet II-style encapsulation (no LLC/Snap header)
    62   Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", String ("IpArp"));  
    62   Config::SetDefault ("ns3::CsmaNetDevice::EncapsulationMode", StringValue ("IpArp"));  
    63 
    63 
    64   // Allow the user to override any of the defaults at
    64   // Allow the user to override any of the defaults at
    65   // run-time, via command-line arguments
    65   // run-time, via command-line arguments
    66   CommandLine cmd;
    66   CommandLine cmd;
    67   cmd.Parse (argc, argv);
    67   cmd.Parse (argc, argv);
    73   NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
    73   NodeContainer c0 = NodeContainer (c.Get (0), c.Get (1), c.Get (2));
    74   NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
    74   NodeContainer c1 = NodeContainer (c.Get (2), c.Get (3), c.Get (4));
    75   
    75   
    76   NS_LOG_INFO ("Build Topology.");
    76   NS_LOG_INFO ("Build Topology.");
    77   CsmaHelper csma;
    77   CsmaHelper csma;
    78   csma.SetChannelParameter ("BitRate", DataRate (5000000));
    78   csma.SetChannelParameter ("BitRate", DataRateValue (DataRate (5000000)));
    79   csma.SetChannelParameter ("Delay", MilliSeconds (2));
    79   csma.SetChannelParameter ("Delay", TimeValue (MilliSeconds (2)));
    80  
    80  
    81   // We will use these NetDevice containers later, for IP addressing
    81   // We will use these NetDevice containers later, for IP addressing
    82   NetDeviceContainer nd0 = csma.Install (c0);  // First LAN
    82   NetDeviceContainer nd0 = csma.Install (c0);  // First LAN
    83   NetDeviceContainer nd1 = csma.Install (c1);  // Second LAN
    83   NetDeviceContainer nd1 = csma.Install (c1);  // Second LAN
    84 
    84 
   141 
   141 
   142   // Configure a multicast packet generator that generates a packet
   142   // Configure a multicast packet generator that generates a packet
   143   // every few seconds
   143   // every few seconds
   144   OnOffHelper onoff ("ns3::Udp", 
   144   OnOffHelper onoff ("ns3::Udp", 
   145     Address (InetSocketAddress (multicastGroup, multicastPort)));
   145     Address (InetSocketAddress (multicastGroup, multicastPort)));
   146   onoff.SetAttribute ("OnTime", ConstantVariable (1));
   146   onoff.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
   147   onoff.SetAttribute ("OffTime", ConstantVariable (0));
   147   onoff.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
   148   onoff.SetAttribute ("DataRate", DataRate ("255b/s"));
   148   onoff.SetAttribute ("DataRate", DataRateValue (DataRate ("255b/s")));
   149   onoff.SetAttribute ("PacketSize", Uinteger (128));
   149   onoff.SetAttribute ("PacketSize", UintegerValue (128));
   150 
   150 
   151   ApplicationContainer srcC = onoff.Install (c0.Get (0));
   151   ApplicationContainer srcC = onoff.Install (c0.Get (0));
   152 
   152 
   153   //
   153   //
   154   // Tell the application when to start and stop.
   154   // Tell the application when to start and stop.
   156   srcC.Start(Seconds(1.));
   156   srcC.Start(Seconds(1.));
   157   srcC.Stop (Seconds(10.));
   157   srcC.Stop (Seconds(10.));
   158 
   158 
   159   // Create an optional packet sink to receive these packets
   159   // Create an optional packet sink to receive these packets
   160   PacketSinkHelper sink ("ns3::Udp",
   160   PacketSinkHelper sink ("ns3::Udp",
   161     Address (InetSocketAddress (Ipv4Address::GetAny(), multicastPort)));
   161                          InetSocketAddress (Ipv4Address::GetAny(), multicastPort));
   162 
   162 
   163   ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 
   163   ApplicationContainer sinkC = sink.Install (c1.Get (2)); // Node n4 
   164   // Start the sink
   164   // Start the sink
   165   sinkC.Start (Seconds (1.0));
   165   sinkC.Start (Seconds (1.0));
   166   sinkC.Stop (Seconds (10.0));
   166   sinkC.Stop (Seconds (10.0));