示例#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 );
}
示例#2
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 );
}
示例#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();
}
示例#4
0
static void
delete_bob_match_entry() {
  struct ofp_match match;

  set_bob_match_entry( &match );
  delete_match_entry( &match );
}
示例#5
0
static void
intsert_bob_match_entry() {
  struct ofp_match match;

  set_bob_match_entry( &match );
  insert_match_entry( &match, BOB_MATCH_PRIORITY, BOB_MATCH_SERVICE_NAME, BOB_MATCH_ENTRY_NAME );
}
示例#6
0
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 );
}
示例#7
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();
}
示例#8
0
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 );
}