* 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>
--- /dev/null
+/*
+ * 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 + "]";
+ }
+}
/*
- * 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,
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
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);
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;
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.
*/
/**
* 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.
/**
* 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;
}
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);
}
}
*/
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.
}
/**
- * Create instance identifier
+ * Create instance identifier.
+ *
* @param nodeId is instance of NodeId
* @return The {@link OvsdbBridgeAugmentation} for the manager node.
*/
}
/**
- * 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.
}
/**
- * Get the connection information of the Node
+ * Get the connection information of the Node.
+ *
* @param ovsdbNode is instance of Node
* @return connectionInfo.
*/
}
/**
- * 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.
}
/**
- * 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.
/**
* 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;
/**
* Return the particular port detail of the given Node.
+ *
* @param bridgeNode A {@link Node} instance.
* @param portName The name of the port.
* @return OvsdbTerminationPointAugmentation.
/**
* Returns all port details of the given Node.
+ *
* @param node A {@link Node} instance.
* @return A list of {@link OvsdbTerminationPointAugmentation} instances.
*/
}
/**
- * 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.
/**
* 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.
}
/**
- * 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.
}
/**
- * 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) {
}
/**
+ * Create instance identifier for the specified termination point.
+ *
* @param node A {@link Node} instance.
* @param portName The name of the port.
* @return InstanceIdentifier.
}
/**
+ * Create a list of controller entries.
+ *
* @param targetString is String value.
* @return ControllerEntry ,the Controller details to be set .
*/
/**
* Returns the supported OpenFlow Protocol Type.
+ *
* @return ProtocolEntry.
*/
private List<ProtocolEntry> createMdsalProtocols() {
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);
}
/**
+ * 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;
/**
* 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
*/
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();
/**
* Read NeutronPort.
- * @param uuid
+ *
+ * @param uuid The UUID associated with the neutron port.
* @return Neutron Port.
*/
private Port readNeutronPort(String uuid) {
/**
* 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;
}
/**
* 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) {
* 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,
listenerRegistration = db.registerDataChangeListener(
LogicalDatastoreType.OPERATIONAL, path, this,
DataChangeScope.SUBTREE);
- ovsdbeventHandler = new OVSDBEventHandler(md, vtn);
+ ovsdbeventHandler = ovh;
}
/**
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;
+ }
}
/*
- * 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,
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;
@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;
--- /dev/null
+/*
+ * 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());
+ }
+ }
+ }
+ }
+ }
+}
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;
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));
}
/**
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);
}
/**
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);
}
/**
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(
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,
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 =
* 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);
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#
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);
}
/**
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;
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));
+ }
+ }
}