use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class L2GatewayUtils method createItmTunnels.
protected static void createItmTunnels(ItmRpcService itmRpcService, String hwvtepId, String psName, IpAddress tunnelIp) {
AddL2GwDeviceInputBuilder builder = new AddL2GwDeviceInputBuilder();
builder.setTopologyId(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID.getValue());
builder.setNodeId(HwvtepSouthboundUtils.createManagedNodeId(new NodeId(hwvtepId), psName).getValue());
builder.setIpAddress(tunnelIp);
try {
Future<RpcResult<Void>> result = itmRpcService.addL2GwDevice(builder.build());
RpcResult<Void> rpcResult = result.get();
if (rpcResult.isSuccessful()) {
LOG.info("Created ITM tunnels for {}", hwvtepId);
} else {
LOG.error("Failed to create ITM Tunnels: {}", rpcResult.getErrors());
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("RPC to create ITM tunnels failed", e);
}
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class ConfigureL3VpnCommand method createL3VpnCLI.
private void createL3VpnCLI() throws InterruptedException, ExecutionException {
if (vid == null) {
session.getConsole().println("Please supply a valid VPN ID");
session.getConsole().println(getHelp("create"));
return;
}
if (rd == null) {
session.getConsole().println("Please supply a valid RD");
session.getConsole().println(getHelp("create"));
return;
}
if (irt == null) {
session.getConsole().println("Please supply a valid list of import RTs separated by {,}");
session.getConsole().println(getHelp("create"));
return;
}
if (ert == null) {
session.getConsole().println("Please supply a valid list of export RTs separated by {,}");
session.getConsole().println(getHelp("create"));
return;
}
Uuid vuuid = new Uuid(vid);
RpcResult<CreateL3VPNOutput> createL3VpnRpcResult = null;
{
ArrayList<String> rdList = new ArrayList<>(Arrays.asList(rd.split(",")));
ArrayList<String> irtList = new ArrayList<>(Arrays.asList(irt.split(",")));
ArrayList<String> ertList = new ArrayList<>(Arrays.asList(ert.split(",")));
Uuid tuuid = null;
if (tid != null) {
tuuid = new Uuid(tid);
}
List<L3vpn> l3vpns = new ArrayList<>();
L3vpn l3vpn = new L3vpnBuilder().setId(vuuid).setName(name).setRouteDistinguisher(rdList).setImportRT(irtList).setExportRT(ertList).setTenantId(tuuid).build();
l3vpns.add(l3vpn);
Future<RpcResult<CreateL3VPNOutput>> result = neutronvpnService.createL3VPN(new CreateL3VPNInputBuilder().setL3vpn(l3vpns).build());
createL3VpnRpcResult = result.get();
if (createL3VpnRpcResult.isSuccessful()) {
session.getConsole().println("L3VPN created successfully");
LOG.trace("createl3vpn: {}", result);
} else {
session.getConsole().println("Error populating createL3VPN : " + result.get().getErrors());
session.getConsole().println(getHelp("create"));
}
}
/**
* passing a subnetId list alongwith create-l3-vpn CLI implicitly indicates that
* association of network(s) to VPN is being intended.
*/
if (createL3VpnRpcResult.isSuccessful()) {
{
List<Uuid> networkIdList = new ArrayList<>();
if (sid != null) {
for (String sidStr : sid.split(",")) {
Uuid subnetId = new Uuid(sidStr);
Uuid networkId = neutronVpnManager.getNetworkForSubnet(subnetId);
if (networkId != null) {
networkIdList.add(networkId);
} else {
session.getConsole().println("Could not find network for subnet " + subnetId.getValue() + ". Not proceeding with adding subnet to VPN");
}
}
if (!networkIdList.isEmpty()) {
Future<RpcResult<AssociateNetworksOutput>> result = neutronvpnService.associateNetworks(new AssociateNetworksInputBuilder().setVpnId(vuuid).setNetworkId(networkIdList).build());
RpcResult<AssociateNetworksOutput> associateNetworksRpcResult = result.get();
if (associateNetworksRpcResult.isSuccessful()) {
session.getConsole().println("Subnet(s) added to VPN successfully");
LOG.trace("associateNetworks: {}", result);
} else {
session.getConsole().println("Error while adding subnet(s) to VPN: " + result.get().getErrors());
session.getConsole().println(getHelp("create"));
}
}
}
}
}
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class ConfigureL3VpnCommand method deleteL3VpnCLI.
private void deleteL3VpnCLI() throws InterruptedException, ExecutionException {
if (vid == null) {
session.getConsole().println("Please supply a valid VPN ID");
session.getConsole().println(getHelp("delete"));
return;
}
Uuid vpnId = new Uuid(vid);
// disassociation of network(s) (removal of subnet(s)) from VPN to be followed by deletion of VPN
RpcResult<DissociateNetworksOutput> dissociateNetworksRpcResult = null;
List<Uuid> networkIdList = null;
networkIdList = neutronVpnManager.getNetworksForVpn(vpnId);
if (networkIdList != null && !networkIdList.isEmpty()) {
Future<RpcResult<DissociateNetworksOutput>> result = neutronvpnService.dissociateNetworks(new DissociateNetworksInputBuilder().setVpnId(vpnId).setNetworkId(networkIdList).build());
dissociateNetworksRpcResult = result.get();
if (dissociateNetworksRpcResult.isSuccessful()) {
session.getConsole().println("Subnet(s) removed from VPN successfully");
LOG.trace("dissociateNetworks: {}", result);
} else {
session.getConsole().println("Error while removing subnet(s) from VPN: " + result.get().getErrors());
session.getConsole().println(getHelp("delete"));
}
}
if (networkIdList == null || networkIdList.isEmpty() || dissociateNetworksRpcResult.isSuccessful()) {
List<Uuid> vpnIdList = new ArrayList<>();
vpnIdList.add(vpnId);
Future<RpcResult<DeleteL3VPNOutput>> result = neutronvpnService.deleteL3VPN(new DeleteL3VPNInputBuilder().setId(vpnIdList).build());
RpcResult<DeleteL3VPNOutput> rpcResult = result.get();
if (rpcResult.isSuccessful()) {
session.getConsole().println("L3VPN deleted successfully");
LOG.trace("deletel3vpn: {}", result);
} else {
session.getConsole().println("Error populating deleteL3VPN : " + result.get().getErrors());
session.getConsole().println(getHelp("delete"));
}
} else {
session.getConsole().println("Not proceeding with deletion of L3VPN since error(s) encountered " + "in removing subnet(s) from VPN");
}
}
use of org.opendaylight.yangtools.yang.common.RpcResult 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.yangtools.yang.common.RpcResult in project controller by opendaylight.
the class RoutedBindingRTClient method runTest.
public void runTest(final int iterations) {
int rpcOk = 0;
int rpcError = 0;
int rpcServerCnt = inVal.size();
for (int i = 0; i < iterations; i++) {
RoutedRpcBenchInput input = inVal.get(ThreadLocalRandom.current().nextInt(rpcServerCnt));
Future<RpcResult<RoutedRpcBenchOutput>> output = service.routedRpcBench(input);
try {
RpcResult<RoutedRpcBenchOutput> rpcResult = output.get();
if (rpcResult.isSuccessful()) {
List<Payload> retVal = rpcResult.getResult().getPayload();
if (retVal.size() == inSize) {
rpcOk++;
} else {
rpcError++;
}
}
} catch (InterruptedException | ExecutionException e) {
rpcError++;
LOG.error("Execution failed: ", e);
}
}
this.rpcOk.addAndGet(rpcOk);
this.rpcError.addAndGet(rpcError);
}
Aggregations