Extension support - easy lookup for toOFJava
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / RegLoadCodec.java
1 package org.opendaylight.openflowjava.nx.codec.action;
2
3 import io.netty.buffer.ByteBuf;
4
5 import java.math.BigInteger;
6
7 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
8 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
9 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.NxmNxRegLoad;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjAugNxAction;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.OfjAugNxActionBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.load.grouping.ActionRegLoad;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.load.grouping.ActionRegLoadBuilder;
18
19 public class RegLoadCodec extends AbstractActionCodec {
20
21     public static final int LENGTH = 24;
22     public static final byte SUBTYPE = 7; // NXAST_REG_LOAD
23     public static final NiciraActionSerializerKey SERIALIZER_KEY = new NiciraActionSerializerKey(
24             EncodeConstants.OF13_VERSION_ID, NxmNxRegLoad.class);
25     public static final NiciraActionDeserializerKey DESERIALIZER_KEY = new NiciraActionDeserializerKey(
26             EncodeConstants.OF13_VERSION_ID, SUBTYPE);
27
28     @Override
29     public void serialize(Action input, ByteBuf outBuffer) {
30         ActionRegLoad actionRegLoad = input.getAugmentation(OfjAugNxAction.class).getActionRegLoad();
31         serializeHeader(LENGTH, SUBTYPE, outBuffer);
32         outBuffer.writeShort(actionRegLoad.getOfsNbits());
33         outBuffer.writeInt(actionRegLoad.getDst().intValue());
34         outBuffer.writeLong(actionRegLoad.getValue().longValue());
35     }
36
37     @Override
38     public Action deserialize(ByteBuf message) {
39         ActionBuilder actionBuilder = deserializeHeader(message);
40         ActionRegLoadBuilder actionRegLoadBuilder = new ActionRegLoadBuilder();
41         actionRegLoadBuilder.setOfsNbits(message.readUnsignedShort());
42         actionRegLoadBuilder.setDst(message.readUnsignedInt());
43         actionRegLoadBuilder.setValue(BigInteger.valueOf(message.readLong()));
44         OfjAugNxActionBuilder augNxActionBuilder = new OfjAugNxActionBuilder();
45         augNxActionBuilder.setActionRegLoad(actionRegLoadBuilder.build());
46         actionBuilder.addAugmentation(ExperimenterIdAction.class, createExperimenterIdAction(NxmNxRegLoad.class));
47         actionBuilder.addAugmentation(OfjAugNxAction.class, augNxActionBuilder.build());
48         return actionBuilder.build();
49     }
50
51 }