A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
dummy-network.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 University of Washington, 2012 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 */
7
8// Network topology
9//
10#include "ns3/core-module.h"
11#include "ns3/fd-net-device-module.h"
12#include "ns3/internet-apps-module.h"
13#include "ns3/internet-module.h"
14#include "ns3/network-module.h"
15
16#include <errno.h>
17#include <sys/socket.h>
18
19using namespace ns3;
20
21NS_LOG_COMPONENT_DEFINE("DummyNetworkExample");
22
23int
24main(int argc, char* argv[])
25{
26 CommandLine cmd(__FILE__);
27 cmd.Parse(argc, argv);
28
30 nodes.Create(2);
31
33 stack.Install(nodes);
34
37
38 int sv[2];
39 if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sv) < 0)
40 {
41 NS_FATAL_ERROR("Error creating pipe=" << strerror(errno));
42 }
43
44 Ptr<NetDevice> d1 = devices.Get(0);
45 Ptr<FdNetDevice> device1 = d1->GetObject<FdNetDevice>();
46 device1->SetFileDescriptor(sv[0]);
47
48 Ptr<NetDevice> d2 = devices.Get(1);
49 Ptr<FdNetDevice> device2 = d2->GetObject<FdNetDevice>();
50 device2->SetFileDescriptor(sv[1]);
51
52 Ipv4AddressHelper addresses;
53 addresses.SetBase("10.0.0.0", "255.255.255.0");
54 Ipv4InterfaceContainer interfaces = addresses.Assign(devices);
55
57 app->SetAttribute("Destination", AddressValue(interfaces.GetAddress(0)));
58 app->SetAttribute("VerboseMode", EnumValue(Ping::VerboseMode::VERBOSE));
59 nodes.Get(1)->AddApplication(app);
60 app->SetStartTime(Seconds(0.0));
61 app->SetStopTime(Seconds(4.0));
62
63 fd.EnablePcapAll("dummy-network", true);
64
65 // The next three lines will stop the simulator at time 5 seconds. Usually,
66 // it is sufficient to just call Simulator::Stop (Seconds (5)).
67 // However, in order to produce a clean valgrind output
68 // when running this example in our test suite (see issue #343), we
69 // first stop each device explicitly at time 5, and then wait one
70 // simulator timestep later (1 nanosecond by default) to call
71 // Simulator::Stop ().
72 device1->Stop(Seconds(5));
73 device2->Stop(Seconds(5));
74 Simulator::Stop(Seconds(5) + TimeStep(1));
77
78 return 0;
79}
Parse command-line arguments.
Hold variables of type enum.
Definition enum.h:52
build a set of FdNetDevice objects Normally we eschew multiple inheritance, however,...
virtual NetDeviceContainer Install(Ptr< Node > node) const
This method creates a FdNetDevice and associates it to a node.
a NetDevice to read/write network traffic from/into a file descriptor.
aggregate IP/TCP/UDP functionality to existing Nodes.
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
holds a vector of std::pair of Ptr<Ipv4> and interface index.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
uint32_t AddApplication(Ptr< Application > application)
Associate an Application to this Node.
Definition node.cc:153
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 ...
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
NodeContainer nodes
devices
Definition first.py:31
stack
Definition first.py:33
interfaces
Definition first.py:39
Every class exported by the ns3 library is enclosed in the ns3 namespace.