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;
50 import org.opendaylight.yangtools.yang.binding.DataContainer;
53 * 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.rev131112.action.Action, ActionResponseConvertorData> PROCESSOR = new ConvertorProcessor<
71 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action,
72 ActionResponseConvertorData>()
73 // Add rules for each action type
74 .addCase(new OfToSalCopyTtlInCase())
75 .addCase(new OfToSalCopyTtlOutCase())
76 .addCase(new OfToSalDecMplsTtlCase())
77 .addCase(new OfToSalDecNwTtlCase())
78 .addCase(new OfToSalGroupCase())
79 .addCase(new OfToSalOutputActionCase())
80 .addCase(new OfToSalPopMplsCase())
81 .addCase(new OfToSalPopVlanCase())
82 .addCase(new OfToSalPushMplsCase())
83 .addCase(new OfToSalPushPbbCase())
84 .addCase(new OfToSalPushVlanCase())
85 .addCase(new OfToSalSetMplsTtlCase())
86 .addCase(new OfToSalSetNwTtlCase())
87 .addCase(new OfToSalSetQueueCase())
88 // OpenFlow 1.3 specific actions
89 .addCase(new OfToSalPopPbbCase())
90 .addCase(new OfToSalSetFieldCase())
91 // OpenFlow 1.0 specific actions
92 .addCase(new OfToSalSetNwSrcCase())
93 .addCase(new OfToSalSetNwDstCase())
94 .addCase(new OfToSalSetNwTosCase())
95 .addCase(new OfToSalSetDlSrcCase())
96 .addCase(new OfToSalSetDlDstCase())
97 .addCase(new OfToSalSetTpSrcCase())
98 .addCase(new OfToSalSetTpDstCase())
99 .addCase(new OfToSalSetVlanPcpCase())
100 .addCase(new OfToSalSetVlanIdCase())
101 .addCase(new OfToSalStripVlanCase());
102 private static final Set<Class<?>> TYPES = Collections.singleton(Action.class);
105 public Collection<Class<?>> getTypes() {
110 public List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convert(List<Action> source, ActionResponseConvertorData data) {
111 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> result = new ArrayList<>();
112 final OpenflowVersion ofVersion = OpenflowVersion.get(data.getVersion());
114 // Iterate over Openflow actions, run them through tokenizer and then add them to list of converted actions
115 if (source != null) {
116 for (final Action action : source) {
117 final Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> convertedAction = PROCESSOR.process(action.getActionChoice(), data, getConvertorExecutor());
119 if (convertedAction.isPresent()) {
120 result.add(convertedAction.get());
123 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
124 * - we might also need a way on how to identify exact type of augmentation to be
125 * used as match can be bound to multiple models
127 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction =
128 ActionExtensionHelper.processAlienAction(action, ofVersion, data.getActionPath());
130 if (processedAction != null) {
131 result.add(processedAction);