OPNFLWPLUG-985: Service recovery for openfplowplugin
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / PushNshCodec.java
1 /*
2  * Copyright (C) 2015 Intel, 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.ActionPushNsh;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionPushNshBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.push.nsh.grouping.NxActionPushNshBuilder;
20
21 /**
22  * Codec for the push_nsh.
23  */
24 public class PushNshCodec extends AbstractActionCodec {
25     public static final int LENGTH = 16;
26     public static final byte NXAST_PUSH_NSH_SUBTYPE = 38;
27     public static final NiciraActionSerializerKey SERIALIZER_KEY =
28             new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, ActionPushNsh.class);
29     public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
30             new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, NXAST_PUSH_NSH_SUBTYPE);
31     private static final int PADDING = 6;
32
33     @Override
34     public void serialize(Action input, ByteBuf outBuffer) {
35         serializeHeader(LENGTH, NXAST_PUSH_NSH_SUBTYPE, outBuffer);
36         outBuffer.writeZero(PADDING);
37     }
38
39     @Override
40     public Action deserialize(ByteBuf message) {
41         ActionBuilder actionBuilder = deserializeHeader(message);
42         ActionPushNshBuilder builder = new ActionPushNshBuilder();
43         NxActionPushNshBuilder nxActionPushNshBuilder = new NxActionPushNshBuilder();
44         message.skipBytes(PADDING);
45         builder.setNxActionPushNsh(nxActionPushNshBuilder.build());
46         actionBuilder.setActionChoice(builder.build());
47         return actionBuilder.build();
48     }
49
50 }