From 87cd21f1f87d5eb38504ebd0108c9b5b50f98f70 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Mon, 24 Sep 2007 18:54:14 +0100 Subject: [PATCH 1/2] Need to enable packet metadata early, else we trigger an assertion. --- utils/run-tests.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utils/run-tests.cc b/utils/run-tests.cc index 774e88c1f..f99f560c3 100644 --- a/utils/run-tests.cc +++ b/utils/run-tests.cc @@ -20,10 +20,13 @@ */ #include "ns3/test.h" +#include "ns3/packet-metadata.h" + int main (int argc, char *argv[]) { #ifdef RUN_SELF_TESTS + ns3::PacketMetadata::Enable (); ns3::TestManager::EnableVerbose (); bool success = ns3::TestManager::RunTests (); if (!success) From ac9d6181880b6dc69bb25cb5ec9f55844583976e Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Mon, 24 Sep 2007 13:28:27 -0700 Subject: [PATCH 2/2] add tutorial files --- tutorial/tutorial-1.cc | 91 ++++++++++++++++++++++++++++++++++++++++++ tutorial/wscript-1 | 10 +++++ 2 files changed, 101 insertions(+) create mode 100644 tutorial/tutorial-1.cc create mode 100644 tutorial/wscript-1 diff --git a/tutorial/tutorial-1.cc b/tutorial/tutorial-1.cc new file mode 100644 index 000000000..fdd60e921 --- /dev/null +++ b/tutorial/tutorial-1.cc @@ -0,0 +1,91 @@ +/* -*- 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/csma-channel.h" +#include "ns3/mac48-address.h" +#include "ns3/csma-net-device.h" +#include "ns3/csma-topology.h" +#include "ns3/csma-ipv4-topology.h" +#include "ns3/udp-echo-client.h" +#include "ns3/udp-echo-server.h" +#include "ns3/simulator.h" +#include "ns3/nstime.h" + +NS_LOG_COMPONENT_DEFINE ("UdpEchoSimulation"); + +using namespace ns3; + +int +main (int argc, char *argv[]) +{ + LogComponentEnable ("UdpEchoSimulation", LOG_LEVEL_INFO); + + NS_LOG_INFO ("UDP Echo Simulation"); + + Ptr n0 = Create (); + Ptr n1 = Create (); + Ptr n2 = Create (); + Ptr n3 = Create (); + + Ptr lan = + CsmaTopology::CreateCsmaChannel (DataRate (5000000), MilliSeconds (2)); + + uint32_t nd0 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n0, lan, + Mac48Address("08:00:2e:00:00:00")); + + uint32_t nd1 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n1, lan, + Mac48Address("08:00:2e:00:00:01")); + + uint32_t nd2 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n2, lan, + Mac48Address("08:00:2e:00:00:02")); + + uint32_t nd3 = CsmaIpv4Topology::AddIpv4CsmaNetDevice (n3, lan, + Mac48Address("08:00:2e:00:00:03")); + + CsmaIpv4Topology::AddIpv4Address (n0, nd0, Ipv4Address ("10.1.1.1"), + Ipv4Mask ("255.255.255.0")); + + CsmaIpv4Topology::AddIpv4Address (n1, nd1, Ipv4Address ("10.1.1.2"), + Ipv4Mask ("255.255.255.0")); + + CsmaIpv4Topology::AddIpv4Address (n2, nd2, Ipv4Address ("10.1.1.3"), + Ipv4Mask ("255.255.255.0")); + + CsmaIpv4Topology::AddIpv4Address (n3, nd3, Ipv4Address ("10.1.1.4"), + Ipv4Mask ("255.255.255.0")); + + uint32_t packetSize = 1024; + uint16_t port = 7; + uint32_t maxPacketCount = 1; + Time interPacketInterval = Seconds (1.); + + Ptr client = Create (n0, "10.1.1.2", port, + maxPacketCount, interPacketInterval, packetSize); + + Ptr server = Create (n1, port); + + server->Start(Seconds(1.)); + client->Start(Seconds(2.)); + + server->Stop (Seconds(10.)); + client->Stop (Seconds(10.)); + + Simulator::Run (); + Simulator::Destroy (); +} diff --git a/tutorial/wscript-1 b/tutorial/wscript-1 new file mode 100644 index 000000000..724d86fb7 --- /dev/null +++ b/tutorial/wscript-1 @@ -0,0 +1,10 @@ +## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- + +def build(bld): + obj = bld.create_ns3_program('hello-simulator', + ['core']) + obj.source = 'hello-simulator.cc' + + obj = bld.create_ns3_program('tutorial-1', + ['core']) + obj.source = 'tutorial-1.cc'