2 * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.Optional;
14 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
15 import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
16 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalCopyTtlInCase;
17 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalCopyTtlOutCase;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalDecMplsTtlCase;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalDecNwTtlCase;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalGroupCase;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalOutputActionCase;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopMplsCase;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopPbbCase;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopVlanCase;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushMplsCase;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushPbbCase;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushVlanCase;
28 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetFieldCase;
29 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetMplsTtlCase;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwDstCase;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwTtlCase;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetQueueCase;
33 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalStripVlanCase;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor;
36 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ParametrizedConvertor;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
41 * Converts OF actions associated with bucket to SAL Actions.
46 * ActionResponseConvertorData data = new ActionResponseConvertorData(version);
47 * data.setActionPath(actionPath);
48 * Optional<List<Action>> salActions = ConvertorManager.getInstance().convert(ofActions, data);
52 public final class ActionResponseConvertor implements ParametrizedConvertor<
54 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>,
55 ActionResponseConvertorData> {
57 private static final ConvertorProcessor<ActionChoice, org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, ActionResponseConvertorData> PROCESSOR = new ConvertorProcessor<
59 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action,
60 ActionResponseConvertorData>()
61 // Add rules for each action type
62 .addCase(new OfToSalCopyTtlInCase())
63 .addCase(new OfToSalCopyTtlOutCase())
64 .addCase(new OfToSalDecMplsTtlCase())
65 .addCase(new OfToSalDecNwTtlCase())
66 .addCase(new OfToSalGroupCase())
67 .addCase(new OfToSalOutputActionCase())
68 .addCase(new OfToSalPopMplsCase())
69 .addCase(new OfToSalPopPbbCase())
70 .addCase(new OfToSalPopVlanCase())
71 .addCase(new OfToSalPushMplsCase())
72 .addCase(new OfToSalPushPbbCase())
73 .addCase(new OfToSalPushVlanCase())
74 .addCase(new OfToSalSetFieldCase())
75 .addCase(new OfToSalSetMplsTtlCase())
76 .addCase(new OfToSalSetNwDstCase())
77 .addCase(new OfToSalSetNwTtlCase())
78 .addCase(new OfToSalSetQueueCase())
79 .addCase(new OfToSalStripVlanCase());
82 public Class<?> getType() {
87 public List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convert(List<Action> source, ActionResponseConvertorData data) {
88 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> result = new ArrayList<>();
89 final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
91 // Iterate over Openflow actions, run them through tokenizer and then add them to list of converted actions
93 for (final Action action : source) {
94 final Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convertedAction = PROCESSOR.process(action.getActionChoice(), data);
96 if (convertedAction.isPresent()) {
97 result.add(convertedAction.get());
100 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
101 * - we might also need a way on how to identify exact type of augmentation to be
102 * used as match can be bound to multiple models
104 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction =
105 ActionExtensionHelper.processAlienAction(action, ofVersion, data.getActionPath());
107 if (processedAction != null) {
108 result.add(processedAction);