equilibrium-mgmt_conn.c

Go to the documentation of this file.
00001 /*
00002  * $Id: equilibrium-mgmt_conn.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  * 
00010  * Copyright (c) 2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00021 #include <sync/common.h>
00022 #include <jnx/pconn.h>
00023 #include <sync/equilibrium_ipc.h>
00024 #include "equilibrium-mgmt_config.h"
00025 #include "equilibrium-mgmt_conn.h"
00026 #include "equilibrium-mgmt_logging.h"
00027 
00028 #include EQUILIBRIUM_OUT_H
00029 
00030 /*** Constants ***/
00031 
00032 #define EQUILIBRIUM_MGMT_SERVER_MAX_CONN 1  
00033 
00034 #define RETRY_INTERVAL 5 
00035 
00036 /*** Data Structures ***/
00037 
00038 static evContext eq_ctx;   
00039 
00040 static pconn_server_t     * mgmt_server;  
00041 static pconn_session_t    * data_session; 
00042 static pconn_peer_info_t  * data_info;    
00043 static evTimerID  timer_id;               
00044 
00050 typedef struct notification_msg_s {
00051     msg_type_e   action;        
00052     char *       svc_set_name;  
00053     uint16_t     message_len;   
00054     void *       message;       
00055     TAILQ_ENTRY(notification_msg_s) entries;    
00056 } notification_msg_t;
00057 
00058 
00063 static TAILQ_HEAD(notification_buffer_s, notification_msg_s) notification_msgs = 
00064             TAILQ_HEAD_INITIALIZER(notification_msgs);
00065 
00066 
00067 /*** STATIC/INTERNAL Functions ***/
00068 
00069 
00082 static void
00083 receive_connection(pconn_session_t * session,
00084                    pconn_event_t event,
00085                    void * cookie __unused)
00086 {
00087     int rc;
00088     eq_serviceset_t * ss;
00089     eq_app_t * app;
00090     eq_server_t * server;
00091     
00092     switch (event) {
00093 
00094     case PCONN_EVENT_ESTABLISHED:
00095             
00096         if(data_info == NULL) {
00097             data_info = malloc(sizeof(pconn_peer_info_t));
00098             INSIST(data_info != NULL);
00099         } else {
00100             LOG(TRACE_LOG_ERR, "%s: data_info already present when receiving "
00101                 "incoming connection", __func__);
00102         }
00103         
00104         rc = pconn_session_get_peer_info(session, data_info);
00105         
00106         if(rc != PCONN_OK) {
00107             LOG(TRACE_LOG_ERR, "%s: Cannot retrieve peer info "
00108                 "for session. Error: %d", __func__, rc);
00109         } else {
00110             INSIST_ERR(data_info->ppi_peer_type == PCONN_PEER_TYPE_PIC);
00111             
00112             junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00113                 "%s: Accepted connection from ms-%d/%d/0",
00114                 __func__, data_info->ppi_fpc_slot, data_info->ppi_pic_slot);
00115         }
00116         
00117         data_session = session;
00118 
00119         // Send all configuration to the data component, we neede this 
00120         // especially in the case of the data component loosing and 
00121         // regaining the connection (possibly from it restarting)
00122 
00123         // first empty out all the messages and send it a reset
00124         notify_delete_all();
00125         
00126         // go thru all service sets
00127         ss = next_service_set(NULL);
00128         while(ss != NULL) {
00129             // send all applications of this service set
00130             app = next_application(ss, NULL);
00131             while(app != NULL) {
00132                 
00133                 if(app->server_mon_params != NULL) {
00134                     notify_application_update(
00135                             ss->svc_set_name, app->application_name,
00136                             app->application_addr, app->application_port,
00137                             app->session_timeout,
00138                             app->server_mon_params->connection_interval,
00139                             app->server_mon_params->connection_timeout,
00140                             app->server_mon_params->timeouts_allowed,
00141                             app->server_mon_params->down_retry_interval);
00142                 } else {
00143                     notify_application_update(
00144                             ss->svc_set_name, app->application_name,
00145                             app->application_addr, app->application_port,
00146                             app->session_timeout, 0, 0, 0, 0);
00147                 }
00148                 
00149                 // send all servers config
00150                 if(app->servers) {
00151                     server = TAILQ_FIRST(app->servers);
00152                     while(server != NULL) {
00153                         notify_server_update(ss->svc_set_name,
00154                                 app->application_name, server->server_addr);
00155                         
00156                         server = TAILQ_NEXT(server, entries);
00157                     }
00158                 }
00159                 
00160                 app = next_application(ss, app);
00161             }
00162             ss = next_service_set(ss);
00163         }
00164         process_notifications();
00165         
00166         break;
00167 
00168     case PCONN_EVENT_SHUTDOWN:
00169         
00170         if(session == data_session) {
00171             data_session = NULL;
00172             
00173             if(data_info != NULL) {
00174                 free(data_info);
00175                 data_info = NULL;
00176             }
00177             
00178             junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: Connection"
00179                 " from the data component was shutdown.", __func__);
00180                 
00181         } else {
00182             LOG(TRACE_LOG_ERR, "%s: Cannot find an existing "
00183                 "peer session to shutdown", __func__);
00184         }
00185 
00186         break;
00187 
00188     case PCONN_EVENT_FAILED:
00189         
00190         if(session == data_session) {
00191             data_session = NULL;
00192             
00193             if(data_info != NULL) {
00194                 free(data_info);
00195                 data_info = NULL;
00196             }
00197             
00198             junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: Connection from "
00199                 "the data component was shutdown (failure).", __func__);
00200         }
00201         
00202         break;
00203         
00204     default:
00205         
00206         LOG(TRACE_LOG_ERR, "%s: Received an unknown event", __func__);
00207         
00208         break;
00209     }
00210 }
00211 
00212 
00229 static status_t
00230 receive_message(pconn_session_t * session,
00231                 ipc_msg_t * msg,
00232                 void * cookie __unused)
00233 {
00234     server_status_t * server_status = NULL;
00235     sessions_status_t * sessions_status = NULL;
00236     struct in_addr addr;
00237     
00238     
00239     INSIST_ERR(session == data_session);
00240     
00241     switch(msg->subtype) {
00242     
00243     case MSG_SERVER_UPDATE:
00244         
00245         server_status = (server_status_t *)msg->data;
00246         // check message length
00247         INSIST_ERR(msg->length == 
00248             sizeof(server_status_t) + ntohs(server_status->app_name_len));
00249         
00250         set_server_status(ntohs(server_status->svc_set_id),
00251                           server_status->app_name,
00252                           server_status->server_addr,
00253                           server_status->server_status);
00254         
00255         addr.s_addr = server_status->server_addr;
00256         
00257         junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: got update that "
00258             "server %s is %s for app %s.", __func__, inet_ntoa(addr),
00259             ((server_status->server_status) ? "up" : "down"),
00260             server_status->app_name);
00261         
00262         break;
00263 
00264     case MSG_STATUS_UPDATE:
00265     
00266         sessions_status = (sessions_status_t *)msg->data;
00267         
00268         // check message length
00269         INSIST_ERR(msg->length == 
00270             sizeof(sessions_status_t) + ntohs(sessions_status->app_name_len));
00271         
00272         set_app_sessions(ntohs(sessions_status->svc_set_id),
00273                          sessions_status->app_name,
00274                          ntohl(sessions_status->active_sessions));
00275         
00276         junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: got update that %d "
00277             "sessions are active for app %s.", __func__,
00278             ntohl(sessions_status->active_sessions), sessions_status->app_name);
00279         
00280         break;
00281         
00282     default:
00283     
00284         LOG(TRACE_LOG_ERR,
00285             "%s: Received an unknown message type (%d) from the "
00286             "data component", __func__, msg->subtype);
00287         break;
00288     }
00289 
00290     return SUCCESS;
00291 }
00292 
00293 
00312 static void
00313 process_notifications_messages(evContext ctx __unused, void * uap  __unused,
00314             struct timespec due __unused, struct timespec inter __unused)
00315 {
00316     
00317     notification_msg_t * msg;
00318     junos_kcom_pub_ssrb_t * ssrb;
00319     int rc = 0;
00320     
00321     if(data_session == NULL) { // don't bother doing anything yet
00322         return;
00323     }
00324     
00325     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s", __func__);
00326     
00327     evClearTimer(eq_ctx, timer_id);
00328     evInitID(&timer_id);
00329     
00330     while((msg = TAILQ_FIRST(&notification_msgs)) != NULL) {
00331         
00332         if(msg->action == MSG_DELETE_ALL) {
00333             rc = pconn_server_send(data_session, msg->action, NULL, 0);
00334             if(rc != PCONN_OK) {
00335                  goto failed_send;
00336             }
00337         } else {
00338             
00339             // all other msg type need the svc_set_id
00340             
00341             switch(msg->action) {
00342             
00343             case MSG_DELETE_SS: // svc set or all apps were deleted
00344             {
00345                 del_svcset_info_t * data = (del_svcset_info_t *)(msg->message);
00346                 // already have the service-set id in this case,
00347                 // see: notify_serviceset_delete
00348                 
00349                 rc = pconn_server_send(data_session, msg->action, 
00350                         data, msg->message_len);
00351                 
00352                 break;
00353             }
00354             case MSG_DELETE_APP:
00355             case MSG_DELETE_ALL_SERVERS:
00356             {
00357                 del_app_info_t * data = (del_app_info_t *)(msg->message);
00358                 if((ssrb = get_ssrb_by_name(msg->svc_set_name)) == NULL) {
00359                     goto reset_timer;
00360                 } else {
00361                     data->svc_set_id = htons(ssrb->svc_set_id);                        
00362                 }
00363                 
00364                 rc = pconn_server_send(data_session, msg->action, 
00365                         data, msg->message_len);
00366                 
00367                 break;
00368             }   
00369             case MSG_DELETE_SERVER:
00370             case MSG_CONF_SERVER:
00371             {
00372                 server_info_t * data = (server_info_t *)(msg->message);
00373                 if((ssrb = get_ssrb_by_name(msg->svc_set_name)) == NULL) {
00374                     goto reset_timer;
00375                 } else {
00376                     data->svc_set_id = htons(ssrb->svc_set_id);                        
00377                 }
00378                 
00379                 rc = pconn_server_send(data_session, msg->action, 
00380                         data, msg->message_len);
00381                 
00382                 break;
00383             }
00384             case MSG_CONF_APPLICATION:
00385             {   
00386                 update_app_info_t * data = (update_app_info_t *)(msg->message);
00387                 if((ssrb = get_ssrb_by_name(msg->svc_set_name)) == NULL) {
00388                     
00389                     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,"%s: Waiting "
00390                         "for SSRB: %s", __func__, msg->svc_set_name);
00391                     
00392                     goto reset_timer;
00393                 } else {
00394                     data->svc_set_id = htons(ssrb->svc_set_id);                    
00395                 }
00396                 
00397                 rc = pconn_server_send(data_session, msg->action, 
00398                         data, msg->message_len);
00399                 
00400                 break;
00401             }
00402             default: break; // ignore warnings for not handling all enum values
00403             }
00404             
00405             if(rc != PCONN_OK) {
00406                  goto failed_send;
00407             }
00408             
00409             free(msg->svc_set_name);
00410             free(msg->message);
00411         }
00412         
00413         TAILQ_REMOVE(&notification_msgs, msg, entries);
00414         free(msg);
00415         
00416         junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00417             "%s: Dequeued message sent to the data component", __func__);
00418     }
00419     
00420     return;
00421     
00422 failed_send:
00423 
00424     LOG(TRACE_LOG_ERR, "%s: Failed to send %d to data component. Error: %d",
00425         __func__, msg->action, rc);
00426     
00427 reset_timer:
00428     
00429     if(evSetTimer(eq_ctx, process_notifications_messages, NULL,
00430             evAddTime(evNowTime(), evConsTime(RETRY_INTERVAL, 0)),
00431             evConsTime(RETRY_INTERVAL, 0), &timer_id)) {
00432 
00433         LOG(LOG_EMERG, "%s: evSetTimer() failed! Will not be "
00434                 "able to process buffered notifications", __func__);
00435     }
00436 }
00437 
00438 
00439 /*** GLOBAL/EXTERNAL Functions ***/
00440 
00441 
00451 status_t
00452 init_server(evContext ctx)
00453 {
00454     pconn_server_params_t params;
00455     
00456     eq_ctx = ctx;
00457     evInitID(&timer_id);
00458     
00459     // init the sessions
00460     data_session = NULL;
00461     data_info = NULL;
00462     
00463     bzero(&params, sizeof(pconn_server_params_t));
00464     
00465     // setup the server args
00466     params.pconn_port            = EQUILIBRIUM_PORT_NUM;
00467     params.pconn_max_connections = EQUILIBRIUM_MGMT_SERVER_MAX_CONN;
00468     params.pconn_event_handler   = receive_connection;
00469     
00470     // bind
00471     mgmt_server = pconn_server_create(&params, eq_ctx, receive_message, NULL);
00472     
00473     if(mgmt_server == NULL) {
00474         LOG(TRACE_LOG_ERR, "%s: Failed to initialize the pconn server"
00475             " on port %d.", __func__, EQUILIBRIUM_PORT_NUM);
00476         return EFAIL;
00477     }
00478     
00479     LOG(TRACE_LOG_INFO, "%s: Successfully initialized "
00480             "the pconn server on port %d.", __func__, EQUILIBRIUM_PORT_NUM);
00481     
00482     return SUCCESS;
00483 }
00484 
00485 
00489 void
00490 close_connections(void)
00491 {
00492     notification_msg_t * msg;
00493     
00494     if(data_session) {
00495         junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00496             "%s: Closing the session to the data component.", __func__);
00497         pconn_session_close(data_session);
00498         data_session = NULL;
00499         if(data_info != NULL) {
00500             free(data_info);
00501             data_info = NULL;
00502         }
00503     }
00504     
00505     if(mgmt_server) {
00506         junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00507             "%s: Shuting down the server on port %d.",
00508             __func__, EQUILIBRIUM_PORT_NUM);
00509         pconn_server_shutdown(mgmt_server);
00510         mgmt_server = NULL;
00511     }
00512     
00513     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00514         "%s: Deleting the queue of notification messages.", __func__);
00515     
00516     while((msg = TAILQ_FIRST(&notification_msgs)) != NULL) {
00517         TAILQ_REMOVE(&notification_msgs, msg, entries);
00518         if(msg->action != MSG_DELETE_ALL) {
00519             free(msg->svc_set_name);
00520             free(msg->message);
00521         }
00522         free(msg);
00523     }
00524 }
00525 
00526 
00533 void
00534 mspic_offline(const char * name)
00535 {
00536     char current_int_prefix[64];
00537     
00538     if(data_info != NULL) {
00539     
00540         sprintf(current_int_prefix,
00541             "ms-%d/%d/0", data_info->ppi_fpc_slot, data_info->ppi_pic_slot);
00542         
00543         if(strstr(name, current_int_prefix) != NULL) {
00544             pconn_session_close(data_session);
00545             data_session = NULL;
00546             free(data_info);
00547             data_info = NULL;
00548             
00549             junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: Connection from "
00550                 "the data component was shutdown (forced).", __func__);
00551         }
00552     }
00553 }
00554 
00555 
00560 void
00561 process_notifications(void)
00562 {
00563     if(!evTestID(timer_id) &&
00564         evSetTimer(eq_ctx, process_notifications_messages, NULL,
00565             evConsTime(0,0), evConsTime(RETRY_INTERVAL, 0), &timer_id)) {
00566 
00567         LOG(LOG_EMERG, "%s: evSetTimer() failed! Will not be "
00568                 "able to process buffered notifications", __func__);
00569     }
00570 }
00571 
00572 
00603 void
00604 notify_application_update(const char * svc_set_name,
00605                           const char * app_name,
00606                           in_addr_t address,
00607                           uint16_t port,
00608                           uint16_t session_timeout,
00609                           uint16_t connection_interval,
00610                           uint16_t connection_timeout,
00611                           uint8_t timeouts_allowed,
00612                           uint16_t down_retry_interval)
00613 {
00614     notification_msg_t * msg;
00615     update_app_info_t * data;
00616     uint16_t len;
00617     
00618     len = strlen(app_name) + 1;
00619 
00620     msg = calloc(1, sizeof(notification_msg_t));
00621     INSIST(msg != NULL);
00622     
00623     msg->action = MSG_CONF_APPLICATION;
00624     
00625     msg->svc_set_name = strdup(svc_set_name);
00626     INSIST(msg->svc_set_name != NULL);
00627     msg->message_len = sizeof(update_app_info_t) + len;
00628     
00629     msg->message = data = calloc(1, msg->message_len);
00630     INSIST(data != NULL);
00631     data->app_addr = address;
00632     data->app_port = htons(port);
00633     data->session_timeout = htons(session_timeout);
00634     data->connection_interval = htons(connection_interval);
00635     data->connection_timeout = htons(connection_timeout);
00636     data->timeouts_allowed = timeouts_allowed;
00637     data->down_retry_interval = htons(down_retry_interval);
00638     data->app_name_len = htons(len);
00639     strcpy(data->app_name, app_name);
00640     
00641     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00642     
00643     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00644         "%s: Enqueueing message for the data component", __func__);
00645 }
00646 
00647 
00660 void
00661 notify_server_update(const char * svc_set_name,
00662                      const char * app_name,
00663                      in_addr_t address)
00664 {
00665     notification_msg_t * msg;
00666     server_info_t * data;
00667     uint16_t len;
00668     
00669     len = strlen(app_name) + 1;
00670 
00671     msg = calloc(1, sizeof(notification_msg_t));
00672     INSIST(msg != NULL);
00673     
00674     msg->action = MSG_CONF_SERVER;
00675     msg->svc_set_name = strdup(svc_set_name);
00676     INSIST(msg->svc_set_name != NULL);
00677     msg->message_len = sizeof(server_info_t) + len;
00678     
00679     msg->message = data = calloc(1, msg->message_len);
00680     INSIST(data != NULL);
00681     data->server_addr = address;
00682     data->app_name_len = htons(len);
00683     strcpy(data->app_name, app_name);
00684     
00685     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00686     
00687     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00688         "%s: Enqueueing message for the data component", __func__);
00689 }
00690 
00691 
00704 void
00705 notify_server_delete(const char * svc_set_name,
00706                      const char * app_name,
00707                      in_addr_t address)
00708 {
00709     notification_msg_t * msg;
00710     server_info_t * data;
00711     uint16_t len;
00712     
00713     len = strlen(app_name) + 1;
00714 
00715     msg = calloc(1, sizeof(notification_msg_t));
00716     INSIST(msg != NULL);
00717     
00718     msg->action = MSG_DELETE_SERVER;
00719     msg->svc_set_name = strdup(svc_set_name);
00720     INSIST(msg->svc_set_name != NULL);
00721     msg->message_len = sizeof(server_info_t) + len;
00722     
00723     msg->message = data = calloc(1, msg->message_len);
00724     INSIST(data != NULL);
00725     data->server_addr = address;
00726     data->app_name_len = htons(len);
00727     strcpy(data->app_name, app_name);
00728     
00729     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00730     
00731     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00732         "%s: Enqueueing message for the data component", __func__);
00733 }
00734 
00735 
00745 void
00746 notify_application_delete(const char * svc_set_name,
00747                           const char * app_name)
00748 {
00749     notification_msg_t * msg, * tmp, * tmp2;
00750     del_app_info_t * data;
00751     uint16_t len;
00752     uint8_t match;
00753     
00754     len = strlen(app_name) + 1;
00755 
00756     msg = calloc(1, sizeof(notification_msg_t));
00757     INSIST(msg != NULL);
00758     
00759     msg->action = MSG_DELETE_APP;
00760     msg->svc_set_name = strdup(svc_set_name);
00761     INSIST(msg->svc_set_name != NULL);
00762     msg->message_len = sizeof(del_app_info_t) + len;
00763     
00764     msg->message = data = calloc(1, msg->message_len);
00765     INSIST(data != NULL);
00766     data->app_name_len = htons(len);
00767     strcpy(data->app_name, app_name);
00768     
00769     // Go thru messages and delete any with the same app name.
00770     // They are useless now, and while the data component isn't connected this 
00771     // prevents tons of useless messages from piling up and consuming memory
00772     tmp = TAILQ_FIRST(&notification_msgs);
00773     while(tmp != NULL) {
00774         
00775         // match the service-set name first
00776         if(tmp->svc_set_name != NULL &&
00777                 strcmp(tmp->svc_set_name, svc_set_name) == 0) {
00778             
00779             // match the applicaiton name:
00780             match = 0;
00781             switch(tmp->action) {
00782             case MSG_DELETE_APP:
00783             case MSG_DELETE_ALL_SERVERS:
00784             {
00785                 del_app_info_t * dat = (del_app_info_t *)tmp->message;
00786                 if(strcmp(dat->app_name, app_name) == 0) {
00787                     match = 1;
00788                 }
00789                 break;
00790             }
00791             case MSG_CONF_SERVER:
00792             case MSG_DELETE_SERVER:
00793             {
00794                 server_info_t * dat = (server_info_t *)tmp->message;
00795                 if(strcmp(dat->app_name, app_name) == 0) {
00796                     match = 1;
00797                 }
00798                 break;
00799             }
00800             case MSG_CONF_APPLICATION:
00801             {
00802                 update_app_info_t * dat = (update_app_info_t *)tmp->message;
00803                 if(strcmp(dat->app_name, app_name) == 0) {
00804                     match = 1;
00805                 }
00806                 break;
00807             }
00808             default: break;
00809             }
00810             
00811             if(match) { // this is one with same app_name
00812                 tmp2 = tmp;
00813                 tmp = TAILQ_NEXT(tmp, entries);
00814                 TAILQ_REMOVE(&notification_msgs, tmp2, entries);
00815                 
00816                 junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: Cleaning up "
00817                         "message for the data component", __func__);
00818             } else {
00819                 tmp = TAILQ_NEXT(tmp, entries);                
00820             }
00821         } else {
00822             tmp = TAILQ_NEXT(tmp, entries);
00823         }
00824     }
00825     
00826     // insert the new message
00827     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00828     
00829     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00830         "%s: Enqueueing message for the data component", __func__);
00831 }
00832 
00833 
00844 void
00845 notify_serviceset_delete(const char * svc_set_name, uint16_t svc_set_id)
00846 {
00847     notification_msg_t * msg, * tmp, * tmp2;
00848     del_svcset_info_t * data;
00849 
00850     msg = calloc(1, sizeof(notification_msg_t));
00851     INSIST(msg != NULL);
00852     
00853     msg->action = MSG_DELETE_SS;
00854     msg->svc_set_name = strdup(svc_set_name);
00855     INSIST(msg->svc_set_name != NULL);
00856     msg->message_len = sizeof(del_svcset_info_t);
00857     
00858     msg->message = data = calloc(1, msg->message_len);
00859     INSIST(data != NULL);
00860     data->svc_set_id = htons(svc_set_id); // save the ID; we can't look it up later
00861     
00862     // go thru message and delete any with the same service-set name
00863     // becase they won't be able to get the SS ID (and they are useless now)
00864     tmp = TAILQ_FIRST(&notification_msgs);
00865     while(tmp != NULL) {
00866         if(tmp->svc_set_name != NULL &&
00867                 strcmp(tmp->svc_set_name, svc_set_name) == 0) {
00868             tmp2 = tmp;
00869             tmp = TAILQ_NEXT(tmp, entries);
00870             TAILQ_REMOVE(&notification_msgs, tmp2, entries);
00871             
00872             junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION, "%s: Cleaning up "
00873                     "message for the data component", __func__);
00874         } else {
00875             tmp = TAILQ_NEXT(tmp, entries);
00876         }
00877     }
00878     
00879     // insert the new message
00880     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00881     
00882     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00883         "%s: Enqueueing message for the data component", __func__);
00884 }
00885 
00886 
00896 void
00897 notify_delete_all_servers(const char * svc_set_name,
00898                           const char * app_name)
00899 {
00900     notification_msg_t * msg;
00901     del_app_info_t * data;
00902     uint16_t len;
00903     
00904     len = strlen(app_name) + 1;
00905 
00906     msg = calloc(1, sizeof(notification_msg_t));
00907     INSIST(msg != NULL);
00908     
00909     msg->action = MSG_DELETE_ALL_SERVERS;
00910     msg->svc_set_name = strdup(svc_set_name);
00911     INSIST(msg->svc_set_name != NULL);
00912     msg->message_len = sizeof(del_app_info_t) + len;
00913     
00914     msg->message = data = calloc(1, msg->message_len);
00915     INSIST(data != NULL);
00916     data->app_name_len = htons(len);
00917     strcpy(data->app_name, app_name);
00918     
00919     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00920     
00921     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00922         "%s: Enqueueing message for the data component", __func__);
00923 }
00924 
00925 
00936 void
00937 notify_delete_all_applications(const char * svc_set_name, uint16_t svc_set_id)
00938 {
00939     notification_msg_t * msg;
00940     del_svcset_info_t * data;
00941 
00942     msg = calloc(1, sizeof(notification_msg_t));
00943     INSIST(msg != NULL);
00944     
00945     msg->action = MSG_DELETE_SS; // just delete the service set at this point
00946     msg->svc_set_name = strdup(svc_set_name);
00947     INSIST(msg->svc_set_name != NULL);
00948     msg->message_len = sizeof(del_svcset_info_t);
00949     
00950     msg->message = data = calloc(1, msg->message_len);
00951     INSIST(msg->message != NULL);
00952     data->svc_set_id = htons(svc_set_id); // save the ID; we can't look it up later
00953     
00954     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00955     
00956     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00957         "%s: Enqueueing message for the data component", __func__);
00958 }
00959 
00960 
00964 void
00965 notify_delete_all(void)
00966 {
00967     notification_msg_t * msg;
00968 
00969     // override any other messages, so delete all others 
00970     while((msg = TAILQ_FIRST(&notification_msgs)) != NULL) {
00971         if(msg->action != MSG_DELETE_ALL) {
00972             free(msg->svc_set_name);
00973             free(msg->message);
00974         }
00975         TAILQ_REMOVE(&notification_msgs, msg, entries);
00976         free(msg);
00977     }
00978     
00979     msg = calloc(1, sizeof(notification_msg_t));
00980     INSIST(msg != NULL);
00981     
00982     msg->action = MSG_DELETE_ALL; 
00983     TAILQ_INSERT_TAIL(&notification_msgs, msg, entries);
00984 
00985     junos_trace(EQUILIBRIUM_TRACEFLAG_CONNECTION,
00986         "%s: Enqueueing message for the data component", __func__);
00987 }
00988 
00989 

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:57 2010 for SDK Your Net Corporation Equilibrium Load Balancer Example: equilibrium-mgmt 1.0 by Doxygen 1.5.1