Ejemplo n.º 1
0
/**
 * Bind an object of type of_list_instruction_t to the parent of type of_flow_modify for
 * member instructions
 * @param obj Pointer to an object of type of_flow_modify.
 * @param instructions Pointer to the child object of type
 * of_list_instruction_t to be filled out.
 * \ingroup of_flow_modify
 *
 * The parameter instructions is filled out to point to the same underlying
 * wire buffer as its parent.
 *
 */
void
of_flow_modify_instructions_bind(
    of_flow_modify_t *obj,
    of_list_instruction_t *instructions)
{
    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(IS_FLOW_MOD_SUBTYPE(obj->object_id));
    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_1:
        offset = 136;
        cur_len = _END_LEN(obj, offset);
        break;
    case OF_VERSION_1_2:
    case OF_VERSION_1_3:
        offset = _FLOW_MODIFY_INSTRUCTIONS_OFFSET(obj);
        cur_len = _END_LEN(obj, offset);
        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_instruction_init(instructions, obj->version, 0, 1);
    /* Attach to parent */
    instructions->parent = (of_object_t *)obj;
    instructions->wire_object.wbuf = obj->wire_object.wbuf;
    instructions->wire_object.obj_offset = abs_offset;
    instructions->wire_object.owned = 0;
    instructions->length = cur_len;

    OF_LENGTH_CHECK_ASSERT(obj);

    return ;
}
of_object_t *
of_list_instruction_new(of_version_t version)
{
    of_object_t *obj;
    int bytes;

    bytes = of_object_fixed_len[version][OF_LIST_INSTRUCTION];

    if ((obj = of_object_new(OF_WIRE_BUFFER_MAX_LENGTH)) == NULL) {
        return NULL;
    }

    of_list_instruction_init(obj, version, bytes, 0);

    return obj;
}