equilibrium-data_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: equilibrium-data_main.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 /* The Application and This Daemon's Documentation: */
00022 
00739 #include "equilibrium-data_main.h"
00740 #include "equilibrium-data_config.h"
00741 #include "equilibrium-data_conn.h"
00742 #include "equilibrium-data_monitor.h"
00743 #include "equilibrium-data_packet.h"
00744 
00745 /*** Constants ***/
00746 
00750 #define DNAME_EQUILIBRIUM_DATA    "equilibrium-data"
00751 
00752 /*** Data Structures ***/
00753 
00754 static evContext mainctx; 
00755 
00756 /*** STATIC/INTERNAL Functions ***/
00757 
00758 
00762 static void 
00763 equilibrium_quit(int signo __unused)
00764 {
00765     LOG(LOG_INFO, "Shutting down");
00766     
00767     close_connections();
00768     
00769     LOG(LOG_INFO, "Shutting down data loops");
00770     destroy_packet_loops(mainctx);
00771     LOG(LOG_INFO, "Shutting down data loops...done");
00772     
00773     clear_config();
00774     
00775     LOG(LOG_INFO, "Stopping server montior");
00776     shutdown_monitor();
00777     
00778     msp_exit();
00779     
00780     LOG(LOG_INFO, "Shutting down finished");
00781     
00782     exit(0);
00783 }
00784 
00785 
00794 static int
00795 equilibrium_init(evContext ctx)
00796 {
00797     int rc;
00798     int other_user_cpu, tmp_cpu;
00799     int monitor_user_cpu;
00800     int mon_core_num, tmp_core_num;
00801 
00802     msp_init();
00803     
00804     // Handle some signals that we may receive:
00805     signal(SIGTERM, equilibrium_quit); // call quit fnc
00806     signal(SIGHUP, SIG_IGN); // ignore
00807     signal(SIGPIPE, SIG_IGN); // ignore
00808     
00809     logging_set_level(LOG_INFO);
00810     logging_set_mode(LOGGING_SYSLOG);
00811     
00812     // call init function for modules:
00813     
00814     mainctx = ctx;
00815     
00816     rc = init_config(ctx);
00817     if(rc != SUCCESS) {
00818         goto failed;
00819     }
00820     
00821     rc = init_connections(ctx);
00822     if(rc != SUCCESS) {
00823         goto failed;
00824     }
00825     
00826     // give the monitor a user cpu number to use
00827     
00828     monitor_user_cpu = msp_env_get_next_user_cpu(MSP_NEXT_NONE);
00829     
00830     rc = init_monitor(ctx, monitor_user_cpu);
00831     if(rc != SUCCESS) {
00832         goto failed;
00833     }
00834     
00835     // find another user cpu number to use for this main thread
00836     tmp_cpu = other_user_cpu = msp_env_get_next_user_cpu(monitor_user_cpu);
00837     
00838     // if at least one valid user cpu available...
00839     if(monitor_user_cpu != MSP_NEXT_END && other_user_cpu != MSP_NEXT_END) {
00840 
00841         mon_core_num = msp_env_cpu_to_core(monitor_user_cpu);
00842         tmp_core_num = msp_env_cpu_to_core(tmp_cpu);
00843         
00844         // try to find a user cpu on a different core from the monitoring
00845         // thread if one exists
00846         while(mon_core_num == tmp_core_num) {
00847             if((tmp_cpu = msp_env_get_next_user_cpu(tmp_cpu)) == MSP_NEXT_END) {
00848                 break;
00849             }
00850             tmp_core_num = msp_env_cpu_to_core(tmp_cpu);
00851         }
00852         
00853         if(tmp_cpu != MSP_NEXT_END) { // it should be on another user core
00854             other_user_cpu = tmp_cpu;
00855         }
00856         // else it will be on the same user core as the monitoring thread
00857         
00858         LOG(LOG_INFO, "%s: Binding main process to user cpu %d",
00859                 __func__, other_user_cpu);
00860         
00861         if(msp_process_bind(other_user_cpu) != SUCCESS) {
00862             goto failed;
00863         }
00864     }
00865     
00866     rc = init_packet_loops(ctx);
00867     if(rc != SUCCESS) {
00868         goto failed;
00869     }
00870 
00871     return SUCCESS;
00872     
00873 failed:
00874 
00875     LOG(LOG_ALERT, "%s: Failed to intialize. "
00876             "See error log for details ", __func__);
00877     equilibrium_quit(0);
00878     return EFAIL;
00879 }
00880 
00881 
00882 /*** GLOBAL/EXTERNAL Functions ***/
00883 
00884 
00897 int
00898 main(int32_t argc , char **argv)
00899 {
00900     mp_sdk_app_ctx_t app_ctx;
00901     int rc;
00902 
00903     app_ctx = msp_create_app_ctx(argc, argv, DNAME_EQUILIBRIUM_DATA);
00904     msp_set_app_cb_init(app_ctx, equilibrium_init);
00905 
00906     rc = msp_app_init(app_ctx);
00907     
00908     /* Should never reach this point */
00909     msp_destroy_app_ctx(app_ctx);
00910     return rc;
00911 }
00912 

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