static void of_set_config_push_wire_types(of_object_t *obj) { unsigned char *buf = OF_OBJECT_BUFFER_INDEX(obj, 0); switch (obj->version) { case OF_VERSION_1_0: case OF_VERSION_1_1: case OF_VERSION_1_2: case OF_VERSION_1_3: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0x9; /* type */ break; default: UNREACHABLE(); } }
static void of_bsn_gentable_bucket_stats_reply_push_wire_types(of_object_t *obj) { unsigned char *buf = OF_OBJECT_BUFFER_INDEX(obj, 0); switch (obj->version) { case OF_VERSION_1_3: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0x13; /* type */ *(uint16_t *)(buf + 8) = htobe16(0xffff); /* stats_type */ *(uint32_t *)(buf + 16) = htobe32(0x5c16c7); /* experimenter */ *(uint32_t *)(buf + 20) = htobe32(0x5); /* subtype */ break; default: UNREACHABLE(); } }
static void of_bsn_get_interfaces_request_push_wire_types(of_object_t *obj) { unsigned char *buf = OF_OBJECT_BUFFER_INDEX(obj, 0); switch (obj->version) { case OF_VERSION_1_0: case OF_VERSION_1_1: case OF_VERSION_1_2: case OF_VERSION_1_3: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0x4; /* type */ *(uint32_t *)(buf + 8) = htobe32(0x5c16c7); /* experimenter */ *(uint32_t *)(buf + 12) = htobe32(0x9); /* subtype */ break; default: UNREACHABLE(); } }
/** * Get match from an object of type of_packet_in. * @param obj Pointer to an object of type of_packet_in. * @param match Pointer to the child object of type * of_match_t to be filled out. * */ int WARN_UNUSED_RESULT of_packet_in_match_get( of_packet_in_t *obj, of_match_t *match) { 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 */ of_octets_t match_octets; /* Serialized string for match */ ASSERT(obj->object_id == OF_PACKET_IN); 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_2: offset = 16; cur_len = _WIRE_MATCH_PADDED_LEN(obj, offset); break; case OF_VERSION_1_3: offset = 24; cur_len = _WIRE_MATCH_PADDED_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); ASSERT(cur_len + abs_offset <= WBUF_CURRENT_BYTES(wbuf)); match_octets.bytes = cur_len; match_octets.data = OF_OBJECT_BUFFER_INDEX(obj, offset); OF_TRY(of_match_deserialize(ver, match, &match_octets)); OF_LENGTH_CHECK_ASSERT(obj); return OF_ERROR_NONE; }
int ind_core_send_error_msg(of_version_t version, indigo_cxn_id_t cxn_id, uint32_t xid, uint16_t type, uint16_t code, of_object_t *bad_obj, of_octets_t *octets) { of_octets_t obj_octets; if (!ind_core_module_enabled) { return INDIGO_ERROR_INIT; } if (bad_obj != NULL) { obj_octets.data = OF_OBJECT_BUFFER_INDEX(bad_obj, 0); obj_octets.bytes = bad_obj->length; octets = &obj_octets; } return indigo_cxn_send_error_msg(version, cxn_id, xid, type, code, octets); }
static void of_flow_modify_push_wire_types(of_object_t *obj) { unsigned char *buf = OF_OBJECT_BUFFER_INDEX(obj, 0); switch (obj->version) { case OF_VERSION_1_0: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0xe; /* type */ *(uint16_t *)(buf + 56) = htobe16(0x1); /* _command */ break; case OF_VERSION_1_1: case OF_VERSION_1_2: case OF_VERSION_1_3: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0xe; /* type */ *(uint8_t *)(buf + 25) = 0x1; /* _command */ break; default: UNREACHABLE(); } }
static void of_queue_stats_reply_push_wire_types(of_object_t *obj) { unsigned char *buf = OF_OBJECT_BUFFER_INDEX(obj, 0); switch (obj->version) { case OF_VERSION_1_0: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0x11; /* type */ *(uint16_t *)(buf + 8) = htobe16(0x5); /* stats_type */ break; case OF_VERSION_1_1: case OF_VERSION_1_2: case OF_VERSION_1_3: *(uint8_t *)(buf + 0) = obj->version; /* version */ *(uint8_t *)(buf + 1) = 0x13; /* type */ *(uint16_t *)(buf + 8) = htobe16(0x5); /* stats_type */ break; default: UNREACHABLE(); } }
int of_packet_in_setup_from_flow_add(of_packet_in_t *obj, of_flow_add_t *flow_add) { int add_len, pkt_in_len; of_wire_buffer_t *wbuf; int abs_offset; int delta; const int pkt_in_match_offset = 16; const int add_match_offset = 48; of_octets_t match_octets; if (obj->version < OF_VERSION_1_2) { /* Nothing to be done before OF 1.2 */ return OF_ERROR_NONE; } /* Transfer match struct from flow add to packet in object */ wbuf = OF_OBJECT_TO_WBUF(obj); pkt_in_len = _WIRE_MATCH_PADDED_LEN(obj, pkt_in_match_offset); add_len = _WIRE_MATCH_PADDED_LEN(flow_add, add_match_offset); match_octets.bytes = add_len; match_octets.data = OF_OBJECT_BUFFER_INDEX(flow_add, add_match_offset); /* Copy data into pkt_in msg */ abs_offset = OF_OBJECT_ABSOLUTE_OFFSET(obj, pkt_in_match_offset); of_wire_buffer_replace_data(wbuf, abs_offset, pkt_in_len, match_octets.data, add_len); /* Not scalar, update lengths if needed */ delta = add_len - pkt_in_len; if (delta != 0) { /* Update parent(s) */ of_object_parent_length_update((of_object_t *)obj, delta); } return OF_ERROR_NONE; }
/** * Set elements in an object of type of_hello. * @param obj Pointer to an object of type of_hello. * @param elements Pointer to the child of type of_list_hello_elem_t. * * If the child's wire buffer is the same as the parent's, then * nothing is done as the changes have already been registered in the * parent. Otherwise, the data in the child's wire buffer is inserted * into the parent's and the appropriate lengths are updated. */ int WARN_UNUSED_RESULT of_hello_elements_set( of_hello_t *obj, of_list_hello_elem_t *elements) { 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 */ int new_len, delta; /* For set, need new length and delta */ ASSERT(obj->object_id == OF_HELLO); 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_3: offset = 8; 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); /* LOCI object type */ new_len = elements->length; /* If underlying buffer already shared; nothing to do */ if (obj->wire_object.wbuf == elements->wire_object.wbuf) { of_wire_buffer_grow(wbuf, abs_offset + new_len); /* Verify that the offsets are correct */ ASSERT(abs_offset == OF_OBJECT_ABSOLUTE_OFFSET(elements, 0)); /* ASSERT(new_len == cur_len); */ /* fixme: may fail for OXM lists */ return OF_ERROR_NONE; } /* Otherwise, replace existing object in data buffer */ of_wire_buffer_replace_data(wbuf, abs_offset, cur_len, OF_OBJECT_BUFFER_INDEX(elements, 0), new_len); /* @fixme Shouldn't this precede copying value's data to buffer? */ if (elements->wire_length_set != NULL) { elements->wire_length_set((of_object_t *)elements, elements->length); } /* Not scalar, update lengths if needed */ delta = new_len - cur_len; if (delta != 0) { /* Update parent(s) */ of_object_parent_length_update((of_object_t *)obj, delta); } OF_LENGTH_CHECK_ASSERT(obj); return OF_ERROR_NONE; }
static int flow_stats_entry_setup_from_flow_add_common(of_flow_stats_entry_t *obj, of_flow_add_t *flow_add, of_object_t *effects, int entry_match_offset, int add_match_offset) { int entry_len, add_len; of_wire_buffer_t *wbuf; int abs_offset; int delta; uint16_t val16; uint64_t cookie; of_octets_t match_octets; /* Transfer the match underlying object from add to stats entry */ wbuf = OF_OBJECT_TO_WBUF(obj); entry_len = _WIRE_MATCH_PADDED_LEN(obj, entry_match_offset); add_len = _WIRE_MATCH_PADDED_LEN(flow_add, add_match_offset); match_octets.bytes = add_len; match_octets.data = OF_OBJECT_BUFFER_INDEX(flow_add, add_match_offset); /* Copy data into flow entry */ abs_offset = OF_OBJECT_ABSOLUTE_OFFSET(obj, entry_match_offset); of_wire_buffer_replace_data(wbuf, abs_offset, entry_len, match_octets.data, add_len); /* Not scalar, update lengths if needed */ delta = add_len - entry_len; if (delta != 0) { /* Update parent(s) */ of_object_parent_length_update((of_object_t *)obj, delta); } of_flow_add_cookie_get(flow_add, &cookie); of_flow_stats_entry_cookie_set(obj, cookie); of_flow_add_priority_get(flow_add, &val16); of_flow_stats_entry_priority_set(obj, val16); of_flow_add_idle_timeout_get(flow_add, &val16); of_flow_stats_entry_idle_timeout_set(obj, val16); of_flow_add_hard_timeout_get(flow_add, &val16); of_flow_stats_entry_hard_timeout_set(obj, val16); /* Effects may come from different places */ if (effects != NULL) { if (obj->version == OF_VERSION_1_0) { OF_TRY(of_flow_stats_entry_actions_set(obj, (of_list_action_t *)effects)); } else { OF_TRY(of_flow_stats_entry_instructions_set(obj, (of_list_instruction_t *)effects)); } } else { if (obj->version == OF_VERSION_1_0) { of_list_action_t actions; of_flow_add_actions_bind(flow_add, &actions); OF_TRY(of_flow_stats_entry_actions_set(obj, &actions)); } else { of_list_instruction_t instructions; of_flow_add_instructions_bind(flow_add, &instructions); OF_TRY(of_flow_stats_entry_instructions_set(obj, &instructions)); } } return OF_ERROR_NONE; }
/** * Set actions in an object of type of_packet_out. * @param obj Pointer to an object of type of_packet_out. * @param actions Pointer to the child of type of_list_action_t. * * If the child's wire buffer is the same as the parent's, then * nothing is done as the changes have already been registered in the * parent. Otherwise, the data in the child's wire buffer is inserted * into the parent's and the appropriate lengths are updated. */ int WARN_UNUSED_RESULT of_packet_out_actions_set( 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 */ int new_len, delta; /* For set, need new length and delta */ 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); /* LOCI object type */ new_len = actions->length; /* If underlying buffer already shared; nothing to do */ if (obj->wire_object.wbuf == actions->wire_object.wbuf) { of_wire_buffer_grow(wbuf, abs_offset + new_len); /* Verify that the offsets are correct */ ASSERT(abs_offset == OF_OBJECT_ABSOLUTE_OFFSET(actions, 0)); /* ASSERT(new_len == cur_len); */ /* fixme: may fail for OXM lists */ return OF_ERROR_NONE; } /* Otherwise, replace existing object in data buffer */ of_wire_buffer_replace_data(wbuf, abs_offset, cur_len, OF_OBJECT_BUFFER_INDEX(actions, 0), new_len); /* Special case for setting action lengths */ _PACKET_OUT_ACTION_LEN_SET(obj, actions->length); /* Not scalar, update lengths if needed */ delta = new_len - cur_len; if (delta != 0) { /* Update parent(s) */ of_object_parent_length_update((of_object_t *)obj, delta); } OF_LENGTH_CHECK_ASSERT(obj); return OF_ERROR_NONE; }