示例#1
0
instruction_list * isl_if_to_noclock (isl_ast_node * if_node)
{
    /* Extract the if then else information. */
    isl_ast_expr * cond = isl_ast_node_if_get_cond (if_node);
    isl_ast_node * if_body = isl_ast_node_if_get_then (if_node);
    bool has_else = isl_ast_node_if_has_else (if_node);

    instruction * if_i = instruction_alloc ();
    if_i->type = INSTR_IF;
    if_i->content.branch.condition = isl_expr_to_noclock_expr (cond);
    if_i->content.branch.true_body = isl_ast_to_noclock_ast (if_body);
    if_i->content.branch.false_body = NULL;

    if (has_else)
    {
        isl_ast_node * else_body = isl_ast_node_if_get_else (if_node);
        if_i->content.branch.false_body =
            isl_ast_to_noclock_ast (else_body);
        if_i->content.branch.has_else = true;
    }

    /* Wrap the if then else in an instruction list node. */
    instruction_list * list = instruction_list_alloc ();
    list->element = if_i;
    list->next = NULL;

    return list;
}
示例#2
0
instruction * instruction_advance (void)
{
    instruction * i = instruction_alloc ();

    instruction_set_type (i, INSTR_ADVANCE);

    return i;
}
示例#3
0
void
test_ofp_flow_reply_create_01(void) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct flow_stats *flow_stats = NULL;
  struct instruction *instruction = NULL;
  struct match *match = NULL;
  const char *require[1] = {
    "04 13 00 58 00 00 00 10 00 01 00 00 00 00 00 00 "
    "00 48 01 00 00 00 00 02 00 00 00 03 00 04 00 05 "
    "00 06 00 07 00 00 00 00 00 00 00 00 00 00 00 08 "
    "00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 0a "
    "00 01 00 10 00 00 01 08 00 00 00 00 00 00 00 00 "
    "00 01 00 08 00 00 00 00"
  };

  TAILQ_INIT(&s_flow_stats_list);
  if ((flow_stats = s_flow_stats_alloc()) != NULL) {
    /* flow_stats = 48, match = 16, instruction = 8, sum = 72 */
    flow_stats->ofp.length = 48 + 16 + 8;
    flow_stats->ofp.table_id = 0x01;
    flow_stats->ofp.duration_sec = 0x02;
    flow_stats->ofp.duration_nsec = 0x03;
    flow_stats->ofp.priority = 0x04;
    flow_stats->ofp.idle_timeout = 0x05;
    flow_stats->ofp.hard_timeout = 0x06;
    flow_stats->ofp.flags = 0x07;
    flow_stats->ofp.cookie = 0x08;
    flow_stats->ofp.packet_count = 0x09;
    flow_stats->ofp.byte_count = 0x0a;
    if ((match = match_alloc(8)) != NULL) {
      match->oxm_class = 0x00;
      match->oxm_field = 0x01;
      match->oxm_length = 0x08;
      TAILQ_INSERT_TAIL(&(flow_stats->match_list), match, entry);
    }
    if ((instruction = instruction_alloc()) != NULL) {
      instruction->ofpit_goto_table.type = OFPIT_GOTO_TABLE;
      instruction->ofpit_goto_table.len = 0x08; /* action_list empty */
      instruction->ofpit_goto_table.table_id = 0x00;
      TAILQ_INSERT_TAIL(&(flow_stats->instruction_list), instruction, entry);
    }
    TAILQ_INSERT_TAIL(&s_flow_stats_list, flow_stats, entry);
  } else {
    TEST_FAIL_MESSAGE("allocation error.");
  }

  /* port 0 */
  ret = check_pbuf_list_packet_create(s_ofp_flow_reply_create_wrap, require, 1);
  TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "create port 0 error.");

  /* free */
  while ((flow_stats = TAILQ_FIRST(&s_flow_stats_list)) != NULL) {
    TAILQ_REMOVE(&s_flow_stats_list, flow_stats, entry);
    ofp_match_list_elem_free(&flow_stats->match_list);
    ofp_instruction_list_elem_free(&flow_stats->instruction_list);
    free(flow_stats);
  }
}
示例#4
0
instruction * instruction_clocked_async (instruction_list * block)
{
    instruction * i = instruction_alloc ();

    instruction_set_type (i, INSTR_CLOCKED_ASYNC);
    instruction_other_set_block (i, block);

    return i;
}
示例#5
0
instruction * instruction_clocked_finish (instruction_list * block)
{
    instruction * i = instruction_alloc ();

    instruction_set_type (i, INSTR_CLOCKED_FINISH);
    instruction_other_set_block (i, block);

    return i;
}
示例#6
0
instruction * instruction_function_call (char * identifier,
        expression_list * arguments)
{
    instruction * i = instruction_alloc ();

    instruction_set_type (i, INSTR_CALL);
    instruction_function_call_set_identifier (i, identifier);
    instruction_function_call_set_arguments (i, arguments);

    return i;
}
示例#7
0
instruction * instruction_if_then_else (bool has_else, expression * condition,
        instruction_list * true_body, instruction_list * false_body)
{
    instruction * i = instruction_alloc ();

    instruction_set_type (i, INSTR_IF);
    instruction_if_then_else_set_has_else (i, has_else);
    instruction_if_then_else_set_condition (i, condition);
    instruction_if_then_else_set_true_body (i, true_body);
    instruction_if_then_else_set_false_body (i, false_body);

    return i;
}
示例#8
0
instruction * instruction_for_loop (char * identifier, expression * left,
        expression * right, instruction_list * body)
{
    instruction * i = instruction_alloc ();

    instruction_set_type (i, INSTR_FOR);
    instruction_for_loop_set_identifier (i, identifier);
    instruction_for_loop_set_left_boundary (i, left);
    instruction_for_loop_set_right_boundary (i, right);
    instruction_for_loop_set_body (i, body);

    return i;
}
示例#9
0
void instruction_list_wrap (instruction_list * list, instruction * instr,
        instruction_type t)
{
    instruction_list * nth = instruction_list_find_parent (list, instr);

    if (nth != NULL && nth->element->type != t)
    {
        instruction_list * wrapped = instruction_list_alloc ();
        wrapped->element = nth->element;
        wrapped->next = NULL;

        instruction * wrapper = instruction_alloc ();
        wrapper->type = t;
        wrapper->content.block = wrapped;

        nth->element = wrapper;
    }
}
示例#10
0
instruction_list * isl_user_to_noclock (isl_ast_node * user_node)
{
    isl_ast_expr * expr = isl_ast_node_user_get_expr (user_node);

    instruction * user = instruction_alloc ();
    user->type = INSTR_CALL;
    user->content.call.identifier = strdup (isl_id_get_name (
                isl_ast_expr_get_id (isl_ast_expr_get_op_arg (expr, 0))));

    for (int i = 1; i < isl_ast_expr_get_op_n_arg (expr); ++i)
    {
        expression_list * e = expression_list_alloc ();
        e->element = isl_expr_to_noclock_expr (isl_ast_expr_get_op_arg (expr, i));
        e->next = NULL;
        user->content.call.arguments = expression_list_cat (
                user->content.call.arguments, e);
    }

    instruction_list * list = instruction_list_alloc ();
    list->element = user;
    list->next = NULL;

    return list;
}
示例#11
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");
}
示例#12
0
static int
cmd_instruction_run( chain_t *chain, char *params[] )
{
	part_t *part;

	if (!cmd_test_cable( chain ))
		return 1;

	if (!chain->parts) {
		printf( _("Run \"detect\" first.\n") );
		return 1;
	}

	if (chain->active_part >= chain->parts->len) {
		printf( _("%s: no active part\n"), "instruction" );
		return 1;
	}

	part = chain->parts->parts[chain->active_part];

	if (cmd_params( params ) == 2) {
		part_set_instruction( part, params[1] );
		if (part->active_instruction == NULL)
			printf( _("%s: unknown instruction '%s'\n"), "instruction", params[1] );
		return 1;
	}
	
	if (cmd_params( params ) == 3) {
		unsigned int len;

		if (strcasecmp( params[1], "length" ) != 0)
			return -1;

		if (part->instructions != NULL) {
			printf( _("instruction length is already set and used\n") );
			return 1;
		}

		if (cmd_get_number( params[2], &len ))
			return -1;

		part->instruction_length = len;
		return 1;
	}

	if (cmd_params( params ) == 4) {
		instruction *i;

		if (strlen( params[2] ) != part->instruction_length) {
			printf( _("invalid instruction length\n") );
			return 1;
		}

		if (part_find_instruction( part, params[1] ) != NULL) {
			printf( _("Instruction '%s' already defined\n"), params[1] );
			return 1;
		}

		i = instruction_alloc( params[1], part->instruction_length, params[2] );
		if (!i) {
			printf( _("out of memory\n") );
			return 1;
		}

		i->next = part->instructions;
		part->instructions = i;

		i->data_register = part_find_data_register( part, params[3] );
		if (i->data_register == NULL) {
			printf( _("unknown data register '%s'\n"), params[3] );
			return 1;
		}

		return 1;
	}

	return -1;
}