From 4e141d07c5fa3dc923f39abfa2373e75ef3a56bb Mon Sep 17 00:00:00 2001 From: Kiran S Date: Wed, 15 Nov 2017 20:07:03 +0530 Subject: [PATCH 1/3] Created internet-apps folder --- Internet-apps | 1 + 1 file changed, 1 insertion(+) create mode 100644 Internet-apps diff --git a/Internet-apps b/Internet-apps new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Internet-apps @@ -0,0 +1 @@ + From 9df8563cd695cc87283631a6f07dc85ecaa09e7f Mon Sep 17 00:00:00 2001 From: Kiran S Date: Wed, 15 Nov 2017 22:27:21 +0530 Subject: [PATCH 2/3] Delete Internet-apps --- Internet-apps | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Internet-apps diff --git a/Internet-apps b/Internet-apps deleted file mode 100644 index 8b13789..0000000 --- a/Internet-apps +++ /dev/null @@ -1 +0,0 @@ - From 46dbe9d7efbdb1e242a02d05b4b262a4f4a35549 Mon Sep 17 00:00:00 2001 From: Kiran S Date: Wed, 15 Nov 2017 21:28:25 +0530 Subject: [PATCH 3/3] Added python versions of csma-ping example and user-friendly ping(iping) example --- internet-apps/csma-ping.py | 65 ++++++++++++++++++++++++++ internet-apps/iping.py | 93 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 158 insertions(+) create mode 100644 internet-apps/csma-ping.py create mode 100644 internet-apps/iping.py diff --git a/internet-apps/csma-ping.py b/internet-apps/csma-ping.py new file mode 100644 index 0000000..e0d83fa --- /dev/null +++ b/internet-apps/csma-ping.py @@ -0,0 +1,65 @@ +import ns.applications +import ns.core +import ns.internet +import ns.network +import ns.point_to_point +import ns.csma +import ns.internet_apps + + +c = ns.network.NodeContainer() +c.Create(4) + + +csma = ns.csma.CsmaHelper() +csma.SetChannelAttribute("DataRate", ns.core.StringValue("100Mbps")) +csma.SetChannelAttribute("Delay", ns.core.TimeValue(ns.core.NanoSeconds(6560))) + +csma.SetDeviceAttribute ("EncapsulationMode", ns.core.StringValue ("Llc")); +devs = csma.Install (c); + +stack = ns.internet.InternetStackHelper() +stack.Install(c) + + +ip = ns.internet.Ipv4AddressHelper() +ip.SetBase(ns.network.Ipv4Address("10.1.1.0"), + ns.network.Ipv4Mask("255.255.255.0")) +addresses = ns.internet.Ipv4InterfaceContainer() + +addresses = ip.Assign(devs) + + +ns.core.Config.SetDefault ("ns3::Ipv4RawSocketImpl::Protocol", ns.core.StringValue ("2")) + +dst = ns.network.InetSocketAddress (addresses.GetAddress (3)) +onoff =ns.applications.OnOffHelper ("ns3::Ipv4RawSocketFactory", dst); +onoff.SetAttribute ("DataRate", ns.core.StringValue("15000")); +onoff.SetAttribute ("PacketSize", ns.core.UintegerValue (1200)); + +apps=ns.network.ApplicationContainer () +apps = onoff.Install (c.Get (0)); +apps.Start (ns.core.Seconds (1.0)); +apps.Stop (ns.core.Seconds (10.0)); + +sink = ns.applications.PacketSinkHelper ("ns3::Ipv4RawSocketFactory", dst) +apps = sink.Install (c.Get (3)); +apps.Start (ns.core.Seconds (0.0)); +apps.Stop (ns.core.Seconds (11.0)); + +ping =ns.internet_apps.V4PingHelper(addresses.GetAddress(2)); +pingers = ns.network.NodeContainer() +pingers.Add (c.Get (0)); +pingers.Add (c.Get (1)); +pingers.Add (c.Get (3)); +apps = ping.Install (pingers); +apps.Start (ns.core.Seconds (2.0)); +apps.Stop (ns.core.Seconds (5.0)); + + +csma.EnablePcapAll("csma-ping", False) + +ns.core.Simulator.Run() +ns.core.Simulator.Destroy() + + diff --git a/internet-apps/iping.py b/internet-apps/iping.py new file mode 100644 index 0000000..58bf2e8 --- /dev/null +++ b/internet-apps/iping.py @@ -0,0 +1,93 @@ +import ns.applications +import ns.core +import ns.internet +import ns.network +import ns.internet_apps +import ns.point_to_point +import sys + +cmd = ns.core.CommandLine() +cmd.c = 4294967295 +cmd.t = 0 +cmd.i = 1.0 +cmd.w = 15.0 +cmd.s = 56 +cmd.v = False +cmd.q = False + +cmd.AddValue("c", "Stops after sending specified number(count) of ECHO_REQUEST packets.") +cmd.AddValue("i", "Specify the interval seconds between sending each packet.") +cmd.AddValue("t", "Set the IP Time to Live.") +cmd.AddValue("w", "Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received.") +cmd.AddValue("s", "Specifies the number of data bytes to be sent.") +cmd.AddValue("v", "Verbose output.") +cmd.AddValue("q", "Quiet output. Nothing is displayed except the summary lines at startup time and when finished.") + +cmd.Parse(sys.argv) + +count = int(cmd.c) +ttl = int(cmd.t) +deadline = float(cmd.w) +packetsize = int(cmd.s) +interval = float(cmd.i) +verbose = bool(cmd.v) +quiet = bool(cmd.q) + +if count <=0: + print ("ping: bad number of packets to transmit.") + sys.exit(1) +if interval < 0: + print ("ping: bad timing interval.") + sys.exit(1) +if ttl < 0: + print ("ping: bad value.") + sys.exit(1) +if packetsize < 0: + print ("ping: illegal negetive packet size.") + sys.exit(1) +if interval < 0.2 and interval >= 0 : + print ("ping: cannot flood minimal interval allowed for user is 200ms.") + sys.exit(1) + +c = ns.network.NodeContainer() +c.Create (2) + +pointToPoint = ns.point_to_point.PointToPointHelper() +pointToPoint.SetDeviceAttribute ("DataRate", ns.core.StringValue ("5Mbps")) +pointToPoint.SetChannelAttribute ("Delay", ns.core.StringValue ("2ms")) + +devices = ns.network.NetDeviceContainer() +devices = pointToPoint.Install(c) + +address = ns.internet.Ipv4AddressHelper() +address.SetBase(ns.network.Ipv4Address("10.1.1.0"), ns.network.Ipv4Mask("255.255.255.0")) +stack = ns.internet.InternetStackHelper() +stack.Install(c) + +interfaces = ns.internet.Ipv4InterfaceContainer() +interfaces = address.Assign(devices) + +app = ns.internet_apps.V4Ping() + +app.SetAttribute ("Remote", ns.network.Ipv4AddressValue (interfaces.GetAddress(1))) +app.SetAttribute ("Verbose", ns.core.BooleanValue (verbose)) +app.SetAttribute ("Count", ns.core.UintegerValue (count)) +app.SetAttribute ("Ttl", ns.core.UintegerValue (ttl)) +app.SetAttribute ("Quiet", ns.core.BooleanValue (quiet) ) +app.SetAttribute ("Interval", ns.core.TimeValue (ns.core.Seconds (interval)) ) +app.SetAttribute ("Size", ns.core.UintegerValue (packetsize)) + +c.Get(0).AddApplication(app) + +app.SetStartTime(ns.core.Seconds(1.0)) +app.SetStopTime(ns.core.Seconds(1.0 + deadline)) + +pointToPoint.EnablePcapAll("iping", False) + +ns.core.Simulator.Run() +ns.core.Simulator.Destroy() + + + + +