A Discrete-Event Network Simulator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 University of Washington, 2012 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
20 // Network topology
21 //
22 #include <sys/socket.h>
23 #include <errno.h>
25 #include "ns3/core-module.h"
26 #include "ns3/network-module.h"
27 #include "ns3/internet-module.h"
28 #include "ns3/fd-net-device-module.h"
29 #include "ns3/applications-module.h"
31 using namespace ns3;
33 NS_LOG_COMPONENT_DEFINE ("DummyNetworkExample");
35 int
36 main (int argc, char *argv[])
37 {
38  NodeContainer nodes;
39  nodes.Create (2);
41  InternetStackHelper stack;
42  stack.Install (nodes);
45  NetDeviceContainer devices = fd.Install (nodes);
47  int sv[2];
48  if (socketpair (AF_UNIX, SOCK_DGRAM, 0, sv) < 0)
49  {
50  NS_FATAL_ERROR ("Error creating pipe=" << strerror (errno));
51  }
53  Ptr<NetDevice> d1 = devices.Get (0);
54  Ptr<FdNetDevice> device1 = d1->GetObject<FdNetDevice> ();
55  device1->SetFileDescriptor (sv[0]);
57  Ptr<NetDevice> d2 = devices.Get (1);
58  Ptr<FdNetDevice> device2 = d2->GetObject<FdNetDevice> ();
59  device2->SetFileDescriptor (sv[1]);
61  Ipv4AddressHelper addresses;
62  addresses.SetBase ("", "");
63  Ipv4InterfaceContainer interfaces = addresses.Assign (devices);
65  Ptr<V4Ping> app = CreateObject<V4Ping> ();
66  app->SetAttribute ("Remote", Ipv4AddressValue (interfaces.GetAddress (0)));
67  app->SetAttribute ("Verbose", BooleanValue (true));
68  nodes.Get (1)->AddApplication (app);
69  app->SetStartTime (Seconds (0.0));
70  app->SetStopTime (Seconds (4.0));
72  fd.EnablePcapAll ("dummy-network", false);
74  Simulator::Stop (Seconds (5.));
75  Simulator::Run ();
77 }
uint32_t AddApplication(Ptr< Application > application)
Definition: node.cc:148
void SetStopTime(Time stop)
Specify application stop time.
Definition: application.cc:74
virtual NetDeviceContainer Install(Ptr< Node > node) const
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Hold a bool native type.
Definition: boolean.h:38
holds a vector of std::pair of Ptr<Ipv4> and interface index.
void SetFileDescriptor(int fd)
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static void Run(void)
Definition: simulator.cc:157
Definition: log.h:122
aggregate IP/TCP/UDP functionality to existing Nodes.
build a set of FdNetDevice objects Normally we eschew multiple inheritance, however, the classes PcapUserHelperForDevice and AsciiTraceUserHelperForDevice are treated as "mixins". A mixin is a self-contained class that encapsulates a general attribute or a set of functionality that may be of interest to many other classes.
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
void EnablePcapAll(std::string prefix, bool promiscuous=false)
Enable pcap output on each device (which is of the appropriate type) in the set of all nodes created ...
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Definition: simulator.cc:121
keep track of a set of node pointers.
void Install(std::string nodeName) const
hold objects of type ns3::Ipv4Address
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
static void Stop(void)
Definition: simulator.cc:164
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:82
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:160
Ptr< T > GetObject(void) const
Definition: object.h:332
void SetStartTime(Time start)
Specify application start time.
Definition: application.cc:68
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="")
Set the base network number, network mask and base address.
Ipv4Address GetAddress(uint32_t i, uint32_t j=0) const