--- /dev/null
+/**\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowplugin.applications.frsync.dao;\r
+\r
+import javax.annotation.Nonnull;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+\r
+import com.google.common.base.Optional;\r
+\r
+/**\r
+ * Implementation of data access object for {@link FlowCapableNode}.\r
+ * Contains pair of snapshot and odl DAOs.\r
+ */\r
+public class FlowCapableNodeCachedDao implements FlowCapableNodeDao {\r
+\r
+ private final FlowCapableNodeDao snapshotDao;\r
+ private final FlowCapableNodeDao odlDao;\r
+\r
+ public FlowCapableNodeCachedDao(FlowCapableNodeDao snapshotDao, FlowCapableNodeDao odlDao) {\r
+ this.snapshotDao = snapshotDao;\r
+ this.odlDao = odlDao;\r
+ }\r
+\r
+ public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {\r
+ final Optional<FlowCapableNode> node = snapshotDao.loadByNodeId(nodeId);\r
+\r
+ if (node.isPresent()) {\r
+ return node;\r
+ }\r
+\r
+ return odlDao.loadByNodeId(nodeId);\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowplugin.applications.frsync.dao;\r
+\r
+import javax.annotation.Nonnull;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+\r
+import com.google.common.base.Optional;\r
+\r
+/**\r
+ * Data access object for {@link FlowCapableNode}.\r
+ */\r
+public interface FlowCapableNodeDao {\r
+ Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId);\r
+}\r
--- /dev/null
+/**\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowplugin.applications.frsync.dao;\r
+\r
+import com.google.common.base.Optional;\r
+\r
+import java.util.concurrent.TimeUnit;\r
+import java.util.concurrent.TimeoutException;\r
+\r
+import javax.annotation.Nonnull;\r
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;\r
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;\r
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+/**\r
+ * Implementation of data access object for ODL {@link FlowCapableNode}.\r
+ */\r
+public class FlowCapableNodeOdlDao implements FlowCapableNodeDao {\r
+\r
+ private static final Logger LOG = LoggerFactory.getLogger(FlowCapableNodeOdlDao.class);\r
+\r
+ private static final InstanceIdentifier<Nodes> NODES_IID = InstanceIdentifier.create(Nodes.class);\r
+ private final DataBroker dataBroker;\r
+ private final LogicalDatastoreType logicalDatastoreType;\r
+\r
+ public FlowCapableNodeOdlDao(DataBroker dataBroker, LogicalDatastoreType logicalDatastoreType) {\r
+ this.dataBroker = dataBroker;\r
+ this.logicalDatastoreType = logicalDatastoreType;\r
+ }\r
+\r
+ public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {\r
+ try (final ReadOnlyTransaction roTx = dataBroker.newReadOnlyTransaction()) {\r
+ final InstanceIdentifier<FlowCapableNode> path =\r
+ NODES_IID.child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class);\r
+ return roTx.read(logicalDatastoreType, path).checkedGet(5000, TimeUnit.MILLISECONDS);\r
+ } catch (ReadFailedException | TimeoutException e) {\r
+ LOG.error("error reading {}", nodeId, e);\r
+ }\r
+\r
+ return Optional.absent();\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+\r
+package org.opendaylight.openflowplugin.applications.frsync.dao;\r
+\r
+import java.util.concurrent.ConcurrentHashMap;\r
+\r
+import javax.annotation.Nonnull;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;\r
+\r
+import com.google.common.base.Optional;\r
+\r
+/**\r
+ * Adding cache to data access object of {@link FlowCapableNode}.\r
+ */\r
+public class FlowCapableNodeSnapshotDao implements FlowCapableNodeDao {\r
+\r
+ private final ConcurrentHashMap<String, FlowCapableNode> cache = new ConcurrentHashMap<>();\r
+\r
+ public void updateCache(@Nonnull NodeId nodeId, Optional<FlowCapableNode> dataAfter) {\r
+ if (dataAfter.isPresent()) {\r
+ cache.put(nodeId.getValue(), dataAfter.get());\r
+ } else {\r
+ cache.remove(nodeId.getValue());\r
+ }\r
+ }\r
+\r
+ public Optional<FlowCapableNode> loadByNodeId(@Nonnull NodeId nodeId) {\r
+ final FlowCapableNode node = cache.get(nodeId.getValue());\r
+ return Optional.fromNullable(node);\r
+ }\r
+\r
+}\r
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
+import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeCachedDao;
+import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeDao;
+import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeOdlDao;
+import org.opendaylight.openflowplugin.applications.frsync.dao.FlowCapableNodeSnapshotDao;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
final MeterForwarder meterForwarder = new MeterForwarder(salMeterService);
final TableForwarder tableForwarder = new TableForwarder(salTableService);
+ {
+ final FlowCapableNodeSnapshotDao configSnapshot = new FlowCapableNodeSnapshotDao();
+ final FlowCapableNodeSnapshotDao operationalSnapshot = new FlowCapableNodeSnapshotDao();
+ final FlowCapableNodeDao configDao = new FlowCapableNodeCachedDao(configSnapshot,
+ new FlowCapableNodeOdlDao(dataService, LogicalDatastoreType.CONFIGURATION));
+ final FlowCapableNodeDao operationalDao = new FlowCapableNodeCachedDao(operationalSnapshot,
+ new FlowCapableNodeOdlDao(dataService, LogicalDatastoreType.OPERATIONAL));
+ }
+
LOG.info("ForwardingRulesSync has started.");
}