tutorial/tutorial-star.cc
changeset 1841 afa9089bcab4
child 1842 a6b327e4b547
equal deleted inserted replaced
1840:f5bb4b608832 1841:afa9089bcab4
       
     1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * This program is free software; you can redistribute it and/or modify
       
     4  * it under the terms of the GNU General Public License version 2 as
       
     5  * published by the Free Software Foundation;
       
     6  *
       
     7  * This program is distributed in the hope that it will be useful,
       
     8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
     9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    10  * GNU General Public License for more details.
       
    11  *
       
    12  * You should have received a copy of the GNU General Public License
       
    13  * along with this program; if not, write to the Free Software
       
    14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    15  */
       
    16 
       
    17 #include "ns3/log.h"
       
    18 #include "ns3/ptr.h"
       
    19 #include "ns3/internet-node.h"
       
    20 #include "ns3/point-to-point-channel.h"
       
    21 #include "ns3/mac48-address.h"
       
    22 #include "ns3/point-to-point-net-device.h"
       
    23 #include "ns3/point-to-point-ipv4-topology.h"
       
    24 #include "ns3/udp-echo-client.h"
       
    25 #include "ns3/udp-echo-server.h"
       
    26 #include "ns3/simulator.h"
       
    27 #include "ns3/nstime.h"
       
    28 #include "ns3/ascii-trace.h"
       
    29 #include "ns3/pcap-trace.h"
       
    30 #include "ns3/global-route-manager.h"
       
    31 
       
    32 NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
       
    33 
       
    34 using namespace ns3;
       
    35 
       
    36 // Network topology
       
    37 //
       
    38 //                  n3    n2
       
    39 //                   |   /
       
    40 //                    | /
       
    41 //              n4 --- n0 --- n1
       
    42 //                    /  |
       
    43 //                   /    |
       
    44 //                  n5    n6
       
    45 
       
    46 int 
       
    47 main (int argc, char *argv[])
       
    48 {
       
    49   LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
       
    50 
       
    51   NS_LOG_INFO ("Point to Point Topology Simulation");
       
    52 
       
    53   Ptr<Node> n0 = Create<InternetNode> ();
       
    54   Ptr<Node> n1 = Create<InternetNode> ();
       
    55   Ptr<Node> n2 = Create<InternetNode> ();
       
    56   Ptr<Node> n3 = Create<InternetNode> ();
       
    57   Ptr<Node> n4 = Create<InternetNode> ();
       
    58   Ptr<Node> n5 = Create<InternetNode> ();
       
    59   Ptr<Node> n6 = Create<InternetNode> ();
       
    60 
       
    61   Ptr<PointToPointChannel> link01 = 
       
    62     PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
       
    63     MilliSeconds (20));
       
    64 
       
    65   uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0,
       
    66     link01);
       
    67 
       
    68   Ptr<PointToPointChannel> link02 = 
       
    69     PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
       
    70     MilliSeconds (20));
       
    71 
       
    72   uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0,
       
    73     link02);
       
    74 
       
    75   Ptr<PointToPointChannel> link03 = 
       
    76     PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
       
    77     MilliSeconds (20));
       
    78 
       
    79   uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0,
       
    80     link03);
       
    81 
       
    82   Ptr<PointToPointChannel> link04 = 
       
    83     PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
       
    84     MilliSeconds (20));
       
    85 
       
    86   uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, 
       
    87     link04);
       
    88 
       
    89   Ptr<PointToPointChannel> link05 = 
       
    90     PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
       
    91     MilliSeconds (20));
       
    92 
       
    93   uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0,
       
    94     link05);
       
    95 
       
    96   Ptr<PointToPointChannel> link06 = 
       
    97     PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
       
    98     MilliSeconds (20));
       
    99 
       
   100   uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, 
       
   101     link06);
       
   102 
       
   103   uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, 
       
   104     link01);
       
   105 
       
   106   uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, 
       
   107     link02);
       
   108 
       
   109   uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, 
       
   110     link03);
       
   111 
       
   112   uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, 
       
   113     link04);
       
   114 
       
   115   uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, 
       
   116     link05);
       
   117 
       
   118   uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, 
       
   119     link06);
       
   120 
       
   121   PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", 
       
   122     "255.255.255.252");
       
   123 
       
   124   PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", 
       
   125     "255.255.255.252");
       
   126 
       
   127   PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", 
       
   128     "255.255.255.252");
       
   129 
       
   130   PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", 
       
   131     "255.255.255.252");
       
   132 
       
   133   PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", 
       
   134     "255.255.255.252");
       
   135 
       
   136   PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", 
       
   137     "255.255.255.252");
       
   138 
       
   139   PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", 
       
   140     "255.255.255.252");
       
   141 
       
   142   PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", 
       
   143     "255.255.255.252");
       
   144 
       
   145   PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", 
       
   146     "255.255.255.252");
       
   147 
       
   148   PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", 
       
   149     "255.255.255.252");
       
   150 
       
   151   PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", 
       
   152     "255.255.255.252");
       
   153 
       
   154   PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", 
       
   155     "255.255.255.252");
       
   156 
       
   157   uint16_t port = 7;
       
   158 
       
   159   Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.1.2", port, 
       
   160     1, Seconds(1.), 1024);
       
   161 
       
   162   Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port);
       
   163 
       
   164   server->Start(Seconds(1.));
       
   165   client->Start(Seconds(2.));
       
   166 
       
   167   server->Stop (Seconds(10.));
       
   168   client->Stop (Seconds(10.));
       
   169 
       
   170   AsciiTrace asciitrace ("tutorial.tr");
       
   171   asciitrace.TraceAllQueues ();
       
   172   asciitrace.TraceAllNetDeviceRx ();
       
   173 
       
   174   Simulator::Run ();
       
   175   Simulator::Destroy ();
       
   176 }