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