use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class AclServiceUtils method releaseId.
public static void releaseId(IdManagerService idManager, String poolName, String idKey) {
ReleaseIdInput idInput = new ReleaseIdInputBuilder().setPoolName(poolName).setIdKey(idKey).build();
try {
Future<RpcResult<Void>> result = idManager.releaseId(idInput);
RpcResult<Void> rpcResult = result.get();
if (!rpcResult.isSuccessful()) {
LOG.error("RPC Call to release Id with Key {} from pool {} returned with Errors {}", idKey, poolName, rpcResult.getErrors());
} else {
LOG.debug("Released ACL ID with key: {} from pool: {}", idKey, poolName);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Exception when releasing Id for key {} from pool {} ", idKey, poolName, e);
}
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class AclServiceUtils method getDpnForInterface.
/**
* Get the data path number for the interface.
* @param interfaceManagerRpcService interfaceManagerRpcService instance.
* @param ifName the interface name.
* @return the dpn.
*/
public static BigInteger getDpnForInterface(OdlInterfaceRpcService interfaceManagerRpcService, String ifName) {
BigInteger nodeId = BigInteger.ZERO;
try {
GetDpidFromInterfaceInput dpIdInput = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build();
Future<RpcResult<GetDpidFromInterfaceOutput>> dpIdOutput = interfaceManagerRpcService.getDpidFromInterface(dpIdInput);
RpcResult<GetDpidFromInterfaceOutput> dpIdResult = dpIdOutput.get();
if (dpIdResult.isSuccessful()) {
nodeId = dpIdResult.getResult().getDpid();
} else {
LOG.error("Could not retrieve DPN Id for interface {}", ifName);
}
} catch (NullPointerException | InterruptedException | ExecutionException e) {
LOG.error("Exception when getting dpn for interface {}", ifName, e);
}
return nodeId;
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class AclLiveStatisticsRpcServiceTest method getStatsTwoPortBothDirection.
/**
* Test stats for two ports and both direction. <br>
* port1 is valid <br>
* port2 is invalid <br>
* Expectation: Error expected for port2
*
* @throws Exception the exception
*/
@Test
public void getStatsTwoPortBothDirection() throws Exception {
List<String> lstInterfaces = Arrays.asList(PORT_1, PORT_2);
Direction direction = Direction.Both;
GetAclPortStatisticsInput input = new GetAclPortStatisticsInputBuilder().setDirection(direction).setInterfaceNames(lstInterfaces).build();
Future<RpcResult<GetAclPortStatisticsOutput>> rpcResultFuture = aclStatsService.getAclPortStatistics(input);
RpcResult<GetAclPortStatisticsOutput> output = rpcResultFuture.get();
LOG.info("getStatsTwoPortBothDirection output = {}", output);
assertStatsOutput(output, direction);
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class AclLiveStatisticsHelper method getAclPortStats.
/**
* Gets the acl port stats.
*
* @param direction the direction
* @param interfaceNames the interface names
* @param odlDirectStatsService the odl direct stats service
* @param dataBroker the data broker
* @return the acl port stats
*/
public static List<AclPortStats> getAclPortStats(Direction direction, List<String> interfaceNames, OpendaylightDirectStatisticsService odlDirectStatsService, DataBroker dataBroker) {
LOG.trace("Get ACL port stats for direction {} and interfaces {}", direction, interfaceNames);
List<AclPortStats> lstAclPortStats = new ArrayList<>();
Short tableId = getTableId(direction);
FlowCookie aclDropFlowCookie = new FlowCookie(AclConstants.COOKIE_ACL_DROP_FLOW);
FlowCookie aclDropFlowCookieMask = new FlowCookie(COOKIE_ACL_DROP_FLOW_MASK);
for (String interfaceName : interfaceNames) {
AclPortStatsBuilder aclStatsBuilder = new AclPortStatsBuilder().setInterfaceName(interfaceName);
Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceName);
if (interfaceState == null) {
String errMsg = "Interface not found in datastore.";
addError(lstAclPortStats, aclStatsBuilder, errMsg);
continue;
}
BigInteger dpId = AclServiceUtils.getDpIdFromIterfaceState(interfaceState);
if (dpId == null) {
String errMsg = "Failed to find device for the interface.";
addError(lstAclPortStats, aclStatsBuilder, errMsg);
continue;
}
NodeRef nodeRef = buildNodeRef(dpId);
Integer lportTag = interfaceState.getIfIndex();
Match metadataMatch = buildMetadataMatch(lportTag);
GetFlowStatisticsInputBuilder input = new GetFlowStatisticsInputBuilder().setNode(nodeRef).setCookie(aclDropFlowCookie).setCookieMask(aclDropFlowCookieMask).setMatch(metadataMatch).setStoreStats(false);
if (direction != Direction.Both) {
input.setTableId(tableId);
}
Future<RpcResult<GetFlowStatisticsOutput>> rpcResultFuture = odlDirectStatsService.getFlowStatistics(input.build());
RpcResult<GetFlowStatisticsOutput> rpcResult = null;
try {
rpcResult = rpcResultFuture.get();
} catch (InterruptedException | ExecutionException e) {
String errMsg = "Unable to retrieve drop counts due to error: " + e.getMessage();
addError(lstAclPortStats, aclStatsBuilder, errMsg);
LOG.error("Exception occurred during get flow statistics for interface {}", interfaceName, e);
}
if (rpcResult != null && rpcResult.isSuccessful() && rpcResult.getResult() != null) {
GetFlowStatisticsOutput flowStatsOutput = rpcResult.getResult();
getAclDropStats(direction, aclStatsBuilder, flowStatsOutput);
lstAclPortStats.add(aclStatsBuilder.build());
} else {
handleRpcErrors(lstAclPortStats, aclStatsBuilder, rpcResult);
}
}
return lstAclPortStats;
}
use of org.opendaylight.yangtools.yang.common.RpcResult in project netvirt by opendaylight.
the class EvpnSnatFlowProgrammer method evpnDelFibTsAndReverseTraffic.
public void evpnDelFibTsAndReverseTraffic(final BigInteger dpnId, final long routerId, final String externalIp, final String vpnName, String extGwMacAddress, WriteTransaction removeFlowInvTx) {
/*
* 1) Remove the flow INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44)
* (FIP VM on DPN1 is responding back to external fixed IP on DPN2) {DNAT to SNAT traffic on
* different Hypervisor}
*
* 2) Remove the flow L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44)
* (FIP VM on DPN1 is responding back to external fixed IP on DPN1 itself){DNAT to SNAT traffic on
* Same Hypervisor}
*
* 3) Remove the flow PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44)
* (If there is no FIP Match on table 25 (PDNAT_TABLE) then default flow to INBOUND_NAPT_TABLE (table=44))
*
* 4) Remove the flow L3_FIB_TABLE (table=21)-> INBOUND_NAPT_TABLE (table=44)
* (FIP VM on DPN1 is responding back to external fixed Ip on DPN1 itself. ie. same Hypervisor)
* {DNAT to SNAT Intra DC traffic}
*/
String rd = NatUtil.getVpnRd(dataBroker, vpnName);
if (rd == null) {
LOG.error("evpnDelFibTsAndReverseTraffic : Could not retrieve RD value from VPN Name {}", vpnName);
return;
}
long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("evpnDelFibTsAndReverseTraffic : Invalid Vpn Id is found for Vpn Name {}", vpnName);
return;
}
if (extGwMacAddress == null) {
LOG.error("evpnDelFibTsAndReverseTraffic : Unable to Get External Gateway MAC address for " + "External Router ID {} ", routerId);
return;
}
long l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("evpnDelFibTsAndReverseTraffic : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue with installing " + "SNAT flows for External Fixed IP {}", vpnName, rd, externalIp);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
final String externalFixedIp = NatUtil.validateAndAddNetworkMask(externalIp);
RemoveFibEntryInput input = new RemoveFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(externalFixedIp).setIpAddressSource(RemoveFibEntryInput.IpAddressSource.ExternalFixedIP).setServiceId(l3Vni).build();
LOG.debug("evpnDelFibTsAndReverseTraffic : Removing custom FIB table {} --> table {} flow on " + "NAPT Switch {} with l3Vni {}, ExternalFixedIp {}, ExternalVpnName {} for RouterId {}", NwConstants.L3_FIB_TABLE, NwConstants.INBOUND_NAPT_TABLE, dpnId, l3Vni, externalIp, vpnName, routerId);
Future<RpcResult<Void>> future = fibService.removeFibEntry(input);
ListenableFuture<RpcResult<Void>> futureVxlan = JdkFutureAdapters.listenInPoolThread(future);
final long finalL3Vni = l3Vni;
Futures.addCallback(futureVxlan, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("evpnDelFibTsAndReverseTraffic : Error in custom fib routes remove process for " + "External Fixed IP {} on DPN {} with l3Vni {}, ExternalVpnName {} for RouterId {}", externalIp, dpnId, finalL3Vni, vpnName, routerId, error);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("evpnDelFibTsAndReverseTraffic : Successfully removed custom FIB routes for " + "External Fixed IP {} on DPN {} with l3Vni {}, ExternalVpnName {} for " + "RouterId {}", externalIp, dpnId, finalL3Vni, vpnName, routerId);
// remove INTERNAL_TUNNEL_TABLE (table=36)-> INBOUND_NAPT_TABLE (table=44) flow
removeTunnelTableEntry(dpnId, finalL3Vni, removeFlowInvTx);
// remove L3_GW_MAC_TABLE (table=19)-> INBOUND_NAPT_TABLE (table=44) flow
NatUtil.removePreDnatToSnatTableEntry(mdsalManager, dpnId, removeFlowInvTx);
// remove PDNAT_TABLE (table=25)-> INBOUND_NAPT_TABLE (table=44) flow
NatEvpnUtil.removeL3GwMacTableEntry(dpnId, vpnId, extGwMacAddress, mdsalManager, removeFlowInvTx);
}
}
}, MoreExecutors.directExecutor());
}
Aggregations