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