import org.opendaylight.openflowplugin.api.openflow.flow.registry.FlowRegistryException;
import org.opendaylight.openflowplugin.impl.flow.registry.FlowHashFactory;
import org.opendaylight.openflowplugin.impl.statistics.services.dedicated.StatisticsGatheringService;
+import org.opendaylight.openflowplugin.impl.util.FlowUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) {
final FlowBuilder flowBuilder = new FlowBuilder(flowStat);
FlowId flowId = null;
+ FlowHash flowHash = FlowHashFactory.create(flowBuilder.build());
try {
- FlowHash flowHash = FlowHashFactory.create(flowBuilder.build());
flowId = deviceContext.getFlowRegistry().retrieveIdForFlow(flowHash);
} catch (FlowRegistryException e) {
- LOG.trace("No flowId found in device's flow registry for flow retrieved by statistics.");
- //TODO : create alien ID for flow
+ flowId = FlowUtil.createAlienFlowId(flowStat.getTableId());
+ deviceContext.getFlowRegistry().store(flowHash, flowId);
}
FlowKey flowKey = new FlowKey(flowId);
flowBuilder.setKey(flowKey);
--- /dev/null
+/*
+ * Copyright (c) 2015 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.impl.util;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
+
+/**
+ * Created by Martin Bobak <mbobak@cisco.com> on 8.4.2015.
+ */
+public final class FlowUtil {
+
+ private static final String ALIEN_SYSTEM_FLOW_ID = "#UF$TABLE*";
+ private static final AtomicInteger unaccountedFlowsCounter = new AtomicInteger(0);
+
+
+ private FlowUtil() {
+ throw new IllegalStateException("This class should not be instantiated.");
+ }
+
+ public static FlowId createAlienFlowId(final Short tableId) {
+ final StringBuilder sBuilder = new StringBuilder(ALIEN_SYSTEM_FLOW_ID)
+ .append(tableId).append("-").append(unaccountedFlowsCounter.incrementAndGet());
+ return new FlowId(sBuilder.toString());
+
+ }
+}