Esempio n. 1
0
static void
test_insert_existing_same_priority_wildcards_entry_succeeds() {
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  oxm_matches *alice_wildcards = create_oxm_matches();
  set_alice_wildcards_entry( alice_wildcards );
  assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) );

  oxm_matches *bob = create_oxm_matches();
  set_bob_match_entry( bob );
  oxm_matches *bob_wildcards = create_oxm_matches();
  set_bob_wildcards_entry( bob_wildcards );
  assert_true( insert_match_entry( bob_wildcards, DEFAULT_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) );

  void *data0 = lookup_match_strict_entry( bob_wildcards, DEFAULT_PRIORITY );
  assert_true( data0 != NULL );
  assert_string_equal( ( char * ) data0, BOB_MATCH_SERVICE_NAME );
  void *data1 = lookup_match_entry( bob );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, BOB_MATCH_SERVICE_NAME );
  assert_true( data0 == data1 );

  oxm_matches *any_wildcards = create_oxm_matches();
  set_any_wildcards_entry( any_wildcards );
  assert_true( insert_match_entry( any_wildcards, DEFAULT_PRIORITY, xstrdup( ANY_MATCH_SERVICE_NAME ) ) );

  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) );

  data0 = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY );
  assert_true( data0 != NULL );
  assert_string_equal( ( char * ) data0, CAROL_MATCH_SERVICE_NAME );
  data1 = lookup_match_entry( carol );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, ANY_MATCH_SERVICE_NAME );
  assert_true( data0 != data1 );

  data1 = lookup_match_entry( alice );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME );
  data1 = lookup_match_entry( bob );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, BOB_MATCH_SERVICE_NAME );

  XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) );
  XFREE( delete_match_strict_entry( bob_wildcards, DEFAULT_PRIORITY ) );
  XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) );
  XFREE( delete_match_strict_entry( any_wildcards, DEFAULT_PRIORITY ) );

  delete_oxm_matches( alice );
  delete_oxm_matches( alice_wildcards );
  delete_oxm_matches( bob );
  delete_oxm_matches( bob_wildcards );
  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );
  delete_oxm_matches( any_wildcards );
}
Esempio n. 2
0
static void
test_insert_lowest_priority_wildcards_entry_succeeds() {
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  oxm_matches *alice_wildcards = create_oxm_matches();
  set_alice_wildcards_entry( alice_wildcards );
  assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) );

  oxm_matches *bob_wildcards = create_oxm_matches();
  set_bob_wildcards_entry( bob_wildcards );
  assert_true( insert_match_entry( bob_wildcards, LOW_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) );

  void *data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY );
  assert_true( data0 != NULL );
  assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME );
  void *data1 = lookup_match_entry( alice );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME );
  assert_true( data0 == data1 );

  oxm_matches *lldp_wildcards = create_oxm_matches();
  set_lldp_wildcards_entry( lldp_wildcards );
  assert_true( insert_match_entry( lldp_wildcards, LOW_PRIORITY, xstrdup( LLDP_MATCH_SERVICE_NAME ) ) );

  data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY );
  assert_true( data0 != NULL );
  assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME );
  data1 = lookup_match_entry( alice );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME );
  assert_true( data0 == data1 );

  oxm_matches *any_wildcards = create_oxm_matches();
  set_any_wildcards_entry( any_wildcards );
  assert_true( insert_match_entry( any_wildcards, LOW_PRIORITY, xstrdup( ANY_MATCH_SERVICE_NAME ) ) );

  data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY );
  assert_true( data0 != NULL );
  assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME );
  data1 = lookup_match_entry( alice );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME );
  assert_true( data0 == data1 );

  XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) );
  XFREE( delete_match_strict_entry( bob_wildcards, LOW_PRIORITY ) );
  XFREE( delete_match_strict_entry( lldp_wildcards, LOW_PRIORITY ) );
  XFREE( delete_match_strict_entry( any_wildcards, LOW_PRIORITY ) );

  delete_oxm_matches( alice );
  delete_oxm_matches( alice_wildcards );
  delete_oxm_matches( bob_wildcards );
  delete_oxm_matches( lldp_wildcards );
  delete_oxm_matches( any_wildcards );
}
Esempio n. 3
0
static void
test_delete_of_deleted_wildcards_entry_fails() {
  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) );
  XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) );

  assert_true( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) == NULL );

  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );
}
Esempio n. 4
0
static void
test_update_nonexistent_wildcards_entry_fails() {
  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  assert_true( !update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  oxm_matches *alice_wildcards = create_oxm_matches();
  set_alice_match_entry( alice_wildcards );
  assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) );

  assert_true( !update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  void *data = lookup_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY );
  assert_true( data == NULL );
  data = lookup_match_entry( carol );
  assert_true( data == NULL );

  XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) );

  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );
  delete_oxm_matches( alice_wildcards );
}
Esempio n. 5
0
static void
test_insert_wildcards_entry_into_empty_table_succeeds() {
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  oxm_matches *alice_wildcards = create_oxm_matches();
  set_alice_wildcards_entry( alice_wildcards );
  assert_true( insert_match_entry( alice_wildcards, DEFAULT_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) );

  oxm_matches *bob = create_oxm_matches();
  set_bob_match_entry( bob );

  void *data0 = lookup_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY );
  assert_true( data0 != NULL );
  assert_string_equal( ( char * ) data0, ALICE_MATCH_SERVICE_NAME );
  void *data1 = lookup_match_entry( alice );
  assert_true( data1 != NULL );
  assert_string_equal( ( char * ) data1, ALICE_MATCH_SERVICE_NAME );
  assert_true( data0 == data1 );
  assert_true( lookup_match_entry( bob ) == NULL );
  void *data2 = delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY );
  assert_true( data2 != NULL );
  assert_string_equal( ( char * ) data2, ALICE_MATCH_SERVICE_NAME );
  assert_true( data1 == data2 );
  XFREE( data2 );

  delete_oxm_matches( alice );
  delete_oxm_matches( alice_wildcards );
  delete_oxm_matches( bob );
}
Esempio n. 6
0
static int
delete_packetin_match_entry( struct ofp_match match, uint16_t priority, const char *service_name ) {
  list_element *head = delete_match_strict_entry( match, priority );
  if ( head == NULL ) {
    return 0;
  }

  int n_deleted = 0;
  int n_remaining_services = 0;
  list_element *services = head;
  while ( services != NULL ) {
    char *service = services->data;
    services = services->next;
    if ( strcmp( service, service_name ) == 0 ) {
      delete_element( &head, service );
      xfree( service );
      n_deleted++;
    }
    else {
      n_remaining_services++;
    }
  }

  if ( n_remaining_services == 0 ) {
    if ( head != NULL ) {
      delete_list( head );
    }
  }
  else {
    insert_match_entry( match, priority, head );
  }

  return n_deleted;
}
Esempio n. 7
0
static void
test_delete_match_strict_entry_dies_if_not_initialized() {
  assert_true( _match_table_head == NULL );
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  expect_assert_failure( delete_match_strict_entry( alice, DEFAULT_PRIORITY ) );
  delete_oxm_matches( alice );
}
Esempio n. 8
0
static void
test_insert_different_priority_wildcards_entry_succeeds() {
  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) );

  assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY + 1, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  void *data = lookup_match_entry( carol );
  assert_true( data != NULL );
  assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME );
  XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) );
  XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY + 1 ) );

  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );
}
Esempio n. 9
0
static void
test_update_different_priority_wildcards_entry_fails() {
  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  assert_true( insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) );

  assert_true( !update_match_entry( carol_wildcards, DEFAULT_PRIORITY + 1, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) );

  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );}
