Ejemplo n.º 1
0
void
test_group_live_bucket(void) {
  struct bridge *bridge;
  struct group_table *group_table;
  struct group *group;
  struct ofp_group_mod group_mod;
  struct bucket_list bucket_list;
  struct bucket *bucket;
  struct action *action;
  struct ofp_error error;
  lagopus_result_t rv;

  bridge = dp_bridge_lookup("br0");
  group_table = bridge->group_table;
  group_mod.group_id = 1;
  group_mod.type = OFPGT_ALL;
  TAILQ_INIT(&bucket_list);
  action = action_alloc(sizeof(uint32_t));
  TEST_ASSERT_NOT_NULL(action);
  action->ofpat.type = OFPAT_OUTPUT;
  bucket = calloc(1, sizeof(struct bucket));
  TEST_ASSERT_NOT_NULL(bucket);
  bucket->ofp.watch_port = 1;
  TAILQ_INIT(&bucket->action_list);
  ((struct ofp_action_output *)&action->ofpat)->port = 1;
  ((struct ofp_action_group *)&action->ofpat)->len =
    sizeof(struct ofp_action_header) + sizeof(uint32_t);
  TAILQ_INSERT_TAIL(&bucket->action_list, action, entry);
  TAILQ_INSERT_TAIL(&bucket_list, bucket, entry);
  action = action_alloc(sizeof(uint32_t));
  TEST_ASSERT_NOT_NULL(action);
  action->ofpat.type = OFPAT_OUTPUT;
  bucket = calloc(1, sizeof(struct bucket));
  TEST_ASSERT_NOT_NULL(bucket);
  TAILQ_INIT(&bucket->action_list);
  ((struct ofp_action_output *)&action->ofpat)->port = 3;
  ((struct ofp_action_output *)&action->ofpat)->len =
    sizeof(struct ofp_action_header) + sizeof(uint32_t);
  TAILQ_INSERT_TAIL(&bucket->action_list, action, entry);
  TAILQ_INSERT_TAIL(&bucket_list, bucket, entry);
  group = group_alloc(&group_mod, &bucket_list);
  rv = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL(rv, LAGOPUS_RESULT_OK);
  TEST_ASSERT_NULL(group_live_bucket(bridge, group));
}
static void
create_data(struct group_desc_list *group_desc_list) {
  struct group_desc *group_desc;
  struct bucket *bucket;
  struct action *action;
  struct ofp_action_output *action_output;
  uint16_t length = 0xe0;
  int i;
  int j;
  int k;

  TAILQ_INIT(group_desc_list);
  for (i = 0; i < group_desc_num; i++) {
    group_desc = group_desc_alloc(length);
    group_desc->ofp.length = length;
    group_desc->ofp.type = OFPGT_SELECT;
    group_desc->ofp.group_id = (uint32_t) (0x01 + i);

    TAILQ_INIT(&group_desc->bucket_list);
    for (j = 0; j < bucket_num; j++) {
      bucket = bucket_alloc();
      bucket->ofp.len = 0x30;
      bucket->ofp.weight = (uint16_t) (0x02 + j);
      bucket->ofp.watch_port = (uint32_t) (0x03 +j);
      bucket->ofp.watch_group = (uint32_t) (0x4 + j);

      TAILQ_INIT(&bucket->action_list);
      for (k = 0; k < action_num; k++) {
        action = action_alloc(0x10);
        action->ofpat.type = OFPAT_OUTPUT;
        action->ofpat.len = 0x10;
        action_output = (struct ofp_action_output *) &action->ofpat;
        action_output->port = (uint32_t) (0x05 + k);
        action_output->max_len = (uint16_t) (0x06 + k);
        TAILQ_INSERT_TAIL(&bucket->action_list, action, entry);
      }
      TAILQ_INSERT_TAIL(&group_desc->bucket_list, bucket, entry);
    }
    TAILQ_INSERT_TAIL(group_desc_list, group_desc, entry);
  }
}
Ejemplo n.º 3
0
void
test_group_table_add(void) {
  struct bridge *bridge;
  struct group_table *group_table;
  struct group *group;
  struct ofp_group_mod group_mod;
  struct bucket_list bucket_list;
  struct bucket *bucket;
  struct action *action;
  struct ofp_error error;
  lagopus_result_t ret;

  bridge = dp_bridge_lookup("br0");
  group_table = group_table_alloc(bridge);
  TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "group_table alloc error.");
  bridge->group_table = group_table;
  group_mod.group_id = 1;
  group_mod.type = OFPGT_ALL;
  TAILQ_INIT(&bucket_list);
  group = group_alloc(&group_mod, &bucket_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(group, "group_alloc error");
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "group_table_add error");

  group_mod.group_id = 2;
  group_mod.type = OFPGT_ALL;
  TAILQ_INIT(&bucket_list);

  action = action_alloc(sizeof(uint32_t));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error");
  action->ofpat.type = OFPAT_GROUP;
  bucket = calloc(1, sizeof(struct bucket));
  TEST_ASSERT_NOT_NULL_MESSAGE(bucket, "bucket alloc error");
  TAILQ_INIT(&bucket->action_list);
  ((struct ofp_action_group *)&action->ofpat)->group_id = 3;
  ((struct ofp_action_group *)&action->ofpat)->len =
    sizeof(struct ofp_action_header) + sizeof(uint32_t);
  TAILQ_INSERT_TAIL(&bucket->action_list, action, entry);
  TAILQ_INSERT_TAIL(&bucket_list, bucket, entry);

  action = action_alloc(sizeof(uint32_t));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error");
  action->ofpat.type = OFPAT_OUTPUT;
  bucket = calloc(1, sizeof(struct bucket));
  TEST_ASSERT_NOT_NULL_MESSAGE(bucket, "bucket alloc error");
  TAILQ_INIT(&bucket->action_list);
  ((struct ofp_action_output *)&action->ofpat)->port = 3;
  ((struct ofp_action_output *)&action->ofpat)->len =
    sizeof(struct ofp_action_header) + sizeof(uint32_t);
  TAILQ_INSERT_TAIL(&bucket->action_list, action, entry);
  TAILQ_INSERT_TAIL(&bucket_list, bucket, entry);

  group = group_alloc(&group_mod, &bucket_list);
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "group_table_add error");
  bucket = TAILQ_FIRST(&group->bucket_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(bucket, "bucket copy error");
  action = TAILQ_FIRST(&bucket->action_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action copy error");
  TEST_ASSERT_EQUAL_MESSAGE(action->ofpat.type, OFPAT_GROUP,
                            "action copy error");
  bucket = TAILQ_NEXT(bucket, entry);
  TEST_ASSERT_NOT_NULL_MESSAGE(bucket, "bucket copy error");
  action = TAILQ_FIRST(&bucket->action_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action copy error");
  TEST_ASSERT_EQUAL_MESSAGE(action->ofpat.type, OFPAT_OUTPUT,
                            "action copy error");
  TEST_ASSERT_EQUAL_MESSAGE(
    ((struct ofp_action_output *)&action->ofpat)->port, 3,
    "action copy error");

  group_mod.group_id = 3;
  group_mod.type = OFPGT_ALL;
  action = action_alloc(sizeof(uint32_t));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error");
  action->ofpat.type = OFPAT_GROUP;
  ((struct ofp_action_group *)&action->ofpat)->group_id = 2;
  ((struct ofp_action_group *)&action->ofpat)->len =
    sizeof(struct ofp_action_header) + sizeof(uint32_t);
  bucket = calloc(1, sizeof(struct bucket));
  TAILQ_INIT(&bucket->action_list);
  TAILQ_INSERT_TAIL(&bucket->action_list, action, entry);
  TAILQ_INIT(&bucket_list);
  TAILQ_INSERT_TAIL(&bucket_list, bucket, entry);
  group = group_alloc(&group_mod, &bucket_list);
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OFP_ERROR,
                            "group_table_add loop error");
  TEST_ASSERT_EQUAL_MESSAGE(error.code, OFPGMFC_LOOP,
                            "loop error detection failed");
}
Ejemplo n.º 4
0
void
test_group_stats(void) {
  struct bridge *bridge;
  struct group_table *group_table;
  struct group *group;
  struct ofp_group_mod group_mod;
  struct bucket_list bucket_list;
  struct ofp_group_stats_request request;
  struct group_stats_list group_stats_list;
  struct group_stats *stats;
  struct ofp_error error;
  struct ofp_flow_mod flow_mod;
  struct match_list match_list;
  struct instruction_list instruction_list;
  struct instruction *instruction;
  struct action *action;
  lagopus_result_t ret;

  bridge = dp_bridge_lookup("br0");
  TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "bridge alloc error.");
  TAILQ_INIT(&bucket_list);
  group_table = group_table_alloc(bridge);
  TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "group_table alloc error.");
  bridge->group_table = group_table;

  group_mod.group_id = 1;
  group_mod.type = OFPGT_ALL;
  group = group_alloc(&group_mod, &bucket_list);
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "group_table_add error");

  group_mod.group_id = 1000000;
  group_mod.type = OFPGT_ALL;
  group = group_alloc(&group_mod, &bucket_list);
  ret = group_table_add(group_table, group, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "group_table_add error");

  request.group_id = 1;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 0,
                            "duration sec error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.ref_count, 0,
                            "ref_count error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NULL_MESSAGE(stats, "number of groups error");

  TAILQ_INIT(&match_list);
  TAILQ_INIT(&instruction_list);
  instruction = instruction_alloc();
  TEST_ASSERT_NOT_NULL_MESSAGE(instruction, "instruction alloc error.");
  instruction->ofpit.type = OFPIT_APPLY_ACTIONS;
  TAILQ_INIT(&instruction->action_list);
  action = action_alloc(sizeof(struct ofp_action_group));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error.");
  action->ofpat.type = OFPAT_GROUP;
  ((struct ofp_action_group *)&action->ofpat)->group_id = 5;
  TAILQ_INSERT_TAIL(&instruction->action_list, action, entry);
  TAILQ_INSERT_TAIL(&instruction_list, instruction, entry);
  flow_mod.table_id = 0;
  flow_mod.priority = 1;
  flow_mod.flags = 0;
  flow_mod.cookie = 0;
  ret = flowdb_flow_add(bridge, &flow_mod, &match_list,
                        &instruction_list, &error);
  TEST_ASSERT_NOT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                                "flowdb_flow_add: group check error");
  TAILQ_INIT(&match_list);
  TAILQ_INIT(&instruction_list);
  instruction = instruction_alloc();
  TEST_ASSERT_NOT_NULL_MESSAGE(instruction, "instruction alloc error.");
  instruction->ofpit.type = OFPIT_APPLY_ACTIONS;
  TAILQ_INIT(&instruction->action_list);
  action = action_alloc(sizeof(struct ofp_action_group));
  TEST_ASSERT_NOT_NULL_MESSAGE(action, "action alloc error.");
  action->ofpat.type = OFPAT_GROUP;
  ((struct ofp_action_group *)&action->ofpat)->group_id = 1;
  TAILQ_INSERT_TAIL(&instruction->action_list, action, entry);
  TAILQ_INSERT_TAIL(&instruction_list, instruction, entry);
  ret = flowdb_flow_add(bridge, &flow_mod, &match_list,
                        &instruction_list, &error);
  printf("%d.%d\n", error.type, error.code);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "flowdb_flow_add: add to empty table error");

  request.group_id = 1;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 0,
                            "duration sec error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.ref_count, 1,
                            "ref_count error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NULL_MESSAGE(stats, "number of groups error");

  request.group_id = OFPG_ALL;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 0,
                            "duration sec error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1000000,
                            "group id error");
  stats = TAILQ_NEXT(stats, entry);
  TEST_ASSERT_NULL_MESSAGE(stats, "number of groups error");

  sleep(1);
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NOT_NULL_MESSAGE(stats, "group not found");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.group_id, 1,
                            "group id error");
  TEST_ASSERT_EQUAL_MESSAGE(stats->ofp.duration_sec, 1,
                            "duration sec error");

  request.group_id = 20;
  TAILQ_INIT(&group_stats_list);
  ret = group_stats(group_table, &request, &group_stats_list, &error);
  TEST_ASSERT_EQUAL_MESSAGE(ret, LAGOPUS_RESULT_OK,
                            "get stats error");
  stats = TAILQ_FIRST(&group_stats_list);
  TEST_ASSERT_NULL_MESSAGE(stats, "stats is not empry");
}