~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/routing/geo-linkstate/gls.c


  1 /*
  2  *
  3  * Copyright (c) 2003 The Regents of the University of California.  All 
  4  * rights reserved.
  5  *
  6  * Redistribution and use in source and binary forms, with or without
  7  * modification, are permitted provided that the following conditions
  8  * are met:
  9  *
 10  * - Redistributions of source code must retain the above copyright
 11  *   notice, this list of conditions and the following disclaimer.
 12  *
 13  * - Neither the name of the University nor the names of its
 14  *   contributors may be used to endorse or promote products derived
 15  *   from this software without specific prior written permission.
 16  *
 17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 20  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  *
 29  */
 30  
 31 
 32 
 33 #include "common.h"
 34 #include "gls_i.h"
 35 #include "hash.h"
 36 #include "dijkstra.h"
 37 
 38 extern node_id_t my_node_id;
 39 extern loc_t my_loc;
 40 
 41 
 42 #define MY_LOG_LEVEL LOG_DEBUG(4)
 43 
 44 
 45 /******************* Emrun Functions **********************/
 46 
 47 
 48 /*
 49  * Simple callback activated when we are asked to shut down by emrun
 50  */
 51 static void gls_app_shutdown(void *data)
 52 {
 53   elog(MY_LOG_LEVEL, "gls application shutting down");
 54   exit(0);
 55 }
 56 
 57 /******************* End Emrun Functions **********************/
 58 
 59 
 60 /*
 61  * set arguments needed by the function which handles updates
 62  */
 63 static void init_gls_state (gls_state_t *gls_state,
 64                        struct routedev_info *tables,
 65                        struct nodeconf *my_cfg) {
 66 
 67   gls_state->info = tables;
 68   /* in the beginning, list of updates is empty, but we allocate the data
 69    * structure itself  */
 70   gls_state->updates = g_queue_new();
 71   /* how long do we sleep upon receiving an update before recomputing the 
 72    * tables (note, that timer will be reset for this same duration if another
 73    * update is received while the timer is "asleep") */
 74   gls_state->recompute_timer_sleeptime = 1000;  /* TODO: configurable */
 75   /* how many times do we reset the timer before forcing recompute? */
 76   gls_state->max_timer_resets = 0;                              /* TODO: configurable */
 77   /* so far, we haven't reset the timer */
 78   gls_state->num_timer_resets = 0;
 79   /* recompute timer is not started */
 80   gls_state->recompute_timer  = NULL;
 81   /* information about the node we're running on */
 82   gls_state->nodecfg          = my_cfg;
 83   
 84   /* init nb_list and count */
 85   gls_state->nb_list = NULL;
 86   gls_state->nb_list_count = 0;
 87 
 88   /* init flood and gls link pointers */
 89   gls_state->flood_link = NULL;
 90   gls_state->gls_link = NULL;
 91 }
 92 
 93 static void init_my_cfg (struct nodeconf *cfg) {
 94   
 95   cfg->id = my_node_id;
 96   cfg->geo.x = loc_trunc(my_loc.x);
 97   cfg->geo.y = loc_trunc(my_loc.y);
 98 
 99 /* udp information is not set */
100 
101   cfg->neighbor_list = NULL;
102 
103   cfg->use_cartesian_symmetric_weights = FALSE;
104 }
105 
106 static int init_routdev_info(struct routedev_info *tables)
107 {
108   assert(tables);
109   
110   tables->rtable = NULL;
111 
112   tables->rtablestatus = NULL;
113   tables->adjstatus = NULL;
114   tables->adjbuf = NULL;
115   tables->rtablebuf = NULL;
116 
117   tables->nodeid = NULL;
118   tables->geo    = NULL;
119   tables->udp    = NULL;
120 
121   /* allocate the table that will contain information about nodes */
122   if (! (tables->nodeid = g_hash_table_new(hash_u32, hash_compare_u32)))
123     {
124       elog(LOG_CRIT, "Error creating a node table (0)");
125       exit(1);
126     }
127   
128   /* allocate the table that will hold pointers to information about nodes,
129    * keyed on the geographical information */
130   if (! (tables->geo = g_hash_table_new(hash_geoinfo, hash_compare_geoinfo)))
131     {
132       elog(LOG_CRIT, "Error creating a geo table");
133       exit(1);
134     }
135 
136   /* allocate the table that will hold pointers to information about nodes,
137    * keyed on the ip/port information */
138   if (! (tables->udp = g_hash_table_new(hash_udp, hash_compare_udp)))
139     {
140       elog(LOG_CRIT, "Error creating a udp table");
141       exit(1);
142     }
143   return 1;
144 
145 }
146 
147 
148 /*
149  * Come up, process configuration file to determine node topology, and create a
150  * routing table. Idle away, waiting for clients' "next hop" requests, and
151  * respond to them. Operates as a 'ROUTE_ROUTEDEV_NAME' device (set in the
152  * gls_i.h)
153  */
154 int 
155 main(int argc, char **argv)
156 {
157   gls_state_t gls_state;
158 
159   struct nodeconf my_cfg;
160 
161   /* routing and book-keeping tables */
162   struct routedev_info tables;
163 
164   emrun_opts_t emrun_opts = {
165     shutdown: gls_app_shutdown
166   };
167 
168   elog(MY_LOG_LEVEL, "Initialization test");
169 
170   elog(LOG_DEBUG(6), "sizeof(gls_pkt_t)=%d",sizeof(gls_pkt_t));
171   elog(LOG_DEBUG(6), "sizeof(gls_addr_t)=%d",sizeof(gls_addr_t));
172   elog(LOG_DEBUG(6), "sizeof(geo_t)=%d",sizeof(geo_t));
173 
174   /* everything in emstar needs this initialization */
175   misc_init(&argc, argv, CVSTAG);
176 
177   /* initialize the routing tables: geo/nodeid/udp */
178   init_routdev_info(&tables);
179 
180   /* initialize status devices for routing tables */
181   tables_status_init(&tables);
182   
183   /* Process file Nodeid and topology removed */
184   init_my_cfg (&my_cfg);
185 
186   /* update_event variable defined. Do we need it anymore? */
187   memset(&gls_state, 0, sizeof(gls_state_t));
188   init_gls_state (&gls_state, &tables, &my_cfg);
189 
190 
191   /* open the default interface */
192   gls_open_link(&gls_state, LINK_INDEX_AUTO);
193 
194   /* Create the upper packetdev interface */
195   gls_register_packetdev(&gls_state);
196 
197   /* open nbr list and nbr list flooding */
198   gls_nblist_open(&gls_state);
199 
200   /* Connect ourselves to emrun, to get shutdown commands */
201   emrun_init(&emrun_opts); /* this should be the last initialization */
202         
203         
204   elog(MY_LOG_LEVEL, "gls service running!");
205   g_main();
206 
207   return 0;
208 }
209 
210 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.