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
8 * Contributor: hema.gopalkrishnan@ericsson.com
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
12 import com.google.common.collect.Ordering;
13 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
16 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
17 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
18 import org.opendaylight.openflowplugin.api.OFConstants;
19 import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwDstReactor;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwSrcReactor;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
25 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
26 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
27 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
28 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstAction;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcAction;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosAction;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueAction;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdAction;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionGrouping;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
154 import org.slf4j.Logger;
155 import org.slf4j.LoggerFactory;
157 import java.math.BigInteger;
158 import java.util.ArrayList;
159 import java.util.List;
162 * @author usha@ericsson Action List:This class takes data from SAL layer and
163 * converts into OF Data
164 * @author avishnoi@in.ibm.com Added convertor for OF bucket actions to SAL
167 public final class ActionConvertor {
168 private static final Logger logger = LoggerFactory.getLogger(ActionConvertor.class);
170 private ActionConvertor() {
175 * Translates SAL actions into OF Library actions
177 * @param actions SAL actions
178 * @param version Openflow protocol version used
180 * @return OF Library actions
182 public static List<Action> getActions(
183 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions,
184 short version, BigInteger datapathid) {
185 List<Action> actionsList = new ArrayList<>();
188 actions = Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>toInstance())
189 .sortedCopy(actions);
191 for (int actionItem = 0; actionItem < actions.size(); actionItem++) {
193 ActionBuilder actionBuilder = new ActionBuilder();
195 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = actions.get(
196 actionItem).getAction();
198 if (action instanceof OutputActionCase)
199 ofAction = salToOFOutputAction(action, actionBuilder, version);
200 else if (action instanceof GroupActionCase)
201 ofAction = SalToOFGroupAction(action, actionBuilder);
202 else if (action instanceof CopyTtlOutCase)
203 ofAction = SalToOFCopyTTLIOut(actionBuilder);
204 else if (action instanceof CopyTtlInCase)
205 ofAction = SalToOFCopyTTLIIn(actionBuilder);
206 else if (action instanceof SetMplsTtlActionCase)
207 ofAction = SalToOFSetMplsTtl(action, actionBuilder);
208 else if (action instanceof DecMplsTtlCase)
209 ofAction = SalToOFDecMplsTtl(actionBuilder);
210 else if (action instanceof PushVlanActionCase)
211 ofAction = SalToOFPushVlanAction(action, actionBuilder, version);
212 else if (action instanceof PopVlanActionCase)
213 ofAction = (version == OFConstants.OFP_VERSION_1_0) ?
214 SalToOFStripVlan(actionBuilder, version)
215 : SalToOFPopVlan(actionBuilder);
216 else if (action instanceof PushMplsActionCase)
217 ofAction = SalToOFPushMplsAction(action, actionBuilder);
218 else if (action instanceof PopMplsActionCase)
219 ofAction = SalToOFPopMpls(action, actionBuilder);
220 else if (action instanceof SetQueueActionCase)
221 ofAction = SalToOFSetQueue(action, actionBuilder);
222 else if (action instanceof SetNwTtlActionCase)
223 ofAction = SalToOFSetNwTtl(action, actionBuilder);
224 else if (action instanceof DecNwTtlCase)
225 ofAction = SalToOFDecNwTtl(actionBuilder);
226 else if (action instanceof SetFieldCase)
227 ofAction = SalToOFSetField(action, actionBuilder, version, datapathid);
228 else if (action instanceof PushPbbActionCase)
229 ofAction = SalToOFPushPbbAction(action, actionBuilder);
230 else if (action instanceof PopPbbActionCase)
231 ofAction = SalToOFPopPBB(actionBuilder);
234 else if (action instanceof SetVlanIdActionCase) {
235 /*if (version == OFConstants.OFP_VERSION_1_0) {
238 List<Action> setVlanIdActionsList = convertToOF13(action, actionBuilder);
239 actionsList.addAll(setVlanIdActionsList);
241 ofAction = SalToOFSetVlanId(action, actionBuilder, version);
243 else if (action instanceof SetVlanPcpActionCase)
244 ofAction = SalToOFSetVlanpcp(action, actionBuilder, version);
245 else if (action instanceof StripVlanActionCase)
246 ofAction = SalToOFStripVlan(actionBuilder, version);
247 else if (action instanceof SetDlSrcActionCase)
248 ofAction = SalToOFSetDlSrc(action, actionBuilder, version);
249 else if (action instanceof SetDlDstActionCase)
250 ofAction = SalToOFSetDlDst(action, actionBuilder, version);
251 else if (action instanceof SetNwSrcActionCase)
252 ofAction = SalToOFSetNwSrc(action, actionBuilder, version);
253 else if (action instanceof SetNwDstActionCase)
254 ofAction = SalToOFSetNwDst(action, actionBuilder, version);
255 else if (action instanceof SetTpSrcActionCase)
256 ofAction = SalToOFSetTpSrc(action, actionBuilder, version);
257 else if (action instanceof SetTpDstActionCase)
258 ofAction = SalToOFSetTpDst(action, actionBuilder, version);
259 else if (action instanceof SetNwTosActionCase)
260 ofAction = SalToOFSetNwTos(action, actionBuilder, version);
261 else if (action instanceof GeneralExtensionGrouping) {
264 * TODO: EXTENSION PROPOSAL (action, MD-SAL to OFJava)
265 * - we might need sessionContext as converter input
269 GeneralExtensionGrouping extensionCaseGrouping = (GeneralExtensionGrouping) action;
270 Extension extAction = extensionCaseGrouping.getExtension();
271 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionCaseGrouping.getExtensionKey(), version);
272 ConvertorToOFJava<Action> convertor =
273 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
274 if (convertor != null) {
275 ofAction = convertor.convert(extAction);
279 TypeVersionKey<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> key =
280 new TypeVersionKey<>(
281 (Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>) action.getImplementedInterface(),
283 ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action> convertor =
284 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
285 if (convertor != null) {
286 ofAction = convertor.convert(action);
290 if (ofAction != null) {
291 actionsList.add(ofAction);
297 private static Action SalToOFSetField(
298 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
299 ActionBuilder actionBuilder, short version, BigInteger datapathid) {
301 SetFieldCase setFieldCase = (SetFieldCase) action;
302 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match =
303 setFieldCase.getSetField();
305 if (version == OFConstants.OFP_VERSION_1_0) {
306 // pushvlan +setField can be called to configure 1.0 switches via MDSAL app
307 if (match.getVlanMatch() != null) {
308 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
309 vlanidActionBuilder.setVlanVid(match.getVlanMatch().getVlanId().getVlanId().getValue());
310 actionBuilder.setType(
311 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
312 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
313 return actionBuilder.build();
315 return emtpyAction(actionBuilder);
319 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
320 MatchReactor.getInstance().convert(match, version, oxmFieldsActionBuilder, datapathid);
322 actionBuilder.setType(
323 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
325 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
326 return actionBuilder.build();
331 private static Action SalToOFDecNwTtl(ActionBuilder actionBuilder) {
333 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class);
334 return emtpyAction(actionBuilder);
337 private static Action SalToOFPushMplsAction(
338 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
339 ActionBuilder actionBuilder) {
340 PushMplsActionCase pushMplsActionCase = (PushMplsActionCase) action;
341 actionBuilder.setType(PushMpls.class);
343 return SalToOFPushAction(pushMplsActionCase.getPushMplsAction().getEthernetType(), actionBuilder);
346 private static Action SalToOFPushPbbAction(
347 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
348 ActionBuilder actionBuilder) {
349 PushPbbActionCase pushPbbActionCase = (PushPbbActionCase) action;
350 actionBuilder.setType(PushPbb.class);
352 return SalToOFPushAction(pushPbbActionCase.getPushPbbAction().getEthernetType(), actionBuilder);
355 private static Action SalToOFPushVlanAction(
356 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
357 ActionBuilder actionBuilder, short version) {
358 if (version == OFConstants.OFP_VERSION_1_0) {
359 // if client configure openflow 1.0 switch as a openflow 1.3 switch using openflow 1.3 instructions
360 // then we can ignore PUSH_VLAN as set-vlan-id will push a vlan header if not present
364 PushVlanActionCase pushVlanActionCase = (PushVlanActionCase) action;
365 PushVlanAction pushVlanAction = pushVlanActionCase.getPushVlanAction();
366 actionBuilder.setType(PushVlan.class);
368 return SalToOFPushAction(pushVlanAction.getEthernetType(), actionBuilder);
371 private static Action SalToOFSetNwTtl(
372 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
373 ActionBuilder actionBuilder) {
374 SetNwTtlActionCase nwTtlActionCase = (SetNwTtlActionCase) action;
375 NwTtlActionBuilder nwTtlActionBuilder = new NwTtlActionBuilder();
376 nwTtlActionBuilder.setNwTtl(nwTtlActionCase.getSetNwTtlAction().getNwTtl());
377 actionBuilder.setType(SetNwTtl.class);
378 actionBuilder.addAugmentation(NwTtlAction.class, nwTtlActionBuilder.build());
379 return actionBuilder.build();
382 private static Action SalToOFSetQueue(
383 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
384 ActionBuilder actionBuilder) {
385 SetQueueActionCase setQueueActionCase = (SetQueueActionCase) action;
386 SetQueueAction setQueueAction = setQueueActionCase.getSetQueueAction();
388 QueueIdActionBuilder queueIdActionBuilder = new QueueIdActionBuilder();
389 queueIdActionBuilder.setQueueId(setQueueAction.getQueueId());
390 actionBuilder.setType(SetQueue.class);
391 actionBuilder.addAugmentation(QueueIdAction.class, queueIdActionBuilder.build());
393 return actionBuilder.build();
396 private static Action SalToOFPopMpls(
397 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
398 ActionBuilder actionBuilder) {
399 PopMplsActionCase popMplsActionCase = (PopMplsActionCase) action;
400 actionBuilder.setType(PopMpls.class);
402 return SalToOFPushAction(popMplsActionCase.getPopMplsAction().getEthernetType(), actionBuilder);
405 private static Action SalToOFPopVlan(ActionBuilder actionBuilder) {
406 actionBuilder.setType(PopVlan.class);
407 return emtpyAction(actionBuilder);
410 private static Action SalToOFPopPBB(ActionBuilder actionBuilder) {
411 actionBuilder.setType(PopPbb.class);
412 return emtpyAction(actionBuilder);
415 // set-vlan-id (1.0 feature) can be called on 1.3 switches as well using ADSAL apis
416 private static Action SalToOFSetVlanId(
417 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
418 ActionBuilder actionBuilder, short version) {
420 SetVlanIdActionCase setvlanidcase = (SetVlanIdActionCase) action;
421 SetVlanIdAction setvlanidaction = setvlanidcase.getSetVlanIdAction();
423 if (version == OFConstants.OFP_VERSION_1_0) {
425 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
426 vlanidActionBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
428 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
429 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
430 return actionBuilder.build();
432 } else if (version >= OFConstants.OFP_VERSION_1_3) {
433 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
435 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
436 List<MatchEntries> matchEntriesList = new ArrayList<>();
437 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
438 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
439 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
440 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
441 vlanVidBuilder.setCfiBit(true);
442 vlanVidBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
443 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
444 matchEntriesBuilder.setHasMask(false);
445 matchEntriesList.add(matchEntriesBuilder.build());
446 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
447 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
448 return actionBuilder.build();
450 logger.error("Unknown Action Type for the Version", version);
455 private static Action SalToOFSetVlanpcp(
456 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
457 ActionBuilder actionBuilder, short version) {
459 SetVlanPcpActionCase setvlanpcpcase = (SetVlanPcpActionCase) action;
460 SetVlanPcpAction setvlanpcpaction = setvlanpcpcase.getSetVlanPcpAction();
462 if (version == OFConstants.OFP_VERSION_1_0) {
463 VlanPcpActionBuilder vlanpcpActionBuilder = new VlanPcpActionBuilder();
464 vlanpcpActionBuilder.setVlanPcp(setvlanpcpaction.getVlanPcp().getValue());
466 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp.class);
467 actionBuilder.addAugmentation(VlanPcpAction.class, vlanpcpActionBuilder.build());
468 return actionBuilder.build();
469 } else if (version >= OFConstants.OFP_VERSION_1_3) {
470 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
472 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
473 List<MatchEntries> matchEntriesList = new ArrayList<>();
474 matchEntriesList.add(MatchConvertorImpl.toOfVlanPcp(setvlanpcpaction.getVlanPcp()));
475 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
476 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
477 return actionBuilder.build();
479 logger.error("Unknown Action Type for the Version", version);
484 private static Action SalToOFStripVlan(ActionBuilder actionBuilder, short version) {
485 if (version == OFConstants.OFP_VERSION_1_0) {
487 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class);
489 return emtpyAction(actionBuilder);
490 } else if (version >= OFConstants.OFP_VERSION_1_3) {
491 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
493 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
494 List<MatchEntries> matchEntriesList = new ArrayList<>();
495 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
496 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
497 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
498 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
499 vlanVidBuilder.setCfiBit(true);
500 vlanVidBuilder.setVlanVid(0x0000);
501 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
502 matchEntriesBuilder.setHasMask(false);
503 matchEntriesList.add(matchEntriesBuilder.build());
504 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
505 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
506 return actionBuilder.build();
508 logger.error("Unknown Action Type for the Version", version);
513 private static Action SalToOFSetDlSrc(
514 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
515 ActionBuilder actionBuilder, short version) {
517 SetDlSrcActionCase setdlsrccase = (SetDlSrcActionCase) action;
518 SetDlSrcAction setdlsrcaction = setdlsrccase.getSetDlSrcAction();
520 if (version == OFConstants.OFP_VERSION_1_0) {
521 DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
522 dladdressactionbuilder.setDlAddress(setdlsrcaction.getAddress());
524 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc.class);
525 actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
526 return actionBuilder.build();
527 } else if (version >= OFConstants.OFP_VERSION_1_3) {
528 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
530 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
531 List<MatchEntries> matchEntriesList = new ArrayList<>();
532 matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthSrc.class, setdlsrcaction.getAddress(), null));
533 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
534 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
535 return actionBuilder.build();
537 logger.error("Unknown Action Type for the Version", version);
542 private static Action SalToOFSetDlDst(
543 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
544 ActionBuilder actionBuilder, short version) {
546 SetDlDstActionCase setdldstcase = (SetDlDstActionCase) action;
547 SetDlDstAction setdldstaction = setdldstcase.getSetDlDstAction();
549 if (version == OFConstants.OFP_VERSION_1_0) {
550 DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
551 dladdressactionbuilder.setDlAddress(setdldstaction.getAddress());
553 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst.class);
554 actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
555 return actionBuilder.build();
556 } else if (version >= OFConstants.OFP_VERSION_1_3) {
557 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
559 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
560 List<MatchEntries> matchEntriesList = new ArrayList<>();
561 matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthDst.class, setdldstaction.getAddress(), null));
562 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
563 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
564 return actionBuilder.build();
566 logger.error("Unknown Action Type for the Version", version);
571 protected static Action SalToOFSetNwSrc(
572 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
573 ActionBuilder actionBuilder, short version) {
576 ActionSetNwSrcReactor.getInstance().convert((SetNwSrcActionCase) action, version, actionBuilder, null);
577 } catch (Exception e) {
578 logger.error(e.getMessage(), e);
582 return actionBuilder.build();
585 protected static Action SalToOFSetNwDst(
586 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
587 ActionBuilder actionBuilder, short version) {
590 ActionSetNwDstReactor.getInstance().convert((SetNwDstActionCase) action, version, actionBuilder, null);
591 } catch (Exception e) {
592 logger.error(e.getMessage(), e);
596 return actionBuilder.build();
599 private static Action SalToOFSetNwTos(
600 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
601 ActionBuilder actionBuilder, short version) {
603 SetNwTosActionCase setnwtoscase = (SetNwTosActionCase) action;
604 SetNwTosAction setnwtosaction = setnwtoscase.getSetNwTosAction();
606 if (version == OFConstants.OFP_VERSION_1_0) {
607 NwTosActionBuilder tosBuilder = new NwTosActionBuilder();
608 tosBuilder.setNwTos(setnwtosaction.getTos().shortValue());
609 actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build());
611 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos.class);
613 return actionBuilder.build();
614 } else if (version >= OFConstants.OFP_VERSION_1_3) {
615 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
617 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
618 List<MatchEntries> matchEntriesList = new ArrayList<>();
619 matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(setnwtosaction.getTos().shortValue())));
620 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
621 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
622 return actionBuilder.build();
624 logger.error("Unknown Action Type for the Version", version);
630 private static Action SalToOFSetTpSrc(
631 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
632 ActionBuilder actionBuilder, short version) {
634 if (version == OFConstants.OFP_VERSION_1_0) {
635 SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
636 SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
638 PortActionBuilder settpsrc = new PortActionBuilder();
639 PortNumber port = new PortNumber(settpsrcaction.getPort().getValue().longValue());
640 settpsrc.setPort(port);
643 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc.class);
644 actionBuilder.addAugmentation(PortAction.class, settpsrc.build());
645 return actionBuilder.build();
646 } else if (version == OFConstants.OFP_VERSION_1_3) {
647 SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
648 SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
650 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
651 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
652 matchEntriesBuilder.setHasMask(false);
653 matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
654 PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
655 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpsrcaction.getPort().getValue().intValue()));
656 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
659 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
661 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
662 List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
663 matchEntries.add(matchEntriesBuilder.build());
664 oxmFieldsActionBuilder.setMatchEntries(matchEntries);
666 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
667 return actionBuilder.build();
669 logger.error("Unknown Action Type for the Version", version);
673 private static Action SalToOFSetTpDst(
674 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
675 ActionBuilder actionBuilder, short version) {
677 if (version == OFConstants.OFP_VERSION_1_0) {
678 SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
679 SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
680 PortActionBuilder settpdst = new PortActionBuilder();
681 PortNumber port = new PortNumber(settpdstaction.getPort().getValue().longValue());
682 settpdst.setPort(port);
685 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst.class);
686 actionBuilder.addAugmentation(PortAction.class, settpdst.build());
687 return actionBuilder.build();
688 } else if (version == OFConstants.OFP_VERSION_1_3) {
689 SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
690 SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
692 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
693 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
694 matchEntriesBuilder.setHasMask(false);
695 matchEntriesBuilder.setOxmMatchField(TcpDst.class);
696 PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
697 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpdstaction.getPort().getValue().intValue()));
698 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
701 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
703 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
704 List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
705 matchEntries.add(matchEntriesBuilder.build());
706 oxmFieldsActionBuilder.setMatchEntries(matchEntries);
708 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
709 return actionBuilder.build();
711 logger.error("Unknown Action Type for the Version", version);
715 private static Action SalToOFGroupAction(
716 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
717 ActionBuilder actionBuilder) {
719 GroupActionCase groupActionCase = (GroupActionCase) action;
720 GroupAction groupAction = groupActionCase.getGroupAction();
722 GroupIdActionBuilder groupIdBuilder = new GroupIdActionBuilder();
723 groupIdBuilder.setGroupId(groupAction.getGroupId());
724 actionBuilder.setType(Group.class);
725 actionBuilder.addAugmentation(GroupIdAction.class, groupIdBuilder.build());
726 return actionBuilder.build();
729 private static Action SalToOFPushAction(Integer ethernetType, ActionBuilder actionBuilder) {
730 EthertypeActionBuilder ethertypeActionBuilder = new EthertypeActionBuilder();
731 if (ethernetType != null) {
732 ethertypeActionBuilder.setEthertype(new EtherType(ethernetType));
736 actionBuilder.addAugmentation(EthertypeAction.class, ethertypeActionBuilder.build());
737 return actionBuilder.build();
740 private static Action SalToOFDecMplsTtl(ActionBuilder actionBuilder) {
742 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class);
743 return emtpyAction(actionBuilder);
746 private static Action SalToOFSetMplsTtl(
747 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
748 ActionBuilder actionBuilder) {
749 SetMplsTtlActionCase mplsTtlActionCase = (SetMplsTtlActionCase) action;
750 SetMplsTtlAction mplsTtlAction = mplsTtlActionCase.getSetMplsTtlAction();
752 MplsTtlActionBuilder mplsTtlActionBuilder = new MplsTtlActionBuilder();
753 mplsTtlActionBuilder.setMplsTtl(mplsTtlAction.getMplsTtl()/* SAL */);
755 actionBuilder.setType(SetMplsTtl.class);
756 actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtlActionBuilder.build());
757 return actionBuilder.build();
760 private static Action SalToOFCopyTTLIIn(ActionBuilder actionBuilder) {
762 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class);
763 return emtpyAction(actionBuilder);
766 private static Action SalToOFCopyTTLIOut(ActionBuilder actionBuilder) {
768 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class);
769 return emtpyAction(actionBuilder);
773 private static Action emtpyAction(ActionBuilder actionBuilder) {
774 return actionBuilder.build();
777 private static Action salToOFOutputAction(
778 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
779 ActionBuilder actionBuilder, short version) {
781 OutputActionCase outputActionCase = ((OutputActionCase) action);
782 OutputAction outputAction = outputActionCase.getOutputAction();
783 PortActionBuilder portAction = new PortActionBuilder();
784 MaxLengthActionBuilder maxLenActionBuilder = new MaxLengthActionBuilder();
785 if (outputAction.getMaxLength() != null) {
786 maxLenActionBuilder.setMaxLength(outputAction.getMaxLength());
788 maxLenActionBuilder.setMaxLength(0);
790 actionBuilder.addAugmentation(MaxLengthAction.class, maxLenActionBuilder.build());
792 Uri uri = outputAction.getOutputNodeConnector();
794 OpenflowVersion ofVersion = OpenflowVersion.get(version);
795 Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, uri.getValue());
796 if (OpenflowPortsUtil.checkPortValidity(ofVersion, portNumber)) {
797 portAction.setPort(new PortNumber(portNumber));
799 logger.error("Invalid Port specified " + portNumber + " for Output Action for OF version:" + ofVersion);
802 actionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
803 actionBuilder.addAugmentation(PortAction.class, portAction.build());
804 return actionBuilder.build();
809 * Method to convert OF actions associated with bucket to SAL Actions.
812 * @param ofVersion current ofp version
813 * @param actionPath TODO
814 * @return List of converted SAL Actions.
816 public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> toMDSalActions(
817 List<Action> actionList, OpenflowVersion ofVersion, ActionPath actionPath) {
819 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> bucketActions = new ArrayList<>();
820 for (Action action : actionList) {
821 if (action.getType().equals(
822 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class)) {
823 bucketActions.add(ofToSALOutputAction(ofVersion, action));
825 } else if (action.getType().equals(
826 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class)) {
827 bucketActions.add(ofToSALGroupAction(action));
829 } else if (action.getType().equals(
830 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class)) {
831 CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder();
832 bucketActions.add(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build());
834 } else if (action.getType().equals(
835 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class)) {
836 CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder();
837 bucketActions.add(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build());
839 } else if (action.getType().equals(
840 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class)) {
841 bucketActions.add(ofToSALSetMplsTtl(action));
843 } else if (action.getType().equals(
844 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class)) {
845 DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder();
846 bucketActions.add(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build());
848 } else if (action.getType().equals(
849 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class)) {
850 bucketActions.add(ofToSALPushVlanAction(action));
852 } else if (action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)
853 || action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class)) {
854 // OF1.0 nodes will emit StripVlan and OF1.3+ will emit StripVlan/PopVlan, convert both to PopVlan for SAL
855 PopVlanActionBuilder popVlan = new PopVlanActionBuilder();
856 bucketActions.add(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build());
858 } else if (action.getType().equals(
859 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class)) {
860 bucketActions.add(ofToSALPushMplsAction(action));
862 } else if (action.getType().equals(
863 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class)) {
864 bucketActions.add(ofToSALPopMplsAction(action));
866 } else if (action.getType().equals(
867 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class)) {
868 bucketActions.add(ofToSALSetQueue(action));
870 } else if (action.getType().equals(
871 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class)) {
872 bucketActions.add(ofToSALSetNwTtl(action));
874 } else if (action.getType().equals(
875 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class)) {
876 DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder();
877 bucketActions.add(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl.build()).build());
879 } else if (action.getType().equals(
880 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class)) {
881 bucketActions.add(new SetFieldCaseBuilder().setSetField(MatchConvertorImpl.fromOFSetFieldToSALSetFieldAction(action, ofVersion))
883 } else if (action.getType().equals(
884 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class)) {
885 bucketActions.add(ofToSALPushPbbAction(action));
887 } else if (action.getType().equals(
888 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class)) {
889 PopPbbActionBuilder popPbb = new PopPbbActionBuilder();
890 bucketActions.add(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build());
892 } else if (action.getType().equals(
893 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter.class)) {
895 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
896 * - we might also need a way on how to identify exact type of augmentation to be
897 * used as match can be bound to multiple models
899 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction =
900 ActionExtensionHelper.processAlienAction(action, ofVersion, actionPath);
901 if (processedAction != null) {
902 bucketActions.add(processedAction);
906 return bucketActions;
910 * Method converts OF Output action object to SAL Output action object.
914 * @param action org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.
915 * action.rev130731.actions.actions.list.Action
916 * @return OutputAction
918 public static OutputActionCase ofToSALOutputAction(OpenflowVersion ofVersion, Action action) {
919 OutputActionBuilder outputAction = new OutputActionBuilder();
920 PortAction port = action.getAugmentation(PortAction.class);
922 CommonPort.PortNumber protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(
923 ofVersion, port.getPort().getValue());
924 String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
925 outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
927 logger.error("Provided action is not OF Output action, no associated port found!");
930 MaxLengthAction length = action.getAugmentation(MaxLengthAction.class);
931 if (length != null) {
932 outputAction.setMaxLength(length.getMaxLength());
934 logger.error("Provided action is not OF Output action, no associated length found!");
937 return new OutputActionCaseBuilder().setOutputAction(outputAction.build()).build();
941 * Method converts OF GroupAction object to SAL GroupAction object
944 * @return GroupAction
946 public static GroupActionCase ofToSALGroupAction(Action action) {
948 GroupActionBuilder groupAction = new GroupActionBuilder();
950 GroupIdAction groupId = action.getAugmentation(GroupIdAction.class);
951 groupAction.setGroupId(groupId.getGroupId());
953 return new GroupActionCaseBuilder().setGroupAction(groupAction.build()).build();
957 * Method converts OF SetMplsTTL action object to SAL SetMplsTTL action
963 public static SetMplsTtlActionCase ofToSALSetMplsTtl(Action action) {
965 SetMplsTtlActionBuilder mplsTtlAction = new SetMplsTtlActionBuilder();
966 MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class);
967 mplsTtlAction.setMplsTtl(mplsTtl.getMplsTtl());
968 return new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(mplsTtlAction.build()).build();
972 * Method converts OF Pushvlan action to SAL PushVlan action.
975 * @return PushVlanAction
977 public static PushVlanActionCase ofToSALPushVlanAction(Action action) {
979 PushVlanActionBuilder pushVlanAction = new PushVlanActionBuilder();
981 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
982 pushVlanAction.setEthernetType(etherType.getEthertype().getValue());
984 return new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build();
988 * Method converts OF PushMpls action to SAL PushMpls action.
991 * @return PushMplsAction
993 public static PushMplsActionCase ofToSALPushMplsAction(Action action) {
995 PushMplsActionBuilder pushMplsAction = new PushMplsActionBuilder();
997 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
998 pushMplsAction.setEthernetType(etherType.getEthertype().getValue());
1000 return new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build();
1004 * Method converts OF PopMpls action to SAL PopMpls action.
1007 * @return PopMplsActionCase
1009 public static PopMplsActionCase ofToSALPopMplsAction(Action action) {
1011 PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder();
1013 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1014 popMplsAction.setEthernetType(etherType.getEthertype().getValue());
1016 return new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build();
1020 * Method converts OF SetQueue action to SAL SetQueue action.
1023 * @return SetQueueAction
1025 public static SetQueueActionCase ofToSALSetQueue(Action action) {
1027 SetQueueActionBuilder setQueueAction = new SetQueueActionBuilder();
1029 QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
1030 setQueueAction.setQueueId(queueId.getQueueId());
1032 return new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build();
1036 * Method converts OF SetNwTtl action to SAL SetNwTtl action.
1039 * @return SetNwTtlAction
1041 public static SetNwTtlActionCase ofToSALSetNwTtl(Action action) {
1043 SetNwTtlActionBuilder setNwTtl = new SetNwTtlActionBuilder();
1044 NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class);
1045 setNwTtl.setNwTtl(nwTtl.getNwTtl());
1047 return new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtl.build()).build();
1051 * Method converts OF Pushvlan action to SAL PushVlan action.
1054 * @return PushVlanAction
1056 public static PushPbbActionCase ofToSALPushPbbAction(Action action) {
1058 PushPbbActionBuilder pushPbbAction = new PushPbbActionBuilder();
1060 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1061 pushPbbAction.setEthernetType(etherType.getEthertype().getValue());
1063 return new PushPbbActionCaseBuilder().setPushPbbAction(pushPbbAction.build()).build();