2 * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.experimenter;
11 import io.netty.buffer.ByteBuf;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleControlType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundleProperty;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundlePropertyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.BundleExperimenterPropertyBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControl;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.BundleControlBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
32 * Translates BundleControl messages (OpenFlow v1.3 extension #230).
34 public class BundleControlFactory implements OFDeserializer<BundleControl>, DeserializerRegistryInjector {
36 private DeserializerRegistry deserializerRegistry;
39 public BundleControl deserialize(ByteBuf message) {
40 BundleId bundleId = new BundleId(message.readUnsignedInt());
41 BundleControlType type = BundleControlType.forValue(message.readUnsignedShort());
42 BundleFlags flags = createBundleFlags(message.readUnsignedShort());
43 BundleControlBuilder builder = new BundleControlBuilder();
44 List<BundleProperty> properties = createBundleProperties(message);
45 return builder.setBundleId(bundleId)
48 .setBundleProperty(properties)
52 private static BundleFlags createBundleFlags(final int flags) {
53 Boolean isAtomic = (flags & (1 << 0)) != 0;
54 Boolean isOrdered = (flags & (1 << 1)) != 0;
55 return new BundleFlags(isAtomic, isOrdered);
58 private List<BundleProperty> createBundleProperties(final ByteBuf message) {
59 List<BundleProperty> properties = new ArrayList<>();
60 while (message.readableBytes() > 0) {
61 BundlePropertyType type = BundlePropertyType.forValue(message.readUnsignedShort());
62 int length = message.readUnsignedShort();
63 if (type != null && type.equals(BundlePropertyType.ONFETBPTEXPERIMENTER)) {
64 properties.add(createExperimenterBundleProperty(length, message));
66 message.skipBytes(length);
72 private BundleProperty createExperimenterBundleProperty(final int length, final ByteBuf message) {
73 BundleExperimenterPropertyBuilder experimenterProperty = new BundleExperimenterPropertyBuilder();
74 long experimenterId = message.readUnsignedInt();
75 long expType = message.readUnsignedInt();
76 experimenterProperty.setExperimenter(new ExperimenterId(experimenterId));
77 experimenterProperty.setExpType(expType);
79 OFDeserializer<BundleExperimenterPropertyData> deserializer = deserializerRegistry.getDeserializer(
80 ExperimenterDeserializerKeyFactory.createBundlePropertyDeserializerKey(EncodeConstants.OF13_VERSION_ID,
81 experimenterId, expType));
82 experimenterProperty.setBundleExperimenterPropertyData(deserializer.deserialize(message.readBytes(length - 12)));
84 return new BundlePropertyBuilder().setType(BundlePropertyType.ONFETBPTEXPERIMENTER)
85 .setBundlePropertyEntry(experimenterProperty.build())
90 public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
91 this.deserializerRegistry = deserializerRegistry;