Initialization and Preparing to Send Messages

The flow of execution for initializing connections and sending messages is as follows.

For simplification purposes, this topic assumes that no errors occur; however, the application does perform error checking.

Initialization in the Management Component

The management component initiates its daemon. The first callback goes to the init_server() function. (See Management Component Operations for details.)

init_server() checks a variable to determine whether this is a master or backup Routing Engine in a master-slave setup. (For details about synchronizing data between Routing Engines or Multiservices PICs, see Synchronizing Runtime Data.) It also starts a server connection.

init_server(evContext ctx)
   if(is_master == TRUE) {
            "%s: Master,starting server", __func__);
   return SUCCESS;

Initialization in the Control Component

On startup, the control component initializes its daemon and goes to init_connections(). init_connections() starts a timer to connect to the management component:

init_connections(evContext ctx)
    mgmt_client = NULL;
    ev_ctx = ctx;
    // Connect to the MGMT component
    if(evSetTimer(ctx, connect_ctrl_pic, NULL, evNowTime(),
        evConsTime(RETRY_CONNECT_INTERVAL, 0), &ctrl_timer_id)) {

        LOG(LOG_EMERG, "%s: Failed to initialize a connect timer to connect "
            "to the MGMT component", __func__);
        return EFAIL;

    return SUCCESS;

connect_control_pic() sets up the libconn parameters to create a server socket for the data component and to create a new connection to the management server. It also sets tracking variables:

 // init the sessions
    data_session = NULL;
    // init the client in case it doesn't occur later
    mgmt_client = NULL;
    // init module's other variables
    data_ready = FALSE;
    mgmt_connected = FALSE;

connect_control_pic() also does the following:

Initialization in the Data Component

On startup, the data client's main() function calls msp_daemon_init(), which invokes the hellopics_data_init() handler. hellopics_data_init() calls init_connections(), which (in the same way as the init_connections() function in the control component) sets a timer to connect to the management component and call the connect_mgmt() function.

Also in parallel to the control components connect_control_pic() functionality, connect_mgmt() creates a client to connect to the management component and sets the event handler for libconn to the mgmt_client_connection() function.

Preparing to Send a Message

After all daemons are up and initialized, the following steps take place:

  1. When start_server() in the management component executes at startup, it calls receive_message(). receive_message() checks whether ctrl_session is enabled, and then checks for MSG_READY, sets ctrl_ready to TRUE, and checks for data_ready. If all are set, it then calls startMessageCycle(), to start the event timer that generates the periodic Hello messages.

    This basically means that the management component waits to hear that both of the other components are ready before sending a message.

    On the first iteration, none of the variables are set, so the cycle is not yet started.

  2. The control component executes the client_connection() handler whenever a connection event executes. If the connection succeeded, client_connection() does the following:

  3. The data component executes mgmt_client_connection() when the connection to the management client has been established. mgmt_client_connection() does the following:

  4. The management component gets the peer information request and does the following:

  5. On receiving MSG_PEER, the data component retrieves the control component's information:
    info = (pconn_peer_info_t *)msg->data;

  6. The data component then sets up libconn parameters for connecting to the control component, including specifying the ctrl_client_connection() event handler for connection events.

  7. ctrl_client_connection() checks for PCONN_EVENT_ESTABLISHED. If this is the case, it sends the data component's ID to the control component and sends MSG_READY to the management and control components.

  8. The data component connects to the control component, specifying ctrl_client_message() as the handler to execute.

  9. ctrl_client_message() calls pconn_client_send() to pass the message to the management component.

  10. The management component starts the message cycle once both the data and control components are ready (that is, it has received MSG_READY from both.)

The Message Cycle

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:26:47 2010 for Juniper Networks Partner Solution Development Platform JUNOS SDK 10.2R1 by Doxygen 1.4.5