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 / SetNshc1Convertor.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.ActionSetNshc1;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionSetNshc1Builder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nshc._1.grouping.NxActionSetNshc1;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.set.nshc._1.grouping.NxActionSetNshc1Builder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionSetNshc1Grouping;
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.NxActionSetNshc1NotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
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.NxActionSetNshc1NotifFlowsStatisticsUpdateWriteActionsCaseBuilder;
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.NxActionSetNshc1NotifGroupDescStatsUpdatedCaseBuilder;
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.NxActionSetNshc1NodesNodeTableFlowWriteActionsCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.set.nshc._1.grouping.NxSetNshc1;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.set.nshc._1.grouping.NxSetNshc1Builder;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import com.google.common.base.Preconditions;
30
31 public class SetNshc1Convertor implements
32         ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action>,
33         ConvertorActionFromOFJava<Action, ActionPath> {
34     private static final Logger LOG = LoggerFactory.getLogger(SetNshc1Convertor.class);
35
36
37     @Override
38     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(Action input, ActionPath path) {
39         NxActionSetNshc1 action = ((ActionSetNshc1) input.getActionChoice()).getNxActionSetNshc1();
40         NxSetNshc1Builder builder = new NxSetNshc1Builder();
41         builder.setNshc(action.getNshc());
42         return resolveAction(builder.build(), path);
43     }
44
45     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(NxSetNshc1 value, ActionPath path) {
46         switch (path) {
47             case NODES_NODE_TABLE_FLOW_INSTRUCTIONS_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION_EXTENSIONLIST_EXTENSION:
48                 return new NxActionSetNshc1NodesNodeTableFlowWriteActionsCaseBuilder().setNxSetNshc1(value).build();
49             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_WRITEACTIONSCASE_WRITEACTIONS_ACTION_ACTION:
50                 return new NxActionSetNshc1NotifFlowsStatisticsUpdateWriteActionsCaseBuilder().setNxSetNshc1(value).build();
51             case FLOWSSTATISTICSUPDATE_FLOWANDSTATISTICSMAPLIST_INSTRUCTIONS_INSTRUCTION_INSTRUCTION_APPLYACTIONSCASE_APPLYACTIONS_ACTION_ACTION:
52                 return new NxActionSetNshc1NotifFlowsStatisticsUpdateApplyActionsCaseBuilder().setNxSetNshc1(value).build();
53             case GROUPDESCSTATSUPDATED_GROUPDESCSTATS_BUCKETS_BUCKET_ACTION:
54                 return new NxActionSetNshc1NotifGroupDescStatsUpdatedCaseBuilder().setNxSetNshc1(value).build();
55             default:
56                 throw new CodecPreconditionException(path);
57         }
58     }
59
60     @Override
61     public Action convert(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
62         Preconditions.checkArgument(nxActionArg instanceof NxActionSetNshc1Grouping);
63         NxActionSetNshc1Grouping nxAction = (NxActionSetNshc1Grouping) nxActionArg;
64         ActionSetNshc1Builder builder = new ActionSetNshc1Builder();
65         NxActionSetNshc1Builder nxActionSetnsc1Builder = new NxActionSetNshc1Builder();
66         nxActionSetnsc1Builder.setNshc(nxAction.getNxSetNshc1().getNshc());
67         builder.setNxActionSetNshc1(nxActionSetnsc1Builder.build());
68         return ActionUtil.createAction(builder.build());
69     }
70
71 }