author | Mitch Watrous <watrous@u.washington.edu> |
Mon, 02 May 2011 17:17:09 -0700 | |
changeset 7106 | 2939fecb7029 |
parent 7101 | cbdd99081786 |
child 11030 | 9914c1a2373f |
permissions | -rw-r--r-- |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
1 |
# /* |
9f4c2934473d
examples/first.cc 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 |
9f4c2934473d
examples/first.cc 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 |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
4 |
# * published by the Free Software Foundation; |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
5 |
# * |
9f4c2934473d
examples/first.cc 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, |
9f4c2934473d
examples/first.cc 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 |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
8 |
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
9 |
# * GNU General Public License for more details. |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
10 |
# * |
9f4c2934473d
examples/first.cc 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 |
9f4c2934473d
examples/first.cc 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 |
9f4c2934473d
examples/first.cc 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 |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
14 |
# */ |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
15 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
16 |
import ns.applications |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
17 |
import ns.core |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
18 |
import ns.internet |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
19 |
import ns.network |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
20 |
import ns.point_to_point |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
21 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
22 |
ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
23 |
ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
24 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
25 |
nodes = ns.network.NodeContainer() |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
26 |
nodes.Create(2) |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
27 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
28 |
pointToPoint = ns.point_to_point.PointToPointHelper() |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
29 |
pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps")) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
30 |
pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms")) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
31 |
|
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
32 |
devices = pointToPoint.Install(nodes) |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
33 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
34 |
stack = ns.internet.InternetStackHelper() |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
35 |
stack.Install(nodes) |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
36 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
37 |
address = ns.internet.Ipv4AddressHelper() |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
38 |
address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
39 |
|
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
40 |
interfaces = address.Assign (devices); |
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
41 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
42 |
echoServer = ns.applications.UdpEchoServerHelper(9) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
43 |
|
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
44 |
serverApps = echoServer.Install(nodes.Get(1)) |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
45 |
serverApps.Start(ns.core.Seconds(1.0)) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
46 |
serverApps.Stop(ns.core.Seconds(10.0)) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
47 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
48 |
echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
49 |
echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1)) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
50 |
echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds (1.0))) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
51 |
echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024)) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
52 |
|
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
53 |
clientApps = echoClient.Install(nodes.Get(0)) |
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
54 |
clientApps.Start(ns.core.Seconds(2.0)) |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
55 |
clientApps.Stop(ns.core.Seconds(10.0)) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
56 |
|
7106
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
57 |
ns.core.Simulator.Run() |
2939fecb7029
Make Python examples use new modular bindings without importing everything
Mitch Watrous <watrous@u.washington.edu>
parents:
7101
diff
changeset
|
58 |
ns.core.Simulator.Destroy() |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
59 |