Skip to content

Commit

Permalink
Merge branch 'master' of github.com:floodlight/loxigen
Browse files Browse the repository at this point in the history
Conflicts:
	java_gen/java_type.py
  • Loading branch information
Rob Vaterlaus committed Oct 2, 2013
2 parents 1932960 + d6244dd commit d6e97d4
Show file tree
Hide file tree
Showing 67 changed files with 1,133 additions and 186 deletions.
5 changes: 5 additions & 0 deletions c_gen/c_code_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,11 @@ def base_h_content(out):
typedef char of_desc_str_t[OF_DESC_STR_LEN];
typedef char of_serial_num_t[OF_SERIAL_NUM_LEN];
typedef struct of_bitmap_128_s {
uint64_t hi;
uint64_t lo;
} of_bitmap_128_t;
/* These are types which change across versions. */
typedef uint32_t of_port_no_t;
typedef uint16_t of_fm_cmd_t;
Expand Down
16 changes: 16 additions & 0 deletions c_gen/c_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ def gen_oxm_defines(out):
OF_OXM_INDEX_IPV6_ND_TLL = 33, /* Target link-layer for ND. */
OF_OXM_INDEX_MPLS_LABEL = 34, /* MPLS label. */
OF_OXM_INDEX_MPLS_TC = 35, /* MPLS TC. */
OF_OXM_INDEX_BSN_IN_PORTS_128 = 36,
};
#define OF_OXM_BIT(index) (((uint64_t) 1) << (index))
Expand Down Expand Up @@ -1066,6 +1068,15 @@ def gen_match_comp(out=sys.stdout):
#define OF_OVERLAP_MAC_ADDR(v1, v2, m1, m2) \\
of_overlap_mac_addr((v1), (v2), (m1), (m2))
#define OF_MORE_SPECIFIC_BITMAP_128(v1, v2) \\
(OF_MORE_SPECIFIC_INT((v1)->lo, (v2)->lo) && OF_MORE_SPECIFIC_INT((v1)->hi, (v2)->hi))
#define OF_RESTRICTED_MATCH_BITMAP_128(v1, v2, mask) \\
(OF_RESTRICTED_MATCH_INT((v1)->lo, (v2)->lo, (mask)->lo) && OF_RESTRICTED_MATCH_INT((v1)->hi, (v2)->hi, (mask)->hi))
#define OF_OVERLAP_BITMAP_128(v1, v2, m1, m2) \\
(OF_OVERLAP_INT((v1)->lo, (v2)->lo, (m1)->lo, (m2)->lo) && OF_OVERLAP_INT((v1)->hi, (v2)->hi, (m1)->hi, (m2)->hi))
/**
* More-specific-than macro for integer types; see above
* @return true if v1 is equal to or more specific than v2
Expand Down Expand Up @@ -1136,6 +1147,9 @@ def gen_match_comp(out=sys.stdout):
elif entry["m_type"] == "of_mac_addr_t":
comp = "OF_MORE_SPECIFIC_MAC_ADDR"
match_type = "OF_RESTRICTED_MATCH_MAC_ADDR"
elif entry["m_type"] == "of_bitmap_128_t":
comp = "OF_MORE_SPECIFIC_BITMAP_128"
match_type = "OF_RESTRICTED_MATCH_BITMAP_128"
else: # Integer
comp = "OF_MORE_SPECIFIC_INT"
match_type = "OF_RESTRICTED_MATCH_INT"
Expand Down Expand Up @@ -1190,6 +1204,8 @@ def gen_match_comp(out=sys.stdout):
check = "OF_OVERLAP_IPV6"
elif entry["m_type"] == "of_mac_addr_t":
check = "OF_OVERLAP_MAC_ADDR"
elif entry["m_type"] == "of_bitmap_128_t":
check = "OF_OVERLAP_BITMAP_128"
else: # Integer
check = "OF_OVERLAP_INT"
m1 = "m1->%s" % key
Expand Down
3 changes: 2 additions & 1 deletion c_gen/c_test_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def var_name_map(m_type):
of_match_t="match",
# BSN extensions
of_bsn_vport_q_in_q_t="vport",
of_bitmap_128_t="bitmap_128",
)

if m_type.find("of_list_") == 0:
Expand All @@ -111,7 +112,7 @@ def var_name_map(m_type):
"of_match_bmap_t", "of_ipv4_t"]
string_types = [ "of_port_name_t", "of_table_name_t",
"of_desc_str_t", "of_serial_num_t", "of_mac_addr_t",
"of_ipv6_t"]
"of_ipv6_t", "of_bitmap_128_t"]

scalar_types = integer_types[:]
scalar_types.extend(string_types)
Expand Down
56 changes: 49 additions & 7 deletions c_gen/c_type_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,52 @@ def gen_type_to_obj_map_functions(out):
return obj_id;
}
"""

oxm_template = """
/**
* oxm wire type to object ID array.
* Treat as private; use function accessor below
*/
extern const of_object_id_t *const of_oxm_type_to_id[OF_VERSION_ARRAY_MAX];
#define OF_OXM_ITEM_COUNT %(ar_len)d\n
/**
* Map an oxm wire value to an OF object
* @param oxm The oxm type wire value
* @param version The version associated with the check
* @return The oxm OF object type
* @return OF_OBJECT_INVALID if type does not map to an object
*
*/
static inline of_object_id_t
of_oxm_to_object_id(uint32_t type_len, of_version_t version)
{
if (!OF_VERSION_OKAY(version)) {
return OF_OBJECT_INVALID;
}
uint16_t class = (type_len >> 16) & 0xffff;
uint8_t masked_type = (type_len >> 8) & 0xff;
if (class == 0x8000) {
if (masked_type < 0 || masked_type >= OF_OXM_ITEM_COUNT) {
return OF_OBJECT_INVALID;
}
return of_oxm_type_to_id[version][masked_type];
} else if (class == 0x0003) {
switch (masked_type) {
case 0x00: return OF_OXM_BSN_IN_PORTS_128;
case 0x01: return OF_OXM_BSN_IN_PORTS_128_MASKED;
default: return OF_OBJECT_INVALID;
}
} else {
return OF_OBJECT_INVALID;
}
}
"""

# Action types array gen
Expand Down Expand Up @@ -619,13 +665,14 @@ def gen_type_to_obj_map_functions(out):
out.write(map_template %
dict(name="flow_mod", u_name="FLOW_MOD", ar_len=ar_len))

# OXM
ar_len = type_maps.type_array_len(type_maps.oxm_types, max_type_value)
out.write("""
/* NOTE: We could optimize the OXM and only generate OF 1.2 versions. */
""")
out.write(map_template %
dict(name="oxm", u_name="OXM", ar_len=ar_len))
out.write(oxm_template % dict(ar_len=ar_len))

# Messages
out.write(experimenter_function)
# Must follow stats reply/request
ar_len = type_maps.type_array_len(type_maps.message_types, max_type_value)
Expand Down Expand Up @@ -1105,11 +1152,6 @@ def gen_type_data_header(out):
extern void of_hello_elem_wire_object_id_get(of_object_t *obj,
of_object_id_t *id);
/* XXX Hardcoded to the OpenFlow Basic OXM class */
#define OF_OXM_MASKED_TYPE_GET(hdr) (((hdr) >> 8) & 0xff)
#define OF_OXM_MASKED_TYPE_SET(hdr, val) \\
(hdr) = ((hdr) & 0x000000ff) + 0x80000000 + (((val) & 0xff) << 8)
#define OF_OXM_LENGTH_GET(hdr) (((hdr) & 0xff) + 4)
#define OF_OXM_LENGTH_SET(hdr, val) \\
(hdr) = ((hdr) & 0xffffff00) + (((val) - 4) & 0xff)
Expand Down
2 changes: 2 additions & 0 deletions c_gen/templates/loci_dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ typedef int (*loci_obj_dump_f)(loci_writer_f writer, void *cookie, of_object_t *
int loci_dump_match(loci_writer_f writer, void* cookie, of_match_t *match);
#define LOCI_DUMP_match(writer, cookie, val) loci_dump_match(writer, cookie, &val)

#define LOCI_DUMP_bitmap_128(writer, cookie, val) writer(cookie, "%" PRIx64 "%" PRIx64, (val).hi, (val).lo)

/**
* Generic version for any object
*/
Expand Down
5 changes: 5 additions & 0 deletions c_gen/templates/loci_show.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ typedef int (*loci_obj_show_f)(loci_writer_f writer,
int loci_show_match(loci_writer_f writer, void *cookie, of_match_t *match);
#define LOCI_SHOW_match(writer, cookie, val) loci_show_match(writer, cookie, &val)

#define LOCI_SHOW_bitmap_128(writer, cookie, val) writer(cookie, "%" PRIx64 "%" PRIx64, (val).hi, (val).lo)

/**
* Generic version for any object
*/
Expand Down Expand Up @@ -337,6 +339,9 @@ int of_object_show(loci_writer_f writer, void *cookie, of_object_t *obj);
#define LOCI_SHOW_ipv4_value_mask(writer, cookie, val) LOCI_SHOW_ipv4(writer, cookie, val)
#define LOCI_SHOW_u8_hybrid_enable(writer, cookie, val) LOCI_SHOW_u8(writer, cookie, val)
#define LOCI_SHOW_u16_hybrid_version(writer, cookie, val) LOCI_SHOW_u16(writer, cookie, val)
#define LOCI_SHOW_bitmap_128_value(writer, cookie, val) LOCI_SHOW_bitmap_128(writer, cookie, val)
#define LOCI_SHOW_bitmap_128_value_mask(writer, cookie, val) LOCI_SHOW_bitmap_128(writer, cookie, val)
#define LOCI_SHOW_bitmap_128_bsn_in_ports_128(writer, cookie, val) LOCI_SHOW_bitmap_128(writer, cookie, val)


#endif /* _LOCI_SHOW_H_ */
22 changes: 16 additions & 6 deletions c_gen/templates/of_type_maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,10 @@ void
of_oxm_wire_object_id_get(of_object_t *obj, of_object_id_t *id)
{
uint32_t type_len;
int wire_type;
of_wire_buffer_t *wbuf;

_GET_OXM_TYPE_LEN(obj, &type_len, wbuf);
wire_type = OF_OXM_MASKED_TYPE_GET(type_len);
*id = of_oxm_to_object_id(wire_type, obj->version);
*id = of_oxm_to_object_id(type_len, obj->version);
}

/**
Expand All @@ -584,9 +582,21 @@ of_oxm_wire_object_id_set(of_object_t *obj, of_object_id_t id)

/* Read-modify-write */
_GET_OXM_TYPE_LEN(obj, &type_len, wbuf);
wire_type = of_object_to_wire_type(id, obj->version);
ASSERT(wire_type >= 0);
OF_OXM_MASKED_TYPE_SET(type_len, wire_type);

switch (id) {
case OF_OXM_BSN_IN_PORTS_128:
type_len = 0x00030000 | (type_len & 0xff);
break;
case OF_OXM_BSN_IN_PORTS_128_MASKED:
type_len = 0x00030100 | (type_len & 0xff);
break;
default:
wire_type = of_object_to_wire_type(id, obj->version);
ASSERT(wire_type >= 0);
type_len = 0x80000000 | (wire_type << 8) | (type_len & 0xff);
break;
}

of_wire_buffer_u32_set(wbuf,
OF_OBJECT_ABSOLUTE_OFFSET(obj, OXM_HDR_OFFSET), type_len);
}
Expand Down
24 changes: 24 additions & 0 deletions c_gen/templates/of_wire_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,30 @@ _wbuf_octets_get(of_wire_buffer_t *wbuf, int offset, uint8_t *dst, int bytes) {
#define of_wire_buffer_ipv6_set(buf, offset, addr) \
_wbuf_octets_set(buf, offset, (uint8_t *)&addr, sizeof(of_ipv6_t))

/**
* Get an bitmap_128 address from a wire buffer
* @param wbuf The pointer to the wire buffer structure
* @param offset Offset in the wire buffer
* @param addr Pointer to where to store the bitmap_128 address
*
* Uses the octets function.
*/

#define of_wire_buffer_bitmap_128_get(buf, offset, addr) \
(of_wire_buffer_u64_get(buf, offset, &addr->hi), of_wire_buffer_u64_get(buf, offset+8, &addr->lo))

/**
* Set an bitmap_128 address in a wire buffer
* @param wbuf The pointer to the wire buffer structure
* @param offset Offset in the wire buffer
* @param addr The variable holding bitmap_128 address to store
*
* Uses the octets function.
*/

#define of_wire_buffer_bitmap_128_set(buf, offset, addr) \
(of_wire_buffer_u64_set(buf, offset, addr.hi), of_wire_buffer_u64_set(buf, offset+8, addr.lo))

/* Relocate data from start offset to the end of the buffer to a new position */
static inline void
of_wire_buffer_move_end(of_wire_buffer_t *wbuf, int start_offset, int new_offset)
Expand Down
42 changes: 34 additions & 8 deletions java_gen/java_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
class JavaModel(object):
# registry for enums that should not be generated
# set(${java_enum_name})
enum_blacklist = set(("OFDefinitions", "OFPortNo",))
enum_blacklist = set(("OFDefinitions", "OFPortNo", "OFVlanId"))
# registry for enum *entry* that should not be generated
# map: ${java_enum_name} -> set(${java_entry_entry_name})
enum_entry_blacklist = defaultdict(lambda: set(), OFFlowWildcards=set([ "NW_DST_BITS", "NW_SRC_BITS", "NW_SRC_SHIFT", "NW_DST_SHIFT" ]))
Expand Down Expand Up @@ -138,7 +138,9 @@ class JavaModel(object):
"OFOxmMplsLabel": OxmMapEntry("U32", "MPLS_LABEL", False),
"OFOxmMplsLabelMasked": OxmMapEntry("U32", "MPLS_LABEL", True),
"OFOxmMplsTc": OxmMapEntry("U8", "MPLS_TC", False),
"OFOxmMplsTcMasked": OxmMapEntry("U8", "MPLS_TC", True)
"OFOxmMplsTcMasked": OxmMapEntry("U8", "MPLS_TC", True),
"OFOxmBsnInPorts128": OxmMapEntry("OFBitMask128", "BSN_IN_PORTS_128", False),
"OFOxmBsnInPorts128Masked": OxmMapEntry("OFBitMask128", "BSN_IN_PORTS_128", True)
}

# Registry of nullable properties:
Expand Down Expand Up @@ -286,14 +288,15 @@ def of_factories(self):
annotated_base_class = base_class + "<?>" if base_class == "OFOxm" else base_class

factories[base_class] = OFFactory(package="%s.%s" % (prefix, package),
name=base_class + "s", members=[], remove_prefix=remove_prefix, base_class=annotated_base_class, sub_factories={})
name=base_class + "s", members=[], remove_prefix=remove_prefix, base_class=annotated_base_class, sub_factories={}, xid_generator=False)

factories[""] = OFFactory(
package=prefix,
name="OFFactory",
remove_prefix="",
members=[], base_class="OFMessage", sub_factories=OrderedDict(
("{}{}s".format(n[2].lower(), n[3:]), "{}s".format(n)) for n in sub_factory_classes ))
("{}{}s".format(n[2].lower(), n[3:]), "{}s".format(n)) for n in sub_factory_classes ),
xid_generator=True)

for i in self.interfaces:
for n, factory in factories.items():
Expand All @@ -306,6 +309,13 @@ def of_factories(self):
factory.members.append(i)
break
return factories.values()

@memoize
def factory_of(self, interface):
for factory in self.of_factories:
if interface in factory.members:
return factory
return None

def generate_class(self, clazz):
""" return wether or not to generate implementation class clazz.
Expand All @@ -329,7 +339,7 @@ def generate_class(self, clazz):
return True


