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;
14 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
15 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
16 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
17 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
18 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
19 import org.opendaylight.openflowplugin.api.OFConstants;
20 import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwDstReactor;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwSrcReactor;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
25 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
26 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
27 import org.opendaylight.openflowplugin.openflow.md.util.ActionUtil;
28 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
29 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
30 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
32 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstAction;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcAction;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosAction;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueAction;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdAction;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntry;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4CodeMatchEntryBuilder;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntry;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv4TypeMatchEntryBuilder;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntry;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6CodeMatchEntryBuilder;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntry;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.Icmpv6TypeMatchEntryBuilder;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
154 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
155 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
156 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Code;
157 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv4Type;
158 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Code;
159 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Icmpv6Type;
160 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
161 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
162 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
163 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpDst;
164 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.UdpSrc;
165 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
166 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
167 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
168 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
169 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionGrouping;
170 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
171 import org.slf4j.Logger;
172 import org.slf4j.LoggerFactory;
174 import java.math.BigInteger;
175 import java.util.ArrayList;
176 import java.util.HashMap;
177 import java.util.List;
178 import java.util.Map;
181 * @author usha@ericsson Action List:This class takes data from SAL layer and
182 * converts into OF Data
183 * @author avishnoi@in.ibm.com Added convertor for OF bucket actions to SAL
186 public final class ActionConvertor {
187 private static final Logger logger = LoggerFactory.getLogger(ActionConvertor.class);
189 private ActionConvertor() {
194 * Translates SAL actions into OF Library actions
196 * @param actions SAL actions
197 * @param version Openflow protocol version used
200 * @return OF Library actions
202 public static List<Action> getActions(
203 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions,
204 short version, BigInteger datapathid, Flow flow) {
205 List<Action> actionsList = new ArrayList<>();
208 actions = Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>build())
209 .sortedCopy(actions);
211 for (int actionItem = 0; actionItem < actions.size(); actionItem++) {
213 ActionBuilder actionBuilder = new ActionBuilder();
215 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = actions.get(
216 actionItem).getAction();
218 if (action instanceof OutputActionCase)
219 ofAction = salToOFOutputAction(action, actionBuilder, version);
220 else if (action instanceof GroupActionCase)
221 ofAction = SalToOFGroupAction(action, actionBuilder);
222 else if (action instanceof CopyTtlOutCase)
223 ofAction = SalToOFCopyTTLIOut(actionBuilder);
224 else if (action instanceof CopyTtlInCase)
225 ofAction = SalToOFCopyTTLIIn(actionBuilder);
226 else if (action instanceof SetMplsTtlActionCase)
227 ofAction = SalToOFSetMplsTtl(action, actionBuilder);
228 else if (action instanceof DecMplsTtlCase)
229 ofAction = SalToOFDecMplsTtl(actionBuilder);
230 else if (action instanceof PushVlanActionCase)
231 ofAction = SalToOFPushVlanAction(action, actionBuilder, version);
232 else if (action instanceof PopVlanActionCase)
233 ofAction = (version == OFConstants.OFP_VERSION_1_0) ?
234 SalToOFStripVlan(actionBuilder, version)
235 : SalToOFPopVlan(actionBuilder);
236 else if (action instanceof PushMplsActionCase)
237 ofAction = SalToOFPushMplsAction(action, actionBuilder);
238 else if (action instanceof PopMplsActionCase)
239 ofAction = SalToOFPopMpls(action, actionBuilder);
240 else if (action instanceof SetQueueActionCase)
241 ofAction = SalToOFSetQueue(action, actionBuilder);
242 else if (action instanceof SetNwTtlActionCase)
243 ofAction = SalToOFSetNwTtl(action, actionBuilder);
244 else if (action instanceof DecNwTtlCase)
245 ofAction = SalToOFDecNwTtl(actionBuilder);
246 else if (action instanceof SetFieldCase)
247 ofAction = SalToOFSetField(action, actionBuilder, version, datapathid);
248 else if (action instanceof PushPbbActionCase)
249 ofAction = SalToOFPushPbbAction(action, actionBuilder);
250 else if (action instanceof PopPbbActionCase)
251 ofAction = SalToOFPopPBB(actionBuilder);
254 else if (action instanceof SetVlanIdActionCase) {
255 /*if (version == OFConstants.OFP_VERSION_1_0) {
258 List<Action> setVlanIdActionsList = convertToOF13(action, actionBuilder);
259 actionsList.addAll(setVlanIdActionsList);
261 ofAction = SalToOFSetVlanId(action, actionBuilder, version);
263 else if (action instanceof SetVlanPcpActionCase)
264 ofAction = SalToOFSetVlanpcp(action, actionBuilder, version);
265 else if (action instanceof StripVlanActionCase)
266 ofAction = SalToOFStripVlan(actionBuilder, version);
267 else if (action instanceof SetDlSrcActionCase)
268 ofAction = SalToOFSetDlSrc(action, actionBuilder, version);
269 else if (action instanceof SetDlDstActionCase)
270 ofAction = SalToOFSetDlDst(action, actionBuilder, version);
271 else if (action instanceof SetNwSrcActionCase)
272 ofAction = SalToOFSetNwSrc(action, actionBuilder, version);
273 else if (action instanceof SetNwDstActionCase)
274 ofAction = SalToOFSetNwDst(action, actionBuilder, version);
275 else if (action instanceof SetTpSrcActionCase) {
276 ofAction = SalToOFSetTpSrc(action, actionBuilder, version, IPProtocols.fromProtocolNum(flow.getMatch().
277 getIpMatch().getIpProtocol()));
279 else if (action instanceof SetTpDstActionCase) {
280 ofAction = SalToOFSetTpDst(action, actionBuilder, version, IPProtocols.fromProtocolNum(flow.getMatch().
281 getIpMatch().getIpProtocol()));
283 else if (action instanceof SetNwTosActionCase)
284 ofAction = SalToOFSetNwTos(action, actionBuilder, version);
285 else if (action instanceof GeneralExtensionGrouping) {
288 * TODO: EXTENSION PROPOSAL (action, MD-SAL to OFJava)
289 * - we might need sessionContext as converter input
293 GeneralExtensionGrouping extensionCaseGrouping = (GeneralExtensionGrouping) action;
294 Extension extAction = extensionCaseGrouping.getExtension();
295 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionCaseGrouping.getExtensionKey(), version);
296 ConvertorToOFJava<Action> convertor =
297 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
298 if (convertor != null) {
299 ofAction = convertor.convert(extAction);
303 TypeVersionKey<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> key =
304 new TypeVersionKey<>(
305 (Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>) action.getImplementedInterface(),
307 ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action> convertor =
308 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
309 if (convertor != null) {
310 ofAction = convertor.convert(action);
314 if (ofAction != null) {
315 actionsList.add(ofAction);
321 private static Action SalToOFSetField(
322 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
323 ActionBuilder actionBuilder, short version, BigInteger datapathid) {
325 SetFieldCase setFieldCase = (SetFieldCase) action;
326 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match =
327 setFieldCase.getSetField();
329 if (version == OFConstants.OFP_VERSION_1_0) {
330 // pushvlan +setField can be called to configure 1.0 switches via MDSAL app
331 if (match.getVlanMatch() != null) {
332 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
333 vlanidActionBuilder.setVlanVid(match.getVlanMatch().getVlanId().getVlanId().getValue());
334 actionBuilder.setType(
335 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
336 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
337 return actionBuilder.build();
339 return emtpyAction(actionBuilder);
343 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
344 MatchReactor.getInstance().convert(match, version, oxmFieldsActionBuilder, datapathid);
346 actionBuilder.setType(
347 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
349 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
350 return actionBuilder.build();
355 private static Action SalToOFDecNwTtl(ActionBuilder actionBuilder) {
357 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class);
358 return emtpyAction(actionBuilder);
361 private static Action SalToOFPushMplsAction(
362 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
363 ActionBuilder actionBuilder) {
364 PushMplsActionCase pushMplsActionCase = (PushMplsActionCase) action;
365 actionBuilder.setType(PushMpls.class);
367 return SalToOFPushAction(pushMplsActionCase.getPushMplsAction().getEthernetType(), actionBuilder);
370 private static Action SalToOFPushPbbAction(
371 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
372 ActionBuilder actionBuilder) {
373 PushPbbActionCase pushPbbActionCase = (PushPbbActionCase) action;
374 actionBuilder.setType(PushPbb.class);
376 return SalToOFPushAction(pushPbbActionCase.getPushPbbAction().getEthernetType(), actionBuilder);
379 private static Action SalToOFPushVlanAction(
380 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
381 ActionBuilder actionBuilder, short version) {
382 if (version == OFConstants.OFP_VERSION_1_0) {
383 // if client configure openflow 1.0 switch as a openflow 1.3 switch using openflow 1.3 instructions
384 // then we can ignore PUSH_VLAN as set-vlan-id will push a vlan header if not present
388 PushVlanActionCase pushVlanActionCase = (PushVlanActionCase) action;
389 PushVlanAction pushVlanAction = pushVlanActionCase.getPushVlanAction();
390 actionBuilder.setType(PushVlan.class);
392 return SalToOFPushAction(pushVlanAction.getEthernetType(), actionBuilder);
395 private static Action SalToOFSetNwTtl(
396 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
397 ActionBuilder actionBuilder) {
398 SetNwTtlActionCase nwTtlActionCase = (SetNwTtlActionCase) action;
399 NwTtlActionBuilder nwTtlActionBuilder = new NwTtlActionBuilder();
400 nwTtlActionBuilder.setNwTtl(nwTtlActionCase.getSetNwTtlAction().getNwTtl());
401 actionBuilder.setType(SetNwTtl.class);
402 actionBuilder.addAugmentation(NwTtlAction.class, nwTtlActionBuilder.build());
403 return actionBuilder.build();
406 private static Action SalToOFSetQueue(
407 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
408 ActionBuilder actionBuilder) {
409 SetQueueActionCase setQueueActionCase = (SetQueueActionCase) action;
410 SetQueueAction setQueueAction = setQueueActionCase.getSetQueueAction();
412 QueueIdActionBuilder queueIdActionBuilder = new QueueIdActionBuilder();
413 queueIdActionBuilder.setQueueId(setQueueAction.getQueueId());
414 actionBuilder.setType(SetQueue.class);
415 actionBuilder.addAugmentation(QueueIdAction.class, queueIdActionBuilder.build());
417 return actionBuilder.build();
420 private static Action SalToOFPopMpls(
421 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
422 ActionBuilder actionBuilder) {
423 PopMplsActionCase popMplsActionCase = (PopMplsActionCase) action;
424 actionBuilder.setType(PopMpls.class);
426 return SalToOFPushAction(popMplsActionCase.getPopMplsAction().getEthernetType(), actionBuilder);
429 private static Action SalToOFPopVlan(ActionBuilder actionBuilder) {
430 actionBuilder.setType(PopVlan.class);
431 return emtpyAction(actionBuilder);
434 private static Action SalToOFPopPBB(ActionBuilder actionBuilder) {
435 actionBuilder.setType(PopPbb.class);
436 return emtpyAction(actionBuilder);
439 // set-vlan-id (1.0 feature) can be called on 1.3 switches as well using ADSAL apis
440 private static Action SalToOFSetVlanId(
441 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
442 ActionBuilder actionBuilder, short version) {
444 SetVlanIdActionCase setvlanidcase = (SetVlanIdActionCase) action;
445 SetVlanIdAction setvlanidaction = setvlanidcase.getSetVlanIdAction();
447 if (version == OFConstants.OFP_VERSION_1_0) {
449 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
450 vlanidActionBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
452 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
453 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
454 return actionBuilder.build();
456 } else if (version >= OFConstants.OFP_VERSION_1_3) {
457 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
459 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
460 List<MatchEntries> matchEntriesList = new ArrayList<>();
461 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
462 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
463 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
464 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
465 vlanVidBuilder.setCfiBit(true);
466 vlanVidBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
467 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
468 matchEntriesBuilder.setHasMask(false);
469 matchEntriesList.add(matchEntriesBuilder.build());
470 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
471 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
472 return actionBuilder.build();
474 logger.error("Unknown Action Type for the Version", version);
479 private static Action SalToOFSetVlanpcp(
480 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
481 ActionBuilder actionBuilder, short version) {
483 SetVlanPcpActionCase setvlanpcpcase = (SetVlanPcpActionCase) action;
484 SetVlanPcpAction setvlanpcpaction = setvlanpcpcase.getSetVlanPcpAction();
486 if (version == OFConstants.OFP_VERSION_1_0) {
487 VlanPcpActionBuilder vlanpcpActionBuilder = new VlanPcpActionBuilder();
488 vlanpcpActionBuilder.setVlanPcp(setvlanpcpaction.getVlanPcp().getValue());
490 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp.class);
491 actionBuilder.addAugmentation(VlanPcpAction.class, vlanpcpActionBuilder.build());
492 return actionBuilder.build();
493 } else if (version >= OFConstants.OFP_VERSION_1_3) {
494 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
496 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
497 List<MatchEntries> matchEntriesList = new ArrayList<>();
498 matchEntriesList.add(MatchConvertorImpl.toOfVlanPcp(setvlanpcpaction.getVlanPcp()));
499 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
500 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
501 return actionBuilder.build();
503 logger.error("Unknown Action Type for the Version", version);
508 private static Action SalToOFStripVlan(ActionBuilder actionBuilder, short version) {
509 if (version == OFConstants.OFP_VERSION_1_0) {
511 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class);
513 return emtpyAction(actionBuilder);
514 } else if (version >= OFConstants.OFP_VERSION_1_3) {
515 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
517 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
518 List<MatchEntries> matchEntriesList = new ArrayList<>();
519 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
520 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
521 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
522 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
523 vlanVidBuilder.setCfiBit(true);
524 vlanVidBuilder.setVlanVid(0x0000);
525 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
526 matchEntriesBuilder.setHasMask(false);
527 matchEntriesList.add(matchEntriesBuilder.build());
528 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
529 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
530 return actionBuilder.build();
532 logger.error("Unknown Action Type for the Version", version);
537 private static Action SalToOFSetDlSrc(
538 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
539 ActionBuilder actionBuilder, short version) {
541 SetDlSrcActionCase setdlsrccase = (SetDlSrcActionCase) action;
542 SetDlSrcAction setdlsrcaction = setdlsrccase.getSetDlSrcAction();
544 if (version == OFConstants.OFP_VERSION_1_0) {
545 DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
546 dladdressactionbuilder.setDlAddress(setdlsrcaction.getAddress());
548 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc.class);
549 actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
550 return actionBuilder.build();
551 } else if (version >= OFConstants.OFP_VERSION_1_3) {
552 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
554 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
555 List<MatchEntries> matchEntriesList = new ArrayList<>();
556 matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthSrc.class, setdlsrcaction.getAddress(), null));
557 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
558 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
559 return actionBuilder.build();
561 logger.error("Unknown Action Type for the Version", version);
566 private static Action SalToOFSetDlDst(
567 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
568 ActionBuilder actionBuilder, short version) {
570 SetDlDstActionCase setdldstcase = (SetDlDstActionCase) action;
571 SetDlDstAction setdldstaction = setdldstcase.getSetDlDstAction();
573 if (version == OFConstants.OFP_VERSION_1_0) {
574 DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
575 dladdressactionbuilder.setDlAddress(setdldstaction.getAddress());
577 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst.class);
578 actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
579 return actionBuilder.build();
580 } else if (version >= OFConstants.OFP_VERSION_1_3) {
581 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
583 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
584 List<MatchEntries> matchEntriesList = new ArrayList<>();
585 matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthDst.class, setdldstaction.getAddress(), null));
586 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
587 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
588 return actionBuilder.build();
590 logger.error("Unknown Action Type for the Version", version);
595 protected static Action SalToOFSetNwSrc(
596 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
597 ActionBuilder actionBuilder, short version) {
600 ActionSetNwSrcReactor.getInstance().convert((SetNwSrcActionCase) action, version, actionBuilder, null);
601 } catch (Exception e) {
602 logger.error(e.getMessage(), e);
606 return actionBuilder.build();
609 protected static Action SalToOFSetNwDst(
610 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
611 ActionBuilder actionBuilder, short version) {
614 ActionSetNwDstReactor.getInstance().convert((SetNwDstActionCase) action, version, actionBuilder, null);
615 } catch (Exception e) {
616 logger.error(e.getMessage(), e);
620 return actionBuilder.build();
623 private static Action SalToOFSetNwTos(
624 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
625 ActionBuilder actionBuilder, short version) {
627 SetNwTosActionCase setnwtoscase = (SetNwTosActionCase) action;
628 SetNwTosAction setnwtosaction = setnwtoscase.getSetNwTosAction();
630 if (version == OFConstants.OFP_VERSION_1_0) {
631 NwTosActionBuilder tosBuilder = new NwTosActionBuilder();
632 tosBuilder.setNwTos(setnwtosaction.getTos().shortValue());
633 actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build());
635 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos.class);
637 return actionBuilder.build();
638 } else if (version >= OFConstants.OFP_VERSION_1_3) {
639 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
641 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
642 List<MatchEntries> matchEntriesList = new ArrayList<>();
643 matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(
644 ActionUtil.tosToDscp(setnwtosaction.getTos().shortValue())
646 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
647 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
648 return actionBuilder.build();
650 logger.error("Unknown Action Type for the Version", version);
656 private static Action SalToOFSetTpSrc(
657 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
658 ActionBuilder actionBuilder, short version, IPProtocols protocol) {
660 if (version == OFConstants.OFP_VERSION_1_0) {
661 SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
662 SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
664 PortActionBuilder settpsrc = new PortActionBuilder();
665 PortNumber port = new PortNumber(settpsrcaction.getPort().getValue().longValue());
666 settpsrc.setPort(port);
669 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc.class);
670 actionBuilder.addAugmentation(PortAction.class, settpsrc.build());
671 return actionBuilder.build();
672 } else if (version == OFConstants.OFP_VERSION_1_3) {
673 SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
674 SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
676 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
677 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
678 matchEntriesBuilder.setHasMask(false);
679 PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
680 int port = settpsrcaction.getPort().getValue().intValue();
681 int type = 0x0f & port;
685 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
686 Icmpv4TypeMatchEntryBuilder icmpv4TypeMatchEntryBuilder = new Icmpv4TypeMatchEntryBuilder();
687 icmpv4TypeMatchEntryBuilder.setIcmpv4Type((short) type);
688 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeMatchEntryBuilder.build());
691 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
692 Icmpv6TypeMatchEntryBuilder icmpv6TypeMatchEntryBuilder = new Icmpv6TypeMatchEntryBuilder();
693 icmpv6TypeMatchEntryBuilder.setIcmpv6Type((short) type);
694 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeMatchEntryBuilder.build());
697 matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
698 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
699 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
702 matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
703 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
704 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
706 default: logger.warn("Unknown protocol with combination of SetSourcePort: {}", protocol);
711 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
713 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
714 List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
715 matchEntries.add(matchEntriesBuilder.build());
716 oxmFieldsActionBuilder.setMatchEntries(matchEntries);
718 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
719 return actionBuilder.build();
721 logger.error("Unknown Action Type for the Version", version);
725 private static Action SalToOFSetTpDst(
726 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
727 ActionBuilder actionBuilder, short version, IPProtocols protocol) {
729 if (version == OFConstants.OFP_VERSION_1_0) {
730 SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
731 SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
732 PortActionBuilder settpdst = new PortActionBuilder();
733 PortNumber port = new PortNumber(settpdstaction.getPort().getValue().longValue());
734 settpdst.setPort(port);
737 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst.class);
738 actionBuilder.addAugmentation(PortAction.class, settpdst.build());
739 return actionBuilder.build();
740 } else if (version == OFConstants.OFP_VERSION_1_3) {
741 SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
742 SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
744 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
745 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
746 matchEntriesBuilder.setHasMask(false);
747 PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
748 int port = settpdstaction.getPort().getValue().intValue();
749 int code = 0x0f & port;
753 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
754 Icmpv4CodeMatchEntryBuilder icmpv4CodeMatchEntryBuilder = new Icmpv4CodeMatchEntryBuilder();
755 icmpv4CodeMatchEntryBuilder.setIcmpv4Code((short) code);
756 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeMatchEntryBuilder.build());
759 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
760 Icmpv6CodeMatchEntryBuilder icmpv6CodeMatchEntryBuilder = new Icmpv6CodeMatchEntryBuilder();
761 icmpv6CodeMatchEntryBuilder.setIcmpv6Code((short) code);
762 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeMatchEntryBuilder.build());
765 matchEntriesBuilder.setOxmMatchField(TcpDst.class);
766 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
767 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
770 matchEntriesBuilder.setOxmMatchField(UdpDst.class);
771 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
772 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
774 default: logger.warn("Unknown protocol with combination of SetDestinationPort: {}", protocol);
779 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
781 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
782 List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
783 matchEntries.add(matchEntriesBuilder.build());
784 oxmFieldsActionBuilder.setMatchEntries(matchEntries);
786 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
787 return actionBuilder.build();
789 logger.error("Unknown Action Type for the Version", version);
793 private static Action SalToOFGroupAction(
794 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
795 ActionBuilder actionBuilder) {
797 GroupActionCase groupActionCase = (GroupActionCase) action;
798 GroupAction groupAction = groupActionCase.getGroupAction();
800 GroupIdActionBuilder groupIdBuilder = new GroupIdActionBuilder();
801 groupIdBuilder.setGroupId(groupAction.getGroupId());
802 actionBuilder.setType(Group.class);
803 actionBuilder.addAugmentation(GroupIdAction.class, groupIdBuilder.build());
804 return actionBuilder.build();
807 private static Action SalToOFPushAction(Integer ethernetType, ActionBuilder actionBuilder) {
808 EthertypeActionBuilder ethertypeActionBuilder = new EthertypeActionBuilder();
809 if (ethernetType != null) {
810 ethertypeActionBuilder.setEthertype(new EtherType(ethernetType));
814 actionBuilder.addAugmentation(EthertypeAction.class, ethertypeActionBuilder.build());
815 return actionBuilder.build();
818 private static Action SalToOFDecMplsTtl(ActionBuilder actionBuilder) {
820 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class);
821 return emtpyAction(actionBuilder);
824 private static Action SalToOFSetMplsTtl(
825 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
826 ActionBuilder actionBuilder) {
827 SetMplsTtlActionCase mplsTtlActionCase = (SetMplsTtlActionCase) action;
828 SetMplsTtlAction mplsTtlAction = mplsTtlActionCase.getSetMplsTtlAction();
830 MplsTtlActionBuilder mplsTtlActionBuilder = new MplsTtlActionBuilder();
831 mplsTtlActionBuilder.setMplsTtl(mplsTtlAction.getMplsTtl()/* SAL */);
833 actionBuilder.setType(SetMplsTtl.class);
834 actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtlActionBuilder.build());
835 return actionBuilder.build();
838 private static Action SalToOFCopyTTLIIn(ActionBuilder actionBuilder) {
840 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class);
841 return emtpyAction(actionBuilder);
844 private static Action SalToOFCopyTTLIOut(ActionBuilder actionBuilder) {
846 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class);
847 return emtpyAction(actionBuilder);
851 private static Action emtpyAction(ActionBuilder actionBuilder) {
852 return actionBuilder.build();
855 private static Action salToOFOutputAction(
856 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
857 ActionBuilder actionBuilder, short version) {
859 OutputActionCase outputActionCase = ((OutputActionCase) action);
860 OutputAction outputAction = outputActionCase.getOutputAction();
861 PortActionBuilder portAction = new PortActionBuilder();
862 MaxLengthActionBuilder maxLenActionBuilder = new MaxLengthActionBuilder();
863 if (outputAction.getMaxLength() != null) {
864 maxLenActionBuilder.setMaxLength(outputAction.getMaxLength());
866 maxLenActionBuilder.setMaxLength(0);
868 actionBuilder.addAugmentation(MaxLengthAction.class, maxLenActionBuilder.build());
870 Uri uri = outputAction.getOutputNodeConnector();
872 OpenflowVersion ofVersion = OpenflowVersion.get(version);
873 Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, uri.getValue());
874 if (OpenflowPortsUtil.checkPortValidity(ofVersion, portNumber)) {
875 portAction.setPort(new PortNumber(portNumber));
877 logger.error("Invalid Port specified " + portNumber + " for Output Action for OF version:" + ofVersion);
880 actionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
881 actionBuilder.addAugmentation(PortAction.class, portAction.build());
882 return actionBuilder.build();
887 * Method to convert OF actions associated with bucket to SAL Actions.
890 * @param ofVersion current ofp version
891 * @param actionPath TODO
892 * @return List of converted SAL Actions.
894 public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> toMDSalActions(
895 List<Action> actionList, OpenflowVersion ofVersion, ActionPath actionPath) {
897 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> bucketActions = new ArrayList<>();
898 for (Action action : actionList) {
899 if (action.getType().equals(
900 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class)) {
901 bucketActions.add(ofToSALOutputAction(ofVersion, action));
903 } else if (action.getType().equals(
904 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class)) {
905 bucketActions.add(ofToSALGroupAction(action));
907 } else if (action.getType().equals(
908 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class)) {
909 CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder();
910 bucketActions.add(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build());
912 } else if (action.getType().equals(
913 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class)) {
914 CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder();
915 bucketActions.add(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build());
917 } else if (action.getType().equals(
918 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class)) {
919 bucketActions.add(ofToSALSetMplsTtl(action));
921 } else if (action.getType().equals(
922 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class)) {
923 DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder();
924 bucketActions.add(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build());
926 } else if (action.getType().equals(
927 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class)) {
928 bucketActions.add(ofToSALPushVlanAction(action));
930 } else if (action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)
931 || action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class)) {
932 // OF1.0 nodes will emit StripVlan and OF1.3+ will emit StripVlan/PopVlan, convert both to PopVlan for SAL
933 PopVlanActionBuilder popVlan = new PopVlanActionBuilder();
934 bucketActions.add(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build());
936 } else if (action.getType().equals(
937 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class)) {
938 bucketActions.add(ofToSALPushMplsAction(action));
940 } else if (action.getType().equals(
941 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class)) {
942 bucketActions.add(ofToSALPopMplsAction(action));
944 } else if (action.getType().equals(
945 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class)) {
946 bucketActions.add(ofToSALSetQueue(action));
948 } else if (action.getType().equals(
949 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class)) {
950 bucketActions.add(ofToSALSetNwTtl(action));
952 } else if (action.getType().equals(
953 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class)) {
954 DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder();
955 bucketActions.add(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl.build()).build());
957 } else if (action.getType().equals(
958 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class)) {
959 bucketActions.add(new SetFieldCaseBuilder().setSetField(MatchConvertorImpl.fromOFSetFieldToSALSetFieldAction(action, ofVersion))
961 } else if (action.getType().equals(
962 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class)) {
963 bucketActions.add(ofToSALPushPbbAction(action));
965 } else if (action.getType().equals(
966 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class)) {
967 PopPbbActionBuilder popPbb = new PopPbbActionBuilder();
968 bucketActions.add(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build());
970 } else if (action.getType().equals(
971 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter.class)) {
973 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
974 * - we might also need a way on how to identify exact type of augmentation to be
975 * used as match can be bound to multiple models
977 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction =
978 ActionExtensionHelper.processAlienAction(action, ofVersion, actionPath);
979 if (processedAction != null) {
980 bucketActions.add(processedAction);
984 return bucketActions;
988 * Method converts OF Output action object to SAL Output action object.
992 * @param action org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.
993 * action.rev130731.actions.actions.list.Action
994 * @return OutputAction
996 public static OutputActionCase ofToSALOutputAction(OpenflowVersion ofVersion, Action action) {
997 OutputActionBuilder outputAction = new OutputActionBuilder();
998 PortAction port = action.getAugmentation(PortAction.class);
1000 CommonPort.PortNumber protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(
1001 ofVersion, port.getPort().getValue());
1002 String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
1003 outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
1005 logger.error("Provided action is not OF Output action, no associated port found!");
1008 MaxLengthAction length = action.getAugmentation(MaxLengthAction.class);
1009 if (length != null) {
1010 outputAction.setMaxLength(length.getMaxLength());
1012 logger.error("Provided action is not OF Output action, no associated length found!");
1015 return new OutputActionCaseBuilder().setOutputAction(outputAction.build()).build();
1019 * Method converts OF GroupAction object to SAL GroupAction object
1022 * @return GroupAction
1024 public static GroupActionCase ofToSALGroupAction(Action action) {
1026 GroupActionBuilder groupAction = new GroupActionBuilder();
1028 GroupIdAction groupId = action.getAugmentation(GroupIdAction.class);
1029 groupAction.setGroupId(groupId.getGroupId());
1031 return new GroupActionCaseBuilder().setGroupAction(groupAction.build()).build();
1035 * Method converts OF SetMplsTTL action object to SAL SetMplsTTL action
1041 public static SetMplsTtlActionCase ofToSALSetMplsTtl(Action action) {
1043 SetMplsTtlActionBuilder mplsTtlAction = new SetMplsTtlActionBuilder();
1044 MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class);
1045 mplsTtlAction.setMplsTtl(mplsTtl.getMplsTtl());
1046 return new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(mplsTtlAction.build()).build();
1050 * Method converts OF Pushvlan action to SAL PushVlan action.
1053 * @return PushVlanAction
1055 public static PushVlanActionCase ofToSALPushVlanAction(Action action) {
1057 PushVlanActionBuilder pushVlanAction = new PushVlanActionBuilder();
1059 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1060 pushVlanAction.setEthernetType(etherType.getEthertype().getValue());
1062 return new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build();
1066 * Method converts OF PushMpls action to SAL PushMpls action.
1069 * @return PushMplsAction
1071 public static PushMplsActionCase ofToSALPushMplsAction(Action action) {
1073 PushMplsActionBuilder pushMplsAction = new PushMplsActionBuilder();
1075 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1076 pushMplsAction.setEthernetType(etherType.getEthertype().getValue());
1078 return new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build();
1082 * Method converts OF PopMpls action to SAL PopMpls action.
1085 * @return PopMplsActionCase
1087 public static PopMplsActionCase ofToSALPopMplsAction(Action action) {
1089 PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder();
1091 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1092 popMplsAction.setEthernetType(etherType.getEthertype().getValue());
1094 return new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build();
1098 * Method converts OF SetQueue action to SAL SetQueue action.
1101 * @return SetQueueAction
1103 public static SetQueueActionCase ofToSALSetQueue(Action action) {
1105 SetQueueActionBuilder setQueueAction = new SetQueueActionBuilder();
1107 QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
1108 setQueueAction.setQueueId(queueId.getQueueId());
1109 return new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build();
1113 * Method converts OF SetNwTtl action to SAL SetNwTtl action.
1116 * @return SetNwTtlAction
1118 public static SetNwTtlActionCase ofToSALSetNwTtl(Action action) {
1120 SetNwTtlActionBuilder setNwTtl = new SetNwTtlActionBuilder();
1121 NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class);
1122 setNwTtl.setNwTtl(nwTtl.getNwTtl());
1124 return new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtl.build()).build();
1128 * Method converts OF Pushvlan action to SAL PushVlan action.
1131 * @return PushVlanAction
1133 public static PushPbbActionCase ofToSALPushPbbAction(Action action) {
1135 PushPbbActionBuilder pushPbbAction = new PushPbbActionBuilder();
1137 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1138 pushPbbAction.setEthernetType(etherType.getEthertype().getValue());
1140 return new PushPbbActionCaseBuilder().setPushPbbAction(pushPbbAction.build()).build();
1143 //TODO make a model in YANG for protocols
1144 /*private enum IPProtocols {
1150 private int protocol;
1152 private static Map<Integer, IPProtocols> valueMap;
1154 valueMap = new HashMap<>();
1155 for(IPProtocols protocols : IPProtocols.values()) {
1156 valueMap.put(protocols.protocol, protocols);
1160 private IPProtocols(int value) {
1161 this.protocol = value;
1164 private byte getValue() {
1165 return (byte) this.protocol;
1168 private Short getShortValue() {
1169 return new Short((short) protocol);
1172 private IPProtocols fromProtocolNum(Short protocolNum) {
1173 return valueMap.get(protocolNum);