예제 #1
0
STATIC lagopus_result_t
ofp_get_async_reply_create(struct channel *channel,
                           struct pbuf **pbuf,
                           struct ofp_header *xid_header) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  struct ofp_async_config async_config;

  /* check params */
  if (channel != NULL && pbuf != NULL &&
      xid_header != NULL) {
    /* alloc */
    *pbuf = channel_pbuf_list_get(channel,
                                  sizeof(struct ofp_async_config));
    if (*pbuf != NULL) {
      pbuf_plen_set(*pbuf, sizeof(struct ofp_async_config));

      /* Copy packet_in_mask, port_status_mask, flow_removed_mask. */
      channel_role_mask_get(channel, &async_config);

      /* Fill in header. */
      ofp_header_set(&async_config.header,
                     channel_version_get(channel),
                     OFPT_GET_ASYNC_REPLY,
                     (uint16_t) pbuf_plen_get(*pbuf),
                     xid_header->xid);

      /* Encode message. */
      ret = ofp_async_config_encode(*pbuf, &async_config);

      if (ret != LAGOPUS_RESULT_OK) {
        lagopus_msg_warning("FAILED : ofp_async_config_encode (%s).\n",
                            lagopus_error_get_string(ret));
      }
    } else {
      lagopus_msg_warning("Can't allocate pbuf.\n");
      ret = LAGOPUS_RESULT_NO_MEMORY;
    }

    if (ret != LAGOPUS_RESULT_OK &&  *pbuf != NULL) {
      channel_pbuf_list_unget(channel, *pbuf);
      *pbuf = NULL;
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  return ret;
}
예제 #2
0
static lagopus_result_t
ofp_role_channel_check_mask_wrap(struct channel **channels,
                                 struct ofp_header *xid_headers) {
  struct ofp_async_config role_mask;
  bool rv;
  int i;
  int j;
  uint8_t reason = 0x01;
  int type_test_num = 3;
  uint8_t type[] = {OFPT_PACKET_IN,
                    OFPT_FLOW_REMOVED,
                    OFPT_PORT_STATUS
                   };
  int role_test_num = 3;
  uint32_t role[] = {OFPCR_ROLE_MASTER,
                     OFPCR_ROLE_EQUAL,
                     OFPCR_ROLE_SLAVE
                    };
  (void) xid_headers;

  for (i = 0; i < type_test_num; i++) {
    for (j = 0; j < role_test_num; j++) {
      /* Call func. (Result true.) */
      channel_role_mask_get(channels[0], &role_mask);
      rv = ofp_role_channel_check_mask(&role_mask, type[i], reason, role[j]);
      TEST_ASSERT_EQUAL_MESSAGE(true, rv,
                                "ofp_role_channel_check_mask error.");
    }
  }

  /* unset mask. */
  for (i = 0; i < 2; i++) {
    role_mask.packet_in_mask[i] = 0x00;
    role_mask.port_status_mask[i] = 0x00;
    role_mask.flow_removed_mask[i] = 0x00;
  }

  for (i = 0; i < type_test_num; i++) {
    for (j = 0; j < role_test_num; j++) {
      /* Call func. (Result false.) */
      rv = ofp_role_channel_check_mask(&role_mask, type[i],
                                       reason, role[j]);
      TEST_ASSERT_EQUAL_MESSAGE(false, rv,
                                "ofp_role_channel_check_mask error.");
    }
  }

  /* set mask packet_in_mask[master, equal] only. */
  for (i = 0; i < 2; i++) {
    role_mask.packet_in_mask[i] = 0x01;
    role_mask.port_status_mask[i] = 0x01;
    role_mask.flow_removed_mask[i] = 0x01;
  }
  role_mask.packet_in_mask[0] = 0x02;

  for (i = 0; i < type_test_num; i++) {
    for (j = 0; j < role_test_num; j++) {
      /* Call func. (Result false.) */
      rv = ofp_role_channel_check_mask(&role_mask, type[i],
                                       reason, role[j]);
      if (i == 0 && (j == 0 || j == 1)) {
        /* packet_in_mask[master, equal] */
        TEST_ASSERT_EQUAL_MESSAGE(true, rv,
                                  "ofp_role_channel_check_mask(packet_in, master) error.");
      } else {
        TEST_ASSERT_EQUAL_MESSAGE(false, rv,
                                  "ofp_role_channel_check_mask error.");
      }
    }
  }

  /* Call func (Arg is NULL). */
  rv = ofp_role_channel_check_mask(NULL, type[0], reason, role[0]);
  TEST_ASSERT_EQUAL_MESSAGE(false, rv,
                            "ofp_role_channel_check_mask error.");

  /* Call func (unsport ofp type). */
  rv = ofp_role_channel_check_mask(&role_mask, OFPT_PACKET_OUT,
                                   reason, role[0]);
  TEST_ASSERT_EQUAL_MESSAGE(false, rv,
                            "ofp_role_channel_check_mask error.");

  /* Call func (unsport role type). */
  rv = ofp_role_channel_check_mask(&role_mask, type[0],
                                   reason, OFPCR_ROLE_NOCHANGE);
  TEST_ASSERT_EQUAL_MESSAGE(false, rv,
                            "ofp_role_channel_check_mask error.");

  return LAGOPUS_RESULT_OK;
}