Add IPv6 python example.
authorSebastien Vincent <vincent@clarinet.u-strasbg.fr>
Fri Sep 04 16:25:55 2009 +0200 (5 months ago)
changeset 475381146e4a3993
parent 4752 3e26b3b2e3a8
child 4754 77c878bc3e84
Add IPv6 python example.
examples/simple-routing-ping6.cc
examples/simple-routing-ping6.py
     1.1 --- a/examples/simple-routing-ping6.cc	Fri Sep 04 16:23:38 2009 +0200
     1.2 +++ b/examples/simple-routing-ping6.cc	Fri Sep 04 16:25:55 2009 +0200
     1.3 @@ -35,7 +35,7 @@
     1.4  
     1.5  using namespace ns3;
     1.6  
     1.7 -NS_LOG_COMPONENT_DEFINE ("SimpleRoutingUdp6Example");
     1.8 +NS_LOG_COMPONENT_DEFINE ("SimpleRoutingPing6Example");
     1.9  
    1.10  int 
    1.11  main (int argc, char** argv)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/examples/simple-routing-ping6.py	Fri Sep 04 16:25:55 2009 +0200
     2.3 @@ -0,0 +1,106 @@
     2.4 +#
     2.5 +# Copyright (c) 2008-2009 Strasbourg University
     2.6 +#
     2.7 +# This program is free software; you can redistribute it and/or modify
     2.8 +# it under the terms of the GNU General Public License version 2 as
     2.9 +# published by the Free Software Foundation;
    2.10 +#
    2.11 +# This program is distributed in the hope that it will be useful,
    2.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.14 +# GNU General Public License for more details.
    2.15 +#
    2.16 +# You should have received a copy of the GNU General Public License
    2.17 +# along with this program; if not, write to the Free Software
    2.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.19 +#
    2.20 +# Author: David Gross <david.gross@eturs.u-strasbg.fr>
    2.21 +#         Sebastien Vincent <vincent@clarinet.u-strasbg.fr>
    2.22 +#
    2.23 +
    2.24 +#
    2.25 +# Network topology:
    2.26 +# 
    2.27 +#             n0   r    n1
    2.28 +#             |    _    |
    2.29 +#             ====|_|====
    2.30 +#                router
    2.31 +#
    2.32 +
    2.33 +import ns3;
    2.34 +
    2.35 +def main(argv):
    2.36 +
    2.37 +  cmd = ns3.CommandLine ();
    2.38 +
    2.39 +  cmd.Parse (argv);
    2.40 +
    2.41 +  # Create nodes
    2.42 +  print "Create nodes"
    2.43 +  n0 = ns3.Node ();
    2.44 +  r = ns3.Node ();
    2.45 +  n1 = ns3.Node ();
    2.46 +
    2.47 +  net1 = ns3.NodeContainer ();
    2.48 +  net1.Add (n0);
    2.49 +  net1.Add (r);
    2.50 +  net2 = ns3.NodeContainer ();
    2.51 +  net2.Add (r);
    2.52 +  net2.Add (n1);
    2.53 +  all = ns3.NodeContainer ();
    2.54 +  all.Add (n0);
    2.55 +  all.Add (r);
    2.56 +  all.Add (n1);
    2.57 +
    2.58 +  # Create IPv6 Internet Stack
    2.59 +  internetv6 = ns3.InternetStackHelper ();
    2.60 +  internetv6.Install (all);
    2.61 +
    2.62 +  # Create channels
    2.63 +  csma = ns3.CsmaHelper ();
    2.64 +  csma.SetChannelAttribute ("DataRate", ns3.DataRateValue (ns3.DataRate (5000000)));
    2.65 +  csma.SetChannelAttribute ("Delay", ns3.TimeValue (ns3.MilliSeconds (2)));
    2.66 +  d1 = csma.Install (net1);
    2.67 +  d2 = csma.Install (net2);
    2.68 +
    2.69 +  # Create networks and assign IPv6 Addresses
    2.70 +  print "Addressing"
    2.71 +  ipv6 = ns3.Ipv6AddressHelper ();
    2.72 +  ipv6.NewNetwork (ns3.Ipv6Address ("2001:1::"), ns3.Ipv6Prefix (64));
    2.73 +  i1 = ipv6.Assign (d1);
    2.74 +  i1.SetRouter (1, True);
    2.75 +  ipv6.NewNetwork (ns3.Ipv6Address ("2001:2::"), ns3.Ipv6Prefix (64));
    2.76 +  i2 = ipv6.Assign (d2);
    2.77 +  i2.SetRouter (0, True);
    2.78 +
    2.79 +  # Create a Ping6 application to send ICMPv6 echo request from n0 to n1 via r 
    2.80 +  print "Application"
    2.81 +  packetSize = 1024;
    2.82 +  maxPacketCount = 5;
    2.83 +  interPacketInterval = ns3.Seconds (1.);
    2.84 +  ping6 = ns3.Ping6Helper ();
    2.85 +
    2.86 +  ping6.SetLocal (i1.GetAddress (0, 1));
    2.87 +  ping6.SetRemote (i2.GetAddress (1, 1)); 
    2.88 +
    2.89 +  ping6.SetAttribute ("MaxPackets", ns3.UintegerValue (maxPacketCount));
    2.90 +  ping6.SetAttribute ("Interval", ns3.TimeValue (interPacketInterval));
    2.91 +  ping6.SetAttribute ("PacketSize", ns3.UintegerValue (packetSize));
    2.92 +
    2.93 +  apps = ping6.Install (ns3.NodeContainer (net1.Get (0)));
    2.94 +  apps.Start (ns3.Seconds (2.0));
    2.95 +  apps.Stop (ns3.Seconds (20.0));
    2.96 +
    2.97 +  print "Tracing"
    2.98 +  ascii = ns3.ofstream ("simple-routing-ping6.tr");
    2.99 +  ns3.CsmaHelper.EnableAsciiAll (ascii);
   2.100 +  ns3.CsmaHelper.EnablePcapAll ("simple-routing-ping6", True);
   2.101 +
   2.102 +  # Run Simulation   
   2.103 +  ns3.Simulator.Run ();
   2.104 +  ns3.Simulator.Destroy ();
   2.105 +
   2.106 +if __name__ == '__main__':
   2.107 +    import sys
   2.108 +    main(sys.argv)
   2.109 +