Fixed sonar warnings in manager.neutron bundle. 16/39316/1
authorShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 24 May 2016 09:37:42 +0000 (18:37 +0900)
committerShigeru Yasuda <s-yasuda@da.jp.nec.com>
Tue, 24 May 2016 09:37:42 +0000 (18:37 +0900)
  * Remove this unused "VTN_IDENTIFIERS_IN_PORT" private field.
  * Make XXX a static final constant or non-public and provide accessors
    if needed.

Change-Id: Ie483788823d880e1b9e64dcccc72562e536d5b80
Signed-off-by: Shigeru Yasuda <s-yasuda@da.jp.nec.com>
manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/NeutronConfig.java [new file with mode: 0644]
manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/NeutronProvider.java
manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/OVSDBEventHandler.java
manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/OvsdbDataChangeListener.java
manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/VTNNeutronUtils.java
manager/neutron/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/vtn/neutron/rev150922/VTNNeutronModule.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/impl/NeutronConfigTest.java [new file with mode: 0644]
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/impl/OVSDBEventHandlerTest.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/impl/OvsdbDataChangeListenerTest.java
manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/impl/VTNNeutronUtilsTest.java

diff --git a/manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/NeutronConfig.java b/manager/neutron/src/main/java/org/opendaylight/vtn/manager/neutron/impl/NeutronConfig.java
new file mode 100644 (file)
index 0000000..2dedfc8
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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.vtn.manager.neutron.impl;
+
+import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getNonNullValue;
+
+import javax.annotation.Nonnull;
+
+/**
+ * {@code NeutronConfig} describes the configuration for the manager.neutron
+ * bundle specified by the config subsystem.
+ */
+public final class NeutronConfig {
+    /**
+     * A string that indicates secure fail mode.
+     */
+    public static final String  FAILMODE_SECURE = "secure";
+
+    /**
+     * A string that indicates standalone fail mode.
+     */
+    public static final String  FAILMODE_STANDALONE = "standalone";
+
+    /**
+     * A string that indicates OpenFlow 1.3.
+     */
+    public static final String  PROTO_OF13 = "OpenFlow13";
+
+    /**
+     * The default name of the OVS bridge.
+     */
+    private static final String  DEFAULT_BRIDGE_NAME = "br-int";
+
+    /**
+     * The default value of the port name in the OVS bridge.
+     */
+    private static final String  DEFAULT_PORT_NAME = "eth0";
+
+    /**
+     * The default value of the protocol used by the OVS.
+     */
+    private static final String  DEFAULT_PROTOCOL = PROTO_OF13;
+
+    /**
+     * The default value of the OVSDB failmode.
+     */
+    private static final String  DEFAULT_FAILMODE = FAILMODE_SECURE;
+
+    /**
+     * The name of the bridge to create in the OVS.
+     */
+    private final String  ovsdbBridgeName;
+
+    /**
+     * The name of the interface to be added as port to the OVS bridge.
+     */
+    private final String  ovsdbPortName;
+
+    /**
+     * The OpenFlow protocol used by the OVS.
+     */
+    private final String  ovsdbProtocol;
+
+    /**
+     * The string that specifies the OVSDB failmode.
+     */
+    private final String  ovsdbFailMode;
+
+    /**
+     * Construct a new instance that contains default values.
+     */
+    public NeutronConfig() {
+        this(null, null, null, null);
+    }
+
+    /**
+     * Construct a new instance.
+     *
+     * @param bname  The name of the bridge to create in the OVS.
+     * @param pname  The name of the port in the OVS bridge.
+     * @param proto  The OpenFlow protocol used by the OVS.
+     * @param fail   The OVSDB failmode.
+     */
+    public NeutronConfig(String bname, String pname, String proto,
+                         String fail) {
+        ovsdbBridgeName = getNonNullValue(bname, DEFAULT_BRIDGE_NAME);
+        ovsdbPortName = getNonNullValue(pname, DEFAULT_PORT_NAME);
+        ovsdbProtocol = getNonNullValue(proto, DEFAULT_PROTOCOL);
+        ovsdbFailMode = getNonNullValue(fail, DEFAULT_FAILMODE);
+    }
+
+    /**
+     * Return the name of the OVS bridge.
+     *
+     * @return  The name of the OVS bridge.
+     */
+    @Nonnull
+    public String getOvsdbBridgeName() {
+        return ovsdbBridgeName;
+    }
+
+    /**
+     * Return the name of the port in the OVS bridge.
+     *
+     * @return  The name of the OVS bridge port.
+     */
+    @Nonnull
+    public String getOvsdbPortName() {
+        return ovsdbPortName;
+    }
+
+    /**
+     * Return the OpenFlow protocol used by the OVS.
+     *
+     * @return  A string that indicates the OpenFlow protocol.
+     */
+    @Nonnull
+    public String getOvsdbProtocol() {
+        return ovsdbProtocol;
+    }
+
+    /**
+     * Return the OVSDB failmode.
+     *
+     * @return  A string that indicates the OVSDB failmode.
+     */
+    @Nonnull
+    public String getOvsdbFailMode() {
+        return ovsdbFailMode;
+    }
+
+    // Object
+
+    /**
+     * Return a string representation of this instance.
+     *
+     * @return  A string representation of this instance.
+     */
+    @Override
+    public String toString() {
+        return "NeutronConfig[bridge-name=" + ovsdbBridgeName +
+            ", port-name=" + ovsdbPortName +
+            ", protocol=" + ovsdbProtocol +
+            ", failmode=" + ovsdbFailMode + "]";
+    }
+}
index ce578353ed6f4b23c69edea454d55dccde1d24bf..62e64aea794ff9f3e0a5a2b81cf396eda19baf5d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation. All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -31,13 +31,46 @@ import com.google.common.base.Optional;
 import com.google.common.util.concurrent.CheckedFuture;
 
 public class NeutronProvider implements BindingAwareProvider, AutoCloseable {
-
+    /**
+     * The logger instance.
+     */
     private static final Logger LOG = LoggerFactory.getLogger(NeutronProvider.class);
+
+    /**
+     * The data broker service.
+     */
     private DataBroker  dataBroker;
+
+    /**
+     * The data change listener that listens OVSDB topology changes.
+     */
     private OvsdbDataChangeListener ovsdbDataChangeListener;
+
+    /**
+     * The data change listener that listens neutron network changes.
+     */
     private NeutronNetworkChangeListener neutronNetworkChangeListener;
+
+    /**
+     * The data change listener that listens neutron port changes.
+     */
     private PortDataChangeListener portDataChangeListener;
 
+    /**
+     * The manager.neutron configuration.
+     */
+    private final NeutronConfig  bundleConfig;
+
+    /**
+     * Construct a new instance.
+     *
+     * @param cfg  The configuration for the manager.neutron bundle.
+     */
+    public NeutronProvider(NeutronConfig cfg) {
+        bundleConfig = cfg;
+        LOG.info("Bundle configuration: {}", cfg);
+    }
+
     /**
      * Method invoked when the open flow switch is Added.
      * @param session the session object
@@ -51,7 +84,8 @@ public class NeutronProvider implements BindingAwareProvider, AutoCloseable {
         MdsalUtils md = new MdsalUtils(db);
         VTNManagerService vtn = new VTNManagerService(md, session);
 
-        ovsdbDataChangeListener = new OvsdbDataChangeListener(db, md, vtn);
+        OVSDBEventHandler ovh = new OVSDBEventHandler(bundleConfig, md, vtn);
+        ovsdbDataChangeListener = new OvsdbDataChangeListener(db, ovh);
         neutronNetworkChangeListener =
             new NeutronNetworkChangeListener(db, vtn);
         initializeOvsdbTopology(LogicalDatastoreType.OPERATIONAL);
index cc11fa32a83245a8cc6fbfe7a3bb3f6f7d2c6916..b0e10d526d4dc3fc49dc9535c6ff920d9ffc2889 100644 (file)
@@ -13,6 +13,9 @@ import static java.net.HttpURLConnection.HTTP_OK;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getBridgeId;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getInterfaceId;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getTenantId;
+import static org.opendaylight.vtn.manager.neutron.impl.NeutronConfig.FAILMODE_SECURE;
+import static org.opendaylight.vtn.manager.neutron.impl.NeutronConfig.FAILMODE_STANDALONE;
+import static org.opendaylight.vtn.manager.neutron.impl.NeutronConfig.PROTO_OF13;
 
 import java.security.InvalidParameterException;
 import java.util.ArrayList;
@@ -87,56 +90,6 @@ public final class OVSDBEventHandler {
     private static final Logger LOG =
         LoggerFactory.getLogger(OVSDBEventHandler.class);
 
-     /**
-     * identifier for the integration bridge name.
-     */
-    private String integrationBridgeName;
-
-    /**
-     * identifier to define failmode of integration bridge.
-     */
-    private String failmode;
-
-    /**
-     * identifier to define protocol of integration bridge.
-     */
-    private String protocols;
-
-     /**
-     * identifier to define portname of the integration bridge.
-     */
-    private String portname;
-
-    /**
-     * A string that indicates secure fail mode.
-     */
-    private static final String  FAILMODE_SECURE = "secure";
-
-    /**
-     * A string that indicates OpenFlow 1.3.
-     */
-    private static final String  OFP13 = "OpenFlow13";
-
-    /**
-     * Default integration bridge name.
-     */
-    private static final String DEFAULT_INTEGRATION_BRIDGENAME = "br-int";
-
-    /**
-     * identifier for Default failmode.
-     */
-    private static final String DEFAULT_FAILMODE = FAILMODE_SECURE;
-
-    /**
-     * identifier for Default protocol.
-     */
-    private static final String DEFAULT_PROTOCOLS = OFP13;
-
-    /**
-     * identifier for Default portname.
-     */
-    private static final String DEFAULT_PORTNAME = "eth0";
-
     /**
      * identifier to read for integration name from config file.
      */
@@ -150,52 +103,49 @@ public final class OVSDBEventHandler {
     /**
      * identifier to read open flow protocol from config file.
      */
-    public static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
+    private static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
 
     /**
-     * identifier to get Action of OVSDB Ports
+     * identifier to get Action of OVSDB Ports.
      */
     private static final String ACTION_PORT = "delete";
 
     /**
-     * Instance of {@link MdsalUtils}.
-     */
-    private final MdsalUtils  mdsalUtils;
-
-    /**
-     * VTN Manager service.
-     */
-    private final VTNManagerService  vtnManager;
-
-    /**
-     * identifier to read BRIDGE_URI_PREFIX.
+     * Stores the Fail Mode Type.
      */
-    public static final String BRIDGE_URI_PREFIX = "bridge";
+    private static final ImmutableBiMap<Class<? extends OvsdbFailModeBase>, String> OVSDB_FAIL_MODE_MAP
+            = new ImmutableBiMap.Builder<Class<? extends OvsdbFailModeBase>, String>()
+            .put(OvsdbFailModeStandalone.class, FAILMODE_STANDALONE)
+            .put(OvsdbFailModeSecure.class, FAILMODE_SECURE)
+            .build();
 
     /**
-     * VTN identifiers in neutron port object.
+     * Stores the Supported Openflow Protocol Version.
      */
-    private static final int VTN_IDENTIFIERS_IN_PORT = 3;
+    private static final ImmutableBiMap<Class<? extends OvsdbBridgeProtocolBase>, String> OVSDB_PROTOCOL_MAP
+            = new ImmutableBiMap.Builder<Class<? extends OvsdbBridgeProtocolBase>, String>()
+            .put(OvsdbBridgeProtocolOpenflow13.class, PROTO_OF13)
+            .build();
 
     /**
-     * identifiers for OVSDB Port Name.
+     * The configuration of the manager.neutron bundle.
      */
-    public static String ovsdbPortName;
+    private final NeutronConfig  bundleConfig;
 
     /**
-     * identifiers for OVSDB Bridge Name.
+     * Instance of {@link MdsalUtils}.
      */
-    public static String ovsdbBridgeName;
+    private final MdsalUtils  mdsalUtils;
 
     /**
-     * identifiers for OVSDB Protocol.
+     * VTN Manager service.
      */
-    public static String ovsdbProtocol;
+    private final VTNManagerService  vtnManager;
 
     /**
-     * identifiers for OVSDB Failmode.
+     * identifier to read BRIDGE_URI_PREFIX.
      */
-    public static String ovsdbFailMode;
+    public static final String BRIDGE_URI_PREFIX = "bridge";
 
     /**
      * Convert the given DPID into an {@link OfNode} instance.
@@ -216,10 +166,13 @@ public final class OVSDBEventHandler {
     /**
      * Method invoked when the open flow switch is Added.
      *
+     * @param cfg  The configuration for the manager.neutron bundle.
      * @param md   A {@link MdsalUtils} instance.
      * @param vtn  A {@link VTNManagerService} instance.
      */
-    public OVSDBEventHandler(MdsalUtils md, VTNManagerService vtn) {
+    public OVSDBEventHandler(NeutronConfig cfg, MdsalUtils md,
+                             VTNManagerService vtn) {
+        bundleConfig = cfg;
         mdsalUtils = md;
         vtnManager = vtn;
     }
@@ -232,8 +185,8 @@ public final class OVSDBEventHandler {
     public void nodeAdded(Node node, DataObject resourceAugmentationData) {
         LOG.trace("nodeAdded() - {}", node.toString());
         try {
-            createInternalNetworkForNeutron(node);
-        } catch (Exception e) {
+            readSystemProperties(node);
+        } catch (RuntimeException e) {
             LOG.warn("Exception occurred while Bridge Creation", e);
         }
     }
@@ -244,64 +197,30 @@ public final class OVSDBEventHandler {
      */
     public void nodeRemoved(Node node) {
         LOG.trace("nodeRemoved() - {}", node.toString());
-        boolean result = deleteBridge(node, integrationBridgeName);
+        boolean result = deleteBridge(node, bundleConfig.getOvsdbBridgeName());
         if (!result) {
             LOG.error("Failure in delete the bridge node entry from Config Datastore");
         }
     }
 
-    /**
-     * Create InternalNetwork if not already present.
-     *
-     * @param node Instance of Node object.
-     */
-    private void createInternalNetworkForNeutron(Node node) {
-        getSystemProperties(node);
-        LOG.trace("createInternalNetworkForNeutron() - node ={}, integration bridge ={}", node.toString());
-
-    }
-
     /**
      * Read the parameters configured in configuration file(default.config).
+     *
      * @param node instance of Node
      */
-    private void getSystemProperties(Node node) {
-        LOG.trace("System properties from default config : {},{},{},{}:",
-                  ovsdbBridgeName, ovsdbPortName, ovsdbProtocol, ovsdbFailMode);
-        integrationBridgeName = ovsdbBridgeName;
-        if (integrationBridgeName == null) {
-            integrationBridgeName = DEFAULT_INTEGRATION_BRIDGENAME;
-        }
-        portname = ovsdbPortName;
-        if (portname == null) {
-            portname = DEFAULT_PORTNAME;
-        }
-        failmode = ovsdbFailMode;
-        if (failmode == null) {
-            failmode = DEFAULT_FAILMODE;
-        }
-        protocols = ovsdbProtocol;
-        if (protocols == null) {
-            protocols = DEFAULT_PROTOCOLS;
-        }
-        LOG.trace("System properties values : {},{},{},{}:",
-                  integrationBridgeName, failmode, protocols, portname);
-        if (null != integrationBridgeName) {
-            try {
-                if (!isBridgeOnOvsdbNode(node, integrationBridgeName)) {
-                    addBridge(node, integrationBridgeName);
-                    addPortToBridge(node, integrationBridgeName, portname);
-                } else {
-                    LOG.trace("Bridge Already exists in the given Node");
-                }
-            } catch (Exception e) {
-                LOG.warn("Exception occurred while Adding Bridge", e);
-            }
+    private void readSystemProperties(Node node) {
+        String bname = bundleConfig.getOvsdbBridgeName();
+        if (!isBridgeOnOvsdbNode(node, bname)) {
+            addBridge(node, bname);
+            addPortToBridge(node, bname, bundleConfig.getOvsdbPortName());
+        } else {
+            LOG.trace("Bridge Already exists in the given Node: {}", bname);
         }
     }
 
     /**
-     * Read Node from the OVSDB path
+     * Read Node from the OVSDB path.
+     *
      * @param ovsdbNodeKey  A {@link NodeKey} instance.
      * @param bridgeName    The name of the bridge.
      * @return The {@link InstanceIdentifier} for the manager node.
@@ -312,7 +231,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Create instance identifier
+     * Create instance identifier.
+     *
      * @param nodeId is instance of NodeId
      * @return The {@link OvsdbBridgeAugmentation} for the manager node.
      */
@@ -325,7 +245,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Get the manager node for this bridge node
+     * Get the manager node for this bridge node.
+     *
      * @param ovsdbNodeId  A {@link NodeId} instance.
      * @param bridgeName   The name of the bridge.
      * @return The {@link OvsdbBridgeAugmentation} for the manager node.
@@ -336,7 +257,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Get the connection information of the Node
+     * Get the connection information of the Node.
+     *
      * @param ovsdbNode is instance of Node
      * @return connectionInfo.
      */
@@ -353,7 +275,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Add Bridge to the given Node
+     * Add Bridge to the given Node.
+     *
      * @param ovsdbNode the node object of the OVS instance
      * @param bridgeName the bridgename of the bridge to be added
      * @return true if the bridge add is successful.
@@ -396,7 +319,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Delete Bridge on the given Node
+     * Delete Bridge on the given Node.
+     *
      * @param ovsdbNode the node object of the OVS instance
      * @param bridgeName the bridgename of the bridge to be removed
      * @return true if the bridge deleted is successful.
@@ -409,8 +333,9 @@ public final class OVSDBEventHandler {
 
     /**
      * Returns controller details of the Node.
+     *
      * @param  node is instance of Node to be added
-     * returns Controller information.
+     * @return Controller information.
      */
     private String getControllerTarget(Node node) {
         String setControllerStr = null;
@@ -437,6 +362,7 @@ public final class OVSDBEventHandler {
 
     /**
      * Return the particular port detail of the given Node.
+     *
      * @param bridgeNode  A {@link Node} instance.
      * @param portName    The name of the port.
      * @return OvsdbTerminationPointAugmentation.
@@ -455,6 +381,7 @@ public final class OVSDBEventHandler {
 
     /**
      * Returns all port details of the given Node.
+     *
      * @param node  A {@link Node} instance.
      * @return A list of {@link OvsdbTerminationPointAugmentation} instances.
      */
@@ -474,7 +401,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-      * Get the bridge node for a particular bridge from config DS
+      * Get the bridge node for a particular bridge from config DS.
+      *
       * @param node  A {@link Node} instance.
       * @param bridgeName   The name of the bridge.
       * @return The {@link Node} for the manager node.
@@ -490,6 +418,7 @@ public final class OVSDBEventHandler {
 
     /**
      * Add a Port to the existing bridge.
+     *
      * @param parentNode        A {@link Node} instance.
      * @param bridgeName  The name of the bridge.
      * @param portName    The name of the port.
@@ -524,7 +453,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Set the manager node for the node
+     * Set the manager node for the node.
+     *
      * @param ovsdbBridgeAugmentationBuilder
      *    A {@link OvsdbBridgeAugmentationBuilder} instance.
      * @param ovsdbNodeKey  A {@link NodeKey} instance.
@@ -537,10 +467,11 @@ public final class OVSDBEventHandler {
     }
 
     /**
-     * Add the port to the node, returns true on success
-     * @param bridgeNode
-     * @param bridgeName
-     * @param portName
+     * Add the port to the node, returns true on success.
+     *
+     * @param bridgeNode  The target bridge node.
+     * @param bridgeName  The name of the bridge.
+     * @param portName    The name of the porrt.
      * @return true on success.
      */
     private Boolean addTerminationPoint(Node bridgeNode, String bridgeName, String portName) {
@@ -556,6 +487,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
+     * Create instance identifier for the specified termination point.
+     *
      * @param node      A {@link Node} instance.
      * @param portName  The name of the port.
      * @return InstanceIdentifier.
@@ -575,6 +508,8 @@ public final class OVSDBEventHandler {
     }
 
     /**
+     * Create a list of controller entries.
+     *
      * @param targetString is String value.
      * @return ControllerEntry ,the Controller details to be set .
      */
@@ -588,6 +523,7 @@ public final class OVSDBEventHandler {
 
     /**
      * Returns the supported OpenFlow Protocol Type.
+     *
      * @return ProtocolEntry.
      */
     private List<ProtocolEntry> createMdsalProtocols() {
@@ -595,39 +531,24 @@ public final class OVSDBEventHandler {
         ImmutableBiMap<String, Class<? extends OvsdbBridgeProtocolBase>> mapper =
                 OVSDB_PROTOCOL_MAP.inverse();
         protocolList.add(new ProtocolEntryBuilder().
-                setProtocol((Class<? extends OvsdbBridgeProtocolBase>)mapper.get(OFP13)).build());
+                setProtocol((Class<? extends OvsdbBridgeProtocolBase>)mapper.get(PROTO_OF13)).build());
         return protocolList;
     }
 
-    /**
-     * Stores the Fail Mode Type.
-     */
-    private static final ImmutableBiMap<Class<? extends OvsdbFailModeBase>, String> OVSDB_FAIL_MODE_MAP
-            = new ImmutableBiMap.Builder<Class<? extends OvsdbFailModeBase>, String>()
-            .put(OvsdbFailModeStandalone.class, "standalone")
-            .put(OvsdbFailModeSecure.class, FAILMODE_SECURE)
-            .build();
-
-    /**
-     * Stores the Supported Openflow Protocol Version.
-     */
-
-    private static final ImmutableBiMap<Class<? extends OvsdbBridgeProtocolBase>, String> OVSDB_PROTOCOL_MAP
-            = new ImmutableBiMap.Builder<Class<? extends OvsdbBridgeProtocolBase>, String>()
-            .put(OvsdbBridgeProtocolOpenflow13.class, OFP13)
-            .build();
-
     /**
      * Read the node details of the provided node.
      * @param node instance of Node.
+     * @return  An {@link OvsdbNodeAugmentation} instance.
      */
     private OvsdbNodeAugmentation extractOvsdbNode(Node node) {
         return node.getAugmentation(OvsdbNodeAugmentation.class);
     }
 
     /**
+     * Return the node ID in the specified instance identifier.
+     *
      * @param iid instance of InstanceIdentifier.
-     * Returns the NodeId of the Controller.
+     * @return  NodeId of the Controller.
      */
     private NodeId createManagedNodeId(InstanceIdentifier<Node> iid) {
         NodeKey nodeKey = iid.firstKeyOf(Node.class);
@@ -635,9 +556,11 @@ public final class OVSDBEventHandler {
     }
 
     /**
+     * Determine whether the specified bridge is present in the node.
+     *
      * @param ovsdbNode Node value
      * @param bridgeName String value
-     * Returns false if bridge does not exist on the give node.
+     * @return  false if bridge does not exist on the give node.
      */
     private boolean isBridgeOnOvsdbNode(Node ovsdbNode, String bridgeName) {
         boolean found = false;
@@ -659,6 +582,7 @@ public final class OVSDBEventHandler {
 
     /**
      * Get OVSDB Ports.
+     *
      * @param node the OVS node on which the ports are to be read
      * @param action denodes the type of action to read for
      */
@@ -670,8 +594,8 @@ public final class OVSDBEventHandler {
         String value = "";
         if (operNode != null) {
             List<OvsdbTerminationPointAugmentation> ports = extractTerminationPointAugmentations(operNode);
-            OvsdbBridgeAugmentation bridgeNode = getBridgeNode(node,
-                    integrationBridgeName);
+            OvsdbBridgeAugmentation bridgeNode =
+                getBridgeNode(node, bundleConfig.getOvsdbBridgeName());
             for (OvsdbTerminationPointAugmentation port : ports) {
                 List<InterfaceExternalIds> pairs = port.getInterfaceExternalIds();
                 String ovsPortName = port.getName();
@@ -758,7 +682,8 @@ public final class OVSDBEventHandler {
 
     /**
      * Read NeutronPort.
-     * @param uuid
+     *
+     * @param uuid  The UUID associated with the neutron port.
      * @return  Neutron Port.
      */
     private Port readNeutronPort(String uuid) {
@@ -780,10 +705,11 @@ public final class OVSDBEventHandler {
 
     /**
      * Get all BridgeDetails.
-     * @param node
+     *
+     * @param node  A {@link Node} instance.
      * @return OvsdbBridgeAugmentation.
      */
-    private  OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
+    private OvsdbBridgeAugmentation extractBridgeAugmentation(Node node) {
         if (node == null) {
             return null;
         }
@@ -792,8 +718,9 @@ public final class OVSDBEventHandler {
 
     /**
      * Get the Bridge Details for specified bridgeName.
-     * @param node
-     * @param bridgeName
+     *
+     * @param node        A {@link Node} instance.
+     * @param bridgeName  The name of the bridge.
      * @return OvsdbBridgeAugmentation.
      */
     private  OvsdbBridgeAugmentation getBridgeNode(Node node, String bridgeName) {
index c1cfd18ec2925f56ee6c8c897976e534e84e4591..2e66f42a12cdaa4fea6867ebe2a5d1daeb55a151 100644 (file)
@@ -55,11 +55,9 @@ public final class OvsdbDataChangeListener
      * Class constructor setting the data broker.
      *
      * @param db   A {@link DataBroker} instance.
-     * @param md   A {@link MdsalUtils} instance.
-     * @param vtn  A {@link VTNManagerService} instance.
+     * @param ovh  An {@link OVSDBEventHandler} instance.
      */
-    public OvsdbDataChangeListener(DataBroker db, MdsalUtils md,
-                                   VTNManagerService vtn) {
+    public OvsdbDataChangeListener(DataBroker db, OVSDBEventHandler ovh) {
         InstanceIdentifier<Node> path = InstanceIdentifier.
             builder(NetworkTopology.class).
             child(Topology.class,
@@ -69,7 +67,7 @@ public final class OvsdbDataChangeListener
         listenerRegistration = db.registerDataChangeListener(
             LogicalDatastoreType.OPERATIONAL, path, this,
             DataChangeScope.SUBTREE);
-        ovsdbeventHandler = new OVSDBEventHandler(md, vtn);
+        ovsdbeventHandler = ovh;
     }
 
     /**
index 23595c739194532e1c197a6af7bbdc11e6dc7483..58645386550521d7ae938a407069238db950b880 100644 (file)
@@ -106,4 +106,17 @@ public final class VTNNeutronUtils {
     public static String getInterfaceId(Port port) {
         return convertUUIDToKey(port.getUuid());
     }
+
+    /**
+     * Ensure that the given value is not {@code null}.
+     *
+     * @param value  The value to be tested.
+     * @param def    The default value.
+     * @param <T>    The type of the value.
+     * @return  {@code value} is returned if it is not {@code null}.
+     *          {@code def} is returned if {@code value} is {@code null}.
+     */
+    public static <T> T getNonNullValue(T value, T def) {
+        return (value == null) ? def : value;
+    }
 }
index cbba78e07db452ae9b563119b567eeb782a11708..710d3e77633f08018938185cd2a8f23504a83b8f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 NEC Corporation.  All rights reserved.
+ * Copyright (c) 2015, 2016 NEC Corporation. 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,
@@ -12,8 +12,8 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.neutron.rev150922;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.opendaylight.vtn.manager.neutron.impl.NeutronConfig;
 import org.opendaylight.vtn.manager.neutron.impl.NeutronProvider;
-import org.opendaylight.vtn.manager.neutron.impl.OVSDBEventHandler;
 
 import org.opendaylight.controller.config.api.DependencyResolver;
 import org.opendaylight.controller.config.api.ModuleIdentifier;
@@ -41,11 +41,9 @@ public class VTNNeutronModule extends AbstractVTNNeutronModule {
 
     @Override
     public java.lang.AutoCloseable createInstance() {
-        OVSDBEventHandler.ovsdbPortName = getPortName();
-        OVSDBEventHandler.ovsdbBridgeName = getBridgeName();
-        OVSDBEventHandler.ovsdbProtocol = getProtocol();
-        OVSDBEventHandler.ovsdbFailMode = getFailMode();
-        NeutronProvider provider = new NeutronProvider();
+        NeutronConfig cfg = new NeutronConfig(
+            getBridgeName(), getPortName(), getProtocol(), getFailMode());
+        NeutronProvider provider = new NeutronProvider(cfg);
         getBrokerDependency().registerProvider(provider);
 
         return provider;
diff --git a/manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/impl/NeutronConfigTest.java b/manager/neutron/src/test/java/org/opendaylight/vtn/manager/neutron/impl/NeutronConfigTest.java
new file mode 100644 (file)
index 0000000..e2408da
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2016 NEC Corporation. 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.vtn.manager.neutron.impl;
+
+import org.junit.Test;
+
+/**
+ * JUnit test for {@link NeutronConfig}.
+ */
+public final class NeutronConfigTest extends TestBase {
+    /**
+     * The default name of the OVS bridge.
+     */
+    static final String  DEFAULT_BRIDGE_NAME = "br-int";
+
+    /**
+     * The default value of the port name in the OVS bridge.
+     */
+    static final String  DEFAULT_PORT_NAME = "eth0";
+
+    /**
+     * The default value of the OVSDB failmode.
+     */
+    static final String  DEFAULT_FAILMODE = "secure";
+
+    /**
+     * The default value of the protocol used by the OVS.
+     */
+    static final String  DEFAULT_PROTOCOL = "OpenFlow13";
+
+    /**
+     * Test case for {@link NeutronConfig#NeutronConfig()}.
+     */
+    @Test
+    public void testConstructor1() {
+        NeutronConfig cfg = new NeutronConfig();
+        assertEquals(DEFAULT_BRIDGE_NAME, cfg.getOvsdbBridgeName());
+        assertEquals(DEFAULT_PORT_NAME, cfg.getOvsdbPortName());
+        assertEquals(DEFAULT_PROTOCOL, cfg.getOvsdbProtocol());
+        assertEquals(DEFAULT_FAILMODE, cfg.getOvsdbFailMode());
+    }
+
+    /**
+     * Test case for {@link NeutronConfig#getOvsdbBridgeName()}.
+     */
+    @Test
+    public void testGetOvsdbBridgeName() {
+        String[] args = {null, "bridge_1", "bridge_2"};
+        for (String arg: args) {
+            String expected = (arg == null) ? DEFAULT_BRIDGE_NAME : arg;
+            NeutronConfig cfg = new NeutronConfig(arg, null, null, null);
+            assertEquals(expected, cfg.getOvsdbBridgeName());
+            assertEquals(DEFAULT_PORT_NAME, cfg.getOvsdbPortName());
+            assertEquals(DEFAULT_PROTOCOL, cfg.getOvsdbProtocol());
+            assertEquals(DEFAULT_FAILMODE, cfg.getOvsdbFailMode());
+        }
+    }
+
+    /**
+     * Test case for {@link NeutronConfig#getOvsdbPortName()}.
+     */
+    @Test
+    public void testGetOvsdbPortName() {
+        String[] args = {null, "if_1", "eth1"};
+        for (String arg: args) {
+            String expected = (arg == null) ? DEFAULT_PORT_NAME : arg;
+            NeutronConfig cfg = new NeutronConfig(null, arg, null, null);
+            assertEquals(DEFAULT_BRIDGE_NAME, cfg.getOvsdbBridgeName());
+            assertEquals(expected, cfg.getOvsdbPortName());
+            assertEquals(DEFAULT_PROTOCOL, cfg.getOvsdbProtocol());
+            assertEquals(DEFAULT_FAILMODE, cfg.getOvsdbFailMode());
+        }
+    }
+
+    /**
+     * Test case for {@link NeutronConfig#getOvsdbProtocol()}.
+     */
+    @Test
+    public void testGetOvsdbProtocol() {
+        String[] args = {null, "OpenFlow10", "OpenFlow14"};
+        for (String arg: args) {
+            String expected = (arg == null) ? DEFAULT_PROTOCOL : arg;
+            NeutronConfig cfg = new NeutronConfig(null, null, arg, null);
+            assertEquals(DEFAULT_BRIDGE_NAME, cfg.getOvsdbBridgeName());
+            assertEquals(DEFAULT_PORT_NAME, cfg.getOvsdbPortName());
+            assertEquals(expected, cfg.getOvsdbProtocol());
+            assertEquals(DEFAULT_FAILMODE, cfg.getOvsdbFailMode());
+        }
+    }
+
+    /**
+     * Test case for {@link NeutronConfig#getOvsdbFailMode()}.
+     */
+    @Test
+    public void testGetOvsdbFailMode() {
+        String[] args = {null, "standalone", "unknown"};
+        for (String arg: args) {
+            String expected = (arg == null) ? DEFAULT_FAILMODE : arg;
+            NeutronConfig cfg = new NeutronConfig(null, null, null, arg);
+            assertEquals(DEFAULT_BRIDGE_NAME, cfg.getOvsdbBridgeName());
+            assertEquals(DEFAULT_PORT_NAME, cfg.getOvsdbPortName());
+            assertEquals(DEFAULT_PROTOCOL, cfg.getOvsdbProtocol());
+            assertEquals(expected, cfg.getOvsdbFailMode());
+        }
+    }
+
+    /**
+     * Test case for {@link NeutronConfig#toString()}.
+     */
+    @Test
+    public void testToString() {
+        String[] bridges = {null, "bridge_1", "bridge_2"};
+        String[] ports = {null, "eth1", "eth2"};
+        String[] protocols = {null, "OpenFlow10", "OpenFlow14"};
+        String[] failmodes = {null, "standalone", "unknown"};
+        for (String bridge: bridges) {
+            String bname = (bridge == null) ? DEFAULT_BRIDGE_NAME : bridge;
+            for (String port: ports) {
+                String pname = (port == null) ? DEFAULT_PORT_NAME : port;
+                for (String protocol: protocols) {
+                    String proto = (protocol == null)
+                        ? DEFAULT_PROTOCOL : protocol;
+                    for (String failmode: failmodes) {
+                        String mode = (failmode == null)
+                            ? DEFAULT_FAILMODE : failmode;
+                        String expected = "NeutronConfig[bridge-name=" + bname +
+                            ", port-name=" + pname +
+                            ", protocol=" + proto +
+                            ", failmode=" + mode + "]";
+                        NeutronConfig cfg = new NeutronConfig(
+                            bridge, port, protocol, failmode);
+                        assertEquals(expected, cfg.toString());
+                    }
+                }
+            }
+        }
+    }
+}
index 2a93d3101c5ac241bd59a6c50973cc17e5c6230a..04309ca0c569574302dfa34534685ab3257802dc 100644 (file)
@@ -17,6 +17,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.verifyZeroInteractions;
 import static org.mockito.Mockito.when;
 
+import static org.opendaylight.vtn.manager.neutron.impl.NeutronConfigTest.DEFAULT_BRIDGE_NAME;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.security.InvalidParameterException;
@@ -104,7 +106,8 @@ public final class OVSDBEventHandlerTest extends TestBase {
         dataBroker = mock(DataBroker.class);
         utils = Mockito.spy(new MdsalUtils(dataBroker));
         service = PowerMockito.mock(VTNManagerService.class);
-        handler = PowerMockito.spy(new OVSDBEventHandler(utils, service));
+        NeutronConfig cfg = new NeutronConfig();
+        handler = PowerMockito.spy(new OVSDBEventHandler(cfg, utils, service));
     }
 
     /**
@@ -119,15 +122,12 @@ public final class OVSDBEventHandlerTest extends TestBase {
         DataObject mockDataObject = PowerMockito.mock(DataObject.class);
         handler.nodeAdded(mockNode, mockDataObject);
         PowerMockito.verifyPrivate(handler, Mockito.times(1)).
-                                   invoke("createInternalNetworkForNeutron",
-                                    mockNode);
+            invoke("readSystemProperties", mockNode);
         PowerMockito.doThrow(new RuntimeException("Exception for testing...")).
-                        when(handler, "createInternalNetworkForNeutron",
-                             mockNode);
+            when(handler, "readSystemProperties", mockNode);
         handler.nodeAdded(mockNode, mockDataObject);
         PowerMockito.verifyPrivate(handler, Mockito.times(2)).
-                                   invoke("createInternalNetworkForNeutron",
-                                   mockNode);
+            invoke("readSystemProperties", mockNode);
     }
 
     /**
@@ -140,13 +140,11 @@ public final class OVSDBEventHandlerTest extends TestBase {
     public void testNodeRemoved() throws Exception {
         Node mockNode = PowerMockito.mock(Node.class);
         PowerMockito.doReturn(true).
-                        when(handler, "deleteBridge",
-                             Matchers.eq(mockNode), Matchers.eq(null));
+            when(handler, "deleteBridge",
+                 Matchers.eq(mockNode), Matchers.eq(DEFAULT_BRIDGE_NAME));
         handler.nodeRemoved(mockNode);
         PowerMockito.verifyPrivate(handler, Mockito.times(1)).
-                                   invoke("deleteBridge",
-                                   mockNode, null);
-
+            invoke("deleteBridge", mockNode, DEFAULT_BRIDGE_NAME);
     }
 
     /**
@@ -163,7 +161,8 @@ public final class OVSDBEventHandlerTest extends TestBase {
         when(utils.delete(Matchers.eq(LogicalDatastoreType.CONFIGURATION),
                           Matchers.eq(mockInstanceIdentifier))).
             thenReturn(true);
-        handler = PowerMockito.spy(new OVSDBEventHandler(utils, service));
+        NeutronConfig cfg = new NeutronConfig();
+        handler = PowerMockito.spy(new OVSDBEventHandler(cfg, utils, service));
         PowerMockito.doReturn(mockInstanceIdentifier).
             when(handler, "createInstanceIdentifier", null, "br-int");
         boolean output = Whitebox.invokeMethod(
@@ -314,7 +313,8 @@ public final class OVSDBEventHandlerTest extends TestBase {
         when(mockNode.getKey()).thenReturn(key);
         when(key.getNodeId()).thenReturn(mock(NodeId.class));
         MdsalUtils utils2 = PowerMockito.mock(MdsalUtils.class);
-        handler = new OVSDBEventHandler(utils2, service);
+        NeutronConfig cfg = new NeutronConfig();
+        handler = new OVSDBEventHandler(cfg, utils2, service);
         boolean output =
                 Whitebox.invokeMethod(handler,
                                      "addTerminationPoint", mockNode,
@@ -727,16 +727,19 @@ public final class OVSDBEventHandlerTest extends TestBase {
         when(utils.read(Matchers.eq(LogicalDatastoreType.OPERATIONAL),
                         Matchers.any(InstanceIdentifier.class))).
             thenReturn(mockOptional);
-        handler = PowerMockito.spy(new OVSDBEventHandler(utils, service));
+        NeutronConfig cfg = new NeutronConfig();
+        handler = PowerMockito.spy(new OVSDBEventHandler(cfg, utils, service));
         NodeId mockNodeId = mock(NodeId.class);
         mockNodeId = mockovsNode.getNodeId();
         PowerMockito.doReturn(mockInstanceIdentifier).
             when(handler, "createInstanceIdentifier", mockNodeId);
         when(mockOptional.orNull()).thenReturn(mockovsNode);
-        OvsdbBridgeAugmentation mockOvsdbBridgeAugmentation =
-            PowerMockito.mock(OvsdbBridgeAugmentation.class);
-        PowerMockito.doReturn(mockOvsdbBridgeAugmentation).
-            when(handler, "getBridgeNode", mockovsNode, null);
+        OvsdbBridgeAugmentation ovbridge =
+            new OvsdbBridgeAugmentationBuilder().
+            setBridgeName(new OvsdbBridgeName(DEFAULT_BRIDGE_NAME)).
+            build();
+        PowerMockito.doReturn(ovbridge).
+            when(handler, "getBridgeNode", mockovsNode, DEFAULT_BRIDGE_NAME);
         List<InterfaceExternalIds> mockListForExtenralIds =
                                      new ArrayList<InterfaceExternalIds>();
         InterfaceExternalIds mockInterfaceExternalIds =
index bf312855102698e2949249aea5bd9f823a26439a..30c0a040283278a7735707067f2e864e93d5cf65 100644 (file)
@@ -48,68 +48,67 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
  * JUnit test for {@link OvsdbDataChangeListener}.
  */
 @RunWith(PowerMockRunner.class)
-@PrepareForTest({ OvsdbDataChangeListener.class, VTNManagerService.class,
-                  MdsalUtils.class, InstanceIdentifier.class, OfNode.class,
-                  OVSDBEventHandler.class})
+@PrepareForTest({ OvsdbDataChangeListener.class, InstanceIdentifier.class,
+                  OfNode.class, OVSDBEventHandler.class})
 public class OvsdbDataChangeListenerTest {
     /**
      * Mock-up of {@link DataBroker}.
      */
     @Mock
     private DataBroker  dataBroker;
+
     /**
-     * Mock-up of {@link DataBroker}.
-     */
-    @Mock
-    private  MdsalUtils mdUtils;
-    /**
-     * VTNManagerService instance.
+     * OVSDB event handler.
      */
-    private VTNManagerService  vtnManagerService;
+    private OVSDBEventHandler  handler;
+
     /**
      * Registration to be associated with {@link OvsdbDataChangeListener}.
      */
     @Mock
     private ListenerRegistration<DataChangeListener>  listenerReg;
+
     /**
      * An {@link OvsdbDataChangeListener} instance for test.
      */
     private OvsdbDataChangeListener  ovsdbDataChangeListener;
-    private OVSDBEventHandler handler;
+
     /**
      * AsyncDataChangeEvent object reference for unit testing.
      */
     private AsyncDataChangeEvent asyncDataChangeEventMockObj;
+
     /**
      * Collection of InstanceIdentifier and Intent.
      */
     private Map<InstanceIdentifier<?>, DataObject> nodeMap;
+
     /**
      * NetworkKey object reference for unit testing.
      */
     private NodeKey nodeKey;
+
     /**
      * Intent object reference for unit testing.
      */
     private Node node;
+
     /**
      * InstanceIdentifier object reference for unit testing.
      */
     private InstanceIdentifier<?> instanceIdentifier;
+
     /**
      * Set up test environment.
      */
-
     @Before
     public void setUp() throws Exception {
         initMocks(this);
-        vtnManagerService = PowerMockito.mock(VTNManagerService.class);
-        ovsdbDataChangeListener = PowerMockito.
-                               spy(new OvsdbDataChangeListener(dataBroker,
-                                                                         mdUtils,
-                                                                                     vtnManagerService));
+        handler = PowerMockito.mock(OVSDBEventHandler.class);
+        ovsdbDataChangeListener = PowerMockito.spy(
+            new OvsdbDataChangeListener(dataBroker, handler));
         asyncDataChangeEventMockObj =
-                                     PowerMockito.mock(AsyncDataChangeEvent.class);
+            PowerMockito.mock(AsyncDataChangeEvent.class);
         nodeMap = new HashMap<InstanceIdentifier<?>,  DataObject>();
         when(asyncDataChangeEventMockObj.getCreatedData())
                 .thenReturn(nodeMap);
@@ -120,15 +119,14 @@ public class OvsdbDataChangeListenerTest {
         when(node.getKey()).thenReturn(nodeKey);
         instanceIdentifier = PowerMockito.mock(InstanceIdentifier.class);
         //nodeMap.put(instanceIdentifier, node);
-        handler = PowerMockito.
-                            spy(new OVSDBEventHandler(mdUtils, vtnManagerService));
         when(dataBroker.
-                   registerDataChangeListener(any(LogicalDatastoreType.class),
-                                                  any(InstanceIdentifier.class),
-                                          isA(OvsdbDataChangeListener.class),
-                                                              any(DataChangeScope.class))).
-             thenReturn(listenerReg);
+             registerDataChangeListener(any(LogicalDatastoreType.class),
+                                        any(InstanceIdentifier.class),
+                                        isA(OvsdbDataChangeListener.class),
+                                        any(DataChangeScope.class))).
+            thenReturn(listenerReg);
     }
+
     /**
      * Test case for
      * {@link OperationalListener#
@@ -138,18 +136,15 @@ public class OvsdbDataChangeListenerTest {
     public void testConstructor() {
         LogicalDatastoreType oper = LogicalDatastoreType.OPERATIONAL;
         DataChangeScope scope = DataChangeScope.SUBTREE;
-        ovsdbDataChangeListener = new
-                       OvsdbDataChangeListener(dataBroker, mdUtils,
-                                                         vtnManagerService);
+        ovsdbDataChangeListener =
+            new OvsdbDataChangeListener(dataBroker, handler);
+
         // Ensure that NeutronNetworkChangeListener has been registered as data change
         // listener.
-        when(dataBroker.
-                        registerDataChangeListener(eq(oper),
-                                                         eq(getPath()),
-                                                                     eq(ovsdbDataChangeListener),
-                                                                     eq(scope))).
+        when(dataBroker.registerDataChangeListener(
+                 eq(oper), eq(getPath()), eq(ovsdbDataChangeListener),
+                 eq(scope))).
             thenReturn(listenerReg);
-        //handler = new OVSDBEventHandler(mdUtils, vtnManagerService);
         verifyZeroInteractions(listenerReg);
     }
     /**
index 02b365a2c629f864aab193dc1bbaa7f9e5de2da5..ba10261052fe8c0dd678d1655253d3e450f5a88d 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.vtn.manager.neutron.impl;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.convertUUIDToKey;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getBridgeId;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getInterfaceId;
+import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getNonNullValue;
 import static org.opendaylight.vtn.manager.neutron.impl.VTNNeutronUtils.getTenantId;
 
 import java.util.Map.Entry;
@@ -213,4 +214,17 @@ public final class VTNNeutronUtilsTest extends TestBase {
             assertEquals(null, getInterfaceId(pb.setUuid(uuid).build()));
         }
     }
+
+    /**
+     * Test case for {@link VTNNeutronUtils#getNonNullValue(Object,Object)}.
+     */
+    @Test
+    public void testGetNonNullValue() {
+        String def = "default-value";
+        String[] values = {null, "value-1", "value-2"};
+        for (String value: values) {
+            String expected = (value == null) ? def : value;
+            assertSame(expected, getNonNullValue(value, def));
+        }
+    }
 }