Bug 3208: Add actions SetNsch[1-4] and matches Nsch[1-4]
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / main / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / action / SetNshc4Convertor.java
1 /*
2  * Copyright (c) 2015 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.extension.vendor.nicira.convertor.action;
9
10 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
12 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
13 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc4;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc4Builder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nshc._4.grouping.NxActionSetNshc4;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nshc._4.grouping.NxActionSetNshc4Builder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionSetNshc4Grouping;
20 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.NxActionSetNshc4NotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
21 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.NxActionSetNshc4NotifFlowsStatisticsUpdateWriteActionsCaseBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.group.desc.stats.updated.group.desc.stats.buckets.bucket.action.action.NxActionSetNshc4NotifGroupDescStatsUpdatedCaseBuilder;
23 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.NxActionSetNshc4NodesNodeTableFlowWriteActionsCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.set.nshc._4.grouping.NxSetNshc4;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.set.nshc._4.grouping.NxSetNshc4Builder;
26
27 import com.google.common.base.Preconditions;
28
29 public class SetNshc4Convertor implements
30         ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action>,
31         ConvertorActionFromOFJava<Action, ActionPath> {
32
33     @Override
34     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(Action input, ActionPath path) {
35         NxActionSetNshc4 action = ((ActionSetNshc4) input.getActionChoice()).getNxActionSetNshc4();
36         NxSetNshc4Builder builder = new NxSetNshc4Builder();
37         builder.setNshc(action.getNshc());
38         return resolveAction(builder.build(), path);
39     }
40
41     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(NxSetNshc4 value, ActionPath path) {
42         switch (path) {
43             case NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION:
44                 return new NxActionSetNshc4NodesNodeTableFlowWriteActionsCaseBuilder().setNxSetNshc4(value).build();
45             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION:
46                 return new NxActionSetNshc4NotifFlowsStatisticsUpdateWriteActionsCaseBuilder().setNxSetNshc4(value).build();
47             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION:
48                 return new NxActionSetNshc4NotifFlowsStatisticsUpdateApplyActionsCaseBuilder().setNxSetNshc4(value).build();
49             case GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION:
50                 return new NxActionSetNshc4NotifGroupDescStatsUpdatedCaseBuilder().setNxSetNshc4(value).build();
51             default:
52                 throw new CodecPreconditionException(path);
53         }
54     }
55
56     @Override
57     public Action convert(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
58         Preconditions.checkArgument(nxActionArg instanceof NxActionSetNshc4Grouping);
59         NxActionSetNshc4Grouping nxAction = (NxActionSetNshc4Grouping) nxActionArg;
60         ActionSetNshc4Builder builder = new ActionSetNshc4Builder();
61         NxActionSetNshc4Builder nxActionSetnsc4Builder = new NxActionSetNshc4Builder();
62         nxActionSetnsc4Builder.setNshc(nxAction.getNxSetNshc4().getNshc());
63         builder.setNxActionSetNshc4(nxActionSetnsc4Builder.build());
64         return ActionUtil.createAction(builder.build());
65     }
66
67 }