/* File : timer.c - pc timer handler */ /* Copyright (C) 1992 Indian Institute of Technology, Bombay Written by V. Srinivas and Vishwas Joglekar, Dept of Computer Science and Engineering. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #define TIMER_INT 0x1c #include #include #include "yapcbr.h" #include "ipxwatch.h" #include "ipxrip.h" #include "sap.h" #include "diag.h" extern ROUT_TABLE *rip_lookup[]; extern struct sap_tbl *sap_lookup[]; extern int send_diag; extern struct network_info *current_net, *pred_net; extern struct time t; WORD ticks = 200; WORD sec=0; void interrupt (*old_clock_handler)(); void interrupt clock_tick(); void flush_rip_table(); void flush_sap_table(); void flush_node_table(struct network_info *net); /* this handler is invoked for every clock tick */ void interrupt clock_tick() { ticks = ticks-1; if(ticks == 0){ ticks = 200; sec+=10; if(sec == DIAG_TX_INTERVAL){ send_diag = TRUE; /* flag to indicate that the diagnostic configuration request packets are to be sent */ sec = 0; /* decrement the elapsed time entries in the sap and rip table */ flush_sap_table(); flush_rip_table(); flush_node_table(current_net); flush_node_table(pred_net); } old_clock_handler(); } } void init_timer() { old_clock_handler = getvect(TIMER_INT); setvect(TIMER_INT,clock_tick); } void release_timer() { setvect(TIMER_INT,old_clock_handler); } /* decrement the age_timer on every clock tick */ int l; ROUT_TABLE *rip_ptr,*old_ptr,*tmp; void flush_rip_table() { for(l=0;l< MAX_PRIME;l++){ rip_ptr = rip_lookup[l]; for(rip_ptr=rip_lookup[l];rip_ptr!=0;rip_ptr=rip_ptr->next){ old_ptr = rip_ptr; if(rip_ptr->route_info.no_of_hops > 0) rip_ptr->age_timer -=10; if(rip_ptr->age_timer <= 0 && rip_ptr->route_info.no_of_hops >0){ /* delete the entry from the table */ if(rip_ptr->alternate_route == 0){ if(rip_ptr == rip_lookup[l]){ rip_lookup[l] = rip_ptr->next; ibuf_free(rip_ptr,NOVLRIP);/* return the freed buffer to the buffer pool */ } else{ old_ptr->next = rip_ptr->next; ibuf_free(rip_ptr,NOVLRIP); continue; } } else{ /* if there is an alternate route */ if(rip_ptr == rip_lookup[l]){ rip_lookup[l] = rip_ptr->alternate_route; ibuf_free(rip_ptr,NOVLRIP); } else{ old_ptr->next = rip_ptr->alternate_route; rip_ptr->alternate_route->next = rip_ptr->next; ibuf_free(rip_ptr,NOVLRIP); continue; } } } else { if(rip_ptr->alternate_route != 0 && rip_ptr->route_info.no_of_hops>0){ rip_ptr->alternate_route->age_timer -=10; if(rip_ptr->alternate_route->age_timer == 0){ ibuf_free(rip_ptr->alternate_route,NOVLRIP); rip_ptr->alternate_route =0; } } } old_ptr = rip_ptr; } /* for */ } /* for */ } /* decrement the timer entries in the server information table */ int k,serv_count=0,temp; struct sap_tbl *tsap_ptr,*tmp_ptr; void flush_sap_table() { for(k=0;k< MAX_PRIME;k++){ for(tsap_ptr = sap_lookup[k]; tsap_ptr != NULLHPTR;tsap_ptr = tsap_ptr->next){ tmp_ptr = tsap_ptr; tsap_ptr->elapsed_time -=10; if(tsap_ptr->elapsed_time <= (WORD) 0){ /* delete entry from the table */ if(tsap_ptr == sap_lookup[k]){ sap_lookup[k] = tsap_ptr->next; ibuf_free(tsap_ptr,NOVLSAP); } else{ tmp_ptr->next = tsap_ptr->next; ibuf_free(tsap_ptr,NOVLSAP); #ifdef TDEBUG printf("\n Timer expired, sap table entry deleted \n"); #endif continue; } } } /* for */ } /* for */ } /* decrement the timer entries in the node information table for the current network */ int ii; NODE_INFO *cnode; void flush_node_table(struct network_info *net) { if(net == 0) return; for(ii=0;iinode_info.node_info_table[ii].head; while(cnode!=0){ if(cnode->clock_ticks >0){ cnode->clock_ticks -=10; if(cnode->clock_ticks == 0 && cnode->status == ACTIVE){ cnode->status = INACTIVE; memcpy(&cnode->down_time,&t,sizeof(t)); /* save the current time */ } } cnode = cnode->next; } } }