scratch/first.cc
author Qasim Javed <qasimj@gmail.com>
Thu Aug 06 01:55:49 2009 +0600 (2009-08-06)
changeset 4638 19aa5f9b4bdf
parent 4635 91e75d702791
permissions -rw-r--r--
Source NAT working! Run (examples/netfilter-example.cc)
     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/core-module.h"
    18 #include "ns3/simulator-module.h"
    19 #include "ns3/node-module.h"
    20 #include "ns3/helper-module.h"
    21 
    22 using namespace ns3;
    23 
    24 NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
    25 
    26   int 
    27 main (int argc, char *argv[])
    28 {
    29   LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
    30   LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO);
    31 
    32   NodeContainer nodes;
    33   nodes.Create (2);
    34 
    35   PointToPointHelper pointToPoint;
    36   pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
    37   pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
    38 
    39   NetDeviceContainer devices;
    40   devices = pointToPoint.Install (nodes);
    41 
    42   InternetStackHelper stack;
    43   stack.Install (nodes);
    44 
    45   Ipv4AddressHelper address;
    46   address.SetBase ("10.1.1.0", "255.255.255.0");
    47 
    48   Ipv4InterfaceContainer interfaces = address.Assign (devices);
    49 
    50   UdpEchoServerHelper echoServer (9);
    51 
    52   ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
    53   serverApps.Start (Seconds (1.0));
    54   serverApps.Stop (Seconds (10.0));
    55 
    56   UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
    57   echoClient.SetAttribute ("MaxPackets", UintegerValue (2));
    58   echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.)));
    59   echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
    60 
    61   ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
    62   clientApps.Start (Seconds (2.0));
    63   clientApps.Stop (Seconds (10.0));
    64   
    65   PointToPointHelper::EnablePcapAll ("netfilter");
    66 
    67   Simulator::Run ();
    68   Simulator::Destroy ();
    69   return 0;
    70 }