A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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/applications-module.h"
30
31
using namespace
ns3;
32
33
NS_LOG_COMPONENT_DEFINE
(
"DummyNetworkExample"
);
34
35
int
36
main
(
int
argc,
char
*argv[])
37
{
38
NodeContainer
nodes;
39
nodes.
Create
(2);
40
41
InternetStackHelper
stack;
42
stack.
Install
(nodes);
43
44
FdNetDeviceHelper
fd;
45
NetDeviceContainer
devices = fd.
Install
(nodes);
46
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
}
52
53
Ptr<NetDevice>
d1 = devices.
Get
(0);
54
Ptr<FdNetDevice>
device1 = d1->
GetObject
<
FdNetDevice
> ();
55
device1->
SetFileDescriptor
(sv[0]);
56
57
Ptr<NetDevice>
d2 = devices.
Get
(1);
58
Ptr<FdNetDevice>
device2 = d2->
GetObject
<
FdNetDevice
> ();
59
device2->
SetFileDescriptor
(sv[1]);
60
61
Ipv4AddressHelper
addresses;
62
addresses.
SetBase
(
"10.0.0.0"
,
"255.255.255.0"
);
63
Ipv4InterfaceContainer
interfaces = addresses.
Assign
(devices);
64
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));
71
72
fd.
EnablePcapAll
(
"dummy-network"
,
false
);
73
74
Simulator::Stop
(
Seconds
(5.));
75
Simulator::Run
();
76
Simulator::Destroy
();
77
}
src
fd-net-device
examples
dummy-network.cc
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2