} else {
String vtname = vpath.getTerminalName();
if (vtname == null) {
- ident = VTenantIdentifier.create(tname, find);
+ ident = createTenantIdentifier(tname, iname, find);
} else {
ident = (iname == null)
? VTerminalIdentifier.create(tname, vtname, find)
return RpcException.getBadArgumentException(msg);
}
+ /**
+ * Create a new identifier for the VTN.
+ *
+ * <p>
+ * This method is called by {@link #create(VnodePathFields, boolean)}
+ * if the specified vnode-path-fields does not specify the name of the
+ * virtual bridge.
+ * </p>
+ *
+ * @param tname The name of the VTN specified by vnode-path-fields.
+ * @param iname The name of the virtual interface specified by
+ * vnode-path-fields.
+ * @param find {@code true} indicates the given name is used for
+ * finding existing virtual node.
+ * @return A {@link VTenantIdentifier} instance that specifies the
+ * location of the VTN.
+ * @throws RpcException An error occurred.
+ */
+ private static VTenantIdentifier createTenantIdentifier(
+ String tname, String iname, boolean find) throws RpcException {
+ VTenantIdentifier ident;
+ if (iname == null) {
+ ident = VTenantIdentifier.create(tname, find);
+ } else {
+ // No virtual bridge name is specified though virtual interface
+ // name is specified. This should be treated as an invalid path.
+ if (tname == null) {
+ VNodeType.VTN.checkName(null, find);
+ }
+
+ throw RpcException.getNullArgumentException("Virtual bridge name");
+ }
+
+ return ident;
+ }
+
/**
* Default constructor only for JAXB.
*/
}
}
+ // Virtual bridge name is not specified though VTN and interface name
+ // are specified.
+ tnames = new String[]{null, "vtn", "vtn1"};
+ for (String tname: tnames) {
+ VnodePathFields noBridge = mock(VnodePathFields.class);
+ when(noBridge.getTenantName()).thenReturn(tname);
+ when(noBridge.getInterfaceName()).thenReturn(inames[0]);
+ String msg = (tname == null)
+ ? "VTN name cannot be null"
+ : "Virtual bridge name cannot be null";
+ for (boolean find: bools) {
+ try {
+ VNodeIdentifier.create(noBridge, find);
+ unexpected();
+ } catch (RpcException e) {
+ assertEquals(RpcErrorTag.MISSING_ELEMENT, e.getErrorTag());
+ assertEquals(VtnErrorTag.BADREQUEST, e.getVtnErrorTag());
+ assertEquals(msg, e.getMessage());
+ }
+ }
+ }
+
// Specifying invalid name (read).
String badName = "bad name";
Map<VnodePathFields, String> cases = new HashMap<>();