- Update yang models. Add grouping common port with mask.
- Use config mask in the PortConvertor and PortMessageSerializer.
- Update unit tests.
Resolves: bug 4747
Change-Id: If558fea34f86c026ca45ba2853107c2cd82c7f50
Signed-off-by: miroslav.macko <miroslav.macko@pantheon.tech>
}
}
+ grouping common-port-with-mask {
+ uses common-port;
+
+ leaf mask {
+ type port-config;
+ description "Bitmap of OFPPC-* flags to be changed";
+ }
+ }
+
grouping flow-port-status {
leaf reason {
type port-reason;
type uint32;
}
- uses common-port;
-
- leaf mask {
- type port-config;
- description "Bitmap of OFPPC-* flags to be changed";
- }
+ uses common-port-with-mask;
leaf container-name {
type string;
}
container port-message {
- uses common-port;
+ uses common-port-with-mask;
uses ofproto:ofHeader;
}
package org.opendaylight.openflowplugin.impl.protocol.serialization.messages;
+import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import io.netty.buffer.ByteBuf;
+import java.util.Objects;
import org.opendaylight.openflowjava.util.ByteBufUtils;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
* OF protocol versions: 1.3.
*/
public class PortMessageSerializer extends AbstractMessageSerializer<PortMessage> {
+
private static final byte PADDING_IN_PORT_MOD_MESSAGE_01 = 4;
private static final byte PADDING_IN_PORT_MOD_MESSAGE_02 = 2;
private static final byte PADDING_IN_PORT_MOD_MESSAGE_03 = 4;
+ private static final int DEFAULT_PORT_CONFIG_MASK = createPortConfigBitMask(
+ new PortConfig(true, true, true, true));
@Override
public void serialize(final PortMessage message, final ByteBuf outBuffer) {
outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_01);
outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHardwareAddress()));
outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_02);
- final int portConfigBitMask = createPortConfigBitMask(message.getConfiguration());
- outBuffer.writeInt(portConfigBitMask); // Configuration
- outBuffer.writeInt(portConfigBitMask); // Configuration mask
+ outBuffer.writeInt(createPortConfigBitMask(message.getConfiguration()));
+ outBuffer.writeInt(MoreObjects.firstNonNull(createPortConfigBitMask(message.getMask()), DEFAULT_PORT_CONFIG_MASK));
outBuffer.writeInt(createPortFeaturesBitMask(message.getAdvertisedFeatures()));
outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_03);
outBuffer.setShort(index + 2, outBuffer.writerIndex() - index);
return 16;
}
- private static int createPortConfigBitMask(final PortConfig config) {
- return ByteBufUtils.fillBitMaskFromMap(ImmutableMap
+ private static Integer createPortConfigBitMask(final PortConfig config) {
+ return Objects.isNull(config) ? null : ByteBufUtils.fillBitMaskFromMap(ImmutableMap
.<Integer, Boolean>builder()
.put(0, config.isPORTDOWN())
.put(2, config.isNORECV())
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.impl.services.AbstractSimpleService;
import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPortWithMask;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
import org.opendaylight.yangtools.yang.binding.DataObject;
-public final class SingleLayerPortService<O extends DataObject> extends AbstractSimpleService<CommonPort, O> {
+public final class SingleLayerPortService<O extends DataObject> extends AbstractSimpleService<CommonPortWithMask, O> {
public SingleLayerPortService(
final RequestContextStack requestContextStack,
}
@Override
- protected OfHeader buildRequest(final Xid xid, final CommonPort input) throws ServiceException {
+ protected OfHeader buildRequest(final Xid xid, final CommonPortWithMask input) throws ServiceException {
return new PortMessageBuilder(input)
.setVersion(getVersion())
.setXid(xid.getValue())
.setVersion(VERSION)
.setPortNumber(new PortNumberUni(PORT_NUMBER))
.setConfiguration(new PortConfig(IS_NOFWD, IS_NOPACKETIN, IS_NORECV, IS_PORTDOWN))
+ .setMask(new PortConfig(true, true, true, true))
.setAdvertisedFeatures(new PortFeatures(
IS_AUTOENG,
IS_COPPER,
.put(5, IS_NOFWD)
.put(6, IS_NOPACKETIN)
.build());
+
+ final int mask = ByteBufUtils.fillBitMaskFromMap(ImmutableMap
+ .<Integer, Boolean>builder()
+ .put(0, true)
+ .put(2, true)
+ .put(5, true)
+ .put(6, true)
+ .build());
+
assertEquals(out.readInt(), config);
- assertEquals(out.readInt(), config);
+ assertEquals(out.readInt(), mask);
// Port features
assertEquals(out.readInt(), ByteBufUtils.fillBitMask(0,
package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.MoreObjects;
import java.util.Collection;
import java.util.Collections;
+import java.util.Objects;
import java.util.Set;
import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfigV10;
private static PortConfig maskPortConfigFields(
org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
+
+ if (Objects.isNull(configData)) {
+ return null;
+ }
+
Boolean portDown = configData.isPORTDOWN();
Boolean noRecv = configData.isNORECV();
Boolean noFwd = configData.isNOFWD();
private static PortConfigV10 maskPortConfigV10Fields(
org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig configData) {
+
+ if (Objects.isNull(configData)) {
+ return null;
+ }
+
Boolean portDown = configData.isPORTDOWN();
Boolean noRecv = configData.isNORECV();
Boolean noFwd = configData.isNOFWD();
OpenflowPortsUtil.getProtocolPortNumber(OpenflowVersion.get(data.getVersion()), source.getPortNumber())));
portModInputBuilder.setConfig(config);
- portModInputBuilder.setMask(config);
+ portModInputBuilder.setMask(MoreObjects.firstNonNull(maskPortConfigFields(source.getMask()),
+ new PortConfig(true, true, true, true)));
portModInputBuilder.setHwAddress(new MacAddress(source.getHardwareAddress()));
portModInputBuilder.setVersion(data.getVersion());
portModInputBuilder.setConfigV10(configV10);
- portModInputBuilder.setMaskV10(configV10);
+ portModInputBuilder.setMaskV10(MoreObjects.firstNonNull(maskPortConfigV10Fields(source.getMask()),
+ new PortConfigV10(true, true, true, true, true, true, true)));
portModInputBuilder.setAdvertiseV10(getPortFeaturesV10(source.getAdvertisedFeatures()));
return portModInputBuilder.build();
}
new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
false, false, false, false);
+ private org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig configMask31 =
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig(
+ true, true, true, true);
+
+ private PortConfigV10 portConfMaskV10 = new PortConfigV10(true, true, true, true, true, true, true);;
+
/**
* test of {@link org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PortConvertor#convert(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.port.mod.port.Port, org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData)} }
*/
PortModInputBuilder portModInputBld = new PortModInputBuilder();
portModInputBld.setConfig(config31);
- portModInputBld.setMask(config31);
+ portModInputBld.setMask(configMask31);
portModInputBld.setPortNo(
new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber(42L));
portModInputBld.setHwAddress(new MacAddress(DEFAULT_MAC_ADDRESS));
portModInputBld.setAdvertise(portf31);
portModInputBld.setConfigV10(portConfV10);
- portModInputBld.setMaskV10(portConfV10);
+ portModInputBld.setMaskV10(portConfMaskV10);
portModInputBld.setAdvertiseV10(
new PortFeaturesV10(null, null, null, null, null, null, null, true, null, null, null, null));