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.IpAddresses in project netvirt by opendaylight.
the class NatUtil method isFloatingIpPresentForDpn.
public static Boolean isFloatingIpPresentForDpn(DataBroker dataBroker, BigInteger dpnId, String rd, String vpnName, String externalIp, Boolean isMoreThanOneFipCheckOnDpn) {
InstanceIdentifier<VpnToDpnList> id = getVpnToDpnListIdentifier(rd, dpnId);
Optional<VpnToDpnList> dpnInVpn = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (dpnInVpn.isPresent()) {
LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list is not empty for vpnName {}, dpn id {}, " + "rd {} and floatingIp {}", vpnName, dpnId, rd, externalIp);
try {
List<IpAddresses> ipAddressList = dpnInVpn.get().getIpAddresses();
if (ipAddressList != null && !ipAddressList.isEmpty()) {
int floatingIpPresentCount = 0;
for (IpAddresses ipAddress : ipAddressList) {
if (!ipAddress.getIpAddress().equals(externalIp) && IpAddresses.IpAddressSource.FloatingIP.equals(ipAddress.getIpAddressSource())) {
floatingIpPresentCount++;
// Add tunnel table check
if (isMoreThanOneFipCheckOnDpn && floatingIpPresentCount > 1) {
return Boolean.TRUE;
}
// Remove tunnel table check
if (!isMoreThanOneFipCheckOnDpn) {
return Boolean.TRUE;
}
}
}
} else {
LOG.debug("isFloatingIpPresentForDpn : vpn-to-dpn-list does not contain any floating IP for DPN {}", dpnId);
return Boolean.FALSE;
}
} catch (NullPointerException e) {
LOG.error("isFloatingIpPresentForDpn: Exception occurred on getting external IP address from " + "vpn-to-dpn-list on Dpn {}", dpnId, e);
return Boolean.FALSE;
}
}
return Boolean.FALSE;
}
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.IpAddresses in project netvirt by opendaylight.
the class VPNServiceChainHandlerTest method stubGetVpnInstance.
private void stubGetVpnInstance(String rd, String ipAddress, String ifaceName) throws Exception {
IpAddresses ipAddr = new IpAddressesBuilder().setIpAddress(ipAddress).setKey(new IpAddressesKey(ipAddress)).build();
List<VpnInterfaces> ifacesList = Collections.singletonList(new VpnInterfacesBuilder().setInterfaceName(ifaceName).build());
VpnToDpnListBuilder vtdlb = new VpnToDpnListBuilder().setKey(new VpnToDpnListKey(DPN_ID)).setDpnId(DPN_ID).setIpAddresses(Collections.singletonList(ipAddr)).setVpnInterfaces(ifacesList);
VpnInstanceOpDataEntry vpnInstanceOpDataEntry = new VpnInstanceOpDataEntryBuilder().setKey(new VpnInstanceOpDataEntryKey(rd)).setVpnId(VPN_ID).setVpnToDpnList(Collections.singletonList(vtdlb.build())).setVrfId("1").build();
CheckedFuture chkdFuture = mock(CheckedFuture.class);
when(chkdFuture.checkedGet()).thenReturn(Optional.of(vpnInstanceOpDataEntry));
when(readTx.read(eq(LogicalDatastoreType.OPERATIONAL), eq(VpnServiceChainUtils.getVpnInstanceOpDataIdentifier(rd)))).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.IpAddresses in project netvirt by opendaylight.
the class GeniusProvider method getIpFromDpnId.
// TODO Should better use the Genius InterfaceManager to avoid duplicate code
// https://bugs.opendaylight.org/show_bug.cgi?id=8127
public Optional<String> getIpFromDpnId(DpnIdType dpnid) {
GetEndpointIpForDpnInputBuilder builder = new GetEndpointIpForDpnInputBuilder();
builder.setDpid(dpnid.getValue());
GetEndpointIpForDpnInput input = builder.build();
if (interfaceManagerRpcService == null) {
LOG.error("getIpFromDpnId({}) failed (service couldn't be retrieved)", input);
return Optional.empty();
}
try {
LOG.debug("getIpFromDpnId: invoking rpc");
RpcResult<GetEndpointIpForDpnOutput> output = interfaceManagerRpcService.getEndpointIpForDpn(input).get();
if (!output.isSuccessful()) {
LOG.error("getIpFromDpnId({}) failed: {}", input, output);
return Optional.empty();
}
LOG.debug("getDpnIdFromInterfaceName({}) succeeded: {}", input, output);
List<IpAddress> localIps = output.getResult().getLocalIps();
// TODO need to figure out why it returns a list, using first entry for now
return Optional.ofNullable(localIps).filter(ipAddresses -> !ipAddresses.isEmpty()).map(ipAddresses -> ipAddresses.get(0)).map(IpAddress::getIpv4Address).map(Ipv4Address::getValue);
} catch (InterruptedException | ExecutionException e) {
LOG.error("getDpnIdFromInterfaceName failed to retrieve target interface name: ", e);
}
return Optional.empty();
}
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.IpAddresses in project netvirt by opendaylight.
the class VpnFootprintService method removeOrUpdateVpnToDpnListForIpAddress.
private void removeOrUpdateVpnToDpnListForIpAddress(long vpnId, String rd, BigInteger dpnId, ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, 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<IpAddresses> ipAddresses = dpnInVpn.getIpAddresses();
if (ipAddresses == null) {
LOG.info("Could not find ipAddresses for DpnInVpn map for VPN=[name={} rd={} id={}] and dpnId={}", vpnName, rd, id, dpnId);
return;
}
IpAddresses currIpAddress = new IpAddressesBuilder().setKey(new IpAddressesKey(ipAddressSourceValuePair.getValue())).setIpAddressSource(ipAddressSourceValuePair.getKey()).build();
if (ipAddresses.remove(currIpAddress)) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
if (ipAddresses.isEmpty()) {
List<VpnInterfaces> vpnInterfaces = dpnInVpn.getVpnInterfaces();
VpnToDpnListBuilder dpnInVpnBuilder = new VpnToDpnListBuilder(dpnInVpn).setIpAddresses(null);
if (vpnInterfaces == null || vpnInterfaces.isEmpty()) {
dpnInVpnBuilder.setDpnState(VpnToDpnList.DpnState.Inactive);
lastDpnOnVpn = Boolean.TRUE;
} else {
LOG.warn("ip addresses are empty but vpn interfaces are present for the vpn {} in dpn {}", vpnName, dpnId);
}
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, dpnInVpnBuilder.build(), true);
} else {
writeTxn.delete(LogicalDatastoreType.OPERATIONAL, id.child(IpAddresses.class, new IpAddressesKey(ipAddressSourceValuePair.getValue())));
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error removing from dpnToVpnList for vpn {} Ipaddress {} dpn {}", vpnName, ipAddressSourceValuePair.getValue(), dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
}
if (lastDpnOnVpn) {
LOG.debug("Sending cleanup event for dpn {} in VPN {}", dpnId, vpnName);
fibManager.cleanUpDpnForVpn(dpnId, vpnId, rd, new DpnEnterExitVpnWorker(dpnId, vpnName, rd, false));
}
}
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.IpAddresses in project netvirt by opendaylight.
the class VpnFootprintService method createOrUpdateVpnToDpnListForIPAddress.
private void createOrUpdateVpnToDpnListForIPAddress(long vpnId, String primaryRd, BigInteger dpnId, ImmutablePair<IpAddresses.IpAddressSource, String> ipAddressSourceValuePair, String vpnName) {
Boolean newDpnOnVpn = Boolean.FALSE;
synchronized (vpnName.intern()) {
WriteTransaction writeTxn = dataBroker.newWriteOnlyTransaction();
InstanceIdentifier<VpnToDpnList> id = VpnUtil.getVpnToDpnListIdentifier(primaryRd, dpnId);
Optional<VpnToDpnList> dpnInVpn = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
IpAddressesBuilder ipAddressesBldr = new IpAddressesBuilder().setIpAddressSource(ipAddressSourceValuePair.getKey());
ipAddressesBldr.setKey(new IpAddressesKey(ipAddressSourceValuePair.getValue()));
ipAddressesBldr.setIpAddress(ipAddressSourceValuePair.getValue());
if (dpnInVpn.isPresent()) {
VpnToDpnList vpnToDpnList = dpnInVpn.get();
List<IpAddresses> ipAddresses = vpnToDpnList.getIpAddresses();
if (ipAddresses == null) {
ipAddresses = new ArrayList<>();
}
ipAddresses.add(ipAddressesBldr.build());
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder(vpnToDpnList);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setIpAddresses(ipAddresses);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), true);
/*
* If earlier state was inactive, it is considered new DPN coming back to the
* same VPN
*/
if (vpnToDpnList.getDpnState() == VpnToDpnList.DpnState.Inactive) {
newDpnOnVpn = Boolean.TRUE;
}
} else {
List<IpAddresses> ipAddresses = new ArrayList<>();
ipAddresses.add(ipAddressesBldr.build());
VpnToDpnListBuilder vpnToDpnListBuilder = new VpnToDpnListBuilder().setDpnId(dpnId);
vpnToDpnListBuilder.setDpnState(VpnToDpnList.DpnState.Active).setIpAddresses(ipAddresses);
writeTxn.put(LogicalDatastoreType.OPERATIONAL, id, vpnToDpnListBuilder.build(), true);
newDpnOnVpn = Boolean.TRUE;
}
try {
writeTxn.submit().get();
} catch (InterruptedException | ExecutionException e) {
LOG.error("Error adding to dpnToVpnList for vpn {} ipAddresses {} dpn {}", vpnName, ipAddressSourceValuePair.getValue(), dpnId, e);
throw new RuntimeException(e.getMessage(), e);
}
}
/*
* Informing the Fib only after writeTxn is submitted successfuly.
*/
if (newDpnOnVpn) {
LOG.debug("Sending populateFib event for new dpn {} in VPN {}", dpnId, vpnName);
fibManager.populateFibOnNewDpn(dpnId, vpnId, primaryRd, new DpnEnterExitVpnWorker(dpnId, vpnName, primaryRd, true));
}
}
Aggregations