Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(50)

Unified Diff: examples/click/nsclick-simple-lan.cc

Issue 1690056: NS-3 Click Integration Code Review (Closed)
Patch Set: Full Patch Set Created 13 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/click/nsclick-routing-node2.click ('k') | examples/click/nsclick-simple-lan.click » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/click/nsclick-simple-lan.cc
===================================================================
new file mode 100644
--- /dev/null
+++ b/examples/click/nsclick-simple-lan.cc
@@ -0,0 +1,99 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/*
+ * 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
+ *
+ * Authors: Lalith Suresh <suresh.lalith@gmail.com>
+ */
+
+// Scenario:
+//
+// (Click) CSMA (non-Click)
+// A ================ B
+// (172.16.1.1) (172.16.1.2)
+// (eth0)
+//
+//
+
+#include "ns3/core-module.h"
+#include "ns3/common-module.h"
+#include "ns3/node-module.h"
+#include "ns3/helper-module.h"
+#include "ns3/log.h"
+
+using namespace ns3;
+
+void ReceivePacket (Ptr<Socket> socket)
+{
+ NS_LOG_UNCOND ("Received one packet!");
+}
+
+int main (int argc, char *argv[])
+{
+#ifdef NS3_CLICK
+ Time interPacketInterval = Seconds(1.0);
+
+ NodeContainer csmaNodes;
+ csmaNodes.Create (2);
+
+ // Setup CSMA channel between the nodes
+ CsmaHelper csma;
+ csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000)));
+ csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2)));
+ NetDeviceContainer csmaDevices = csma.Install (csmaNodes);
+
+ // Install normal internet stack on node B
+ InternetStackHelper internet;
+ internet.Install (csmaNodes.Get (1));
+
+ // Install Click on node A
+ ClickInternetStackHelper clickinternet;
+ clickinternet.SetClickFile (csmaNodes.Get (0), "examples/click/nsclick-simple-lan.click");
+ clickinternet.SetRoutingTableElement (csmaNodes.Get (0), "u/rt");
+ clickinternet.Install (csmaNodes.Get (0));
+
+ // Configure IP addresses for the nodes
+ Ipv4AddressHelper ipv4;
+ ipv4.SetBase ("172.16.1.0", "255.255.255.0");
+ ipv4.Assign (csmaDevices);
+
+ // Configure traffic application and sockets
+ Address LocalAddress (InetSocketAddress (Ipv4Address::GetAny (), 50000));
+ PacketSinkHelper packetSinkHelper ("ns3::TcpSocketFactory", LocalAddress);
+ ApplicationContainer recvapp = packetSinkHelper.Install (csmaNodes.Get (1));
+ recvapp.Start (Seconds (5.0));
+ recvapp.Stop (Seconds (10.0));
+
+ OnOffHelper onOffHelper ("ns3::TcpSocketFactory", Address ());
+ onOffHelper.SetAttribute ("OnTime", RandomVariableValue (ConstantVariable (1)));
+ onOffHelper.SetAttribute ("OffTime", RandomVariableValue (ConstantVariable (0)));
+
+ ApplicationContainer appcont;
+
+ AddressValue remoteAddress (InetSocketAddress (Ipv4Address ("172.16.1.2"), 50000));
+ onOffHelper.SetAttribute ("Remote", remoteAddress);
+ appcont.Add (onOffHelper.Install (csmaNodes.Get (0)));
+
+ appcont.Start (Seconds (5.0));
+ appcont.Stop (Seconds (10.0));
+
+ // For tracing
+ csma.EnablePcap ("nsclick-simple-lan", csmaDevices, false);
+
+ Simulator::Stop (Seconds(20.0));
+ Simulator::Run();
+ return 0;
+#else
+ NS_FATAL_ERROR ("Can't use ns-3-click without NSCLICK compiled in");
+#endif
+}
« no previous file with comments | « examples/click/nsclick-routing-node2.click ('k') | examples/click/nsclick-simple-lan.click » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b