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.openflow.md.core.sal.convertor.action.cases.SalToOfCopyTtlInCase;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfCopyTtlOutCase;
19 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfDecMplsTtlCase;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfDecNwTtlCase;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfDropActionCase;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfGeneralExtensionGroupingCase;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfGroupActionCase;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfOutputActionCase;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopMplsActionCase;
26 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopPbbActionCase;
27 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopVlanActionCase;
28 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPopVlanActionV10Case;
29 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPushMplsActionCase;
30 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPushPbbActionCase;
31 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfPushVlanActionCase;
32 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlDstActionCase;
33 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlDstActionV10Case;
34 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlSrcActionCase;
35 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetDlSrcActionV10Case;
36 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetFieldCase;
37 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetFieldV10Case;
38 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetMplsTtlActionCase;
39 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwDstActionCase;
40 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwDstActionV10Case;
41 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwSrcActionCase;
42 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwSrcActionV10Case;
43 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwTosActionCase;
44 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwTosActionV10Case;
45 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetNwTtlActionCase;
46 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetQueueActionCase;
47 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpDstActionCase;
48 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpDstActionV10Case;
49 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpSrcActionCase;
50 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetTpSrcActionV10Case;
51 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanIdActionCase;
52 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanIdActionV10Case;
53 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanPcpActionCase;
54 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfSetVlanPcpActionV10Case;
55 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfStripVlanActionCase;
56 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfStripVlanActionV10Case;
57 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.cases.SalToOfVendorCodecCase;
58 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData;
59 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Convertor;
60 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.ConvertorProcessor;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
62 import org.opendaylight.yangtools.yang.binding.DataContainer;
65 * Converts SAL actions into OF Library actions
70 * ActionConvertorData data = new ActionConvertorData(version);
71 * data.setDatapathId(datapathId);
72 * data.setIpProtocol(ipProtocol);
73 * Optional<List<Action>> ofActions = convertorManager.convert(salActions, data);
77 public final class ActionConvertor extends Convertor<
78 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>,
80 ActionConvertorData> {
82 private static final ConvertorProcessor<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action, ActionConvertorData> PROCESSOR = new ConvertorProcessor<
83 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action,
85 ActionConvertorData>()
86 // Set default rule, what will be used if no rule match is found
87 .setDefaultCase(new SalToOfVendorCodecCase())
88 // Add rules for each action type
89 .addCase(new SalToOfCopyTtlInCase())
90 .addCase(new SalToOfCopyTtlOutCase())
91 .addCase(new SalToOfDecMplsTtlCase())
92 .addCase(new SalToOfDecNwTtlCase())
93 .addCase(new SalToOfDropActionCase())
94 .addCase(new SalToOfGroupActionCase())
95 .addCase(new SalToOfOutputActionCase())
96 .addCase(new SalToOfPopMplsActionCase())
97 .addCase(new SalToOfPopPbbActionCase())
98 .addCase(new SalToOfPopVlanActionCase())
99 .addCase(new SalToOfPopVlanActionV10Case())
100 .addCase(new SalToOfPushMplsActionCase())
101 .addCase(new SalToOfPushPbbActionCase())
102 .addCase(new SalToOfPushVlanActionCase())
103 .addCase(new SalToOfSetFieldCase())
104 .addCase(new SalToOfSetFieldV10Case())
105 .addCase(new SalToOfSetMplsTtlActionCase())
106 .addCase(new SalToOfSetNwTtlActionCase())
107 .addCase(new SalToOfSetQueueActionCase())
108 // Openflow 1.0 actions, with support for Openflow 1.3
109 .addCase(new SalToOfSetVlanIdActionCase())
110 .addCase(new SalToOfSetVlanIdActionV10Case())
111 .addCase(new SalToOfSetVlanPcpActionCase())
112 .addCase(new SalToOfSetVlanPcpActionV10Case())
113 .addCase(new SalToOfStripVlanActionCase())
114 .addCase(new SalToOfStripVlanActionV10Case())
115 .addCase(new SalToOfSetDlSrcActionCase())
116 .addCase(new SalToOfSetDlSrcActionV10Case())
117 .addCase(new SalToOfSetDlDstActionCase())
118 .addCase(new SalToOfSetDlDstActionV10Case())
119 .addCase(new SalToOfSetNwSrcActionCase())
120 .addCase(new SalToOfSetNwSrcActionV10Case())
121 .addCase(new SalToOfSetNwDstActionCase())
122 .addCase(new SalToOfSetNwDstActionV10Case())
123 .addCase(new SalToOfSetTpSrcActionCase())
124 .addCase(new SalToOfSetTpSrcActionV10Case())
125 .addCase(new SalToOfSetTpDstActionCase())
126 .addCase(new SalToOfSetTpDstActionV10Case())
127 .addCase(new SalToOfSetNwTosActionCase())
128 .addCase(new SalToOfSetNwTosActionV10Case())
129 // Try to convert action grouping using converters from openflowplugin-extension
130 .addCase(new SalToOfGeneralExtensionGroupingCase());
131 private static final Set<Class<? extends DataContainer>> TYPES = Collections.singleton(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action.class);
134 public Collection<Class<? extends DataContainer>> getTypes() {
139 public List<Action> convert(List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> source, ActionConvertorData data) {
140 // Prepare list of converted actions
141 final List<Action> result = new ArrayList<>();
143 // Iterate over SAL actions, run them through tokenizer and then add them to list of converted actions
144 if (source != null) {
145 for (final org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action action : source) {
146 final Optional<Action> convertedAction = PROCESSOR.process(action.getAction(), data, getConvertorExecutor());
148 if (convertedAction.isPresent()) {
149 result.add(convertedAction.get());