[OPNFLWPLUG-1102] Refactor OpenFlow protocol serializers/deserializers Created: 02/Sep/20  Updated: 02/May/23

Status: Confirmed
Project: OpenFlowPlugin
Component/s: openflowjava-impl
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Medium
Reporter: Robert Varga Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Examination of the use of this class shows we can reduce code duplication by sharing simple action case serialize. Furthermore we can reuse objects across deserializeHeader() invocations. Similar is true for others, hence audit and refactor them from performance.



 Comments   
Comment by Robert Varga [ 06/Jan/21 ]

A first pass has been made.

We still need to deal with registries, which are quite inefficient. All of the lookups go through generalized MessageCodeKey and similar constructs, forcing callers to create these. Rather than exposing keys in this way, we should provide specialized lookup registries, where all required parameters will be supplied to the lookup method, hence instead of this:

 

    private void writeExperimenterRelatedTableProperty(final ByteBuf output,
            final TableFeatureProperties property) {
        long expId = property.augmentation(ExperimenterIdTableFeatureProperty.class).getExperimenter().getValue()
            .toJava();
        OFSerializer<TableFeatureProperties> serializer = registry.getSerializer(
                ExperimenterSerializerKeyFactory.createMultipartRequestTFSerializerKey(
                        EncodeConstants.OF13_VERSION_ID, expId));
        serializer.serialize(property, output);
    }

we would do something like:

 

    private void writeExperimenterRelatedTableProperty(final ByteBuf output,
            final TableFeatureProperties property) {
        long expId = property.augmentation(ExperimenterIdTableFeatureProperty.class).getExperimenter().getValue()
            .toJava();
        OFSerializer<TableFeatureProperties> serializer = registry.getSerializer(
                EncodeConstants.OF13_VERSION_ID, expId, TableFeatureProperties.class);
        serializer.serialize(property, output);
    }

With this, we can perform a number of internal optimizations to speed up lookup:

  1. have an internal array of per-OF-version registries, i.e. deal with version through a trivial array lookup or through a switch(version) statement
  2. deal with the other two parts in whatever way makes sense – either as a fused key-based registry, or two nested registries

Structuring things this way will also allow us to propagate invariants, such as:

  • peeling the OF versions lookup out of the picture
  • specializing serializer classes, i.e. to have OFSerializer<TableFeatureProperties> have as 'TableFeaturePropertiesSerializer', allowing JIT to perform CHA on potential targets

 

 

Generated at Wed Feb 07 20:34:12 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.