コード例 #1
0
lagopus_result_t
check_packet_parse_expect_error(ofp_handler_proc_t handler_proc,
                                const char packet[],
                                const struct ofp_error *expected_error) {
  lagopus_result_t res = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel = create_data_channel();
  struct ofp_header xid_header = {0, 0, 0, 0};
  struct pbuf *pbuf;
  struct ofp_error error;

  /* create packet */
  create_packet(packet, &pbuf);
  /* ignore result code. */
  (void) ofp_header_decode_sneak_test(pbuf, &xid_header);

  /* call func & check */
  res = (handler_proc)(channel, pbuf, &xid_header, &error);
  if (res == LAGOPUS_RESULT_OK) {
    TEST_ASSERT_EQUAL_MESSAGE(0, pbuf->plen,
                              "handler_test_utils.c: packet data len error.");
  } else if (res == LAGOPUS_RESULT_OFP_ERROR) {
    /* check error if expected */
    if (expected_error != NULL) {
      TEST_ASSERT_EQUAL_OFP_ERROR(expected_error, &error);
    }
  }

  pbuf_free(pbuf);
  s_destroy_static_data();
  return res;
}
コード例 #2
0
lagopus_result_t
check_packet_parse_array_expect_error(ofp_handler_proc_t handler_proc,
                                      const char *packet[],
                                      int array_len,
                                      const struct ofp_error *expected_error) {

  lagopus_result_t res = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel = create_data_channel();
  struct ofp_header xid_header;
  struct pbuf *pbuf;
  struct ofp_error error;
  bool error_has_occurred = false;
  int i;
  for (i = 0; i < array_len; i++) {
    lagopus_msg_debug(1, "packet[%d] start ... %s\n", i, packet[i]);
    /* create packet */
    create_packet(packet[i], &pbuf);
    /* parse header */
    if (ofp_header_decode_sneak_test(pbuf, &xid_header) !=
        LAGOPUS_RESULT_OK) {
      pbuf_free(pbuf);
      s_destroy_static_data();
      TEST_FAIL_MESSAGE("handler_test_utils.c: cannot decode header\n");
      return LAGOPUS_RESULT_OFP_ERROR;
    }
    /* call func & check */
    res = (handler_proc)(channel, pbuf, &xid_header, &error);
    lagopus_msg_debug(1, "packet[%d] done ... %s\n", i,
                      lagopus_error_get_string(res));
    if (res == LAGOPUS_RESULT_OK) {
      TEST_ASSERT_EQUAL_MESSAGE(0, pbuf->plen,
                                "handler_test_utils.c: packet data len error.");
    } else if (res == LAGOPUS_RESULT_OFP_ERROR) {
      error_has_occurred = true;
      if (expected_error != NULL) {
        TEST_ASSERT_EQUAL_OFP_ERROR(expected_error, &error);
      }
      pbuf_free(pbuf);
      break;
    }
    /* free */
    pbuf_free(pbuf);
  }

  /* free */
  s_destroy_static_data();

  if (error_has_occurred == true) {
    TEST_ASSERT_EQUAL_OFP_ERROR(expected_error, &error);
  }

  return res;
}
コード例 #3
0
static lagopus_result_t
s_ofp_set_config_request_handle_wrap(struct channel *channel,
                                     struct pbuf *pbuf,
                                     struct ofp_header *xid_header,
                                     struct ofp_error *error) {
  /* set xid_header. */
  if (ofp_header_decode_sneak_test(pbuf, xid_header) !=
      LAGOPUS_RESULT_OK) {
    TEST_FAIL_MESSAGE("handler_test_utils.c: cannot decode header\n");
  }
  return ofp_set_config_handle(channel, pbuf, xid_header, error);
}
コード例 #4
0
lagopus_result_t
check_packet_parse_with_dequeue_expect_error(ofp_handler_proc_t handler_proc,
    const char packet[],
    void **get,
    const struct ofp_error *expected_error) {
  lagopus_result_t res = LAGOPUS_RESULT_ANY_FAILURES;
  struct channel *channel = NULL;
  struct ofp_header xid_header;
  struct ofp_bridge *ofpb = NULL;
  struct pbuf *pbuf = NULL;
  struct ofp_error error;
  struct ofp_bridgeq *bridgeq = NULL;

  if (get == NULL) {
    return LAGOPUS_RESULT_INVALID_ARGS;
  }
  /* start ofp_handler */
  if (s_start_ofp_handler() == false) {
    goto done;
  }

  /* get ofp_bridge */
  channel = create_data_channel();
  if (channel == NULL) {
    TEST_FAIL_MESSAGE("channel is NULL.");
  }

  res = ofp_bridgeq_mgr_bridge_lookup(channel_dpid_get(channel), &bridgeq);
  if (res == LAGOPUS_RESULT_OK) {
    ofpb = ofp_bridgeq_mgr_bridge_get(bridgeq);
    ofp_bridgeq_mgr_bridgeq_free(bridgeq);
  } else {
    TEST_FAIL_MESSAGE("handler_test_utils.c: "
                      "ofp_bridgeq_mgr_bridge_get error.");
  }

  /* create packet */
  create_packet(packet, &pbuf);
  /* parse header */
  if (ofp_header_decode_sneak_test(pbuf, &xid_header) != LAGOPUS_RESULT_OK) {
    TEST_FAIL_MESSAGE("handler_test_utils.c: cannot decode header\n");
    return LAGOPUS_RESULT_OFP_ERROR;
  }
  /* call func & check */
  res = (handler_proc)(channel, pbuf, &xid_header, &error);
  if (res == LAGOPUS_RESULT_OK) {
    res = lagopus_bbq_get(&ofpb->event_dataq, get, void *, TIMEOUT);
    TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, res,
                              "handler_test_utils.c: lagopus_bbq_get error.");
  } else if (res == LAGOPUS_RESULT_OFP_ERROR) {