introduced FlowUtils that creates alien ids 30/17930/1
authorMartin Bobak <mbobak@cisco.com>
Wed, 8 Apr 2015 13:12:15 +0000 (15:12 +0200)
committerMartin Bobak <mbobak@cisco.com>
Wed, 8 Apr 2015 13:57:47 +0000 (15:57 +0200)
Change-Id: I939ebc15e03cc450771d4644f2f23934a586688f
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/FlowUtil.java [new file with mode: 0644]

index 830ff783108d6fce921470c5070d8e7d21165c7a..db92a0ef254ea4614394a9581b2febaac7727697 100644 (file)
@@ -20,6 +20,7 @@ import org.opendaylight.openflowplugin.api.openflow.flow.registry.FlowHash;
 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;
@@ -225,12 +226,12 @@ public final class StatisticsGatheringUtils {
                                 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);
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/FlowUtil.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/util/FlowUtil.java
new file mode 100644 (file)
index 0000000..5c83a17
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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 &lt;mbobak@cisco.com&gt; 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());
+
+    }
+}