f3fafcd9f77885c4ab9235cb5c3568ed93556952
[netvirt.git] / openstack / net-virt-providers / src / main / java / org / opendaylight / netvirt / openstack / netvirt / providers / openflow13 / services / IngressAclLearnServiceUtil.java
1 /*
2  * Copyright (c) 2016 NEC Corporation 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
9 package org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.services;
10
11 import java.math.BigInteger;
12 import java.util.List;
13 import java.util.ArrayList;
14
15
16
17 import org.opendaylight.netvirt.openstack.netvirt.providers.openflow13.Service;
18 import org.opendaylight.netvirt.openstack.netvirt.api.LearnConstants;
19 import org.opendaylight.netvirt.openstack.netvirt.api.LearnConstants.LearnFlowModsType;
20 import org.opendaylight.netvirt.openstack.netvirt.providers.NetvirtProvidersProvider;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.add.group.input.buckets.bucket.action.action.NxActionResubmitRpcAddGroupCaseBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.resubmit.grouping.NxResubmitBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModAddMatchFromFieldCaseBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModAddMatchFromValueCaseBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModCopyFieldIntoFieldCaseBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModCopyValueIntoFieldCaseBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.FlowModOutputToPortCaseBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.add.match.from.field._case.FlowModAddMatchFromFieldBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.add.match.from.value._case.FlowModAddMatchFromValueBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.copy.field.into.field._case.FlowModCopyFieldIntoFieldBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.copy.value.into.field._case.FlowModCopyValueIntoFieldBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.flow.mod.spec.flow.mod.spec.flow.mod.output.to.port._case.FlowModOutputToPortBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nodes.node.table.flow.instructions.instruction.instruction.apply.actions._case.apply.actions.action.action.NxActionLearnNodesNodeTableFlowApplyActionsCaseBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.NxLearnBuilder;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.nx.learn.FlowMods;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.nx.action.learn.grouping.nx.learn.FlowModsBuilder;
49
50 public class IngressAclLearnServiceUtil {
51     private static final short LEARN_TABLE_ID = Service.ACL_LEARN_SERVICE.getTable();
52     private static final short RESUBMIT_TABLE_ID = Service.OUTBOUND_NAT.getTable();
53
54     /*
55      * (Table:IngressAclLearnService) IngressAcl Learning
56      * Match: reg6 = LearnConstants.NxmOfFieldType.NXM_NX_REG6
57      * Action: learn and resubmit to next table
58      * "table=90,dl_src=fa:16:3e:d3:bb:8a,tcp,priority=61002,tcp_dst=22,actions=learn(table=39,idle_timeout=18000,fin_idle_timeout=300,
59      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
60      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
61      */
62     public static FlowBuilder programIngressAclLearnRuleForTcp(FlowBuilder flowBuilder) {
63         List<Action> listAction = new ArrayList<>();
64
65         // Create learn action
66         /*
67          * learn header
68          * 0 1 2 3 4 5 6 7 idleTO hardTO prio cook flags table finidle finhard
69          *
70          * learn flowmod
71          * 0 1 2 3 learnFlowModType srcField dstField FlowModNumBits
72          */
73         /*String[] header = new String[] {
74                 "18000", "0", "61010", "0", "0", "39", "300", "0"
75         };*/
76         String[] header = new String[] {
77             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpIdleTimeout()),
78             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpHardTimeout()),
79             LearnConstants.LEARN_PRIORITY,
80             "0",
81             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
82             String.valueOf(LEARN_TABLE_ID),
83             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpFinIdleTimeout()),
84             String.valueOf(NetvirtProvidersProvider.getSecurityGroupTcpFinHardTimeout())
85         };
86
87         String[][] flowMod = new String[8][];
88         //eth_type=0x800
89         flowMod[0] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
90                 Integer.toString(LearnConstants.ETHTYPE_IPV4),
91                 LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getHexType(),
92                 LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLen() };
93         flowMod[1] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
94                 Integer.toString(LearnConstants.IP_PROT_TCP),
95                 LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getHexType(),
96                 LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getFlowModHeaderLen() };
97         //nw_proto=6
98         //NXM_OF_IP_SRC[]=NXM_OF_IP_DST[]
99         flowMod[2] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
100                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
101                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
102                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getFlowModHeaderLen()};
103         // NXM_OF_IP_DST[]=NXM_OF_IP_SRC[]
104         flowMod[3] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
105                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
106                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
107                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getFlowModHeaderLen()};
108         //NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[]
109         flowMod[4] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
110                 LearnConstants.NxmOfFieldType.NXM_OF_TCP_DST.getHexType(),
111                 LearnConstants.NxmOfFieldType.NXM_OF_TCP_SRC.getHexType(),
112                 LearnConstants.NxmOfFieldType.NXM_OF_TCP_DST.getFlowModHeaderLen()};
113         //NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[]
114         flowMod[5] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
115                 LearnConstants.NxmOfFieldType.NXM_OF_TCP_SRC.getHexType(),
116                 LearnConstants.NxmOfFieldType.NXM_OF_TCP_DST.getHexType(),
117                 LearnConstants.NxmOfFieldType.NXM_OF_TCP_SRC.getFlowModHeaderLen()};
118      // NXM_NX_TUN_ID[]
119         flowMod[6] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
120                 LearnConstants.NxmOfFieldType.NXM_NX_TUN_ID.getHexType(),
121                 LearnConstants.NxmOfFieldType.NXM_NX_TUN_ID.getHexType(),
122                 LearnConstants.NxmOfFieldType.NXM_NX_TUN_ID.getFlowModHeaderLen() };
123         flowMod[7] = new String[] {
124                 LearnConstants.LearnFlowModsType.COPY_FROM_VALUE.name(), "1",
125                 LearnConstants.NxmOfFieldType.NXM_NX_REG6.getHexType(), "8" };
126         listAction.add(buildAction(0, header, flowMod));
127         ActionBuilder ab = new ActionBuilder();
128         ab = new ActionBuilder();
129         ab.setAction(createResubmitActions());
130         ab.setKey(new ActionKey(1));
131         listAction.add(ab.build());
132         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
133         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
134         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
135         List<Instruction> instructions = new ArrayList<>();
136         InstructionBuilder instructionBuilder = new InstructionBuilder();
137         instructionBuilder.setInstruction(applyActionsCase);
138         instructionBuilder.setOrder(0);
139         instructionBuilder.setKey(new InstructionKey(0));
140         instructions.add(instructionBuilder.build());
141         // Add InstructionBuilder to the Instruction(s)Builder List
142         instructionsBuilder.setInstruction(instructions);
143         // Add InstructionsBuilder to FlowBuilder
144         flowBuilder.setInstructions(instructionsBuilder.build());
145
146         return flowBuilder;
147     }
148
149     /*
150      * (Table:IngressAclLearnService) IngressAcl Learning
151      * Match: reg6 = LearnConstants.NxmOfFieldType.NXM_NX_REG6
152      * Action: learn and resubmit to next table
153      * "table=90,dl_src=fa:16:3e:d3:bb:8a,tcp,priority=61002,tcp_dst=22,actions=learn(table=39,idle_timeout=300,fin_idle_timeout=0,
154      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
155      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
156      */
157     public static FlowBuilder programIngressAclLearnRuleForUdp(FlowBuilder flowBuilder) {
158         List<Action> listAction = new ArrayList<>();
159
160         // Create learn action
161         /*
162          * learn header
163          * 0 1 2 3 4 5 6 7 idleTO hardTO prio cook flags table finidle finhard
164          *
165          * learn flowmod
166          * 0 1 2 3 learnFlowModType srcField dstField FlowModNumBits
167          */
168         /*String[] header = new String[] {
169                 "300", "0", "61010", "0", "0", "39", "0", "0"
170         };*/
171         String[] header = new String[] {
172             String.valueOf(NetvirtProvidersProvider.getSecurityGroupUdpIdleTimeout()),
173             String.valueOf(NetvirtProvidersProvider.getSecurityGroupUdpHardTimeout()),
174             LearnConstants.LEARN_PRIORITY,
175             "0",
176             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
177             String.valueOf(LEARN_TABLE_ID),
178             "0",
179             "0"
180         };
181
182         String[][] flowMod = new String[8][];
183         //eth_type=0x800
184         flowMod[0] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
185                 Integer.toString(LearnConstants.ETHTYPE_IPV4),
186                 LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getHexType(),
187                 LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLen() };
188         flowMod[1] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
189                 Integer.toString(LearnConstants.IP_PROT_UDP),
190                 LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getHexType(),
191                 LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getFlowModHeaderLen() };
192         //nw_proto=6
193         //NXM_OF_IP_SRC[]=NXM_OF_IP_DST[]
194         flowMod[2] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
195                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
196                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
197                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getFlowModHeaderLen()};
198         // NXM_OF_IP_DST[]=NXM_OF_IP_SRC[]
199         flowMod[3] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
200                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
201                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
202                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getFlowModHeaderLen()};
203         //NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[]
204         flowMod[4] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
205                 LearnConstants.NxmOfFieldType.NXM_OF_UDP_DST.getHexType(),
206                 LearnConstants.NxmOfFieldType.NXM_OF_UDP_SRC.getHexType(),
207                 LearnConstants.NxmOfFieldType.NXM_OF_UDP_DST.getFlowModHeaderLen()};
208         //NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[]
209         flowMod[5] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
210                 LearnConstants.NxmOfFieldType.NXM_OF_UDP_SRC.getHexType(),
211                 LearnConstants.NxmOfFieldType.NXM_OF_UDP_DST.getHexType(),
212                 LearnConstants.NxmOfFieldType.NXM_OF_UDP_SRC.getFlowModHeaderLen()};
213      // NXM_NX_TUN_ID[]
214         flowMod[6] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
215                 LearnConstants.NxmOfFieldType.NXM_NX_TUN_ID.getHexType(),
216                 LearnConstants.NxmOfFieldType.NXM_NX_TUN_ID.getHexType(),
217                 LearnConstants.NxmOfFieldType.NXM_NX_TUN_ID.getFlowModHeaderLen() };
218         flowMod[7] = new String[] {
219                 LearnConstants.LearnFlowModsType.COPY_FROM_VALUE.name(), LearnConstants.LEARN_MATCH_REG_VALUE,
220                 LearnConstants.NxmOfFieldType.NXM_NX_REG6.getHexType(), "8" };
221
222         listAction.add(buildAction(0, header, flowMod));
223
224         ActionBuilder ab = new ActionBuilder();
225         ab = new ActionBuilder();
226         ab.setAction(createResubmitActions());
227         ab.setKey(new ActionKey(1));
228         listAction.add(ab.build());
229
230         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
231         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
232         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
233         List<Instruction> instructions = new ArrayList<>();
234         InstructionBuilder instructionBuilder = new InstructionBuilder();
235         instructionBuilder.setInstruction(applyActionsCase);
236         instructionBuilder.setOrder(0);
237         instructionBuilder.setKey(new InstructionKey(0));
238         instructions.add(instructionBuilder.build());
239         // Add InstructionBuilder to the Instruction(s)Builder List
240         instructionsBuilder.setInstruction(instructions);
241         // Add InstructionsBuilder to FlowBuilder
242         flowBuilder.setInstructions(instructionsBuilder.build());
243
244         return flowBuilder;
245     }
246
247     /*
248      * (Table:IngressAclLearnService) IngressAcl Learning
249      * Match: reg6 = LearnConstants.NxmOfFieldType.NXM_NX_REG6
250      * Action: learn and resubmit to next table
251      * "table=90,dl_src=fa:16:3e:d3:bb:8a,tcp,priority=61002,tcp_dst=22,actions=learn(table=39,idle_timeout=300,fin_idle_timeout=0,
252      * fin_hard_timeout=0,priority=61010, cookie=0x6900000,eth_type=0x800,nw_proto=6, NXM_OF_IP_SRC[]=NXM_OF_IP_DST[],NXM_OF_IP_DST[]=NXM_OF_IP_SRC[],
253      * NXM_OF_TCP_SRC[]=NXM_OF_TCP_DST[],NXM_OF_TCP_DST[]=NXM_OF_TCP_SRC[],load:0x1->NXM_NX_REG6[0..7]),resubmit(,100)"
254      */
255     public static FlowBuilder programIngressAclLearnRuleForIcmp(FlowBuilder flowBuilder, String icmpType, String icmpCode) {
256         //, Integer icmpCode,Integer icmpType
257         List<Action> listAction = new ArrayList<>();
258
259         String[] header = new String[] {
260             String.valueOf(NetvirtProvidersProvider.getSecurityGroupDefaultIdleTimeout()),
261             String.valueOf(NetvirtProvidersProvider.getSecurityGroupDefaultHardTimeout()),
262             LearnConstants.LEARN_PRIORITY,
263             "0",
264             LearnConstants.DELETE_LEARNED_FLAG_VALUE,
265             String.valueOf(LEARN_TABLE_ID),
266             "0",
267             "0"
268         };
269
270         String[][] flowMod = new String[7][];
271         //eth_type=0x800
272         flowMod[0] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
273                 Integer.toString(LearnConstants.ETHTYPE_IPV4),
274                 LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getHexType(),
275                 LearnConstants.NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLen() };
276         //nw_proto=1
277         flowMod[1] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(),
278                 Integer.toString(LearnConstants.IP_PROT_ICMP),
279                 LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getHexType(),
280                 LearnConstants.NxmOfFieldType.NXM_OF_IP_PROTO.getFlowModHeaderLen() };
281         //NXM_OF_IP_SRC[]=NXM_OF_IP_DST[]
282         flowMod[2] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
283                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
284                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
285                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getFlowModHeaderLen()};
286         // NXM_OF_IP_DST[]=NXM_OF_IP_SRC[]
287         flowMod[3] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_FIELD.name(),
288                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getHexType(),
289                 LearnConstants.NxmOfFieldType.NXM_OF_IP_DST.getHexType(),
290                 LearnConstants.NxmOfFieldType.NXM_OF_IP_SRC.getFlowModHeaderLen()};
291       //icmp_code=0
292         flowMod[4] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(), icmpCode,
293                 LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getHexType(),
294                 LearnConstants.NxmOfFieldType.NXM_OF_ICMP_CODE.getFlowModHeaderLen()};
295         //icmp_type=0
296         flowMod[5] = new String[] { LearnConstants.LearnFlowModsType.MATCH_FROM_VALUE.name(), icmpType,
297                 LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getHexType(),
298                 LearnConstants.NxmOfFieldType.NXM_OF_ICMP_TYPE.getFlowModHeaderLen()};
299         flowMod[6] = new String[] {
300                 LearnConstants.LearnFlowModsType.COPY_FROM_VALUE.name(), LearnConstants.LEARN_MATCH_REG_VALUE,
301                 LearnConstants.NxmOfFieldType.NXM_NX_REG6.getHexType(), "8" };
302         listAction.add(buildAction(0, header, flowMod));
303         ActionBuilder ab = new ActionBuilder();
304         ab = new ActionBuilder();
305         ab.setAction(createResubmitActions());
306         ab.setKey(new ActionKey(1));
307         listAction.add(ab.build());
308         ApplyActions applyActions = new ApplyActionsBuilder().setAction(listAction).build();
309         ApplyActionsCase applyActionsCase = new ApplyActionsCaseBuilder().setApplyActions(applyActions).build();
310         InstructionsBuilder instructionsBuilder = new InstructionsBuilder();
311         List<Instruction> instructions = new ArrayList<>();
312
313         InstructionBuilder instructionBuilder = new InstructionBuilder();
314         instructionBuilder.setInstruction(applyActionsCase);
315         instructionBuilder.setOrder(0);
316         instructionBuilder.setKey(new InstructionKey(0));
317         instructions.add(instructionBuilder.build());
318         // Add InstructionBuilder to the Instruction(s)Builder List
319         instructionsBuilder.setInstruction(instructions);
320
321         // Add InstructionsBuilder to FlowBuilder
322         flowBuilder.setInstructions(instructionsBuilder.build());
323
324         return flowBuilder;
325     }
326
327     /*
328      * build Action
329      *
330      * copy from org.opendaylight.genius.mdsalutil.ActionType.learn
331      */
332     private static Action buildAction(int newActionKey, String[] header, String[][] actionValues) {
333         NxLearnBuilder learnBuilder = new NxLearnBuilder();
334         learnBuilder.setIdleTimeout(Integer.parseInt(header[0]));
335         learnBuilder.setHardTimeout(Integer.parseInt(header[1]));
336         learnBuilder.setPriority(Integer.parseInt(header[2]));
337         learnBuilder.setCookie(BigInteger.valueOf(Long.valueOf(header[3])));
338         learnBuilder.setFlags(Integer.parseInt(header[4]));
339         learnBuilder.setTableId(Short.parseShort(header[5]));
340         learnBuilder.setFinIdleTimeout(Integer.parseInt(header[6]));
341         learnBuilder.setFinHardTimeout(Integer.parseInt(header[7]));
342
343         List<FlowMods> flowModsList = new ArrayList<>();
344         for(String[] values : actionValues) {
345             if(LearnFlowModsType.MATCH_FROM_FIELD.name().equals(values[0])) {
346                 FlowModAddMatchFromFieldBuilder builder = new FlowModAddMatchFromFieldBuilder();
347                 builder.setSrcField(Long.decode(values[1]));
348                 builder.setSrcOfs(0);
349                 builder.setDstField(Long.decode(values[2]));
350                 builder.setDstOfs(0);
351                 builder.setFlowModNumBits(Integer.parseInt(values[3]));
352
353                 FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
354                 FlowModAddMatchFromFieldCaseBuilder caseBuilder = new FlowModAddMatchFromFieldCaseBuilder();
355                 caseBuilder.setFlowModAddMatchFromField(builder.build());
356                 flowModsBuilder.setFlowModSpec(caseBuilder.build());
357                 flowModsList.add(flowModsBuilder.build());
358             } else if (LearnFlowModsType.MATCH_FROM_VALUE.name().equals(values[0])) {
359                 FlowModAddMatchFromValueBuilder builder = new FlowModAddMatchFromValueBuilder();
360                 builder.setValue(Integer.parseInt(values[1]));
361                 builder.setSrcField(Long.decode(values[2]));
362                 builder.setSrcOfs(0);
363                 builder.setFlowModNumBits(Integer.parseInt(values[3]));
364
365                 FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
366                 FlowModAddMatchFromValueCaseBuilder caseBuilder = new FlowModAddMatchFromValueCaseBuilder();
367                 caseBuilder.setFlowModAddMatchFromValue(builder.build());
368                 flowModsBuilder.setFlowModSpec(caseBuilder.build());
369                 flowModsList.add(flowModsBuilder.build());
370             } else if (LearnFlowModsType.COPY_FROM_FIELD.name().equals(values[0])) {
371                 FlowModCopyFieldIntoFieldBuilder builder = new FlowModCopyFieldIntoFieldBuilder();
372                 builder.setSrcField(Long.decode(values[1]));
373                 builder.setSrcOfs(0);
374                 builder.setDstField(Long.decode(values[2]));
375                 builder.setDstOfs(0);
376                 builder.setFlowModNumBits(Integer.parseInt(values[3]));
377
378                 FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
379                 FlowModCopyFieldIntoFieldCaseBuilder caseBuilder = new FlowModCopyFieldIntoFieldCaseBuilder();
380                 caseBuilder.setFlowModCopyFieldIntoField(builder.build());
381                 flowModsBuilder.setFlowModSpec(caseBuilder.build());
382                 flowModsList.add(flowModsBuilder.build());
383             } else if (LearnFlowModsType.COPY_FROM_VALUE.name().equals(values[0])) {
384                 FlowModCopyValueIntoFieldBuilder builder = new FlowModCopyValueIntoFieldBuilder();
385                 builder.setValue(Integer.parseInt(values[1]));
386                 builder.setDstField(Long.decode(values[2]));
387                 builder.setDstOfs(0);
388                 builder.setFlowModNumBits(Integer.parseInt(values[3]));
389
390                 FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
391                 FlowModCopyValueIntoFieldCaseBuilder caseBuilder = new FlowModCopyValueIntoFieldCaseBuilder();
392                 caseBuilder.setFlowModCopyValueIntoField(builder.build());
393                 flowModsBuilder.setFlowModSpec(caseBuilder.build());
394                 flowModsList.add(flowModsBuilder.build());
395             } else if (LearnFlowModsType.OUTPUT_TO_PORT.name().equals(values[0])) {
396                 FlowModOutputToPortBuilder builder = new FlowModOutputToPortBuilder();
397                 builder.setSrcField(Long.decode(values[1]));
398                 builder.setSrcOfs(0);
399                 builder.setFlowModNumBits(Integer.parseInt(values[2]));
400
401                 FlowModsBuilder flowModsBuilder = new FlowModsBuilder();
402                 FlowModOutputToPortCaseBuilder caseBuilder = new FlowModOutputToPortCaseBuilder();
403                 caseBuilder.setFlowModOutputToPort(builder.build());
404                 flowModsBuilder.setFlowModSpec(caseBuilder.build());
405                 flowModsList.add(flowModsBuilder.build());
406             }
407         }
408         learnBuilder.setFlowMods(flowModsList);
409
410         ActionBuilder abExt = new ActionBuilder();
411         abExt.setKey(new ActionKey(newActionKey));
412
413         abExt.setAction(new NxActionLearnNodesNodeTableFlowApplyActionsCaseBuilder()
414             .setNxLearn(learnBuilder.build()).build());
415         return abExt.build();
416     }
417
418     private static org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action createResubmitActions() {
419
420         NxResubmitBuilder gttb = new NxResubmitBuilder();
421         gttb.setTable(RESUBMIT_TABLE_ID);
422
423         // Wrap our Apply Action in an InstructionBuilder
424         return (new NxActionResubmitRpcAddGroupCaseBuilder().setNxResubmit(gttb.build())).build();
425     }
426 }