Extension support - easy lookup for toOFJava
[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.experimenter.ExperimenterActionSerializerKey;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
12 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
13 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
14 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterIdAction;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * 
22  */
23 public final class ActionExtensionHelper {
24     
25     private static final Logger LOG = LoggerFactory
26             .getLogger(ActionExtensionHelper.class);
27     
28     private ActionExtensionHelper() {
29         throw new IllegalAccessError("singleton enforcement");
30     }
31
32     /**
33      * @param action 
34      * @param ofVersion
35      * @param actionPath
36      * @return augmentation wrapper containing augmentation depending on matchPath
37      */
38     public static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action
39     processAlienAction(Action action, OpenflowVersion ofVersion, ActionPath actionPath) {
40         
41         /** TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL) */
42         ExperimenterActionSerializerKey key = new ExperimenterActionSerializerKey(
43                 ofVersion.getVersion(), 
44                 action.getAugmentation(ExperimenterIdAction.class).getExperimenter().getValue(), 
45                 action.getAugmentation(ExperimenterIdAction.class).getSubType());
46         
47         org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action alienAction = null;
48         ConvertorActionFromOFJava<Action, ActionPath> convertor = OFSessionUtil.getExtensionConvertorProvider().getActionConverter(key);
49         if (convertor != null) {
50             alienAction = convertor.convert(
51                     action, actionPath);
52         }
53         
54         return alienAction;
55     }
56 }