examples/mixed-wireless.py
author Florian Westphal <fw@strlen.de>
Wed, 03 Sep 2008 23:24:59 +0200
changeset 3595 693faf7f4e9b
parent 3536 087b1b45b3b5
child 4211 11cae8936153
permissions -rw-r--r--
nsc: Fix build problem if gtk config store is disabled gtk config store pulled in libdl.so for us, so things fail to link of the config store isn't enabled. This makes nsc pull in libdl itself when its enabled.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3422
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     1
# /*
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     2
#  * This program is free software; you can redistribute it and/or modify
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     3
#  * it under the terms of the GNU General Public License version 2 as
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     4
#  * published by the Free Software Foundation;
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     5
#  *
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     6
#  * This program is distributed in the hope that it will be useful,
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     7
#  * but WITHOUT ANY WARRANTY; without even the implied warranty of
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     8
#  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
     9
#  * GNU General Public License for more details.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    10
#  *
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    11
#  * You should have received a copy of the GNU General Public License
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    12
#  * along with this program; if not, write to the Free Software
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    13
#  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    14
#  *
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    15
#  */
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    16
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    17
# 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    18
#  This ns-3 example demonstrates the use of helper functions to ease 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    19
#  the construction of simulation scenarios.  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    20
#  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    21
#  The simulation topology consists of a mixed wired and wireless
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    22
#  scenario in which a hierarchical mobility model is used.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    23
# 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    24
#  The simulation layout consists of N backbone routers interconnected
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    25
#  by an ad hoc wifi network.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    26
#  Each backbone router also has a local 802.11 network and is connected
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    27
#  to a local LAN.  An additional set of(K-1) nodes are connected to
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    28
#  this backbone.  Finally, a local LAN is connected to each router
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    29
#  on the backbone, with L-1 additional hosts.  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    30
# 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    31
#  The nodes are populated with TCP/IP stacks, and OLSR unicast routing
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    32
#  on the backbone.  An example UDP transfer is shown.  The simulator
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    33
#  be configured to output tcpdumps or traces from different nodes.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    34
# 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    35
# 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    36
#           +--------------------------------------------------------+
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    37
#           |                                                        |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    38
#           |              802.11 ad hoc, ns-2 mobility              | 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    39
#           |                                                        |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    40
#           +--------------------------------------------------------+
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    41
#                    |       o o o(N backbone routers)       |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    42
#                +--------+                               +--------+
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    43
#      wired LAN | mobile |                     wired LAN | mobile |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    44
#     -----------| router |                    -----------| router |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    45
#                ---------                                ---------
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    46
#                    |                                        |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    47
#           +----------------+                       +----------------+
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    48
#           |     802.11     |                       |     802.11     |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    49
#           |      net       |                       |       net      |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    50
#           |   K-1 hosts    |                       |   K-1 hosts    |
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    51
#           +----------------+                       +----------------+
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    52
# 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    53
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    54
import ns3
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    55
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    56
# # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    57
# #  This function will be used below as a trace sink
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    58
# #  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    59
# static void
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    60
# CourseChangeCallback(std.string path, Ptr<const MobilityModel> model)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    61
# {
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    62
#   Vector position = model.GetPosition();
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    63
#   std.cout << "CourseChange " << path << " x=" << position.x << ", y=" << position.y << ", z=" << position.z << std.endl;
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    64
# }
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    65
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    66
def main(argv): 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    67
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    68
    #  First, we declare and initialize a few local variables that control some 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    69
    #  simulation parameters.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    70
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    71
    backboneNodes = 10
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    72
    infraNodes = 5
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    73
    lanNodes = 5
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    74
    stopTime = 10
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    75
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    76
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    77
    #  Simulation defaults are typically set next, before command line
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    78
    #  arguments are parsed.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    79
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    80
    ns3.Config.SetDefault("ns3::OnOffApplication::PacketSize", ns3.StringValue("210"))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    81
    ns3.Config.SetDefault("ns3::OnOffApplication::DataRate", ns3.StringValue("448kb/s"))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    82
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    83
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    84
    #  For convenience, we add the local variables to the command line argument
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    85
    #  system so that they can be overridden with flags such as 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    86
    #  "--backboneNodes=20"
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    87
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    88
    cmd = ns3.CommandLine()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    89
    #cmd.AddValue("backboneNodes", "number of backbone nodes", backboneNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    90
    #cmd.AddValue("infraNodes", "number of leaf nodes", infraNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    91
    #cmd.AddValue("lanNodes", "number of LAN nodes", lanNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    92
    #cmd.AddValue("stopTime", "simulation stop time(seconds)", stopTime)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    93
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    94
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    95
    #  The system global variables and the local values added to the argument
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    96
    #  system can be overridden by command line arguments by using this call.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    97
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    98
    cmd.Parse(argv)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
    99
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   100
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   101
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   102
    #  Construct the backbone                                                # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   103
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   104
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   105
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   106
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   107
    #  Create a container to manage the nodes of the adhoc(backbone) network.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   108
    #  Later we'll create the rest of the nodes we'll need.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   109
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   110
    backbone = ns3.NodeContainer()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   111
    backbone.Create(backboneNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   112
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   113
    #  Create the backbone wifi net devices and install them into the nodes in 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   114
    #  our container
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   115
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   116
    wifi = ns3.WifiHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   117
    wifi.SetMac("ns3::AdhocWifiMac")
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   118
    wifi.SetPhy("ns3::WifiPhy")
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   119
    backboneDevices = wifi.Install(backbone)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   120
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   121
    #  Add the IPv4 protocol stack to the nodes in our container
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   122
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   123
    internet = ns3.InternetStackHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   124
    internet.Install(backbone)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   125
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   126
    #  Assign IPv4 addresses to the device drivers(actually to the associated
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   127
    #  IPv4 interfaces) we just created.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   128
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   129
    ipAddrs = ns3.Ipv4AddressHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   130
    ipAddrs.SetBase(ns3.Ipv4Address("192.168.0.0"), ns3.Ipv4Mask("255.255.255.0"))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   131
    ipAddrs.Assign(backboneDevices)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   132
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   133
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   134
    #  The ad-hoc network nodes need a mobility model so we aggregate one to 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   135
    #  each of the nodes we just finished building.  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   136
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   137
    mobility = ns3.MobilityHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   138
    positionAlloc = ns3.ListPositionAllocator()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   139
    x = 0.0
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   140
    for i in range(backboneNodes):
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   141
        positionAlloc.Add(ns3.Vector(x, 0.0, 0.0))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   142
        x += 5.0
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   143
    mobility.SetPositionAllocator(positionAlloc)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   144
    mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   145
                               "Bounds", ns3.RectangleValue(ns3.Rectangle(0, 1000, 0, 1000)),
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   146
                               "Speed", ns3.RandomVariableValue(ns3.ConstantVariable(2000)),
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   147
                               "Pause", ns3.RandomVariableValue(ns3.ConstantVariable(0.2)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   148
    mobility.Install(backbone)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   149
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   150
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   151
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   152
    #  Construct the LANs                                                    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   153
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   154
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   155
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   156
    #  Reset the address base-- all of the CSMA networks will be in
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   157
    #  the "172.16 address space
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   158
    ipAddrs.SetBase(ns3.Ipv4Address("172.16.0.0"), ns3.Ipv4Mask("255.255.255.0"))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   159
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   160
    for i in range(backboneNodes):
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   161
        print "Configuring local area network for backbone node ", i
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   162
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   163
        #  Create a container to manage the nodes of the LAN.  We need
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   164
        #  two containers here; one with all of the new nodes, and one
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   165
        #  with all of the nodes including new and existing nodes
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   166
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   167
        newLanNodes = ns3.NodeContainer()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   168
        newLanNodes.Create(lanNodes - 1)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   169
        #  Now, create the container with all nodes on this link
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   170
        lan = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), newLanNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   171
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   172
        #  Create the CSMA net devices and install them into the nodes in our 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   173
        #  collection.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   174
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   175
        csma = ns3.CsmaHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   176
        csma.SetChannelAttribute("DataRate", ns3.DataRateValue(ns3.DataRate(5000000)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   177
        csma.SetChannelAttribute("Delay", ns3.TimeValue(ns3.MilliSeconds(2)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   178
        lanDevices = csma.Install(lan)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   179
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   180
        #  Add the IPv4 protocol stack to the new LAN nodes
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   181
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   182
        internet.Install(newLanNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   183
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   184
        #  Assign IPv4 addresses to the device drivers(actually to the 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   185
        #  associated IPv4 interfaces) we just created.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   186
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   187
        ipAddrs.Assign(lanDevices)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   188
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   189
        #  Assign a new network prefix for the next LAN, according to the
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   190
        #  network mask initialized above
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   191
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   192
        ipAddrs.NewNetwork()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   193
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   194
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   195
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   196
    #  Construct the mobile networks                                         # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   197
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   198
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   199
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   200
    #  Reset the address base-- all of the 802.11 networks will be in
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   201
    #  the "10.0" address space
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   202
    ipAddrs.SetBase(ns3.Ipv4Address("10.0.0.0"), ns3.Ipv4Mask("255.255.255.0"))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   203
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   204
    for i in range(backboneNodes):
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   205
        print "Configuring wireless network for backbone node ", i
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   206
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   207
        #  Create a container to manage the nodes of the LAN.  We need
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   208
        #  two containers here; one with all of the new nodes, and one
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   209
        #  with all of the nodes including new and existing nodes
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   210
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   211
        newInfraNodes = ns3.NodeContainer()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   212
        newInfraNodes.Create(infraNodes - 1)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   213
        #  Now, create the container with all nodes on this link
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   214
        infra = ns3.NodeContainer(ns3.NodeContainer(backbone.Get(i)), newInfraNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   215
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   216
        #  Create another ad hoc network and devices
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   217
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   218
        wifiInfra = ns3.WifiHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   219
        wifiInfra.SetMac("ns3::AdhocWifiMac")
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   220
        wifiInfra.SetPhy("ns3::WifiPhy")
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   221
        infraDevices = wifiInfra.Install(infra)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   222
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   223
        #  Add the IPv4 protocol stack to the nodes in our container
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   224
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   225
        internet.Install(newInfraNodes)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   226
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   227
        #  Assign IPv4 addresses to the device drivers(actually to the associated
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   228
        #  IPv4 interfaces) we just created.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   229
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   230
        ipAddrs.Assign(infraDevices)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   231
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   232
        #  Assign a new network prefix for each mobile network, according to 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   233
        #  the network mask initialized above
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   234
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   235
        ipAddrs.NewNetwork()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   236
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   237
        #  The new wireless nodes need a mobility model so we aggregate one 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   238
        #  to each of the nodes we just finished building.
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   239
        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   240
        subnetAlloc = ns3.ListPositionAllocator()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   241
        for j in range(infra.GetN()):
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   242
            subnetAlloc.Add(ns3.Vector(0.0, j, 0.0))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   243
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   244
        mobility.PushReferenceMobilityModel(backbone.Get(i))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   245
        mobility.SetPositionAllocator(subnetAlloc)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   246
        mobility.SetMobilityModel("ns3::RandomDirection2dMobilityModel",
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   247
                                  "Bounds", ns3.RectangleValue(ns3.Rectangle(-25, 25, -25, 25)),
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   248
                                  "Speed", ns3.RandomVariableValue(ns3.ConstantVariable(30)),
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   249
                                  "Pause", ns3.RandomVariableValue(ns3.ConstantVariable(0.4)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   250
        mobility.Install(infra)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   251
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   252
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   253
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   254
    #  Routing configuration                                                 # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   255
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   256
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   257
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   258
    print "Enabling OLSR routing on all backbone nodes"
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   259
    olsr = ns3.OlsrHelper()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   260
    olsr.Install(backbone)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   261
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   262
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   263
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   264
    #  Application configuration                                             # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   265
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   266
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   267
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   268
    #  Create the OnOff application to send UDP datagrams of size
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   269
    #  210 bytes at a rate of 448 Kb/s, between two nodes
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   270
    print "Create Applications."
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   271
    port = 9   #  Discard port(RFC 863)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   272
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   273
    #  Let's make sure that the user does not define too few LAN nodes
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   274
    #  to make this example work.  We need lanNodes >= 5
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   275
    assert (lanNodes >= 5)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   276
    appSource = ns3.NodeList.GetNode(11)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   277
    appSink = ns3.NodeList.GetNode(13)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   278
    remoteAddr = ns3.Ipv4Address("172.16.0.5")
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   279
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   280
    onoff = ns3.OnOffHelper("ns3::UdpSocketFactory", 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   281
                            ns3.Address(ns3.InetSocketAddress(remoteAddr, port)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   282
    onoff.SetAttribute("OnTime", ns3.RandomVariableValue(ns3.ConstantVariable(1)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   283
    onoff.SetAttribute("OffTime", ns3.RandomVariableValue(ns3.ConstantVariable(0)))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   284
    apps = onoff.Install(ns3.NodeContainer(appSource))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   285
    apps.Start(ns3.Seconds(3.0))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   286
    apps.Stop(ns3.Seconds(20.0))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   287
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   288
    #  Create a packet sink to receive these packets
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   289
    sink = ns3.PacketSinkHelper("ns3::UdpSocketFactory", 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   290
                                ns3.InetSocketAddress(ns3.Ipv4Address.GetAny(), port))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   291
    apps = sink.Install(ns3.NodeContainer(appSink))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   292
    apps.Start(ns3.Seconds(3.0))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   293
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   294
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   295
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   296
    #  Tracing configuration                                                 # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   297
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   298
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # / 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   299
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   300
    print "Configure Tracing."
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   301
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   302
    #  Let's set up some ns-2-like ascii traces, using another helper class
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   303
    # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   304
    #std.ofstream ascii
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   305
    #ascii.open("mixed-wireless.tr")
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   306
    #WifiHelper.EnableAsciiAll(ascii)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   307
    #CsmaHelper.EnableAsciiAll(ascii)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   308
    print "(tracing not done for Python)"
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   309
    #  Look at nodes 11, 13 only
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   310
    # WifiHelper.EnableAscii(ascii, 11, 0); 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   311
    # WifiHelper.EnableAscii(ascii, 13, 0); 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   312
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   313
    #  Let's do a pcap trace on the backbone devices
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   314
    ns3.WifiHelper.EnablePcap("mixed-wireless", backboneDevices)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   315
    #  Let's additionally trace the application Sink, ifIndex 0
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   316
    ns3.CsmaHelper.EnablePcap("mixed-wireless", appSink.GetId(), 0)
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   317
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   318
#   #ifdef ENABLE_FOR_TRACING_EXAMPLE
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   319
#     Config.Connect("/NodeList/*/$MobilityModel/CourseChange",
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   320
#       MakeCallback(&CourseChangeCallback))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   321
#   #endif
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   322
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   323
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   324
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   325
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   326
    #  Run simulation                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   327
    #                                                                        # 
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   328
    # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #  
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   329
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   330
    print "Run Simulation."
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   331
    ns3.Simulator.Stop(ns3.Seconds(stopTime))
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   332
    ns3.Simulator.Run()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   333
    ns3.Simulator.Destroy()
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   334
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   335
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   336
if __name__ == '__main__':
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   337
    import sys
ad0c05e68792 Add mixed-wireless example ported to Python.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff changeset
   338
    main(sys.argv)