samples/main-adhoc-wifi.cc
changeset 2075 ae2cdfcd0368
parent 2068 af5f03746dbe
child 2079 673a34d2e3d7
equal deleted inserted replaced
2074:93c8fdda610f 2075:ae2cdfcd0368
    76 
    76 
    77 static void 
    77 static void 
    78 AdvancePosition (Ptr<Node> node) 
    78 AdvancePosition (Ptr<Node> node) 
    79 {
    79 {
    80   Position pos = GetPosition (node);
    80   Position pos = GetPosition (node);
    81   pos.x += 50.0;
    81   double mbs = ((g_bytesTotal * 8.0) / 1000000);
    82   if (pos.x >= 2100.0) {
    82   g_bytesTotal = 0;
       
    83   std::cout << pos.x << " " << mbs << std::endl;
       
    84   pos.x += 5.0;
       
    85   if (pos.x >= 210.0) {
    83     return;
    86     return;
    84   }
    87   }
    85   SetPosition (node, pos);
    88   SetPosition (node, pos);
    86   //std::cout << "x="<<pos.x << std::endl;
    89   //std::cout << "x="<<pos.x << std::endl;
    87   Simulator::Schedule (Seconds (1.0), &AdvancePosition, node);
    90   Simulator::Schedule (Seconds (1.0), &AdvancePosition, node);
    88 }
       
    89 
       
    90 static void
       
    91 Printer (Ptr<Node> node)
       
    92 {
       
    93   Ptr<MobilityModel> mobility = node->QueryInterface<MobilityModel> (MobilityModel::iid);
       
    94   Position position = mobility->Get ();
       
    95   double mbs = ((g_bytesTotal * 8.0) / 1000000);
       
    96   g_bytesTotal = 0;
       
    97   std::cout << position.x << " " << mbs << std::endl;
       
    98   if (Simulator::Now ().GetSeconds () < 43.0)
       
    99     {
       
   100       Simulator::Schedule (Seconds (1.0), &Printer, node);
       
   101     }
       
   102 }
    91 }
   103 
    92 
   104 static void
    93 static void
   105 ReceivePacket (Ptr<Socket> socket, const Packet &packet, const Address &address)
    94 ReceivePacket (Ptr<Socket> socket, const Packet &packet, const Address &address)
   106 {
    95 {
   142                                  "192.168.0.1");
   131                                  "192.168.0.1");
   143   Ptr<Node> b = CreateAdhocNode (channel,
   132   Ptr<Node> b = CreateAdhocNode (channel,
   144                                  Position (0.0, 0.0, 0.0),
   133                                  Position (0.0, 0.0, 0.0),
   145                                  "192.168.0.2");
   134                                  "192.168.0.2");
   146 
   135 
   147   Simulator::Schedule (Seconds (1.0), &AdvancePosition, b);
       
   148 
       
   149   Ptr<Application> app = Create<OnOffApplication> (a, InetSocketAddress ("192.168.0.2", 10), 
   136   Ptr<Application> app = Create<OnOffApplication> (a, InetSocketAddress ("192.168.0.2", 10), 
   150                                                    "Udp", 
   137                                                    "Udp", 
   151                                                    ConstantVariable (42),
   138                                                    ConstantVariable (45),
   152                                                    ConstantVariable (0),
   139                                                    ConstantVariable (0),
   153                                                    DataRate (60000000),
   140                                                    DataRate (60000000),
   154                                                    2048);
   141                                                    2000);
   155 
   142 
   156   app->Start (Seconds (0.5));
   143   app->Start (Seconds (0.5));
   157   app->Stop (Seconds (43.0));
   144   app->Stop (Seconds (45.0));
   158 
   145 
   159   Simulator::Schedule (Seconds (0.5), &Printer, b);
   146   Simulator::Schedule (Seconds (1.5), &AdvancePosition, b);
   160   Ptr<Socket> recvSink = SetupUdpReceive (b, 10);
   147   Ptr<Socket> recvSink = SetupUdpReceive (b, 10);
   161 
   148 
   162   GlobalRouteManager::PopulateRoutingTables ();
   149   GlobalRouteManager::PopulateRoutingTables ();
   163 
   150 
   164   Simulator::Run ();
   151   Simulator::Run ();