Port ELAN service to datastore-constrained txns
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / internal / ElanNodeListener.java
1 /*
2  * Copyright (c) 2016, 2017 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 package org.opendaylight.netvirt.elan.internal;
9
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
11
12 import java.math.BigInteger;
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.Collections;
16 import java.util.List;
17
18 import javax.annotation.PostConstruct;
19 import javax.inject.Inject;
20 import javax.inject.Singleton;
21
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
25 import org.opendaylight.genius.infra.Datastore.Configuration;
26 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
27 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
28 import org.opendaylight.genius.infra.TypedWriteTransaction;
29 import org.opendaylight.genius.mdsalutil.ActionInfo;
30 import org.opendaylight.genius.mdsalutil.BucketInfo;
31 import org.opendaylight.genius.mdsalutil.FlowEntity;
32 import org.opendaylight.genius.mdsalutil.InstructionInfo;
33 import org.opendaylight.genius.mdsalutil.MDSALUtil;
34 import org.opendaylight.genius.mdsalutil.MatchInfo;
35 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
36 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
37 import org.opendaylight.genius.mdsalutil.NwConstants;
38 import org.opendaylight.genius.mdsalutil.NwConstants.NxmOfFieldType;
39 import org.opendaylight.genius.mdsalutil.actions.ActionDrop;
40 import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
41 import org.opendaylight.genius.mdsalutil.actions.ActionLearn;
42 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.CopyFromValue;
43 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromField;
44 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromValue;
45 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
46 import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
47 import org.opendaylight.genius.mdsalutil.actions.ActionRegLoad;
48 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
49 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
50 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
51 import org.opendaylight.genius.mdsalutil.matches.MatchArpOp;
52 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
53 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
54 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister;
55 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
56 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderConstant;
57 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
58 import org.opendaylight.netvirt.elan.utils.ElanConstants;
59 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
66 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
67 import org.slf4j.Logger;
68 import org.slf4j.LoggerFactory;
69
70 @Singleton
71 public class ElanNodeListener extends AsyncDataTreeChangeListenerBase<Node, ElanNodeListener> {
72
73     private static final Logger LOG = LoggerFactory.getLogger(ElanNodeListener.class);
74     private static final int LEARN_MATCH_REG4_VALUE = 1;
75     private static final int ARP_LEARN_FLOW_PRIORITY = 10;
76     private static final int ARP_LEARN_MATCH_VALUE = 0x1;
77     private static final int GARP_LEARN_MATCH_VALUE = 0x101;
78     private static final long ARP_LEARN_MATCH_MASK = 0xFFFFL;
79
80     private final DataBroker broker;
81     private final ManagedNewTransactionRunner txRunner;
82     private final IMdsalApiManager mdsalManager;
83     private final IdManagerService idManagerService;
84     private final int tempSmacLearnTimeout;
85     private final int arpPuntTimeout;
86     private final boolean puntLldpToController;
87     private final JobCoordinator jobCoordinator;
88
89     @Inject
90     public ElanNodeListener(DataBroker dataBroker, IMdsalApiManager mdsalManager, ElanConfig elanConfig,
91             IdManagerService idManagerService, JobCoordinator jobCoordinator) {
92         this.broker = dataBroker;
93         this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
94         this.mdsalManager = mdsalManager;
95         this.tempSmacLearnTimeout = elanConfig.getTempSmacLearnTimeout();
96         this.arpPuntTimeout = elanConfig.getArpPuntTimeout().intValue();
97         this.puntLldpToController = elanConfig.isPuntLldpToController();
98         this.idManagerService = idManagerService;
99         this.jobCoordinator = jobCoordinator;
100     }
101
102     @Override
103     @PostConstruct
104     public void init() {
105         registerListener(LogicalDatastoreType.OPERATIONAL, broker);
106     }
107
108     @Override
109     protected InstanceIdentifier<Node> getWildCardPath() {
110         return InstanceIdentifier.create(Nodes.class).child(Node.class);
111     }
112
113     @Override
114     protected void remove(InstanceIdentifier<Node> identifier, Node del) {
115     }
116
117     @Override
118     protected void update(InstanceIdentifier<Node> identifier, Node original, Node update) {
119     }
120
121     @Override
122     protected void add(InstanceIdentifier<Node> identifier, Node add) {
123         NodeId nodeId = add.getId();
124         String[] node = nodeId.getValue().split(":");
125         if (node.length < 2) {
126             LOG.warn("Unexpected nodeId {}", nodeId.getValue());
127             return;
128         }
129         BigInteger dpId = new BigInteger(node[1]);
130         createTableMissEntry(dpId);
131         createMulticastFlows(dpId);
132         createArpDefaultFlowsForArpCheckTable(dpId);
133     }
134
135     private void createArpDefaultFlowsForArpCheckTable(BigInteger dpId) {
136         jobCoordinator.enqueueJob("ARP_CHECK_TABLE-" + dpId.toString(),
137             () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
138                 LOG.debug("Received notification to install Arp Check Default entries for dpn {} ", dpId);
139                 createArpRequestMatchFlows(dpId, tx);
140                 createArpResponseMatchFlows(dpId, tx);
141                 createArpPuntAndLearnFlow(dpId, tx);
142                 addGarpLearnMatchFlow(dpId, tx);
143                 addArpLearnMatchFlow(dpId, tx);
144             })));
145     }
146
147     public void createTableMissEntry(BigInteger dpnId) {
148         setupTableMissSmacFlow(dpnId);
149         setupTableMissDmacFlow(dpnId);
150         setupTableMissArpCheckFlow(dpnId);
151         setupTableMissApResponderFlow(dpnId);
152         setupExternalL2vniTableMissFlow(dpnId);
153     }
154
155     private void createMulticastFlows(BigInteger dpId) {
156         createL2ControlProtocolDropFlows(dpId);
157         createMulticastPuntFlows(dpId);
158     }
159
160     private void createMulticastPuntFlows(BigInteger dpId) {
161         if (puntLldpToController) {
162             createLldpFlows(dpId);
163         }
164     }
165
166     private void createLldpFlows(BigInteger dpId) {
167         createLldpFlow(dpId, ElanConstants.LLDP_DST_1, "LLDP dMac Table Flow 1");
168         createLldpFlow(dpId, ElanConstants.LLDP_DST_2, "LLDP dMac Table Flow 2");
169         createLldpFlow(dpId, ElanConstants.LLDP_DST_3, "LLDP dMac Table Flow 3");
170     }
171
172     private void createLldpFlow(BigInteger dpId, String dstMac, String flowName) {
173         List<MatchInfo> mkMatches = new ArrayList<>();
174         mkMatches.add(new MatchEthernetType(ElanConstants.LLDP_ETH_TYPE));
175         mkMatches.add(new MatchEthernetDestination(new MacAddress(dstMac)));
176
177         List<ActionInfo> listActionInfo = new ArrayList<>();
178         listActionInfo.add(new ActionPuntToController());
179
180         List<InstructionInfo> mkInstructions = new ArrayList<>();
181         mkInstructions.add(new InstructionApplyActions(listActionInfo));
182
183         String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "lldp" + ElanConstants.LLDP_ETH_TYPE + dstMac;
184         FlowEntity lldpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 16, flowName, 0, 0,
185                 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
186
187         mdsalManager.installFlow(lldpFlow);
188     }
189
190     private void setupTableMissSmacFlow(BigInteger dpId) {
191         List<ActionInfo> actionsInfos = new ArrayList<>();
192         actionsInfos.add(new ActionPuntToController());
193         actionsInfos.add(new ActionLearn(0, tempSmacLearnTimeout, 0, ElanConstants.COOKIE_ELAN_LEARNED_SMAC, 0,
194                 NwConstants.ELAN_SMAC_LEARNED_TABLE, 0, 0,
195                 Arrays.asList(
196                         new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
197                                 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
198                                 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getFlowModHeaderLenInt()),
199                         new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(),
200                                 NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(), ElanConstants.INTERFACE_TAG_LENGTH),
201                         new ActionLearn.CopyFromValue(LEARN_MATCH_REG4_VALUE,
202                                 NwConstants.NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
203
204         List<InstructionInfo> mkInstructions = new ArrayList<>();
205         mkInstructions.add(new InstructionApplyActions(actionsInfos));
206         mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
207
208         List<MatchInfo> mkMatches = new ArrayList<>();
209         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE,
210                 getTableMissFlowRef(NwConstants.ELAN_SMAC_TABLE), 0, "ELAN sMac Table Miss Flow", 0, 0,
211                 ElanConstants.COOKIE_ELAN_KNOWN_SMAC, mkMatches, mkInstructions);
212         mdsalManager.installFlow(flowEntity);
213
214         addSmacBaseTableFlow(dpId);
215         addSmacLearnedTableFlow(dpId);
216     }
217
218     private void addSmacBaseTableFlow(BigInteger dpId) {
219         // T48 - resubmit to T49 & T50
220         List<ActionInfo> actionsInfo = new ArrayList<>();
221         actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
222         actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
223         List<InstructionInfo> mkInstruct = new ArrayList<>();
224         mkInstruct.add(new InstructionApplyActions(actionsInfo));
225         List<MatchInfo> mkMatch = new ArrayList<>();
226         FlowEntity doubleResubmitTable = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE,
227                 getTableMissFlowRef(NwConstants.ELAN_BASE_TABLE), 0, "Elan sMac resubmit table", 0, 0,
228                 ElanConstants.COOKIE_ELAN_BASE_SMAC, mkMatch, mkInstruct);
229         mdsalManager.installFlow(doubleResubmitTable);
230     }
231
232     private void addSmacLearnedTableFlow(BigInteger dpId) {
233         // T50 - match on Reg4 and goto T51
234         List<MatchInfoBase> mkMatches = new ArrayList<>();
235         mkMatches.add(new NxMatchRegister(NxmNxReg4.class, LEARN_MATCH_REG4_VALUE));
236         List<InstructionInfo> mkInstructions = new ArrayList<>();
237         mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
238         String flowRef = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(NwConstants.FLOWID_SEPARATOR)
239                 .append(LEARN_MATCH_REG4_VALUE).toString();
240         FlowEntity flowEntity =
241                 MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef, 10, "ELAN sMac Table Reg4 Flow",
242                         0, 0, ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE)),
243                         mkMatches, mkInstructions);
244         mdsalManager.installFlow(flowEntity);
245     }
246
247     private void setupTableMissDmacFlow(BigInteger dpId) {
248         List<MatchInfo> mkMatches = new ArrayList<>();
249
250         List<InstructionInfo> mkInstructions = new ArrayList<>();
251         mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_UNKNOWN_DMAC_TABLE));
252
253         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE,
254                 getTableMissFlowRef(NwConstants.ELAN_DMAC_TABLE), 0, "ELAN dMac Table Miss Flow", 0, 0,
255                 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
256
257         mdsalManager.installFlow(flowEntity);
258     }
259
260     private void setupExternalL2vniTableMissFlow(BigInteger dpnId) {
261         List<MatchInfo> matches = new ArrayList<>();
262         List<ActionInfo> actionsInfos = Collections.singletonList(new ActionNxResubmit(NwConstants
263                         .LPORT_DISPATCHER_TABLE));
264         List<InstructionInfo> instructions = Collections.singletonList(new InstructionApplyActions(actionsInfos));
265         FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
266                         getTableMissFlowRef(NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE), 0,
267                         "External L2VNI Table Miss Flow", 0, 0,
268                          ElanConstants.COOKIE_L2VNI_DEMUX, matches, instructions);
269         mdsalManager.installFlow(flowEntity);
270     }
271
272
273     private void createL2ControlProtocolDropFlows(BigInteger dpId) {
274         List<MatchInfo> mkMatches = new ArrayList<>();
275         MatchEthernetDestination matchEthDst =
276                 new MatchEthernetDestination(new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC),
277                         new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK));
278
279         mkMatches.add(matchEthDst);
280
281         List<ActionInfo> listActionInfo = new ArrayList<>();
282         listActionInfo.add(new ActionDrop());
283
284         List<InstructionInfo> mkInstructions = new ArrayList<>();
285         mkInstructions.add(new InstructionApplyActions(listActionInfo));
286
287         String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "l2control"
288                 + ElanConstants.L2_CONTROL_PACKETS_DMAC + ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK;
289         FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 15,
290                 "L2 control packets dMac Table Flow", 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches,
291                 mkInstructions);
292
293         mdsalManager.installFlow(flow);
294     }
295
296     private String getTableMissFlowRef(long tableId) {
297         return new StringBuffer().append(tableId).toString();
298     }
299
300     @Override
301     protected ElanNodeListener getDataTreeChangeListener() {
302         return ElanNodeListener.this;
303     }
304
305     private void setupTableMissApResponderFlow(final BigInteger dpnId) {
306         mdsalManager.installFlow(dpnId, ArpResponderUtil.getArpResponderTableMissFlow(dpnId));
307     }
308
309     private void setupTableMissArpCheckFlow(BigInteger dpnId) {
310         mdsalManager.installFlow(dpnId,
311                 MDSALUtil.buildFlowEntity(dpnId, NwConstants.ARP_CHECK_TABLE,
312                         String.valueOf("L2.ELAN." + NwConstants.ARP_CHECK_TABLE), NwConstants.TABLE_MISS_PRIORITY,
313                         ArpResponderConstant.DROP_FLOW_NAME.value(), 0, 0, NwConstants.COOKIE_ARP_RESPONDER,
314                         new ArrayList<MatchInfo>(),
315                         Collections.singletonList(new InstructionGotoTable(NwConstants.ELAN_BASE_TABLE))));
316     }
317
318     private void createArpRequestMatchFlows(BigInteger dpId, TypedWriteTransaction<Configuration> tx) {
319
320         long arpRequestGroupId = ArpResponderUtil.retrieveStandardArpResponderGroupId(idManagerService);
321         List<BucketInfo> buckets = ArpResponderUtil.getDefaultBucketInfos(NwConstants.ARP_RESPONDER_TABLE);
322         ArpResponderUtil.installGroup(mdsalManager, dpId, arpRequestGroupId,
323                 ArpResponderConstant.GROUP_FLOW_NAME.value(), buckets);
324
325         FlowEntity arpReqArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
326                 NwConstants.ARP_REQUEST, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REQUEST), () ->
327                         Arrays.asList(new ActionGroup(arpRequestGroupId),
328                                 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
329                                 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
330                                 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
331         LOG.trace("Invoking MDSAL to install Arp Rquest Match Flow for table {}", NwConstants.ARP_CHECK_TABLE);
332         mdsalManager.addFlow(tx, arpReqArpCheckTbl);
333     }
334
335     private void createArpResponseMatchFlows(BigInteger dpId, TypedWriteTransaction<Configuration> tx) {
336         FlowEntity arpRepArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
337                 NwConstants.ARP_REPLY, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REPLY), () ->
338                         Arrays.asList(new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
339                                 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
340                                 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
341         LOG.trace("Invoking MDSAL to install  Arp Reply Match Flow for Table {} ", NwConstants.ARP_CHECK_TABLE);
342         mdsalManager.addFlow(tx, arpRepArpCheckTbl);
343     }
344
345     private void createArpPuntAndLearnFlow(BigInteger dpId, TypedWriteTransaction<Configuration> tx) {
346         LOG.debug("adding arp punt and learn entry in table {}", NwConstants.ARP_LEARN_TABLE_1);
347
348         List<MatchInfo> matches = new ArrayList<>();
349         List<ActionInfo> actions = new ArrayList<>();
350         BigInteger cookie = new BigInteger("88880000", 16);
351
352         matches.add(MatchEthernetType.ARP);
353         actions.add(new ActionPuntToController());
354         if (arpPuntTimeout != 0) {
355             actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
356                     NwConstants.ARP_LEARN_TABLE_1, 0, 0,
357                     Arrays.asList(
358                             new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
359                                     NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
360                             new MatchFromField(NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
361                                     NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
362                                     NxmOfFieldType.NXM_OF_ARP_SPA.getFlowModHeaderLenInt()),
363                             new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
364                                     NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
365                                     NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
366                             new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
367                                     MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
368                                     NxmOfFieldType.OXM_OF_METADATA.getType(), MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
369                                     ElanConstants.ELAN_TAG_LENGTH),
370                             new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
371
372             actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
373                     NwConstants.ARP_LEARN_TABLE_2, 0, 0,
374                     Arrays.asList(
375                             new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
376                                     NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
377                             new MatchFromField(NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
378                                     NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
379                                     NxmOfFieldType.NXM_OF_ARP_SPA.getFlowModHeaderLenInt()),
380                             new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
381                                     NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
382                                     NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
383                             new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
384                                     MetaDataUtil.METADATA_ELAN_TAG_OFFSET, NxmOfFieldType.OXM_OF_METADATA.getType(),
385                                     MetaDataUtil.METADATA_ELAN_TAG_OFFSET, MetaDataUtil.METADATA_ELAN_TAG_BITLEN),
386                             new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8, 8))));
387         }
388
389         List<InstructionInfo> instructions = new ArrayList<>();
390         instructions.add(new InstructionApplyActions(actions));
391         String flowid = String.valueOf(NwConstants.ARP_LEARN_TABLE_1) + NwConstants.FLOWID_SEPARATOR + "arp.punt";
392         FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ARP_LEARN_TABLE_1, flowid,
393                 NwConstants.TABLE_MISS_PRIORITY, "arp punt/learn flow", 0,
394                 0, cookie, matches, instructions);
395         mdsalManager.addFlow(tx, flow);
396     }
397
398     private void addGarpLearnMatchFlow(BigInteger dpId, TypedWriteTransaction<Configuration> tx) {
399         List<ActionInfo> actions = new ArrayList<>();
400         List<MatchInfoBase> matches = new ArrayList<>();
401
402         matches.add(MatchEthernetType.ARP);
403         matches.add(new NxMatchRegister(NxmNxReg4.class, GARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
404
405         actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
406         actions.add(new ActionPuntToController());
407         actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
408         actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
409
410         List<InstructionInfo> instructions = new ArrayList<>();
411         instructions.add(new InstructionApplyActions(actions));
412         String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "garp.match";
413         FlowEntity garpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
414                 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "GARP learn match flow", 0, 0,
415                 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
416         mdsalManager.addFlow(tx, garpFlow);
417     }
418
419     private void addArpLearnMatchFlow(BigInteger dpId, TypedWriteTransaction<Configuration> tx) {
420         List<ActionInfo> actions = new ArrayList<>();
421         List<MatchInfoBase> matches = new ArrayList<>();
422
423         matches.add(MatchEthernetType.ARP);
424         matches.add(new NxMatchRegister(NxmNxReg4.class, ARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
425
426         actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
427         actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
428         actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
429
430         List<InstructionInfo> instructions = new ArrayList<>();
431         instructions.add(new InstructionApplyActions(actions));
432         String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "arp.match";
433         FlowEntity arpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
434                 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "ARP learn match flow", 0, 0,
435                 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
436         mdsalManager.addFlow(tx, arpFlow);
437     }
438
439 }