f6a54166eb66db6b79d3611502f84cea8bcabe35
[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.path.ActionPath;
16 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice.ExperimenterIdCase;
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 /**
23  *
24  */
25 public final class ActionExtensionHelper {
26
27     private static final Logger LOG = LoggerFactory
28             .getLogger(ActionExtensionHelper.class);
29
30     private ActionExtensionHelper() {
31         throw new IllegalAccessError("singleton enforcement");
32     }
33
34     /**
35      * @param action
36      * @param ofVersion
37      * @param actionPath
38      * @return augmentation wrapper containing augmentation depending on matchPath
39      */
40     public static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
41     processAlienAction(final Action action, final OpenflowVersion ofVersion, final ActionPath actionPath) {
42         ConvertorActionFromOFJava<Action, ActionPath> convertor = null;
43         org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action alienAction = null;
44         if(action.getActionChoice() instanceof ExperimenterIdCase) {
45             ExperimenterIdCase actionCase = (ExperimenterIdCase) action.getActionChoice();
46             /** TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL) */
47             ExperimenterActionSerializerKey key = new ExperimenterActionSerializerKey(
48                     ofVersion.getVersion(),
49                     actionCase.getExperimenter().getExperimenter().getValue(),
50                     actionCase.getExperimenter().getSubType());
51             convertor = OFSessionUtil.getExtensionConvertorProvider().getActionConverter(key);
52         } else if (action.getActionChoice() != null){
53             ActionSerializerKey<?> key = new ActionSerializerKey(EncodeConstants.OF13_VERSION_ID, action.getActionChoice().getImplementedInterface(), null);
54             convertor = OFSessionUtil.getExtensionConvertorProvider().getActionConverter(key);
55         }
56         if (convertor != null) {
57             alienAction = convertor.convert(
58                     action, actionPath);
59         }
60         return alienAction;
61     }
62 }