use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey in project netvirt by opendaylight.
the class SubnetOpDpnManager method removeInterfaceFromDpn.
public boolean removeInterfaceFromDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
boolean dpnRemoved = false;
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
LOG.debug("removeInterfaceFromDpn: Cannot delete, SubnetToDpn for intf {} subnet {} DPN {}" + " not available in datastore", intfName, subnetId.getValue(), dpnId);
return false;
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.remove(vpnIntfs);
if (vpnIntfList.isEmpty()) {
// Remove the DPN as well
removeDpnFromSubnet(subnetId, dpnId);
dpnRemoved = true;
} else {
subDpnBuilder.setVpnInterfaces(vpnIntfList);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpnBuilder.build());
}
LOG.info("removeInterfaceFromDpn: Removed interface {} from sunbet {} dpn {}", intfName, subnetId.getValue(), dpnId);
} catch (TransactionCommitFailedException ex) {
LOG.error("removeInterfaceFromDpn: Deletion of Interface {} for SubnetToDpn on subnet {}" + " with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
return false;
}
return dpnRemoved;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey in project netvirt by opendaylight.
the class SubnetOpDpnManager method addInterfaceToDpn.
public SubnetToDpn addInterfaceToDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
SubnetToDpn subDpn = null;
try {
// Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
// Please use a synchronize block here as we donot need a cluster-wide lock
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
// Create a new DPN Entry
subDpn = addDpnToSubnet(subnetId, dpnId);
} else {
subDpn = optionalSubDpn.get();
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.add(vpnIntfs);
subDpnBuilder.setVpnInterfaces(vpnIntfList);
subDpn = subDpnBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}", subnetId.getValue(), dpnId, intfName);
} catch (TransactionCommitFailedException ex) {
LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
return null;
}
return subDpn;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey in project netvirt by opendaylight.
the class VPNServiceChainHandlerTest method stubReadVpnToDpnList.
private void stubReadVpnToDpnList(String rd, BigInteger dpnId, List<String> vpnIfacesOnDpn) throws Exception {
List<VpnInterfaces> vpnIfacesList = vpnIfacesOnDpn.stream().map((ifaceName) -> new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(ifaceName)).setInterfaceName(ifaceName).build()).collect(Collectors.toList());
CheckedFuture chkdFuture = mock(CheckedFuture.class);
when(chkdFuture.checkedGet()).thenReturn(Optional.of(vpnIfacesList));
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), eq(VpnServiceChainUtils.getVpnToDpnListIdentifier(rd, dpnId)))).thenReturn(chkdFuture);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey in project netvirt by opendaylight.
the class VpnFootprintService method removeOrUpdateVpnToDpnListForInterfaceName.
private void removeOrUpdateVpnToDpnListForInterfaceName(long vpnId, String rd, BigInteger dpnId, String intfName, String vpnName) {
Boolean lastDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(rd, dpnId);
VpnToDpnList dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id).orNull();
if (dpnInVpn == null) {
LOG.error("removeOrUpdateVpnToDpnList: Could not find DpnToVpn map for VPN=[name={} rd={} id={}]" + " and dpnId={}", vpnName, rd, id, dpnId);
return;
}
List<VpnInterfaces> vpnInterfaces = dpnInVpn.getVpnInterfaces();
if (vpnInterfaces == null) {
LOG.error("Could not find vpnInterfaces for DpnInVpn map for VPN=[name={} rd={} id={}] and dpnId={}", vpnName, rd, id, dpnId);
return;
}
VpnInterfaces currVpnInterface = new VpnInterfacesBuilder().setInterfaceName(intfName).build();
if (vpnInterfaces.remove(currVpnInterface)) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
if (vpnInterfaces.isEmpty()) {
List<IpAddresses> ipAddresses = dpnInVpn.getIpAddresses();
VpnToDpnListBuilder dpnInVpnBuilder = new VpnToDpnListBuilder(dpnInVpn).setVpnInterfaces(null);
if (ipAddresses == null || ipAddresses.isEmpty()) {
dpnInVpnBuilder.setDpnState(VpnToDpnList.DpnState.Inactive);
lastDpnOnVpn = Boolean.TRUE;
} else {
LOG.error("removeOrUpdateVpnToDpnList: vpn interfaces are empty but ip addresses are present" + " for the vpn {} in dpn {} interface {}", vpnName, dpnId, intfName);
}
LOG.debug("removeOrUpdateVpnToDpnList: Removing vpn footprint for vpn {} vpnId {} interface {}," + " on dpn {}", vpnName, vpnName, intfName, dpnId);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, dpnInVpnBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
} else {
writeTxn.delete(LogicalDatastoreType.OPERATIONAL, id.child(VpnInterfaces.class, new VpnInterfacesKey(intfName)));
LOG.debug("removeOrUpdateVpnToDpnList: Updating vpn footprint for vpn {} vpnId {} interface {}," + " on dpn {}", vpnName, vpnName, intfName, dpnId);
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("removeOrUpdateVpnToDpnList: Error removing from dpnToVpnList for vpn {} vpnId {}" + " interface {} dpn {}", vpnName, vpnId, intfName, dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
// Ends synchronized block
LOG.info("removeOrUpdateVpnToDpnList: Updated/Removed vpn footprint for vpn {} vpnId {} interface {}," + " on dpn {}", vpnName, vpnName, intfName, dpnId);
if (lastDpnOnVpn) {
fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd, new DpnEnterExitVpnWorker(dpnId, vpnName, rd, false));
LOG.info("removeOrUpdateVpnToDpnList: Sent cleanup event for dpn {} in VPN {} vpnId {} interface {}", dpnId, vpnName, vpnId, intfName);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.VpnInterfacesKey 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();
}
Aggregations