use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction in project netvirt by opendaylight.
the class StatisticsImpl method deleteCounterRequest.
private void deleteCounterRequest(CounterRequests counterRequest, ElementCountersDirection direction) {
WriteTransaction tx = db.newWriteOnlyTransaction();
if (ElementCountersDirection.INGRESS.equals(direction)) {
tx.delete(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(counterRequest.getKey().getRequestId())).build());
} else if (ElementCountersDirection.EGRESS.equals(direction)) {
tx.delete(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(counterRequest.getKey().getRequestId())).build());
}
tx.submit();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction 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.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction in project netvirt by opendaylight.
the class AclEventListener method updateAclCaches.
private void updateAclCaches(Acl aclBefore, Acl aclAfter, Collection<AclInterface> aclInterfaces, Class<? extends DirectionBase> direction) {
Uuid aclId = new Uuid(aclAfter.getAclName());
Set<Uuid> remoteAclsBefore = AclServiceUtils.getRemoteAclIdsByDirection(aclBefore, direction);
Set<Uuid> remoteAclsAfter = AclServiceUtils.getRemoteAclIdsByDirection(aclAfter, direction);
Set<Uuid> remoteAclsDeleted = new HashSet<>(remoteAclsBefore);
remoteAclsDeleted.removeAll(remoteAclsAfter);
for (Uuid remoteAcl : remoteAclsDeleted) {
aclDataUtil.removeRemoteAclId(remoteAcl, aclId, direction);
}
Set<Uuid> remoteAclsAdded = new HashSet<>(remoteAclsAfter);
remoteAclsAdded.removeAll(remoteAclsBefore);
for (Uuid remoteAcl : remoteAclsAdded) {
aclDataUtil.addRemoteAclId(remoteAcl, aclId, direction);
}
if (remoteAclsDeleted.isEmpty() && remoteAclsAdded.isEmpty()) {
return;
}
if (aclInterfaces != null) {
for (AclInterface aclInterface : aclInterfaces) {
AclInterface aclInterfaceInCache = aclInterfaceCache.addOrUpdate(aclInterface.getInterfaceId(), (prevAclInterface, builder) -> {
SortedSet<Integer> remoteAclTags = aclServiceUtils.getRemoteAclTags(aclInterface.getSecurityGroups(), direction);
if (DirectionEgress.class.equals(direction)) {
builder.egressRemoteAclTags(remoteAclTags);
} else {
builder.ingressRemoteAclTags(remoteAclTags);
}
});
aclDataUtil.addOrUpdateAclInterfaceMap(aclInterface.getSecurityGroups(), aclInterfaceInCache);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction 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.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.Direction in project netvirt by opendaylight.
the class AclLiveStatisticsRpcServiceImpl method getAclPortStatistics.
@Override
public Future<RpcResult<GetAclPortStatisticsOutput>> getAclPortStatistics(GetAclPortStatisticsInput input) {
LOG.trace("Get ACL port statistics for input: {}", input);
RpcResultBuilder<GetAclPortStatisticsOutput> rpcResultBuilder;
if (this.securityGroupMode != SecurityGroupMode.Stateful) {
rpcResultBuilder = RpcResultBuilder.failed();
rpcResultBuilder.withError(ErrorType.APPLICATION, "operation-not-supported", "Operation not supported for ACL " + this.securityGroupMode + " mode");
return Futures.immediateFuture(rpcResultBuilder.build());
}
// Default direction is Both
Direction direction = input.getDirection() == null ? Direction.Both : input.getDirection();
List<AclPortStats> lstAclInterfaceStats = AclLiveStatisticsHelper.getAclPortStats(direction, input.getInterfaceNames(), this.odlDirectStatsService, this.dataBroker);
GetAclPortStatisticsOutputBuilder output = new GetAclPortStatisticsOutputBuilder().setAclPortStats(lstAclInterfaceStats);
rpcResultBuilder = RpcResultBuilder.success();
rpcResultBuilder.withResult(output.build());
return Futures.immediateFuture(rpcResultBuilder.build());
}
Aggregations