Application class running mechanism of NS3

4525 단어 NS3

initialization related


Inheritance relationship: UdpEchoClient:Application:Object



  • Object::Initialize() calls DoInitialize() on each pointer in the collection of aggregate object pointers to implement polymorphism.
  • Application does not override Initialize(), but overrides DoInitialize():

  • void Application::DoInitialize (void){
      m_startEvent = Simulator::Schedule (m_startTime, &Application::StartApplication, this);
     m_stopEvent = Simulator::Schedule (m_stopTime, &Application::StopApplication, this);
      Object::DoInitialize ();
    }

  • UdpEchoClient() overrides Application::StartApplication(), Application::StopApplication(); does not redefine Initialize() and DoInitialize()

  • void  UdpEchoClient::StartApplication(){
      , Schedule , Schedule 
    }

    Application and Node binding



  • UdpEchoServerHelper::install(node) Call the UdpEchoServerHelper::InstallPriv(node) function to associate the corresponding Node object pointer for the Application.
  • Node::AddApplication(app) Store the app in a member variable of the Node object.

  • Application initialization call chain



  • Node::AddApplication(Application app) Calling the Initialize of the app is actually calling the Initialize of its parent class Object.
  • Object::Initialize Object::Initialize will call the member function DoInitialize. And Application has overridden the DoInitialize function. So here is the call to Application::DoInitialize
  • Application::DoInitialize

  • Application initialization call chain



  • Application::DoInitialize
  • Application::StartApplication

  • Application example analysis in first.cc


    udp-echo-client class



  • StartApplication function of udp-echo-client

  • 1. m_socket
    2. Server
    3. m_socket->SetRecvCallback (MakeCallback (&UdpEchoClient::HandleRead, this));// m_socket 
    4.ScheduleTransmit (Seconds (0.));// 0Schedule 

  • The ScheduleTransmit function further executes the Schedule function UdpEchoClient::Send(), adding a send event.

  • UdpEchoClient::Send()

  • UdpEchoClient::Send (void)
    {
    Ptr<Packet> p;
    p = Create<Packet> (m_data, m_dataSize);
    m_txTrace (p);
    m_socket->Send (p);
    ++m_sent;
    if (m_sent < m_count) 
        {
          ScheduleTransmit (m_interval);// Schedule , , 。
        }
    }

    Design ideas for the operation mechanism of each App in the project


    The operating mechanism of the App is also written in this way. In your module, if it needs to be executed periodically, Schedule itself inside the function. Then call the function for the first time in the Start function. The initialization of the module is done in the Init function of the module.

    좋은 웹페이지 즐겨찾기