The Message Cycle

The easiest way to see how the various event handlers in Hello PICs mesh to create the message flow among the components is to trace the trajectory of a HELLO message as it loops around the three components.

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

As we have already seen in Management Component Operations, the management component sends the HELLO message to the data or control component, depending on the value in its local direction variable. On the first iteration, the message goes to the data component. The code is as follows:

static component_id_e direction = HELLOPICS_ID_DATA; // first execution

      if(direction == HELLOPICS_ID_DATA) {

           rc = pconn_server_send(data_session, MSG_HELLO,
                               &hello_data, sizeof(hello_data));
            direction = HELLOPICS_ID_CTRL; // switch direction

       else {
            rc = pconn_server_send(ctrl_session, MSG_HELLO,
                               &hello_data, sizeof(hello_data));
            direction = HELLOPICS_ID_CTRL; // switch direction

The logic of the message flow among the components is illustrated in the following figure and described in the subsequent paragraphs.

hellopics-flow-with-numbers-g016852.gif

The Message Cycle

Step 1: Data Component Gets Message from Management Component

The data component's mgmt_client_message() handler is triggered on a message from the management component. If the message is MSG_HELLO, the data component sends the message onward to the control component:

          case MSG_HELLO:
            // Received a HELLO from the mgmt component, so
            // pass it along to the ctrl component
                
            rc = pconn_client_send(ctrl_client, MSG_HELLO,
                                   msg->data, sizeof(uint32_t));

Step 2: Control Component Gets Message from Data Component

The control component's receive_message() handler is triggered on a message from the data component. If the message is MSG_HELLO, the control component sends the message onward to the management component:

case MSG_HELLO:
            // Received a HELLO from the data component, so
            // pass it along to the mgmt component
             rc =  pconn_client_send(mgmt_client, MSG_HELLO,
                                   msg->data, sizeof(uint32_t));

Step 3: Management Component Gets Message from Control Component

The management component's receive_message() handler is triggered on a HELLO message, which it knows to be coming from the control component. In this case, the management component simply increments the messages-received counter and updates the data for the backup.

case MSG_HELLO:
            
                INSIST_ERR(msg->length == sizeof(uint32_t));
                
                helloNum = ntohl(*((uint32_t *)msg->data));
                
                junos_trace(HELLOPICS_TRACEFLAG_CONNECTION,
                    "%s: Received a HELLO from the control component (%d)",
                    __func__, helloNum);
                
                if(helloNum == hello_seq_num) {
                    ++hellopics_stats.msgs_received;
                    received = TRUE;
                } else {
                    ++hellopics_stats.msgs_badorder;
                }
                update_replication_entry(&hellopics_stats); 
                break;

Step 4: Control Component Gets Message from Management Component

Because the direction variable was set to HELLOPICS_ID_CTRL after the management component sent the first HELLO message, the management component sends the second message to the control component, and the cycle continues.

The control component's receive_message() handler is triggered on the message from the management component. If the message is MSG_HELLO, the control component sends the message onward to the data component:

          case MSG_HELLO:
           ...
          
            rc = pconn_server_send(data_session, MSG_HELLO,
                                   msg->data, sizeof(uint32_t));
           ...                        

Step 5: Data Component Gets Message from Control Component

The data component's ctrl_client_message() handler is triggered on a message from the control component. If the message is MSG_HELLO, the data component sends the message onward to the management component,:

      case MSG_HELLO:
            // Received a HELLO from the ctrl component, so
            // pass it along to the mgmt component
           ... 
           rc =  pconn_client_send(mgmt_client, MSG_HELLO,
                                   msg->data, sizeof(uint32_t));
           ...                        

Step 6: New Cycle

The management component receives the message, completing the cycle. It switches the direction variable, and a new cycle is initiated, this time in the opposite direction, beginning with the management component sending the message to the control component.

Tracking and Displaying Application Statistics


© 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