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;
173 import java.math.BigInteger;
174 import java.util.ArrayList;
175 import java.util.List;
178 * @author usha@ericsson Action List:This class takes data from SAL layer and
179 * converts into OF Data
180 * @author avishnoi@in.ibm.com Added convertor for OF bucket actions to SAL
183 public final class ActionConvertor {
184 private static final Logger LOG = LoggerFactory.getLogger(ActionConvertor.class);
185 private static final String UNKNOWN_ACTION_TYPE_VERSION = "Unknown Action Type for the Version";
187 private ActionConvertor() {
192 * Translates SAL actions into OF Library actions
194 * @param actions SAL actions
195 * @param version Openflow protocol version used
198 * @return OF Library actions
200 public static List<Action> getActions(
201 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions,
202 short version, BigInteger datapathid, Flow flow) {
203 List<Action> actionsList = new ArrayList<>();
206 final List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> sortedActions =
207 Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>build())
208 .sortedCopy(actions);
210 for (int actionItem = 0; actionItem < sortedActions.size(); actionItem++) {
212 ActionBuilder actionBuilder = new ActionBuilder();
214 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = sortedActions.get(
215 actionItem).getAction();
217 if (action instanceof OutputActionCase) {
218 ofAction = salToOFAction((OutputActionCase)action, actionBuilder, version);
219 } else if (action instanceof GroupActionCase) {
220 ofAction = salToOFGroupAction(action, actionBuilder);
221 } else if (action instanceof CopyTtlOutCase) {
222 ofAction = salToOFCopyTTLIOut(actionBuilder);
223 } else if (action instanceof CopyTtlInCase) {
224 ofAction = salToOFCopyTTLIIn(actionBuilder);
225 } else if (action instanceof SetMplsTtlActionCase) {
226 ofAction = salToOFSetMplsTtl(action, actionBuilder);
227 } else if (action instanceof DecMplsTtlCase) {
228 ofAction = salToOFDecMplsTtl(actionBuilder);
229 } else if (action instanceof PushVlanActionCase) {
230 ofAction = salToOFPushVlanAction(action, actionBuilder, version);
231 } else if (action instanceof PopVlanActionCase) {
232 ofAction = (version == OFConstants.OFP_VERSION_1_0) ?
233 salToOFStripVlan(actionBuilder, version)
234 : salToOFPopVlan(actionBuilder);
235 } else if (action instanceof PushMplsActionCase) {
236 ofAction = salToOFPushMplsAction(action, actionBuilder);
237 } else if (action instanceof PopMplsActionCase) {
238 ofAction = salToOFPopMpls(action, actionBuilder);
239 } else if (action instanceof SetQueueActionCase) {
240 ofAction = salToOFSetQueue(action, actionBuilder);
241 } else if (action instanceof SetNwTtlActionCase) {
242 ofAction = salToOFSetNwTtl(action, actionBuilder);
243 } else if (action instanceof DecNwTtlCase) {
244 ofAction = salToOFDecNwTtl(actionBuilder);
245 } else if (action instanceof SetFieldCase) {
246 ofAction = salToOFSetField(action, actionBuilder, version, datapathid);
247 } else if (action instanceof PushPbbActionCase) {
248 ofAction = salToOFPushPbbAction(action, actionBuilder);
249 } else if (action instanceof PopPbbActionCase) {
250 ofAction = salToOFPopPBB(actionBuilder);
253 } else if (action instanceof SetVlanIdActionCase) {
254 /*if (version == OFConstants.OFP_VERSION_1_0) {
257 List<Action> setVlanIdActionsList = convertToOF13(action, actionBuilder);
258 actionsList.addAll(setVlanIdActionsList);
260 ofAction = salToOFSetVlanId(action, actionBuilder, version);
261 } else if (action instanceof SetVlanPcpActionCase) {
262 ofAction = salToOFSetVlanpcp(action, actionBuilder, version);
263 } else if (action instanceof StripVlanActionCase) {
264 ofAction = salToOFStripVlan(actionBuilder, version);
265 } else if (action instanceof SetDlSrcActionCase) {
266 ofAction = salToOFSetDlSrc(action, actionBuilder, version);
267 } else if (action instanceof SetDlDstActionCase) {
268 ofAction = salToOFSetDlDst(action, actionBuilder, version);
269 } else if (action instanceof SetNwSrcActionCase) {
270 ofAction = salToOFSetNwSrc(action, actionBuilder, version);
271 } else if (action instanceof SetNwDstActionCase) {
272 ofAction = salToOFSetNwDst(action, actionBuilder, version);
273 } else if (action instanceof SetTpSrcActionCase) {
274 ofAction = salToOFSetTpSrc(action, actionBuilder, version, IPProtocols.fromProtocolNum(flow.getMatch().
275 getIpMatch().getIpProtocol()));
276 } else if (action instanceof SetTpDstActionCase) {
277 ofAction = salToOFSetTpDst(action, actionBuilder, version, IPProtocols.fromProtocolNum(flow.getMatch().
278 getIpMatch().getIpProtocol()));
279 } else if (action instanceof SetNwTosActionCase) {
280 ofAction = salToOFSetNwTos(action, actionBuilder, version);
281 } else if (action instanceof GeneralExtensionGrouping) {
284 * TODO: EXTENSION PROPOSAL (action, MD-SAL to OFJava)
285 * - we might need sessionContext as converter input
289 GeneralExtensionGrouping extensionCaseGrouping = (GeneralExtensionGrouping) action;
290 Extension extAction = extensionCaseGrouping.getExtension();
291 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionCaseGrouping.getExtensionKey(), version);
292 ConvertorToOFJava<Action> convertor =
293 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
294 if (convertor != null) {
295 ofAction = convertor.convert(extAction);
299 TypeVersionKey<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> key =
300 new TypeVersionKey<>(
301 (Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>) action.getImplementedInterface(),
303 ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action> convertor =
304 OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
305 if (convertor != null) {
306 ofAction = convertor.convert(action);
310 if (ofAction != null) {
311 actionsList.add(ofAction);
317 private static Action salToOFSetField(
318 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
319 ActionBuilder actionBuilder, short version, BigInteger datapathid) {
321 SetFieldCase setFieldCase = (SetFieldCase) action;
322 org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match =
323 setFieldCase.getSetField();
325 if (version == OFConstants.OFP_VERSION_1_0) {
326 // pushvlan +setField can be called to configure 1.0 switches via MDSAL app
327 if (match.getVlanMatch() != null) {
328 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
329 vlanidActionBuilder.setVlanVid(match.getVlanMatch().getVlanId().getVlanId().getValue());
330 actionBuilder.setType(
331 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
332 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
333 return actionBuilder.build();
335 return emtpyAction(actionBuilder);
339 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
340 MatchReactor.getInstance().convert(match, version, oxmFieldsActionBuilder, datapathid);
342 actionBuilder.setType(
343 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
345 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
346 return actionBuilder.build();
351 private static Action salToOFDecNwTtl(ActionBuilder actionBuilder) {
353 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class);
354 return emtpyAction(actionBuilder);
357 private static Action salToOFPushMplsAction(
358 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
359 ActionBuilder actionBuilder) {
360 PushMplsActionCase pushMplsActionCase = (PushMplsActionCase) action;
361 actionBuilder.setType(PushMpls.class);
363 return salToOFPushAction(pushMplsActionCase.getPushMplsAction().getEthernetType(), actionBuilder);
366 private static Action salToOFPushPbbAction(
367 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
368 ActionBuilder actionBuilder) {
369 PushPbbActionCase pushPbbActionCase = (PushPbbActionCase) action;
370 actionBuilder.setType(PushPbb.class);
372 return salToOFPushAction(pushPbbActionCase.getPushPbbAction().getEthernetType(), actionBuilder);
375 private static Action salToOFPushVlanAction(
376 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
377 ActionBuilder actionBuilder, short version) {
378 if (version == OFConstants.OFP_VERSION_1_0) {
379 // if client configure openflow 1.0 switch as a openflow 1.3 switch using openflow 1.3 instructions
380 // then we can ignore PUSH_VLAN as set-vlan-id will push a vlan header if not present
384 PushVlanActionCase pushVlanActionCase = (PushVlanActionCase) action;
385 PushVlanAction pushVlanAction = pushVlanActionCase.getPushVlanAction();
386 actionBuilder.setType(PushVlan.class);
388 return salToOFPushAction(pushVlanAction.getEthernetType(), actionBuilder);
391 private static Action salToOFSetNwTtl(
392 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
393 ActionBuilder actionBuilder) {
394 SetNwTtlActionCase nwTtlActionCase = (SetNwTtlActionCase) action;
395 NwTtlActionBuilder nwTtlActionBuilder = new NwTtlActionBuilder();
396 nwTtlActionBuilder.setNwTtl(nwTtlActionCase.getSetNwTtlAction().getNwTtl());
397 actionBuilder.setType(SetNwTtl.class);
398 actionBuilder.addAugmentation(NwTtlAction.class, nwTtlActionBuilder.build());
399 return actionBuilder.build();
402 private static Action salToOFSetQueue(
403 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
404 ActionBuilder actionBuilder) {
405 SetQueueActionCase setQueueActionCase = (SetQueueActionCase) action;
406 SetQueueAction setQueueAction = setQueueActionCase.getSetQueueAction();
408 QueueIdActionBuilder queueIdActionBuilder = new QueueIdActionBuilder();
409 queueIdActionBuilder.setQueueId(setQueueAction.getQueueId());
410 actionBuilder.setType(SetQueue.class);
411 actionBuilder.addAugmentation(QueueIdAction.class, queueIdActionBuilder.build());
413 return actionBuilder.build();
416 private static Action salToOFPopMpls(
417 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
418 ActionBuilder actionBuilder) {
419 PopMplsActionCase popMplsActionCase = (PopMplsActionCase) action;
420 actionBuilder.setType(PopMpls.class);
422 return salToOFPushAction(popMplsActionCase.getPopMplsAction().getEthernetType(), actionBuilder);
425 private static Action salToOFPopVlan(ActionBuilder actionBuilder) {
426 actionBuilder.setType(PopVlan.class);
427 return emtpyAction(actionBuilder);
430 private static Action salToOFPopPBB(ActionBuilder actionBuilder) {
431 actionBuilder.setType(PopPbb.class);
432 return emtpyAction(actionBuilder);
435 // set-vlan-id (1.0 feature) can be called on 1.3 switches as well using ADSAL apis
436 private static Action salToOFSetVlanId(
437 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
438 ActionBuilder actionBuilder, short version) {
440 SetVlanIdActionCase setvlanidcase = (SetVlanIdActionCase) action;
441 SetVlanIdAction setvlanidaction = setvlanidcase.getSetVlanIdAction();
443 if (version == OFConstants.OFP_VERSION_1_0) {
445 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
446 vlanidActionBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
448 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
449 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
450 return actionBuilder.build();
452 } else if (version >= OFConstants.OFP_VERSION_1_3) {
453 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
455 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
456 List<MatchEntries> matchEntriesList = new ArrayList<>();
457 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
458 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
459 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
460 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
461 vlanVidBuilder.setCfiBit(true);
462 vlanVidBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
463 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
464 matchEntriesBuilder.setHasMask(false);
465 matchEntriesList.add(matchEntriesBuilder.build());
466 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
467 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
468 return actionBuilder.build();
470 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
475 private static Action salToOFSetVlanpcp(
476 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
477 ActionBuilder actionBuilder, short version) {
479 SetVlanPcpActionCase setvlanpcpcase = (SetVlanPcpActionCase) action;
480 SetVlanPcpAction setvlanpcpaction = setvlanpcpcase.getSetVlanPcpAction();
482 if (version == OFConstants.OFP_VERSION_1_0) {
483 VlanPcpActionBuilder vlanpcpActionBuilder = new VlanPcpActionBuilder();
484 vlanpcpActionBuilder.setVlanPcp(setvlanpcpaction.getVlanPcp().getValue());
486 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp.class);
487 actionBuilder.addAugmentation(VlanPcpAction.class, vlanpcpActionBuilder.build());
488 return actionBuilder.build();
489 } else if (version >= OFConstants.OFP_VERSION_1_3) {
490 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
492 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
493 List<MatchEntries> matchEntriesList = new ArrayList<>();
494 matchEntriesList.add(MatchConvertorImpl.toOfVlanPcp(setvlanpcpaction.getVlanPcp()));
495 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
496 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
497 return actionBuilder.build();
499 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
504 private static Action salToOFStripVlan(ActionBuilder actionBuilder, short version) {
505 if (version == OFConstants.OFP_VERSION_1_0) {
507 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class);
509 return emtpyAction(actionBuilder);
510 } else if (version >= OFConstants.OFP_VERSION_1_3) {
511 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
513 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
514 List<MatchEntries> matchEntriesList = new ArrayList<>();
515 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
516 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
517 matchEntriesBuilder.setOxmMatchField(VlanVid.class);
518 VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
519 vlanVidBuilder.setCfiBit(true);
520 vlanVidBuilder.setVlanVid(0x0000);
521 matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
522 matchEntriesBuilder.setHasMask(false);
523 matchEntriesList.add(matchEntriesBuilder.build());
524 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
525 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
526 return actionBuilder.build();
528 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
533 private static Action salToOFSetDlSrc(
534 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
535 ActionBuilder actionBuilder, short version) {
537 SetDlSrcActionCase setdlsrccase = (SetDlSrcActionCase) action;
538 SetDlSrcAction setdlsrcaction = setdlsrccase.getSetDlSrcAction();
540 if (version == OFConstants.OFP_VERSION_1_0) {
541 DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
542 dladdressactionbuilder.setDlAddress(setdlsrcaction.getAddress());
544 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc.class);
545 actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
546 return actionBuilder.build();
547 } else if (version >= OFConstants.OFP_VERSION_1_3) {
548 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
550 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
551 List<MatchEntries> matchEntriesList = new ArrayList<>();
552 matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthSrc.class, setdlsrcaction.getAddress(), null));
553 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
554 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
555 return actionBuilder.build();
557 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
562 private static Action salToOFSetDlDst(
563 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
564 ActionBuilder actionBuilder, short version) {
566 SetDlDstActionCase setdldstcase = (SetDlDstActionCase) action;
567 SetDlDstAction setdldstaction = setdldstcase.getSetDlDstAction();
569 if (version == OFConstants.OFP_VERSION_1_0) {
570 DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
571 dladdressactionbuilder.setDlAddress(setdldstaction.getAddress());
573 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst.class);
574 actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
575 return actionBuilder.build();
576 } else if (version >= OFConstants.OFP_VERSION_1_3) {
577 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
579 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
580 List<MatchEntries> matchEntriesList = new ArrayList<>();
581 matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthDst.class, setdldstaction.getAddress(), null));
582 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
583 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
584 return actionBuilder.build();
586 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
591 protected static Action salToOFSetNwSrc(
592 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
593 ActionBuilder actionBuilder, short version) {
596 ActionSetNwSrcReactor.getInstance().convert((SetNwSrcActionCase) action, version, actionBuilder, null);
597 } catch (Exception e) {
598 LOG.error(e.getMessage(), e);
602 return actionBuilder.build();
605 protected static Action salToOFSetNwDst(
606 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
607 ActionBuilder actionBuilder, short version) {
610 ActionSetNwDstReactor.getInstance().convert((SetNwDstActionCase) action, version, actionBuilder, null);
611 } catch (Exception e) {
612 LOG.error(e.getMessage(), e);
616 return actionBuilder.build();
619 private static Action salToOFSetNwTos(
620 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
621 ActionBuilder actionBuilder, short version) {
623 SetNwTosActionCase setnwtoscase = (SetNwTosActionCase) action;
624 SetNwTosAction setnwtosaction = setnwtoscase.getSetNwTosAction();
626 if (version == OFConstants.OFP_VERSION_1_0) {
627 NwTosActionBuilder tosBuilder = new NwTosActionBuilder();
628 tosBuilder.setNwTos(setnwtosaction.getTos().shortValue());
629 actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build());
631 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos.class);
633 return actionBuilder.build();
634 } else if (version >= OFConstants.OFP_VERSION_1_3) {
635 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
637 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
638 List<MatchEntries> matchEntriesList = new ArrayList<>();
639 matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(
640 ActionUtil.tosToDscp(setnwtosaction.getTos().shortValue())
642 oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
643 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
644 return actionBuilder.build();
646 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
652 private static Action salToOFSetTpSrc(
653 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
654 ActionBuilder actionBuilder, short version, IPProtocols protocol) {
656 if (version == OFConstants.OFP_VERSION_1_0) {
657 SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
658 SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
660 PortActionBuilder settpsrc = new PortActionBuilder();
661 PortNumber port = new PortNumber(settpsrcaction.getPort().getValue().longValue());
662 settpsrc.setPort(port);
665 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc.class);
666 actionBuilder.addAugmentation(PortAction.class, settpsrc.build());
667 return actionBuilder.build();
668 } else if (version == OFConstants.OFP_VERSION_1_3) {
669 SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
670 SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
672 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
673 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
674 matchEntriesBuilder.setHasMask(false);
675 PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
676 int port = settpsrcaction.getPort().getValue().intValue();
677 int type = 0x0f & port;
681 matchEntriesBuilder.setOxmMatchField(Icmpv4Type.class);
682 Icmpv4TypeMatchEntryBuilder icmpv4TypeMatchEntryBuilder = new Icmpv4TypeMatchEntryBuilder();
683 icmpv4TypeMatchEntryBuilder.setIcmpv4Type((short) type);
684 matchEntriesBuilder.addAugmentation(Icmpv4TypeMatchEntry.class, icmpv4TypeMatchEntryBuilder.build());
687 matchEntriesBuilder.setOxmMatchField(Icmpv6Type.class);
688 Icmpv6TypeMatchEntryBuilder icmpv6TypeMatchEntryBuilder = new Icmpv6TypeMatchEntryBuilder();
689 icmpv6TypeMatchEntryBuilder.setIcmpv6Type((short) type);
690 matchEntriesBuilder.addAugmentation(Icmpv6TypeMatchEntry.class, icmpv6TypeMatchEntryBuilder.build());
693 matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
694 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
695 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
698 matchEntriesBuilder.setOxmMatchField(UdpSrc.class);
699 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
700 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
702 default: LOG.warn("Unknown protocol with combination of SetSourcePort: {}", protocol);
707 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
709 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
710 List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
711 matchEntries.add(matchEntriesBuilder.build());
712 oxmFieldsActionBuilder.setMatchEntries(matchEntries);
714 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
715 return actionBuilder.build();
717 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
721 private static Action salToOFSetTpDst(
722 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
723 ActionBuilder actionBuilder, short version, IPProtocols protocol) {
725 if (version == OFConstants.OFP_VERSION_1_0) {
726 SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
727 SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
728 PortActionBuilder settpdst = new PortActionBuilder();
729 PortNumber port = new PortNumber(settpdstaction.getPort().getValue().longValue());
730 settpdst.setPort(port);
733 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst.class);
734 actionBuilder.addAugmentation(PortAction.class, settpdst.build());
735 return actionBuilder.build();
736 } else if (version == OFConstants.OFP_VERSION_1_3) {
737 SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
738 SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
740 MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
741 matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
742 matchEntriesBuilder.setHasMask(false);
743 PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
744 int port = settpdstaction.getPort().getValue().intValue();
745 int code = 0x0f & port;
749 matchEntriesBuilder.setOxmMatchField(Icmpv4Code.class);
750 Icmpv4CodeMatchEntryBuilder icmpv4CodeMatchEntryBuilder = new Icmpv4CodeMatchEntryBuilder();
751 icmpv4CodeMatchEntryBuilder.setIcmpv4Code((short) code);
752 matchEntriesBuilder.addAugmentation(Icmpv4CodeMatchEntry.class, icmpv4CodeMatchEntryBuilder.build());
755 matchEntriesBuilder.setOxmMatchField(Icmpv6Code.class);
756 Icmpv6CodeMatchEntryBuilder icmpv6CodeMatchEntryBuilder = new Icmpv6CodeMatchEntryBuilder();
757 icmpv6CodeMatchEntryBuilder.setIcmpv6Code((short) code);
758 matchEntriesBuilder.addAugmentation(Icmpv6CodeMatchEntry.class, icmpv6CodeMatchEntryBuilder.build());
761 matchEntriesBuilder.setOxmMatchField(TcpDst.class);
762 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
763 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
766 matchEntriesBuilder.setOxmMatchField(UdpDst.class);
767 portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(port));
768 matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
770 default: LOG.warn("Unknown protocol with combination of SetDestinationPort: {}", protocol);
775 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
777 OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
778 List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
779 matchEntries.add(matchEntriesBuilder.build());
780 oxmFieldsActionBuilder.setMatchEntries(matchEntries);
782 actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
783 return actionBuilder.build();
785 LOG.error(UNKNOWN_ACTION_TYPE_VERSION, version);
789 private static Action salToOFGroupAction(
790 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
791 ActionBuilder actionBuilder) {
793 GroupActionCase groupActionCase = (GroupActionCase) action;
794 GroupAction groupAction = groupActionCase.getGroupAction();
796 GroupIdActionBuilder groupIdBuilder = new GroupIdActionBuilder();
797 groupIdBuilder.setGroupId(groupAction.getGroupId());
798 actionBuilder.setType(Group.class);
799 actionBuilder.addAugmentation(GroupIdAction.class, groupIdBuilder.build());
800 return actionBuilder.build();
803 private static Action salToOFPushAction(Integer ethernetType, ActionBuilder actionBuilder) {
804 EthertypeActionBuilder ethertypeActionBuilder = new EthertypeActionBuilder();
805 if (ethernetType != null) {
806 ethertypeActionBuilder.setEthertype(new EtherType(ethernetType));
810 actionBuilder.addAugmentation(EthertypeAction.class, ethertypeActionBuilder.build());
811 return actionBuilder.build();
814 private static Action salToOFDecMplsTtl(ActionBuilder actionBuilder) {
816 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class);
817 return emtpyAction(actionBuilder);
820 private static Action salToOFSetMplsTtl(
821 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
822 ActionBuilder actionBuilder) {
823 SetMplsTtlActionCase mplsTtlActionCase = (SetMplsTtlActionCase) action;
824 SetMplsTtlAction mplsTtlAction = mplsTtlActionCase.getSetMplsTtlAction();
826 MplsTtlActionBuilder mplsTtlActionBuilder = new MplsTtlActionBuilder();
827 mplsTtlActionBuilder.setMplsTtl(mplsTtlAction.getMplsTtl()/* SAL */);
829 actionBuilder.setType(SetMplsTtl.class);
830 actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtlActionBuilder.build());
831 return actionBuilder.build();
834 private static Action salToOFCopyTTLIIn(ActionBuilder actionBuilder) {
836 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class);
837 return emtpyAction(actionBuilder);
840 private static Action salToOFCopyTTLIOut(ActionBuilder actionBuilder) {
842 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class);
843 return emtpyAction(actionBuilder);
847 private static Action emtpyAction(ActionBuilder actionBuilder) {
848 return actionBuilder.build();
851 private static Action salToOFAction(
852 OutputActionCase outputActionCase,
853 ActionBuilder actionBuilder, short version) {
855 OutputAction outputAction = outputActionCase.getOutputAction();
856 PortActionBuilder portAction = new PortActionBuilder();
857 MaxLengthActionBuilder maxLenActionBuilder = new MaxLengthActionBuilder();
858 if (outputAction.getMaxLength() != null) {
859 maxLenActionBuilder.setMaxLength(outputAction.getMaxLength());
861 maxLenActionBuilder.setMaxLength(0);
863 actionBuilder.addAugmentation(MaxLengthAction.class, maxLenActionBuilder.build());
865 Uri uri = outputAction.getOutputNodeConnector();
867 OpenflowVersion ofVersion = OpenflowVersion.get(version);
868 Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, uri.getValue());
869 if (OpenflowPortsUtil.checkPortValidity(ofVersion, portNumber)) {
870 portAction.setPort(new PortNumber(portNumber));
872 LOG.error("Invalid Port specified " + portNumber + " for Output Action for OF version:" + ofVersion);
875 actionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
876 actionBuilder.addAugmentation(PortAction.class, portAction.build());
877 return actionBuilder.build();
882 * Method to convert OF actions associated with bucket to SAL Actions.
885 * @param ofVersion current ofp version
886 * @param actionPath TODO
887 * @return List of converted SAL Actions.
889 public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> toMDSalActions(
890 List<Action> actionList, OpenflowVersion ofVersion, ActionPath actionPath) {
892 List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> bucketActions = new ArrayList<>();
893 for (Action action : actionList) {
894 if (action.getType().equals(
895 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class)) {
896 bucketActions.add(ofToSALOutputAction(ofVersion, action));
898 } else if (action.getType().equals(
899 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class)) {
900 bucketActions.add(ofToSALGroupAction(action));
902 } else if (action.getType().equals(
903 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class)) {
904 CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder();
905 bucketActions.add(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build());
907 } else if (action.getType().equals(
908 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class)) {
909 CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder();
910 bucketActions.add(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build());
912 } else if (action.getType().equals(
913 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class)) {
914 bucketActions.add(ofToSALSetMplsTtl(action));
916 } else if (action.getType().equals(
917 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class)) {
918 DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder();
919 bucketActions.add(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build());
921 } else if (action.getType().equals(
922 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class)) {
923 bucketActions.add(ofToSALPushVlanAction(action));
925 } else if (action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)
926 || action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class)) {
927 // OF1.0 nodes will emit StripVlan and OF1.3+ will emit StripVlan/PopVlan, convert both to PopVlan for SAL
928 PopVlanActionBuilder popVlan = new PopVlanActionBuilder();
929 bucketActions.add(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build());
931 } else if (action.getType().equals(
932 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class)) {
933 bucketActions.add(ofToSALPushMplsAction(action));
935 } else if (action.getType().equals(
936 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class)) {
937 bucketActions.add(ofToSALPopMplsAction(action));
939 } else if (action.getType().equals(
940 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class)) {
941 bucketActions.add(ofToSALSetQueue(action));
943 } else if (action.getType().equals(
944 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class)) {
945 bucketActions.add(ofToSALSetNwTtl(action));
947 } else if (action.getType().equals(
948 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class)) {
949 DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder();
950 bucketActions.add(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl.build()).build());
952 } else if (action.getType().equals(
953 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class)) {
954 bucketActions.add(new SetFieldCaseBuilder().setSetField(MatchConvertorImpl.fromOFSetFieldToSALSetFieldAction(action, ofVersion))
956 } else if (action.getType().equals(
957 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class)) {
958 bucketActions.add(ofToSALPushPbbAction(action));
960 } else if (action.getType().equals(
961 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class)) {
962 PopPbbActionBuilder popPbb = new PopPbbActionBuilder();
963 bucketActions.add(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build());
965 } else if (action.getType().equals(
966 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter.class)) {
968 * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
969 * - we might also need a way on how to identify exact type of augmentation to be
970 * used as match can be bound to multiple models
972 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction =
973 ActionExtensionHelper.processAlienAction(action, ofVersion, actionPath);
974 if (processedAction != null) {
975 bucketActions.add(processedAction);
979 return bucketActions;
983 * Method converts OF Output action object to SAL Output action object.
987 * @param action org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.
988 * action.rev130731.actions.actions.list.Action
989 * @return OutputAction
991 public static OutputActionCase ofToSALOutputAction(OpenflowVersion ofVersion, Action action) {
992 OutputActionBuilder outputAction = new OutputActionBuilder();
993 PortAction port = action.getAugmentation(PortAction.class);
995 CommonPort.PortNumber protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(
996 ofVersion, port.getPort().getValue());
997 String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
998 outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
1000 LOG.error("Provided action is not OF Output action, no associated port found!");
1003 MaxLengthAction length = action.getAugmentation(MaxLengthAction.class);
1004 if (length != null) {
1005 outputAction.setMaxLength(length.getMaxLength());
1007 LOG.error("Provided action is not OF Output action, no associated length found!");
1010 return new OutputActionCaseBuilder().setOutputAction(outputAction.build()).build();
1014 * Method converts OF GroupAction object to SAL GroupAction object
1017 * @return GroupAction
1019 public static GroupActionCase ofToSALGroupAction(Action action) {
1021 GroupActionBuilder groupAction = new GroupActionBuilder();
1023 GroupIdAction groupId = action.getAugmentation(GroupIdAction.class);
1024 groupAction.setGroupId(groupId.getGroupId());
1026 return new GroupActionCaseBuilder().setGroupAction(groupAction.build()).build();
1030 * Method converts OF SetMplsTTL action object to SAL SetMplsTTL action
1036 public static SetMplsTtlActionCase ofToSALSetMplsTtl(Action action) {
1038 SetMplsTtlActionBuilder mplsTtlAction = new SetMplsTtlActionBuilder();
1039 MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class);
1040 mplsTtlAction.setMplsTtl(mplsTtl.getMplsTtl());
1041 return new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(mplsTtlAction.build()).build();
1045 * Method converts OF Pushvlan action to SAL PushVlan action.
1048 * @return PushVlanAction
1050 public static PushVlanActionCase ofToSALPushVlanAction(Action action) {
1052 PushVlanActionBuilder pushVlanAction = new PushVlanActionBuilder();
1054 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1055 pushVlanAction.setEthernetType(etherType.getEthertype().getValue());
1057 return new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build();
1061 * Method converts OF PushMpls action to SAL PushMpls action.
1064 * @return PushMplsAction
1066 public static PushMplsActionCase ofToSALPushMplsAction(Action action) {
1068 PushMplsActionBuilder pushMplsAction = new PushMplsActionBuilder();
1070 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1071 pushMplsAction.setEthernetType(etherType.getEthertype().getValue());
1073 return new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build();
1077 * Method converts OF PopMpls action to SAL PopMpls action.
1080 * @return PopMplsActionCase
1082 public static PopMplsActionCase ofToSALPopMplsAction(Action action) {
1084 PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder();
1086 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1087 popMplsAction.setEthernetType(etherType.getEthertype().getValue());
1089 return new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build();
1093 * Method converts OF SetQueue action to SAL SetQueue action.
1096 * @return SetQueueAction
1098 public static SetQueueActionCase ofToSALSetQueue(Action action) {
1100 SetQueueActionBuilder setQueueAction = new SetQueueActionBuilder();
1102 QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
1103 setQueueAction.setQueueId(queueId.getQueueId());
1104 return new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build();
1108 * Method converts OF SetNwTtl action to SAL SetNwTtl action.
1111 * @return SetNwTtlAction
1113 public static SetNwTtlActionCase ofToSALSetNwTtl(Action action) {
1115 SetNwTtlActionBuilder setNwTtl = new SetNwTtlActionBuilder();
1116 NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class);
1117 setNwTtl.setNwTtl(nwTtl.getNwTtl());
1119 return new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtl.build()).build();
1123 * Method converts OF Pushvlan action to SAL PushVlan action.
1126 * @return PushVlanAction
1128 public static PushPbbActionCase ofToSALPushPbbAction(Action action) {
1130 PushPbbActionBuilder pushPbbAction = new PushPbbActionBuilder();
1132 EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1133 pushPbbAction.setEthernetType(etherType.getEthertype().getValue());
1135 return new PushPbbActionCaseBuilder().setPushPbbAction(pushPbbAction.build()).build();
1138 //TODO make a model in YANG for protocols
1139 /*private enum IPProtocols {
1145 private int protocol;
1147 private static Map<Integer, IPProtocols> valueMap;
1149 valueMap = new HashMap<>();
1150 for(IPProtocols protocols : IPProtocols.values()) {
1151 valueMap.put(protocols.protocol, protocols);
1155 private IPProtocols(int value) {
1156 this.protocol = value;
1159 private byte getValue() {
1160 return (byte) this.protocol;
1163 private Short getShortValue() {
1164 return new Short((short) protocol);
1167 private IPProtocols fromProtocolNum(Short protocolNum) {
1168 return valueMap.get(protocolNum);