loci: inline of_wire_object into of_object
This extra layer of structs was not needed.
diff --git a/c_gen/c_code_gen.py b/c_gen/c_code_gen.py
index e26ef93..feafe95 100644
--- a/c_gen/c_code_gen.py
+++ b/c_gen/c_code_gen.py
@@ -375,7 +375,7 @@
* Treat as private
*/
#define OF_OBJECT_TO_MESSAGE(obj) \\
- ((of_message_t)(WBUF_BUF((obj)->wire_object.wbuf)))
+ ((of_message_t)(WBUF_BUF((obj)->wbuf)))
/**
* Macro for the fixed length part of an object
@@ -469,8 +469,8 @@
*/
#define OF_LENGTH_CHECK_ASSERT(obj) \\
LOCI_ASSERT(((obj)->parent != NULL) || \\
- ((obj)->wire_object.wbuf == NULL) || \\
- (WBUF_CURRENT_BYTES((obj)->wire_object.wbuf) == (obj)->length))
+ ((obj)->wbuf == NULL) || \\
+ (WBUF_CURRENT_BYTES((obj)->wbuf) == (obj)->length))
#define OF_DEBUG_DUMP
#if defined(OF_DEBUG_DUMP)
@@ -1677,9 +1677,9 @@
%(m_type)s_init(%(m_name)s, obj->version, 0, 1);
/* Attach to parent */
%(m_name)s->parent = (of_object_t *)obj;
- %(m_name)s->wire_object.wbuf = obj->wire_object.wbuf;
- %(m_name)s->wire_object.obj_offset = abs_offset;
- %(m_name)s->wire_object.owned = 0;
+ %(m_name)s->wbuf = obj->wbuf;
+ %(m_name)s->obj_offset = abs_offset;
+ %(m_name)s->owned = 0;
%(m_name)s->length = cur_len;
""" % dict(m_type=m_type[:-2], m_name=m_name))
@@ -1721,7 +1721,7 @@
out.write("""
new_len = %(m_name)s->length;
/* If underlying buffer already shared; nothing to do */
- if (obj->wire_object.wbuf == %(m_name)s->wire_object.wbuf) {
+ if (obj->wbuf == %(m_name)s->wbuf) {
of_wire_buffer_grow(wbuf, abs_offset + new_len);
/* Verify that the offsets are correct */
LOCI_ASSERT(abs_offset == OF_OBJECT_ABSOLUTE_OFFSET(%(m_name)s, 0));
@@ -2060,11 +2060,11 @@
out.write("""
/* Grow the wire buffer */
- if (obj->wire_object.wbuf != NULL) {
+ if (obj->wbuf != NULL) {
int tot_bytes;
- tot_bytes = bytes + obj->wire_object.obj_offset;
- of_wire_buffer_grow(obj->wire_object.wbuf, tot_bytes);
+ tot_bytes = bytes + obj->obj_offset;
+ of_wire_buffer_grow(obj->wbuf, tot_bytes);
}
}
diff --git a/c_gen/c_match.py b/c_gen/c_match.py
index 0da5227..109778b 100644
--- a/c_gen/c_match.py
+++ b/c_gen/c_match.py
@@ -928,7 +928,7 @@
/* Free the wire buffer control block without freeing
* octets->bytes. */
- of_wire_buffer_steal(wire_match.wire_object.wbuf, &tmp);
+ of_wire_buffer_steal(wire_match.wbuf, &tmp);
}
break;
""" % dict(version=version, ver_name=of_g.of_version_wire2name[version]))
diff --git a/c_gen/templates/loci_int.h b/c_gen/templates/loci_int.h
index c57371a..1ea9eeb 100644
--- a/c_gen/templates/loci_int.h
+++ b/c_gen/templates/loci_int.h
@@ -67,8 +67,8 @@
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);
+ of_wire_buffer_u16_get(obj->wbuf,
+ obj->obj_offset + offset, &val16);
return (int)val16;
}
@@ -86,8 +86,8 @@
uint16_t val16;
val16 = (uint16_t)value;
- of_wire_buffer_u16_set(obj->wire_object.wbuf,
- obj->wire_object.obj_offset + offset, val16);
+ of_wire_buffer_u16_set(obj->wbuf,
+ obj->obj_offset + offset, val16);
}
/**
diff --git a/c_gen/templates/locitest/test_setup_from_add.c b/c_gen/templates/locitest/test_setup_from_add.c
index 0b07076..ebb4968 100644
--- a/c_gen/templates/locitest/test_setup_from_add.c
+++ b/c_gen/templates/locitest/test_setup_from_add.c
@@ -112,8 +112,8 @@
/* 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),
+ TEST_ASSERT(memcmp(WBUF_BUF(list->wbuf),
+ WBUF_BUF(list_out.wbuf),
list->length));
of_flow_add_delete(add);
diff --git a/c_gen/templates/of_object.c b/c_gen/templates/of_object.c
index 6f20658..feb447a 100644
--- a/c_gen/templates/of_object.c
+++ b/c_gen/templates/of_object.c
@@ -61,11 +61,11 @@
MEMSET(obj, 0, sizeof(*obj));
if (bytes > 0) {
- if ((obj->wire_object.wbuf = of_wire_buffer_new(bytes)) == NULL) {
+ if ((obj->wbuf = of_wire_buffer_new(bytes)) == NULL) {
FREE(obj);
return NULL;
}
- obj->wire_object.owned = 1;
+ obj->owned = 1;
}
return obj;
@@ -87,8 +87,8 @@
return;
}
- if (obj->wire_object.owned) {
- of_wire_buffer_free(obj->wire_object.wbuf);
+ if (obj->owned) {
+ of_wire_buffer_free(obj->wbuf);
}
FREE(obj);
@@ -114,12 +114,12 @@
MEMSET(dst, 0, sizeof(*dst));
/* Allocate a minimal wire buffer assuming we will not write to it. */
- if ((dst->wire_object.wbuf = of_wire_buffer_new(src->length)) == NULL) {
+ if ((dst->wbuf = of_wire_buffer_new(src->length)) == NULL) {
FREE(dst);
return NULL;
}
- dst->wire_object.owned = 1;
+ dst->owned = 1;
init_fn = of_object_init_map[src->object_id];
init_fn(dst, src->version, src->length, 0);
@@ -204,7 +204,7 @@
}
obj->version = version;
- obj->wire_object.wbuf = wbuf;
+ obj->wbuf = wbuf;
wbuf->buf = msg;
wbuf->alloc_bytes = len;
wbuf->current_bytes = len;
@@ -232,23 +232,19 @@
of_object_buffer_bind(of_object_t *obj, uint8_t *buf, int bytes,
of_buffer_free_f buf_free)
{
- of_wire_object_t *wobj;
of_wire_buffer_t *wbuf;
LOCI_ASSERT(buf != NULL);
LOCI_ASSERT(bytes > 0);
- // LOCI_ASSERT(wobj is not bound);
-
- wobj = &obj->wire_object;
- MEMSET(wobj, 0, sizeof(*wobj));
wbuf = of_wire_buffer_new_bind(buf, bytes, buf_free);
if (wbuf == NULL) {
return OF_ERROR_RESOURCE;
}
- wobj->wbuf = wbuf;
- wobj->owned = 1;
+ obj->wbuf = wbuf;
+ obj->obj_offset = 0;
+ obj->owned = 1;
obj->length = bytes;
return OF_ERROR_NONE;
@@ -284,17 +280,15 @@
object_child_attach(of_object_t *parent, of_object_t *child,
int offset, int bytes)
{
- of_wire_object_t *c_wobj; /* Pointer to child's wire object */
of_wire_buffer_t *wbuf; /* Pointer to common wire buffer manager */
child->parent = parent;
- wbuf = parent->wire_object.wbuf;
+ wbuf = parent->wbuf;
/* Set up the child's wire buf to point to same as parent */
- c_wobj = &child->wire_object;
- c_wobj->wbuf = wbuf;
- c_wobj->obj_offset = parent->wire_object.obj_offset + offset;
- c_wobj->owned = 0;
+ child->wbuf = wbuf;
+ child->obj_offset = parent->obj_offset + offset;
+ child->owned = 0;
/*
* bytes determines if this is a read or write setup.
@@ -305,7 +299,7 @@
int tot_bytes; /* Total bytes to request for buffer if updated */
/* Set up space for the child in the parent's buffer */
- tot_bytes = parent->wire_object.obj_offset + offset + bytes;
+ tot_bytes = parent->obj_offset + offset + bytes;
of_wire_buffer_grow(wbuf, tot_bytes);
child->length = bytes;
@@ -324,7 +318,7 @@
of_object_can_grow(of_object_t *obj, int new_len)
{
return OF_OBJECT_ABSOLUTE_OFFSET(obj, new_len) <=
- WBUF_ALLOC_BYTES(obj->wire_object.wbuf);
+ WBUF_ALLOC_BYTES(obj->wbuf);
}
/**
@@ -398,7 +392,7 @@
of_list_append_bind(of_object_t *parent, of_object_t *child)
{
if (parent == NULL || child == NULL ||
- parent->wire_object.wbuf == NULL) {
+ parent->wbuf == NULL) {
return OF_ERROR_PARAM;
}
@@ -440,7 +434,7 @@
return OF_ERROR_RESOURCE;
}
- of_wire_buffer_grow(list->wire_object.wbuf,
+ of_wire_buffer_grow(list->wbuf,
OF_OBJECT_ABSOLUTE_OFFSET(list, new_len));
MEMCPY(OF_OBJECT_BUFFER_INDEX(list, list->length),
@@ -491,8 +485,8 @@
static int
of_list_is_last(of_object_t *parent, of_object_t *child)
{
- if (child->wire_object.obj_offset + child->length >=
- parent->wire_object.obj_offset + parent->length) {
+ if (child->obj_offset + child->length >=
+ parent->obj_offset + parent->length) {
return 1;
}
@@ -526,7 +520,7 @@
}
/* Offset is relative to parent start */
- offset = (child->wire_object.obj_offset - parent->wire_object.obj_offset) +
+ offset = (child->obj_offset - parent->obj_offset) +
child->length;
object_child_attach(parent, child, offset, 0);
@@ -537,8 +531,8 @@
of_object_wire_buffer_steal(of_object_t *obj, uint8_t **buffer)
{
LOCI_ASSERT(obj != NULL);
- of_wire_buffer_steal(obj->wire_object.wbuf, buffer);
- obj->wire_object.wbuf = NULL;
+ of_wire_buffer_steal(obj->wbuf, buffer);
+ obj->wbuf = NULL;
}
#define _MAX_PARENT_ITERATIONS 4
@@ -565,14 +559,14 @@
obj->length += delta;
of_object_wire_length_set(obj, obj->length);
#ifndef NDEBUG
- wbuf = obj->wire_object.wbuf;
+ wbuf = obj->wbuf;
#endif
/* Asserts for wire length checking */
- LOCI_ASSERT(obj->length + obj->wire_object.obj_offset <=
+ LOCI_ASSERT(obj->length + obj->obj_offset <=
WBUF_CURRENT_BYTES(wbuf));
if (obj->parent == NULL) {
- LOCI_ASSERT(obj->length + obj->wire_object.obj_offset ==
+ LOCI_ASSERT(obj->length + obj->obj_offset ==
WBUF_CURRENT_BYTES(wbuf));
}
@@ -651,8 +645,8 @@
d_wbuf = OF_OBJECT_TO_WBUF(dst);
s_wbuf = OF_OBJECT_TO_WBUF(src);
- dst_offset = dst->wire_object.obj_offset + dst_length;
- src_offset = src->wire_object.obj_offset;
+ dst_offset = dst->obj_offset + dst_length;
+ src_offset = src->obj_offset;
OF_WIRE_BUFFER_INIT_CHECK(d_wbuf, dst_offset + src->length);
MEMCPY(OF_WBUF_BUFFER_POINTER(d_wbuf, dst_offset),
OF_WBUF_BUFFER_POINTER(s_wbuf, 0), src->length);
@@ -671,7 +665,7 @@
of_packet_out_actions_length_set(of_packet_t *obj, int len)
{
if (obj == NULL || obj->object_id != OF_PACKET_IN ||
- obj->wire_object.wbuf == NULL) {
+ obj->wbuf == NULL) {
return OF_ERROR_PARAM;
}
@@ -682,7 +676,7 @@
_packet_out_data_offset_get(of_packet_t *obj)
{
if (obj == NULL || obj->object_id != OF_PACKET_IN ||
- obj->wire_object.wbuf == NULL) {
+ obj->wbuf == NULL) {
return -1;
}
diff --git a/c_gen/templates/of_object.h b/c_gen/templates/of_object.h
index ba73a92..bce0808 100644
--- a/c_gen/templates/of_object.h
+++ b/c_gen/templates/of_object.h
@@ -101,8 +101,16 @@
void of_object_parent_length_update(of_object_t *obj, int delta);
struct of_object_s {
- /* The control block for the underlying data buffer */
- of_wire_object_t wire_object;
+ /** A pointer to the underlying buffer's management structure. */
+ of_wire_buffer_t *wbuf;
+
+ /** The start offset for this object relative to the start of the
+ * underlying buffer */
+ int obj_offset;
+
+ /* Boolean, whether the object owns the wire buffer. */
+ char owned;
+
/* The LOCI type enum value of the object */
of_object_id_t object_id;
diff --git a/c_gen/templates/of_wire_buf.h b/c_gen/templates/of_wire_buf.h
index 0723454..2194321 100644
--- a/c_gen/templates/of_wire_buf.h
+++ b/c_gen/templates/of_wire_buf.h
@@ -62,21 +62,6 @@
of_buffer_free_f free;
} of_wire_buffer_t;
-/**
- * Decouples object from underlying wire buffer
- *
- * Called a 'slice' in some places.
- */
-typedef struct of_wire_object_s {
- /** A pointer to the underlying buffer's management structure. */
- of_wire_buffer_t *wbuf;
- /** The start offset for this object relative to the start of the
- * underlying buffer */
- int obj_offset;
- /* Boolean, whether the object owns the wire buffer. */
- char owned;
-} of_wire_object_t;
-
#define WBUF_BUF(wbuf) (wbuf)->buf
#define WBUF_ALLOC_BYTES(wbuf) (wbuf)->alloc_bytes
#define WBUF_CURRENT_BYTES(wbuf) (wbuf)->current_bytes
@@ -104,15 +89,6 @@
*/
#define OF_WIRE_BUFFER_INDEX(wbuf, offset) (&((WBUF_BUF(wbuf))[offset]))
-/**
- * Return a pointer to a particular offset in the underlying buffer
- * associated with a wire object
- * @param wobj Pointer to an of_wire_object_t structure
- * @param offset The location to reference relative to the start of the object
- */
-#define OF_WIRE_OBJECT_INDEX(wobj, offset) \
- OF_WIRE_BUFFER_INDEX((wobj)->wbuf, (offset) + (wobj)->obj_offset)
-
/****************************************************************
* Object specific macros; of_object_t includes a wire_object
****************************************************************/
@@ -124,7 +100,7 @@
* @param offset The location to reference relative to the start of the object
*/
#define OF_OBJECT_BUFFER_INDEX(obj, offset) \
- OF_WIRE_OBJECT_INDEX(&((obj)->wire_object), offset)
+ OF_WIRE_BUFFER_INDEX((obj)->wbuf, (obj)->obj_offset + offset)
/**
* Return the absolute offset as an integer from a object-relative offset
@@ -132,7 +108,7 @@
* @param offset The location to reference relative to the start of the object
*/
#define OF_OBJECT_ABSOLUTE_OFFSET(obj, offset) \
- ((obj)->wire_object.obj_offset + offset)
+ ((obj)->obj_offset + offset)
/**
@@ -140,7 +116,7 @@
*
* Treat as private
*/
-#define OF_OBJECT_TO_WBUF(obj) ((obj)->wire_object.wbuf)
+#define OF_OBJECT_TO_WBUF(obj) ((obj)->wbuf)