tutorial/tutorial-bus-network.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 02 Jan 2008 09:09:24 +0100
changeset 2230 9f13ac3291e0
parent 1846 b0a2f5612f4e
child 2311 a7dbe3cba7de
permissions -rw-r--r--
add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * This program is free software; you can redistribute it and/or modify
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 * it under the terms of the GNU General Public License version 2 as
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * published by the Free Software Foundation;
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 *
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * This program is distributed in the hope that it will be useful,
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * GNU General Public License for more details.
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 *
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * You should have received a copy of the GNU General Public License
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 * along with this program; if not, write to the Free Software
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 */
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
#include "ns3/log.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
#include "ns3/ipv4-address.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#include "ns3/udp-echo-client.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#include "ns3/udp-echo-server.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
#include "ns3/simulator.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include "ns3/nstime.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "ns3/ascii-trace.h"
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    25
#include "ipv4-bus-network.h"
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation");
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
using namespace ns3;
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
int 
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
main (int argc, char *argv[])
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
{
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
  LogComponentEnable ("BusNetworkSimulation", LOG_LEVEL_ALL);
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
  NS_LOG_INFO ("Bus Network Simulation");
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
1846
b0a2f5612f4e don't use any for starting address
Craig Dowell <craigdo@ee.washington.edu>
parents: 1845
diff changeset
    38
  Ipv4BusNetwork bus ("10.1.0.0", "255.255.0.0", "0.0.0.3",
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    39
    DataRate(10000000), MilliSeconds(20), 10);
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
  uint32_t port = 7;
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    43
  Ptr<Node> n0 = bus.GetNode (0);
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1846
diff changeset
    44
  Ptr<UdpEchoClient> client = CreateObject<UdpEchoClient> (n0, "10.1.0.1", port, 
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
    1, Seconds(1.), 1024);
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    47
  Ptr<Node> n1 = bus.GetNode (1);
2230
9f13ac3291e0 add CreateObject<> to instanciate subclasses of the Object base class. Replaces Create<>.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1846
diff changeset
    48
  Ptr<UdpEchoServer> server = CreateObject<UdpEchoServer> (n1, port);
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  server->Start(Seconds(1.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
  client->Start(Seconds(2.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
  server->Stop (Seconds(10.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
  client->Stop (Seconds(10.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
  AsciiTrace asciitrace ("tutorial.tr");
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  asciitrace.TraceAllQueues ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
  asciitrace.TraceAllNetDeviceRx ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  Simulator::Run ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
  Simulator::Destroy ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
}