blob: c57371a27c9f7384e134c3423a558efdae392f66 [file] [log] [blame]
:: # Copyright 2013, Big Switch Networks, Inc.
:: #
:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
:: # the following special exception:
:: #
:: # LOXI Exception
:: #
:: # As a special exception to the terms of the EPL, you may distribute libraries
:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
:: # from the LoxiGen Libraries and the notice provided below is (i) included in
:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
:: # documentation for the LoxiGen Libraries, if distributed in binary form.
:: #
:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
:: #
:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
:: # a copy of the EPL at:
:: #
:: # http://www.eclipse.org/legal/epl-v10.html
:: #
:: # Unless required by applicable law or agreed to in writing, software
:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
:: # EPL for the specific language governing permissions and limitations
:: # under the EPL.
::
:: include('_copyright.c')
:: import c_gen.of_g_legacy as of_g
:: flow_mod = of_g.base_length[("of_flow_modify",of_g.VERSION_1_2)]
:: packet_in = of_g.base_length[("of_packet_in",of_g.VERSION_1_2)]
:: packet_in_1_3 = of_g.base_length[("of_packet_in",of_g.VERSION_1_3)]
:: flow_stats = of_g.base_length[("of_flow_stats_entry", of_g.VERSION_1_2)]
:: match1 = of_g.base_length[("of_match_v1",of_g.VERSION_1_0)]
:: match2 = of_g.base_length[("of_match_v2",of_g.VERSION_1_1)]
/******************************************************************************
*
* /module/src/loci_int.h
*
* loci Internal Header
*
*****************************************************************************/
#ifndef __LOCI_INT_H__
#define __LOCI_INT_H__
#include <loci/loci.h>
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define UNREACHABLE() __builtin_unreachable()
#else
#define UNREACHABLE()
#endif
/****************************************************************
* Special case macros for calculating variable lengths and offsets
****************************************************************/
/**
* Get a u16 directly from an offset in an object's wire buffer
* @param obj An of_object_t object
* @param offset Base offset of the uint16 relative to the object
*
*/
static inline int
of_object_u16_get(of_object_t *obj, int offset) {
uint16_t val16;
of_wire_buffer_u16_get(obj->wire_object.wbuf,
obj->wire_object.obj_offset + offset, &val16);
return (int)val16;
}
/**
* Set a u16 directly at an offset in an object's wire buffer
* @param obj An of_object_t object
* @param offset Base offset of the uint16 relative to the object
* @param val The value to store
*
*/
static inline void
of_object_u16_set(of_object_t *obj, int offset, int value) {
uint16_t val16;
val16 = (uint16_t)value;
of_wire_buffer_u16_set(obj->wire_object.wbuf,
obj->wire_object.obj_offset + offset, val16);
}
/**
* Get length of an object with a TLV header with uint16_t
* @param obj An object with a match member
* @param offset The wire offset of the start of the object
*
* The length field follows the type field.
*/
#define _TLV16_LEN(obj, offset) \
(of_object_u16_get((of_object_t *)(obj), (offset) + 2))
/**
* Get length of an object that is the "rest" of the object
* @param obj An object with a match member
* @param offset The wire offset of the start of the object
*
*/
#define _END_LEN(obj, offset) ((obj)->length - (offset))
/**
* Offset of the action_len member in a packet-out object
*/
#define _PACKET_OUT_ACTION_LEN_OFFSET(obj) \
(((obj)->version == OF_VERSION_1_0) ? 14 : 16)
/**
* Get length of the action list object in a packet_out object
* @param obj An object of type of_packet_out
*/
#define _PACKET_OUT_ACTION_LEN(obj) \
(of_object_u16_get((of_object_t *)(obj), _PACKET_OUT_ACTION_LEN_OFFSET(obj)))
/**
* Set length of the action list object in a packet_out object
* @param obj An object of type of_packet_out
*/
#define _PACKET_OUT_ACTION_LEN_SET(obj, len) \
(of_object_u16_set((of_object_t *)(obj), _PACKET_OUT_ACTION_LEN_OFFSET(obj), len))
/*
* Match structs in 1.2 come at the end of the fixed length part
* of structures. They add 8 bytes to the minimal length of the
* message, but are also variable length. This means that the
* type/length offsets are 8 bytes back from the end of the fixed
* length part of the object. The right way to handle this is to
* expose the offset of the match member more explicitly. For now,
* we make the calculation as described here.
*/
/* 1.2 min length of match is 8 bytes */
#define _MATCH_MIN_LENGTH_V3 8
/**
* The offset of a 1.2 match object relative to fixed length of obj
*/
#define _MATCH_OFFSET_V3(fixed_obj_len) \
((fixed_obj_len) - _MATCH_MIN_LENGTH_V3)
/**
* The "extra" length beyond the minimal 8 bytes of a match struct
* in an object
*/
#define _MATCH_EXTRA_LENGTH_V3(obj, fixed_obj_len) \
(OF_MATCH_BYTES(_TLV16_LEN(obj, _MATCH_OFFSET_V3(fixed_obj_len))) - \
_MATCH_MIN_LENGTH_V3)
/**
* The offset of an object following a match object for 1.2
*/
#define _OFFSET_FOLLOWING_MATCH_V3(obj, fixed_obj_len) \
((fixed_obj_len) + _MATCH_EXTRA_LENGTH_V3(obj, fixed_obj_len))
/**
* Get length of a match object from its wire representation
* @param obj An object with a match member
* @param match_offset The wire offset of the match object.
*
* See above; for 1.2,
* The match length is raw bytes but the actual space it takes
* up is padded for alignment to 64-bits
*/
#define _WIRE_MATCH_LEN(obj, match_offset) \
(((obj)->version == OF_VERSION_1_0) ? ${match1} : \
(((obj)->version == OF_VERSION_1_1) ? ${match2} : \
_TLV16_LEN(obj, match_offset)))
#define _WIRE_LEN_MIN 4
/*
* Wrapper function for match len. There are cases where the wire buffer
* has not been set with the proper minimum length. In this case, the
* wire match len is interpretted as its minimum length, 4 bytes.
*/
static inline int
wire_match_len(of_object_t *obj, int match_offset) {
int len;
len = _WIRE_MATCH_LEN(obj, match_offset);
return (len == 0) ? _WIRE_LEN_MIN : len;
}
#define _WIRE_MATCH_PADDED_LEN(obj, match_offset) \
OF_MATCH_BYTES(wire_match_len((of_object_t *)(obj), (match_offset)))
/**
* Macro to calculate variable offset of instructions member in flow mod
* @param obj An object of some type of flow modify/add/delete
*
* Get length of preceding match object and add to fixed length
* Applies only to version 1.2
*/
#define _FLOW_MOD_INSTRUCTIONS_OFFSET(obj) \
_OFFSET_FOLLOWING_MATCH_V3(obj, ${flow_mod})
/* The different flavors of flow mod all use the above */
#define _FLOW_ADD_INSTRUCTIONS_OFFSET(obj) \
_FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
#define _FLOW_MODIFY_INSTRUCTIONS_OFFSET(obj) \
_FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
#define _FLOW_MODIFY_STRICT_INSTRUCTIONS_OFFSET(obj) \
_FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
#define _FLOW_DELETE_INSTRUCTIONS_OFFSET(obj) \
_FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
#define _FLOW_DELETE_STRICT_INSTRUCTIONS_OFFSET(obj) \
_FLOW_MOD_INSTRUCTIONS_OFFSET(obj)
/**
* Macro to calculate variable offset of instructions member in flow stats
* @param obj An object of type of_flow_mod_t
*
* Get length of preceding match object and add to fixed length
* Applies only to version 1.2 and 1.3
*/
#define _FLOW_STATS_ENTRY_INSTRUCTIONS_OFFSET(obj) \
_OFFSET_FOLLOWING_MATCH_V3(obj, ${flow_stats})
/**
* Macro to calculate variable offset of data (packet) member in packet_in
* @param obj An object of type of_packet_in_t
*
* Get length of preceding match object and add to fixed length
* Applies only to version 1.2 and 1.3
* The +2 comes from the 2 bytes of padding between the match and packet data.
*/
#define _PACKET_IN_DATA_OFFSET(obj) \
(_OFFSET_FOLLOWING_MATCH_V3((obj), (obj)->version == OF_VERSION_1_2 ? \
${packet_in} : ${packet_in_1_3}) + 2)
/**
* Macro to calculate variable offset of data (packet) member in packet_out
* @param obj An object of type of_packet_out_t
*
* Find the length in the actions_len variable and add to the fixed len
* Applies only to version 1.2 and 1.3
*/
#define _PACKET_OUT_DATA_OFFSET(obj) (_PACKET_OUT_ACTION_LEN(obj) + \
of_object_fixed_len[(obj)->version][OF_PACKET_OUT])
/**
* Macro to map port numbers that changed across versions
* @param port The port_no_t variable holding the value
* @param ver The OpenFlow version from which the value was extracted
*/
#define OF_PORT_NO_VALUE_CHECK(port, ver) \
if (((ver) == OF_VERSION_1_0) && ((port) > 0xff00)) (port) += 0xffff0000
/**
* Macro to detect if an object ID falls in the "flow mod" family of objects
* This includes add, modify, modify_strict, delete and delete_strict
*/
#define IS_FLOW_MOD_SUBTYPE(object_id) \
(((object_id) == OF_FLOW_MODIFY) || \
((object_id) == OF_FLOW_MODIFY_STRICT) || \
((object_id) == OF_FLOW_DELETE) || \
((object_id) == OF_FLOW_DELETE_STRICT) || \
((object_id) == OF_FLOW_ADD))
/**
* Macro to calculate variable offset of value member in of_bsn_gentable_entry_add
* @param obj An object of type of_bsn_gentable_entry_add_t
*/
#define _BSN_GENTABLE_ENTRY_ADD_VALUE_OFFSET(obj) \
(of_object_u16_get(obj, 18) + \
of_object_fixed_len[(obj)->version][OF_BSN_GENTABLE_ENTRY_ADD])
#define _BSN_GENTABLE_ENTRY_DESC_STATS_ENTRY_VALUE_OFFSET(obj) \
(of_object_u16_get(obj, 2) + \
of_object_fixed_len[(obj)->version][OF_BSN_GENTABLE_ENTRY_DESC_STATS_ENTRY])
#define _BSN_GENTABLE_ENTRY_STATS_ENTRY_STATS_OFFSET(obj) \
(of_object_u16_get(obj, 2) + \
of_object_fixed_len[(obj)->version][OF_BSN_GENTABLE_ENTRY_STATS_ENTRY])
#endif /* __LOCI_INT_H__ */