}
@Nonnull
- public static Map<SwitchFlowId, Flow> wrapFlowsToMap(@Nullable final List<Flow> flows) {
- final Map<SwitchFlowId, Flow> flowMap;
+ public static Map<FlowDescriptor, Flow> wrapFlowsToMap(@Nullable final List<Flow> flows) {
+ final Map<FlowDescriptor, Flow> flowMap;
if (flows == null) {
flowMap = Collections.emptyMap();
LOG.trace("flows found: {}", flows.size());
flowMap = new HashMap<>();
for (Flow flow : flows) {
- flowMap.put(new SwitchFlowId(flow), flow);
+ flowMap.put(new FlowDescriptor(flow), flow);
}
}
return flowMap;
}
- public static Flow flowMapLookupExisting(Flow flow, Map<SwitchFlowId, Flow> flowConfigMap) {
- return flowConfigMap.get(new SwitchFlowId(flow));
+ public static Flow flowMapLookupExisting(Flow flow, Map<FlowDescriptor, Flow> flowConfigMap) {
+ return flowConfigMap.get(new FlowDescriptor(flow));
}
@Nonnull
--- /dev/null
+/**
+ * Copyright (c) 2016 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowplugin.applications.frsync.util;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
+
+/**
+ * Identifier of {@link Flow} in datastore using combination of flow-id and table-id from datastore datapath.
+ */
+public class FlowDescriptor {
+
+ private final FlowId flowId;
+ private final Short tableId;
+
+ public FlowDescriptor(Flow flow) {
+ this.flowId = flow.getId();
+ this.tableId = flow.getTableId();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ FlowDescriptor that = (FlowDescriptor) o;
+ if (flowId != null ? !flowId.equals(that.flowId) : that.flowId != null) {
+ return false;
+ }
+ return tableId != null ? tableId.equals(that.tableId) : that.tableId == null;
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = flowId != null ? flowId.hashCode() : 0;
+ result = 31 * result + (tableId != null ? tableId.hashCode() : 0);
+ return result;
+ }
+
+}
* @return list of safe synchronization steps
*/
public static ItemSyncBox<Flow> resolveFlowDiffsInTable(final List<Flow> flowsConfigured,
- final Map<SwitchFlowId, Flow> flowOperationalMap,
- final boolean gatherUpdates) {
+ final Map<FlowDescriptor, Flow> flowOperationalMap,
+ final boolean gatherUpdates) {
final ItemSyncBox<Flow> flowsSyncBox = new ItemSyncBox<>();
// loop configured flows and check if already present on device
for (final Flow flow : flowsConfigured) {
// lookup table (on device)
final Table tableOperational = tableOperationalMap.get(tableConfigured.getId());
// wrap existing (on device) flows in current table into map
- final Map<SwitchFlowId, Flow> flowOperationalMap = FlowCapableNodeLookups.wrapFlowsToMap(
+ final Map<FlowDescriptor, Flow> flowOperationalMap = FlowCapableNodeLookups.wrapFlowsToMap(
tableOperational != null
? tableOperational.getFlow()
: null);
+++ /dev/null
-/**
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.applications.frsync.util;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
-
-/**
- * Identifier of {@link Flow} on device. Switch does not know about flow-id but,
- * it uses combination of these unique fields: table-id, priority, match.
- */
-public class SwitchFlowId {
-
- private final Short tableId;
-
- private final Integer priority;
-
- private final Match match;
-
- public SwitchFlowId(Flow flow) {
- this.tableId = flow.getTableId();
- this.priority = flow.getPriority();
- this.match = flow.getMatch();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- SwitchFlowId that = (SwitchFlowId) o;
-
- if (tableId != null ? !tableId.equals(that.tableId) : that.tableId != null) {
- return false;
- }
- if (priority != null ? !priority.equals(that.priority) : that.priority != null) {
- return false;
- }
- return match != null ? match.equals(that.match) : that.match == null;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((match == null) ? 0 : match.hashCode());
- result = prime * result + ((priority == null) ? 0 : priority.hashCode());
- result = prime * result + ((tableId == null) ? 0 : tableId.hashCode());
- return result;
- }
-
-}