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.Collection;
13 import java.util.Collections;
14 import java.util.List;
15 import java.util.Optional;
17 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
18 import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalCopyTtlInCase;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalCopyTtlOutCase;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalDecMplsTtlCase;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalDecNwTtlCase;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalGroupCase;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalOutputActionCase;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopMplsCase;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopPbbCase;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPopVlanCase;
28 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushMplsCase;
29 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushPbbCase;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalPushVlanCase;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetDlDstCase;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetDlSrcCase;
33 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetFieldCase;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetMplsTtlCase;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwDstCase;
36 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwSrcCase;
37 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwTosCase;
38 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetNwTtlCase;
39 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetQueueCase;
40 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetTpDstCase;
41 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetTpSrcCase;
42 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetVlanIdCase;
43 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalSetVlanPcpCase;
44 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.OfToSalStripVlanCase;
45 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionResponseConvertorData;
46 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
47 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.ActionChoice;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
52 * Converts OF actions associated with bucket to SAL Actions.
58 * ActionResponseConvertorData data = new ActionResponseConvertorData(version);
59 * data.setActionPath(actionPath);
60 * Optional<List<Action>> salActions = convertorManager.convert(ofActions, data);
64 public final class ActionResponseConvertor extends Convertor<
66 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>,
67 ActionResponseConvertorData> {
69 private static final ConvertorProcessor<ActionChoice, org.opendaylight.yang.gen.v1.urn.opendaylight.action.types
70 .rev131112.action.Action, ActionResponseConvertorData> PROCESSOR = new ConvertorProcessor<
72 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action,
73 ActionResponseConvertorData>()
74 // Add rules for each action type
75 .addCase(new OfToSalCopyTtlInCase())
76 .addCase(new OfToSalCopyTtlOutCase())
77 .addCase(new OfToSalDecMplsTtlCase())
78 .addCase(new OfToSalDecNwTtlCase())
79 .addCase(new OfToSalGroupCase())
80 .addCase(new OfToSalOutputActionCase())
81 .addCase(new OfToSalPopMplsCase())
82 .addCase(new OfToSalPopVlanCase())
83 .addCase(new OfToSalPushMplsCase())
84 .addCase(new OfToSalPushPbbCase())
85 .addCase(new OfToSalPushVlanCase())
86 .addCase(new OfToSalSetMplsTtlCase())
87 .addCase(new OfToSalSetNwTtlCase())
88 .addCase(new OfToSalSetQueueCase())
89 // OpenFlow 1.3 specific actions
90 .addCase(new OfToSalPopPbbCase())
91 .addCase(new OfToSalSetFieldCase())
92 // OpenFlow 1.0 specific actions
93 .addCase(new OfToSalSetNwSrcCase())
94 .addCase(new OfToSalSetNwDstCase())
95 .addCase(new OfToSalSetNwTosCase())
96 .addCase(new OfToSalSetDlSrcCase())
97 .addCase(new OfToSalSetDlDstCase())
98 .addCase(new OfToSalSetTpSrcCase())
99 .addCase(new OfToSalSetTpDstCase())
100 .addCase(new OfToSalSetVlanPcpCase())
101 .addCase(new OfToSalSetVlanIdCase())
102 .addCase(new OfToSalStripVlanCase());
103 private static final Set<Class<?>> TYPES = Collections.singleton(Action.class);
106 public Collection<Class<?>> getTypes() {
111 public List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>
112 convert(List<Action> source, ActionResponseConvertorData data) {
113 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> result =
115 final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
117 // Iterate over Openflow actions, run them through tokenizer and then add them to list of converted actions
118 if (source != null) {
119 for (final Action action : source) {
120 final Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>
121 convertedAction = PROCESSOR.process(action.getActionChoice(), data, getConvertorExecutor());
123 if (convertedAction.isPresent()) {
124 result.add(convertedAction.get());
127 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
128 * - we might also need a way on how to identify exact type of augmentation to be
129 * used as match can be bound to multiple models
131 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction =
132 ActionExtensionHelper.processAlienAction(action, ofVersion, data.getActionPath());
134 if (processedAction != null) {
135 result.add(processedAction);