support for star network, example in tutorial
authorCraig Dowell <craigdo@ee.washington.edu>
Mon, 08 Oct 2007 20:51:21 -0700
changeset 1841 afa9089bcab4
parent 1840 f5bb4b608832
child 1842 a6b327e4b547
support for star network, example in tutorial
src/devices/point-to-point/point-to-point-ipv4-topology.cc
src/devices/point-to-point/point-to-point-ipv4-topology.h
src/devices/point-to-point/wscript
tutorial/tutorial-point-to-point.cc
tutorial/tutorial-star.cc
tutorial/wscript
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/point-to-point/point-to-point-ipv4-topology.cc	Mon Oct 08 20:51:21 2007 -0700
@@ -0,0 +1,73 @@
+/* -*- 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
+ */
+
+#include "ns3/assert.h"
+#include "ns3/log.h"
+#include "ns3/nstime.h"
+#include "ns3/internet-node.h"
+#include "ns3/ipv4-address.h"
+#include "ns3/ipv4.h"
+#include "ns3/queue.h"
+
+#include "point-to-point-channel.h"
+#include "point-to-point-net-device.h"
+#include "point-to-point-ipv4-topology.h"
+
+namespace ns3 {
+
+  Ptr<PointToPointChannel>
+PointToPointIpv4Topology::CreateChannel (
+  const DataRate& bps,
+  const Time& delay)
+{
+  return Create<PointToPointChannel> (bps, delay);
+}
+
+  uint32_t
+PointToPointIpv4Topology::AddNetDevice (
+  Ptr<Node> node,
+  Ptr<PointToPointChannel> channel)
+{
+  NS_ASSERT (channel->GetNDevices () <= 1);
+
+  Ptr<PointToPointNetDevice> nd = Create<PointToPointNetDevice> (node);
+
+  Ptr<Queue> q = Queue::CreateDefault ();
+  nd->AddQueue(q);
+  nd->Attach (channel);
+
+  return nd->GetIfIndex ();
+}
+
+  uint32_t
+PointToPointIpv4Topology::AddAddress (
+  Ptr<Node> node,
+  uint32_t netDeviceNumber,
+  Ipv4Address address,
+  Ipv4Mask mask)
+{
+  Ptr<NetDevice> nd = node->GetDevice(netDeviceNumber);
+  Ptr<Ipv4> ipv4 = node->QueryInterface<Ipv4> (Ipv4::iid);
+  uint32_t ifIndex = ipv4->AddInterface (nd);
+
+  ipv4->SetAddress (ifIndex, address);
+  ipv4->SetNetworkMask (ifIndex, mask);
+  ipv4->SetUp (ifIndex);
+
+  return ifIndex;
+}
+
+} // namespace ns3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/devices/point-to-point/point-to-point-ipv4-topology.h	Mon Oct 08 20:51:21 2007 -0700
@@ -0,0 +1,49 @@
+/* -*- 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
+ */
+
+#ifndef POINT_TO_POINT_IPV4_TOPOLOGY_H
+#define POINT_TO_POINT_IPV4_TOPOLOGY_H
+
+#include "ns3/ptr.h"
+
+namespace ns3 {
+
+class PointToPointChannel;
+class Node;
+class Ipv4Address;
+class Ipv4Mask;
+class DataRate;
+
+class PointToPointIpv4Topology {
+public:
+  static Ptr<PointToPointChannel> CreateChannel (
+    const DataRate& dataRate, const Time& delay);
+
+  static uint32_t AddNetDevice(
+    Ptr<Node> node,
+    Ptr<PointToPointChannel> channel);
+
+  static uint32_t AddAddress(
+    Ptr<Node> node,
+    uint32_t ndIndex,
+    Ipv4Address address,
+    Ipv4Mask mask);
+};
+
+} // namespace ns3
+
+#endif // POINT_TO_POINT_IPV4_TOPOLOGY_H
+
--- a/src/devices/point-to-point/wscript	Mon Oct 08 18:52:08 2007 -0700
+++ b/src/devices/point-to-point/wscript	Mon Oct 08 20:51:21 2007 -0700
@@ -7,11 +7,13 @@
         'point-to-point-net-device.cc',
         'point-to-point-channel.cc',
         'point-to-point-topology.cc',
