A Discrete-Event Network Simulator
API
realtime-dummy-network.cc
Go to the documentation of this file.
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
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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  */
19 
20 // Network topology
21 //
22 #include <sys/socket.h>
23 #include <errno.h>
24 
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/internet-apps-module.h"
30 
31 using namespace ns3;
32 
33 NS_LOG_COMPONENT_DEFINE ("RealtimeDummyNetworkExample");
34 
35 int
36 main (int argc, char *argv[])
37 {
39  cmd.Parse (argc, argv);
40 
41  GlobalValue::Bind ("SimulatorImplementationType", StringValue ("ns3::RealtimeSimulatorImpl"));
42  GlobalValue::Bind ("ChecksumEnabled", BooleanValue (true));
43 
45  nodes.Create (2);
46 
48  stack.Install (nodes);
49 
52 
53  int sv[2];
54  if (socketpair (AF_UNIX, SOCK_DGRAM, 0, sv) < 0)
55  {
56  NS_FATAL_ERROR ("Error creating pipe=" << strerror (errno));
57  }
58 
59  Ptr<NetDevice> d1 = devices.Get (0);
60  Ptr<FdNetDevice> device1 = d1->GetObject<FdNetDevice> ();
61  device1->SetFileDescriptor (sv[0]);
62 
63  Ptr<NetDevice> d2 = devices.Get (1);
64  Ptr<FdNetDevice> device2 = d2->GetObject<FdNetDevice> ();
65  device2->SetFileDescriptor (sv[1]);
66 
67  Ipv4AddressHelper addresses;
68  addresses.SetBase ("10.0.0.0", "255.255.255.0");
70 
71  Ptr<V4Ping> app = CreateObject<V4Ping> ();
72  app->SetAttribute ("Remote", Ipv4AddressValue (interfaces.GetAddress (0)));
73  app->SetAttribute ("Verbose", BooleanValue (true));
74  nodes.Get (1)->AddApplication (app);
75  app->SetStartTime (Seconds (0.0));
76  app->SetStopTime (Seconds (4.0));
77 
78  fd.EnablePcapAll ("realtime-dummy-network", false);
79 
80  Simulator::Stop (Seconds (5.));
81  Simulator::Run ();
83 }
void SetStopTime(Time stop)
Specify application stop time.
Definition: application.cc:75
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
AttributeValue implementation for Boolean.
Definition: boolean.h:36
holds a vector of std::pair of Ptr<Ipv4> and interface index.
void SetFileDescriptor(int fd)
Set the associated file descriptor.
Hold variables of type string.
Definition: string.h:41
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
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".
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
cmd
Definition: second.py:35
stack
Definition: first.py:34
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
nodes
Definition: first.py:25
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 Bind(std::string name, const AttributeValue &value)
Iterate over the set of GlobalValues until a matching name is found and then set its value with Globa...
Parse command-line arguments.
Definition: command-line.h:213
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
AttributeValue implementation for Ipv4Address.
Definition: ipv4-address.h:329
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
interfaces
Definition: first.py:41
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
a NetDevice to read/write network traffic from/into a file descriptor.
Definition: fd-net-device.h:84
devices
Definition: first.py:32
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
void SetStartTime(Time start)
Specify application start time.
Definition: application.cc:69
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.