abd1284b88e32568a8580b3333ffc744516d4da7
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / action / OF13PushMplsActionDeserializer.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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.protocol.impl.deserialization.action;
9
10 import io.netty.buffer.ByteBuf;
11 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
12 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PushMplsCaseBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.push.mpls._case.PushMplsActionBuilder;
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.openflow.common.types.rev130731.EtherType;
19 import org.opendaylight.yangtools.yang.common.netty.ByteBufUtils;
20
21 /**
22  * OF13PushMplsActionDeserializer.
23  *
24  * @author michal.polkorab
25  */
26 public class OF13PushMplsActionDeserializer extends AbstractActionDeserializer {
27
28     @Override
29     public Action deserialize(ByteBuf input) {
30         final ActionBuilder builder = new ActionBuilder();
31         input.skipBytes(2 * EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
32         PushMplsCaseBuilder caseBuilder = new PushMplsCaseBuilder();
33         PushMplsActionBuilder mplsBuilder = new PushMplsActionBuilder();
34         mplsBuilder.setEthertype(new EtherType(ByteBufUtils.readUint16(input)));
35         caseBuilder.setPushMplsAction(mplsBuilder.build());
36         builder.setActionChoice(caseBuilder.build());
37         input.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING);
38         return builder.build();
39     }
40
41     @Override
42     protected ActionChoice getType() {
43         return new PushMplsCaseBuilder().build();
44     }
45 }