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