2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.netvirt.elan.internal;
10 import static org.opendaylight.genius.infra.Datastore.CONFIGURATION;
12 import java.math.BigInteger;
13 import java.time.Duration;
14 import java.util.ArrayList;
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.List;
18 import java.util.concurrent.ExecutionException;
20 import javax.annotation.PostConstruct;
21 import javax.inject.Inject;
22 import javax.inject.Singleton;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
27 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
28 import org.opendaylight.genius.infra.Datastore.Configuration;
29 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
30 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
31 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
32 import org.opendaylight.genius.mdsalutil.ActionInfo;
33 import org.opendaylight.genius.mdsalutil.BucketInfo;
34 import org.opendaylight.genius.mdsalutil.FlowEntity;
35 import org.opendaylight.genius.mdsalutil.InstructionInfo;
36 import org.opendaylight.genius.mdsalutil.MDSALUtil;
37 import org.opendaylight.genius.mdsalutil.MatchInfo;
38 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
39 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
40 import org.opendaylight.genius.mdsalutil.NwConstants;
41 import org.opendaylight.genius.mdsalutil.NwConstants.NxmOfFieldType;
42 import org.opendaylight.genius.mdsalutil.actions.ActionDrop;
43 import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
44 import org.opendaylight.genius.mdsalutil.actions.ActionLearn;
45 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.CopyFromValue;
46 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromField;
47 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromValue;
48 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
49 import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
50 import org.opendaylight.genius.mdsalutil.actions.ActionRegLoad;
51 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
52 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
53 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
54 import org.opendaylight.genius.mdsalutil.matches.MatchArpOp;
55 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
56 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
57 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister;
58 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
59 import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
60 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderConstant;
61 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
62 import org.opendaylight.netvirt.elan.utils.ElanConstants;
63 import org.opendaylight.netvirt.elan.utils.ElanUtils;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
72 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
77 public class ElanNodeListener extends AsyncDataTreeChangeListenerBase<Node, ElanNodeListener> {
79 private static final Logger LOG = LoggerFactory.getLogger(ElanNodeListener.class);
80 private static final int LEARN_MATCH_REG4_VALUE = 1;
81 private static final int ARP_LEARN_FLOW_PRIORITY = 10;
82 private static final int ARP_LEARN_MATCH_VALUE = 0x1;
83 private static final int GARP_LEARN_MATCH_VALUE = 0x101;
84 private static final long ARP_LEARN_MATCH_MASK = 0xFFFFL;
86 private final DataBroker broker;
87 private final ManagedNewTransactionRunner txRunner;
88 private final IMdsalApiManager mdsalManager;
89 private final IdManagerService idManagerService;
90 private final int tempSmacLearnTimeout;
91 private final int arpPuntTimeout;
92 private final boolean puntLldpToController;
93 private final JobCoordinator jobCoordinator;
94 private final DataTreeEventCallbackRegistrar eventCallbacks;
97 public ElanNodeListener(DataBroker dataBroker, IMdsalApiManager mdsalManager, ElanConfig elanConfig,
98 IdManagerService idManagerService, JobCoordinator jobCoordinator,
99 DataTreeEventCallbackRegistrar eventCallbacks) {
100 this.broker = dataBroker;
101 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
102 this.mdsalManager = mdsalManager;
103 this.tempSmacLearnTimeout = elanConfig.getTempSmacLearnTimeout();
104 this.arpPuntTimeout = elanConfig.getArpPuntTimeout().intValue();
105 this.puntLldpToController = elanConfig.isPuntLldpToController();
106 this.idManagerService = idManagerService;
107 this.jobCoordinator = jobCoordinator;
108 this.eventCallbacks = eventCallbacks;
114 registerListener(LogicalDatastoreType.OPERATIONAL, broker);
118 protected InstanceIdentifier<Node> getWildCardPath() {
119 return InstanceIdentifier.create(Nodes.class).child(Node.class);
123 protected void remove(InstanceIdentifier<Node> identifier, Node del) {
127 protected void update(InstanceIdentifier<Node> identifier, Node original, Node update) {
131 protected void add(InstanceIdentifier<Node> identifier, Node add) {
132 NodeId nodeId = add.getId();
133 String[] node = nodeId.getValue().split(":");
134 if (node.length < 2) {
135 LOG.warn("Unexpected nodeId {}", nodeId.getValue());
138 BigInteger dpId = new BigInteger(node[1]);
139 createTableMissEntry(dpId);
140 createMulticastFlows(dpId);
141 createArpDefaultFlowsForArpCheckTable(dpId);
144 private void createArpDefaultFlowsForArpCheckTable(BigInteger dpId) {
146 jobCoordinator.enqueueJob("ARP_CHECK_TABLE-" + dpId.toString(),
147 () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
149 LOG.debug("Received notification to install Arp Check Default entries for dpn {} ", dpId);
150 createArpRequestMatchFlows(dpId, tx);
151 createArpResponseMatchFlows(dpId, tx);
152 createArpPuntAndLearnFlow(dpId, tx);
153 addGarpLearnMatchFlow(dpId, tx);
154 addArpLearnMatchFlow(dpId, tx);
155 } catch (InterruptedException | ExecutionException e) {
156 LOG.error("Error programming ARP rules for dpn {}", dpId, e);
161 public void createTableMissEntry(BigInteger dpnId) {
162 setupTableMissSmacFlow(dpnId);
163 setupTableMissDmacFlow(dpnId);
164 setupTableMissArpCheckFlow(dpnId);
165 setupTableMissApResponderFlow(dpnId);
166 setupExternalL2vniTableMissFlow(dpnId);
169 private void createMulticastFlows(BigInteger dpId) {
170 createL2ControlProtocolDropFlows(dpId);
171 createMulticastPuntFlows(dpId);
174 private void createMulticastPuntFlows(BigInteger dpId) {
175 if (puntLldpToController) {
176 createLldpFlows(dpId);
180 private void createLldpFlows(BigInteger dpId) {
181 createLldpFlow(dpId, ElanConstants.LLDP_DST_1, "LLDP dMac Table Flow 1");
182 createLldpFlow(dpId, ElanConstants.LLDP_DST_2, "LLDP dMac Table Flow 2");
183 createLldpFlow(dpId, ElanConstants.LLDP_DST_3, "LLDP dMac Table Flow 3");
186 private void createLldpFlow(BigInteger dpId, String dstMac, String flowName) {
187 List<MatchInfo> mkMatches = new ArrayList<>();
188 mkMatches.add(new MatchEthernetType(ElanConstants.LLDP_ETH_TYPE));
189 mkMatches.add(new MatchEthernetDestination(new MacAddress(dstMac)));
191 List<ActionInfo> listActionInfo = new ArrayList<>();
192 listActionInfo.add(new ActionPuntToController());
194 List<InstructionInfo> mkInstructions = new ArrayList<>();
195 mkInstructions.add(new InstructionApplyActions(listActionInfo));
197 String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "lldp" + ElanConstants.LLDP_ETH_TYPE + dstMac;
198 FlowEntity lldpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 16, flowName, 0, 0,
199 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
201 mdsalManager.installFlow(lldpFlow);
204 private void setupTableMissSmacFlow(BigInteger dpId) {
205 List<ActionInfo> actionsInfos = new ArrayList<>();
206 actionsInfos.add(new ActionPuntToController());
207 actionsInfos.add(new ActionLearn(0, tempSmacLearnTimeout, 0, ElanConstants.COOKIE_ELAN_LEARNED_SMAC, 0,
208 NwConstants.ELAN_SMAC_LEARNED_TABLE, 0, 0,
210 new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
211 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
212 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getFlowModHeaderLenInt()),
213 new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(),
214 NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(), ElanConstants.INTERFACE_TAG_LENGTH),
215 new ActionLearn.CopyFromValue(LEARN_MATCH_REG4_VALUE,
216 NwConstants.NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
218 List<InstructionInfo> mkInstructions = new ArrayList<>();
219 mkInstructions.add(new InstructionApplyActions(actionsInfos));
220 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
222 List<MatchInfo> mkMatches = new ArrayList<>();
223 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE,
224 getTableMissFlowRef(NwConstants.ELAN_SMAC_TABLE), 0, "ELAN sMac Table Miss Flow", 0, 0,
225 ElanConstants.COOKIE_ELAN_KNOWN_SMAC, mkMatches, mkInstructions);
226 mdsalManager.installFlow(flowEntity);
228 addSmacBaseTableFlow(dpId);
229 addSmacLearnedTableFlow(dpId);
232 private void addSmacBaseTableFlow(BigInteger dpId) {
233 // T48 - resubmit to T49 & T50
234 List<ActionInfo> actionsInfo = new ArrayList<>();
235 actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
236 actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
237 List<InstructionInfo> mkInstruct = new ArrayList<>();
238 mkInstruct.add(new InstructionApplyActions(actionsInfo));
239 List<MatchInfo> mkMatch = new ArrayList<>();
240 FlowEntity doubleResubmitTable = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE,
241 getTableMissFlowRef(NwConstants.ELAN_BASE_TABLE), 0, "Elan sMac resubmit table", 0, 0,
242 ElanConstants.COOKIE_ELAN_BASE_SMAC, mkMatch, mkInstruct);
243 mdsalManager.installFlow(doubleResubmitTable);
246 private void addSmacLearnedTableFlow(BigInteger dpId) {
247 // T50 - match on Reg4 and goto T51
248 List<MatchInfoBase> mkMatches = new ArrayList<>();
249 mkMatches.add(new NxMatchRegister(NxmNxReg4.class, LEARN_MATCH_REG4_VALUE));
250 List<InstructionInfo> mkInstructions = new ArrayList<>();
251 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
252 String flowRef = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(NwConstants.FLOWID_SEPARATOR)
253 .append(LEARN_MATCH_REG4_VALUE).toString();
254 FlowEntity flowEntity =
255 MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef, 10, "ELAN sMac Table Reg4 Flow",
256 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE)),
257 mkMatches, mkInstructions);
258 mdsalManager.installFlow(flowEntity);
261 private void setupTableMissDmacFlow(BigInteger dpId) {
262 List<MatchInfo> mkMatches = new ArrayList<>();
264 List<InstructionInfo> mkInstructions = new ArrayList<>();
265 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_UNKNOWN_DMAC_TABLE));
267 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE,
268 getTableMissFlowRef(NwConstants.ELAN_DMAC_TABLE), 0, "ELAN dMac Table Miss Flow", 0, 0,
269 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
271 mdsalManager.installFlow(flowEntity);
274 private void setupExternalL2vniTableMissFlow(BigInteger dpnId) {
275 List<MatchInfo> matches = new ArrayList<>();
276 List<ActionInfo> actionsInfos = Collections.singletonList(new ActionNxResubmit(NwConstants
277 .LPORT_DISPATCHER_TABLE));
278 List<InstructionInfo> instructions = Collections.singletonList(new InstructionApplyActions(actionsInfos));
279 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
280 getTableMissFlowRef(NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE), 0,
281 "External L2VNI Table Miss Flow", 0, 0,
282 ElanConstants.COOKIE_L2VNI_DEMUX, matches, instructions);
283 mdsalManager.installFlow(flowEntity);
287 private void createL2ControlProtocolDropFlows(BigInteger dpId) {
288 List<MatchInfo> mkMatches = new ArrayList<>();
289 MatchEthernetDestination matchEthDst =
290 new MatchEthernetDestination(new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC),
291 new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK));
293 mkMatches.add(matchEthDst);
295 List<ActionInfo> listActionInfo = new ArrayList<>();
296 listActionInfo.add(new ActionDrop());
298 List<InstructionInfo> mkInstructions = new ArrayList<>();
299 mkInstructions.add(new InstructionApplyActions(listActionInfo));
301 String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "l2control"
302 + ElanConstants.L2_CONTROL_PACKETS_DMAC + ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK;
303 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 15,
304 "L2 control packets dMac Table Flow", 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches,
307 mdsalManager.installFlow(flow);
310 private String getTableMissFlowRef(long tableId) {
311 return new StringBuffer().append(tableId).toString();
315 protected ElanNodeListener getDataTreeChangeListener() {
316 return ElanNodeListener.this;
319 private void setupTableMissApResponderFlow(final BigInteger dpnId) {
320 mdsalManager.installFlow(dpnId, ArpResponderUtil.getArpResponderTableMissFlow(dpnId));
323 private void setupTableMissArpCheckFlow(BigInteger dpnId) {
324 mdsalManager.installFlow(dpnId,
325 MDSALUtil.buildFlowEntity(dpnId, NwConstants.ARP_CHECK_TABLE,
326 String.valueOf("L2.ELAN." + NwConstants.ARP_CHECK_TABLE), NwConstants.TABLE_MISS_PRIORITY,
327 ArpResponderConstant.DROP_FLOW_NAME.value(), 0, 0, NwConstants.COOKIE_ARP_RESPONDER,
328 new ArrayList<MatchInfo>(),
329 Collections.singletonList(new InstructionGotoTable(NwConstants.ELAN_BASE_TABLE))));
332 private void createArpRequestMatchFlows(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx)
333 throws ExecutionException, InterruptedException {
334 long arpRequestGroupId = ArpResponderUtil.retrieveStandardArpResponderGroupId(idManagerService);
335 List<BucketInfo> buckets = ArpResponderUtil.getDefaultBucketInfos(NwConstants.ARP_RESPONDER_TABLE);
336 ArpResponderUtil.installGroup(mdsalManager, dpId, arpRequestGroupId,
337 ArpResponderConstant.GROUP_FLOW_NAME.value(), buckets);
338 InstanceIdentifier<Group> groupIid = ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId);
339 if (tx.read(groupIid).get().isPresent()) {
340 LOG.info("group {} is present in the config hence adding the flow", arpRequestGroupId);
341 createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId,tx);
344 eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION,
345 ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId), (unused, newGroupId) -> {
346 LOG.info("group {} added in the config", arpRequestGroupId);
347 ListenableFutures.addErrorLogging(
348 txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
349 innerConfTx -> createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId,
351 LOG, "Error adding flow for the group {}",arpRequestGroupId);
352 return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
353 }, Duration.ofSeconds(5), iid -> LOG.error("arpRequestGroupId {} not found in Config datastore",
358 private void createArpRequestMatchFlowsForGroup(BigInteger dpId, long arpRequestGroupId,
359 TypedReadWriteTransaction<Configuration> tx) {
360 FlowEntity arpReqArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
361 NwConstants.ARP_REQUEST, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REQUEST), () ->
362 Arrays.asList(new ActionGroup(arpRequestGroupId),
363 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
364 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
365 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
366 LOG.trace("Invoking MDSAL to install Arp Rquest Match Flow for table {}", NwConstants.ARP_CHECK_TABLE);
367 mdsalManager.addFlow(tx, arpReqArpCheckTbl);
370 private void createArpResponseMatchFlows(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
371 FlowEntity arpRepArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
372 NwConstants.ARP_REPLY, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REPLY), () ->
373 Arrays.asList(new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
374 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
375 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
376 LOG.trace("Invoking MDSAL to install Arp Reply Match Flow for Table {} ", NwConstants.ARP_CHECK_TABLE);
377 mdsalManager.addFlow(tx, arpRepArpCheckTbl);
380 private void createArpPuntAndLearnFlow(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
381 LOG.debug("adding arp punt and learn entry in table {}", NwConstants.ARP_LEARN_TABLE_1);
383 List<MatchInfo> matches = new ArrayList<>();
384 List<ActionInfo> actions = new ArrayList<>();
385 BigInteger cookie = new BigInteger("88880000", 16);
387 matches.add(MatchEthernetType.ARP);
388 actions.add(new ActionPuntToController());
389 if (arpPuntTimeout != 0) {
390 actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
391 NwConstants.ARP_LEARN_TABLE_1, 0, 0,
393 new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
394 NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
395 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_OP.getType(),
396 NxmOfFieldType.NXM_OF_ARP_OP.getType(),
397 NxmOfFieldType.NXM_OF_ARP_OP.getFlowModHeaderLenInt()),
398 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
399 NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
400 NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
401 new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
402 MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
403 NxmOfFieldType.OXM_OF_METADATA.getType(), MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
404 ElanConstants.ELAN_TAG_LENGTH),
405 new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
407 actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
408 NwConstants.ARP_LEARN_TABLE_2, 0, 0,
410 new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
411 NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
412 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_OP.getType(),
413 NxmOfFieldType.NXM_OF_ARP_OP.getType(),
414 NxmOfFieldType.NXM_OF_ARP_OP.getFlowModHeaderLenInt()),
415 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
416 NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
417 NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
418 new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
419 MetaDataUtil.METADATA_ELAN_TAG_OFFSET, NxmOfFieldType.OXM_OF_METADATA.getType(),
420 MetaDataUtil.METADATA_ELAN_TAG_OFFSET, MetaDataUtil.METADATA_ELAN_TAG_BITLEN),
421 new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8, 8))));
424 List<InstructionInfo> instructions = new ArrayList<>();
425 instructions.add(new InstructionApplyActions(actions));
426 String flowid = String.valueOf(NwConstants.ARP_LEARN_TABLE_1) + NwConstants.FLOWID_SEPARATOR + "arp.punt";
427 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ARP_LEARN_TABLE_1, flowid,
428 NwConstants.TABLE_MISS_PRIORITY, "arp punt/learn flow", 0,
429 0, cookie, matches, instructions);
430 mdsalManager.addFlow(tx, flow);
433 private void addGarpLearnMatchFlow(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
434 List<ActionInfo> actions = new ArrayList<>();
435 List<MatchInfoBase> matches = new ArrayList<>();
437 matches.add(MatchEthernetType.ARP);
438 matches.add(new NxMatchRegister(NxmNxReg4.class, GARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
440 actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
441 actions.add(new ActionPuntToController());
442 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
443 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
445 List<InstructionInfo> instructions = new ArrayList<>();
446 instructions.add(new InstructionApplyActions(actions));
447 String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "garp.match";
448 FlowEntity garpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
449 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "GARP learn match flow", 0, 0,
450 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
451 mdsalManager.addFlow(tx, garpFlow);
454 private void addArpLearnMatchFlow(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
455 List<ActionInfo> actions = new ArrayList<>();
456 List<MatchInfoBase> matches = new ArrayList<>();
458 matches.add(MatchEthernetType.ARP);
459 matches.add(new NxMatchRegister(NxmNxReg4.class, ARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
461 actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
462 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
463 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
465 List<InstructionInfo> instructions = new ArrayList<>();
466 instructions.add(new InstructionApplyActions(actions));
467 String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "arp.match";
468 FlowEntity arpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
469 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "ARP learn match flow", 0, 0,
470 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
471 mdsalManager.addFlow(tx, arpFlow);