Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void
  2. AodvExample::InstallApplications ()
  3. {
  4. //-------------------------------------tcp-------------------------------------------------
  5.  Config::SetDefault ("ns3::OnOffApplication::PacketSize", UintegerValue (512));
  6.   Config::SetDefault ("ns3::OnOffApplication::DataRate", StringValue ("2kb/s"));
  7.  
  8. // Create a packet sink on the star "hub" to receive these packets
  9.   NodeContainer serverNodeContainer(nodes.Get(2));
  10.   uint16_t port = 9;
  11.   Address sinkLocalAddress (InetSocketAddress (Ipv4Address::GetAny (), port));
  12.   PacketSinkHelper sinkHelper ("ns3::TcpSocketFactory", sinkLocalAddress);
  13.   ApplicationContainer sinkApp = sinkHelper.Install (serverNodeContainer);
  14.   sinkApp.Start (Seconds (1.0));
  15.   sinkApp.Stop (Seconds (100.0));
  16.  
  17. // Create the OnOff applications to send TCP to the server
  18.   OnOffHelper clientHelper ("ns3::TcpSocketFactory", Address ());
  19.   clientHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
  20.   clientHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
  21. ApplicationContainer clientApps;
  22. AddressValue remoteAddress
  23.        (InetSocketAddress (interfaces.GetAddress(2,0), port));
  24.       clientHelper.SetAttribute ("Remote", remoteAddress);
  25.       clientApps.Add (clientHelper.Install (nodes.Get (0)));
  26.   clientApps.Start (Seconds (2.0));
  27.   clientApps.Stop (Seconds (100.0));
  28.  
  29. //TypeId tid = TypeId::LookupByName ("ns3::TcpSocketFactory");
  30.  // Ptr<Socket> recvSink = Socket::CreateSocket (nodes.Get (0), tid);
  31.   //InetSocketAddress local = InetSocketAddress (Ipv4Address::GetAny (), port);
  32.  // recvSink->Bind (local);
  33. //recvSink->TraceConnectWithoutContext ("CongestionWindow", MakeCallback (&CwndChange));
  34.  
  35.  
  36. //-----------------------------------------------------------------------------------------
  37.   Ptr<Node> node = nodes.Get (1);
  38.   Ptr<MobilityModel> mob = node->GetObject<MobilityModel> ();
  39.   // Trace Received Packets
  40.   Config::ConnectWithoutContext("/NodeList/*/ApplicationList/*/$ns3::PacketSink/Rx", MakeCallback (&ReceivePacket));
  41.  
  42.  
  43.   // Trace changes to the congestion window
  44. //  Config::ConnectWithoutContext ("/NodeList/0/$ns3::TcpL4Protocol/SocketList/0/CongestionWindow", MakeCallback (&CwndTracer));
  45.  
  46.  Simulator::Schedule (Seconds (0), &MobilityModel::SetPosition, mob, Vector (1000, 0, 0));
  47.  
  48.  
  49.   Simulator::Schedule (Seconds (20), &MobilityModel::SetPosition, mob, Vector (100, 0, 0));
  50.  
  51.   Simulator::Schedule (Seconds (35), &MobilityModel::SetPosition, mob, Vector (2000, 0, 0));
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement