Example #1
0
static void
test_map_entry_if_match_set_nw_prefix() {
  oxm_matches *nw_src_prefix_20 = create_oxm_matches();
  set_nw_src_prefix_20_wildcards_entry( nw_src_prefix_20 );
  assert_true( insert_match_entry( nw_src_prefix_20, DEFAULT_PRIORITY, xstrdup( NW_SRC_PREFIX_20_SERVICE_NAME ) ) );
  oxm_matches *nw_dst_prefix_20 = create_oxm_matches();
  set_nw_dst_prefix_20_wildcards_entry( nw_dst_prefix_20 );
  assert_true( insert_match_entry( nw_dst_prefix_20, DEFAULT_PRIORITY, xstrdup( NW_DST_PREFIX_20_SERVICE_NAME ) ) );
  oxm_matches *nw_prefix_24 = create_oxm_matches();
  set_nw_prefix_24_wildcards_entry( nw_prefix_24 );
  assert_true( insert_match_entry( nw_prefix_24, DEFAULT_PRIORITY, xstrdup( NW_PREFIX_24_SERVICE_NAME ) ) );
  oxm_matches *nw_prefix_28 = create_oxm_matches();
  set_nw_prefix_28_wildcards_entry( nw_prefix_28 );
  assert_true( insert_match_entry( nw_prefix_28, DEFAULT_PRIORITY, xstrdup( NW_PREFIX_28_SERVICE_NAME ) ) );

  oxm_matches *match = create_oxm_matches();
  set_nw_prefix_24_wildcards_entry( match );
  char *user_data = xstrdup( USER_DATA );
  count = 0;
  map_match_table( match, test_map_entry_if_match_set_nw_prefix_helper, user_data );
  assert_int_equal( count, 2 );

  XFREE( user_data );

  delete_oxm_matches( nw_src_prefix_20 );
  delete_oxm_matches( nw_dst_prefix_20 );
  delete_oxm_matches( nw_prefix_24 );
  delete_oxm_matches( nw_prefix_28 );
  delete_oxm_matches( match );
}
Example #2
0
static void
add_all_wildcards_entry() {
  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, DEFAULT_PRIORITY, xstrdup( BOB_MATCH_SERVICE_NAME ) ) );
  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 ) ) );
  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 ) ) );
  oxm_matches *lldp_wildcards = create_oxm_matches();
  set_lldp_wildcards_entry( lldp_wildcards );
  assert_true( insert_match_entry( lldp_wildcards, HIGH_PRIORITY, xstrdup( LLDP_MATCH_SERVICE_NAME ) ) );
  assert_true( update_match_entry( carol_wildcards, DEFAULT_PRIORITY, xstrdup( CAROL_MATCH_OTHER_SERVICE_NAME ) ) );

  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 );
}
Example #3
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 );
}
Example #4
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 );
}
Example #5
0
static void
intsert_lldp_match_entry() {
  struct ofp_match match;

  set_lldp_match_entry( &match );
  insert_match_entry( &match, LLDP_MATCH_PRIORITY, LLDP_MATCH_SERVICE_NAME, LLDP_MATCH_ENTRY_NAME );
}
Example #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;
}
Example #7
0
static void
intsert_mallory_match_entry() {
  struct ofp_match match;

  set_alice_match_entry( &match );
  insert_match_entry( &match, MALLORY_MATCH_PRIORITY, MALLORY_MATCH_SERVICE_NAME, MALLORY_MATCH_ENTRY_NAME );
}
Example #8
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 );
}
Example #9
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 );
}
Example #10
0
static void
intsert_ipv4_match_entry() {
  struct ofp_match match;

  set_ipv4_match_entry( &match );
  insert_match_entry( &match, IPV4_MATCH_PRIORITY, IPV4_MATCH_SERVICE_NAME, IPV4_MATCH_ENTRY_NAME );
}
Example #11
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 );
}
Example #12
0
static void
intsert_any_match_entry() {
  struct ofp_match match;

  set_any_match_entry( &match );
  insert_match_entry( &match, ANY_MATCH_PRIORITY, ANY_MATCH_SERVICE_NAME, ANY_MATCH_ENTRY_NAME );
}
Example #13
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 );
}
Example #14
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 );
}
Example #15
0
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 );
}
Example #16
0
// TODO: use pubsub lib.
static void
register_any_filter( uint16_t priority, const char *service_name,
                     const char *entry_name ) {
  struct ofp_match ofp_match;
  memset( &ofp_match, 0, sizeof( struct ofp_match ) );
  ofp_match.wildcards = OFPFW_ALL;

  insert_match_entry( &ofp_match, priority, service_name, entry_name );
}
Example #17
0
static void
test_insert_match_entry_dies_if_not_initialized() {
  assert_true( _match_table_head == NULL );
  oxm_matches *alice = create_oxm_matches();
  set_alice_match_entry( alice );
  void *data =  xstrdup( ALICE_MATCH_SERVICE_NAME );
  expect_assert_failure( insert_match_entry( alice, DEFAULT_PRIORITY, data ) );
  XFREE( data );
  delete_oxm_matches( alice );
}
Example #18
0
// TODO: use pubsub lib.
static void
register_dl_type_filter( uint16_t dl_type, uint16_t priority,
                         const char *service_name, const char *entry_name ) {
  struct ofp_match ofp_match;
  memset( &ofp_match, 0, sizeof( struct ofp_match ) );
  ofp_match.wildcards = OFPFW_ALL & ~OFPFW_DL_TYPE;
  ofp_match.dl_type = dl_type;

  insert_match_entry( &ofp_match, priority, service_name, entry_name );
}
Example #19
0
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 );
}
Example #20
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 );
}
Example #21
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 );}