586e4a1a51a7537ae9f922a85eaf3c73413deade
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / main / java / org / opendaylight / openflowjava / nx / codec / action / CtClearCodec.java
1 /*
2  * Copyright (C) 2018 Redhat, 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 io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
12 import org.opendaylight.openflowjava.nx.api.NiciraActionSerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.aug.nx.action.ActionCtClear;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.aug.nx.action.ActionCtClearBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.ct.clear.grouping.NxActionCtClearBuilder;
19
20 /**
21  * Codec for the ct_Clear.
22  */
23 public class CtClearCodec extends AbstractActionCodec {
24     private static final int LENGTH = 16;
25     private static final byte NX_CT_CLEAR_SUBTYPE = 43;
26     public static final NiciraActionSerializerKey SERIALIZER_KEY =
27             new NiciraActionSerializerKey(EncodeConstants.OF_VERSION_1_3, ActionCtClear.class);
28     public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
29             new NiciraActionDeserializerKey(EncodeConstants.OF_VERSION_1_3, NX_CT_CLEAR_SUBTYPE);
30     private static final int PADDING = 6;
31
32     @Override
33     public void serialize(final Action input, final ByteBuf outBuffer) {
34         serializeHeader(LENGTH, NX_CT_CLEAR_SUBTYPE, outBuffer);
35         outBuffer.writeZero(PADDING);
36     }
37
38     @Override
39     public Action deserialize(final ByteBuf message) {
40         ActionBuilder actionBuilder = deserializeHeader(message);
41         ActionCtClearBuilder builder = new ActionCtClearBuilder();
42         NxActionCtClearBuilder nxActionCtClearBuilder = new NxActionCtClearBuilder();
43         message.skipBytes(PADDING);
44         builder.setNxActionCtClear(nxActionCtClearBuilder.build());
45         actionBuilder.setActionChoice(builder.build());
46         return actionBuilder.build();
47     }
48 }