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