Bug 6259 - ArbitraryBitMask compare
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / SetNshc2Codec.java
1 /*
2  * Copyright (c) 2015 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
13 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
14 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc2;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc2Builder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nshc._2.grouping.NxActionSetNshc2Builder;
21
22 /**
23  * Codec for the NX_SetNsp and NX_SetNsp_TABLE
24  */
25 public class SetNshc2Codec extends AbstractActionCodec {
26     public static final int LENGTH = 16;
27     public static final byte NXAST_SET_NSC_SUBTYPE = 35;
28     public static final NiciraActionSerializerKey SERIALIZER_KEY =
29             new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, ActionSetNshc2.class);
30     public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
31             new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, NXAST_SET_NSC_SUBTYPE);
32     private static final int padding = 2; // nx_action_SetNsp : uint8_t pad[3];
33
34     @Override
35     public void serialize(Action input, ByteBuf outBuffer) {
36         ActionSetNshc2 action = ((ActionSetNshc2) input.getActionChoice());
37         serializeHeader(LENGTH, NXAST_SET_NSC_SUBTYPE, outBuffer);
38         outBuffer.writeZero(padding);
39         outBuffer.writeInt(action.getNxActionSetNshc2().getNshc().intValue());
40     }
41
42     @Override
43     public Action deserialize(ByteBuf message) {
44         ActionBuilder actionBuilder = deserializeHeader(message);
45         ActionSetNshc2Builder builder = new ActionSetNshc2Builder();
46         NxActionSetNshc2Builder nxActionSetNspBuilder = new NxActionSetNshc2Builder();
47         message.skipBytes(padding);
48         nxActionSetNspBuilder.setNshc(message.readUnsignedInt());
49         builder.setNxActionSetNshc2(nxActionSetNspBuilder.build());
50         actionBuilder.setActionChoice(builder.build());
51         return actionBuilder.build();
52     }
53
54 }