Merge "Clear the receive buffer when message parser throws exceptions. Don't terminat...
authorGiovanni Meo <gmeo@cisco.com>
Mon, 11 Nov 2013 11:15:08 +0000 (11:15 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 11 Nov 2013 11:15:08 +0000 (11:15 +0000)
16 files changed:
opendaylight/md-sal/sal-common-impl/src/main/java/org/opendaylight/controller/md/sal/common/impl/routing/AbstractDataReadRouter.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/mount/MountProvisionInstance.java
opendaylight/md-sal/sal-dom-api/src/main/java/org/opendaylight/controller/sal/core/api/mount/MountService.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/BrokerActivator.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointImpl.java
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/MountPointManagerImpl.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/impl/DataReaderRouter.xtend
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/MountProviderServiceProxy.java [new file with mode: 0644]
opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/ProxyFactory.xtend
opendaylight/md-sal/sal-zeromq-connector/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/router/zeromq/Activator.java
opendaylight/md-sal/sal-zeromq-connector/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/router/zeromq/Message.java
opendaylight/md-sal/sal-zeromq-connector/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/router/zeromq/RouteIdentifierImpl.java
opendaylight/md-sal/sal-zeromq-connector/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/router/zeromq/RpcRequestImpl.java
opendaylight/md-sal/sal-zeromq-connector/src/main/java/org/opendaylight/controller/sal/connector/remoterpc/router/zeromq/ZeroMqRpcRouter.java
opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java

index f83c61f8049205977e998c61295072fe84176624..531ce224e6a02867a8fe6b71ae565fef1f7b9b0b 100644 (file)
@@ -75,7 +75,7 @@ public abstract class AbstractDataReadRouter<P extends Path<?>, D> implements Da
         return new Function<DataReader<P, D>, D>() {
             @Override
             public D apply(DataReader<P, D> input) {
-                return input.readConfigurationData(path);
+                return input.readOperationalData(path);
             }
         };
     }
index 8f6a5d0a90cb4fed609fb94a997c44ebe42ae02a..92542bc3455e497a6082fe64cf6607a290b30723 100644 (file)
@@ -1,8 +1,13 @@
 package org.opendaylight.controller.sal.core.api.mount;
 
 import org.opendaylight.controller.sal.core.api.RpcProvisionRegistry;
+import org.opendaylight.controller.sal.core.api.data.DataProviderService;
 import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService;
 
