author | Tom Henderson <tomh@tomh.org> |
Sat, 11 May 2013 13:27:05 -0700 | |
changeset 9754 | 66ac1ca6913c |
parent 9145 | 5752b425cdf5 |
permissions | -rw-r--r-- |
9145
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
2 |
/* |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
3 |
* This program is free software; you can redistribute it and/or modify |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
4 |
* it under the terms of the GNU General Public License version 2 as |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
5 |
* published by the Free Software Foundation; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
6 |
* |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
7 |
* This program is distributed in the hope that it will be useful, |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
10 |
* GNU General Public License for more details. |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
11 |
* |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
12 |
* You should have received a copy of the GNU General Public License |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
13 |
* along with this program; if not, write to the Free Software |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
14 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
15 |
*/ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
16 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
17 |
// Network topology |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
18 |
// |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
19 |
// n0 n1 |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
20 |
// | | |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
21 |
// ================= |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
22 |
// LAN |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
23 |
// |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
24 |
// - UDP flows from n0 to n1 |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
25 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
26 |
#include <fstream> |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
27 |
#include "ns3/core-module.h" |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
28 |
#include "ns3/csma-module.h" |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
29 |
#include "ns3/applications-module.h" |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
30 |
#include "ns3/internet-module.h" |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
31 |
#include "ns3/network-module.h" |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
32 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
33 |
using namespace ns3; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
34 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
35 |
NS_LOG_COMPONENT_DEFINE ("SocketOptionsIpv4"); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
36 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
37 |
void ReceivePacket (Ptr<Socket> socket) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
38 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
39 |
NS_LOG_INFO ("Received one packet!"); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
40 |
Ptr<Packet> packet = socket->Recv (); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
41 |
SocketIpTosTag tosTag; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
42 |
if (packet->RemovePacketTag (tosTag)) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
43 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
44 |
NS_LOG_INFO (" TOS = " << (uint32_t)tosTag.GetTos ()); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
45 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
46 |
SocketIpTtlTag ttlTag; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
47 |
if (packet->RemovePacketTag (ttlTag)) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
48 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
49 |
NS_LOG_INFO (" TTL = " << (uint32_t)ttlTag.GetTtl ()); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
50 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
51 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
52 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
53 |
static void SendPacket (Ptr<Socket> socket, uint32_t pktSize, |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
54 |
uint32_t pktCount, Time pktInterval ) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
55 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
56 |
if (pktCount > 0) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
57 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
58 |
socket->Send (Create<Packet> (pktSize)); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
59 |
Simulator::Schedule (pktInterval, &SendPacket, |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
60 |
socket, pktSize,pktCount - 1, pktInterval); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
61 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
62 |
else |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
63 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
64 |
socket->Close (); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
65 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
66 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
67 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
68 |
int |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
69 |
main (int argc, char *argv[]) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
70 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
71 |
// |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
72 |
// Allow the user to override any of the defaults and the above Bind() at |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
73 |
// run-time, via command-line arguments |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
74 |
// |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
75 |
uint32_t packetSize = 1024; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
76 |
uint32_t packetCount = 10; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
77 |
double packetInterval = 1.0; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
78 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
79 |
//Socket options for IPv4, currently TOS, TTL, RECVTOS, and RECVTTL |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
80 |
uint32_t ipTos = 0; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
81 |
bool ipRecvTos = true; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
82 |
uint32_t ipTtl = 0; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
83 |
bool ipRecvTtl = true; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
84 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
85 |
CommandLine cmd; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
86 |
cmd.AddValue ("PacketSize", "Packet size in bytes", packetSize); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
87 |
cmd.AddValue ("PacketCount", "Number of packets to send", packetCount); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
88 |
cmd.AddValue ("Interval", "Interval between packets", packetInterval); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
89 |
cmd.AddValue ("IP_TOS", "IP_TOS", ipTos); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
90 |
cmd.AddValue ("IP_RECVTOS", "IP_RECVTOS", ipRecvTos); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
91 |
cmd.AddValue ("IP_TTL", "IP_TTL", ipTtl); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
92 |
cmd.AddValue ("IP_RECVTTL", "IP_RECVTTL", ipRecvTtl); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
93 |
cmd.Parse (argc, argv); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
94 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
95 |
NS_LOG_INFO ("Create nodes."); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
96 |
NodeContainer n; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
97 |
n.Create (2); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
98 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
99 |
InternetStackHelper internet; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
100 |
internet.Install (n); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
101 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
102 |
Address serverAddress; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
103 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
104 |
NS_LOG_INFO ("Create channels."); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
105 |
CsmaHelper csma; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
106 |
csma.SetChannelAttribute ("DataRate", DataRateValue (DataRate (5000000))); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
107 |
csma.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (2))); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
108 |
csma.SetDeviceAttribute ("Mtu", UintegerValue (1400)); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
109 |
NetDeviceContainer d = csma.Install (n); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
110 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
111 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
112 |
NS_LOG_INFO ("Assign IP Addresses."); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
113 |
Ipv4AddressHelper ipv4; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
114 |
ipv4.SetBase ("10.1.1.0", "255.255.255.0"); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
115 |
Ipv4InterfaceContainer i = ipv4.Assign (d); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
116 |
serverAddress = Address(i.GetAddress (1)); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
117 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
118 |
NS_LOG_INFO ("Create sockets."); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
119 |
//Receiver socket on n1 |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
120 |
TypeId tid = TypeId::LookupByName ("ns3::UdpSocketFactory"); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
121 |
Ptr<Socket> recvSink = Socket::CreateSocket (n.Get (1), tid); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
122 |
InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), 4477); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
123 |
recvSink->SetIpRecvTos (ipRecvTos); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
124 |
recvSink->SetIpRecvTtl (ipRecvTtl); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
125 |
recvSink->Bind (local); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
126 |
recvSink->SetRecvCallback (MakeCallback (&ReceivePacket)); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
127 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
128 |
//Sender socket on n0 |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
129 |
Ptr<Socket> source = Socket::CreateSocket (n.Get (0), tid); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
130 |
InetSocketAddress remote = InetSocketAddress (i.GetAddress (1), 4477); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
131 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
132 |
//Set socket options, it is also possible to set the options after the socket has been created/connected. |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
133 |
if (ipTos > 0) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
134 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
135 |
source->SetIpTos (ipTos); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
136 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
137 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
138 |
if (ipTtl > 0) |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
139 |
{ |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
140 |
source->SetIpTtl (ipTtl); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
141 |
} |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
142 |
source->Connect (remote); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
143 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
144 |
AsciiTraceHelper ascii; |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
145 |
csma.EnableAsciiAll (ascii.CreateFileStream ("socket-options-ipv4.tr")); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
146 |
csma.EnablePcapAll ("socket-options-ipv4", false); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
147 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
148 |
//Schedule SendPacket |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
149 |
Time interPacketInterval = Seconds (packetInterval); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
150 |
Simulator::ScheduleWithContext (source->GetNode ()->GetId (), |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
151 |
Seconds (1.0), &SendPacket, |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
152 |
source, packetSize, packetCount, interPacketInterval); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
153 |
|
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
154 |
NS_LOG_INFO ("Run Simulation."); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
155 |
Simulator::Run (); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
156 |
Simulator::Destroy (); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
157 |
NS_LOG_INFO ("Done."); |
5752b425cdf5
Bug 1361 - Set TOS from Application level (sockets)
Daniel Lertpratchya <nikkipui@gmail.com>
parents:
diff
changeset
|
158 |
} |