Initial checkin for FIB Manager Provider 90/18690/2
authorDeepthi V V <deepthi.v.v@ericsson.com>
Tue, 21 Apr 2015 06:44:18 +0000 (12:14 +0530)
committerDeepthi V V <deepthi.v.v@ericsson.com>
Thu, 23 Apr 2015 05:08:07 +0000 (05:08 +0000)
Signed-off-by: Deepthi V V <deepthi.v.v@ericsson.com>
Change-Id: I92db8ae164b14d47c3d8e4b7e9cefe709cea3564

fibmanager/fibmanager-impl/pom.xml
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManager.java [new file with mode: 0644]
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManagerProvider.java [new file with mode: 0644]
fibmanager/fibmanager-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/fibmanager/impl/rev150325/FibmanagerImplModule.java
nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/nexthopmgr/impl/rev150325/NexthopmgrImplModule.java

index 732bd2f594f9a498d127f287eaa62d0010569157..95b37969a3e5456c9bb70c8b16fdc38ca2015777 100644 (file)
@@ -21,6 +21,16 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <version>0.0.1-SNAPSHOT</version>
   <packaging>bundle</packaging>
   <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.vpnservice</groupId>
+      <artifactId>fibmanager-api</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.vpnservice</groupId>
+      <artifactId>vpnmanager-impl</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
     <!-- Testing Dependencies -->
     <dependency>
       <groupId>junit</groupId>
diff --git a/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManager.java b/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManager.java
new file mode 100644 (file)
index 0000000..42476b0
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.fibmanager;
+
+import com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import com.google.common.util.concurrent.FutureCallback;
+import org.opendaylight.vpnservice.AbstractDataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.fibmanager.rev150330.FibEntries;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.google.common.base.Optional;
+
+public class FibManager extends AbstractDataChangeListener<FibEntries> implements AutoCloseable{
+  private static final Logger LOG = LoggerFactory.getLogger(FibManager.class);
+  private ListenerRegistration<DataChangeListener> listenerRegistration;
+  private final DataBroker broker;
+
+  private static final FutureCallback<Void> DEFAULT_CALLBACK =
+      new FutureCallback<Void>() {
+        public void onSuccess(Void result) {
+          LOG.debug("Success in Datastore write operation");
+        }
+
+        public void onFailure(Throwable error) {
+          LOG.error("Error in Datastore write operation", error);
+        };
+      };
+
+  public FibManager(final DataBroker db) {
+    super(FibEntries.class);
+    broker = db;
+    registerListener(db);
+  }
+
+  @Override
+  public void close() throws Exception {
+    if (listenerRegistration != null) {
+      try {
+        listenerRegistration.close();
+      } catch (final Exception e) {
+        LOG.error("Error when cleaning up DataChangeListener.", e);
+      }
+      listenerRegistration = null;
+    }
+    LOG.info("Fib Manager Closed");
+  }
+
+  private void registerListener(final DataBroker db) {
+    try {
+      listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION,
+                                                           getWildCardPath(), FibManager.this, DataChangeScope.SUBTREE);
+    } catch (final Exception e) {
+      LOG.error("FibManager DataChange listener registration fail!", e);
+      throw new IllegalStateException("FibManager registration Listener failed.", e);
+    }
+  }
+
+  @Override
+  protected void add(final InstanceIdentifier<FibEntries> identifier,
+                     final FibEntries fibEntries) {
+    LOG.trace("key: " + identifier + ", value=" + fibEntries );
+  }
+
+  private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
+                                                  InstanceIdentifier<T> path) {
+
+    ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
+
+    Optional<T> result = Optional.absent();
+    try {
+      result = tx.read(datastoreType, path).get();
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+
+    return result;
+  }
+
+  private InstanceIdentifier<FibEntries> getWildCardPath() {
+    return InstanceIdentifier.create(FibEntries.class);
+  }
+
+  @Override
+  protected void remove(InstanceIdentifier<FibEntries> identifier, FibEntries del) {
+    LOG.trace("key: " + identifier + ", value=" + del );
+  }
+
+  @Override
+  protected void update(InstanceIdentifier<FibEntries> identifier, FibEntries original, FibEntries update) {
+    LOG.trace("key: " + identifier + ", original=" + original + ", update=" + update );
+  }
+
+  private <T extends DataObject> void asyncWrite(LogicalDatastoreType datastoreType,
+                                                 InstanceIdentifier<T> path, T data, FutureCallback<Void> callback) {
+    WriteTransaction tx = broker.newWriteOnlyTransaction();
+    tx.put(datastoreType, path, data, true);
+    Futures.addCallback(tx.submit(), callback);
+  }
+}
diff --git a/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManagerProvider.java b/fibmanager/fibmanager-impl/src/main/java/org/opendaylight/vpnservice/fibmanager/FibManagerProvider.java
new file mode 100644 (file)
index 0000000..2015dc0
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.vpnservice.fibmanager;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
+import org.opendaylight.controller.sal.binding.api.BindingAwareProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FibManagerProvider implements BindingAwareProvider, AutoCloseable {
+
+  private static final Logger LOG = LoggerFactory.getLogger(FibManagerProvider.class);
+
+  private FibManager fibManager;
+
+  @Override
+  public void onSessionInitiated(ProviderContext session) {
+    LOG.info("FibManagerProvider Session Initiated");
+    try {
+      final  DataBroker dataBroker = session.getSALService(DataBroker.class);
+      fibManager = new FibManager(dataBroker);
+    } catch (Exception e) {
+      LOG.error("Error initializing services", e);
+    }
+  }
+
+  @Override
+  public void close() throws Exception {
+    LOG.info("FibManagerProvider Closed");
+    fibManager.close();
+  }
+
+}
\ No newline at end of file
index c845721713814d42cd42ccbef0f850cce2b4cc4d..f3d9acd90e41b1e72b6a971311ac051a3b54b341 100644 (file)
@@ -1,4 +1,13 @@
+/*
+ * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.fibmanager.impl.rev150325;
+import org.opendaylight.vpnservice.fibmanager.FibManagerProvider;
+
 public class FibmanagerImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.fibmanager.impl.rev150325.AbstractFibmanagerImplModule {
     public FibmanagerImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
@@ -15,8 +24,9 @@ public class FibmanagerImplModule extends org.opendaylight.yang.gen.v1.urn.opend
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        // TODO:implement
-        throw new java.lang.UnsupportedOperationException();
+        FibManagerProvider provider = new FibManagerProvider();
+        getBrokerDependency().registerProvider(provider);
+        return provider;
     }
 
 }
index 66ae335c8ca9d23e6eba9ff8b904e2bd3bd9f321..90470f0ce61d73aa3be6d46422202d521098a1d1 100644 (file)
@@ -1,4 +1,7 @@
 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nexthopmgr.impl.rev150325;
+
+import org.opendaylight.vpnservice.nexthopmgr.NexthopmgrProvider;
+
 public class NexthopmgrImplModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nexthopmgr.impl.rev150325.AbstractNexthopmgrImplModule {
     public NexthopmgrImplModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
         super(identifier, dependencyResolver);
@@ -15,8 +18,9 @@ public class NexthopmgrImplModule extends org.opendaylight.yang.gen.v1.urn.opend
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        // TODO:implement
-        throw new java.lang.UnsupportedOperationException();
+        NexthopmgrProvider provider = new NexthopmgrProvider();
+        getBrokerDependency().registerProvider(provider);
+        return provider;
     }
 
 }