Merge "BUG-1421: VLAN tag"
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / ActionConvertor.java
1 /**
2  * Copyright (c) 2014 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
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
7  *
8  * Contributor: hema.gopalkrishnan@ericsson.com
9  */
10 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
11
12 import com.google.common.collect.Ordering;
13 import org.opendaylight.openflowplugin.extension.api.ConverterExtensionKey;
14 import org.opendaylight.openflowplugin.extension.api.ConvertorActionToOFJava;
15 import org.opendaylight.openflowplugin.extension.api.ConvertorToOFJava;
16 import org.opendaylight.openflowplugin.extension.api.TypeVersionKey;
17 import org.opendaylight.openflowplugin.extension.api.path.ActionPath;
18 import org.opendaylight.openflowplugin.api.OFConstants;
19 import org.opendaylight.openflowplugin.openflow.md.core.extension.ActionExtensionHelper;
20 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwDstReactor;
21 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.ActionSetNwSrcReactor;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator;
23 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchConvertorImpl;
24 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
25 import org.opendaylight.openflowplugin.openflow.md.core.session.OFSessionUtil;
26 import org.opendaylight.openflowplugin.openflow.md.util.InventoryDataServiceUtil;
27 import org.opendaylight.openflowplugin.openflow.md.util.OpenflowPortsUtil;
28 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
30 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCase;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlInCaseBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCase;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.CopyTtlOutCaseBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCase;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecMplsTtlCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCase;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.DecNwTtlCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCaseBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopPbbActionCaseBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCase;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopVlanActionCaseBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCase;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushMplsActionCaseBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCase;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushPbbActionCaseBuilder;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCase;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlDstActionCase;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetDlSrcActionCase;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCase;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCaseBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTosActionCase;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCase;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwTtlActionCaseBuilder;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCase;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetQueueActionCaseBuilder;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanPcpActionCase;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.StripVlanActionCase;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.in._case.CopyTtlInBuilder;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.copy.ttl.out._case.CopyTtlOutBuilder;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.mpls.ttl._case.DecMplsTtlBuilder;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.dec.nw.ttl._case.DecNwTtlBuilder;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupAction;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputAction;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.pbb.action._case.PopPbbActionBuilder;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.vlan.action._case.PopVlanActionBuilder;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanAction;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.dst.action._case.SetDlDstAction;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.dl.src.action._case.SetDlSrcAction;
90 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlAction;
91 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.mpls.ttl.action._case.SetMplsTtlActionBuilder;
92 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.tos.action._case.SetNwTosAction;
93 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.nw.ttl.action._case.SetNwTtlActionBuilder;
94 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueAction;
95 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.queue.action._case.SetQueueActionBuilder;
96 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstAction;
97 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcAction;
98 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdAction;
99 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.pcp.action._case.SetVlanPcpAction;
100 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.CommonPort;
101 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressAction;
102 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.DlAddressActionBuilder;
103 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeAction;
104 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.EthertypeActionBuilder;
105 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdAction;
106 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.GroupIdActionBuilder;
107 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthAction;
108 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MaxLengthActionBuilder;
109 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlAction;
110 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.MplsTtlActionBuilder;
111 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosAction;
112 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTosActionBuilder;
113 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlAction;
114 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.NwTtlActionBuilder;
115 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsAction;
116 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.OxmFieldsActionBuilder;
117 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortAction;
118 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortActionBuilder;
119 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntry;
120 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.PortMatchEntryBuilder;
121 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdAction;
122 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.QueueIdActionBuilder;
123 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpAction;
124 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanPcpActionBuilder;
125 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidAction;
126 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidActionBuilder;
127 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntry;
128 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.VlanVidMatchEntryBuilder;
129 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group;
130 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls;
131 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb;
132 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan;
133 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls;
134 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb;
135 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan;
136 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl;
137 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl;
138 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue;
139 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
140 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.ActionBuilder;
141 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.EtherType;
142 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
143 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthDst;
144 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.EthSrc;
145 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
146 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpDst;
147 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.TcpSrc;
148 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.VlanVid;
149 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntries;
150 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.oxm.fields.grouping.MatchEntriesBuilder;
151 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.ExtensionKey;
152 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.GeneralExtensionGrouping;
153 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.general.rev140714.general.extension.grouping.Extension;
154 import org.slf4j.Logger;
155 import org.slf4j.LoggerFactory;
156
157 import java.math.BigInteger;
158 import java.util.ArrayList;
159 import java.util.List;
160
161 /**
162  * @author usha@ericsson Action List:This class takes data from SAL layer and
163  *         converts into OF Data
164  * @author avishnoi@in.ibm.com Added convertor for OF bucket actions to SAL
165  *         actions
166  */
167 public final class ActionConvertor {
168     private static final Logger logger = LoggerFactory.getLogger(ActionConvertor.class);
169
170     private ActionConvertor() {
171         // NOOP
172     }
173
174     /**
175      * Translates SAL actions into OF Library actions
176      *
177      * @param actions    SAL actions
178      * @param version    Openflow protocol version used
179      * @param datapathid
180      * @return OF Library actions
181      */
182     public static List<Action> getActions(
183             List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actions,
184             short version, BigInteger datapathid) {
185         List<Action> actionsList = new ArrayList<>();
186         Action ofAction;
187
188         actions = Ordering.from(OrderComparator.<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action>toInstance())
189             .sortedCopy(actions);
190
191         for (int actionItem = 0; actionItem < actions.size(); actionItem++) {
192             ofAction = null;
193             ActionBuilder actionBuilder = new ActionBuilder();
194
195             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action = actions.get(
196                     actionItem).getAction();
197
198             if (action instanceof OutputActionCase)
199                 ofAction = salToOFOutputAction(action, actionBuilder, version);
200             else if (action instanceof GroupActionCase)
201                 ofAction = SalToOFGroupAction(action, actionBuilder);
202             else if (action instanceof CopyTtlOutCase)
203                 ofAction = SalToOFCopyTTLIOut(actionBuilder);
204             else if (action instanceof CopyTtlInCase)
205                 ofAction = SalToOFCopyTTLIIn(actionBuilder);
206             else if (action instanceof SetMplsTtlActionCase)
207                 ofAction = SalToOFSetMplsTtl(action, actionBuilder);
208             else if (action instanceof DecMplsTtlCase)
209                 ofAction = SalToOFDecMplsTtl(actionBuilder);
210             else if (action instanceof PushVlanActionCase)
211                 ofAction = SalToOFPushVlanAction(action, actionBuilder, version);
212             else if (action instanceof PopVlanActionCase)
213                 ofAction = (version == OFConstants.OFP_VERSION_1_0) ?
214                     SalToOFStripVlan(actionBuilder, version)
215                         : SalToOFPopVlan(actionBuilder);
216             else if (action instanceof PushMplsActionCase)
217                 ofAction = SalToOFPushMplsAction(action, actionBuilder);
218             else if (action instanceof PopMplsActionCase)
219                 ofAction = SalToOFPopMpls(action, actionBuilder);
220             else if (action instanceof SetQueueActionCase)
221                 ofAction = SalToOFSetQueue(action, actionBuilder);
222             else if (action instanceof SetNwTtlActionCase)
223                 ofAction = SalToOFSetNwTtl(action, actionBuilder);
224             else if (action instanceof DecNwTtlCase)
225                 ofAction = SalToOFDecNwTtl(actionBuilder);
226             else if (action instanceof SetFieldCase)
227                 ofAction = SalToOFSetField(action, actionBuilder, version, datapathid);
228             else if (action instanceof PushPbbActionCase)
229                 ofAction = SalToOFPushPbbAction(action, actionBuilder);
230             else if (action instanceof PopPbbActionCase)
231                 ofAction = SalToOFPopPBB(actionBuilder);
232
233                 // 1.0 Actions
234             else if (action instanceof SetVlanIdActionCase) {
235                 /*if (version == OFConstants.OFP_VERSION_1_0) {
236
237                 } else {
238                     List<Action> setVlanIdActionsList = convertToOF13(action, actionBuilder);
239                     actionsList.addAll(setVlanIdActionsList);
240                 }*/
241                 ofAction = SalToOFSetVlanId(action, actionBuilder, version);
242             }
243             else if (action instanceof SetVlanPcpActionCase)
244                 ofAction = SalToOFSetVlanpcp(action, actionBuilder, version);
245             else if (action instanceof StripVlanActionCase)
246                 ofAction = SalToOFStripVlan(actionBuilder, version);
247             else if (action instanceof SetDlSrcActionCase)
248                 ofAction = SalToOFSetDlSrc(action, actionBuilder, version);
249             else if (action instanceof SetDlDstActionCase)
250                 ofAction = SalToOFSetDlDst(action, actionBuilder, version);
251             else if (action instanceof SetNwSrcActionCase)
252                 ofAction = SalToOFSetNwSrc(action, actionBuilder, version);
253             else if (action instanceof SetNwDstActionCase)
254                 ofAction = SalToOFSetNwDst(action, actionBuilder, version);
255             else if (action instanceof SetTpSrcActionCase)
256                 ofAction = SalToOFSetTpSrc(action, actionBuilder, version);
257             else if (action instanceof SetTpDstActionCase)
258                 ofAction = SalToOFSetTpDst(action, actionBuilder, version);
259             else if (action instanceof SetNwTosActionCase)
260                 ofAction = SalToOFSetNwTos(action, actionBuilder, version);
261             else if (action instanceof GeneralExtensionGrouping) {
262                 
263                 /**
264                  * TODO: EXTENSION PROPOSAL (action, MD-SAL to OFJava)
265                  * - we might need sessionContext as converter input
266                  * 
267                  */
268                 
269                 GeneralExtensionGrouping extensionCaseGrouping = (GeneralExtensionGrouping) action;
270                 Extension extAction = extensionCaseGrouping.getExtension();
271                 ConverterExtensionKey<? extends ExtensionKey> key = new ConverterExtensionKey<>(extensionCaseGrouping.getExtensionKey(), version);
272                 ConvertorToOFJava<Action> convertor = 
273                         OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
274                 if (convertor != null) {
275                     ofAction = convertor.convert(extAction);
276                 }
277             } else {
278                 // try vendor codecs
279                 TypeVersionKey<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> key =
280                         new TypeVersionKey<>(
281                                 (Class<? extends org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action>) action.getImplementedInterface(),
282                                 version);
283                 ConvertorActionToOFJava<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action, Action> convertor = 
284                         OFSessionUtil.getExtensionConvertorProvider().getConverter(key);
285                 if (convertor != null) {
286                     ofAction = convertor.convert(action);
287                 }
288             }
289             
290             if (ofAction != null) {
291                 actionsList.add(ofAction);
292             }
293         }
294         return actionsList;
295     }
296
297     private static Action SalToOFSetField(
298             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
299             ActionBuilder actionBuilder, short version, BigInteger datapathid) {
300
301         SetFieldCase setFieldCase = (SetFieldCase) action;
302         org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match match =
303             setFieldCase.getSetField();
304
305         if (version == OFConstants.OFP_VERSION_1_0) {
306             // pushvlan +setField can be called to configure 1.0 switches via MDSAL app
307             if (match.getVlanMatch() != null) {
308                 VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
309                 vlanidActionBuilder.setVlanVid(match.getVlanMatch().getVlanId().getVlanId().getValue());
310                 actionBuilder.setType(
311                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
312                 actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
313                 return actionBuilder.build();
314             } else {
315                 return emtpyAction(actionBuilder);
316             }
317
318         } else {
319             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
320             MatchReactor.getInstance().convert(match, version, oxmFieldsActionBuilder, datapathid);
321
322             actionBuilder.setType(
323                 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
324
325             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
326             return actionBuilder.build();
327         }
328
329     }
330
331     private static Action SalToOFDecNwTtl(ActionBuilder actionBuilder) {
332         actionBuilder
333                 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class);
334         return emtpyAction(actionBuilder);
335     }
336
337     private static Action SalToOFPushMplsAction(
338             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
339             ActionBuilder actionBuilder) {
340         PushMplsActionCase pushMplsActionCase = (PushMplsActionCase) action;
341         actionBuilder.setType(PushMpls.class);
342
343         return SalToOFPushAction(pushMplsActionCase.getPushMplsAction().getEthernetType(), actionBuilder);
344     }
345
346     private static Action SalToOFPushPbbAction(
347             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
348             ActionBuilder actionBuilder) {
349         PushPbbActionCase pushPbbActionCase = (PushPbbActionCase) action;
350         actionBuilder.setType(PushPbb.class);
351
352         return SalToOFPushAction(pushPbbActionCase.getPushPbbAction().getEthernetType(), actionBuilder);
353     }
354
355     private static Action SalToOFPushVlanAction(
356             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
357             ActionBuilder actionBuilder, short version) {
358         if (version == OFConstants.OFP_VERSION_1_0) {
359             // if client configure openflow 1.0 switch as a openflow 1.3 switch using openflow 1.3 instructions
360             // then we can ignore PUSH_VLAN as set-vlan-id will push a vlan header if not present
361             return null;
362         }
363
364         PushVlanActionCase pushVlanActionCase = (PushVlanActionCase) action;
365         PushVlanAction pushVlanAction = pushVlanActionCase.getPushVlanAction();
366         actionBuilder.setType(PushVlan.class);
367
368         return SalToOFPushAction(pushVlanAction.getEthernetType(), actionBuilder);
369     }
370
371     private static Action SalToOFSetNwTtl(
372             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
373             ActionBuilder actionBuilder) {
374         SetNwTtlActionCase nwTtlActionCase = (SetNwTtlActionCase) action;
375         NwTtlActionBuilder nwTtlActionBuilder = new NwTtlActionBuilder();
376         nwTtlActionBuilder.setNwTtl(nwTtlActionCase.getSetNwTtlAction().getNwTtl());
377         actionBuilder.setType(SetNwTtl.class);
378         actionBuilder.addAugmentation(NwTtlAction.class, nwTtlActionBuilder.build());
379         return actionBuilder.build();
380     }
381
382     private static Action SalToOFSetQueue(
383             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
384             ActionBuilder actionBuilder) {
385         SetQueueActionCase setQueueActionCase = (SetQueueActionCase) action;
386         SetQueueAction setQueueAction = setQueueActionCase.getSetQueueAction();
387
388         QueueIdActionBuilder queueIdActionBuilder = new QueueIdActionBuilder();
389         queueIdActionBuilder.setQueueId(setQueueAction.getQueueId());
390         actionBuilder.setType(SetQueue.class);
391         actionBuilder.addAugmentation(QueueIdAction.class, queueIdActionBuilder.build());
392
393         return actionBuilder.build();
394     }
395
396     private static Action SalToOFPopMpls(
397             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
398             ActionBuilder actionBuilder) {
399         PopMplsActionCase popMplsActionCase = (PopMplsActionCase) action;
400         actionBuilder.setType(PopMpls.class);
401
402         return SalToOFPushAction(popMplsActionCase.getPopMplsAction().getEthernetType(), actionBuilder);
403     }
404
405     private static Action SalToOFPopVlan(ActionBuilder actionBuilder) {
406         actionBuilder.setType(PopVlan.class);
407         return emtpyAction(actionBuilder);
408     }
409
410     private static Action SalToOFPopPBB(ActionBuilder actionBuilder) {
411         actionBuilder.setType(PopPbb.class);
412         return emtpyAction(actionBuilder);
413     }
414
415     // set-vlan-id (1.0 feature) can be called on  1.3 switches as well using ADSAL apis
416     private static Action SalToOFSetVlanId(
417             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
418             ActionBuilder actionBuilder, short version) {
419
420         SetVlanIdActionCase setvlanidcase = (SetVlanIdActionCase) action;
421         SetVlanIdAction setvlanidaction = setvlanidcase.getSetVlanIdAction();
422
423         if (version == OFConstants.OFP_VERSION_1_0) {
424
425             VlanVidActionBuilder vlanidActionBuilder = new VlanVidActionBuilder();
426             vlanidActionBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
427             actionBuilder
428                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanVid.class);
429             actionBuilder.addAugmentation(VlanVidAction.class, vlanidActionBuilder.build());
430             return actionBuilder.build();
431
432         } else if (version >= OFConstants.OFP_VERSION_1_3) {
433             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
434             actionBuilder
435                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
436             List<MatchEntries> matchEntriesList = new ArrayList<>();
437             MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
438             matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
439             matchEntriesBuilder.setOxmMatchField(VlanVid.class);
440             VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
441             vlanVidBuilder.setCfiBit(true);
442             vlanVidBuilder.setVlanVid(setvlanidaction.getVlanId().getValue());
443             matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
444             matchEntriesBuilder.setHasMask(false);
445             matchEntriesList.add(matchEntriesBuilder.build());
446             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
447             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
448             return actionBuilder.build();
449         } else {
450             logger.error("Unknown Action Type for the Version", version);
451             return null;
452         }
453     }
454
455     private static Action SalToOFSetVlanpcp(
456             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
457             ActionBuilder actionBuilder, short version) {
458
459         SetVlanPcpActionCase setvlanpcpcase = (SetVlanPcpActionCase) action;
460         SetVlanPcpAction setvlanpcpaction = setvlanpcpcase.getSetVlanPcpAction();
461
462         if (version == OFConstants.OFP_VERSION_1_0) {
463             VlanPcpActionBuilder vlanpcpActionBuilder = new VlanPcpActionBuilder();
464             vlanpcpActionBuilder.setVlanPcp(setvlanpcpaction.getVlanPcp().getValue());
465             actionBuilder
466                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetVlanPcp.class);
467             actionBuilder.addAugmentation(VlanPcpAction.class, vlanpcpActionBuilder.build());
468             return actionBuilder.build();
469         } else if (version >= OFConstants.OFP_VERSION_1_3) {
470             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
471             actionBuilder
472                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
473             List<MatchEntries> matchEntriesList = new ArrayList<>();
474             matchEntriesList.add(MatchConvertorImpl.toOfVlanPcp(setvlanpcpaction.getVlanPcp()));
475             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
476             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
477             return actionBuilder.build();
478         } else {
479             logger.error("Unknown Action Type for the Version", version);
480             return null;
481         }
482     }
483
484     private static Action SalToOFStripVlan(ActionBuilder actionBuilder, short version) {
485         if (version == OFConstants.OFP_VERSION_1_0) {
486             actionBuilder
487                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class);
488
489             return emtpyAction(actionBuilder);
490         } else if (version >= OFConstants.OFP_VERSION_1_3) {
491             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
492             actionBuilder
493                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
494             List<MatchEntries> matchEntriesList = new ArrayList<>();
495             MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
496             matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
497             matchEntriesBuilder.setOxmMatchField(VlanVid.class);
498             VlanVidMatchEntryBuilder vlanVidBuilder = new VlanVidMatchEntryBuilder();
499             vlanVidBuilder.setCfiBit(true);
500             vlanVidBuilder.setVlanVid(0x0000);
501             matchEntriesBuilder.addAugmentation(VlanVidMatchEntry.class, vlanVidBuilder.build());
502             matchEntriesBuilder.setHasMask(false);
503             matchEntriesList.add(matchEntriesBuilder.build());
504             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
505             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
506             return actionBuilder.build();
507         } else {
508             logger.error("Unknown Action Type for the Version", version);
509             return null;
510         }
511     }
512
513     private static Action SalToOFSetDlSrc(
514             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
515             ActionBuilder actionBuilder, short version) {
516
517         SetDlSrcActionCase setdlsrccase = (SetDlSrcActionCase) action;
518         SetDlSrcAction setdlsrcaction = setdlsrccase.getSetDlSrcAction();
519
520         if (version == OFConstants.OFP_VERSION_1_0) {
521             DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
522             dladdressactionbuilder.setDlAddress(setdlsrcaction.getAddress());
523             actionBuilder
524                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlSrc.class);
525             actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
526             return actionBuilder.build();
527         } else if (version >= OFConstants.OFP_VERSION_1_3) {
528             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
529             actionBuilder
530                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
531             List<MatchEntries> matchEntriesList = new ArrayList<>();
532             matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthSrc.class, setdlsrcaction.getAddress(), null));
533             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
534             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
535             return actionBuilder.build();
536         } else {
537             logger.error("Unknown Action Type for the Version", version);
538             return null;
539         }
540     }
541
542     private static Action SalToOFSetDlDst(
543             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
544             ActionBuilder actionBuilder, short version) {
545
546         SetDlDstActionCase setdldstcase = (SetDlDstActionCase) action;
547         SetDlDstAction setdldstaction = setdldstcase.getSetDlDstAction();
548
549         if (version == OFConstants.OFP_VERSION_1_0) {
550             DlAddressActionBuilder dladdressactionbuilder = new DlAddressActionBuilder();
551             dladdressactionbuilder.setDlAddress(setdldstaction.getAddress());
552             actionBuilder
553                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetDlDst.class);
554             actionBuilder.addAugmentation(DlAddressAction.class, dladdressactionbuilder.build());
555             return actionBuilder.build();
556         } else if (version >= OFConstants.OFP_VERSION_1_3) {
557             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
558             actionBuilder
559                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
560             List<MatchEntries> matchEntriesList = new ArrayList<>();
561             matchEntriesList.add(MatchConvertorImpl.toOfMacAddress(EthDst.class, setdldstaction.getAddress(), null));
562             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
563             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
564             return actionBuilder.build();
565         } else {
566             logger.error("Unknown Action Type for the Version", version);
567             return null;
568         }
569     }
570
571     protected static Action SalToOFSetNwSrc(
572             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
573             ActionBuilder actionBuilder, short version) {
574
575         try {
576             ActionSetNwSrcReactor.getInstance().convert((SetNwSrcActionCase) action, version, actionBuilder, null);
577         } catch (Exception e) {
578             logger.error(e.getMessage(), e);
579             return null;
580         }
581
582         return actionBuilder.build();
583     }
584
585     protected static Action SalToOFSetNwDst(
586             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
587             ActionBuilder actionBuilder, short version) {
588
589         try {
590             ActionSetNwDstReactor.getInstance().convert((SetNwDstActionCase) action, version, actionBuilder, null);
591         } catch (Exception e) {
592             logger.error(e.getMessage(), e);
593             return null;
594         }
595
596         return actionBuilder.build();
597     }
598
599     private static Action SalToOFSetNwTos(
600             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
601             ActionBuilder actionBuilder, short version) {
602
603         SetNwTosActionCase setnwtoscase = (SetNwTosActionCase) action;
604         SetNwTosAction setnwtosaction = setnwtoscase.getSetNwTosAction();
605
606         if (version == OFConstants.OFP_VERSION_1_0) {
607             NwTosActionBuilder tosBuilder = new NwTosActionBuilder();
608             tosBuilder.setNwTos(setnwtosaction.getTos().shortValue());
609             actionBuilder.addAugmentation(NwTosAction.class, tosBuilder.build());
610             actionBuilder
611                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTos.class);
612
613             return actionBuilder.build();
614         } else if (version >= OFConstants.OFP_VERSION_1_3) {
615             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
616             actionBuilder
617                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
618             List<MatchEntries> matchEntriesList = new ArrayList<>();
619             matchEntriesList.add(MatchConvertorImpl.toOfIpDscp(new Dscp(setnwtosaction.getTos().shortValue())));
620             oxmFieldsActionBuilder.setMatchEntries(matchEntriesList);
621             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
622             return actionBuilder.build();
623         } else {
624             logger.error("Unknown Action Type for the Version", version);
625             return null;
626         }
627
628     }
629
630     private static Action SalToOFSetTpSrc(
631             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
632             ActionBuilder actionBuilder, short version) {
633
634         if (version == OFConstants.OFP_VERSION_1_0) {
635             SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
636             SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
637
638             PortActionBuilder settpsrc = new PortActionBuilder();
639             PortNumber port = new PortNumber(settpsrcaction.getPort().getValue().longValue());
640             settpsrc.setPort(port);
641
642             actionBuilder
643                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpSrc.class);
644             actionBuilder.addAugmentation(PortAction.class, settpsrc.build());
645             return actionBuilder.build();
646         } else if (version == OFConstants.OFP_VERSION_1_3) {
647             SetTpSrcActionCase settpsrccase = (SetTpSrcActionCase) action;
648             SetTpSrcAction settpsrcaction = settpsrccase.getSetTpSrcAction();
649             
650             MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
651             matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
652             matchEntriesBuilder.setHasMask(false);
653             matchEntriesBuilder.setOxmMatchField(TcpSrc.class);
654             PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
655             portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpsrcaction.getPort().getValue().intValue()));
656             matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
657             
658             actionBuilder
659             .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
660             
661             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
662             List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
663             matchEntries.add(matchEntriesBuilder.build());
664             oxmFieldsActionBuilder.setMatchEntries(matchEntries);
665
666             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
667             return actionBuilder.build();
668         }
669         logger.error("Unknown Action Type for the Version", version);
670         return null;
671     }
672
673     private static Action SalToOFSetTpDst(
674             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
675             ActionBuilder actionBuilder, short version) {
676
677         if (version == OFConstants.OFP_VERSION_1_0) {
678             SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
679             SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
680             PortActionBuilder settpdst = new PortActionBuilder();
681             PortNumber port = new PortNumber(settpdstaction.getPort().getValue().longValue());
682             settpdst.setPort(port);
683
684             actionBuilder
685                     .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetTpDst.class);
686             actionBuilder.addAugmentation(PortAction.class, settpdst.build());
687             return actionBuilder.build();
688         } else if (version == OFConstants.OFP_VERSION_1_3) {
689             SetTpDstActionCase settpdstcase = (SetTpDstActionCase) action;
690             SetTpDstAction settpdstaction = settpdstcase.getSetTpDstAction();
691             
692             MatchEntriesBuilder matchEntriesBuilder = new MatchEntriesBuilder();
693             matchEntriesBuilder.setOxmClass(OpenflowBasicClass.class);
694             matchEntriesBuilder.setHasMask(false);
695             matchEntriesBuilder.setOxmMatchField(TcpDst.class);
696             PortMatchEntryBuilder portMatchEntryBuilder = new PortMatchEntryBuilder();
697             portMatchEntryBuilder.setPort(new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber(settpdstaction.getPort().getValue().intValue()));
698             matchEntriesBuilder.addAugmentation(PortMatchEntry.class, portMatchEntryBuilder.build());
699             
700             actionBuilder
701             .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class);
702             
703             OxmFieldsActionBuilder oxmFieldsActionBuilder = new OxmFieldsActionBuilder();
704             List<MatchEntries> matchEntries = new ArrayList<MatchEntries>();
705             matchEntries.add(matchEntriesBuilder.build());
706             oxmFieldsActionBuilder.setMatchEntries(matchEntries);
707
708             actionBuilder.addAugmentation(OxmFieldsAction.class, oxmFieldsActionBuilder.build());
709             return actionBuilder.build();
710         }
711         logger.error("Unknown Action Type for the Version", version);
712         return null;
713     }
714
715     private static Action SalToOFGroupAction(
716             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
717             ActionBuilder actionBuilder) {
718
719         GroupActionCase groupActionCase = (GroupActionCase) action;
720         GroupAction groupAction = groupActionCase.getGroupAction();
721
722         GroupIdActionBuilder groupIdBuilder = new GroupIdActionBuilder();
723         groupIdBuilder.setGroupId(groupAction.getGroupId());
724         actionBuilder.setType(Group.class);
725         actionBuilder.addAugmentation(GroupIdAction.class, groupIdBuilder.build());
726         return actionBuilder.build();
727     }
728
729     private static Action SalToOFPushAction(Integer ethernetType, ActionBuilder actionBuilder) {
730         EthertypeActionBuilder ethertypeActionBuilder = new EthertypeActionBuilder();
731         if (ethernetType != null) {
732             ethertypeActionBuilder.setEthertype(new EtherType(ethernetType));
733         }
734
735         /* OF */
736         actionBuilder.addAugmentation(EthertypeAction.class, ethertypeActionBuilder.build());
737         return actionBuilder.build();
738     }
739
740     private static Action SalToOFDecMplsTtl(ActionBuilder actionBuilder) {
741         actionBuilder
742                 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class);
743         return emtpyAction(actionBuilder);
744     }
745
746     private static Action SalToOFSetMplsTtl(
747             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
748             ActionBuilder actionBuilder) {
749         SetMplsTtlActionCase mplsTtlActionCase = (SetMplsTtlActionCase) action;
750         SetMplsTtlAction mplsTtlAction = mplsTtlActionCase.getSetMplsTtlAction();
751
752         MplsTtlActionBuilder mplsTtlActionBuilder = new MplsTtlActionBuilder();
753         mplsTtlActionBuilder.setMplsTtl(mplsTtlAction.getMplsTtl()/* SAL */);
754         /* OF */
755         actionBuilder.setType(SetMplsTtl.class);
756         actionBuilder.addAugmentation(MplsTtlAction.class, mplsTtlActionBuilder.build());
757         return actionBuilder.build();
758     }
759
760     private static Action SalToOFCopyTTLIIn(ActionBuilder actionBuilder) {
761         actionBuilder
762                 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class);
763         return emtpyAction(actionBuilder);
764     }
765
766     private static Action SalToOFCopyTTLIOut(ActionBuilder actionBuilder) {
767         actionBuilder
768                 .setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class);
769         return emtpyAction(actionBuilder);
770
771     }
772
773     private static Action emtpyAction(ActionBuilder actionBuilder) {
774         return actionBuilder.build();
775     }
776
777     private static Action salToOFOutputAction(
778             org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action action,
779             ActionBuilder actionBuilder, short version) {
780
781         OutputActionCase outputActionCase = ((OutputActionCase) action);
782         OutputAction outputAction = outputActionCase.getOutputAction();
783         PortActionBuilder portAction = new PortActionBuilder();
784         MaxLengthActionBuilder maxLenActionBuilder = new MaxLengthActionBuilder();
785         if (outputAction.getMaxLength() != null) {
786             maxLenActionBuilder.setMaxLength(outputAction.getMaxLength());
787         } else {
788             maxLenActionBuilder.setMaxLength(0);
789         }
790         actionBuilder.addAugmentation(MaxLengthAction.class, maxLenActionBuilder.build());
791
792         Uri uri = outputAction.getOutputNodeConnector();
793
794         OpenflowVersion ofVersion = OpenflowVersion.get(version);
795         Long portNumber = InventoryDataServiceUtil.portNumberfromNodeConnectorId(ofVersion, uri.getValue());
796         if (OpenflowPortsUtil.checkPortValidity(ofVersion, portNumber)) {
797             portAction.setPort(new PortNumber(portNumber));
798         } else {
799             logger.error("Invalid Port specified " + portNumber + " for Output Action for OF version:" + ofVersion);
800         }
801
802         actionBuilder.setType(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class);
803         actionBuilder.addAugmentation(PortAction.class, portAction.build());
804         return actionBuilder.build();
805
806     }
807
808     /**
809      * Method to convert OF actions associated with bucket to SAL Actions.
810      *
811      * @param actionList
812      * @param ofVersion  current ofp version
813      * @param actionPath TODO
814      * @return List of converted SAL Actions.
815      */
816     public static List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> toMDSalActions(
817             List<Action> actionList, OpenflowVersion ofVersion, ActionPath actionPath) {
818
819         List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action> bucketActions = new ArrayList<>();
820         for (Action action : actionList) {
821             if (action.getType().equals(
822                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Output.class)) {
823                 bucketActions.add(ofToSALOutputAction(ofVersion, action));
824
825             } else if (action.getType().equals(
826                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Group.class)) {
827                 bucketActions.add(ofToSALGroupAction(action));
828
829             } else if (action.getType().equals(
830                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlOut.class)) {
831                 CopyTtlOutBuilder copyTtlOutaction = new CopyTtlOutBuilder();
832                 bucketActions.add(new CopyTtlOutCaseBuilder().setCopyTtlOut(copyTtlOutaction.build()).build());
833
834             } else if (action.getType().equals(
835                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.CopyTtlIn.class)) {
836                 CopyTtlInBuilder copyTtlInaction = new CopyTtlInBuilder();
837                 bucketActions.add(new CopyTtlInCaseBuilder().setCopyTtlIn(copyTtlInaction.build()).build());
838
839             } else if (action.getType().equals(
840                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetMplsTtl.class)) {
841                 bucketActions.add(ofToSALSetMplsTtl(action));
842
843             } else if (action.getType().equals(
844                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecMplsTtl.class)) {
845                 DecMplsTtlBuilder decMplsTtl = new DecMplsTtlBuilder();
846                 bucketActions.add(new DecMplsTtlCaseBuilder().setDecMplsTtl(decMplsTtl.build()).build());
847
848             } else if (action.getType().equals(
849                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushVlan.class)) {
850                 bucketActions.add(ofToSALPushVlanAction(action));
851
852             } else if (action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopVlan.class)
853                     || action.getType().equals(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.StripVlan.class)) {
854                 // OF1.0 nodes will emit StripVlan and OF1.3+ will emit StripVlan/PopVlan, convert both to PopVlan for SAL
855                 PopVlanActionBuilder popVlan = new PopVlanActionBuilder();
856                 bucketActions.add(new PopVlanActionCaseBuilder().setPopVlanAction(popVlan.build()).build());
857
858             } else if (action.getType().equals(
859                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushMpls.class)) {
860                 bucketActions.add(ofToSALPushMplsAction(action));
861
862             } else if (action.getType().equals(
863                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopMpls.class)) {
864                 bucketActions.add(ofToSALPopMplsAction(action));
865
866             } else if (action.getType().equals(
867                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetQueue.class)) {
868                 bucketActions.add(ofToSALSetQueue(action));
869
870             } else if (action.getType().equals(
871                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetNwTtl.class)) {
872                 bucketActions.add(ofToSALSetNwTtl(action));
873
874             } else if (action.getType().equals(
875                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.DecNwTtl.class)) {
876                 DecNwTtlBuilder decNwTtl = new DecNwTtlBuilder();
877                 bucketActions.add(new DecNwTtlCaseBuilder().setDecNwTtl(decNwTtl.build()).build());
878
879             } else if (action.getType().equals(
880                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField.class)) {
881                 bucketActions.add(new SetFieldCaseBuilder().setSetField(MatchConvertorImpl.fromOFSetFieldToSALSetFieldAction(action, ofVersion))
882                         .build());
883             } else if (action.getType().equals(
884                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PushPbb.class)) {
885                 bucketActions.add(ofToSALPushPbbAction(action));
886
887             } else if (action.getType().equals(
888                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.PopPbb.class)) {
889                 PopPbbActionBuilder popPbb = new PopPbbActionBuilder();
890                 bucketActions.add(new PopPbbActionCaseBuilder().setPopPbbAction(popPbb.build()).build());
891
892             } else if (action.getType().equals(
893                     org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter.class)) {
894                 /**
895                  * TODO: EXTENSION PROPOSAL (action, OFJava to MD-SAL)
896                  * - we might also need a way on how to identify exact type of augmentation to be 
897                  *   used as match can be bound to multiple models
898                  */
899                 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action processedAction = 
900                         ActionExtensionHelper.processAlienAction(action, ofVersion, actionPath);
901                 if (processedAction != null) {
902                     bucketActions.add(processedAction);
903                 }
904             }
905         }
906         return bucketActions;
907     }
908
909     /**
910      * Method converts OF Output action object to SAL Output action object.
911      *
912      * @param ofVersion
913      * @param ofVersion
914      * @param action    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.
915      *                  action.rev130731.actions.actions.list.Action
916      * @return OutputAction
917      */
918     public static OutputActionCase ofToSALOutputAction(OpenflowVersion ofVersion, Action action) {
919         OutputActionBuilder outputAction = new OutputActionBuilder();
920         PortAction port = action.getAugmentation(PortAction.class);
921         if (port != null) {
922             CommonPort.PortNumber protocolAgnosticPort = OpenflowPortsUtil.getProtocolAgnosticPort(
923                     ofVersion, port.getPort().getValue());
924             String portNumberAsString = OpenflowPortsUtil.portNumberToString(protocolAgnosticPort);
925             outputAction.setOutputNodeConnector(new Uri(portNumberAsString));
926         } else {
927             logger.error("Provided action is not OF Output action, no associated port found!");
928         }
929
930         MaxLengthAction length = action.getAugmentation(MaxLengthAction.class);
931         if (length != null) {
932             outputAction.setMaxLength(length.getMaxLength());
933         } else {
934             logger.error("Provided action is not OF Output action, no associated length found!");
935         }
936
937         return new OutputActionCaseBuilder().setOutputAction(outputAction.build()).build();
938     }
939
940     /**
941      * Method converts OF GroupAction object to SAL GroupAction object
942      *
943      * @param action
944      * @return GroupAction
945      */
946     public static GroupActionCase ofToSALGroupAction(Action action) {
947
948         GroupActionBuilder groupAction = new GroupActionBuilder();
949
950         GroupIdAction groupId = action.getAugmentation(GroupIdAction.class);
951         groupAction.setGroupId(groupId.getGroupId());
952
953         return new GroupActionCaseBuilder().setGroupAction(groupAction.build()).build();
954     }
955
956     /**
957      * Method converts OF SetMplsTTL action object to SAL SetMplsTTL action
958      * object.
959      *
960      * @param action
961      * @return
962      */
963     public static SetMplsTtlActionCase ofToSALSetMplsTtl(Action action) {
964
965         SetMplsTtlActionBuilder mplsTtlAction = new SetMplsTtlActionBuilder();
966         MplsTtlAction mplsTtl = action.getAugmentation(MplsTtlAction.class);
967         mplsTtlAction.setMplsTtl(mplsTtl.getMplsTtl());
968         return new SetMplsTtlActionCaseBuilder().setSetMplsTtlAction(mplsTtlAction.build()).build();
969     }
970
971     /**
972      * Method converts OF Pushvlan action to SAL PushVlan action.
973      *
974      * @param action
975      * @return PushVlanAction
976      */
977     public static PushVlanActionCase ofToSALPushVlanAction(Action action) {
978
979         PushVlanActionBuilder pushVlanAction = new PushVlanActionBuilder();
980
981         EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
982         pushVlanAction.setEthernetType(etherType.getEthertype().getValue());
983
984         return new PushVlanActionCaseBuilder().setPushVlanAction(pushVlanAction.build()).build();
985     }
986
987     /**
988      * Method converts OF PushMpls action to SAL PushMpls action.
989      *
990      * @param action
991      * @return PushMplsAction
992      */
993     public static PushMplsActionCase ofToSALPushMplsAction(Action action) {
994
995         PushMplsActionBuilder pushMplsAction = new PushMplsActionBuilder();
996
997         EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
998         pushMplsAction.setEthernetType(etherType.getEthertype().getValue());
999
1000         return new PushMplsActionCaseBuilder().setPushMplsAction(pushMplsAction.build()).build();
1001     }
1002
1003     /**
1004      * Method converts OF PopMpls action to SAL PopMpls action.
1005      *
1006      * @param action
1007      * @return PopMplsActionCase
1008      */
1009     public static PopMplsActionCase ofToSALPopMplsAction(Action action) {
1010
1011         PopMplsActionBuilder popMplsAction = new PopMplsActionBuilder();
1012
1013         EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1014         popMplsAction.setEthernetType(etherType.getEthertype().getValue());
1015
1016         return new PopMplsActionCaseBuilder().setPopMplsAction(popMplsAction.build()).build();
1017     }
1018
1019     /**
1020      * Method converts OF SetQueue action to SAL SetQueue action.
1021      *
1022      * @param action
1023      * @return SetQueueAction
1024      */
1025     public static SetQueueActionCase ofToSALSetQueue(Action action) {
1026
1027         SetQueueActionBuilder setQueueAction = new SetQueueActionBuilder();
1028
1029         QueueIdAction queueId = action.getAugmentation(QueueIdAction.class);
1030         setQueueAction.setQueueId(queueId.getQueueId());
1031
1032         return new SetQueueActionCaseBuilder().setSetQueueAction(setQueueAction.build()).build();
1033     }
1034
1035     /**
1036      * Method converts OF SetNwTtl action to SAL SetNwTtl action.
1037      *
1038      * @param action
1039      * @return SetNwTtlAction
1040      */
1041     public static SetNwTtlActionCase ofToSALSetNwTtl(Action action) {
1042
1043         SetNwTtlActionBuilder setNwTtl = new SetNwTtlActionBuilder();
1044         NwTtlAction nwTtl = action.getAugmentation(NwTtlAction.class);
1045         setNwTtl.setNwTtl(nwTtl.getNwTtl());
1046
1047         return new SetNwTtlActionCaseBuilder().setSetNwTtlAction(setNwTtl.build()).build();
1048     }
1049
1050     /**
1051      * Method converts OF Pushvlan action to SAL PushVlan action.
1052      *
1053      * @param action
1054      * @return PushVlanAction
1055      */
1056     public static PushPbbActionCase ofToSALPushPbbAction(Action action) {
1057
1058         PushPbbActionBuilder pushPbbAction = new PushPbbActionBuilder();
1059
1060         EthertypeAction etherType = action.getAugmentation(EthertypeAction.class);
1061         pushPbbAction.setEthernetType(etherType.getEthertype().getValue());
1062
1063         return new PushPbbActionCaseBuilder().setPushPbbAction(pushPbbAction.build()).build();
1064     }
1065
1066 }