Fix license header violations in extensions/openflowjava
[openflowplugin.git] / extension / openflowjava-extension-nicira-api / src / main / java / org / opendaylight / openflowjava / nx / api / impl / ActionDeserializer.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, 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.api.impl;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.opendaylight.openflowjava.nx.api.NiciraActionDeserializerKey;
14 import org.opendaylight.openflowjava.nx.api.NiciraConstants;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
16 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionDeserializerKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 public class ActionDeserializer implements OFDeserializer<Action> {
23
24     private static final Logger LOG = LoggerFactory.getLogger(ActionDeserializer.class);
25
26     public static final ExperimenterActionDeserializerKey OF13_DESERIALIZER_KEY = new ExperimenterActionDeserializerKey(
27             EncodeConstants.OF13_VERSION_ID, NiciraConstants.NX_VENDOR_ID);
28     public static final ExperimenterActionDeserializerKey OF10_DESERIALIZER_KEY = new ExperimenterActionDeserializerKey(
29             EncodeConstants.OF10_VERSION_ID, NiciraConstants.NX_VENDOR_ID);
30
31     private final short version;
32
33     /**
34      * @param version protocol wire version
35      */
36     public ActionDeserializer(short version) {
37         this.version = version;
38     }
39
40     @Override
41     public Action deserialize(ByteBuf message) {
42         int startPossition = message.readerIndex();
43         // size of experimenter type
44         message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
45         // size of length
46         message.skipBytes(EncodeConstants.SIZE_OF_SHORT_IN_BYTES);
47         long experimenterId = message.readUnsignedInt();
48         if (NiciraConstants.NX_VENDOR_ID != experimenterId) {
49             throw new IllegalStateException("Experimenter ID is not Nicira vendor id but is " + experimenterId);
50         }
51         int subtype = message.readUnsignedShort();
52         NiciraActionDeserializerKey key = new NiciraActionDeserializerKey(version, subtype);
53         OFDeserializer<Action> actionDeserializer = NiciraExtensionCodecRegistratorImpl.getActionDeserializer(key);
54         if (actionDeserializer == null) {
55             LOG.info("No deserializer was found for key {}", key);
56             return null;
57         }
58         message.readerIndex(startPossition);
59         return actionDeserializer.deserialize(message);
60     }
61
62 }