Exemplo n.º 1
0
void
test_lagopus_get_port_statistics(void) {
    datastore_bridge_info_t info;
    struct bridge *bridge;
    struct ofp_port_stats_request req;
    struct port_stats_list list;
    struct ofp_error error;
    lagopus_result_t rv;

    memset(&info, 0, sizeof(info));
    info.fail_mode = DATASTORE_BRIDGE_FAIL_MODE_SECURE;
    rv = dp_bridge_create("br0", &info);
    TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK,
                              "bridge add error");

    bridge = dp_bridge_lookup("br0");
    TEST_ASSERT_NOT_NULL_MESSAGE(bridge, "dp_bridge_lookup error");
    req.port_no = 1;
    TAILQ_INIT(&list);
    rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error);
    TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OFP_ERROR, "result error");

    req.port_no = OFPP_ANY;
    TAILQ_INIT(&list);
    rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error);
    TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "result error");
    TEST_ASSERT_NULL_MESSAGE(TAILQ_FIRST(&list), "empty list error");

    TEST_ASSERT_EQUAL(dp_port_create("port1"), LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_interface_create("interface1"), LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_port_interface_set("port1", "interface1"),
                      LAGOPUS_RESULT_OK);
    TEST_ASSERT_EQUAL(dp_bridge_port_set("br0", "port1", 1), LAGOPUS_RESULT_OK);

    req.port_no = OFPP_ANY;
    TAILQ_INIT(&list);
    rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error);
    TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "result error");
    TEST_ASSERT_NOT_NULL_MESSAGE(TAILQ_FIRST(&list), "list error");

    req.port_no = 1;
    TAILQ_INIT(&list);
    rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error);
    TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OK, "result error");
    TEST_ASSERT_NOT_NULL_MESSAGE(TAILQ_FIRST(&list), "list error");

    req.port_no = 5;
    TAILQ_INIT(&list);
    rv = lagopus_get_port_statistics(bridge->ports, &req, &list, &error);
    TEST_ASSERT_EQUAL_MESSAGE(rv, LAGOPUS_RESULT_OFP_ERROR, "result error");
}
Exemplo n.º 2
0
/*
 * port_stats (Agent/DP API)
 */
lagopus_result_t
ofp_port_stats_request_get(uint64_t dpid,
                           struct ofp_port_stats_request *port_stats_request,
                           struct port_stats_list *port_stats_list,
                           struct ofp_error *error) {
  struct bridge *bridge;

  bridge = dp_bridge_lookup_by_dpid(dpid);
  if (bridge == NULL) {
    return LAGOPUS_RESULT_NOT_FOUND;
  }

  return lagopus_get_port_statistics(bridge->ports,
                                     port_stats_request,
                                     port_stats_list,
                                     error);
}