A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
first.py
Go to the documentation of this file.
1
#
2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License version 2 as
4
# published by the Free Software Foundation;
5
#
6
# This program is distributed in the hope that it will be useful,
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
# GNU General Public License for more details.
10
#
11
# You should have received a copy of the GNU General Public License
12
# along with this program; if not, write to the Free Software
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
#
15
16
try
:
17
from
ns
import
ns
18
except
ModuleNotFoundError:
19
raise
SystemExit(
20
"Error: ns3 Python module not found;"
21
" Python bindings may not be enabled"
22
" or your PYTHONPATH might not be properly configured"
23
)
24
25
# // Default Network Topology
26
# //
27
# // 10.1.1.0
28
# // n0 -------------- n1
29
# // point-to-point
30
# //
31
32
ns.LogComponentEnable(
"UdpEchoClientApplication"
, ns.LOG_LEVEL_INFO)
33
ns.LogComponentEnable(
"UdpEchoServerApplication"
, ns.LOG_LEVEL_INFO)
34
35
nodes = ns.NodeContainer()
36
nodes.Create(2)
37
38
pointToPoint = ns.PointToPointHelper()
39
pointToPoint.SetDeviceAttribute(
"DataRate"
, ns.StringValue(
"5Mbps"
))
40
pointToPoint.SetChannelAttribute(
"Delay"
, ns.StringValue(
"2ms"
))
41
42
devices = pointToPoint.Install(nodes)
43
44
stack = ns.InternetStackHelper()
45
stack.Install(nodes)
46
47
address = ns.Ipv4AddressHelper()
48
address.SetBase(ns.Ipv4Address(
"10.1.1.0"
), ns.Ipv4Mask(
"255.255.255.0"
))
49
50
interfaces = address.Assign(devices)
51
52
echoServer = ns.UdpEchoServerHelper(9)
53
54
serverApps = echoServer.Install(nodes.Get(1))
55
serverApps.Start(ns.Seconds(1.0))
56
serverApps.Stop(ns.Seconds(10.0))
57
58
address = interfaces.GetAddress(1).ConvertTo()
59
echoClient = ns.UdpEchoClientHelper(address, 9)
60
echoClient.SetAttribute(
"MaxPackets"
, ns.UintegerValue(1))
61
echoClient.SetAttribute(
"Interval"
, ns.TimeValue(ns.Seconds(1.0)))
62
echoClient.SetAttribute(
"PacketSize"
, ns.UintegerValue(1024))
63
64
clientApps = echoClient.Install(nodes.Get(0))
65
clientApps.Start(ns.Seconds(2.0))
66
clientApps.Stop(ns.Seconds(10.0))
67
68
ns.Simulator.Run()
69
ns.Simulator.Destroy()
examples
tutorial
first.py
Generated on Tue May 28 2024 23:33:50 for ns-3 by
1.9.6