2 * Copyright (c) 2018 SUSE LINUX GmbH. All rights reserved.
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
9 package org.opendaylight.openflowjava.nx.codec.action;
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.ActionDecap;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionDecapBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.decap.grouping.NxActionDecap;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.decap.grouping.NxActionDecapBuilder;
22 public class DecapCodec extends AbstractActionCodec {
24 public static final int LENGTH = 16;
25 private static final int NXAST_DECAP_SUBTYPE = 47;
26 private static final int PADDING = 2;
28 public static final NiciraActionSerializerKey SERIALIZER_KEY =
29 new NiciraActionSerializerKey(EncodeConstants.OF13_VERSION_ID, ActionDecap.class);
30 public static final NiciraActionDeserializerKey DESERIALIZER_KEY =
31 new NiciraActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, NXAST_DECAP_SUBTYPE);
34 public Action deserialize(ByteBuf message) {
35 final ActionBuilder actionBuilder = deserializeHeader(message);
37 message.skipBytes(PADDING);
38 long packetType = message.readUnsignedInt();
39 NxActionDecap nxActionDecap = new NxActionDecapBuilder().setPacketType(packetType).build();
40 ActionDecap actionDecap = new ActionDecapBuilder().setNxActionDecap(nxActionDecap).build();
41 actionBuilder.setActionChoice(actionDecap);
42 return actionBuilder.build();
46 public void serialize(Action input, ByteBuf outBuffer) {
47 serializeHeader(LENGTH, NXAST_DECAP_SUBTYPE, outBuffer);
49 outBuffer.writeZero(PADDING);
50 ActionDecap actionDecap = (ActionDecap) input.getActionChoice();
51 Long packetType = actionDecap.getNxActionDecap().getPacketType();
52 outBuffer.writeInt(packetType.intValue());