use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInput 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.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInput in project genius by opendaylight.
the class InterfacemgrProvider method getEndpointIpForDpn.
@Override
public String getEndpointIpForDpn(BigInteger dpnId) {
GetEndpointIpForDpnInput input = new GetEndpointIpForDpnInputBuilder().setDpid(dpnId).build();
Future<RpcResult<GetEndpointIpForDpnOutput>> output = interfaceManagerRpcService.getEndpointIpForDpn(input);
try {
RpcResult<GetEndpointIpForDpnOutput> ipForDpnOutputRpcResult = output.get();
if (ipForDpnOutputRpcResult.isSuccessful()) {
List<IpAddress> localIps = ipForDpnOutputRpcResult.getResult().getLocalIps();
if (!localIps.isEmpty()) {
return localIps.get(0).getIpv4Address().getValue();
}
}
} catch (NullPointerException | InterruptedException | ExecutionException e) {
LOG.warn("Exception when getting port for interface", e);
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInput in project genius by opendaylight.
the class InterfaceManagerServiceImpl method getEndpointIpForDpn.
@Override
public ListenableFuture<GetEndpointIpForDpnOutput> getEndpointIpForDpn(GetEndpointIpForDpnInput input) {
BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(input.getDpid());
InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier = InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
BridgeEntry bridgeEntry = interfaceMetaUtils.getBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier);
// local ip of any of the bridge interface entry will be the dpn end
// point ip
BridgeInterfaceEntry bridgeInterfaceEntry = bridgeEntry.getBridgeInterfaceEntry().get(0);
InterfaceKey interfaceKey = new InterfaceKey(bridgeInterfaceEntry.getInterfaceName());
Interface interfaceInfo = interfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey);
IfTunnel tunnel = interfaceInfo.getAugmentation(IfTunnel.class);
return Futures.immediateFuture(new GetEndpointIpForDpnOutputBuilder().setLocalIps(Collections.singletonList(tunnel.getTunnelSource())).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInput in project netvirt by opendaylight.
the class TestOdlInterfaceRpcService method getEndpointIpForDpn.
@Override
public Future<RpcResult<GetEndpointIpForDpnOutput>> getEndpointIpForDpn(GetEndpointIpForDpnInput input) {
BigInteger dpnId = input.getDpid();
// if the dpnId is DPN_ID_NO_EXIST, then an empty response will be returned
GetEndpointIpForDpnOutputBuilder builder = new GetEndpointIpForDpnOutputBuilder();
if (dpnId == GeniusProviderTestParams.DPN_ID) {
List<IpAddress> localIpList = new ArrayList<>();
localIpList.add(new IpAddress(new Ipv4Address(GeniusProviderTestParams.IPV4_ADDRESS_STR)));
builder.setLocalIps(localIpList);
} else if (dpnId == GeniusProviderTestParams.DPN_ID_INVALID) {
return Futures.immediateFuture(RpcResultBuilder.<GetEndpointIpForDpnOutput>failed().withError(ErrorType.APPLICATION, "Invalid data.").build());
}
return Futures.immediateFuture(RpcResultBuilder.<GetEndpointIpForDpnOutput>success(builder.build()).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.GetEndpointIpForDpnInput in project genius by opendaylight.
the class InterfaceManagerConfigurationTest method checkTunnelRpcs.
private void checkTunnelRpcs() throws Exception {
// 1. Test endpoint ip fetching for dpn-id
GetEndpointIpForDpnInput endpointIpForDpnInput = new GetEndpointIpForDpnInputBuilder().setDpid(DPN_ID_2).build();
Future<RpcResult<GetEndpointIpForDpnOutput>> endpointIpForDpnOutput = odlInterfaceRpcService.getEndpointIpForDpn(endpointIpForDpnInput);
assertEqualBeans(EndPointIpFromDpn.newEndPointIpFromDpn(), endpointIpForDpnOutput.get().getResult());
// 2. fetch tunnel type from interface-name
GetTunnelTypeInput tunnelTypeInput = new GetTunnelTypeInputBuilder().setIntfName(TUNNEL_INTERFACE_NAME).build();
Future<RpcResult<GetTunnelTypeOutput>> tunnelTypeOutput = odlInterfaceRpcService.getTunnelType(tunnelTypeInput);
assertEqualBeans(TunnelTypeOutput.newTunnelTypeOutput(), tunnelTypeOutput.get().getResult());
}
Aggregations