Esempio n. 1
0
lagopus_result_t
ofp_role_channel_write(struct pbuf *pbuf, uint64_t dpid,
                       uint8_t type, uint8_t reason) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  if (pbuf != NULL) {
    struct role_write_vars v;

    v.type = type;
    v.reason = reason;
    v.pbuf = pbuf;
    v.ret = LAGOPUS_RESULT_ANY_FAILURES;

    channel_mgr_dpid_iterate(dpid, ofp_role_write, (void *) &v);

    ret = v.ret;
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  if (ret == LAGOPUS_RESULT_OK && pbuf != NULL) {
    /* move getp to putp. */
    pbuf_getp_set(pbuf, pbuf_putp_get(pbuf));
  }

  return ret;
}
Esempio n. 2
0
void
test_pbuf_info_store_load_normal(void) {
  struct pbuf *pbuf = pbuf_alloc(PBUF_LENGTH);
  pbuf_info_t pbuf_info;

  /* create test data */
  pbuf->getp = pbuf->data + 1;
  pbuf->putp = pbuf->data + 3;
  pbuf->plen = 2;

  /* call store func. */
  pbuf_info_store(pbuf, &pbuf_info);

  TEST_ASSERT_EQUAL_MESSAGE(pbuf->data + 1, pbuf_getp_get(&pbuf_info),
                            "getp error.");
  TEST_ASSERT_EQUAL_MESSAGE(pbuf->data + 3, pbuf_putp_get(&pbuf_info),
                            "putp error.");
  TEST_ASSERT_EQUAL_MESSAGE(2, pbuf_plen_get(&pbuf_info),
                            "plen error.");

  /* create test data */
  pbuf_reset(pbuf);
  /* check reset. */
  TEST_ASSERT_EQUAL_MESSAGE(pbuf->data, pbuf_getp_get(pbuf),
                            "getp error.");
  TEST_ASSERT_EQUAL_MESSAGE(pbuf->data, pbuf_putp_get(pbuf),
                            "putp error.");
  TEST_ASSERT_EQUAL_MESSAGE(0, pbuf_plen_get(pbuf),
                            "plen error.");

  /* call load func. */
  pbuf_info_load(pbuf, &pbuf_info);

  TEST_ASSERT_EQUAL_MESSAGE(pbuf->data + 1, pbuf_getp_get(pbuf),
                            "getp error.");
  TEST_ASSERT_EQUAL_MESSAGE(pbuf->data + 3, pbuf_putp_get(pbuf),
                            "putp error.");
  TEST_ASSERT_EQUAL_MESSAGE(2, pbuf_plen_get(pbuf),
                            "plen error.");

  /* after. */
  pbuf_free(pbuf);
}
Esempio n. 3
0
lagopus_result_t
ofp_role_channel_write(struct pbuf *pbuf, uint64_t dpid,
                       uint8_t type, uint8_t reason) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  if (pbuf != NULL) {
    struct role_write_vars v;

    v.type = type;
    v.reason = reason;
    v.pbuf = pbuf;
    v.ret = LAGOPUS_RESULT_ANY_FAILURES;

    ret = channel_mgr_dpid_iterate(dpid, ofp_role_write, (void *) &v);

    if (ret != LAGOPUS_RESULT_OK) {
      if (ret == LAGOPUS_RESULT_NOT_OPERATIONAL ||
          ret == LAGOPUS_RESULT_NOT_FOUND) {
        lagopus_msg_info("Channel is not alive, drop asynchronous message(%s)\n",
                         ofp_type_str(v.type));
        /* Not send packet. */
        ret = LAGOPUS_RESULT_OK;
      } else {
        ret = v.ret;
      }
    }
  } else {
    ret = LAGOPUS_RESULT_INVALID_ARGS;
  }

  if (ret == LAGOPUS_RESULT_OK && pbuf != NULL) {
    /* move getp to putp. */
    pbuf_getp_set(pbuf, pbuf_putp_get(pbuf));
  }

  return ret;
}