tutorial/tutorial-bus-network.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Mar 2008 11:10:38 -0700
changeset 2600 6c389d0c717d
parent 2592 3ebf97150166
child 2811 80ad195c1770
permissions -rw-r--r--
add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
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"
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    24
#include "ns3/inet-socket-address.h"
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    25
#include "ns3/uinteger.h"
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    27
#include "ipv4-bus-network.h"
1844
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
NS_LOG_COMPONENT_DEFINE ("BusNetworkSimulation");
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
using namespace ns3;
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
int 
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
main (int argc, char *argv[])
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
  LogComponentEnable ("BusNetworkSimulation", LOG_LEVEL_ALL);
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
  NS_LOG_INFO ("Bus Network Simulation");
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
1846
b0a2f5612f4e don't use any for starting address
Craig Dowell <craigdo@ee.washington.edu>
parents: 1845
diff changeset
    40
  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
    41
    DataRate(10000000), MilliSeconds(20), 10);
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
  uint32_t port = 7;
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    45
  Ptr<Node> n0 = bus.GetNode (0);
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    46
  Ptr<UdpEchoClient> client =  
2600
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    47
    CreateObject<UdpEchoClient> ("RemoteIpv4", Ipv4Address ("10.1.0.1"),
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    48
				 "RemotePort", Uinteger (port),
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    49
				 "MaxPackets", Uinteger (1), 
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    50
				 "Interval", Seconds(1.), 
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    51
				 "PacketSize", Uinteger (1024));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    52
  n0->AddApplication (client);
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
1845
836f0c983165 improve obj design example
Craig Dowell <craigdo@ee.washington.edu>
parents: 1844
diff changeset
    54
  Ptr<Node> n1 = bus.GetNode (1);
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    55
  Ptr<UdpEchoServer> server = 
2600
6c389d0c717d add Application::SetNode and NetDevice::SetNode, use them from Node::AddApplication and Node::AddDevice. kill useless "Node" attributes.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2592
diff changeset
    56
    CreateObject<UdpEchoServer> ("Port", Uinteger (port));
2494
1c69ea12779c port Applications to Attributes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2311
diff changeset
    57
  n1->AddApplication (server);
1844
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
  server->Start(Seconds(1.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
  client->Start(Seconds(2.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
  server->Stop (Seconds(10.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
  client->Stop (Seconds(10.));
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
  AsciiTrace asciitrace ("tutorial.tr");
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
  asciitrace.TraceAllQueues ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  asciitrace.TraceAllNetDeviceRx ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
  Simulator::Run ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
  Simulator::Destroy ();
9fe7ff742494 bus network
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
}