PostHandshakeNodeProducer help class
[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
9 package org.opendaylight.openflowjava.nx.codec.action;
10
11 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
13 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.NxmNxOutputReg;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputReg;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionOutputRegBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.output.reg.grouping.NxActionOutputRegBuilder;
21
22 /**
23  * Codec for the Nicira OutputRegAction
24  *
25  * @author readams
26  */
27 public class OutputRegCodec extends AbstractActionCodec {
28     public static final int LENGTH = 24;
29     public static final byte SUBTYPE = 15; // NXAST_OUTPUT_REG
30     public static final byte PADDING_IN_OUTPUT_REG_ACTION = 6;
31     public static final NiciraActionSerializerKey SERIALIZER_KEY =
32             new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, NxmNxOutputReg.class);
33     public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
34             new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, SUBTYPE);
35
36     @Override
37     public void serialize(Action input, ByteBuf outBuffer) {
38         ActionOutputReg action = ((ActionOutputReg) input.getActionChoice());
39         serializeHeader(LENGTH, SUBTYPE, outBuffer);
40         outBuffer.writeShort(action.getNxActionOutputReg().getNBits().shortValue());
41         outBuffer.writeInt(action.getNxActionOutputReg().getSrc().intValue());
42         outBuffer.writeShort(action.getNxActionOutputReg().getMaxLen().shortValue());
43         outBuffer.writeZero(6);
44     }
45
46     @Override
47     public Action deserialize(ByteBuf message) {
48         ActionBuilder actionBuilder = deserializeHeader(message);
49         ActionOutputRegBuilder builder = new ActionOutputRegBuilder();
50         NxActionOutputRegBuilder nxActionOutputRegBuilder = new NxActionOutputRegBuilder();
51         nxActionOutputRegBuilder.setNBits(message.readUnsignedShort());
52         nxActionOutputRegBuilder.setSrc(message.readUnsignedInt());
53         nxActionOutputRegBuilder.setMaxLen(message.readUnsignedShort());
54         nxActionOutputRegBuilder.setExperimenterId(getExperimenterId());
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 }