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
nsclick-simple-lan.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* This program is free software; you can redistribute it and/or modify
4
* it under the terms of the GNU General Public License version 2 as
5
* published by the Free Software Foundation;
6
*
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU General Public License for more details.
11
*
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*
16
* Authors: Lalith Suresh <suresh.lalith@gmail.com>
17
*/
18
19
// Scenario:
20
//
21
// (Click) CSMA (non-Click)
22
// A ================ B
23
// (172.16.1.1) (172.16.1.2)
24
// (eth0)
25
//
26
//
27
28
#include "ns3/core-module.h"
29
#include "ns3/network-module.h"
30
#include "ns3/csma-module.h"
31
#include "ns3/internet-module.h"
32
#include "ns3/applications-module.h"
33
#include "ns3/click-internet-stack-helper.h"
34
#include "ns3/log.h"
35
36
using namespace
ns3;
37
38
void
ReceivePacket
(
Ptr<Socket>
socket)
39
{
40
NS_LOG_UNCOND
(
"Received one packet!"
);
41
}
42
43
int
main
(
int
argc,
char
*argv[])
44
{
45
#ifdef NS3_CLICK
46
NodeContainer
csmaNodes;
47
csmaNodes.
Create
(2);
48
49
// Setup CSMA channel between the nodes
50
CsmaHelper
csma;
51
csma.
SetChannelAttribute
(
"DataRate"
,
DataRateValue
(
DataRate
(5000000)));
52
csma.
SetChannelAttribute
(
"Delay"
,
TimeValue
(
MilliSeconds
(2)));
53
NetDeviceContainer
csmaDevices = csma.
Install
(csmaNodes);
54
55
// Install normal internet stack on node B
56
InternetStackHelper
internet;
57
internet.
Install
(csmaNodes.
Get
(1));
58
59
// Install Click on node A
60
ClickInternetStackHelper clickinternet;
61
clickinternet.SetClickFile (csmaNodes.
Get
(0),
"src/click/examples/nsclick-lan-single-interface.click"
);
62
clickinternet.SetRoutingTableElement (csmaNodes.
Get
(0),
"rt"
);
63
clickinternet.Install (csmaNodes.
Get
(0));
64
65
// Configure IP addresses for the nodes
66
Ipv4AddressHelper
ipv4;
67
ipv4.
SetBase
(
"172.16.1.0"
,
"255.255.255.0"
);
68
ipv4.
Assign
(csmaDevices);
69
70
// Configure traffic application and sockets
71
Address
LocalAddress (
InetSocketAddress
(
Ipv4Address::GetAny
(), 50000));
72
PacketSinkHelper
packetSinkHelper (
"ns3::TcpSocketFactory"
, LocalAddress);
73
ApplicationContainer
recvapp = packetSinkHelper.
Install
(csmaNodes.
Get
(1));
74
recvapp.
Start
(
Seconds
(5.0));
75
recvapp.
Stop
(
Seconds
(10.0));
76
77
OnOffHelper
onOffHelper (
"ns3::TcpSocketFactory"
,
Address
());
78
onOffHelper.
SetAttribute
(
"OnTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=1]"
));
79
onOffHelper.
SetAttribute
(
"OffTime"
,
StringValue
(
"ns3::ConstantRandomVariable[Constant=0]"
));
80
81
ApplicationContainer
appcont;
82
83
AddressValue
remoteAddress (
InetSocketAddress
(
Ipv4Address
(
"172.16.1.2"
), 50000));
84
onOffHelper.
SetAttribute
(
"Remote"
, remoteAddress);
85
appcont.
Add
(onOffHelper.
Install
(csmaNodes.
Get
(0)));
86
87
appcont.
Start
(
Seconds
(5.0));
88
appcont.
Stop
(
Seconds
(10.0));
89
90
// For tracing
91
csma.
EnablePcap
(
"nsclick-simple-lan"
, csmaDevices,
false
);
92
93
Simulator::Stop
(
Seconds
(20.0));
94
Simulator::Run
();
95
96
Simulator::Destroy
();
97
return
0;
98
#else
99
NS_FATAL_ERROR
(
"Can't use ns-3-click without NSCLICK compiled in"
);
100
#endif
101
}
src
click
examples
nsclick-simple-lan.cc
Generated on Tue Oct 9 2012 16:45:33 for ns-3 by
1.8.1.2