use of org.opendaylight.genius.interfacemanager.exceptions.InterfaceAlreadyExistsException in project genius by opendaylight.
the class InterfacemgrProvider method createVLANInterface.
@Override
public ListenableFuture<Void> createVLANInterface(String interfaceName, String portName, Integer vlanId, String description, IfL2vlan.L2vlanMode l2vlanMode, boolean isExternal) throws InterfaceAlreadyExistsException {
LOG.info("Create VLAN interface : {}", interfaceName);
Interface interfaceOptional = interfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(interfaceName));
if (interfaceOptional != null) {
LOG.debug("VLAN interface already exists {} ", interfaceOptional.getDescription());
throw new InterfaceAlreadyExistsException(interfaceOptional.getName());
}
IfL2vlanBuilder l2vlanBuilder = new IfL2vlanBuilder().setL2vlanMode(l2vlanMode);
if (vlanId != null && vlanId > 0) {
l2vlanBuilder.setVlanId(new VlanId(vlanId));
}
ParentRefs parentRefs = new ParentRefsBuilder().setParentInterface(portName).build();
InterfaceBuilder interfaceBuilder = new InterfaceBuilder().setEnabled(true).setName(interfaceName).setType(L2vlan.class).addAugmentation(IfL2vlan.class, l2vlanBuilder.build()).addAugmentation(ParentRefs.class, parentRefs).setDescription(description);
if (isExternal) {
interfaceBuilder.addAugmentation(IfExternal.class, new IfExternalBuilder().setExternal(true).build());
}
InstanceIdentifier<Interface> interfaceIId = interfaceManagerCommonUtils.getInterfaceIdentifier(new InterfaceKey(interfaceName));
ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.put(CONFIGURATION, interfaceIId, interfaceBuilder.build(), CREATE_MISSING_PARENTS));
ListenableFutures.addErrorLogging(future, LOG, "Failed to (async) write {}", interfaceIId);
return future;
}
use of org.opendaylight.genius.interfacemanager.exceptions.InterfaceAlreadyExistsException in project netvirt by opendaylight.
the class ElanServiceProvider method createIetfInterfaces.
/**
* Create ietf-interfaces based on the ELAN segment type.<br>
* For segment type flat - create transparent interface pointing to the
* patch-port attached to the physnet port.<br>
* For segment type vlan - create trunk interface pointing to the patch-port
* attached to the physnet port + trunk-member interface pointing to the
* trunk interface.
*
* @param elanInstance
* ELAN instance
* @param parentRef
* parent interface name
* @return the name of the interface to be added to the ELAN instance i.e.
* trunk-member name for vlan network and transparent for flat
* network or null otherwise
*/
private String createIetfInterfaces(ElanInstance elanInstance, String parentRef) {
String interfaceName = null;
try {
String trunkName = getTrunkInterfaceName(parentRef);
// trunk interface may have been created by other vlan network
Interface trunkInterface = interfaceManager.getInterfaceInfoFromConfigDataStore(trunkName);
if (trunkInterface == null) {
interfaceManager.createVLANInterface(trunkName, parentRef, null, null, IfL2vlan.L2vlanMode.Trunk, true);
}
if (ElanUtils.isFlat(elanInstance)) {
interfaceName = trunkName;
} else if (ElanUtils.isVlan(elanInstance)) {
Long segmentationId = elanInstance.getSegmentationId();
interfaceName = parentRef + IfmConstants.OF_URI_SEPARATOR + segmentationId;
interfaceManager.createVLANInterface(interfaceName, trunkName, segmentationId.intValue(), null, IfL2vlan.L2vlanMode.TrunkMember, true);
}
} catch (InterfaceAlreadyExistsException e) {
LOG.trace("Interface {} was already created", interfaceName);
}
return interfaceName;
}
Aggregations