2009-02-10 17:15:06 +00:00
|
|
|
# /*
|
|
|
|
|
# * This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# * it under the terms of the GNU General Public License version 2 as
|
|
|
|
|
# * published by the Free Software Foundation;
|
|
|
|
|
# *
|
|
|
|
|
# * This program is distributed in the hope that it will be useful,
|
|
|
|
|
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# * GNU General Public License for more details.
|
|
|
|
|
# *
|
|
|
|
|
# * You should have received a copy of the GNU General Public License
|
|
|
|
|
# * along with this program; if not, write to the Free Software
|
|
|
|
|
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
# */
|
|
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
import ns.applications
|
|
|
|
|
import ns.core
|
|
|
|
|
import ns.internet
|
|
|
|
|
import ns.network
|
|
|
|
|
import ns.point_to_point
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2020-02-02 17:00:30 +05:30
|
|
|
# // Default Network Topology
|
|
|
|
|
# //
|
|
|
|
|
# // 10.1.1.0
|
|
|
|
|
# // n0 -------------- n1
|
|
|
|
|
# // point-to-point
|
|
|
|
|
# //
|
|
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
ns.core.LogComponentEnable("UdpEchoClientApplication", ns.core.LOG_LEVEL_INFO)
|
|
|
|
|
ns.core.LogComponentEnable("UdpEchoServerApplication", ns.core.LOG_LEVEL_INFO)
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
nodes = ns.network.NodeContainer()
|
2009-02-10 17:15:06 +00:00
|
|
|
nodes.Create(2)
|
|
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
pointToPoint = ns.point_to_point.PointToPointHelper()
|
|
|
|
|
pointToPoint.SetDeviceAttribute("DataRate", ns.core.StringValue("5Mbps"))
|
|
|
|
|
pointToPoint.SetChannelAttribute("Delay", ns.core.StringValue("2ms"))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
devices = pointToPoint.Install(nodes)
|
|
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
stack = ns.internet.InternetStackHelper()
|
2009-02-10 17:15:06 +00:00
|
|
|
stack.Install(nodes)
|
|
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
address = ns.internet.Ipv4AddressHelper()
|
2014-10-15 07:38:06 -07:00
|
|
|
address.SetBase(ns.network.Ipv4Address("10.1.1.0"),
|
|
|
|
|
ns.network.Ipv4Mask("255.255.255.0"))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2014-10-15 07:38:06 -07:00
|
|
|
interfaces = address.Assign(devices)
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
echoServer = ns.applications.UdpEchoServerHelper(9)
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
serverApps = echoServer.Install(nodes.Get(1))
|
2011-05-02 17:17:09 -07:00
|
|
|
serverApps.Start(ns.core.Seconds(1.0))
|
|
|
|
|
serverApps.Stop(ns.core.Seconds(10.0))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
echoClient = ns.applications.UdpEchoClientHelper(interfaces.GetAddress(1), 9)
|
|
|
|
|
echoClient.SetAttribute("MaxPackets", ns.core.UintegerValue(1))
|
2014-10-15 07:38:06 -07:00
|
|
|
echoClient.SetAttribute("Interval", ns.core.TimeValue(ns.core.Seconds(1.0)))
|
2011-05-02 17:17:09 -07:00
|
|
|
echoClient.SetAttribute("PacketSize", ns.core.UintegerValue(1024))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
clientApps = echoClient.Install(nodes.Get(0))
|
2011-05-02 17:17:09 -07:00
|
|
|
clientApps.Start(ns.core.Seconds(2.0))
|
|
|
|
|
clientApps.Stop(ns.core.Seconds(10.0))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-05-02 17:17:09 -07:00
|
|
|
ns.core.Simulator.Run()
|
|
|
|
|
ns.core.Simulator.Destroy()
|
2009-02-10 17:15:06 +00:00
|
|
|
|