Fix checkstyle API.
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / extension / ActionExtensionHelper.java
1 /**
2  * Copyright (c) 2014 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 package org.opendaylight.openflowplugin.openflow.md.core.extension;
9
10 import java.util.Objects;
11 import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey;
12 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
16 import org.opendaylight.openflowplugin.extension.api.core.extension.ExtensionConverterProvider;
17 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
18 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice.ExperimenterIdCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 /**
25  *
26  */
27 public final class ActionExtensionHelper {
28
29     private static final Logger LOG = LoggerFactory
30             .getLogger(ActionExtensionHelper.class);
31
32     private ActionExtensionHelper() {
33         throw new IllegalAccessError("singleton enforcement");
34     }
35
36     /**
37      * @param action openflow action
38      * @param ofVersion openflow version
39      * @param actionPath openflow action path
40      * @return augmentation wrapper containing augmentation depending on matchPath
41      */
42     public static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
43     processAlienAction(final Action action, final OpenflowVersion ofVersion, final ActionPath actionPath) {
44         ConvertorActionFromOFJava<Action, ActionPath> convertor = null;
45         org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action alienAction = null;
46         final ExtensionConverterProvider extensionConvertorProvider = OFSessionUtil.getExtensionConvertorProvider();
47
48         if (Objects.isNull(extensionConvertorProvider)) {
49             return null;
50         }
51
52         if(action.getActionChoice() instanceof ExperimenterIdCase) {
53             ExperimenterIdCase actionCase = (ExperimenterIdCase) action.getActionChoice();
54             /** TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL) */
55             ExperimenterActionSerializerKey key = new ExperimenterActionSerializerKey(
56                     ofVersion.getVersion(),
57                     actionCase.getExperimenter().getExperimenter().getValue(),
58                     actionCase.getExperimenter().getSubType());
59             convertor = extensionConvertorProvider.getActionConverter(key);
60         } else if (action.getActionChoice() != null){
61             ActionSerializerKey<?> key = new ActionSerializerKey(EncodeConstants.OF13_VERSION_ID, action.getActionChoice().getImplementedInterface(), null);
62             convertor = extensionConvertorProvider.getActionConverter(key);
63         }
64
65         if (convertor != null) {
66             alienAction = convertor.convert(action, actionPath);
67         }
68
69         return alienAction;
70     }
71 }