BUG-2794: Incorporated model Action api changes in OFJava to openflowplugin
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / main / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / action / SetNspConvertor.java
1 /*
2  * Copyright (C) 2014 Red Hat, Inc.
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  * Authors : Madhu Venugopal
9  */
10 package org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.action;
11
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
16 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNsp;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNspBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nsp.grouping.NxActionSetNsp;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nsp.grouping.NxActionSetNspBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionSetNspGrouping;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionSetNspNotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flows.statistics.update.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionSetNspNotifFlowsStatisticsUpdateWriteActionsCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionSetNspNotifGroupDescStatsUpdatedCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionSetNspNodesNodeTableFlowWriteActionsCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.set.nsp.grouping.NxSetNsp;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.set.nsp.grouping.NxSetNspBuilder;
29
30 public class SetNspConvertor implements
31         ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action>,
32         ConvertorActionFromOFJava<Action, ActionPath> {
33
34     @Override
35     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(Action input, ActionPath path) {
36         NxActionSetNsp action = ((ActionSetNsp) input.getActionChoice()).getNxActionSetNsp();
37         NxSetNspBuilder builder = new NxSetNspBuilder();
38         builder.setNsp(action.getNsp());
39         return resolveAction(builder.build(), path);
40     }
41
42     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(NxSetNsp value, ActionPath path) {
43         switch (path) {
44             case NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION:
45                 return new NxActionSetNspNodesNodeTableFlowWriteActionsCaseBuilder().setNxSetNsp(value).build();
46             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION:
47                 return new NxActionSetNspNotifFlowsStatisticsUpdateWriteActionsCaseBuilder().setNxSetNsp(value).build();
48             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION:
49                 return new NxActionSetNspNotifFlowsStatisticsUpdateApplyActionsCaseBuilder().setNxSetNsp(value).build();
50             case GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION:
51                 return new NxActionSetNspNotifGroupDescStatsUpdatedCaseBuilder().setNxSetNsp(value).build();
52             default:
53                 throw new CodecPreconditionException(path);
54         }
55     }
56
57     @Override
58     public Action convert(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
59         Preconditions.checkArgument(nxActionArg instanceof NxActionSetNspGrouping);
60         NxActionSetNspGrouping nxAction = (NxActionSetNspGrouping) nxActionArg;
61         ActionSetNspBuilder builder = new ActionSetNspBuilder();
62         NxActionSetNspBuilder nxActionSetNspBuilder = new NxActionSetNspBuilder();
63         nxActionSetNspBuilder.setNsp(nxAction.getNxSetNsp().getNsp());
64         nxActionSetNspBuilder.setExperimenterId(ActionUtil.EXPERIMENTER_ID);
65         builder.setNxActionSetNsp(nxActionSetNspBuilder.build());
66         return ActionUtil.createAction(builder.build());
67     }
68
69 }