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