Bump mdsal to 5.0.2
[openflowplugin.git] / extension / openflowplugin-extension-nicira / src / main / java / org / opendaylight / openflowplugin / extension / vendor / nicira / convertor / action / RegMoveConvertor.java
1 /*
2  * Copyright (c) 2014, 2016 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 com.google.common.base.Preconditions;
11 import org.opendaylight.openflowplugin.extension.api.ConvertorActionFromOFJava;
12 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
13 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
14 import org.opendaylight.openflowplugin.extension.vendor.nicira.convertor.CodecPreconditionException;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMove;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.action.container.action.choice.ActionRegMoveBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMove;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.ofj.nx.action.reg.move.grouping.NxActionRegMoveBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.NxActionRegMoveGrouping;
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.apply.actions._case.apply.actions.action.action.NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCaseBuilder;
22 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.NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCaseBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.get.flow.statistics.output.flow.and.statistics.map.list.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNotifDirectStatisticsUpdateApplyActionsCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.get.flow.statistics.output.flow.and.statistics.map.list.instructions.instruction.instruction.write.actions._case.write.actions.action.action.NxActionRegMoveNotifDirectStatisticsUpdateWriteActionsCaseBuilder;
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.NxActionRegMoveNotifGroupDescStatsUpdatedCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder;
27 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.NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMove;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.NxRegMoveBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Dst;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.DstBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.Src;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.reg.move.grouping.nx.reg.move.SrcBuilder;
34
35 /**
36  * Convert to/from SAL flow model to openflowjava model for NxActionRegMove action.
37  *
38  * @author msunal
39  * @author Josh Hershberg (jhershbe@redhat.com)
40  */
41 public class RegMoveConvertor implements
42         ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action,
43             Action>, ConvertorActionFromOFJava<Action, ActionPath> {
44
45
46
47     @Override
48     public Action convert(
49             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action nxActionArg) {
50         Preconditions.checkArgument(nxActionArg instanceof NxActionRegMoveGrouping);
51         NxActionRegMoveGrouping nxAction = (NxActionRegMoveGrouping) nxActionArg;
52
53         Dst dst = nxAction.getNxRegMove().getDst();
54         Src src = nxAction.getNxRegMove().getSrc();
55         final ActionRegMoveBuilder actionRegMoveBuilder = new ActionRegMoveBuilder();
56         NxActionRegMoveBuilder nxActionRegMove = new NxActionRegMoveBuilder();
57
58         nxActionRegMove.setDst(FieldChoiceResolver.resolveDstHeaderUint64(dst.getDstChoice()));
59         nxActionRegMove.setDstOfs(dst.getStart());
60         nxActionRegMove.setSrc(FieldChoiceResolver.resolveSrcHeaderUint64(src.getSrcChoice()));
61         nxActionRegMove.setSrcOfs(src.getStart());
62         nxActionRegMove.setNBits(dst.getEnd().toJava() - dst.getStart().toJava() + 1);
63         actionRegMoveBuilder.setNxActionRegMove(nxActionRegMove.build());
64         return ActionUtil.createAction(actionRegMoveBuilder.build());
65     }
66
67     @Override
68     public org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action convert(
69             Action input, ActionPath path) {
70         NxActionRegMove actionRegMove = ((ActionRegMove) input.getActionChoice()).getNxActionRegMove();
71         DstBuilder dstBuilder = new DstBuilder();
72         dstBuilder.setDstChoice(FieldChoiceResolver.resolveDstChoice(actionRegMove.getDst()));
73         dstBuilder.setStart(actionRegMove.getDstOfs());
74         dstBuilder.setEnd(actionRegMove.getDstOfs().toJava() + actionRegMove.getNBits().toJava() - 1);
75         SrcBuilder srcBuilder = new SrcBuilder();
76         srcBuilder.setSrcChoice(FieldChoiceResolver.resolveSrcChoice(actionRegMove.getSrc()));
77         srcBuilder.setStart(actionRegMove.getSrcOfs());
78         srcBuilder.setEnd(actionRegMove.getSrcOfs().toJava() + actionRegMove.getNBits().toJava() - 1);
79         NxRegMoveBuilder nxRegMoveBuilder = new NxRegMoveBuilder();
80         nxRegMoveBuilder.setDst(dstBuilder.build());
81         nxRegMoveBuilder.setSrc(srcBuilder.build());
82         return resolveAction(nxRegMoveBuilder.build(), path);
83     }
84
85     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action resolveAction(
86             NxRegMove value, ActionPath path) {
87         switch (path) {
88             case INVENTORY_FLOWNODE_TABLE_WRITE_ACTIONS:
89                 return new NxActionRegMoveNodesNodeTableFlowWriteActionsCaseBuilder().setNxRegMove(value).build();
90             case FLOWS_STATISTICS_UPDATE_WRITE_ACTIONS:
91                 return new NxActionRegMoveNotifFlowsStatisticsUpdateWriteActionsCaseBuilder()
92                         .setNxRegMove(value).build();
93             case FLOWS_STATISTICS_UPDATE_APPLY_ACTIONS:
94                 return new NxActionRegMoveNotifFlowsStatisticsUpdateApplyActionsCaseBuilder()
95                         .setNxRegMove(value).build();
96             case GROUP_DESC_STATS_UPDATED_BUCKET_ACTION:
97                 return new NxActionRegMoveNotifGroupDescStatsUpdatedCaseBuilder().setNxRegMove(value).build();
98             case FLOWS_STATISTICS_RPC_WRITE_ACTIONS:
99                 return new NxActionRegMoveNotifDirectStatisticsUpdateWriteActionsCaseBuilder()
100                         .setNxRegMove(value).build();
101             case FLOWS_STATISTICS_RPC_APPLY_ACTIONS:
102                 return new NxActionRegMoveNotifDirectStatisticsUpdateApplyActionsCaseBuilder()
103                         .setNxRegMove(value).build();
104             case INVENTORY_FLOWNODE_TABLE_APPLY_ACTIONS:
105                 return new NxActionRegMoveNodesNodeTableFlowApplyActionsCaseBuilder().setNxRegMove(value).build();
106             default:
107                 throw new CodecPreconditionException(path);
108         }
109     }
110
111 }