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;
29 import org.opendaylight.genius.infra.Datastore.Configuration;
30 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
31 import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
32 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
33 import org.opendaylight.genius.infra.TypedWriteTransaction;
34 import org.opendaylight.genius.mdsalutil.ActionInfo;
35 import org.opendaylight.genius.mdsalutil.BucketInfo;
36 import org.opendaylight.genius.mdsalutil.FlowEntity;
37 import org.opendaylight.genius.mdsalutil.GroupEntity;
38 import org.opendaylight.genius.mdsalutil.InstructionInfo;
39 import org.opendaylight.genius.mdsalutil.MDSALUtil;
40 import org.opendaylight.genius.mdsalutil.MatchInfo;
41 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
42 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
43 import org.opendaylight.genius.mdsalutil.NwConstants;
44 import org.opendaylight.genius.mdsalutil.NwConstants.NxmOfFieldType;
45 import org.opendaylight.genius.mdsalutil.actions.ActionDrop;
46 import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
47 import org.opendaylight.genius.mdsalutil.actions.ActionLearn;
48 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.CopyFromValue;
49 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromField;
50 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromValue;
51 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
52 import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
53 import org.opendaylight.genius.mdsalutil.actions.ActionRegLoad;
54 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
55 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
56 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
57 import org.opendaylight.genius.mdsalutil.matches.MatchArpOp;
58 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
59 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
60 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister;
61 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
62 import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
63 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderConstant;
64 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
65 import org.opendaylight.netvirt.elan.utils.ElanConstants;
66 import org.opendaylight.netvirt.elan.utils.ElanUtils;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
76 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
81 public class ElanNodeListener extends AsyncDataTreeChangeListenerBase<Node, ElanNodeListener> {
83 private static final Logger LOG = LoggerFactory.getLogger(ElanNodeListener.class);
84 private static final int LEARN_MATCH_REG4_VALUE = 1;
85 private static final int ARP_LEARN_FLOW_PRIORITY = 10;
86 private static final int ARP_LEARN_MATCH_VALUE = 0x1;
87 private static final int GARP_LEARN_MATCH_VALUE = 0x101;
88 private static final long ARP_LEARN_MATCH_MASK = 0xFFFFL;
90 private final DataBroker broker;
91 private final ManagedNewTransactionRunner txRunner;
92 private final IMdsalApiManager mdsalManager;
93 private final IdManagerService idManagerService;
94 private final int tempSmacLearnTimeout;
95 private final int arpPuntTimeout;
96 private final boolean puntLldpToController;
97 private final JobCoordinator jobCoordinator;
98 private final DataTreeEventCallbackRegistrar eventCallbacks;
101 public ElanNodeListener(DataBroker dataBroker, IMdsalApiManager mdsalManager, ElanConfig elanConfig,
102 IdManagerService idManagerService, JobCoordinator jobCoordinator,
103 DataTreeEventCallbackRegistrar eventCallbacks) {
104 this.broker = dataBroker;
105 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
106 this.mdsalManager = mdsalManager;
107 this.tempSmacLearnTimeout = elanConfig.getTempSmacLearnTimeout();
108 this.arpPuntTimeout = elanConfig.getArpPuntTimeout().intValue();
109 this.puntLldpToController = elanConfig.isPuntLldpToController();
110 this.idManagerService = idManagerService;
111 this.jobCoordinator = jobCoordinator;
112 this.eventCallbacks = eventCallbacks;
118 registerListener(LogicalDatastoreType.OPERATIONAL, broker);
122 protected InstanceIdentifier<Node> getWildCardPath() {
123 return InstanceIdentifier.create(Nodes.class).child(Node.class);
127 protected void remove(InstanceIdentifier<Node> identifier, Node del) {
131 protected void update(InstanceIdentifier<Node> identifier, Node original, Node update) {
135 protected void add(InstanceIdentifier<Node> identifier, Node add) {
136 NodeId nodeId = add.getId();
137 String[] node = nodeId.getValue().split(":");
138 if (node.length < 2) {
139 LOG.warn("Unexpected nodeId {}", nodeId.getValue());
142 ListenableFutures.addErrorLogging(
143 txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION, tx -> {
144 BigInteger dpId = new BigInteger(node[1]);
145 createTableMissEntry(tx, dpId);
146 createMulticastFlows(tx, dpId);
147 createArpDefaultFlowsForArpCheckTable(dpId);
148 }), LOG, "Error handling ELAN node addition for {}", add);
151 private void createArpDefaultFlowsForArpCheckTable(BigInteger dpId) {
153 jobCoordinator.enqueueJob("ARP_CHECK_TABLE-" + dpId.toString(),
154 () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
156 LOG.debug("Received notification to install Arp Check Default entries for dpn {} ", dpId);
157 createArpRequestMatchFlows(dpId, tx);
158 createArpResponseMatchFlows(dpId, tx);
159 createArpPuntAndLearnFlow(dpId, tx);
160 addGarpLearnMatchFlow(dpId, tx);
161 addArpLearnMatchFlow(dpId, tx);
162 } catch (InterruptedException | ExecutionException e) {
163 LOG.error("Error programming ARP rules for dpn {}", dpId, e);
168 public void createTableMissEntry(TypedWriteTransaction<Configuration> tx, BigInteger dpnId) {
169 setupTableMissSmacFlow(tx, dpnId);
170 setupTableMissDmacFlow(tx, dpnId);
171 setupTableMissArpCheckFlow(tx, dpnId);
172 setupTableMissApResponderFlow(tx, dpnId);
173 setupExternalL2vniTableMissFlow(tx, dpnId);
176 private void createMulticastFlows(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
177 createL2ControlProtocolDropFlows(tx, dpId);
178 createMulticastPuntFlows(tx, dpId);
181 private void createMulticastPuntFlows(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
182 if (puntLldpToController) {
183 createLldpFlows(tx, dpId);
187 private void createLldpFlows(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
188 createLldpFlow(tx, dpId, ElanConstants.LLDP_DST_1, "LLDP dMac Table Flow 1");
189 createLldpFlow(tx, dpId, ElanConstants.LLDP_DST_2, "LLDP dMac Table Flow 2");
190 createLldpFlow(tx, dpId, ElanConstants.LLDP_DST_3, "LLDP dMac Table Flow 3");
193 private void createLldpFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpId, String dstMac,
195 List<MatchInfo> mkMatches = new ArrayList<>();
196 mkMatches.add(new MatchEthernetType(ElanConstants.LLDP_ETH_TYPE));
197 mkMatches.add(new MatchEthernetDestination(new MacAddress(dstMac)));
199 List<ActionInfo> listActionInfo = new ArrayList<>();
200 listActionInfo.add(new ActionPuntToController());
202 List<InstructionInfo> mkInstructions = new ArrayList<>();
203 mkInstructions.add(new InstructionApplyActions(listActionInfo));
205 String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "lldp" + ElanConstants.LLDP_ETH_TYPE + dstMac;
206 FlowEntity lldpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 16, flowName, 0, 0,
207 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
209 mdsalManager.addFlow(tx, lldpFlow);
212 private void setupTableMissSmacFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
213 List<ActionInfo> actionsInfos = new ArrayList<>();
214 actionsInfos.add(new ActionPuntToController());
215 actionsInfos.add(new ActionLearn(0, tempSmacLearnTimeout, 0, ElanConstants.COOKIE_ELAN_LEARNED_SMAC, 0,
216 NwConstants.ELAN_SMAC_LEARNED_TABLE, 0, 0,
218 new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
219 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
220 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getFlowModHeaderLenInt()),
221 new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(),
222 NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(), ElanConstants.INTERFACE_TAG_LENGTH),
223 new ActionLearn.CopyFromValue(LEARN_MATCH_REG4_VALUE,
224 NwConstants.NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
226 List<InstructionInfo> mkInstructions = new ArrayList<>();
227 mkInstructions.add(new InstructionApplyActions(actionsInfos));
228 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
230 List<MatchInfo> mkMatches = new ArrayList<>();
231 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE,
232 getTableMissFlowRef(NwConstants.ELAN_SMAC_TABLE), 0, "ELAN sMac Table Miss Flow", 0, 0,
233 ElanConstants.COOKIE_ELAN_KNOWN_SMAC, mkMatches, mkInstructions);
234 mdsalManager.addFlow(tx, flowEntity);
236 addSmacBaseTableFlow(tx, dpId);
237 addSmacLearnedTableFlow(tx, dpId);
240 private void addSmacBaseTableFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
241 // T48 - resubmit to T49 & T50
242 List<ActionInfo> actionsInfo = new ArrayList<>();
243 actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
244 actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
245 List<InstructionInfo> mkInstruct = new ArrayList<>();
246 mkInstruct.add(new InstructionApplyActions(actionsInfo));
247 List<MatchInfo> mkMatch = new ArrayList<>();
248 FlowEntity doubleResubmitTable = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE,
249 getTableMissFlowRef(NwConstants.ELAN_BASE_TABLE), 0, "Elan sMac resubmit table", 0, 0,
250 ElanConstants.COOKIE_ELAN_BASE_SMAC, mkMatch, mkInstruct);
251 mdsalManager.addFlow(tx, doubleResubmitTable);
254 private void addSmacLearnedTableFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
255 // T50 - match on Reg4 and goto T51
256 List<MatchInfoBase> mkMatches = new ArrayList<>();
257 mkMatches.add(new NxMatchRegister(NxmNxReg4.class, LEARN_MATCH_REG4_VALUE));
258 List<InstructionInfo> mkInstructions = new ArrayList<>();
259 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
260 String flowRef = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(NwConstants.FLOWID_SEPARATOR)
261 .append(LEARN_MATCH_REG4_VALUE).toString();
262 FlowEntity flowEntity =
263 MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef, 10, "ELAN sMac Table Reg4 Flow",
264 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_SMAC.add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE)),
265 mkMatches, mkInstructions);
266 mdsalManager.addFlow(tx, flowEntity);
269 private void setupTableMissDmacFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
270 List<MatchInfo> mkMatches = new ArrayList<>();
272 List<InstructionInfo> mkInstructions = new ArrayList<>();
273 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_UNKNOWN_DMAC_TABLE));
275 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE,
276 getTableMissFlowRef(NwConstants.ELAN_DMAC_TABLE), 0, "ELAN dMac Table Miss Flow", 0, 0,
277 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
279 mdsalManager.addFlow(tx, flowEntity);
282 private void setupExternalL2vniTableMissFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpnId) {
283 List<MatchInfo> matches = new ArrayList<>();
284 List<ActionInfo> actionsInfos = Collections.singletonList(new ActionNxResubmit(NwConstants
285 .LPORT_DISPATCHER_TABLE));
286 List<InstructionInfo> instructions = Collections.singletonList(new InstructionApplyActions(actionsInfos));
287 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
288 getTableMissFlowRef(NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE), 0,
289 "External L2VNI Table Miss Flow", 0, 0,
290 ElanConstants.COOKIE_L2VNI_DEMUX, matches, instructions);
291 mdsalManager.addFlow(tx, flowEntity);
295 private void createL2ControlProtocolDropFlows(TypedWriteTransaction<Configuration> tx, BigInteger dpId) {
296 List<MatchInfo> mkMatches = new ArrayList<>();
297 MatchEthernetDestination matchEthDst =
298 new MatchEthernetDestination(new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC),
299 new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK));
301 mkMatches.add(matchEthDst);
303 List<ActionInfo> listActionInfo = new ArrayList<>();
304 listActionInfo.add(new ActionDrop());
306 List<InstructionInfo> mkInstructions = new ArrayList<>();
307 mkInstructions.add(new InstructionApplyActions(listActionInfo));
309 String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "l2control"
310 + ElanConstants.L2_CONTROL_PACKETS_DMAC + ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK;
311 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 15,
312 "L2 control packets dMac Table Flow", 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches,
315 mdsalManager.addFlow(tx, flow);
318 private String getTableMissFlowRef(long tableId) {
319 return String.valueOf(tableId);
323 protected ElanNodeListener getDataTreeChangeListener() {
324 return ElanNodeListener.this;
327 private void setupTableMissApResponderFlow(TypedWriteTransaction<Configuration> tx, final BigInteger dpnId) {
328 mdsalManager.addFlow(tx, ArpResponderUtil.getArpResponderTableMissFlow(dpnId));
331 private void setupTableMissArpCheckFlow(TypedWriteTransaction<Configuration> tx, BigInteger dpnId) {
332 mdsalManager.addFlow(tx,
333 MDSALUtil.buildFlowEntity(dpnId, NwConstants.ARP_CHECK_TABLE,
334 String.valueOf("L2.ELAN." + NwConstants.ARP_CHECK_TABLE), NwConstants.TABLE_MISS_PRIORITY,
335 ArpResponderConstant.DROP_FLOW_NAME.value(), 0, 0, NwConstants.COOKIE_ARP_RESPONDER,
336 new ArrayList<MatchInfo>(),
337 Collections.singletonList(new InstructionGotoTable(NwConstants.ELAN_BASE_TABLE))));
340 private void createArpRequestMatchFlows(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx)
341 throws ExecutionException, InterruptedException {
342 long arpRequestGroupId = ArpResponderUtil.retrieveStandardArpResponderGroupId(idManagerService);
343 List<BucketInfo> buckets = ArpResponderUtil.getDefaultBucketInfos(NwConstants.ARP_RESPONDER_TABLE);
344 LOG.trace("Installing group flow on dpn {}", dpId);
345 GroupEntity groupEntity =
346 MDSALUtil.buildGroupEntity(dpId, arpRequestGroupId, ArpResponderConstant.GROUP_FLOW_NAME.value(),
347 GroupTypes.GroupAll, buckets);
348 mdsalManager.addGroup(tx, groupEntity);
349 InstanceIdentifier<Group> groupIid = ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId);
350 if (tx.read(groupIid).get().isPresent()) {
351 LOG.info("group {} is present in the config hence adding the flow", arpRequestGroupId);
352 createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId,tx);
355 eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION,
356 ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId), (unused, newGroupId) -> {
357 LOG.info("group {} added in the config", arpRequestGroupId);
358 ListenableFutures.addErrorLogging(
359 txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
360 innerConfTx -> createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId,
362 LOG, "Error adding flow for the group {}",arpRequestGroupId);
363 return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
364 }, Duration.ofSeconds(5), iid -> LOG.error("arpRequestGroupId {} not found in Config datastore",
369 private void createArpRequestMatchFlowsForGroup(BigInteger dpId, long arpRequestGroupId,
370 TypedReadWriteTransaction<Configuration> tx) {
371 FlowEntity arpReqArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
372 NwConstants.ARP_REQUEST, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REQUEST), () ->
373 Arrays.asList(new ActionGroup(arpRequestGroupId),
374 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
375 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
376 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
377 LOG.trace("Invoking MDSAL to install Arp Rquest Match Flow for table {}", NwConstants.ARP_CHECK_TABLE);
378 mdsalManager.addFlow(tx, arpReqArpCheckTbl);
381 private void createArpResponseMatchFlows(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
382 FlowEntity arpRepArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
383 NwConstants.ARP_REPLY, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REPLY), () ->
384 Arrays.asList(new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
385 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
386 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
387 LOG.trace("Invoking MDSAL to install Arp Reply Match Flow for Table {} ", NwConstants.ARP_CHECK_TABLE);
388 mdsalManager.addFlow(tx, arpRepArpCheckTbl);
391 private void createArpPuntAndLearnFlow(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
392 LOG.debug("adding arp punt and learn entry in table {}", NwConstants.ARP_LEARN_TABLE_1);
394 List<MatchInfo> matches = new ArrayList<>();
395 List<ActionInfo> actions = new ArrayList<>();
396 BigInteger cookie = new BigInteger("88880000", 16);
398 matches.add(MatchEthernetType.ARP);
399 actions.add(new ActionPuntToController());
400 if (arpPuntTimeout != 0) {
401 actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
402 NwConstants.ARP_LEARN_TABLE_1, 0, 0,
404 new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
405 NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
406 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_OP.getType(),
407 NxmOfFieldType.NXM_OF_ARP_OP.getType(),
408 NxmOfFieldType.NXM_OF_ARP_OP.getFlowModHeaderLenInt()),
409 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
410 NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
411 NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
412 new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
413 MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
414 NxmOfFieldType.OXM_OF_METADATA.getType(), MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
415 ElanConstants.ELAN_TAG_LENGTH),
416 new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
418 actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
419 NwConstants.ARP_LEARN_TABLE_2, 0, 0,
421 new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
422 NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
423 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_OP.getType(),
424 NxmOfFieldType.NXM_OF_ARP_OP.getType(),
425 NxmOfFieldType.NXM_OF_ARP_OP.getFlowModHeaderLenInt()),
426 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
427 NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
428 NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
429 new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
430 MetaDataUtil.METADATA_ELAN_TAG_OFFSET, NxmOfFieldType.OXM_OF_METADATA.getType(),
431 MetaDataUtil.METADATA_ELAN_TAG_OFFSET, MetaDataUtil.METADATA_ELAN_TAG_BITLEN),
432 new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8, 8))));
435 List<InstructionInfo> instructions = new ArrayList<>();
436 instructions.add(new InstructionApplyActions(actions));
437 String flowid = String.valueOf(NwConstants.ARP_LEARN_TABLE_1) + NwConstants.FLOWID_SEPARATOR + "arp.punt";
438 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ARP_LEARN_TABLE_1, flowid,
439 NwConstants.TABLE_MISS_PRIORITY, "arp punt/learn flow", 0,
440 0, cookie, matches, instructions);
441 mdsalManager.addFlow(tx, flow);
444 private void addGarpLearnMatchFlow(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
445 List<ActionInfo> actions = new ArrayList<>();
446 List<MatchInfoBase> matches = new ArrayList<>();
448 matches.add(MatchEthernetType.ARP);
449 matches.add(new NxMatchRegister(NxmNxReg4.class, GARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
451 actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
452 actions.add(new ActionPuntToController());
453 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
454 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
456 List<InstructionInfo> instructions = new ArrayList<>();
457 instructions.add(new InstructionApplyActions(actions));
458 String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "garp.match";
459 FlowEntity garpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
460 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "GARP learn match flow", 0, 0,
461 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
462 mdsalManager.addFlow(tx, garpFlow);
465 private void addArpLearnMatchFlow(BigInteger dpId, TypedReadWriteTransaction<Configuration> tx) {
466 List<ActionInfo> actions = new ArrayList<>();
467 List<MatchInfoBase> matches = new ArrayList<>();
469 matches.add(MatchEthernetType.ARP);
470 matches.add(new NxMatchRegister(NxmNxReg4.class, ARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
472 actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
473 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
474 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
476 List<InstructionInfo> instructions = new ArrayList<>();
477 instructions.add(new InstructionApplyActions(actions));
478 String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "arp.match";
479 FlowEntity arpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
480 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "ARP learn match flow", 0, 0,
481 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
482 mdsalManager.addFlow(tx, arpFlow);