Esempio n. 10
0
static void
delete_all_wildcards_entry() {
  oxm_matches *alice_wildcards = create_oxm_matches();
  set_alice_wildcards_entry( alice_wildcards );
  XFREE( delete_match_strict_entry( alice_wildcards, DEFAULT_PRIORITY ) );
  oxm_matches *bob_wildcards = create_oxm_matches();
  set_bob_wildcards_entry( bob_wildcards );
  XFREE( delete_match_strict_entry( bob_wildcards, DEFAULT_PRIORITY ) );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  XFREE( delete_match_strict_entry( carol_wildcards, DEFAULT_PRIORITY ) );
  oxm_matches *any_wildcards = create_oxm_matches();
  set_any_wildcards_entry( any_wildcards );
  XFREE( delete_match_strict_entry( any_wildcards, LOW_PRIORITY ) );
  oxm_matches *lldp_wildcards = create_oxm_matches();
  set_lldp_wildcards_entry( lldp_wildcards );
  XFREE( delete_match_strict_entry( lldp_wildcards, HIGH_PRIORITY ) );

  delete_oxm_matches( alice_wildcards );
  delete_oxm_matches( bob_wildcards );
  delete_oxm_matches( carol_wildcards );
  delete_oxm_matches( any_wildcards );
  delete_oxm_matches( lldp_wildcards );
}
Esempio n. 11
0
static void
delete_filter_walker( struct ofp_match match, uint16_t priority, void *data, void *user_data ) {
  UNUSED( data );
  buffer *reply_buffer = user_data;
  assert( reply_buffer != NULL );

  delete_packetin_filter_reply *reply = reply_buffer->data;
  list_element *head = delete_match_strict_entry( match, priority );
  for ( list_element *services = head; services != NULL; services = services->next ) {
    xfree( services->data );
    reply->n_deleted++;
  }
  if ( head != NULL ) {
    delete_list( head );
  }
}