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.infrautils.utils.concurrent.LoggingFutures.addErrorLogging;
11 import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
13 import java.math.BigInteger;
14 import java.time.Duration;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.Collections;
18 import java.util.List;
19 import java.util.concurrent.ExecutionException;
20 import javax.annotation.PreDestroy;
21 import javax.inject.Inject;
22 import javax.inject.Singleton;
23 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
24 import org.opendaylight.genius.mdsalutil.ActionInfo;
25 import org.opendaylight.genius.mdsalutil.BucketInfo;
26 import org.opendaylight.genius.mdsalutil.FlowEntity;
27 import org.opendaylight.genius.mdsalutil.GroupEntity;
28 import org.opendaylight.genius.mdsalutil.InstructionInfo;
29 import org.opendaylight.genius.mdsalutil.MDSALUtil;
30 import org.opendaylight.genius.mdsalutil.MatchInfo;
31 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
32 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
33 import org.opendaylight.genius.mdsalutil.NwConstants;
34 import org.opendaylight.genius.mdsalutil.NwConstants.NxmOfFieldType;
35 import org.opendaylight.genius.mdsalutil.actions.ActionDrop;
36 import org.opendaylight.genius.mdsalutil.actions.ActionGroup;
37 import org.opendaylight.genius.mdsalutil.actions.ActionLearn;
38 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.CopyFromValue;
39 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromField;
40 import org.opendaylight.genius.mdsalutil.actions.ActionLearn.MatchFromValue;
41 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
42 import org.opendaylight.genius.mdsalutil.actions.ActionPuntToController;
43 import org.opendaylight.genius.mdsalutil.actions.ActionRegLoad;
44 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
45 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
46 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
47 import org.opendaylight.genius.mdsalutil.matches.MatchArpOp;
48 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination;
49 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
50 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchRegister;
51 import org.opendaylight.infrautils.jobcoordinator.JobCoordinator;
52 import org.opendaylight.infrautils.utils.concurrent.Executors;
53 import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
54 import org.opendaylight.mdsal.binding.api.DataBroker;
55 import org.opendaylight.mdsal.binding.util.Datastore.Configuration;
56 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
57 import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
58 import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
59 import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
60 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
61 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderConstant;
62 import org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil;
63 import org.opendaylight.netvirt.elan.utils.ElanConstants;
64 import org.opendaylight.netvirt.elan.utils.ElanUtils;
65 import org.opendaylight.serviceutils.tools.listener.AbstractAsyncDataTreeChangeListener;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.config.rev150710.ElanConfig;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
75 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
76 import org.opendaylight.yangtools.yang.common.Uint64;
77 import org.slf4j.Logger;
78 import org.slf4j.LoggerFactory;
81 public class ElanNodeListener extends AbstractAsyncDataTreeChangeListener<Node> {
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 super(dataBroker, LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class).child(Node.class),
105 Executors.newListeningSingleThreadExecutor("ElanNodeListener", LOG));
106 this.broker = dataBroker;
107 this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
108 this.mdsalManager = mdsalManager;
109 this.tempSmacLearnTimeout = elanConfig.getTempSmacLearnTimeout().toJava();
110 this.arpPuntTimeout = elanConfig.getArpPuntTimeout().intValue();
111 this.puntLldpToController = elanConfig.isPuntLldpToController();
112 this.idManagerService = idManagerService;
113 this.jobCoordinator = jobCoordinator;
114 this.eventCallbacks = eventCallbacks;
118 LOG.info("{} registered", getClass().getSimpleName());
123 public void close() {
125 Executors.shutdownAndAwaitTermination(getExecutorService());
129 public void remove(InstanceIdentifier<Node> identifier, Node del) {
133 public void update(InstanceIdentifier<Node> identifier, Node original, Node update) {
137 public void add(InstanceIdentifier<Node> identifier, Node add) {
138 NodeId nodeId = add.getId();
139 String[] node = nodeId.getValue().split(":");
140 if (node.length < 2) {
141 LOG.warn("Unexpected nodeId {}", nodeId.getValue());
144 addErrorLogging(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, tx -> {
145 Uint64 dpId = Uint64.valueOf(node[1]);
146 createTableMissEntry(tx, dpId);
147 createMulticastFlows(tx, dpId);
148 createArpDefaultFlowsForArpCheckTable(dpId);
149 }), LOG, "Error handling ELAN node addition for {}", add);
152 private void createArpDefaultFlowsForArpCheckTable(Uint64 dpId) {
154 jobCoordinator.enqueueJob("ARP_CHECK_TABLE-" + dpId.toString(),
155 () -> Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
157 LOG.debug("Received notification to install Arp Check Default entries for dpn {} ", dpId);
158 createArpRequestMatchFlows(dpId, tx);
159 createArpResponseMatchFlows(dpId, tx);
160 createArpPuntAndLearnFlow(dpId, tx);
161 addGarpLearnMatchFlow(dpId, tx);
162 addArpLearnMatchFlow(dpId, tx);
163 } catch (InterruptedException | ExecutionException e) {
164 LOG.error("Error programming ARP rules for dpn {}", dpId, e);
169 public void createTableMissEntry(TypedWriteTransaction<Configuration> tx, Uint64 dpnId) {
170 setupTableMissSmacFlow(tx, dpnId);
171 setupTableMissDmacFlow(tx, dpnId);
172 setupTableMissArpCheckFlow(tx, dpnId);
173 setupTableMissApResponderFlow(tx, dpnId);
174 setupExternalL2vniTableMissFlow(tx, dpnId);
177 private void createMulticastFlows(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
178 createL2ControlProtocolDropFlows(tx, dpId);
179 createMulticastPuntFlows(tx, dpId);
182 private void createMulticastPuntFlows(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
183 if (puntLldpToController) {
184 createLldpFlows(tx, dpId);
188 private void createLldpFlows(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
189 createLldpFlow(tx, dpId, ElanConstants.LLDP_DST_1, "LLDP dMac Table Flow 1");
190 createLldpFlow(tx, dpId, ElanConstants.LLDP_DST_2, "LLDP dMac Table Flow 2");
191 createLldpFlow(tx, dpId, ElanConstants.LLDP_DST_3, "LLDP dMac Table Flow 3");
194 private void createLldpFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpId, String dstMac,
196 List<MatchInfo> mkMatches = new ArrayList<>();
197 mkMatches.add(new MatchEthernetType(ElanConstants.LLDP_ETH_TYPE));
198 mkMatches.add(new MatchEthernetDestination(new MacAddress(dstMac)));
200 List<ActionInfo> listActionInfo = new ArrayList<>();
201 listActionInfo.add(new ActionPuntToController());
203 List<InstructionInfo> mkInstructions = new ArrayList<>();
204 mkInstructions.add(new InstructionApplyActions(listActionInfo));
206 String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "lldp" + ElanConstants.LLDP_ETH_TYPE + dstMac;
207 FlowEntity lldpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 16, flowName, 0, 0,
208 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
210 mdsalManager.addFlow(tx, lldpFlow);
213 private void setupTableMissSmacFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
214 List<ActionInfo> actionsInfos = new ArrayList<>();
215 actionsInfos.add(new ActionPuntToController());
216 actionsInfos.add(new ActionLearn(0, tempSmacLearnTimeout, 0, ElanConstants.COOKIE_ELAN_LEARNED_SMAC, 0,
217 NwConstants.ELAN_SMAC_LEARNED_TABLE, 0, 0,
219 new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
220 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getType(),
221 NwConstants.NxmOfFieldType.NXM_OF_ETH_SRC.getFlowModHeaderLenInt()),
222 new ActionLearn.MatchFromField(NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(),
223 NwConstants.NxmOfFieldType.NXM_NX_REG1.getType(), ElanConstants.INTERFACE_TAG_LENGTH),
224 new ActionLearn.CopyFromValue(LEARN_MATCH_REG4_VALUE,
225 NwConstants.NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
227 List<InstructionInfo> mkInstructions = new ArrayList<>();
228 mkInstructions.add(new InstructionApplyActions(actionsInfos));
229 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
231 List<MatchInfo> mkMatches = new ArrayList<>();
232 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE,
233 getTableMissFlowRef(NwConstants.ELAN_SMAC_TABLE), 0, "ELAN sMac Table Miss Flow", 0, 0,
234 ElanConstants.COOKIE_ELAN_KNOWN_SMAC, mkMatches, mkInstructions);
235 mdsalManager.addFlow(tx, flowEntity);
237 addSmacBaseTableFlow(tx, dpId);
238 addSmacLearnedTableFlow(tx, dpId);
241 private void addSmacBaseTableFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
242 // T48 - resubmit to T49 & T50
243 List<ActionInfo> actionsInfo = new ArrayList<>();
244 actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
245 actionsInfo.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
246 List<InstructionInfo> mkInstruct = new ArrayList<>();
247 mkInstruct.add(new InstructionApplyActions(actionsInfo));
248 List<MatchInfo> mkMatch = new ArrayList<>();
249 FlowEntity doubleResubmitTable = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE,
250 getTableMissFlowRef(NwConstants.ELAN_BASE_TABLE), 0, "Elan sMac resubmit table", 0, 0,
251 ElanConstants.COOKIE_ELAN_BASE_SMAC, mkMatch, mkInstruct);
252 mdsalManager.addFlow(tx, doubleResubmitTable);
255 private void addSmacLearnedTableFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
256 // T50 - match on Reg4 and goto T51
257 List<MatchInfoBase> mkMatches = new ArrayList<>();
258 mkMatches.add(new NxMatchRegister(NxmNxReg4.class, LEARN_MATCH_REG4_VALUE));
259 List<InstructionInfo> mkInstructions = new ArrayList<>();
260 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_DMAC_TABLE));
261 String flowRef = new StringBuilder().append(NwConstants.ELAN_SMAC_TABLE).append(NwConstants.FLOWID_SEPARATOR)
262 .append(LEARN_MATCH_REG4_VALUE).toString();
263 FlowEntity flowEntity =
264 MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_SMAC_TABLE, flowRef, 10, "ELAN sMac Table Reg4 Flow",
265 0, 0, Uint64.valueOf(ElanConstants.COOKIE_ELAN_KNOWN_SMAC.toJava()
266 .add(BigInteger.valueOf(LEARN_MATCH_REG4_VALUE))),
267 mkMatches, mkInstructions);
268 mdsalManager.addFlow(tx, flowEntity);
271 private void setupTableMissDmacFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
272 List<MatchInfo> mkMatches = new ArrayList<>();
274 List<InstructionInfo> mkInstructions = new ArrayList<>();
275 mkInstructions.add(new InstructionGotoTable(NwConstants.ELAN_UNKNOWN_DMAC_TABLE));
277 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE,
278 getTableMissFlowRef(NwConstants.ELAN_DMAC_TABLE), 0, "ELAN dMac Table Miss Flow", 0, 0,
279 ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches, mkInstructions);
281 mdsalManager.addFlow(tx, flowEntity);
284 private void setupExternalL2vniTableMissFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpnId) {
285 List<MatchInfo> matches = new ArrayList<>();
286 List<ActionInfo> actionsInfos = Collections.singletonList(new ActionNxResubmit(NwConstants
287 .LPORT_DISPATCHER_TABLE));
288 List<InstructionInfo> instructions = Collections.singletonList(new InstructionApplyActions(actionsInfos));
289 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE,
290 getTableMissFlowRef(NwConstants.L2VNI_EXTERNAL_TUNNEL_DEMUX_TABLE), 0,
291 "External L2VNI Table Miss Flow", 0, 0,
292 ElanConstants.COOKIE_L2VNI_DEMUX, matches, instructions);
293 mdsalManager.addFlow(tx, flowEntity);
297 private void createL2ControlProtocolDropFlows(TypedWriteTransaction<Configuration> tx, Uint64 dpId) {
298 List<MatchInfo> mkMatches = new ArrayList<>();
299 MatchEthernetDestination matchEthDst =
300 new MatchEthernetDestination(new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC),
301 new MacAddress(ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK));
303 mkMatches.add(matchEthDst);
305 List<ActionInfo> listActionInfo = new ArrayList<>();
306 listActionInfo.add(new ActionDrop());
308 List<InstructionInfo> mkInstructions = new ArrayList<>();
309 mkInstructions.add(new InstructionApplyActions(listActionInfo));
311 String flowId = dpId.toString() + NwConstants.ELAN_DMAC_TABLE + "l2control"
312 + ElanConstants.L2_CONTROL_PACKETS_DMAC + ElanConstants.L2_CONTROL_PACKETS_DMAC_MASK;
313 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_DMAC_TABLE, flowId, 15,
314 "L2 control packets dMac Table Flow", 0, 0, ElanConstants.COOKIE_ELAN_KNOWN_DMAC, mkMatches,
317 mdsalManager.addFlow(tx, flow);
320 private static String getTableMissFlowRef(long tableId) {
321 return String.valueOf(tableId);
324 private void setupTableMissApResponderFlow(TypedWriteTransaction<Configuration> tx, final Uint64 dpnId) {
325 mdsalManager.addFlow(tx, ArpResponderUtil.getArpResponderTableMissFlow(dpnId));
328 private void setupTableMissArpCheckFlow(TypedWriteTransaction<Configuration> tx, Uint64 dpnId) {
329 mdsalManager.addFlow(tx,
330 MDSALUtil.buildFlowEntity(dpnId, NwConstants.ARP_CHECK_TABLE,
331 String.valueOf("L2.ELAN." + NwConstants.ARP_CHECK_TABLE), NwConstants.TABLE_MISS_PRIORITY,
332 ArpResponderConstant.DROP_FLOW_NAME.value(), 0, 0, NwConstants.COOKIE_ARP_RESPONDER,
333 new ArrayList<MatchInfo>(),
334 Collections.singletonList(new InstructionGotoTable(NwConstants.ELAN_BASE_TABLE))));
337 private void createArpRequestMatchFlows(Uint64 dpId, TypedReadWriteTransaction<Configuration> tx)
338 throws ExecutionException, InterruptedException {
339 long arpRequestGroupId = ArpResponderUtil.retrieveStandardArpResponderGroupId(idManagerService);
340 List<BucketInfo> buckets = ArpResponderUtil.getDefaultBucketInfos(NwConstants.ARP_RESPONDER_TABLE);
341 LOG.trace("Installing group flow on dpn {}", dpId);
342 GroupEntity groupEntity =
343 MDSALUtil.buildGroupEntity(dpId, arpRequestGroupId, ArpResponderConstant.GROUP_FLOW_NAME.value(),
344 GroupTypes.GroupAll, buckets);
345 mdsalManager.addGroup(tx, groupEntity);
346 InstanceIdentifier<Group> groupIid = ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId);
347 if (tx.read(groupIid).get().isPresent()) {
348 LOG.info("group {} is present in the config hence adding the flow", arpRequestGroupId);
349 createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId,tx);
352 eventCallbacks.onAddOrUpdate(LogicalDatastoreType.CONFIGURATION,
353 ElanUtils.getGroupInstanceid(dpId, arpRequestGroupId), (unused, newGroupId) -> {
354 LOG.info("group {} added in the config", arpRequestGroupId);
355 LoggingFutures.addErrorLogging(
356 txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
357 innerConfTx -> createArpRequestMatchFlowsForGroup(dpId, arpRequestGroupId,
359 LOG, "Error adding flow for the group {}",arpRequestGroupId);
360 return DataTreeEventCallbackRegistrar.NextAction.UNREGISTER;
361 }, Duration.ofSeconds(5), iid -> LOG.error("arpRequestGroupId {} not found in Config datastore",
366 private void createArpRequestMatchFlowsForGroup(Uint64 dpId, long arpRequestGroupId,
367 TypedReadWriteTransaction<Configuration> tx) {
368 FlowEntity arpReqArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
369 NwConstants.ARP_REQUEST, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REQUEST), () ->
370 Arrays.asList(new ActionGroup(arpRequestGroupId),
371 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
372 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
373 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
374 LOG.trace("Invoking MDSAL to install Arp Rquest Match Flow for table {}", NwConstants.ARP_CHECK_TABLE);
375 mdsalManager.addFlow(tx, arpReqArpCheckTbl);
378 private void createArpResponseMatchFlows(Uint64 dpId, TypedReadWriteTransaction<Configuration> tx) {
379 FlowEntity arpRepArpCheckTbl = ArpResponderUtil.createArpDefaultFlow(dpId, NwConstants.ARP_CHECK_TABLE,
380 NwConstants.ARP_REPLY, () -> Arrays.asList(MatchEthernetType.ARP, MatchArpOp.REPLY), () ->
381 Arrays.asList(new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_1),
382 new ActionNxResubmit(NwConstants.ARP_LEARN_TABLE_2),
383 new ActionNxResubmit(NwConstants.ELAN_BASE_TABLE)));
384 LOG.trace("Invoking MDSAL to install Arp Reply Match Flow for Table {} ", NwConstants.ARP_CHECK_TABLE);
385 mdsalManager.addFlow(tx, arpRepArpCheckTbl);
388 private void createArpPuntAndLearnFlow(Uint64 dpId, TypedReadWriteTransaction<Configuration> tx) {
389 LOG.debug("adding arp punt and learn entry in table {}", NwConstants.ARP_LEARN_TABLE_1);
391 List<MatchInfo> matches = new ArrayList<>();
392 List<ActionInfo> actions = new ArrayList<>();
393 Uint64 cookie = Uint64.valueOf("88880000", 16).intern();
395 matches.add(MatchEthernetType.ARP);
396 actions.add(new ActionPuntToController());
397 if (arpPuntTimeout != 0) {
398 actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
399 NwConstants.ARP_LEARN_TABLE_1, 0, 0,
401 new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
402 NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
403 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_OP.getType(),
404 NxmOfFieldType.NXM_OF_ARP_OP.getType(),
405 NxmOfFieldType.NXM_OF_ARP_OP.getFlowModHeaderLenInt()),
406 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
407 NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
408 NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
409 new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
410 MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
411 NxmOfFieldType.OXM_OF_METADATA.getType(), MetaDataUtil.METADATA_ELAN_TAG_OFFSET,
412 ElanConstants.ELAN_TAG_LENGTH),
413 new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8))));
415 actions.add(new ActionLearn(0, arpPuntTimeout, ARP_LEARN_FLOW_PRIORITY, cookie, 0,
416 NwConstants.ARP_LEARN_TABLE_2, 0, 0,
418 new MatchFromValue(NwConstants.ETHTYPE_ARP, NxmOfFieldType.NXM_OF_ETH_TYPE.getType(),
419 NxmOfFieldType.NXM_OF_ETH_TYPE.getFlowModHeaderLenInt()),
420 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_OP.getType(),
421 NxmOfFieldType.NXM_OF_ARP_OP.getType(),
422 NxmOfFieldType.NXM_OF_ARP_OP.getFlowModHeaderLenInt()),
423 new MatchFromField(NxmOfFieldType.NXM_OF_ARP_TPA.getType(),
424 NxmOfFieldType.NXM_OF_ARP_SPA.getType(),
425 NxmOfFieldType.NXM_OF_ARP_TPA.getFlowModHeaderLenInt()),
426 new ActionLearn.MatchFromField(NxmOfFieldType.OXM_OF_METADATA.getType(),
427 MetaDataUtil.METADATA_ELAN_TAG_OFFSET, NxmOfFieldType.OXM_OF_METADATA.getType(),
428 MetaDataUtil.METADATA_ELAN_TAG_OFFSET, MetaDataUtil.METADATA_ELAN_TAG_BITLEN),
429 new CopyFromValue(1, NxmOfFieldType.NXM_NX_REG4.getType(), 8, 8))));
432 List<InstructionInfo> instructions = new ArrayList<>();
433 instructions.add(new InstructionApplyActions(actions));
434 String flowid = String.valueOf(NwConstants.ARP_LEARN_TABLE_1) + NwConstants.FLOWID_SEPARATOR + "arp.punt";
435 FlowEntity flow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ARP_LEARN_TABLE_1, flowid,
436 NwConstants.TABLE_MISS_PRIORITY, "arp punt/learn flow", 0,
437 0, cookie, matches, instructions);
438 mdsalManager.addFlow(tx, flow);
441 private void addGarpLearnMatchFlow(Uint64 dpId, TypedReadWriteTransaction<Configuration> tx) {
442 List<ActionInfo> actions = new ArrayList<>();
443 List<MatchInfoBase> matches = new ArrayList<>();
445 matches.add(MatchEthernetType.ARP);
446 matches.add(new NxMatchRegister(NxmNxReg4.class, GARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
448 actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
449 actions.add(new ActionPuntToController());
450 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
451 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
453 List<InstructionInfo> instructions = new ArrayList<>();
454 instructions.add(new InstructionApplyActions(actions));
455 String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "garp.match";
456 FlowEntity garpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
457 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "GARP learn match flow", 0, 0,
458 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
459 mdsalManager.addFlow(tx, garpFlow);
462 private void addArpLearnMatchFlow(Uint64 dpId, TypedReadWriteTransaction<Configuration> tx) {
463 List<ActionInfo> actions = new ArrayList<>();
464 List<MatchInfoBase> matches = new ArrayList<>();
466 matches.add(MatchEthernetType.ARP);
467 matches.add(new NxMatchRegister(NxmNxReg4.class, ARP_LEARN_MATCH_VALUE, ARP_LEARN_MATCH_MASK));
469 actions.add(new ActionRegLoad(NxmNxReg4.class, 0, 31, 0));
470 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_LEARNED_TABLE));
471 actions.add(new ActionNxResubmit(NwConstants.ELAN_SMAC_TABLE));
473 List<InstructionInfo> instructions = new ArrayList<>();
474 instructions.add(new InstructionApplyActions(actions));
475 String flowid = String.valueOf(NwConstants.ELAN_BASE_TABLE) + NwConstants.FLOWID_SEPARATOR + "arp.match";
476 FlowEntity arpFlow = MDSALUtil.buildFlowEntity(dpId, NwConstants.ELAN_BASE_TABLE, flowid,
477 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, "ARP learn match flow", 0, 0,
478 ElanConstants.COOKIE_ELAN_BASE_SMAC, matches, instructions);
479 mdsalManager.addFlow(tx, arpFlow);