Migrate uint/ByteBuf interactions
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / OutputRegCodec.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.nx.codec.action;
9
10 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint16;
11 import static org.opendaylight.yangtools.yang.common.netty.ByteBufUtils.readUint32;
12
13 import io.netty.buffer.ByteBuf;
14 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
15 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputReg;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputRegBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.output.reg.grouping.NxActionOutputRegBuilder;
22
23 /**
24  * Codec for the Nicira OutputRegAction.
25  *
26  * @author readams
27  */
28 public class OutputRegCodec extends AbstractActionCodec {
29     public static final int LENGTH = 24;
30     public static final byte SUBTYPE = 15; // NXAST_OUTPUT_REG
31     public static final byte PADDING_IN_OUTPUT_REG_ACTION = 6;
32     public static final NiciraActionSerializerKey SERIALIZER_KEY =
33             new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, ActionOutputReg.class);
34     public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
35             new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, SUBTYPE);
36
37     @Override
38     public void serialize(final Action input, final ByteBuf outBuffer) {
39         ActionOutputReg action = (ActionOutputReg) input.getActionChoice();
40         serializeHeader(LENGTH, SUBTYPE, outBuffer);
41         outBuffer.writeShort(action.getNxActionOutputReg().getNBits().shortValue());
42         outBuffer.writeInt(action.getNxActionOutputReg().getSrc().intValue());
43         outBuffer.writeShort(action.getNxActionOutputReg().getMaxLen().shortValue());
44         outBuffer.writeZero(6);
45     }
46
47     @Override
48     public Action deserialize(final ByteBuf message) {
49         final ActionBuilder actionBuilder = deserializeHeader(message);
50         final ActionOutputRegBuilder builder = new ActionOutputRegBuilder();
51         NxActionOutputRegBuilder nxActionOutputRegBuilder = new NxActionOutputRegBuilder();
52         nxActionOutputRegBuilder.setNBits(readUint16(message));
53         nxActionOutputRegBuilder.setSrc(readUint32(message));
54         nxActionOutputRegBuilder.setMaxLen(readUint16(message));
55         message.skipBytes(PADDING_IN_OUTPUT_REG_ACTION);
56         builder.setNxActionOutputReg(nxActionOutputRegBuilder.build());
57         actionBuilder.setActionChoice(builder.build());
58         return actionBuilder.build();
59     }
60
61 }