thunder
unread,Sep 6, 2011, 10:49:19 AM9/6/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ns-3-users
hi all
I made a simulation on ns3 for wifi nodes (802.11b) sending TCP
packets and everything went fine and the results appeared in
wireshark
but wireshark gives me that there is a bad check sum why does that
happen
the following is my simulation script:
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* This program is free software; you can redistribute it and/or
modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/
#include "ns3/core-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/network-module.h"
#include "ns3/applications-module.h"
#include "ns3/wifi-module.h"
#include "ns3/mobility-module.h"
#include "ns3/csma-module.h"
#include "ns3/internet-module.h"
// Default Network Topology
//
// Wifi 10.1.1.0
//
// AP1 _
// *<-------* |
// | | |
// n2 n0 |
// \ Both links will operate at same freq.
// AP2 / The are both in the same network
// *<-------* |
// | | |
// n3 n1 |
// -
// *
// |
// n4
//
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("ThirdScriptExample");
int
main (int argc, char *argv[])
{
uint32_t nWifi = 3;
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi);
NodeContainer wifiApNodes;
wifiApNodes.Create(2);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi;
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
wifi.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
"DataMode",StringValue
("DsssRate1Mbps"),
"ControlMode",StringValue
("DsssRate1Mbps"));
NqosWifiMacHelper mac = NqosWifiMacHelper::Default ();
Ssid ssid = Ssid ("ns-3-ssid");
mac.SetType ("ns3::StaWifiMac",
"Ssid", SsidValue (ssid),
"ActiveProbing", BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType ("ns3::ApWifiMac",
"Ssid", SsidValue (ssid));
NetDeviceContainer apDevices;
apDevices = wifi.Install (phy, mac, wifiApNodes);
NetDeviceContainer allDevices;
allDevices.Add(apDevices);
allDevices.Add(staDevices);
MobilityHelper mobility;
mobility.SetPositionAllocator ("ns3::GridPositionAllocator",
"MinX", DoubleValue (0.0),
"MinY", DoubleValue (0.0),
"DeltaX", DoubleValue (5.0),
"DeltaY", DoubleValue (10.0),
"GridWidth", UintegerValue (3),
"LayoutType", StringValue
("RowFirst"));
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiStaNodes);
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
mobility.Install (wifiApNodes);
InternetStackHelper stack;
stack.Install (wifiApNodes);
stack.Install (wifiStaNodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer wifiInterfaces;
wifiInterfaces = address.Assign (allDevices);
//
// Create a BulkSendApplication and install it on node 0
//
uint16_t port = 5000;
DataRate dataRate1 ("1Mb/s");
OnOffHelper onOff ("ns3::TcpSocketFactory", Address
(InetSocketAddress (wifiInterfaces.GetAddress (2), port)));
onOff.SetAttribute ("DataRate", DataRateValue (dataRate1));
//onOff.SetAttribute ("OnTime", RandomVariableValue
(ConstantVariable (0.01)));
//onOff.SetAttribute ("OffTime", RandomVariableValue
(ConstantVariable (10)));
onOff.SetAttribute ("PacketSize", UintegerValue (50));
ApplicationContainer staApps = onOff.Install (wifiApNodes.Get(0));
//staApps.Start (Seconds (1.0));
//staApps.Stop (Seconds (10.0));
////DataRate dataRate2 ("1Mb/s");
////OnOffHelper onOff2 ("ns3::TcpSocketFactory", Address
(InetSocketAddress (wifiInterfaces.GetAddress (3), port)));
////onOff2.SetAttribute ("DataRate", DataRateValue (dataRate2));
//onOff2.SetAttribute ("OnTime", RandomVariableValue
(ConstantVariable (0.01)));
//onOff2.SetAttribute ("OffTime", RandomVariableValue
(ConstantVariable (10)));
////onOff2.SetAttribute ("PacketSize", UintegerValue (50));
////ApplicationContainer staApps2 = onOff2.Install
(wifiApNodes.Get(1));
//staApps2.Start (Seconds (1.0));
//staApps2.Stop (Seconds (10.0));
for (int i=0; i<10; i++)
{
staApps.Start (Seconds (i));
staApps.Stop (Seconds (i));
ApplicationContainer staApps = onOff.Install (wifiApNodes.Get(0));
};
phy.SetPcapDataLinkType(YansWifiPhyHelper::DLT_IEEE802_11_RADIO);
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
Simulator::Stop (Seconds (10.0));
phy.EnablePcap ("third", apDevices.Get(0));
phy.EnablePcap ("third", apDevices.Get(1));
phy.EnablePcap ("third", staDevices.Get(0));
phy.EnablePcap ("third", staDevices.Get(1));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}