Hallo guide,
i am newbie, i am trying to write a Network Simulation with 8 notes in
order to analyze the thoughput of the sink note with callback function
but there are Error i don't know how can i correct the code. Help me
Please.Thanks you all.
sincerely
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include "ns3/ipv4-global-routing-helper.h"
#include "ns3/core-module.h"
#include "ns3/simulator-module.h"
#include "ns3/node-module.h"
#include "ns3/helper-module.h"
#include "ns3/olsr-helper.h"
#include "ns3/ipv4-static-routing-helper.h"
#include "ns3/ipv4-list-routing-helper.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE("SimpleGlobalRoutingExample");
/
*---------------------------------------------------------------------
*/
double m_TotalByte=0;
// trace the received Packet
void
Rx(Ptr<Packet const> _receivedpacket)
{
m_TotalByte += _receivedpacket->GetSize();
}
static void
thoughput()
{
double mbps = (((m_TotalByte*8)/1000000));
Simulator::Schedule(Seconds(1),&thoughput);
std::cout<<" Time : "<<Simulator::Now().GetSeconds()<<"\t"<< mbps
<<"Mbps"<< std::endl;
// NS_LOG_UNCOND(Simulator::Now().GetSeconds() << "\t" << mbps);
}
int
main(int argc,char *argv[]) {
#if 0
LogComponentEnable ("SimpleGlobalRoutingExample", LOG_LEVEL_INFO);
#endif
/*8 notes */
NS_LOG_INFO("Create nodes.");
NodeContainer c;
c.Create(8);
// build the Network Topology with 8 notes
NodeContainer n20 = NodeContainer(c.Get(2),c.Get(0));
NodeContainer n30 = NodeContainer(c.Get(3),c.Get(0));
NodeContainer n40 = NodeContainer(c.Get(4),c.Get(0));
NodeContainer n01 = NodeContainer(c.Get(0),c.Get(1));
NodeContainer n15 = NodeContainer(c.Get(1),c.Get(5));
NodeContainer n16 = NodeContainer(c.Get(1),c.Get(6));
NodeContainer n17 = NodeContainer(c.Get(1),c.Get(7));
/*
* (2*) (5*)
* \ /
* \ /
* (3*)--------(0*)--------------------------(1*)---------(6*)
* / \
* / \
* (4*) (7*)
*
*
* */
// Now add ip/tcp stack to all nodes.
InternetStackHelper internet;
internet.InstallAll ();
// create the channel without the Information about IP Address
NS_LOG_INFO("Create channels.");
PointToPointHelper p2p;
p2p.SetDeviceAttribute("DataRate",StringValue("5Mbps"));
p2p.SetChannelAttribute("Delay", StringValue("2ms"));
// Add of two NetDevices in den 2. and 4.5.7. note, that have the
same character
NetDeviceContainer nd20 =p2p.Install(n20);
NetDeviceContainer nd30 =p2p.Install(n40);
NetDeviceContainer nd15 =p2p.Install(n15);
NetDeviceContainer nd17 =p2p.Install(n17);
p2p.SetDeviceAttribute("DataRate",StringValue("500kbps"));
p2p.SetChannelAttribute("Delay",StringValue("5ms"));
/*
* (2*) (5*)
* \ /
* SetDeviceAttribute 5Mbps,
* SetChannelAttribute 2ms
* \ /
* (3*)--500kbps--(0*)--------------------------(1*)--500 kbps----
(6*)
* / \
*
* / \
* (4*) (7*)
*
*
* */
/******************* Add NetDevices in den 3. and 6.note
***********************/
NetDeviceContainer nd40 = p2p.Install(n30);
NetDeviceContainer nd16 = p2p.Install(n16);
/******************* configuration of the main link note 0 - note 1
*******************/
p2p.SetDeviceAttribute("DataRate",StringValue("3Mbps"));
p2p.SetChannelAttribute("Delay",StringValue("3ms"));
NetDeviceContainer nd01 = p2p.Install(n01);
// Add the new IP-Address in all the interfaces
NS_LOG_INFO("Assign IP Addresses.");
Ipv4AddressHelper ipv4;
ipv4.SetBase("10.1.1.0","255.255.255.0");
Ipv4InterfaceContainer interface_20 = ipv4.Assign(nd20);
ipv4.SetBase("10.1.2.0","255.255.255.0");
Ipv4InterfaceContainer interface_30 = ipv4.Assign(nd30);
ipv4.SetBase("10.1.3.0","255.255.255.0");
Ipv4InterfaceContainer interface_40 = ipv4.Assign(nd40);
ipv4.SetBase("10.1.4.0","255.255.255.0");
Ipv4InterfaceContainer interface_01 = ipv4.Assign(nd01);
ipv4.SetBase("10.1.5.0","255.255.255.0");
Ipv4InterfaceContainer interface_15 = ipv4.Assign(nd15);
ipv4.SetBase("10.1.6.0","255.255.255.0");
Ipv4InterfaceContainer interface_16 = ipv4.Assign(nd16);
ipv4.SetBase("10.1.7.0","255.255.255.0");
Ipv4InterfaceContainer interface_17 = ipv4.Assign(nd17);
/******************* UDP constant Bit Rate from note 2 to note 5
with Socket 15 ***********************/
/* create the Application for continuous UDP datagrams
* at Size of 210 bytes and data rate of 448 Kilobit per seconds
*
************************************************************************************************/
// and setup ip routing tables to get total ip-level connectivity.
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
NS_LOG_INFO("Create Applications");
//
// Create one udpServer applications on node 5.
//
uint16_t udpport = 4000;
UdpServerHelper server (udpport);
ApplicationContainer apps = server.Install (c.Get(5));
apps.Start (Seconds (1.0));
apps.Stop (Seconds (10.0));
//
// Create one UdpClient application to send UDP datagrams from
node 2 to
// node 5.
//
uint32_t MaxPacketSize = 210;
Time interPacketInterval = Seconds (0.00375);
uint32_t maxPacketCount = 320;
UdpClientHelper client (interface_20.GetAddress (2), udpport);
client.SetAttribute ("MaxPackets", UintegerValue
(maxPacketCount));
client.SetAttribute ("Interval", TimeValue
(interPacketInterval));
client.SetAttribute ("PacketSize", UintegerValue
(MaxPacketSize));
apps = client.Install (c.Get (2));
apps.Start (Seconds (2.0));
apps.Stop (Seconds (10.0));
/*
ApplicationContainer apps = onoff.Install(c.Get(2));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
// create Packet sink in order to receive Packet
PacketSinkHelper
sink("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),port));
apps = sink.Install(c.Get(5));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
*/
/************* discontinuous bit rate from note 3 to 6 with Socket
16 from time point 1.5 to 3*******************
create similar stream from note 3 to note 6 ,start point at 1.5.
Seconds to 3.Seconds */
uint16_t port = 9 ;
NS_LOG_INFO("Create UDP Applications");
OnOffHelper
onoff("ns3::UdpSocketFactory",InetSocketAddress(interface_16.GetAddress(0),port));
//OnOffApplication
onoff("ns3::UdpSocketFactory",InetSocketAddress(interface_16.GetAddress(0),port));
onoff.SetAttribute("OnTime",RandomVariableValue(ConstantVariable(1)));
onoff.SetAttribute("OffTime",RandomVariableValue(ConstantVariable(0)));
// Definition of PaketSize and Data Rate for the Application.
onoff.SetAttribute("Datarate",DataRateValue (DataRate ("448kb/
s")));
onoff.SetAttribute("PacketSize",UintegerValue (210));
apps = onoff.Install(c.Get(3));
apps.Start(Seconds(1.5));
apps.Stop(Seconds(3.0));
//create Packet sink in order to receive Packet
PacketSinkHelper
sink2("ns3::UdpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),port));
apps = sink2.Install(c.Get(6)); // access moment note
apps.Start(Seconds(1.5));
apps.Stop(Seconds(3.0));
/************** TCP Constant Bit Rate of note 4 to note 7 with
Socket 17 of time 1.0 to 10.0****************/
NS_LOG_INFO("Create TCP Applications");
uint16_t port2 = 10 ;
onoff.SetAttribute("Remote",AddressValue(InetSocketAddress(interface_17.GetAddress(0),port2)));
apps = onoff.Install(c.Get(4));
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
// create Packet Sink , in order to receive Packets
PacketSinkHelper
sink3("ns3::TcpSocketFactory",InetSocketAddress(Ipv4Address::GetAny(),port2));
apps = sink3.Install(c.Get(7)); // access now the note 7
apps.Start(Seconds(1.0));
apps.Stop(Seconds(10.0));
/***************************** Call back functions
************************************************/
/* Call back function for continuous UDP
*
* new Pointer for Data access at Socket Object is angelegt
*/
Ptr<Socket> ns3con_UdpSocket =
Socket::CreateSocket(c.Get(5),UdpSocketFactory::GetTypeId());
ns3con_UdpSocket->Bind();
/* Config::Connect("a path to match trace sources",the CB to connect
to the matching trace sources);
.AddTraceSource ("Rx", "A packet has been
received",MakeTraceSourceAccessor (&PacketSink::m_rxTrace))*/
Config::ConnectWithoutContext("/NodeList/5/ApplicationList/
5/$ns3::PacketSink/Rx",MakeCallback(&Rx));
thoughput();
//Simulator::ScheduleNow(ns3con_UdpSocket,interface_15,port);
//Simulator::ScheduleNow (&StartFlow, ns3con_UdpSocket,
interface_15.GetAddress (1), port);
/*
// Call back Function for discontinuous UDP
Ptr<Socket> ns3discon_UdpSocket =
Socket::CreateSocket(c.Get(6),UdpSocketFactory::GetTypeId());
Config::Connect()TraceConnectWithoutContext("CongestionWindow",MakeCallback(&thoughput));
// Callback Function for TCP
Ptr<Socket> ns3TcpSocket =
Socket::CreateSocket(c.Get(7),TcpSocketFactory::GetTypeId());
ns3TcpSocket-
>TraceConnectWithoutContext("CongestionWindow",MakeCallback(&thoughput));
*/
/************************** save simulation data in trace
file*******************************/
AsciiTraceHelper ascii;
p2p.EnableAsciiAll (ascii.CreateFileStream ("simple-3point-
to-3point.tr"));
p2p.EnablePcapAll ("simple-3point-to-3point");
Simulator::Stop(Seconds(10.0));
NS_LOG_INFO("Run Simulation.");
Simulator::Run();
Simulator::Destroy();
NS_LOG_INFO("Done .");
return 0;
}
--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.
Someone know where do I find it in ns3.10?
thanks
rodolfo
2011/2/18 rodolfo meneguette <rodm...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "ns-3-users" group.
> To post to this group, send email to ns-3-...@googlegroups.com.
> To unsubscribe from this group, send email to
> ns-3-users+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ns-3-users?hl=en.
>
>
--
Eng. Sergio Martínez Tornell
Universidad Politécnica de Valencia.
Spain