use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onSubnetDeletedFromVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetDeletedFromVpn(Subnetmap subnetmap, boolean isBgpVpn) {
Uuid subnetId = subnetmap.getId();
LOG.info("{} onSubnetDeletedFromVpn: Subnet {} with ip {} being removed from vpnId {}", LOGGING_PREFIX, subnetId, subnetmap.getSubnetIp(), subnetmap.getVpnId());
// TODO(vivek): Change this to use more granularized lock at subnetId level
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (!optionalSubs.isPresent()) {
LOG.error("{} onSubnetDeletedFromVpn: SubnetOpDataEntry for subnet {} subnetIp {} vpn {}" + " not available in datastore", LOGGING_PREFIX, subnetId.getValue(), subnetId.getValue(), subnetmap.getVpnId());
return;
}
LOG.trace("{} onSubnetDeletedFromVpn: Removing the SubnetOpDataEntry node for subnet {} subnetIp {}" + " vpnName {} rd {} TaskState {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState());
/* If subnet is deleted (or if its removed from VPN), the ports that are DOWN on that subnet
* will continue to be stale in portOpData DS, as subDpnList used for portOpData removal will
* contain only ports that are UP. So here we explicitly cleanup the ports of the subnet by
* going through the list of ports on the subnet
*/
InstanceIdentifier<Subnetmap> subMapid = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
Optional<Subnetmap> sm = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subMapid);
if (!sm.isPresent()) {
LOG.error("{} onSubnetDeletedFromVpn: Stale ports removal: Unable to retrieve subnetmap entry" + " for subnet {} subnetIp {} vpnName {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName());
} else {
Subnetmap subMap = sm.get();
List<Uuid> portList = subMap.getPortList();
if (portList != null) {
for (Uuid port : portList) {
InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(port.getValue())).build();
LOG.trace("{} onSubnetDeletedFromVpn: Deleting portOpData entry for port {}" + " from subnet {} subnetIp {} vpnName {} TaskState {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getRouteAdvState());
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
}
}
}
SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get());
String rd = subOpBuilder.getVrfId();
String subnetIp = subOpBuilder.getSubnetCidr();
String vpnName = subOpBuilder.getVpnName();
// Withdraw the routes for all the interfaces on this subnet
// Remove subnet route entry from FIB
deleteSubnetRouteFromFib(rd, subnetIp, vpnName, isBgpVpn);
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
LOG.info("{} onSubnetDeletedFromVpn: Removed subnetopdataentry successfully from Datastore" + " for subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd);
} catch (RuntimeException ex) {
LOG.error("{} onSubnetDeletedFromVpn: Removal of SubnetOpDataEntry for subnet {} subnetIp {}" + " vpnId {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetmap.getSubnetIp(), subnetmap.getVpnId(), ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (RuntimeException e) {
LOG.error("{} onSubnetDeletedFromVpn: Unable to handle subnet {} with Ip {} removed from vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetmap.getSubnetIp(), subnetmap.getVpnId(), e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey in project netvirt by opendaylight.
the class SubnetOpDpnManagerTest method setupMocks.
private void setupMocks() {
List<VpnInterfaces> vpnInterfaces = new ArrayList<>();
List<Uuid> subnetIdList = new ArrayList<>();
subnetIdList.add(subnetId);
subnetToDpn = new SubnetToDpnBuilder().setDpnId(dpId).setKey(new SubnetToDpnKey(dpId)).setVpnInterfaces(vpnInterfaces).build();
portOp = new PortOpDataEntryBuilder().setDpnId(dpId).setKey(new PortOpDataEntryKey(infName)).setSubnetIds(subnetIdList).setPortId(portId).build();
doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey in project netvirt by opendaylight.
the class VpnSubnetRouteHandlerTest method setupMocks.
private void setupMocks() {
nexthopIp = "10.1.1.25";
idKey = "100:1.10.1.1.24";
poolName = "vpnservices";
elanTag = 2L;
longId = Long.valueOf("100");
nodeConnectorId = buildNodeConnectorId(dpId, 2L);
ipAddress = IpAddressBuilder.getDefaultInstance(nexthopIp);
vpnIntfaces = new VpnInterfacesBuilder().setInterfaceName(interfaceName).setKey(new VpnInterfacesKey(interfaceName)).build();
List<VpnInterfaces> vpnInterfaces = new ArrayList<>();
final List<SubnetToDpn> subToDpn = new ArrayList<>();
final List<Uuid> portList = new ArrayList<>();
final List<PortOpDataEntry> listPortOpDataEntry = new ArrayList<>();
final List<TunnelEndPoints> tunnelEndPoints = new ArrayList<>();
List<Uuid> subnetIdList = new ArrayList<>();
subnetIdList.add(subnetId);
vpnInterfaces.add(vpnIntfaces);
lowerLayerIfList.add(nodeConnectorId.getValue());
portOp = new PortOpDataEntryBuilder().setDpnId(dpId).setKey(new PortOpDataEntryKey(tenantId.getValue())).setSubnetIds(subnetIdList).setPortId(tenantId.getValue()).build();
subnetToDpn = new SubnetToDpnBuilder().setDpnId(dpId).setKey(new SubnetToDpnKey(dpId)).setVpnInterfaces(vpnInterfaces).build();
allocateIdOutput = new AllocateIdOutputBuilder().setIdValue(longId).build();
allocateIdInput = new AllocateIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
subToDpn.add(subnetToDpn);
portList.add(portId);
listPortOpDataEntry.add(portOp);
org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder ifaceBuilder = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceBuilder();
ifaceBuilder.setLowerLayerIf(lowerLayerIfList).setType(L2vlan.class).setAdminStatus(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.AdminStatus.Up).setOperStatus(Interface.OperStatus.Up).setIfIndex(100).setKey(new InterfaceKey(interfaceName)).setName(interfaceName).setPhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress.getDefaultInstance("AA:AA:AA:AA:AA:AA"));
stateInterface = ifaceBuilder.build();
subnetOp = new SubnetOpDataEntryBuilder().setElanTag(elanTag).setNhDpnId(dpId).setSubnetCidr(subnetIp).setSubnetId(subnetId).setKey(new SubnetOpDataEntryKey(subnetId)).setVpnName(interfaceName).setVrfId(primaryRd).setSubnetToDpn(subToDpn).setRouteAdvState(TaskState.Advertised).build();
vpnInstance = new VpnInstanceBuilder().setVpnId(elanTag).setVpnInstanceName(interfaceName).setVrfId(interfaceName).setKey(new VpnInstanceKey(interfaceName)).build();
subnetmap = new SubnetmapBuilder().setSubnetIp(subnetIp).setId(subnetId).setNetworkId(portId).setKey(new SubnetmapKey(subnetId)).setRouterId(portId).setVpnId(subnetId).setTenantId(tenantId).setPortList(portList).build();
portOpData = new PortOpDataBuilder().setPortOpDataEntry(listPortOpDataEntry).build();
dpntePsInfo = new DPNTEPsInfoBuilder().setDPNID(dpId).setUp(true).setKey(new DPNTEPsInfoKey(dpId)).setTunnelEndPoints(tunnelEndPoints).build();
tunlEndPts = new TunnelEndPointsBuilder().setInterfaceName(interfaceName).setVLANID(10).setIpAddress(ipAddress).build();
tunnelEndPoints.add(tunlEndPts);
ipv4Family = new Ipv4FamilyBuilder().setRouteDistinguisher(routeDistinguishers).build();
vpnInstnce = new org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceBuilder().setKey(new org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstanceKey(interfaceName)).setVpnInstanceName(interfaceName).setIpv4Family(ipv4Family).build();
networks = new NetworksBuilder().setId(portId).setKey(new NetworksKey(portId)).build();
doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey in project netvirt by opendaylight.
the class SubnetOpDpnManager method removePortOpDataEntry.
public PortOpDataEntry removePortOpDataEntry(String intfName, Uuid subnetId) {
// Remove PortOpData and return out
InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
PortOpDataEntry portOpEntry = null;
Optional<PortOpDataEntry> optionalPortOp = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
if (!optionalPortOp.isPresent()) {
LOG.info("removePortOpDataEntry: Cannot delete, portOp for port {} is not available in datastore", intfName);
return null;
} else {
portOpEntry = optionalPortOp.get();
List<Uuid> listSubnet = portOpEntry.getSubnetIds();
if (listSubnet == null) {
listSubnet = new ArrayList<>();
}
if (subnetId != null && listSubnet.contains(subnetId)) {
listSubnet.remove(subnetId);
}
if (listSubnet.isEmpty() || subnetId == null) {
MDSALUtil.syncDelete(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
LOG.info("removePortOpDataEntry: Deleted portOpData entry for port {}", intfName);
} else {
try {
PortOpDataEntryBuilder portOpBuilder = null;
portOpBuilder = new PortOpDataEntryBuilder(portOpEntry);
portOpBuilder.setSubnetIds(listSubnet);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier, portOpEntry);
LOG.info("removePortOpDataEntry: Updated PortOpData entry for port {} with removing subnetId {}", intfName, subnetId.getValue());
} catch (TransactionCommitFailedException ex) {
LOG.error("removePortOpDataEntry failed: Updated PortOpData entry for port {}" + " with removing subnetId {}", intfName, subnetId.getValue());
}
return null;
}
}
return portOpEntry;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey in project netvirt by opendaylight.
the class SubnetOpDpnManager method addPortOpDataEntry.
public void addPortOpDataEntry(String intfName, Uuid subnetId, BigInteger dpnId) {
try {
// Add to PortOpData as well.
PortOpDataEntryBuilder portOpBuilder = null;
PortOpDataEntry portOpEntry = null;
InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
Optional<PortOpDataEntry> optionalPortOp = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
if (!optionalPortOp.isPresent()) {
// Create PortOpDataEntry only if not present
portOpBuilder = new PortOpDataEntryBuilder().setKey(new PortOpDataEntryKey(intfName)).setPortId(intfName);
List<Uuid> listSubnet = new ArrayList<>();
listSubnet.add(subnetId);
portOpBuilder.setSubnetIds(listSubnet);
} else {
List<Uuid> listSubnet = optionalPortOp.get().getSubnetIds();
portOpBuilder = new PortOpDataEntryBuilder(optionalPortOp.get());
if (listSubnet == null) {
listSubnet = new ArrayList<>();
}
if (!listSubnet.contains(subnetId)) {
listSubnet.add(subnetId);
}
portOpBuilder.setSubnetIds(listSubnet);
}
if (dpnId != null && !dpnId.equals(BigInteger.ZERO)) {
portOpBuilder.setDpnId(dpnId);
}
portOpEntry = portOpBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier, portOpEntry);
LOG.info("addPortOpDataEntry: Created PortOpData entry for port {} with DPNId {} subnetId {}", intfName, dpnId, subnetId.getValue());
} catch (TransactionCommitFailedException ex) {
LOG.error("addPortOpDataEntry: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
}
}
Aggregations