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-04-29 16:59:33 -07:00
|
|
|
from ns.applications import *
|
|
|
|
|
from ns.core import *
|
|
|
|
|
from ns.internet import *
|
|
|
|
|
from ns.network import *
|
|
|
|
|
from ns.point_to_point import *
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO)
|
|
|
|
|
LogComponentEnable("UdpEchoServerApplication", LOG_LEVEL_INFO)
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
nodes = NodeContainer()
|
2009-02-10 17:15:06 +00:00
|
|
|
nodes.Create(2)
|
|
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
pointToPoint = PointToPointHelper()
|
|
|
|
|
pointToPoint.SetDeviceAttribute("DataRate", StringValue("5Mbps"))
|
|
|
|
|
pointToPoint.SetChannelAttribute("Delay", StringValue("2ms"))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
devices = pointToPoint.Install(nodes)
|
|
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
stack = InternetStackHelper()
|
2009-02-10 17:15:06 +00:00
|
|
|
stack.Install(nodes)
|
|
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
address = Ipv4AddressHelper()
|
|
|
|
|
address.SetBase(Ipv4Address("10.1.1.0"), Ipv4Mask("255.255.255.0"))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
interfaces = address.Assign (devices);
|
|
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
echoServer = UdpEchoServerHelper(9)
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
serverApps = echoServer.Install(nodes.Get(1))
|
2011-04-29 16:59:33 -07:00
|
|
|
serverApps.Start(Seconds(1.0))
|
|
|
|
|
serverApps.Stop(Seconds(10.0))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
echoClient = UdpEchoClientHelper(interfaces.GetAddress(1), 9)
|
|
|
|
|
echoClient.SetAttribute("MaxPackets", UintegerValue(1))
|
|
|
|
|
echoClient.SetAttribute("Interval", TimeValue(Seconds (1.0)))
|
|
|
|
|
echoClient.SetAttribute("PacketSize", UintegerValue(1024))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
|
|
|
|
clientApps = echoClient.Install(nodes.Get(0))
|
2011-04-29 16:59:33 -07:00
|
|
|
clientApps.Start(Seconds(2.0))
|
|
|
|
|
clientApps.Stop(Seconds(10.0))
|
2009-02-10 17:15:06 +00:00
|
|
|
|
2011-04-29 16:59:33 -07:00
|
|
|
Simulator.Run()
|
|
|
|
|
Simulator.Destroy()
|
2009-02-10 17:15:06 +00:00
|
|
|
|