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 );
}
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 );
}
Exemple #3
0
static void
test_insert_and_delete_of_exact_all_entry_failed() {
  setup();

  struct ofp_match lookup_match;
  match_entry *match_entry;

  init_match_table();

  intsert_alice_match_entry();
  intsert_bob_match_entry();
  intsert_carol_match_entry();

  delete_carol_match_entry();
  set_carol_match_entry( &lookup_match );
  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  delete_bob_match_entry();
  set_bob_match_entry( &lookup_match );
  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  delete_alice_match_entry();
  set_alice_match_entry( &lookup_match );
  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  finalize_match_table();

  teardown();
}
Exemple #4
0
static void
delete_carol_match_entry() {
  struct ofp_match match;

  set_carol_match_entry( &match );
  delete_match_entry( &match );
}
Exemple #5
0
static void
intsert_carol_match_entry() {
  struct ofp_match match;

  set_carol_match_entry( &match );
  insert_match_entry( &match, CAROL_MATCH_PRIORITY, CAROL_MATCH_SERVICE_NAME, CAROL_MATCH_ENTRY_NAME );
}
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 );
}
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 );}
static void
add_all_exact_entry() {
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  assert_true( insert_match_entry( alice, HIGH_PRIORITY, xstrdup( ALICE_MATCH_SERVICE_NAME ) ) );
  oxm_matches *bob = create_oxm_matches();
  set_bob_match_entry( bob );
  assert_true( insert_match_entry( bob, HIGH_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) );
  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );
  assert_true( insert_match_entry( carol, HIGH_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) );
  assert_true( update_match_entry( carol, HIGH_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  delete_oxm_matches( alice );
  delete_oxm_matches( bob );
  delete_oxm_matches( carol );
}
static void
test_insert_existing_same_match_same_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( !insert_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

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

  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );
}
Exemple #10
0
static void
test_insert_and_lookup_of_exact_all_entry() {
  setup();

  struct ofp_match lookup_match;
  match_entry *match_entry;

  init_match_table();

  intsert_alice_match_entry();
  intsert_bob_match_entry();
  intsert_carol_match_entry();

  set_alice_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) );
  assert_string_equal( match_entry->service_name, ALICE_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, ALICE_MATCH_ENTRY_NAME );

  set_bob_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) );
  assert_string_equal( match_entry->service_name, BOB_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, BOB_MATCH_ENTRY_NAME );

  set_carol_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) );
  assert_string_equal( match_entry->service_name, CAROL_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, CAROL_MATCH_ENTRY_NAME );

  finalize_match_table();

  teardown();
}
static void
test_reinsert_of_deleted_lowhest_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, LOW_PRIORITY, xstrdup( CAROL_MATCH_SERVICE_NAME ) ) );
  XFREE( delete_match_strict_entry( carol_wildcards, LOW_PRIORITY ) );
  void *data = lookup_match_strict_entry( carol, LOW_PRIORITY );
  assert_true( data == NULL );
  data = lookup_match_entry( carol );
  assert_true( data == NULL );
  assert_true( insert_match_entry( carol_wildcards, LOW_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  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, LOW_PRIORITY ) );

  delete_oxm_matches( carol );
  delete_oxm_matches( carol_wildcards );
}
static void
test_foreach_entry_helper( oxm_matches *match, uint16_t priority, void *data, void *user_data ) {
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  oxm_matches *bob = create_oxm_matches();
  set_bob_match_entry( bob );
  oxm_matches *carol = create_oxm_matches();
  set_carol_match_entry( carol );

  oxm_matches *alice_wildcards = create_oxm_matches();
  set_alice_wildcards_entry( alice_wildcards );
  oxm_matches *bob_wildcards = create_oxm_matches();
  set_bob_wildcards_entry( bob_wildcards );
  oxm_matches *carol_wildcards = create_oxm_matches();
  set_carol_wildcards_entry( carol_wildcards );
  oxm_matches *any_wildcards = create_oxm_matches();
  set_any_wildcards_entry( any_wildcards );
  oxm_matches *lldp_wildcards = create_oxm_matches();
  set_lldp_wildcards_entry( lldp_wildcards );


  switch ( ++count ) {
    case 1:
      assert_string_equal( ( char * ) data, ALICE_MATCH_SERVICE_NAME );
      assert_true( priority == HIGH_PRIORITY );
      assert_true( compare_oxm_match_strict( match, alice ) );
      XFREE( data );
      break;
    case 2:
      assert_string_equal( ( char * ) data, BOB_MATCH_SERVICE_NAME );
      assert_true( priority == HIGH_PRIORITY );
      assert_true( compare_oxm_match_strict( match, bob ) );
      XFREE( data );
      break;
    case 3:
      assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME );
      assert_true( priority == HIGH_PRIORITY );
      assert_true( compare_oxm_match_strict( match, carol ) );
      XFREE( data );
      break;
    case 5:
      assert_string_equal( ( char * ) data, ALICE_MATCH_SERVICE_NAME );
      assert_true( priority == DEFAULT_PRIORITY );
      assert_true( compare_oxm_match_strict( match, alice_wildcards ) );
      XFREE( data );
      break;
    case 6:
      assert_string_equal( ( char * ) data, BOB_MATCH_SERVICE_NAME );
      assert_true( priority == DEFAULT_PRIORITY );
      assert_true( compare_oxm_match_strict( match, bob_wildcards ) );
      XFREE( data );
      break;
    case 7:
      assert_string_equal( ( char * ) data, CAROL_MATCH_OTHER_SERVICE_NAME );
      assert_true( priority == DEFAULT_PRIORITY );
      assert_true( compare_oxm_match_strict( match, carol_wildcards ) );
      XFREE( data );
      break;
    case 8:
      assert_string_equal( ( char * ) data, ANY_MATCH_SERVICE_NAME );
      assert_true( priority == LOW_PRIORITY );
      assert_true( compare_oxm_match_strict( match, any_wildcards ) );
      XFREE( data );
      break;
    case 4:
      assert_string_equal( ( char * ) data, LLDP_MATCH_SERVICE_NAME );
      assert_true( priority == HIGH_PRIORITY );
      assert_true( compare_oxm_match_strict( match, lldp_wildcards ) );
      XFREE( data );
      break;
    default:
      assert_true( false );
      break;
  }
  assert_string_equal( ( char * ) user_data, USER_DATA );

  delete_oxm_matches( alice );
  delete_oxm_matches( bob );
  delete_oxm_matches( carol );
  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 );
}