-public interface MountProvisionInstance extends MountInstance, NotificationPublishService, RpcProvisionRegistry {
+public interface MountProvisionInstance extends //
+        MountInstance,//
+        NotificationPublishService, //
+        RpcProvisionRegistry,//
+        DataProviderService {
 
 }
index 530b02b733a0ea945ddad4018a2d29e4f8050705..3180271c935311a64bb69a66b7264ab1ef72cb2a 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.controller.sal.core.api.mount;
 
+import org.opendaylight.controller.sal.core.api.BrokerService;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
 
-public interface MountService {
+public interface MountService extends BrokerService {
 
     MountInstance getMountPoint(InstanceIdentifier path);
 }
index 2bab4dbd26ca5896f3703978171e5ff72274b9db..e49cb4bb0a7580c6905eade22b13b7ae88e3f7a5 100644 (file)
@@ -6,6 +6,8 @@ import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
 import org.opendaylight.controller.sal.core.api.data.DataProviderService;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
+import org.opendaylight.controller.sal.core.api.mount.MountService;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
@@ -20,6 +22,9 @@ public class BrokerActivator implements BundleActivator {
     private ServiceRegistration<DataProviderService> dataProviderReg;
     private SchemaServiceImpl schemaService;
     private DataBrokerImpl dataService;
+    private MountPointManagerImpl mountService;
+    private ServiceRegistration<MountService> mountReg;
+    private ServiceRegistration<MountProvisionService> mountProviderReg;
 
     @Override
     public void start(BundleContext context) throws Exception {
@@ -38,7 +43,11 @@ public class BrokerActivator implements BundleActivator {
         dataReg = context.registerService(DataBrokerService.class, dataService, emptyProperties);
         dataProviderReg = context.registerService(DataProviderService.class, dataService, emptyProperties);
         
+        mountService = new MountPointManagerImpl();
+        mountService.setDataBroker(dataService);
         
+        mountReg = context.registerService(MountService.class, mountService, emptyProperties);
+        mountProviderReg =  context.registerService(MountProvisionService.class, mountService, emptyProperties);
     }
 
     @Override
index 7037b46ce978dea4d717692498e526c8706cb7a8..eafc402ddcea6987b82980b5a2d92ffec5443108 100644 (file)
@@ -1,15 +1,19 @@
 package org.opendaylight.controller.sal.dom.broker;
 
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.Future;
 
+import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler;
 import org.opendaylight.controller.md.sal.common.api.data.DataReader;
+import org.opendaylight.controller.sal.common.DataStoreIdentifier;
 import org.opendaylight.controller.sal.core.api.Broker.RoutedRpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcImplementation;
 import org.opendaylight.controller.sal.core.api.Broker.RpcRegistration;
 import org.opendaylight.controller.sal.core.api.RpcRegistrationListener;
 import org.opendaylight.controller.sal.core.api.data.DataChangeListener;
 import org.opendaylight.controller.sal.core.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.core.api.data.DataValidator;
 import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
 import org.opendaylight.controller.sal.dom.broker.impl.DataReaderRouter;
@@ -23,17 +27,33 @@ import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.InstanceIdentifierBuilder;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
 
 public class MountPointImpl implements MountProvisionInstance {
 
-    final RpcRouter rpcs;
-    final DataReaderRouter dataReader;
-    final NotificationRouter notificationRouter;
+    private final RpcRouter rpcs;
+    private final DataReaderRouter dataReader;
+    private final NotificationRouter notificationRouter;
+    private final DataReader<InstanceIdentifier,CompositeNode> readWrapper;
+    
+    
+    private final InstanceIdentifier mountPath;
 
     public MountPointImpl(InstanceIdentifier path) {
+        this.mountPath = path;
         rpcs = new RpcRouterImpl("");
         dataReader = new DataReaderRouter();
         notificationRouter = new NotificationRouterImpl();
+        readWrapper = new ReadWrapper();
+    }
+
+    public InstanceIdentifier getMountPath() {
+        return mountPath;
+    }
+
+    public DataReader<InstanceIdentifier, CompositeNode> getReadWrapper() {
+        return readWrapper;
     }
 
     @Override
@@ -113,6 +133,62 @@ public class MountPointImpl implements MountProvisionInstance {
     @Override
     public void sendNotification(CompositeNode notification) {
         publish(notification);
+    }
+    
+    @Override
+    public Registration<DataCommitHandler<InstanceIdentifier, CompositeNode>> registerCommitHandler(
+            InstanceIdentifier path, DataCommitHandler<InstanceIdentifier, CompositeNode> commitHandler) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+    
+    @Override
+    public void removeRefresher(DataStoreIdentifier store, DataRefresher refresher) {
+     // NOOP
+    }
+    
+    @Override
+    public void addRefresher(DataStoreIdentifier store, DataRefresher refresher) {
+     // NOOP
+    }
+    
+    @Override
+    public void addValidator(DataStoreIdentifier store, DataValidator validator) {
+     // NOOP
+    }
+    @Override
+    public void removeValidator(DataStoreIdentifier store, DataValidator validator) {
+        // NOOP
+    }
+    
+    class ReadWrapper implements DataReader<InstanceIdentifier, CompositeNode> {
+        
+        
+        private InstanceIdentifier shortenPath(InstanceIdentifier path) {
+            InstanceIdentifier ret = null;
+            if(mountPath.contains(path)) {
+                List<PathArgument> newArgs = path.getPath().subList(mountPath.getPath().size(), path.getPath().size());
+                ret = new InstanceIdentifier(newArgs);
+            }
+            return ret;
+        }
+        
+        @Override
+        public CompositeNode readConfigurationData(InstanceIdentifier path) {
+            InstanceIdentifier newPath = shortenPath(path);
+            if(newPath == null) {
+                return null;
+            }
+            return MountPointImpl.this.readConfigurationData(newPath);
+        }
         
+        @Override
+        public CompositeNode readOperationalData(InstanceIdentifier path) {
+            InstanceIdentifier newPath = shortenPath(path);
+            if(newPath == null) {
+                return null;
+            }
+            return MountPointImpl.this.readOperationalData(newPath);
+        }
     }
 }
index c64d1e56dd9638d28d9dee0d1d508aaead85e030..19634d79c2203fafe5aaa0156c41bf45a62f905f 100644 (file)
@@ -6,15 +6,27 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import java.util.concurrent.ConcurrentMap
 import java.util.concurrent.ConcurrentHashMap
 import static com.google.common.base.Preconditions.*;
+import org.opendaylight.controller.sal.core.api.data.DataProviderService
 
 class MountPointManagerImpl implements MountProvisionService {
     
+    @Property
+    DataProviderService dataBroker;
+    
     ConcurrentMap<InstanceIdentifier,MountPointImpl> mounts = new ConcurrentHashMap();
     
     override createMountPoint(InstanceIdentifier path) {
         checkState(!mounts.containsKey(path),"Mount already created");
         val mount = new MountPointImpl(path);
+        registerMountPoint(mount);
         mounts.put(path,mount);
+        return mount;
+    }
+    
+    def registerMountPoint(MountPointImpl impl) {
+        dataBroker?.registerConfigurationReader(impl.mountPath,impl.readWrapper);
+        dataBroker?.registerOperationalReader(impl.mountPath,impl.readWrapper);
+        
     }
     
     
@@ -30,6 +42,4 @@ class MountPointManagerImpl implements MountProvisionService {
     override getMountPoint(InstanceIdentifier path) {
         mounts.get(path);
     }
-    
-    
 }
index 1e0f3385ccf78bdf418261c15077d2d056fad1f1..b0c61c920f7c6ee967a9e5229a11b5c21558f8e6 100644 (file)
@@ -3,6 +3,7 @@ package org.opendaylight.controller.sal.dom.broker.impl
 import org.opendaylight.controller.md.sal.common.impl.routing.AbstractDataReadRouter
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
 import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import org.opendaylight.controller.md.sal.common.api.data.DataReader
 
 class DataReaderRouter extends AbstractDataReadRouter<InstanceIdentifier, CompositeNode> {
 
diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/MountProviderServiceProxy.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/sal/dom/broker/osgi/MountProviderServiceProxy.java
new file mode 100644 (file)
index 0000000..0d18cb3
--- /dev/null
@@ -0,0 +1,27 @@
+package org.opendaylight.controller.sal.dom.broker.osgi;
+
+import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionInstance;
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService;
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.osgi.framework.ServiceReference;
+
+public class MountProviderServiceProxy extends AbstractBrokerServiceProxy<MountProvisionService> implements MountProvisionService{
+
+    
+    public MountProviderServiceProxy(ServiceReference<MountProvisionService> ref, MountProvisionService delegate) {
+        super(ref, delegate);
+    }
+
+    public MountProvisionInstance getMountPoint(InstanceIdentifier path) {
+        return getDelegate().getMountPoint(path);
+    }
+
+    public MountProvisionInstance createMountPoint(InstanceIdentifier path) {
+        return getDelegate().createMountPoint(path);
+    }
+
+    public MountProvisionInstance createOrGetMountPoint(InstanceIdentifier path) {
+        return getDelegate().createOrGetMountPoint(path);
+    }
+}
index eb738673cb9d724ab830cd16edc56f4d560e4c8b..938808facd58911411a60377b39061947ade2e23 100644 (file)
@@ -7,6 +7,7 @@ import org.opendaylight.controller.sal.core.api.data.DataProviderService
 import org.opendaylight.controller.sal.core.api.notify.NotificationPublishService
 import org.opendaylight.controller.sal.core.api.notify.NotificationService
 import org.opendaylight.controller.sal.core.api.model.SchemaService
+import org.opendaylight.controller.sal.core.api.mount.MountProvisionService
 
 class ProxyFactory {
 
@@ -30,6 +31,11 @@ class ProxyFactory {
         new NotificationServiceProxy(ref as ServiceReference<NotificationService>, service);
     }
 
+    private static def dispatch createProxyImpl(ServiceReference<?> ref, MountProvisionService service) {
+        new MountProviderServiceProxy(ref as ServiceReference<MountProvisionService>, service);
+    }
+
+
     private static def dispatch createProxyImpl(ServiceReference<?> ref, SchemaService service) {
         new SchemaServiceProxy(ref as ServiceReference<SchemaService>, service);
     }
index 74688155302effe515a7d0ce3a68280dd838749c..5b927a56b1077379d6e6231e98792d1acc49ceca 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2013 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.controller.sal.connector.remoterpc.router.zeromq;
 
 import org.opendaylight.controller.sal.core.api.AbstractProvider;
@@ -5,19 +12,19 @@ import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.osgi.framework.BundleContext;
 
 public class Activator extends AbstractProvider {
-    
-    ZeroMqRpcRouter router;
-    
-    @Override
-    public void onSessionInitiated(ProviderSession session) {
-        router = ZeroMqRpcRouter.getInstance();
-        router.setBrokerSession(session);
-        router.start();
-    }
-    
-    @Override
-    protected void stopImpl(BundleContext context) {
-       router.stop();
-    }
+
+  ZeroMqRpcRouter router;
+
+  @Override
+  public void onSessionInitiated(ProviderSession session) {
+    router = ZeroMqRpcRouter.getInstance();
+    router.setBrokerSession(session);
+    router.start();
+  }
+
+  @Override
+  protected void stopImpl(BundleContext context) {
+    router.stop();
+  }
 
 }
index 500f7d562bd85ca993528cf28f15adeea2d92bca..c2c037aee6f1b65bafd3391c6a1975b42b72a375 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013 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.controller.sal.connector.remoterpc.router.zeromq;
 
 
index fff7fad9728b076f93b6bd2481b0d184333bc724..ca404f2ca962f3165d12f14f34d9e600d6576b7c 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2013 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.controller.sal.connector.remoterpc.router.zeromq;
 
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
index 40c5fa10a7b7bd3e0e7f3df22d2ad8f7e02c20bd..206894905ebb7f88a2840b4121d8079f6a217b18 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2013 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.controller.sal.connector.remoterpc.router.zeromq;
 
 import org.opendaylight.controller.sal.connector.api.RpcRouter;
@@ -6,13 +13,6 @@ import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
 
 import java.io.Serializable;
 
-/**
- * Created with IntelliJ IDEA.
- * User: abhishk2
- * Date: 10/25/13
- * Time: 12:32 PM
- * To change this template use File | Settings | File Templates.
- */
 public class RpcRequestImpl implements RpcRouter.RpcRequest<QName, QName, InstanceIdentifier, Object>,Serializable {
 
   private RpcRouter.RouteIdentifier<QName, QName, InstanceIdentifier> routeIdentifier;
index acb733d5cbf3ebfcb1692153ee4339e732357d68..af9480432206455ba38a49bade85d59a10e0a772 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * Copyright (c) 2013 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.controller.sal.connector.remoterpc.router.zeromq;
 
 import java.io.IOException;
@@ -28,6 +35,8 @@ import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.zeromq.ZMQ;
 
 /**
@@ -64,6 +73,8 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
   private String pubIp = System.getProperty("pub.ip"); // other controller's ip
   private String rpcPort = System.getProperty("rpc.port");// port on which RPC messages are received
 
+  private Logger _logger = LoggerFactory.getLogger(ZeroMqRpcRouter.class);
+
   //Prevent instantiation
   private ZeroMqRpcRouter() {
   }
@@ -76,7 +87,6 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
     context = ZMQ.context(2);
     publisher = context.socket(ZMQ.PUB);
     int ret = publisher.bind("tcp://*:" + pubPort);
-    System.out.println(Thread.currentThread().getName() + " Return(publish bind) :[" + ret + "]");
     // serverPool = Executors.newSingleThreadExecutor();
     serverPool = Executors.newCachedThreadPool();
     handlersPool = Executors.newCachedThreadPool();
@@ -126,9 +136,9 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
 
           // Bind to publishing controller
           subscriber = context.socket(ZMQ.SUB);
-          subscriber.connect("tcp://" + pubIp + ":" + subPort);
-          System.out.println(Thread.currentThread().getName() + "-Subscribing at[" + "tcp://"
-              + pubIp + ":" + subPort + "]");
+          String pubAddress = "tcp://" + pubIp + ":" + subPort;
+          subscriber.connect(pubAddress);
+          _logger.debug("{} Subscribing at[{}]", Thread.currentThread().getName(), pubAddress);
 
           //subscribe for announcements
           //TODO: Message type would be changed. Update this
@@ -138,7 +148,6 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
           ZMQ.Poller poller = new ZMQ.Poller(2);
           poller.register(replySocket, ZMQ.Poller.POLLIN);
           poller.register(subscriber, ZMQ.Poller.POLLIN);
-          System.out.println(Thread.currentThread().getName() + "-Start Polling");
 
           //TODO: Add code to restart the thread after exception
           while (!Thread.currentThread().isInterrupted()) {
@@ -168,14 +177,15 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
    * @throws ClassNotFoundException
    */
   private void handleAnnouncement() throws IOException, ClassNotFoundException {
-    System.out.println("\n" + Thread.currentThread().getName() + "-Received message");
+
+    _logger.info("Announcement received");
     Message.MessageType topic = (MessageType) Message.deserialize(subscriber.recv());
-    System.out.println("Topic:[" + topic + "]");
 
     if (subscriber.hasReceiveMore()) {
       try {
         Message m = (Message) Message.deserialize(subscriber.recv());
-        System.out.println(m);
+        _logger.debug("Announcement message [{}]", m);
+
         // TODO: check on msg type or topic. Both
         // should be same. Need to normalize.
         if (Message.MessageType.ANNOUNCE == m.getType())
@@ -193,30 +203,30 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
    */
   private void handleRpcCall() throws InterruptedException, ExecutionException {
     try {
-      Message req = parseMessage(replySocket);
+      Message request = parseMessage(replySocket);
 
-      System.out.println("Received RPC request [" + req + "]");
+      _logger.debug("Received rpc request [{}]", request);
 
       // Call broker to process the message then reply
       Future<RpcResult<CompositeNode>> rpc = brokerSession.rpc(
-          (QName) req.getRoute().getType(), (CompositeNode) req.getPayload());
+          (QName) request.getRoute().getType(), (CompositeNode) request.getPayload());
 
       RpcResult<CompositeNode> result = rpc.get();
 
       Message response = new Message.MessageBuilder()
           .type(MessageType.RESPONSE)
           .sender(localIp + ":" + rpcPort)
-          .route(req.getRoute())
+          .route(request.getRoute())
           //.payload(result)    TODO: enable and test
           .build();
 
       replySocket.send(Message.serialize(response));
 
-      System.out.println("Sent RPC response [" + response + "]");
+      _logger.debug("Sent rpc response [{}]", response);
 
     } catch (IOException ex) {
       //TODO: handle exception and send error codes to caller
-      System.out.println("Rpc request could not be handled" + ex);
+      ex.printStackTrace();
     }
   }
 
@@ -241,26 +251,27 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
             .payload(input.getPayload())
             .build();
 
+        _logger.debug("Sending rpc request [{}]", requestMessage);
+
         RpcReply<Object> reply = null;
 
         try {
-          System.out.println("\n\nRPC Request [" + requestMessage + "]");
 
           requestSocket.send(Message.serialize(requestMessage));
-          final Message resp = parseMessage(requestSocket);
+          final Message response = parseMessage(requestSocket);
 
-          System.out.println("\n\nRPC Response [" + resp + "]");
+          _logger.debug("Received response [{}]", response);
 
           reply = new RpcReply<Object>() {
 
             @Override
             public Object getPayload() {
-              return resp.getPayload();
+              return response.getPayload();
             }
           };
         } catch (IOException ex) {
           // TODO: Pass exception back to the caller
-          System.out.println("Error in RPC send. Input could not be serialized[" + input + "]");
+          ex.printStackTrace();
         }
 
         return reply;
@@ -278,24 +289,15 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
     Runnable task = new Runnable() {
       public void run() {
 
-        System.out.println(
-            Thread.currentThread().getName() + "-Publisher started at port[" + pubPort + "]");
-
         try {
 
-          System.out.println(
-              Thread.currentThread().getName() + "-Sending announcement[" + notice + "]");
-
           publisher.sendMore(Message.serialize(Message.MessageType.ANNOUNCE));
           publisher.send(Message.serialize(notice));
-
+          _logger.debug("Announcement sent [{}]", notice);
         } catch (IOException ex) {
-          System.out.println("Error in publishing");
+          _logger.error("Error in sending announcement [{}]", notice);
           ex.printStackTrace();
         }
-        System.out.println(Thread.currentThread().getName() + "-Published message[" + notice
-            + "]");
-
       }
     };
     handlersPool.execute(task);
@@ -345,6 +347,7 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
     // TODO: do registration for instance based routing
     QName rpcType = route.getType();
     RpcRegistration registration = brokerSession.addRpcImplementation(rpcType, facade);
+    _logger.debug("Routing table updated");
   }
 
   /**
@@ -356,10 +359,9 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
     Message msg = null;
     try {
       byte[] bytes = socket.recv();
-      System.out.println("Received bytes:[" + bytes.length + "]");
+      _logger.debug("Received bytes:[{}]", bytes.length);
       msg = (Message) Message.deserialize(bytes);
     } catch (Throwable t) {
-      System.out.println("Caught exception");
       t.printStackTrace();
     }
     return msg;
@@ -418,8 +420,8 @@ public class ZeroMqRpcRouter implements RpcRouter<QName, QName, InstanceIdentifi
 
     @Override
     public void onRpcImplementationAdded(QName name) {
-      System.out.println("In ZeroMQ Rpc Listener onRpcImplementationAdded()");
 
+      _logger.debug("Announcing registration for [{}]", name);
       RouteIdentifierImpl routeId = new RouteIdentifierImpl();
       routeId.setType(name);
 
index 7bec2722bf96fd1e9b3b645203aa67c8a6b4f36c..602de9a1c6f28f8e195ed0aa00c78bd82f3da434 100644 (file)
@@ -310,7 +310,7 @@ public class NorthboundIT {
         JSONTokener jt = new JSONTokener(result);
         JSONObject json = new JSONObject(jt);
         JSONArray subnetConfigs = json.getJSONArray("subnetConfig");
-        Assert.assertEquals(subnetConfigs.length(), 0);
+        Assert.assertEquals(subnetConfigs.length(), 1); // should only get the default subnet
 
         // Test GET subnet1 expecting 404
         result = getJsonResult(baseURL + "default/subnet/" + name1);
index 99482debd6d7e51c84415d3064ed38d05b5ca77e..4d2aea203601dafe6e19fcacc208ae4760819b0f 100644 (file)
@@ -111,6 +111,19 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
     private boolean isDefaultContainer = true;
     private static final int REPLACE_RETRY = 1;
 
+    /* Information about the default subnet. If there have been no configured subnets, i.e.,
+     * subnets.size() == 0 or subnetsConfigList.size() == 0, then this subnet will be the
+     * only subnet returned. As soon as a user-configured subnet is created this one will
+     * vanish.
+     */
+    protected static SubnetConfig DEFAULT_SUBNETCONFIG;
+    protected static Subnet DEFAULT_SUBNET;
+    protected static String DEFAULT_SUBNET_NAME = "default (cannot be modifed)";
+    static{
+        DEFAULT_SUBNETCONFIG = new SubnetConfig(DEFAULT_SUBNET_NAME, "0.0.0.0/0", new ArrayList<String>());
+        DEFAULT_SUBNET = new Subnet(DEFAULT_SUBNETCONFIG);
+    }
+
     public void notifySubnetChange(Subnet sub, boolean add) {
         synchronized (switchManagerAware) {
             for (Object subAware : switchManagerAware) {
@@ -295,12 +308,22 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
 
     @Override
     public List<SubnetConfig> getSubnetsConfigList() {
-        return new ArrayList<SubnetConfig>(subnetsConfigList.values());
+        // if there are no subnets, return the default subnet
+        if(subnetsConfigList.size() == 0){
+            return Collections.singletonList(DEFAULT_SUBNETCONFIG);
+        }else{
+            return new ArrayList<SubnetConfig>(subnetsConfigList.values());
+        }
     }
 
     @Override
     public SubnetConfig getSubnetConfig(String subnet) {
-        return subnetsConfigList.get(subnet);
+        // if there are no subnets, return the default subnet
+        if(subnetsConfigList.size() == 0 && subnet == DEFAULT_SUBNET_NAME){
+            return DEFAULT_SUBNETCONFIG;
+        }else{
+            return subnetsConfigList.get(subnet);
+        }
     }
 
     private List<SpanConfig> getSpanConfigList(Node node) {
@@ -646,6 +669,11 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
 
     @Override
     public Subnet getSubnetByNetworkAddress(InetAddress networkAddress) {
+        // if there are no subnets, return the default subnet
+        if (subnets.size() == 0) {
+            return DEFAULT_SUBNET;
+        }
+
         Subnet sub;
         Set<InetAddress> indices = subnets.keySet();
         for (InetAddress i : indices) {