author | Mitch Watrous <watrous@u.washington.edu> |
Fri, 29 Apr 2011 16:59:33 -0700 | |
changeset 7101 | cbdd99081786 |
parent 5369 | 86beb5869f67 |
child 7106 | 2939fecb7029 |
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 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
16 |
from ns.applications import * |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
17 |
from ns.core import * |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
18 |
from ns.internet import * |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
19 |
from ns.network import * |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
20 |
from ns.point_to_point import * |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
21 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
22 |
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
23 |
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
24 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
25 |
nodes = 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 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
28 |
pointToPoint = PointToPointHelper() |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
29 |
pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps")) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
30 |
pointToPoint.SetChannelAttribute("Delay", 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 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
34 |
stack = 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 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
37 |
address = Ipv4AddressHelper() |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
38 |
address.SetBase(Ipv4Address("10.1.1.0"), 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 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
42 |
echoServer = 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)) |
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
45 |
serverApps.Start(Seconds(1.0)) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
46 |
serverApps.Stop(Seconds(10.0)) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
47 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
48 |
echoClient = UdpEchoClientHelper(interfaces.GetAddress(1), 9) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
49 |
echoClient.SetAttribute("MaxPackets", UintegerValue(1)) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
50 |
echoClient.SetAttribute("Interval", TimeValue(Seconds (1.0))) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
51 |
echoClient.SetAttribute("PacketSize", 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)) |
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
54 |
clientApps.Start(Seconds(2.0)) |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
55 |
clientApps.Stop(Seconds(10.0)) |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
56 |
|
7101
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
57 |
Simulator.Run() |
cbdd99081786
Make Python examples use new modular bindings
Mitch Watrous <watrous@u.washington.edu>
parents:
5369
diff
changeset
|
58 |
Simulator.Destroy() |
4138
9f4c2934473d
examples/first.cc ported to Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents:
diff
changeset
|
59 |