use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStatsBuilder 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.acl.stats.output.AclPortStatsBuilder in project netvirt by opendaylight.
the class AclLiveStatisticsHelper method addError.
/**
* Adds the error.
*
* @param lstAclPortStats the lst acl port stats
* @param aclStatsBuilder the acl stats builder
* @param errMsg the error message
*/
private static void addError(List<AclPortStats> lstAclPortStats, AclPortStatsBuilder aclStatsBuilder, String errMsg) {
aclStatsBuilder.setError(new ErrorBuilder().setErrorMessage(errMsg).build());
lstAclPortStats.add(aclStatsBuilder.build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.AclPortStatsBuilder in project netvirt by opendaylight.
the class AclLiveStatisticsHelper method getAclDropStats.
/**
* Gets the acl drop stats.
*
* @param direction the direction
* @param aclStatsBuilder the acl stats builder
* @param flowStatsOutput the flow stats output
*/
private static void getAclDropStats(Direction direction, AclPortStatsBuilder aclStatsBuilder, GetFlowStatisticsOutput flowStatsOutput) {
List<FlowAndStatisticsMapList> flowAndStatisticsMapList = flowStatsOutput.getFlowAndStatisticsMapList();
if (flowAndStatisticsMapList == null || flowAndStatisticsMapList.isEmpty()) {
String errMsg = "Unable to retrieve drop counts as interface is not configured for statistics collection.";
aclStatsBuilder.setError(new ErrorBuilder().setErrorMessage(errMsg).build());
return;
}
BytesBuilder portEgressBytesBuilder = new BytesBuilder();
BytesBuilder portIngressBytesBuilder = new BytesBuilder();
PacketsBuilder portEgressPacketsBuilder = new PacketsBuilder();
PacketsBuilder portIngressPacketsBuilder = new PacketsBuilder();
for (FlowAndStatisticsMapList flowStats : flowAndStatisticsMapList) {
BigInteger portEgressBytesBuilderDropCount = BigInteger.valueOf(0);
BigInteger portEgressPacketsBuilderDropCount = BigInteger.valueOf(0);
BigInteger portIngressBytesBuilderDropCount = BigInteger.valueOf(0);
BigInteger portIngressPacketsBuilderDropCount = BigInteger.valueOf(0);
switch(flowStats.getTableId()) {
case NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
portEgressBytesBuilder.setInvalidDropCount(flowStats.getByteCount().getValue());
portEgressPacketsBuilder.setInvalidDropCount(flowStats.getPacketCount().getValue());
} else if (flowStats.getPriority().equals(AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY)) {
if (portEgressBytesBuilder.getDropCount() != null) {
portEgressBytesBuilderDropCount = portEgressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
portEgressPacketsBuilderDropCount = portEgressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
} else {
portEgressBytesBuilderDropCount = flowStats.getByteCount().getValue();
portEgressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
}
} else if (flowStats.getPriority().equals(AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY)) {
if (portEgressBytesBuilder.getDropCount() != null) {
portEgressBytesBuilderDropCount = portEgressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
portEgressPacketsBuilderDropCount = portEgressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
} else {
portEgressBytesBuilderDropCount = flowStats.getByteCount().getValue();
portEgressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
}
}
// TODO: Update stats for other drops
break;
case NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
portIngressBytesBuilder.setInvalidDropCount(flowStats.getByteCount().getValue());
portIngressPacketsBuilder.setInvalidDropCount(flowStats.getPacketCount().getValue());
} else if (flowStats.getPriority().equals(AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY)) {
if (portIngressBytesBuilder.getDropCount() != null) {
portIngressBytesBuilderDropCount = portIngressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
portIngressPacketsBuilderDropCount = portIngressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
} else {
portIngressBytesBuilderDropCount = flowStats.getByteCount().getValue();
portIngressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
}
} else if (flowStats.getPriority().equals(AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY)) {
if (portIngressBytesBuilder.getDropCount() != null) {
portIngressBytesBuilderDropCount = portIngressBytesBuilder.getDropCount().add(flowStats.getByteCount().getValue());
portIngressPacketsBuilderDropCount = portIngressPacketsBuilder.getDropCount().add(flowStats.getPacketCount().getValue());
} else {
portIngressBytesBuilderDropCount = flowStats.getByteCount().getValue();
portIngressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
}
}
// TODO: Update stats for other drops
break;
default:
LOG.warn("Invalid table ID filtered for Acl flow stats: {}", flowStats);
break;
}
portEgressBytesBuilder.setDropCount(portEgressBytesBuilderDropCount);
portEgressPacketsBuilder.setDropCount(portEgressPacketsBuilderDropCount);
portIngressBytesBuilder.setDropCount(portIngressBytesBuilderDropCount);
portIngressPacketsBuilder.setDropCount(portIngressPacketsBuilderDropCount);
}
List<AclDropStats> lstAclDropStats = new ArrayList<>();
if (direction == Direction.Egress || direction == Direction.Both) {
AclDropStats aclEgressDropStats = new AclDropStatsBuilder().setDirection(Direction.Egress).setBytes(portEgressBytesBuilder.build()).setPackets(portEgressPacketsBuilder.build()).build();
lstAclDropStats.add(aclEgressDropStats);
}
if (direction == Direction.Ingress || direction == Direction.Both) {
AclDropStats aclIngressDropStats = new AclDropStatsBuilder().setDirection(Direction.Ingress).setBytes(portIngressBytesBuilder.build()).setPackets(portIngressPacketsBuilder.build()).build();
lstAclDropStats.add(aclIngressDropStats);
}
aclStatsBuilder.setAclDropStats(lstAclDropStats);
}
Aggregations