+        'point-to-point-ipv4-topology.cc',
         ]
     headers = bld.create_obj('ns3header')
     headers.source = [
         'point-to-point-net-device.h',
         'point-to-point-channel.h',
         'point-to-point-topology.h',
+        'point-to-point-ipv4-topology.h',
         ]
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tutorial/tutorial-point-to-point.cc	Mon Oct 08 20:51:21 2007 -0700
@@ -0,0 +1,78 @@
+/* -*- 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
+ */
+
+#include "ns3/log.h"
+#include "ns3/ptr.h"
+#include "ns3/internet-node.h"
+#include "ns3/point-to-point-channel.h"
+#include "ns3/mac48-address.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/point-to-point-topology.h"
+#include "ns3/udp-echo-client.h"
+#include "ns3/udp-echo-server.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/ascii-trace.h"
+#include "ns3/pcap-trace.h"
+#include "ns3/global-route-manager.h"
+
+NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
+
+using namespace ns3;
+
+// Network topology
+//
+//                       point to point
+//                      +--------------+
+//                      |              |
+//                     n0             n1
+//
+int 
+main (int argc, char *argv[])
+{
+  LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
+
+  NS_LOG_INFO ("Point to Point Topology Simulation");
+
+  Ptr<Node> n0 = Create<InternetNode> ();
+  Ptr<Node> n1 = Create<InternetNode> ();
+
+  Ptr<PointToPointChannel> link = PointToPointTopology::AddPointToPointLink (
+    n0, n1, DataRate (38400), MilliSeconds (20));
+
+  PointToPointTopology::AddIpv4Addresses (link, n0, "10.1.1.1", 
+    n1, "10.1.1.2");
+
+  uint16_t port = 7;
+
+  Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.1.2", port, 
+    1, Seconds(1.), 1024);
+
+  Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port);
+
+  server->Start(Seconds(1.));
+  client->Start(Seconds(2.));
+
+  server->Stop (Seconds(10.));
+  client->Stop (Seconds(10.));
+
+  AsciiTrace asciitrace ("tutorial.tr");
+  asciitrace.TraceAllQueues ();
+  asciitrace.TraceAllNetDeviceRx ();
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tutorial/tutorial-star.cc	Mon Oct 08 20:51:21 2007 -0700
@@ -0,0 +1,176 @@
+/* -*- 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
+ */
+
+#include "ns3/log.h"
+#include "ns3/ptr.h"
+#include "ns3/internet-node.h"
+#include "ns3/point-to-point-channel.h"
+#include "ns3/mac48-address.h"
+#include "ns3/point-to-point-net-device.h"
+#include "ns3/point-to-point-ipv4-topology.h"
+#include "ns3/udp-echo-client.h"
+#include "ns3/udp-echo-server.h"
+#include "ns3/simulator.h"
+#include "ns3/nstime.h"
+#include "ns3/ascii-trace.h"
+#include "ns3/pcap-trace.h"
+#include "ns3/global-route-manager.h"
+
+NS_LOG_COMPONENT_DEFINE ("PointToPointSimulation");
+
+using namespace ns3;
+
+// Network topology
+//
+//                  n3    n2
+//                   |   /
+//                    | /
+//              n4 --- n0 --- n1
+//                    /  |
+//                   /    |
+//                  n5    n6
+
+int 
+main (int argc, char *argv[])
+{
+  LogComponentEnable ("PointToPointSimulation", LOG_LEVEL_INFO);
+
+  NS_LOG_INFO ("Point to Point Topology Simulation");
+
+  Ptr<Node> n0 = Create<InternetNode> ();
+  Ptr<Node> n1 = Create<InternetNode> ();
+  Ptr<Node> n2 = Create<InternetNode> ();
+  Ptr<Node> n3 = Create<InternetNode> ();
+  Ptr<Node> n4 = Create<InternetNode> ();
+  Ptr<Node> n5 = Create<InternetNode> ();
+  Ptr<Node> n6 = Create<InternetNode> ();
+
+  Ptr<PointToPointChannel> link01 = 
+    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
+    MilliSeconds (20));
+
+  uint32_t nd01 = PointToPointIpv4Topology::AddNetDevice (n0,
+    link01);
+
+  Ptr<PointToPointChannel> link02 = 
+    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
+    MilliSeconds (20));
+
+  uint32_t nd02 = PointToPointIpv4Topology::AddNetDevice (n0,
+    link02);
+
+  Ptr<PointToPointChannel> link03 = 
+    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
+    MilliSeconds (20));
+
+  uint32_t nd03 = PointToPointIpv4Topology::AddNetDevice (n0,
+    link03);
+
+  Ptr<PointToPointChannel> link04 = 
+    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
+    MilliSeconds (20));
+
+  uint32_t nd04 = PointToPointIpv4Topology::AddNetDevice (n0, 
+    link04);
+
+  Ptr<PointToPointChannel> link05 = 
+    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
+    MilliSeconds (20));
+
+  uint32_t nd05 = PointToPointIpv4Topology::AddNetDevice (n0,
+    link05);
+
+  Ptr<PointToPointChannel> link06 = 
+    PointToPointIpv4Topology::CreateChannel (DataRate (38400), 
+    MilliSeconds (20));
+
+  uint32_t nd06 = PointToPointIpv4Topology::AddNetDevice (n0, 
+    link06);
+
+  uint32_t nd1 = PointToPointIpv4Topology::AddNetDevice (n1, 
+    link01);
+
+  uint32_t nd2 = PointToPointIpv4Topology::AddNetDevice (n2, 
+    link02);
+
+  uint32_t nd3 = PointToPointIpv4Topology::AddNetDevice (n3, 
+    link03);
+
+  uint32_t nd4 = PointToPointIpv4Topology::AddNetDevice (n4, 
+    link04);
+
+  uint32_t nd5 = PointToPointIpv4Topology::AddNetDevice (n5, 
+    link05);
+
+  uint32_t nd6 = PointToPointIpv4Topology::AddNetDevice (n6, 
+    link06);
+
+  PointToPointIpv4Topology::AddAddress (n0, nd01, "10.1.1.1", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n1, nd1, "10.1.1.2", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n0, nd02, "10.1.2.1", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n2, nd2, "10.1.2.2", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n0, nd03, "10.1.3.1", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n3, nd3, "10.1.2.2", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n0, nd04, "10.1.4.1", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n4, nd4, "10.1.4.2", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n0, nd05, "10.1.5.1", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n5, nd5, "10.1.5.2", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n0, nd06, "10.1.6.1", 
+    "255.255.255.252");
+
+  PointToPointIpv4Topology::AddAddress (n6, nd6, "10.1.6.2", 
+    "255.255.255.252");
+
+  uint16_t port = 7;
+
+  Ptr<UdpEchoClient> client = Create<UdpEchoClient> (n0, "10.1.1.2", port, 
+    1, Seconds(1.), 1024);
+
+  Ptr<UdpEchoServer> server = Create<UdpEchoServer> (n1, port);
+
+  server->Start(Seconds(1.));
+  client->Start(Seconds(2.));
+
+  server->Stop (Seconds(10.));
+  client->Stop (Seconds(10.));
+
+  AsciiTrace asciitrace ("tutorial.tr");
+  asciitrace.TraceAllQueues ();
+  asciitrace.TraceAllNetDeviceRx ();
+
+  Simulator::Run ();
+  Simulator::Destroy ();
+}
--- a/tutorial/wscript	Mon Oct 08 18:52:08 2007 -0700
+++ b/tutorial/wscript	Mon Oct 08 20:51:21 2007 -0700
@@ -17,9 +17,17 @@
         ['core'])
     obj.source = 'tutorial-csma-echo-pcap-trace.cc'
 
-    obj = bld.create_ns3_program('tutorial-naive-dumbbell',
+    obj = bld.create_ns3_program('tutorial-point-to-point',
+        ['core'])
+    obj.source = 'tutorial-point-to-point.cc'
+
+    obj = bld.create_ns3_program('tutorial-star',
         ['core'])
-    obj.source = 'tutorial-naive-dumbbell.cc'
+    obj.source = 'tutorial-star.cc'
+
+    obj = bld.create_ns3_program('tutorial-linear-dumbbell',
+        ['core'])
+    obj.source = 'tutorial-linear-dumbbell.cc'
 
     obj = bld.create_ns3_program('testipv4',
         ['core'])