void Allegro_midifile_reader::Mf_tempo(int tempo) { double beat = get_currtime(); beat = beat / divisions; // convert to quarters // 6000000 us/min / n us/beat => beat / min double bps = 60000000.0 / tempo; seq->insert_tempo(bps, beat); }
void hello_send(void *arg) { RREP *rrep; AODV_ext *ext = NULL; u_int8_t flags = 0; u_int64_t time_expired; rt_table_t *entry; int msg_size = RREP_SIZE; time_expired = get_currtime() - this_host->bcast_time; /* This check will ensure we don't send unnecessary hello msgs, in case we have sent other bcast msgs within HELLO_INTERVAL */ if (time_expired >= HELLO_INTERVAL) { #ifdef DEBUG_HELLO log(LOG_DEBUG, 0, "SEND_BCAST: sending Hello to %s", ip_to_str(AODV_BROADCAST)); #endif rrep = rrep_create(flags, 0, 0, this_host->ipaddr, this_host->seqno, this_host->ipaddr, ALLOWED_HELLO_LOSS*HELLO_INTERVAL); /* Assemble a RREP extension which contain our neighbor set... */ if(unidir_hack) { u_int32_t neigh; int i; ext = (AODV_ext *)((char *)rrep + RREP_SIZE); ext->type = RREP_HELLO_NEIGHBOR_SET_EXT; ext->length = 0; for(i = 0; i < RT_TABLESIZE; i++) { entry = routing_table[i]; while(entry != NULL) { /* If an entry has an active hello timer, we asume that we are receiving hello messages from that node... */ if(entry->hello_timer_id != 0) { #ifdef DEBUG_HELLO log(LOG_INFO, 0, "hello_send: Adding %s to hello neighbor set ext", ip_to_str(entry->dest)); #endif neigh = htonl(entry->dest); memcpy(AODV_EXT_NEXT(ext), &neigh, 4); ext->length += 4; } entry = entry->next; } } if(ext->length) msg_size = RREP_SIZE + AODV_EXT_SIZE(ext); } aodv_socket_send((AODV_msg *)rrep, AODV_BROADCAST, msg_size, 1); timer_new(HELLO_INTERVAL, hello_send, NULL); } else { timer_new((HELLO_INTERVAL - time_expired), hello_send, NULL); } }
rt_table_t *rt_table_update_timeout(rt_table_t *entry, u_int32_t life) { entry->expire = get_currtime() + life; timer_remove(entry->timer_id); #ifdef DEBUG /* log(LOG_INFO, 0, "rt_table_update(): New timer for %s, life=%d", */ /* ip_to_str(entry->dest), newlife); */ #endif entry->timer_id = timer_new(life, route_expire_timeout, entry); return entry; }
rt_table_t *rt_table_insert(u_int32_t dest, u_int32_t next, u_int8_t hops, u_int32_t seqno, u_int32_t life, u_int16_t flags) { rt_table_t *entry; hash_value hash; unsigned int index; /* Calculate hash key */ index = hashing(&dest, &hash); entry = routing_table[index]; /* printf("rt_table_insert(): Adding dest=%s, nex_hop=%s\n", ip_to_str(dest), ip_to_str(next)); */ #ifdef DEBUG log(LOG_INFO, 0, "rt_table_insert: Inserting %s into bucket %d", ip_to_str(dest), index); if(entry != NULL) log(LOG_INFO, 0, "rt_table_insert: Collision in bucket %s detected!", index); #endif /* Check if we already have an entry for dest */ while(entry != NULL) { if(memcmp(&entry->dest, &dest, sizeof(u_int32_t)) == 0) return NULL; } if((entry = (rt_table_t *)malloc(sizeof(rt_table_t))) == NULL) { fprintf(stderr, "insert_rt_table: Malloc failed!\n"); exit(-1); } entry->dest = dest; entry->next_hop = next; entry->dest_seqno = seqno; entry->expire = get_currtime() + life; entry->flags = flags; entry->hcnt = hops; entry->last_hcnt = 0; entry->last_life = life; entry->precursors = NULL; entry->hash = hash; entry->ack_timer_id = 0; entry->hello_timer_id = 0; /* Insert first in bucket... */ entry->next = routing_table[index]; routing_table[index] = entry; total_entries++; /* We should also update our own sequence number whenever our neighbor set changes. (AODV draft v.8, section 8.4.1.) */ if(hops == 1) this_host->seqno++; /* Add route to kernel routing table ... */ if(dest == next) k_add_rte(dest, 0, 0, hops); else k_add_rte(dest, next, 0, hops); /* flush_rt_cache(); */ #ifdef DEBUG log(LOG_INFO, 0, "rt_table_insert: New timer for %s, life=%d", ip_to_str(entry->dest), life); #endif entry->timer_id = timer_new(life, route_expire_timeout, entry); return entry; }
double Allegro_midifile_reader::get_time() { double beat = ((double) get_currtime()) / divisions; return seq->map.beat_to_time(beat); }
int main (int argc, char **argv) { static char *ifname = NULL; /* Name of interface to attach to */ fd_set rfds, readers; int n, nfds = 0, i; int daemonize = 0; /* Remember the name of the executable... */ progname = strrchr(argv[0], '/'); if (progname) progname++; else progname = argv[0]; /* Use debug output as default */ debug = 1; /* Parse command line: */ argc--; argv++; while(argc) { if(argv[0][0] == '-') { switch(argv[0][1]) { case 'i': if(argv[1] != NULL) { ifname = argv[1]; argc--; argv++; break; } print_usage(); exit(-1); case 'd': debug = 0; daemonize = 1; break; case 'l': log_to_file = 1; break; case 'u': unidir_hack = 1; break; case 'g': rreq_gratuitous = 1; break; case 't': log_rt_table = 1; if(argv[1] != NULL && argv[1][0] != '-') { printf("arg: %d\n", atoi(argv[1])); rt_log_interval = atoi(argv[1])*1000; argc--; argv++; } break; default: print_usage(); exit(-1); } } else { fprintf(stderr, "Unknown option: %s\n", argv[0]); print_usage(); exit(-1); } argc--; argv++; } /* Check that we are running as root */ if (geteuid() != 0) { fprintf(stderr, "aodvd: must be root\n"); exit(1); } /* Detach from terminal */ if(daemonize) { if (fork() != 0) exit(0); /* Close stdin, stdout and stderr... */ close(0); close(1); close(2); setsid(); } /* Initialize data structures and services... */ host_init(ifname); log_init(); timer_queue_init(); rt_table_init(); packet_input_init(); aodv_socket_init(); log(LOG_NOTICE, 0, "INIT: Attaching to interface %s, override with -i <interface>.",this_host->ifname); /* Make sure we cleanup at exit... */ atexit((void *)&cleanup); /* Make sure we run at high priority to make up for the user space packet processing... */ /* nice(-5); */ /* Catch SIGHUP, SIGINT and SIGTERM type signals */ signal(SIGHUP, signal_handler); signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); /* Only capture segmentation faults when we are not debugging... */ #ifndef DEBUG signal(SIGSEGV, signal_handler); #endif /* Set sockets to watch... */ FD_ZERO(&readers); for (i = 0; i < nr_callbacks; i++) { FD_SET(callbacks[i].fd, &readers); if (callbacks[i].fd >= nfds) nfds = callbacks[i].fd + 1; } /* Set bcast_time, which ensures that we don't send unnecessary hello msgs. */ this_host->bcast_time = get_currtime(); /* Schedule the first Hello */ timer_new(HELLO_INTERVAL, hello_send, NULL); if(log_rt_table) timer_new(rt_log_interval, print_rt_table, NULL); while(1) { memcpy((char *)&rfds, (char *)&readers, sizeof(rfds)); if ((n = select(nfds, &rfds, NULL, NULL, NULL)) < 0) { if (errno != EINTR) log(LOG_WARNING, errno, "main.c: Failed select (main loop)"); continue; } if (n > 0) { for (i = 0; i < nr_callbacks; i++) { if (FD_ISSET(callbacks[i].fd, &rfds)) { /* We don't want any timer SIGALRM's while executing the callback functions, therefore we block the timer... */ timer_block(); (*callbacks[i].func)(callbacks[i].fd); timer_unblock(); } } } } /* Main loop */ return 0; }
void route_expire_timeout(void *arg) { rt_table_t *rt_entry; #ifdef DEBUG u_int32_t now = get_currtime(); #endif rt_entry = (rt_table_t *)arg; if(rt_entry == NULL) { log(LOG_WARNING, 0, "route_expire_timer: arg was NULL, ignoring timeout!"); return; } #ifdef DEBUG log(LOG_DEBUG, 0, "route_expire_timeout: %s curT=%lu exp=%lu", ip_to_str(rt_entry->dest_addr), now, rt_entry->expire); #endif /* If hopcount = 1, this is a direct neighbor and a link break has occured. Send a RERR with the incremented sequence number */ if(rt_entry->hcnt == 1) { RERR *rerr; rt_table_t *u_entry; int i; #ifdef DEBUG log(LOG_DEBUG, 0, "route_expire_timeout: LINK FAILURE for %s, seqno=%d", ip_to_str(rt_entry->dest_addr), rt_entry->dest_seqno); #endif /* Create a route error msg */ rerr = rerr_create(0, rt_entry->dest_addr, rt_entry->dest_seqno); /* Check the routing table for entries which have the unreachable destination (dest) as next hop. These entries (destinations) cannot be reached either since dest is down. They should therefore also be included in the RERR. */ for(i = 0; i < RT_TABLESIZE; i++) { for (u_entry = routing_table[i]; u_entry != NULL; u_entry = u_entry->next) { if ((u_entry->next_hop == rt_entry->dest_addr) && (u_entry->dest_addr != rt_entry->dest_addr)) { if(u_entry->precursors != NULL) { rerr_add_udest(rerr, u_entry->dest_addr, u_entry->dest_seqno); #ifdef DEBUG log(LOG_DEBUG, 0, "route_expire_timeout: Added %s as unreachable, seqno=%d", ip_to_str(u_entry->dest_addr), u_entry->dest_seqno); #endif rerr->dest_count++; } rt_table_invalidate(u_entry); } } } /* FIXME: Check if we should unicast the RERR. This check does not catch all cases when we could unicast (like when several unreachable destinations have the same precursor). */ if(rerr->dest_count == 1 && rt_entry->precursors != NULL && rt_entry->precursors->next == NULL) aodv_socket_send((AODV_msg *)rerr, rt_entry->precursors->neighbor, RERR_CALC_SIZE(rerr), 1); else if(rerr->dest_count > 1 && (rt_entry->precursors != NULL)) aodv_socket_send((AODV_msg *)rerr, AODV_BROADCAST, RERR_CALC_SIZE(rerr), 1); #ifdef DEBUG else log(LOG_DEBUG, 0, "route_expire_timeout: No precursors, dropping RERR"); #endif } /* Now also invalidate the entry of the link that broke... */ rt_table_invalidate(rt_entry); }