org.opendaylight.openflowjava.nx.codec.action.MultipathCodec Maven / Gradle / Ivy
/*
* Copyright (c) 2014 SDN Hub, LLC. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.openflowjava.nx.codec.action;
import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
import io.netty.buffer.ByteBuf;
import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxHashFields;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjNxMpAlgorithm;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.aug.nx.action.ActionMultipath;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.aug.nx.action.ActionMultipathBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.multipath.grouping.NxActionMultipathBuilder;
/**
* Codec for the NX_MULTIPATH.
*/
public class MultipathCodec extends AbstractActionCodec {
public static final int LENGTH = 32;
public static final byte NXAST_MULTIPATH_SUBTYPE = 10;
public static final NiciraActionSerializerKey SERIALIZER_KEY =
new NiciraActionSerializerKey(EncodeConstants.OF_VERSION_1_3, ActionMultipath.class);
public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
new NiciraActionDeserializerKey(EncodeConstants.OF_VERSION_1_3, NXAST_MULTIPATH_SUBTYPE);
@Override
public void serialize(final Action input, final ByteBuf outBuffer) {
ActionMultipath action = (ActionMultipath) input.getActionChoice();
serializeHeader(LENGTH, NXAST_MULTIPATH_SUBTYPE, outBuffer);
outBuffer.writeShort(action.getNxActionMultipath().getFields().getIntValue());
outBuffer.writeShort(action.getNxActionMultipath().getBasis().shortValue());
outBuffer.writeZero(2);
outBuffer.writeShort(action.getNxActionMultipath().getAlgorithm().getIntValue());
outBuffer.writeShort(action.getNxActionMultipath().getMaxLink().shortValue());
outBuffer.writeInt(action.getNxActionMultipath().getArg().intValue());
outBuffer.writeZero(2);
outBuffer.writeShort(action.getNxActionMultipath().getOfsNbits().shortValue());
outBuffer.writeInt(action.getNxActionMultipath().getDst().intValue());
}
@Override
public Action deserialize(final ByteBuf message) {
final ActionBuilder actionBuilder = deserializeHeader(message);
final ActionMultipathBuilder actionMultipathBuilder = new ActionMultipathBuilder();
NxActionMultipathBuilder nxActionMultipathBuilder = new NxActionMultipathBuilder();
nxActionMultipathBuilder.setFields(OfjNxHashFields.forValue(message.readUnsignedShort()));
nxActionMultipathBuilder.setBasis(readUint16(message));
message.skipBytes(2); //two bytes
nxActionMultipathBuilder.setAlgorithm(OfjNxMpAlgorithm.forValue(message.readUnsignedShort()));
nxActionMultipathBuilder.setMaxLink(readUint16(message));
nxActionMultipathBuilder.setArg(readUint32(message));
message.skipBytes(2); //two bytes
nxActionMultipathBuilder.setOfsNbits(readUint16(message));
nxActionMultipathBuilder.setDst(readUint32(message));
actionMultipathBuilder.setNxActionMultipath(nxActionMultipathBuilder.build());
actionBuilder.setActionChoice(actionMultipathBuilder.build());
return actionBuilder.build();
}
}