void operator()(const NumberT) { if(m_left->derived_type_name() != m_right->derived_type_name()) throw common::SetupError(FromHere(), "Array types do not match"); Handle< List<NumberT> const > left_list(m_left); Handle< List<NumberT> const > right_list(m_right); if(is_not_null(left_list) && is_not_null(right_list)) { m_found_type = true; if(left_list->size() != right_list->size()) { CFdebug << m_prefix << "Array sizes don't match: left: " << left_list->size() << ", right: " << right_list->size() << CFendl; m_arrays_equal = false; return; } compare_lists(boost::is_floating_point<NumberT>(), *left_list, *right_list); } else { Handle< Table<NumberT> const > left_table(m_left); Handle< Table<NumberT> const > right_table(m_right); if(is_not_null(left_table) && is_not_null(right_table)) { m_found_type = true; if(left_table->size() != right_table->size() || left_table->row_size() != right_table->row_size()) { CFdebug << m_prefix << "Array sizes don't match: left: " << left_table->size() << "x" << left_table->row_size() << ", right: " << right_table->size() << "x" << right_table->row_size() << CFendl; m_arrays_equal = false; return; } compare_tables(boost::is_floating_point<NumberT>(), *left_table, *right_table); } } }
int main(int argc, char * argv[]) { system("clear"); signal(SIGINT, interrupt); ipv4_addr_t multiaddress; ipv4_str_addr (RIP_MULTICAST_IPv4, multiaddress); if(argc == 2) { if( !strcmp(argv[1], "--verbose")) { is_verbose = 1; print_warning("(Debug mode ON) \n"); } } else printf("(Run with --verbose to print more info)\n"); bold ("Starting RIP Server... \t\t\t\t\t"); print_success("[ OK ]\n"); table = rip_table_create (); if (initialize_rip (table, RIP_PORT) == -1) { /* Already printed advert inside function */ return -1; } int K = rip_route_table_read ( RIP_TABLE_TXT, table ); /* set inf timer to routes read from file */ int k; for( k = 0; k < K; k++ ) { timerms_reset(&table->routes[k]->time, INFINITE_TIMER); } rip_table_t * table_aux; ipv4_addr_t src; long int r = random_number(-15, 15)*1000; //SEND UNSOLICITED RESPONSE MESSAGES EVERY 30 SECONDS +- 15s timerms_t update_timer = timer_start ( UPDATE_TIME + r ); //SEND REQUEST TO FILL ROUTE TABLE rip_route_table_print ( table ); for ( ;; ) { if (timer_ended (update_timer)) { /* Si se ha acabado el update timer */ send_rip_response (multiaddress, message_ptr, table, RIP_PORT); r = random_number(-15, 15)*1000; if ( is_verbose ) printf("(update_time set to %ld)\n", r +UPDATE_TIME); update_timer = timer_start (UPDATE_TIME + r); bold ("\nCurrent table:\n"); rip_route_table_print ( table ); } int src_port; int bytes_received = rip_recv (src, message_ptr, MIN_TIMER, &src_port); //WE RECEIVE A MESSAGE if (bytes_received>0) { //WE CONVERT THE MESSAGE TO A ROUTE TABLE FORMAT table_aux = convert_message_table (message_ptr, rip_number_entries(bytes_received)); if ( is_verbose ) { print_notice ("\nReceived packet\n"); print_packet (message_ptr, rip_number_entries(bytes_received)); } //IF THE MESSAGE IS A RESPONSE... if (message_ptr->command == 2) { //VALIDATE (HAY QUE IMPLEMENTARLO) //number of entries in the received message int num_entries = rip_number_entries (bytes_received); int trig_update_flag = 0; //by default, when receiving, do not send update //AND THIS IS WHERE THE MAGIC HAPPENS, WE PROCESS THE RESPONSE MESSAGE trig_update_flag = compare_tables (table, table_aux, num_entries, src); if (trig_update_flag) { send_rip_response (multiaddress, message_ptr, table, RIP_PORT); } bold ("\nCurrent table:\n"); rip_route_table_print ( table ); } if (message_ptr->command == 1 && metric_is_inf(ntohl(message_ptr->entry[0].metric))) { //IF REQUEST FOR WHOLE TABLE, RESPOND WITH WHOLE TABLE print_warning("Received a request for single entry, sending whole table\n"); send_rip_response (src, message_ptr, table, src_port); } else if (message_ptr->command == 1) { //IF REQUEST FOR SPECIFIC ENTRIES, RESPOND WITH SPECIFIC ENTRIES IF FOUND print_warning("Received a request for specific entries\n"); rip_table_t * table_send = table_to_send (table, table_aux); send_rip_response (src, message_ptr, table_send, src_port); } } int is_garbage_on = garbage_collector_start (table, garbage_collector_timers); int garbage_collected = garbage_collector (table, garbage_collector_timers); if (garbage_collected || is_garbage_on) { if(garbage_collected) print_notice("Garbage Collected \n"); else if(is_garbage_on) print_notice("Garbage countdown ON\n"); if( is_verbose ) rip_route_table_print(table); } } return 0; }
struct plum *bpf_dp_register_plum(struct bpf_image *image, struct plum *old_plum, bool alloc_tbl) { int ret; struct bpf_program *bpf_prog; struct plum *plum; struct hlist_head *replicators = NULL; int i; int tsize; union table_priv { struct plum_hash_table htable; struct plum_lpm_table ltable; }; ret = bpf_load(image, &bpf_plum_cb, &bpf_prog); if (ret < 0) { pr_err("BPF load failed %d\n", ret); return ERR_PTR(ret); } if (old_plum && !alloc_tbl && compare_tables(old_plum, bpf_prog)) { ret = -EINVAL; goto err_free_bpf_prog; } ret = -ENOMEM; plum = kzalloc(sizeof(*plum), GFP_KERNEL); if (!plum) goto err_free_bpf_prog; plum->bpf_prog = bpf_prog; plum->num_tables = bpf_prog->table_cnt; if (!old_plum) { alloc_tbl = true; replicators = kzalloc(PLUM_MAX_REPLICATORS * sizeof(struct hlist_head), GFP_KERNEL); if (!replicators) goto err_free_plum; plum->replicators = replicators; for (i = 0; i < PLUM_MAX_REPLICATORS; i++) INIT_HLIST_HEAD(&plum->replicators[i]); } else { if (!alloc_tbl) plum->tables = old_plum->tables; plum->replicators = old_plum->replicators; memcpy(&plum->ports[0], &old_plum->ports[0], sizeof(old_plum->ports[0]) * PLUM_MAX_PORTS); memcpy(&plum->stats[0], &old_plum->stats[0], sizeof(old_plum->stats[0]) * PLUM_MAX_PORTS); } if (alloc_tbl) { if (bpf_prog->table_cnt) { plum->tables = kzalloc(bpf_prog->table_cnt * sizeof(*plum->tables), GFP_KERNEL); if (!plum->tables) goto err_free_replicators; tsize = sizeof(struct plum_table); tsize += ALIGN(sizeof(struct plum_table), PLUM_TABLE_ALIGN); tsize += sizeof(union table_priv); for (i = 0; i < bpf_prog->table_cnt; i++) { plum->tables[i] = kzalloc(tsize, GFP_KERNEL); if (!plum->tables[i]) goto err_free_tables; memcpy(&plum->tables[i]->info, &bpf_prog->tables[i], sizeof(struct bpf_table)); } if (init_plum_tables(plum) < 0) goto err_free_table_array; } } if (bpf_prog->jit_image) plum->run = (void (*)(struct bpf_dp_context *ctx))bpf_prog->jit_image; else plum->run = bpf_run_wrap; return plum; err_free_tables: for (i = 0; i < bpf_prog->table_cnt; i++) kfree(plum->tables[i]); err_free_table_array: kfree(plum->tables); err_free_replicators: kfree(replicators); err_free_plum: kfree(plum); err_free_bpf_prog: bpf_free(bpf_prog); return ERR_PTR(ret); }
static int walk_log(WT_SESSION *session) { WT_CONNECTION *wt_conn2; WT_CURSOR *cursor, *cursor2; WT_LSN lsn, lsnsave; WT_ITEM logrec_key, logrec_value; WT_SESSION *session2; uint64_t txnid; uint32_t fileid, opcount, optype, rectype; int first, i, in_txn, ret; ret = setup_copy(&wt_conn2, &session2); ret = session->open_cursor(session, "log:", NULL, NULL, &cursor); ret = session2->open_cursor(session2, uri, NULL, "raw=true", &cursor2); i = 0; in_txn = 0; txnid = 0; memset(&lsnsave, 0, sizeof(lsnsave)); while ((ret = cursor->next(cursor)) == 0) { ret = cursor->get_key(cursor, &lsn.file, &lsn.offset, &opcount); /* * Save one of the LSNs we get back to search for it * later. Pick a later one because we want to walk from * that LSN to the end (where the multi-step transaction * was performed). Just choose the record that is MAX_KEYS. */ if (++i == MAX_KEYS) lsnsave = lsn; ret = cursor->get_value(cursor, &txnid, &rectype, &optype, &fileid, &logrec_key, &logrec_value); print_record(&lsn, opcount, rectype, optype, txnid, fileid, &logrec_key, &logrec_value); /* * If we are in a transaction and this is a new one, end * the previous one. */ if (in_txn && opcount == 0) { ret = session2->commit_transaction(session2, NULL); in_txn = 0; } /* * If the operation is a put, replay it here on the backup * connection. Note, we cheat by looking only for fileid 1 * in this example. The metadata is fileid 0. */ if (fileid == 1 && rectype == WT_LOGREC_COMMIT && optype == WT_LOGOP_ROW_PUT) { if (!in_txn) { ret = session2->begin_transaction(session2, NULL); in_txn = 1; } cursor2->set_key(cursor2, &logrec_key); cursor2->set_value(cursor2, &logrec_value); ret = cursor2->insert(cursor2); } } if (in_txn) ret = session2->commit_transaction(session2, NULL); ret = cursor2->close(cursor2); /* * Compare the tables after replay. They should be identical. */ if (compare_tables(session, session2)) printf("compare failed\n"); ret = session2->close(session2, NULL); ret = wt_conn2->close(wt_conn2, NULL); ret = cursor->reset(cursor); /*! [log cursor set_key] */ cursor->set_key(cursor, lsnsave.file, lsnsave.offset, 0); /*! [log cursor set_key] */ /*! [log cursor search] */ ret = cursor->search(cursor); /*! [log cursor search] */ printf("Reset to saved...\n"); /* * Walk all records starting with this key. */ first = 1; while ((ret = cursor->get_key(cursor, &lsn.file, &lsn.offset, &opcount)) == 0) { if (first) { first = 0; if (lsnsave.file != lsn.file || lsnsave.offset != lsn.offset) { fprintf(stderr, "search returned the wrong LSN\n"); exit (1); } } ret = cursor->get_value(cursor, &txnid, &rectype, &optype, &fileid, &logrec_key, &logrec_value); print_record(&lsn, opcount, rectype, optype, txnid, fileid, &logrec_key, &logrec_value); ret = cursor->next(cursor); if (ret != 0) break; } ret = cursor->close(cursor); return (ret); }