96e5f566982758a6511c5dd00dd1dc1fb3cee42e
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / SetNsiCodec.java
1 /*
2  * Copyright (C) 2014, 2015 Red Hat, 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.action.container.action.choice.ActionSetNsi;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNsiBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nsi.grouping.NxActionSetNsiBuilder;
20
21 /**
22  * Codec for the NX_SetNsi and NX_SetNsi_TABLE
23  */
24 public class SetNsiCodec extends AbstractActionCodec {
25     public static final int LENGTH = 16;
26     public static final byte NXAST_SET_NSI_SUBTYPE = 33;
27     public static final NiciraActionSerializerKey SERIALIZER_KEY =
28             new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, ActionSetNsi.class);
29     public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
30             new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, NXAST_SET_NSI_SUBTYPE);
31     private static final int padding = 5; // nx_action_SetNsi : uint8_t pad[3];
32
33     @Override
34     public void serialize(final Action input, final ByteBuf outBuffer) {
35         ActionSetNsi action = ((ActionSetNsi) input.getActionChoice());
36         serializeHeader(LENGTH, NXAST_SET_NSI_SUBTYPE, outBuffer);
37         outBuffer.writeByte(action.getNxActionSetNsi().getNsi().byteValue());
38         outBuffer.writeZero(padding);
39     }
40
41     @Override
42     public Action deserialize(final ByteBuf message) {
43         ActionBuilder actionBuilder = deserializeHeader(message);
44         ActionSetNsiBuilder builder = new ActionSetNsiBuilder();
45         NxActionSetNsiBuilder nxActionSetNsiBuilder = new NxActionSetNsiBuilder();
46         nxActionSetNsiBuilder.setNsi(message.readUnsignedByte());
47         message.skipBytes(padding);
48
49         builder.setNxActionSetNsi(nxActionSetNsiBuilder.build());
50         actionBuilder.setActionChoice(builder.build());
51         return actionBuilder.build();
52     }
53
54 }