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