class OFFactory(namedtuple("OFFactory", ("package", "name", "members", "remove_prefix", "base_class", "sub_factories"))):
class OFFactory(namedtuple("OFFactory", ("package", "name", "members", "remove_prefix", "base_class", "sub_factories", "xid_generator"))):
@property
def factory_classes(self):
return [ OFFactoryClass(
Expand All @@ -348,6 +358,12 @@ def method_name(self, member, builder=True):
return "build" + n[0].upper() + n[1:]
else:
return n

def of_version(self, version):
for fc in self.factory_classes:
if fc.version == version:
return fc
return None

OFGenericClass = namedtuple("OFGenericClass", ("package", "name"))
class OFFactoryClass(namedtuple("OFFactoryClass", ("package", "name", "interface", "version"))):
Expand Down Expand Up @@ -480,8 +496,10 @@ def class_info(self):
# FIXME: This duplicates inheritance information that is now available in the loxi_ir
# model (note, that the loxi model is on versioned classes). Should check/infer the
# inheritance information from the versioned lox_ir classes.
if re.match(r'OF.+StatsRequest$', self.name):
return ("", "OFStatsRequest", None)
if re.match(r'OFStatsRequest$', self.name):
return ("", "OFMessage", "T extends OFStatsReply")
elif re.match(r'OF.+StatsRequest$', self.name):
return ("", "OFStatsRequest<{}>".format(re.sub(r'Request$', 'Reply', self.name)), None)
elif re.match(r'OF.+StatsReply$', self.name):
return ("", "OFStatsReply", None)
elif re.match(r'OF.+ErrorMsg$', self.name):
Expand Down Expand Up @@ -532,6 +550,10 @@ def class_info(self):
def writeable_members(self):
return [ m for m in self.members if m.is_writeable ]

@memoize
def member_by_name(self, name):
return find(lambda m: m.name == name, self.members)

@property
@memoize
def members(self):
Expand Down Expand Up @@ -1016,7 +1038,11 @@ def package(self):
@property
def name(self):
return self.test_class_name


@property
def interface(self):
return self.java_class.interface

@property
def has_test_data(self):
return test_data.exists(self.data_file_name)
Expand Down
Loading

0 comments on commit d6e97d4

Please sign in to comment.