use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder in project netvirt by opendaylight.
the class VpnElanInterfaceChangeListener method add.
@Override
protected void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
String interfaceName = elanInterface.getName();
if (!elanService.isExternalInterface(interfaceName)) {
LOG.debug("add: Interface {} is not external. Ignoring", interfaceName);
return;
}
Uuid networkId;
try {
networkId = new Uuid(elanInterface.getElanInstanceName());
} catch (IllegalArgumentException e) {
LOG.debug("add: ELAN instance {} for interface {} is not Uuid", elanInterface.getElanInstanceName(), elanInterface.getName());
return;
}
Uuid vpnId = VpnUtil.getExternalNetworkVpnId(broker, networkId);
if (vpnId == null) {
LOG.debug("add: Network {} is not external or vpn-id missing. Ignoring interface {} on elan {}", networkId.getValue(), elanInterface.getName(), elanInterface.getElanInstanceName());
return;
}
VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
List<VpnInstanceNames> listVpn = new ArrayList<>();
listVpn.add(vpnInstance);
VpnInterface vpnInterface = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(interfaceName)).setVpnInstanceNames(listVpn).setScheduledForRemove(Boolean.FALSE).build();
InstanceIdentifier<VpnInterface> vpnInterfaceIdentifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
VpnUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, vpnInterfaceIdentifier, vpnInterface);
LOG.info("add: Added VPN interface {} with VPN-id {} elanInstance {}", interfaceName, vpnId.getValue(), elanInterface.getElanInstanceName());
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder in project netvirt by opendaylight.
the class ArpNotificationHandler method addMipAdjacency.
private void addMipAdjacency(String vpnName, String vpnInterface, IpAddress srcPrefix, String mipMacAddress, IpAddress dstPrefix) {
LOG.trace("Adding {} adjacency to VPN Interface {} ", srcPrefix, vpnInterface);
InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
synchronized (vpnInterface.intern()) {
Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
String nextHopIpAddr = null;
String nextHopMacAddress = null;
String ip = srcPrefix.getIpv4Address().getValue();
if (interfaceManager.isExternalInterface(vpnInterface)) {
String subnetId = getSubnetId(vpnName, dstPrefix.getIpv4Address().getValue());
if (subnetId == null) {
LOG.trace("Can't find corresponding subnet for src IP {}, src MAC {}, dst IP {}, in VPN {}", srcPrefix, mipMacAddress, dstPrefix, vpnName);
return;
}
ip = VpnUtil.getIpPrefix(ip);
AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip).setKey(new AdjacencyKey(ip)).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setMacAddress(mipMacAddress).setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);
List<Adjacency> adjacencyList = adjacencies.isPresent() ? adjacencies.get().getAdjacency() : new ArrayList<>();
adjacencyList.add(newAdjBuilder.build());
Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
Optional<VpnInterface> optionalVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
VpnInterface newVpnIntf;
if (optionalVpnInterface.isPresent()) {
newVpnIntf = new VpnInterfaceBuilder(optionalVpnInterface.get()).addAugmentation(Adjacencies.class, aug).build();
VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
}
LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
return;
}
if (adjacencies.isPresent()) {
List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
ip = VpnUtil.getIpPrefix(ip);
for (Adjacency adjacs : adjacencyList) {
if (adjacs.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
if (adjacs.getIpAddress().equals(ip)) {
LOG.error("The MIP {} is already present as a primary adjacency for interface {} vpn {}." + "Skipping adjacency addition.", ip, vpnInterface, vpnName);
return;
}
nextHopIpAddr = adjacs.getIpAddress();
nextHopMacAddress = adjacs.getMacAddress();
break;
}
}
if (nextHopIpAddr != null) {
String rd = VpnUtil.getVpnRd(dataBroker, vpnName);
long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnName, ip));
if (label == 0) {
LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP adjacency {} " + "to vpn interface {} for vpn {}", ip, vpnInterface, vpnName);
return;
}
String nextHopIp = nextHopIpAddr.split("/")[0];
AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip).setKey(new AdjacencyKey(ip)).setNextHopIpList(Collections.singletonList(nextHopIp)).setAdjacencyType(AdjacencyType.LearntIp);
if (mipMacAddress != null && !mipMacAddress.equalsIgnoreCase(nextHopMacAddress)) {
newAdjBuilder.setMacAddress(mipMacAddress);
}
adjacencyList.add(newAdjBuilder.build());
Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
Optional<VpnInterface> optionalVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
VpnInterface newVpnIntf;
if (optionalVpnInterface.isPresent()) {
newVpnIntf = new VpnInterfaceBuilder(optionalVpnInterface.get()).addAugmentation(Adjacencies.class, aug).build();
VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
}
LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method removeVpnFromVpnInterface.
protected void removeVpnFromVpnInterface(Uuid vpnId, Port port, WriteTransaction writeConfigTxn, Subnetmap sm) {
if (vpnId == null || port == null) {
return;
}
String infName = port.getUuid().getValue();
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
try {
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
List<VpnInstanceNames> listVpn = optionalVpnInterface.get().getVpnInstanceNames();
if (listVpn != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId.getValue(), listVpn)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId.getValue(), listVpn);
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(listVpn);
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
LOG.debug("Updating vpn interface {}", infName);
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
Iterator<Adjacency> adjacencyIter = adjacencyList.iterator();
while (adjacencyIter.hasNext()) {
Adjacency adjacency = adjacencyIter.next();
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
continue;
}
String mipToQuery = adjacency.getIpAddress().split("/")[0];
InstanceIdentifier<LearntVpnVipToPort> id = NeutronvpnUtils.buildLearntVpnVipToPortIdentifier(vpnId.getValue(), mipToQuery);
Optional<LearntVpnVipToPort> optionalVpnVipToPort = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (optionalVpnVipToPort.isPresent()) {
LOG.trace("Removing adjacencies from vpninterface {} upon dissociation of router {}", infName, vpnId);
if (listVpn == null || listVpn.isEmpty()) {
adjacencyIter.remove();
}
neutronvpnUtils.removeLearntVpnVipToPort(vpnId.getValue(), mipToQuery);
LOG.trace("Entry for fixedIP {} for port {} on VPN {} removed from VpnPortFixedIPToPortData", mipToQuery, infName, vpnId.getValue());
}
}
List<FixedIps> ips = port.getFixedIps();
for (FixedIps ip : ips) {
String ipValue = String.valueOf(ip.getIpAddress().getValue());
neutronvpnUtils.removeVpnPortFixedIpToPort(vpnId.getValue(), ipValue, writeConfigTxn);
}
if (listVpn == null || listVpn.isEmpty()) {
if (sm != null && sm.getRouterId() != null) {
removeFromNeutronRouterInterfacesMap(sm.getRouterId(), port.getUuid().getValue());
}
deleteVpnInterface(port.getUuid().getValue(), null, /* vpn-id */
writeConfigTxn);
} else {
writeConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
} else {
LOG.info("removeVpnFromVpnInterface: VPN Interface {} not found", infName);
}
} catch (ReadFailedException ex) {
LOG.error("Update of vpninterface {} failed", infName, ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder in project netvirt by opendaylight.
the class NeutronvpnManager method deleteVpnInterface.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected boolean deleteVpnInterface(String infName, @Nullable String vpnId, WriteTransaction wrtConfigTxn) {
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NeutronvpnUtils.buildVpnInterfaceIdentifier(infName);
Optional<VpnInterface> optionalVpnInterface = null;
try {
optionalVpnInterface = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
} catch (ReadFailedException ex) {
LOG.error("Error during deletion of vpninterface {}", infName, ex);
return false;
}
if (!optionalVpnInterface.isPresent()) {
LOG.warn("Deletion of vpninterface {}, optionalVpnInterface is not present()", infName);
return false;
}
boolean wrtConfigTxnPresent = true;
if (wrtConfigTxn == null) {
wrtConfigTxnPresent = false;
wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
}
if (vpnId != null) {
VpnInterface vpnInterface = optionalVpnInterface.get();
List<VpnInstanceNames> vpnList = vpnInterface.getVpnInstanceNames();
if (vpnList != null && VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnId, vpnList)) {
VpnHelper.removeVpnInterfaceVpnInstanceNamesFromList(vpnId, vpnList);
if (!vpnList.isEmpty()) {
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
LOG.debug("Deleting vpn interface {} not immediately since vpnInstanceName " + "List not empty", infName);
return false;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get()).setVpnInstanceNames(vpnList);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIfBuilder.build());
}
}
LOG.debug("Deleting vpn interface {}", infName);
wrtConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (!wrtConfigTxnPresent) {
wrtConfigTxn.submit();
}
return true;
}
use of org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder in project netvirt by opendaylight.
the class CoeUtils method createVpnInterface.
public static void createVpnInterface(String vpnName, Pods pod, String interfaceName, String macAddress, boolean isRouterInterface, WriteTransaction wrtConfigTxn) {
LOG.trace("createVpnInterface for Port: {}, isRouterInterface: {}", interfaceName, isRouterInterface);
List<VpnInstanceNames> listVpn = new ArrayList<>();
listVpn.add(new VpnInstanceNamesBuilder().setKey(new VpnInstanceNamesKey(vpnName)).setVpnName(vpnName).setAssociatedSubnetType(VpnInstanceNames.AssociatedSubnetType.V4Subnet).build());
VpnInterfaceBuilder vpnb = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(interfaceName)).setName(interfaceName).setVpnInstanceNames(listVpn).setRouterInterface(isRouterInterface);
Adjacencies adjs = createPortIpAdjacencies(pod, interfaceName, macAddress, isRouterInterface);
if (adjs != null) {
vpnb.addAugmentation(Adjacencies.class, adjs);
}
VpnInterface vpnIf = vpnb.build();
LOG.info("Creating vpn interface {}", vpnIf);
InstanceIdentifier<VpnInterface> vpnIfIdentifier = buildVpnInterfaceIdentifier(interfaceName);
wrtConfigTxn.put(LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier, vpnIf);
}
Aggregations