import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.genius.mdsalutil.MetaDataUtil;
import org.opendaylight.genius.mdsalutil.NwConstants;
+import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.netvirt.aclservice.utils.AclConstants;
import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.GetFlowStatisticsOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.direct.statistics.rev160511.OpendaylightDirectStatisticsService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.acl.drop.stats.BytesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.acl.live.statistics.rev161129.acl.stats.output.acl.port.stats.acl.drop.stats.PacketsBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(AclLiveStatisticsHelper.class);
/** The Constant COOKIE_ACL_DROP_FLOW_MASK. */
- static final BigInteger COOKIE_ACL_DROP_FLOW_MASK = new BigInteger("FFFFFFF", 16);
+ static final BigInteger COOKIE_ACL_DROP_FLOW_MASK = new BigInteger("FFFFFFFFFFFFFFFF", 16);
private AclLiveStatisticsHelper() {
throw new IllegalStateException("Utility class");
* @param dataBroker the data broker
* @return the acl port stats
*/
- public static List<AclPortStats> getAclPortStats(Direction direction, List<String> interfaceNames,
+ public static List<AclPortStats> getAclPortStats(Direction direction, @NonNull 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) {
NodeRef nodeRef = buildNodeRef(dpId);
Integer lportTag = interfaceState.getIfIndex();
- Match metadataMatch = buildMetadataMatch(lportTag);
+ FlowCookie aclDropFlowCookie = new FlowCookie(AclServiceUtils.getDropFlowCookie(lportTag));
GetFlowStatisticsInputBuilder input =
new GetFlowStatisticsInputBuilder().setNode(nodeRef).setCookie(aclDropFlowCookie)
- .setCookieMask(aclDropFlowCookieMask).setMatch(metadataMatch).setStoreStats(false);
- if (direction != Direction.Both) {
- input.setTableId(tableId);
- }
+ .setCookieMask(aclDropFlowCookieMask).setStoreStats(false);
Future<RpcResult<GetFlowStatisticsOutput>> rpcResultFuture =
odlDirectStatsService.getFlowStatistics(input.build());
* @param rpcResult the rpc result
*/
private static void handleRpcErrors(List<AclPortStats> lstAclPortStats, AclPortStatsBuilder aclStatsBuilder,
- RpcResult<GetFlowStatisticsOutput> rpcResult) {
+ @Nullable RpcResult<GetFlowStatisticsOutput> rpcResult) {
LOG.error("Unable to retrieve drop counts due to error: {}", rpcResult);
String errMsg = "Unable to retrieve drop counts due to error: ";
- if (rpcResult != null && rpcResult.getErrors() != null) {
- for (RpcError error : rpcResult.getErrors()) {
- errMsg += error.getMessage();
- break;
- }
+ if (rpcResult != null && rpcResult.getErrors() != null && !rpcResult.getErrors().isEmpty()) {
+ errMsg += rpcResult.getErrors().iterator().next().getMessage();
} else {
errMsg += "Internal RPC call failed.";
}
*/
private static void getAclDropStats(Direction direction, AclPortStatsBuilder aclStatsBuilder,
GetFlowStatisticsOutput flowStatsOutput) {
- List<FlowAndStatisticsMapList> flowAndStatisticsMapList = flowStatsOutput.getFlowAndStatisticsMapList();
- if (flowAndStatisticsMapList == null || flowAndStatisticsMapList.isEmpty()) {
+ Map<FlowAndStatisticsMapListKey, FlowAndStatisticsMapList> keyFlowAndStatisticsMapListMap
+ = flowStatsOutput.getFlowAndStatisticsMapList();
+ if (keyFlowAndStatisticsMapListMap == null || keyFlowAndStatisticsMapListMap.isEmpty()) {
String errMsg = "Unable to retrieve drop counts as interface is not configured for statistics collection.";
aclStatsBuilder.setError(new ErrorBuilder().setErrorMessage(errMsg).build());
return;
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()) {
+ for (FlowAndStatisticsMapList flowStats : keyFlowAndStatisticsMapListMap.values()) {
+ switch (flowStats.getTableId().toJava()) {
case NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE:
- if (flowStats.getPriority().equals(AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY)) {
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority().toJava())) {
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)) {
+ } else if (AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY.equals(flowStats.getPriority().toJava())
+ || AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY.equals(flowStats.getPriority().toJava())) {
+ BigInteger portEgressBytesBuilderDropCount = BigInteger.valueOf(0);
+ BigInteger portEgressPacketsBuilderDropCount = BigInteger.valueOf(0);
if (portEgressBytesBuilder.getDropCount() != null) {
- portEgressBytesBuilderDropCount = portEgressBytesBuilder.getDropCount()
- .add(flowStats.getByteCount().getValue());
- portEgressPacketsBuilderDropCount = portEgressPacketsBuilder.getDropCount()
- .add(flowStats.getPacketCount().getValue());
+ portEgressBytesBuilderDropCount = portEgressBytesBuilder.getDropCount().toJava()
+ .add(flowStats.getByteCount().getValue().toJava());
+ portEgressPacketsBuilderDropCount = portEgressPacketsBuilder.getDropCount().toJava()
+ .add(flowStats.getPacketCount().getValue().toJava());
} else {
- portEgressBytesBuilderDropCount = flowStats.getByteCount().getValue();
- portEgressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
+ portEgressBytesBuilderDropCount = flowStats.getByteCount().getValue().toJava();
+ portEgressPacketsBuilderDropCount = flowStats.getPacketCount().getValue().toJava();
}
+ portEgressBytesBuilder.setDropCount(portEgressBytesBuilderDropCount);
+ portEgressPacketsBuilder.setDropCount(portEgressPacketsBuilderDropCount);
}
// 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)) {
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority().toJava())) {
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)) {
+ } else if (AclConstants.ACL_PORT_SPECIFIC_DROP_PRIORITY.equals(flowStats.getPriority().toJava())
+ || AclConstants.ACE_LAST_REMOTE_ACL_PRIORITY.equals(flowStats.getPriority().toJava())) {
+ BigInteger portIngressBytesBuilderDropCount = BigInteger.valueOf(0);
+ BigInteger portIngressPacketsBuilderDropCount = BigInteger.valueOf(0);
if (portIngressBytesBuilder.getDropCount() != null) {
- portIngressBytesBuilderDropCount = portIngressBytesBuilder.getDropCount()
- .add(flowStats.getByteCount().getValue());
- portIngressPacketsBuilderDropCount = portIngressPacketsBuilder.getDropCount()
- .add(flowStats.getPacketCount().getValue());
+ portIngressBytesBuilderDropCount = portIngressBytesBuilder.getDropCount().toJava()
+ .add(flowStats.getByteCount().getValue().toJava());
+ portIngressPacketsBuilderDropCount = portIngressPacketsBuilder.getDropCount().toJava()
+ .add(flowStats.getPacketCount().getValue().toJava());
} else {
- portIngressBytesBuilderDropCount = flowStats.getByteCount().getValue();
- portIngressPacketsBuilderDropCount = flowStats.getPacketCount().getValue();
+ portIngressBytesBuilderDropCount = flowStats.getByteCount().getValue().toJava();
+ portIngressPacketsBuilderDropCount = flowStats.getPacketCount().getValue().toJava();
}
+ portIngressBytesBuilder.setDropCount(portIngressBytesBuilderDropCount);
+ portIngressPacketsBuilder.setDropCount(portIngressPacketsBuilderDropCount);
}
// TODO: Update stats for other drops
break;
+ case NwConstants.INGRESS_ACL_COMMITTER_TABLE:
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority().toJava())) {
+ portEgressBytesBuilder.setAntiSpoofDropCount(flowStats.getByteCount().getValue());
+ portEgressPacketsBuilder.setAntiSpoofDropCount(flowStats.getPacketCount().getValue());
+ }
+ break;
+ case NwConstants.EGRESS_ACL_COMMITTER_TABLE:
+ if (AclConstants.CT_STATE_TRACKED_INVALID_PRIORITY.equals(flowStats.getPriority().toJava())) {
+ portIngressBytesBuilder.setAntiSpoofDropCount(flowStats.getByteCount().getValue());
+ portIngressPacketsBuilder.setAntiSpoofDropCount(flowStats.getPacketCount().getValue());
+ }
+ 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) {
+ updateTotalDropCount(portEgressBytesBuilder,portEgressPacketsBuilder);
AclDropStats aclEgressDropStats = new AclDropStatsBuilder().setDirection(Direction.Egress)
.setBytes(portEgressBytesBuilder.build()).setPackets(portEgressPacketsBuilder.build()).build();
lstAclDropStats.add(aclEgressDropStats);
}
if (direction == Direction.Ingress || direction == Direction.Both) {
+ updateTotalDropCount(portIngressBytesBuilder,portIngressPacketsBuilder);
AclDropStats aclIngressDropStats = new AclDropStatsBuilder().setDirection(Direction.Ingress)
.setBytes(portIngressBytesBuilder.build()).setPackets(portIngressPacketsBuilder.build()).build();
lstAclDropStats.add(aclIngressDropStats);
aclStatsBuilder.setAclDropStats(lstAclDropStats);
}
+ private static void updateTotalDropCount(BytesBuilder portBytesBuilder, PacketsBuilder portPacketsBuilder) {
+ BigInteger dropCountByt = BigInteger.ZERO;
+ BigInteger invalidDropCountByt = BigInteger.ZERO;
+ BigInteger antispoofDropCountByt = BigInteger.ZERO;
+ BigInteger dropCountPkt = BigInteger.ZERO;
+ BigInteger invalidDropCountPkt = BigInteger.ZERO;
+ BigInteger antispoofDropCountPkt = BigInteger.ZERO;
+
+ if (portBytesBuilder.getDropCount() != null) {
+ dropCountByt = portBytesBuilder.getDropCount().toJava();
+ }
+ if (portPacketsBuilder.getDropCount() != null) {
+ dropCountPkt = portPacketsBuilder.getDropCount().toJava();
+ }
+ if (portBytesBuilder.getDropCount() != null) {
+ invalidDropCountByt = portBytesBuilder.getInvalidDropCount().toJava();
+ }
+ if (portPacketsBuilder.getDropCount() != null) {
+ invalidDropCountPkt = portPacketsBuilder.getInvalidDropCount().toJava();
+ }
+ if (portBytesBuilder.getDropCount() != null) {
+ antispoofDropCountByt = portBytesBuilder.getAntiSpoofDropCount().toJava();
+ }
+ if (portPacketsBuilder.getDropCount() != null) {
+ antispoofDropCountPkt = portPacketsBuilder.getAntiSpoofDropCount().toJava();
+ }
+ portBytesBuilder.setTotalDropCount(antispoofDropCountByt.add(dropCountByt.add(invalidDropCountByt)));
+ portPacketsBuilder.setTotalDropCount(antispoofDropCountPkt.add(dropCountPkt.add(invalidDropCountPkt)));
+
+ }
+
/**
* Adds the error.
*
return new MatchBuilder().setMetadata(metadata).build();
}
- /**
- * Gets the table id.
- *
- * @param direction the direction
- * @return the table id
- */
- private static Short getTableId(Direction direction) {
- Short tableId;
- if (direction == Direction.Egress) {
- tableId = NwConstants.INGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE;
- } else {
- // in case of ingress
- tableId = NwConstants.EGRESS_ACL_FILTER_CUM_DISPATCHER_TABLE;
- }
- return tableId;
- }
-
/**
* Builds the node ref.
*