static int test_stats_entry_setup_from_add(void) { of_flow_add_t *add; of_flow_stats_entry_t *entry; of_match_t m1, m2; of_list_action_t *list; of_list_action_t list_out; TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL); TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL); TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0); TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0); TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, NULL) == 0); TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0); TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0); of_flow_add_delete(add); of_flow_stats_entry_delete(entry); /* @todo check action lists agree */ /* Same with an external action list */ TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL); TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL); TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0); TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0); list = of_list_action_new(OF_VERSION_1_0); TEST_ASSERT(list != NULL); TEST_ASSERT(of_list_action_OF_VERSION_1_0_populate(list, 1) != 0); /* Verify matches agree */ TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, list) == 0); TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0); TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0); of_list_action_init(&list_out, OF_VERSION_1_0, 0, 1); of_flow_stats_entry_actions_bind(entry, &list_out); /* Verify lists agree */ TEST_ASSERT(list->length == list_out.length); TEST_ASSERT(memcmp(WBUF_BUF(list->wire_object.wbuf), WBUF_BUF(list_out.wire_object.wbuf), list->length)); of_flow_add_delete(add); of_list_action_delete(list); of_flow_stats_entry_delete(entry); return TEST_PASS; }
/** * Bind an object of type of_list_action_t to the parent of type of_packet_out for * member actions * @param obj Pointer to an object of type of_packet_out. * @param actions Pointer to the child object of type * of_list_action_t to be filled out. * \ingroup of_packet_out * * The parameter actions is filled out to point to the same underlying * wire buffer as its parent. * */ void of_packet_out_actions_bind( of_packet_out_t *obj, of_list_action_t *actions) { of_wire_buffer_t *wbuf; int offset = 0; /* Offset of value relative to the start obj */ int abs_offset; /* Offset of value relative to start of wbuf */ of_version_t ver; int cur_len = 0; /* Current length of object data */ ASSERT(obj->object_id == OF_PACKET_OUT); ver = obj->version; wbuf = OF_OBJECT_TO_WBUF(obj); ASSERT(wbuf != NULL); /* By version, determine offset and current length (where needed) */ switch (ver) { case OF_VERSION_1_0: offset = 16; cur_len = _PACKET_OUT_ACTION_LEN(obj); break; case OF_VERSION_1_1: case OF_VERSION_1_2: case OF_VERSION_1_3: offset = 24; cur_len = _PACKET_OUT_ACTION_LEN(obj); break; default: ASSERT(0); } abs_offset = OF_OBJECT_ABSOLUTE_OFFSET(obj, offset); ASSERT(abs_offset >= 0); ASSERT(cur_len >= 0 && cur_len < 64 * 1024); /* Initialize child */ of_list_action_init(actions, obj->version, 0, 1); /* Attach to parent */ actions->parent = (of_object_t *)obj; actions->wire_object.wbuf = obj->wire_object.wbuf; actions->wire_object.obj_offset = abs_offset; actions->wire_object.owned = 0; actions->length = cur_len; OF_LENGTH_CHECK_ASSERT(obj); return ; }