static void test_instructions( void **state ) { UNUSED( state ); uint64_t metadata = 0x5dd2ca2bcd04d53e; uint64_t metadata_mask = 0x3012174b861ea4fd; instruction *metadata_ins = create_instruction_write_metadata( metadata, metadata_mask ); instruction_list *ins_list = init_instruction_list(); append_instruction( ins_list, metadata_ins ); instruction *meter = create_instruction_meter( 0xc7231908 ); append_instruction( ins_list, meter ); instruction *apply_actions = create_instruction_apply_actions( complete_action_list() ); append_instruction( ins_list, apply_actions ); instruction *clear_actions = create_instruction_clear_actions(); append_instruction( ins_list, clear_actions ); dlist_element *e = get_first_element( ins_list ); if ( e->data == NULL ) { e = ins_list->next; } for (; e; e = e->next ) { if ( e->data != NULL ) { instruction *ins = e->data; printf( "ins type( %u )\n", ins->type ); } } instruction_list *new_ins_list; new_ins_list = copy_instruction_list( ins_list ); remove_instruction( ins_list, meter ); e = get_first_element( ins_list ); if ( e->data == NULL ) { e = ins_list->next; } for (; e; e = e->next ) { if ( e->data != NULL ) { instruction *ins = e->data; printf( "ad ins type( %u )\n", ins->type ); } } e = get_first_element( new_ins_list ); if ( e->data == NULL ) { e = new_ins_list->next; } for (; e; e = e->next ) { if ( e->data != NULL ) { instruction *ins = e->data; printf( "ins type( %u )\n", ins->type ); } } finalize_instruction_list( &new_ins_list ); finalize_instruction_list( &ins_list ); }
// "alpha" <-> "bravo" <-> "charlie" static void test_get_first_element() { char element_data2[] = "bravo"; char element_data3[] = "charlie"; dlist_element *alpha = create_dlist(); dlist_element *bravo = insert_after_dlist( alpha, element_data2 ); dlist_element *charlie = insert_after_dlist( bravo, element_data3 ); assert_true( get_first_element( alpha ) == alpha ); assert_true( get_first_element( bravo ) == alpha ); assert_true( get_first_element( charlie ) == alpha ); delete_dlist( alpha ); }
OFDPE validate_action_list( action_list *list ) { if ( list == NULL ) { return true; } OFDPE ret = OFDPE_SUCCESS; for ( dlist_element *element = get_first_element( list ); element != NULL; element = element->next ) { if ( element->data == NULL ) { continue; } action *action = element->data; if ( action->type == OFPAT_GROUP ) { if ( !group_exists( action->group_id ) ) { ret = ERROR_OFDPE_BAD_ACTION_BAD_OUT_GROUP; break; } } if ( action->type == OFPAT_OUTPUT ) { if ( action->port > 0 && action->port <= OFPP_MAX ) { if ( !switch_port_exists( action->port ) ) { ret = ERROR_OFDPE_BAD_ACTION_BAD_OUT_PORT; } break; } else if ( action->port != OFPP_ALL && action->port != OFPP_FLOOD && action->port != OFPP_IN_PORT && action->port != OFPP_CONTROLLER ) { ret = ERROR_OFDPE_BAD_ACTION_BAD_OUT_PORT; break; } } } return ret; }
static OFDPE validate_buckets( uint8_t type, bucket_list *buckets ) { assert( table != NULL ); assert( buckets != NULL ); OFDPE ret = OFDPE_SUCCESS; for ( dlist_element *element = get_first_element( buckets ); element != NULL; element = element->next ) { if ( element->data == NULL ) { continue; } bucket *bucket = element->data; if ( ( table->features.types & GROUP_TYPE_FF ) != 0 && type == OFPGT_FF ) { if ( !switch_port_exists( bucket->watch_port ) ) { ret = ERROR_OFDPE_GROUP_MOD_FAILED_BAD_WATCH; break; } if ( !group_exists( bucket->watch_group ) ) { ret = ERROR_OFDPE_GROUP_MOD_FAILED_BAD_WATCH; break; } } ret = validate_action_bucket( bucket ); if ( ret != OFDPE_SUCCESS ) { break; } } return ret; }
static void update_reference_counters_in_instruction( instruction *instruction, counter_update_type type ) { assert( instruction != NULL ); if ( instruction->actions == NULL ) { return; } for ( dlist_element *a = get_first_element( instruction->actions ); a != NULL; a = a->next ) { if ( a->data == NULL ) { continue; } action *action = a->data; if ( action->type == OFPAT_GROUP ) { if ( type == INCREMENT ) { increment_reference_count( action->group_id ); } else if ( type == DECREMENT ) { decrement_reference_count( action->group_id ); } else { error( "Undefined counter update type ( %#x ).", type ); } } } }
void test_get_first_element(){ LinkedList list = createList(); void *item = (int *)malloc(sizeof(int)); *(int *)item = 20; int length = add_to_list(&list, item); assert(*(int *)get_first_element(list) == 20); void *item1 = (int *)malloc(sizeof(int)); *(int *)item1 = 10; length = add_to_list(&list, item1); assert(*(int *)get_first_element(list) == 20); printf("First item is the same afetr the insertion of the first element\n"); };
static void make_path( routing_switch *routing_switch, uint64_t in_datapath_id, uint16_t in_port, uint64_t out_datapath_id, uint16_t out_port, const buffer *packet ) { dlist_element *hops = resolve_path( routing_switch->path_resolver, in_datapath_id, in_port, out_datapath_id, out_port ); if ( hops == NULL ) { warn( "No available path found ( %#" PRIx64 ":%u -> %#" PRIx64 ":%u ).", in_datapath_id, in_port, out_datapath_id, out_port ); discard_packet_in( in_datapath_id, in_port, packet ); return; } // ask path manager to install flow entries size_t length = offsetof( path_manager_path, hops ) + sizeof( path_manager_hop ) * count_hops( hops ); path_manager_path *path = xmalloc( length ); set_match_from_packet( &path->match, OFPP_NONE, 0, packet ); path->n_hops = count_hops( hops ); dlist_element *e = get_first_element( hops ); for( int i = 0; e != NULL; e = e->next, i++ ) { path_resolver_hop *hop = e->data; path->hops[ i ].datapath_id = hop->dpid; path->hops[ i ].in_port = hop->in_port_no; path->hops[ i ].out_port = hop->out_port_no; } send_message( PATH_SETUP_SERVICE_NAME, MESSENGER_PATH_SETUP_REQUEST, ( void * ) path, length ); xfree( path ); // send packet out to tail switch output_packet_from_last_switch( hops, packet ); // free hop list free_hop_list( hops ); }
static void make_path( sliceable_switch *sliceable_switch, uint64_t in_datapath_id, uint16_t in_port, uint16_t in_vid, uint64_t out_datapath_id, uint16_t out_port, uint16_t out_vid, const buffer *packet ) { dlist_element *hops = resolve_path( sliceable_switch->pathresolver, in_datapath_id, in_port, out_datapath_id, out_port ); if ( hops == NULL ) { warn( "No available path found ( %#" PRIx64 ":%u -> %#" PRIx64 ":%u ).", in_datapath_id, in_port, out_datapath_id, out_port ); discard_packet_in( in_datapath_id, in_port, packet ); return; } // check if the packet is ARP or not if ( sliceable_switch->handle_arp_with_packetout && packet_type_arp( packet ) ) { // send packet out for tail switch free_hop_list( hops ); output_packet( packet, out_datapath_id, out_port, out_vid ); return; } const uint32_t wildcards = 0; struct ofp_match match; set_match_from_packet( &match, in_port, wildcards, packet ); if ( lookup_path( in_datapath_id, match, PRIORITY ) != NULL ) { warn( "Duplicated path found." ); output_packet( packet, out_datapath_id, out_port, out_vid ); return; } const uint16_t hard_timeout = 0; path *p = create_path( match, PRIORITY, sliceable_switch->idle_timeout, hard_timeout ); assert( p != NULL ); for ( dlist_element *e = get_first_element( hops ); e != NULL; e = e->next ) { pathresolver_hop *rh = e->data; hop *h = create_hop( rh->dpid, rh->in_port_no, rh->out_port_no, NULL ); assert( h != NULL ); append_hop_to_path( p, h ); } // for(;;) dlist_element *e = get_last_element( hops ); pathresolver_hop *last_hop = e->data; packet_out_params *params = xmalloc( sizeof( struct packet_out_params ) ); params->packet = duplicate_buffer( packet ); params->out_datapath_id = last_hop->dpid; params->out_port_no = last_hop->out_port_no; params->out_vid = out_vid; bool ret = setup_path( p, handle_setup, params, NULL, NULL ); if ( ret != true ) { error( "Failed to set up path." ); output_packet( packet, out_datapath_id, out_port, out_vid ); free_buffer( params->packet ); xfree( params ); } delete_path( p ); // free them free_hop_list( hops ); }
void test_get_first_element_char(){ LinkedList list = createList(); char letter[] = "a"; char letter1[] = "b"; add_to_list(&list,letter); add_to_list(&list,letter1); assert(strcmp((char *)get_first_element(list),"a")==0); }
void test_get_first_element_emptystring(){ LinkedList list = createList(); char letter[] = ""; char letter1[] = "babitha"; add_to_list(&list,letter); add_to_list(&list,letter1); assert(strcmp((char *)get_first_element(list),"")==0); }
void test_get_first_element_float(){ LinkedList list = createList(); float a = 15.7,b=20.0; add_to_list(&list,&a); add_to_list(&list,&b); float first = *(float *)get_first_element(list); assert(first==a); }
void test_get_first_element(){ LinkedList list = createList(); int num = 10,num1 = 9,num2 = 8; add_to_list(&list,&num); add_to_list(&list,&num1); add_to_list(&list,&num2); int result = *(int *)get_first_element(list); assert(10==result); }
static int count_hops( dlist_element *hops ) { int i = 0; for ( dlist_element *e = get_first_element( hops ); e != NULL; e = e->next ) { i++; } return i; }
void test_get_first_element(){ LinkedList list = createList(); int number = 44, number2 = 33, number3 = 23; add_to_list(&list, &number); add_to_list(&list, &number2); add_to_list(&list, &number3); void *first_element = get_first_element(list); assert(_TYPEINT_(first_element) == 44); };
void test_get_first_element_double() { LinkedList list = createList(); double value = 4.302; double value1 = 3.211; double value2 = 7.02; add_to_list(&list, &value); add_to_list(&list, &value1); add_to_list(&list, &value2); assert(4.302 == *(double *)get_first_element(list)); };
void first_element(void) { LinkedList list = create(); int x = 3; int y = 5; add(&list, &x); add(&list, &y); Element *ele = get_first_element(list); int *value = ele -> value; assert(*value == 3); };
void test_get_first_element_char() { LinkedList list = createList(); char value = 'S'; char value1 = 'A'; char value2 = 'X'; add_to_list(&list, &value); add_to_list(&list, &value1); add_to_list(&list, &value2); assert('S' == *(char *)get_first_element(list)); };
void test_get_first_element_string() { LinkedList list = createList(); char value[] = "The"; char value1[] = "World"; char value2[] = "Beautiful"; add_to_list(&list, &value); add_to_list(&list, &value1); add_to_list(&list, &value2); assert(value == (char *)get_first_element(list)); };
void test_get_first_element_float() { LinkedList list = createList(); float value = 4.302; float value1 = 3.211; float value2 = 7.02; add_to_list(&list, &value); add_to_list(&list, &value1); add_to_list(&list, &value2); assert(value == *(float *)get_first_element(list)); };
void test_get_first_element_int() { LinkedList list = createList(); int value = 4; int value1 = 3; int value2 = 7; add_to_list(&list, &value); add_to_list(&list, &value1); add_to_list(&list, &value2); assert(4 == *(int *)get_first_element(list)); };
void test_get_first_element() { LinkedList list = createList(); int element = 12; add_to_list(&list,&element); int element1 = 13; add_to_list(&list,&element1); int element2 = 14; add_to_list(&list,&element2); int *value = get_first_element(list); assert(12 == *value); }
void dump_action_list( action_list *list, void dump_function( const char *format, ... ) ) { assert( dump_function != NULL ); for ( dlist_element *e = get_first_element( list ); e != NULL; e = e->next ) { if ( e->data == NULL ) { continue; } dump_action( e->data, dump_function ); } }
void delete_action_list( action_list *list ) { assert( list != NULL ); for ( dlist_element *element = get_first_element( list ); element != NULL; element = element->next ) { action *action = element->data; if ( action != NULL ) { delete_action( action ); } } delete_dlist( list ); }
void delete_action_bucket_list( bucket_list *list ) { assert( list != NULL ); dlist_element *element = get_first_element( list ); while ( element != NULL ) { bucket *b = element->data; if ( b != NULL ) { delete_action_bucket( b ); } element = element->next; } delete_dlist( list ); }
void test_reverse_using_getFirstElement(){ LinkedList list = createList(); int number = 12, number2 = 33, number3 = 23, number4 = 44, number5 = 23; add_to_list(&list, &number); add_to_list(&list, &number2); add_to_list(&list, &number3); add_to_list(&list, &number4); add_to_list(&list, &number5); LinkedList reverse_list = reverse(list); void *get_reverse_ele = get_first_element(reverse_list); assert(_TYPEINT_(get_reverse_ele) == 23); };
OFDPE remove_action( action_list *list, action *action ) { assert( list != NULL ); assert( action != NULL ); dlist_element *element = find_element( get_first_element( list ), action ); if ( element == NULL ) { return ERROR_NOT_FOUND; } delete_action( action ); delete_dlist_element( element ); return OFDPE_SUCCESS; }
void test_to_get_first_element_of_list() { LinkedList list = createList(); int ele1 = 25; int ele2 = 55; int ele3 = 35; int ele4 = 15; int ele5 = 5; add_to_list(&list,&ele1); add_to_list(&list,&ele2); add_to_list(&list,&ele3); add_to_list(&list,&ele4); add_to_list(&list,&ele5); void *head = get_first_element(list); assert(*(int *)head==25); };
size_t get_ofp_buckets_length( bucket_list *buckets ) { assert( buckets != NULL ); size_t length = 0; for ( dlist_element *e = get_first_element( buckets ); e != NULL; e = e->next ) { if ( e->data == NULL ) { continue; } length += get_ofp_bucket_length( e->data ); } return length; }
uint32_t get_bucket_count( bucket_list *list ) { assert( list != NULL ); uint32_t count = 0; dlist_element *element = get_first_element ( list ); while ( element != NULL ) { if ( element->data != NULL ) { count++; } element = element->next; } return count; }
bucket_list * duplicate_bucket_list( bucket_list *buckets ) { if ( buckets == NULL ) { return NULL; } bucket_list *duplicated = create_action_bucket_list(); for ( dlist_element *e = get_first_element( buckets ); e != NULL; e = e->next ) { if ( e->data == NULL ) { continue; } append_action_bucket( duplicated, duplicate_bucket( e->data ) ); } return duplicated; }