merge with HEAD
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue Jun 02 19:46:01 2009 +0200 (8 months ago)
changeset 44881faf35545dfd
parent 4486 e12cbd513b47
parent 4487 0d67f380c764
child 4489 b322b179c5f6
child 4502 07d34c0d8d18
merge with HEAD
src/common/packet.cc
     1.1 --- a/examples/stats/wifi-example-apps.cc	Tue Jun 02 19:40:05 2009 +0200
     1.2 +++ b/examples/stats/wifi-example-apps.cc	Tue Jun 02 19:46:01 2009 +0200
     1.3 @@ -39,7 +39,7 @@
     1.4  
     1.5  using namespace ns3;
     1.6  
     1.7 -NS_LOG_COMPONENT_DEFINE ("WiFiThroughputApps");
     1.8 +NS_LOG_COMPONENT_DEFINE ("WiFiDistanceApps");
     1.9  
    1.10  TypeId
    1.11  Sender::GetTypeId(void)
    1.12 @@ -47,26 +47,26 @@
    1.13    static TypeId tid = TypeId ("Sender")
    1.14      .SetParent<Application> ()
    1.15      .AddConstructor<Sender> ()
    1.16 -    .AddAttribute ("PacketSize", "The size of packets transmitted [Bytes].",
    1.17 +    .AddAttribute ("PacketSize", "The size of packets transmitted.",
    1.18                     UintegerValue(64),
    1.19                     MakeUintegerAccessor(&Sender::m_pktSize),
    1.20                     MakeUintegerChecker<uint32_t>(1))
    1.21 -    .AddAttribute ("DataRate", "The data rate in on state.",
    1.22 -                   DataRateValue (DataRate ("500kb/s")),
    1.23 -                   MakeDataRateAccessor (&Sender::m_cbrRate),
    1.24 -                   MakeDataRateChecker ())
    1.25 -    .AddAttribute ("Destination", "Target host address.",
    1.26 -                   Ipv4AddressValue("255.255.255.255"),
    1.27 -                   MakeIpv4AddressAccessor(&Sender::m_destAddr),
    1.28 -                   MakeIpv4AddressChecker())
    1.29 -    .AddAttribute ("Port", "Destination app port.",
    1.30 -                   UintegerValue(1603),
    1.31 -                   MakeUintegerAccessor(&Sender::m_destPort),
    1.32 -                   MakeUintegerChecker<uint32_t>())
    1.33 -    .AddAttribute ("NumPackets", "Total number of packets to send.",
    1.34 -                   UintegerValue(30),
    1.35 -                   MakeUintegerAccessor(&Sender::m_numPkts),
    1.36 -                   MakeUintegerChecker<uint32_t>(1))
    1.37 +    .AddAttribute("Destination", "Target host address.",
    1.38 +                  Ipv4AddressValue("255.255.255.255"),
    1.39 +                  MakeIpv4AddressAccessor(&Sender::m_destAddr),
    1.40 +                  MakeIpv4AddressChecker())
    1.41 +    .AddAttribute("Port", "Destination app port.",
    1.42 +                  UintegerValue(1603),
    1.43 +                  MakeUintegerAccessor(&Sender::m_destPort),
    1.44 +                  MakeUintegerChecker<uint32_t>())
    1.45 +    .AddAttribute("NumPackets", "Total number of packets to send.",
    1.46 +                  UintegerValue(30),
    1.47 +                  MakeUintegerAccessor(&Sender::m_numPkts),
    1.48 +                  MakeUintegerChecker<uint32_t>(1))
    1.49 +    .AddAttribute ("Interval", "Delay between transmissions.",
    1.50 +                   RandomVariableValue(ConstantVariable(0.5)),
    1.51 +                   MakeRandomVariableAccessor(&Sender::m_interval),
    1.52 +                   MakeRandomVariableChecker())
    1.53      .AddTraceSource ("Tx", "A new packet is created and is sent",
    1.54                       MakeTraceSourceAccessor (&Sender::m_txTrace))
    1.55      ;
    1.56 @@ -105,7 +105,7 @@
    1.57        m_socket = socketFactory->CreateSocket ();
    1.58        m_socket->Bind ();
    1.59    }
    1.60 -  
    1.61 +
    1.62    m_count = 0;
    1.63  
    1.64    Simulator::Cancel(m_sendEvent);
    1.65 @@ -124,13 +124,8 @@
    1.66  void Sender::SendPacket()
    1.67  {
    1.68    // NS_LOG_FUNCTION_NOARGS ();
    1.69 -  uint32_t bits = m_pktSize * 8;
    1.70 -  
    1.71 -  NS_LOG_LOGIC ("bits = " << bits);
    1.72 -  nextTime = Time(Seconds (bits / static_cast<double>(m_cbrRate.GetBitRate()))); // Time till next packet
    1.73 -  
    1.74 -  NS_LOG_UNCOND("Sending packet at " << Simulator::Now() << " to " <<
    1.75 -              m_destAddr << " -- Time Interval is: " << nextTime);
    1.76 +  NS_LOG_INFO("Sending packet at " << Simulator::Now() << " to " <<
    1.77 +              m_destAddr);
    1.78  
    1.79    Ptr<Packet> packet = Create<Packet>(m_pktSize);
    1.80  
    1.81 @@ -145,11 +140,11 @@
    1.82    // Report the event to the trace.
    1.83    m_txTrace(packet);
    1.84  
    1.85 -  if (++m_count < m_numPkts) {    
    1.86 -    m_sendEvent = Simulator::Schedule(nextTime,
    1.87 +  if (++m_count < m_numPkts) {
    1.88 +    m_sendEvent = Simulator::Schedule(Seconds(m_interval.GetValue()),
    1.89                                        &Sender::SendPacket, this);
    1.90    }
    1.91 -  
    1.92 +
    1.93    // end Sender::SendPacket
    1.94  }
    1.95  
    1.96 @@ -255,17 +250,13 @@
    1.97      }
    1.98  
    1.99      TimestampTag timestamp;
   1.100 -    if( packet->FindFirstMatchingTag(timestamp) ) {
   1.101 -      Time tx = timestamp.GetTimestamp();
   1.102 -      
   1.103 -      if (m_delay != 0) {
   1.104 -        m_delay->Update(Simulator::Now() - tx);
   1.105 -      }
   1.106 +    packet->FindFirstMatchingTag(timestamp);
   1.107 +    Time tx = timestamp.GetTimestamp();
   1.108 +
   1.109 +    if (m_delay != 0) {
   1.110 +      m_delay->Update(Simulator::Now() - tx);
   1.111      }
   1.112 -    else {
   1.113 -      NS_LOG_UNCOND ("** missing time tag **");
   1.114 -    }
   1.115 -    
   1.116 +
   1.117      if (m_calc != 0) {
   1.118        m_calc->Update();
   1.119      }
     2.1 --- a/examples/stats/wifi-example-apps.h	Tue Jun 02 19:40:05 2009 +0200
     2.2 +++ b/examples/stats/wifi-example-apps.h	Tue Jun 02 19:46:01 2009 +0200
     2.3 @@ -55,10 +55,9 @@
     2.4    uint32_t        m_pktSize;
     2.5    Ipv4Address     m_destAddr;
     2.6    uint32_t        m_destPort;
     2.7 +  RandomVariable  m_interval;
     2.8    uint32_t        m_numPkts;
     2.9 -  DataRate        m_cbrRate;      // Rate that data is generated
    2.10 -  Time            nextTime;       // Time till next packet
    2.11 -  
    2.12 +
    2.13    Ptr<Socket>     m_socket;
    2.14    EventId         m_sendEvent;
    2.15  
     3.1 --- a/examples/stats/wifi-example-sim.cc	Tue Jun 02 19:40:05 2009 +0200
     3.2 +++ b/examples/stats/wifi-example-sim.cc	Tue Jun 02 19:46:01 2009 +0200
     3.3 @@ -48,7 +48,7 @@
     3.4  using namespace ns3;
     3.5  using namespace std;
     3.6  
     3.7 -NS_LOG_COMPONENT_DEFINE ("WiFiThroughputExperiment");
     3.8 +NS_LOG_COMPONENT_DEFINE ("WiFiDistanceExperiment");
     3.9  
    3.10  
    3.11  
    3.12 @@ -73,14 +73,11 @@
    3.13    double distance = 50.0;
    3.14    string format("omnet");
    3.15  
    3.16 -  string experiment("wifi-throughput-test");
    3.17 +  string experiment("wifi-distance-test");
    3.18    string strategy("wifi-default");
    3.19    string input;
    3.20    string runID;
    3.21 -  int nStas = 2;
    3.22 -  
    3.23 -  //LogComponentEnableAll(LOG_LEVEL_ALL);
    3.24 -  
    3.25 +
    3.26    {
    3.27      stringstream sstr;
    3.28      sstr << "run-" << time(NULL);
    3.29 @@ -126,49 +123,25 @@
    3.30    //-- Create nodes and network stacks
    3.31    //--------------------------------------------
    3.32    NS_LOG_INFO("Creating nodes.");
    3.33 -  NodeContainer stas;
    3.34 -  NodeContainer ap;
    3.35 -  NetDeviceContainer apDev;
    3.36 -  NetDeviceContainer stasDev;
    3.37 -  Ipv4InterfaceContainer staInterface;
    3.38 -  Ipv4InterfaceContainer apInterface;
    3.39 +  NodeContainer nodes;
    3.40 +  nodes.Create(2);
    3.41  
    3.42 -  Ssid ssid = Ssid ( "wifi-default" );
    3.43 -  
    3.44 -  ap.Create(1);
    3.45 -  stas.Create(nStas);
    3.46 -  
    3.47 +  NS_LOG_INFO("Installing WiFi and Internet stack.");
    3.48 +  WifiHelper wifi = WifiHelper::Default ();
    3.49 +  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
    3.50 +  wifiMac.SetType ("ns3::AdhocWifiMac");
    3.51 +  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
    3.52    YansWifiChannelHelper wifiChannel = YansWifiChannelHelper::Default ();
    3.53 -  YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
    3.54    wifiPhy.SetChannel (wifiChannel.Create ());
    3.55 -  NqosWifiMacHelper wifiMac = NqosWifiMacHelper::Default ();
    3.56 -  WifiHelper wifi = WifiHelper::Default ();
    3.57 +  NetDeviceContainer nodeDevices = wifi.Install(wifiPhy, wifiMac, nodes);
    3.58  
    3.59    InternetStackHelper internet;
    3.60 -  internet.Install(NodeContainer(stas,ap));
    3.61 +  internet.Install(nodes);
    3.62    Ipv4AddressHelper ipAddrs;
    3.63    ipAddrs.SetBase("192.168.0.0", "255.255.255.0");
    3.64 +  ipAddrs.Assign(nodeDevices);
    3.65  
    3.66 -  
    3.67 -  NS_LOG_INFO("Installing WiFi and Internet stack on AP.");
    3.68 -  // wifiMac.SetType ("ns3::AdhocWifiMac");
    3.69 -  wifiMac.SetType ("ns3::NqapWifiMac",
    3.70 -                   "Ssid", SsidValue (ssid),
    3.71 -                   "BeaconGeneration", BooleanValue (true),
    3.72 -                   "BeaconInterval", TimeValue (Seconds (2.5)));
    3.73 -  apDev = wifi.Install(wifiPhy, wifiMac, ap);
    3.74 -  apInterface = ipAddrs.Assign(apDev);
    3.75 -  
    3.76 -  
    3.77 -  NS_LOG_INFO("Installing WiFi and Internet stack on nodes.");
    3.78 -  WifiHelper wifiNodes = WifiHelper::Default ();
    3.79 -  NqosWifiMacHelper wifiMacNodes = NqosWifiMacHelper::Default ();
    3.80 -  //wifiMac.SetType ("ns3::AdhocWifiMac");
    3.81 -  wifiMac.SetType ("ns3::NqstaWifiMac",
    3.82 -                   "Ssid", SsidValue (ssid),
    3.83 -                   "ActiveProbing", BooleanValue (false));
    3.84 -  stasDev = wifi.Install(wifiPhy, wifiMac, stas);
    3.85 -  staInterface = ipAddrs.Assign(stasDev);
    3.86 +
    3.87  
    3.88  
    3.89    //------------------------------------------------------------
    3.90 @@ -181,7 +154,7 @@
    3.91    positionAlloc->Add(Vector(0.0, 0.0, 0.0));
    3.92    positionAlloc->Add(Vector(0.0, distance, 0.0));
    3.93    mobility.SetPositionAllocator(positionAlloc);
    3.94 -  mobility.Install(NodeContainer(stas,ap));
    3.95 +  mobility.Install(nodes);
    3.96  
    3.97  
    3.98  
    3.99 @@ -190,22 +163,16 @@
   3.100    //-- Create a custom traffic source and sink
   3.101    //--------------------------------------------
   3.102    NS_LOG_INFO ("Create traffic source & sink.");
   3.103 -  Ptr<Node> appSink = NodeList::GetNode(0);  
   3.104 +  Ptr<Node> appSource = NodeList::GetNode(0);  
   3.105 +  Ptr<Sender> sender = CreateObject<Sender>();
   3.106 +  appSource->AddApplication(sender);
   3.107 +  sender->Start(Seconds(1));
   3.108 +
   3.109 +  Ptr<Node> appSink = NodeList::GetNode(1);  
   3.110    Ptr<Receiver> receiver = CreateObject<Receiver>();
   3.111    appSink->AddApplication(receiver);
   3.112    receiver->Start(Seconds(0));
   3.113 -  
   3.114 -  for( int i=0; i<nStas; i++ ) {
   3.115 -    Ptr<Node> appSource = NodeList::GetNode(i+1);  
   3.116 -    Ptr<Sender> sender = CreateObject<Sender>();
   3.117 -    sender->SetAttribute ("Destination", Ipv4AddressValue(apInterface.GetAddress(0)));
   3.118 -    sender->SetAttribute ("DataRate", DataRateValue (DataRate ("1kbps")) );
   3.119 -    sender->SetAttribute ("PacketSize", UintegerValue(1000));
   3.120 -    sender->SetAttribute ("NumPackets", UintegerValue(1000));
   3.121 -    
   3.122 -    appSource->AddApplication(sender);
   3.123 -    sender->Start(Seconds(1));
   3.124 -  }
   3.125 +
   3.126    //  Config::Set("/NodeList/*/ApplicationList/*/$Sender/Destination",
   3.127    //              Ipv4AddressValue("192.168.0.2"));
   3.128  
   3.129 @@ -231,36 +198,26 @@
   3.130    // are triggered by the trace signal generated by the WiFi MAC model
   3.131    // object.  Here we connect the counter to the signal via the simple
   3.132    // TxCallback() glue function defined above.
   3.133 -  Ptr<PacketCounterCalculator> totalTx = CreateObject<PacketCounterCalculator>();
   3.134 -  totalTx->SetKey("wifiMac-tx-packets");
   3.135 -  Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTx",
   3.136 -                  MakeCallback(&PacketCounterCalculator::PacketUpdate, totalTx));
   3.137 +  Ptr<CounterCalculator<uint32_t> > totalTx =
   3.138 +    CreateObject<CounterCalculator<uint32_t> >();
   3.139 +  totalTx->SetKey("wifi-tx-frames");
   3.140 +  Config::Connect("/NodeList/0/DeviceList/*/$ns3::WifiNetDevice/Tx",
   3.141 +                  MakeBoundCallback(&TxCallback, totalTx));
   3.142    data.AddDataCalculator(totalTx);
   3.143  
   3.144 -  Ptr<PacketCounterCalculator> totalTxDrop = CreateObject<PacketCounterCalculator>();
   3.145 -  totalTxDrop->SetKey("wifiMac-txDrop-packets");
   3.146 -  Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacTxDrop",
   3.147 -                  MakeCallback(&PacketCounterCalculator::PacketUpdate, totalTxDrop));
   3.148 -  data.AddDataCalculator(totalTxDrop);
   3.149 -
   3.150 -  
   3.151    // This is similar, but creates a counter to track how many frames
   3.152    // are received.  Instead of our own glue function, this uses a
   3.153    // method of an adapter class to connect a counter directly to the
   3.154    // trace signal generated by the WiFi MAC.
   3.155 -  Ptr<PacketCounterCalculator> totalRx = CreateObject<PacketCounterCalculator>();
   3.156 -  totalRx->SetKey("wifiMac-rx-packets");
   3.157 -  Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRx",
   3.158 -                  MakeCallback(&PacketCounterCalculator::PacketUpdate, totalRx));
   3.159 +  Ptr<PacketCounterCalculator> totalRx =
   3.160 +    CreateObject<PacketCounterCalculator>();
   3.161 +  totalRx->SetKey("wifi-rx-frames");
   3.162 +  Config::Connect("/NodeList/1/DeviceList/*/$ns3::WifiNetDevice/Rx",
   3.163 +                  MakeCallback(&PacketCounterCalculator::FrameUpdate,
   3.164 +                                    totalRx));
   3.165    data.AddDataCalculator(totalRx);
   3.166 -  
   3.167 -  Ptr<PacketCounterCalculator> totalRxDrop = CreateObject<PacketCounterCalculator>();
   3.168 -  totalRxDrop->SetKey("wifiMac-rxDrop-packets");
   3.169 -  Config::Connect("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Mac/MacRxDrop",
   3.170 -                  MakeCallback(&PacketCounterCalculator::PacketUpdate, totalRxDrop));
   3.171 -  data.AddDataCalculator(totalRxDrop);
   3.172 -  
   3.173 -  
   3.174 +
   3.175 +
   3.176  
   3.177  
   3.178    // This counter tracks how many packets---as opposed to frames---are
   3.179 @@ -269,7 +226,7 @@
   3.180    Ptr<PacketCounterCalculator> appTx =
   3.181      CreateObject<PacketCounterCalculator>();
   3.182    appTx->SetKey("sender-tx-packets");
   3.183 -  Config::Connect("/NodeList/*/ApplicationList/*/$Sender/Tx",
   3.184 +  Config::Connect("/NodeList/0/ApplicationList/*/$Sender/Tx",
   3.185                    MakeCallback(&PacketCounterCalculator::PacketUpdate,
   3.186                                      appTx));
   3.187    data.AddDataCalculator(appTx);
   3.188 @@ -307,7 +264,7 @@
   3.189    Ptr<PacketSizeMinMaxAvgTotalCalculator> appTxPkts =
   3.190      CreateObject<PacketSizeMinMaxAvgTotalCalculator>();
   3.191    appTxPkts->SetKey("tx-pkt-size");
   3.192 -  Config::Connect("/NodeList/*/ApplicationList/*/$Sender/Tx",
   3.193 +  Config::Connect("/NodeList/0/ApplicationList/*/$Sender/Tx",
   3.194                    MakeCallback
   3.195                      (&PacketSizeMinMaxAvgTotalCalculator::PacketUpdate,
   3.196                      appTxPkts));
   3.197 @@ -326,14 +283,11 @@
   3.198  
   3.199  
   3.200  
   3.201 -  YansWifiPhyHelper::EnablePcap ("wifi-throughput-experiment", stasDev);
   3.202 -  YansWifiPhyHelper::EnablePcap ("wifi-throughput-experiment", apDev);
   3.203  
   3.204    //------------------------------------------------------------
   3.205    //-- Run the simulation
   3.206    //--------------------------------------------
   3.207    NS_LOG_INFO("Run Simulation.");
   3.208 -  Simulator::Stop (Seconds (50));
   3.209    Simulator::Run();    
   3.210    Simulator::Destroy();
   3.211