equilibrium-mgmt_kcom.c

Go to the documentation of this file.
00001 /*
00002  * $Id: equilibrium-mgmt_kcom.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/junos_kcom_pub_blob.h>
00023 #include <jnx/provider_info.h>
00024 #include "equilibrium-mgmt_kcom.h"
00025 #include "equilibrium-mgmt_config.h"
00026 #include "equilibrium-mgmt_conn.h"
00027 #include "equilibrium-mgmt_logging.h"
00028 
00029 #include EQUILIBRIUM_OUT_H
00030 
00031 /*** Constants ***/
00032 
00033 #define MSP_IFD_NAME_PATTERN "ms-"  
00034 
00035 /*** Data Structures ***/
00036 
00037 
00038 /*** STATIC/INTERNAL Functions ***/
00039 
00052 static int
00053 ifd_down_async_handler(kcom_ifdev_t * msg, void * user_info __unused)
00054 {
00055     char * name = msg->ifdev_name;
00056 
00057     if((msg->ifdev_op == KCOM_DELETE || junos_kcom_ifd_down(msg)) &&
00058        strstr(name, MSP_IFD_NAME_PATTERN)) {
00059         
00060         junos_trace(EQUILIBRIUM_TRACEFLAG_KCOM,
00061                 "%s: Handling ifd %s going down", __func__, name);
00062         
00063         // An MS PIC is going down and may be one we're connected to
00064         mspic_offline(name);
00065     }
00066     
00067     junos_kcom_msg_free(msg);
00068 
00069     return 0;
00070 }
00071 
00072 
00085 static int
00086 ssrb_async_handler(junos_kcom_pub_blob_msg_t * kpb_msg, void * arg __unused)
00087 {
00088     junos_kcom_pub_ssrb_t * ssrb;
00089 
00090     if (kpb_msg->key.blob_id != JNX_PUB_EXT_SVC_SSR_BLOB) {
00091         LOG(TRACE_LOG_ERR, "%s: Public blob, but not an SSRB <%d>",
00092             __func__, kpb_msg->pub_blob.blob_id);
00093         free(kpb_msg);
00094         return 0;
00095     }
00096     
00097     ssrb = &kpb_msg->pub_blob.blob.ssrb;
00098     
00099     switch (kpb_msg->op) {
00100 
00101         case JUNOS_KCOM_PUB_BLOB_MSG_ADD:
00102                 
00103             LOG(TRACE_LOG_INFO, "%s: public ssrb add <%s,%d>",
00104                     __func__, ssrb->svc_set_name, ssrb->svc_set_id);
00105 
00106             if(add_ssrb(ssrb) != SUCCESS) {
00107                 LOG(TRACE_LOG_INFO, 
00108                     "%s: ssrb was not added to config (already exists) <%s,%d>",
00109                     __func__, ssrb->svc_set_name, ssrb->svc_set_id);
00110             }
00111             
00112             break;
00113 
00114         case JUNOS_KCOM_PUB_BLOB_MSG_DEL:
00115 
00116             LOG(TRACE_LOG_INFO, "%s: public ssrb delete <%d>", __func__,
00117                 kpb_msg->key.blob_key.pub_ssrb_key.svc_set_id);
00118 
00119             delete_ssrb_by_id(kpb_msg->key.blob_key.pub_ssrb_key.svc_set_id);
00120 
00121             break;
00122 
00123         case JUNOS_KCOM_PUB_BLOB_MSG_CHANGE:
00124             
00125             LOG(TRACE_LOG_INFO, "%s: public ssrb change "
00126                 "<%s,%d>", __func__, ssrb->svc_set_name, ssrb->svc_set_id);
00127 
00128               
00129              // We don't need to worry about receiving these, since we do not
00130              // use the next-hop-service style of service sets.
00131              // This event would occur upon a next-hop index changing. 
00132              
00133 
00134             break;
00135             
00136         default:
00137             LOG(TRACE_LOG_ERR, "%s: public ssrb unknown event <%s,%d>", __func__,
00138                         ssrb->svc_set_name, ssrb->svc_set_id);
00139             
00140             break;
00141     }
00142     
00143     free(kpb_msg);
00144     return 0;
00145 }
00146 
00147 
00160 static int 
00161 process_initial_ssrb(junos_kcom_pub_blob_t * pub_blob, void * arg __unused)
00162 {
00163     if (pub_blob->blob_id != JNX_PUB_EXT_SVC_SSR_BLOB) {
00164         LOG(LOG_ERR, "%s: Public blob, but not an SSRB <%d>",
00165             __func__, pub_blob->blob_id);
00166         free(pub_blob);
00167         return 0;
00168     }
00169 
00170     LOG(LOG_INFO, "%s: public ssrb add <%s,%d>", __func__,
00171                 pub_blob->blob.ssrb.svc_set_name, pub_blob->blob.ssrb.svc_set_id);
00172 
00173     if(add_ssrb(&pub_blob->blob.ssrb) != SUCCESS) {
00174         LOG(LOG_ERR, "%s: ssrb add to config failed (already exists) "
00175                 "<%s,%d>", __func__, pub_blob->blob.ssrb.svc_set_name,
00176                 pub_blob->blob.ssrb.svc_set_id);
00177     }
00178     
00179     free(pub_blob);
00180     return 0;
00181 }
00182 
00183 
00196 static int 
00197 gencfg_async_handler(junos_kcom_gencfg_t * gencfg, void * arg __unused)
00198 {
00199     junos_kcom_msg_free(gencfg);
00200     return 0;
00201 }
00202 
00203 
00204 /*** GLOBAL/EXTERNAL Functions ***/
00205 
00206 
00216 int
00217 kcom_init(evContext ctx)
00218 {
00219     int status;
00220     provider_origin_id_t origin_id;
00221     junos_kcom_gencfg_t         kcom_req;
00222     junos_kcom_pub_blob_req_t   kpb_req;
00223     
00224     status = provider_info_get_origin_id(&origin_id);
00225     
00226     if (status) {
00227         LOG(TRACE_LOG_ERR, "%s: Retrieving origin ID failed: %m", __func__);
00228         return status;
00229     }
00230     
00231     status = junos_kcom_init(origin_id, ctx);
00232     INSIST(status == KCOM_OK);
00233 
00234     // Register for IFD notification (listen for ms interfaces going down)
00235     status = junos_kcom_register_ifd_handler(NULL, ifd_down_async_handler);
00236     if(status != KCOM_OK) {
00237         LOG(TRACE_LOG_ERR, "%s: Register ifd handler failed", __func__);
00238     }
00239     
00240     // register for General KCOM GENCFG events
00241     bzero(&kcom_req, sizeof(junos_kcom_gencfg_t));
00242 
00243     kcom_req.opcode       = JUNOS_KCOM_GENCFG_OPCODE_INIT;
00244     kcom_req.user_handler = gencfg_async_handler;
00245 
00246     status = junos_kcom_gencfg(&kcom_req);
00247     if(status != KCOM_OK) {
00248         LOG(TRACE_LOG_ERR, "%s: Request to register for GENCFG notification "
00249                 "failed", __func__);
00250         return status;
00251     }
00252     
00253     bzero(&kpb_req, sizeof(junos_kcom_pub_blob_req_t));
00254 
00255     // register for SSRB KCOM GENCFG events
00256     kpb_req.opcode           = JUNOS_KCOM_PUB_BLOB_REG;
00257     kpb_req.blob_id          = JNX_PUB_EXT_SVC_SSR_BLOB; 
00258     kpb_req.msg_user_info    = NULL;
00259     kpb_req.msg_user_handler = ssrb_async_handler;
00260 
00261     status = junos_kcom_pub_blob_req(&kpb_req);
00262     if(status != KCOM_OK) {
00263         LOG(TRACE_LOG_ERR, "%s: Request to register for public SSR blob "
00264             "notification failed", __func__);
00265         return status;
00266     }
00267     
00268     bzero(&kpb_req, sizeof(junos_kcom_pub_blob_req_t));
00269 
00270     // Now request the KCOM to get all the public blobs registered till now
00271     
00272     kpb_req.opcode  = JUNOS_KCOM_PUB_BLOB_GET_ALL;
00273     kpb_req.blob_id = JNX_PUB_EXT_SVC_SSR_BLOB; // service-set resolution
00274     kpb_req.get_all_user_info = NULL;
00275     kpb_req.get_all_user_func = process_initial_ssrb;
00276 
00277     status = junos_kcom_pub_blob_req(&kpb_req);
00278     if(status != KCOM_OK) {
00279         LOG(TRACE_LOG_ERR, "%s: Request to retrieve public blobs failed",
00280             __func__);
00281         return status;
00282     }
00283     
00284     return status;
00285 }
00286 
00287 
00291 void
00292 kcom_shutdown(void)
00293 {
00294     junos_kcom_pub_blob_req_t   kpb_req;
00295     
00296     junos_trace(EQUILIBRIUM_TRACEFLAG_KCOM, "%s", __func__);
00297 
00298     bzero(&kpb_req, sizeof(junos_kcom_pub_blob_req_t));
00299 
00300     kpb_req.opcode  = JUNOS_KCOM_PUB_BLOB_DEREG;
00301     kpb_req.blob_id = JNX_PUB_EXT_SVC_SSR_BLOB; 
00302 
00303     junos_kcom_pub_blob_req(&kpb_req);
00304 
00305     junos_kcom_shutdown();
00306 }

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