Search in sources :

Example 46 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method transmitArpOrNsPacket.

private void transmitArpOrNsPacket(Uint64 dpnId, String sourceIpAddress, String sourceMac, byte[] dstIpBytes, String dstIpAddress, long elanTag) throws UnknownHostException {
    long groupid = VpnUtil.getRemoteBCGroup(elanTag);
    if (NWUtil.isIpv4Address(dstIpAddress)) {
        LOG.debug("Sending ARP: srcIp={}, srcMac={}, dstIp={}, dpId={}, elan-tag={}, groupid={}", sourceIpAddress, sourceMac, dstIpAddress, dpnId, elanTag, groupid);
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_arp_sent.toString()).label(sourceIpAddress + "." + dstIpAddress);
        counter.increment();
        TransmitPacketInput packetInput = ArpUtils.createArpRequestInput(dpnId, groupid, HexEncode.bytesFromHexString(sourceMac), InetAddress.getByName(sourceIpAddress).getAddress(), dstIpBytes);
        LoggingFutures.addErrorLogging(packetService.transmitPacket(packetInput), LOG, "Transmit packet");
    } else {
        // IPv6 case
        LOG.debug("Sending NS: srcIp={}, srcMac={}, dstIp={}, dpId={}, elan-tag={}, groupid={}", sourceIpAddress, sourceMac, dstIpAddress, dpnId, elanTag, groupid);
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_ns_sent.toString()).label(sourceIpAddress + "." + dstIpAddress);
        counter.increment();
        VpnUtil.sendNeighborSolicationToOfGroup(this.ipv6NdUtilService, new Ipv6Address(sourceIpAddress), new MacAddress(sourceMac), new Ipv6Address(dstIpAddress), groupid, dpnId);
    }
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)

Example 47 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method handlePacketToInternalNetwork.

private void handlePacketToInternalNetwork(byte[] dstIp, String dstIpStr, long elanTag, String srcIpStr) throws UnknownHostException {
    try {
        SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(elanTag, dstIpStr);
        if (targetSubnetForPacketOut == null) {
            LOG.debug("Couldn't find matching subnet for elan tag {} and destination ip {}", elanTag, dstIpStr);
            Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(srcIpStr + "." + dstIpStr);
            counter.increment();
            return;
        }
        Optional<Subnetmap> subnetMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildSubnetmapIdentifier(targetSubnetForPacketOut.getSubnetId()));
        if (!subnetMap.isPresent()) {
            LOG.debug("Couldn't find subnet map for subnet {}", targetSubnetForPacketOut.getSubnetId());
            Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(srcIpStr + "." + dstIpStr);
            counter.increment();
            return;
        }
        String sourceIp = subnetMap.get().getRouterInterfaceFixedIp();
        if (sourceIp == null) {
            LOG.debug("Subnet map {} doesn't have a router interface ip defined", subnetMap.get().getId());
            Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label("." + dstIpStr);
            counter.increment();
            return;
        }
        String sourceMac = subnetMap.get().getRouterIntfMacAddress();
        if (sourceMac == null) {
            LOG.debug("Subnet map {} doesn't have a router interface mac address defined", subnetMap.get().getId());
            Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(sourceIp + "." + dstIpStr);
            counter.increment();
            return;
        }
        transmitArpOrNsPacket(targetSubnetForPacketOut.getNhDpnId(), sourceIp, sourceMac, dstIp, dstIpStr, elanTag);
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("handlePacketToInternalNetwork: Failed to read data store for destIp {} elanTag {}", dstIpStr, elanTag);
    }
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) ExecutionException(java.util.concurrent.ExecutionException)

Example 48 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method acquireElementCountersRequestHandler.

@Override
public ListenableFuture<RpcResult<AcquireElementCountersRequestHandlerOutput>> acquireElementCountersRequestHandler(AcquireElementCountersRequestHandlerInput input) {
    AcquireElementCountersRequestHandlerOutputBuilder aecrhob = new AcquireElementCountersRequestHandlerOutputBuilder();
    UUID randomNumber = UUID.randomUUID();
    Integer intRequestKey = allocateId(randomNumber.toString());
    if (intRequestKey == null) {
        LOG.warn("failed generating unique request identifier");
        statisticsCounters.failedGeneratingUniqueRequestId();
        return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed generating unique request identifier").buildFuture();
    }
    String requestKey = String.valueOf(intRequestKey);
    SettableFuture<RpcResult<AcquireElementCountersRequestHandlerOutput>> result = SettableFuture.create();
    LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(transaction -> {
        if (input.getIncomingTraffic() != null) {
            Optional<EgressElementCountersRequestConfig> eecrcOpt = transaction.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER).get();
            if (!eecrcOpt.isPresent()) {
                LOG.warn("failed creating incoming traffic counter request data container in DB");
                statisticsCounters.failedCreatingEgressCounterDataConfig();
                result.setFuture(RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed creating egress counter request data container in DB").buildFuture());
                return;
            }
            if (!isIdenticalCounterRequestExist(input.getPortId(), ElementCountersDirection.EGRESS.toString(), input.getIncomingTraffic().getFilters(), eecrcOpt.get().getCounterRequests())) {
                installCounterSpecificRules(input.getPortId(), getLportTag(input.getPortId()), getDpn(input.getPortId()), ElementCountersDirection.EGRESS, input.getIncomingTraffic().getFilters());
            }
            putEgressElementCounterRequestInConfig(input, ElementCountersDirection.EGRESS, transaction, requestKey, CountersServiceUtils.EECRC_IDENTIFIER, eecrcOpt, randomNumber.toString());
            aecrhob.setIncomingTrafficHandler(requestKey);
            bindCountersServiceIfUnbound(input.getPortId(), ElementCountersDirection.EGRESS);
        }
        if (input.getOutgoingTraffic() != null) {
            Optional<IngressElementCountersRequestConfig> iecrcOpt = transaction.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER).get();
            if (!iecrcOpt.isPresent()) {
                LOG.warn("failed creating outgoing traffc counter request data container in DB");
                statisticsCounters.failedCreatingIngressCounterDataConfig();
                result.setFuture(RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed creating ingress counter request data container in DB").buildFuture());
                return;
            }
            if (!isIdenticalCounterRequestExist(input.getPortId(), ElementCountersDirection.INGRESS.toString(), input.getOutgoingTraffic().getFilters(), iecrcOpt.get().getCounterRequests())) {
                installCounterSpecificRules(input.getPortId(), getLportTag(input.getPortId()), getDpn(input.getPortId()), ElementCountersDirection.INGRESS, input.getOutgoingTraffic().getFilters());
            }
            putIngressElementCounterRequestInConfig(input, ElementCountersDirection.INGRESS, transaction, requestKey, CountersServiceUtils.IECRC_IDENTIFIER, iecrcOpt, randomNumber.toString());
            aecrhob.setIncomingTrafficHandler(requestKey);
            bindCountersServiceIfUnbound(input.getPortId(), ElementCountersDirection.INGRESS);
            result.setFuture(RpcResultBuilder.success(aecrhob.build()).buildFuture());
        }
    }), LOG, "Error acquiring element counters");
    return result;
}
Also used : AcquireElementCountersRequestHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutputBuilder) BigInteger(java.math.BigInteger) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) GetNodeConnectorCountersInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersInput) CounterResultBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResultBuilder) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) AcquireElementCountersRequestHandlerInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerInput) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match) Future(java.util.concurrent.Future) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) GetElementCountersByHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutput) Map(java.util.Map) BigInteger(java.math.BigInteger) CreateIdPoolInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInput) GetElementCountersByHandlerInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerInput) ReleaseIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInput) ReleaseElementCountersRequestHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerOutput) ReadWriteTransaction(org.opendaylight.mdsal.binding.api.ReadWriteTransaction) Set(java.util.Set) ErrorType(org.opendaylight.yangtools.yang.common.RpcError.ErrorType) CleanAllElementCounterRequestsOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.CleanAllElementCounterRequestsOutput) GetNodeCountersInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeCountersInput) NonNull(org.eclipse.jdt.annotation.NonNull) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput) StatisticsService(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.StatisticsService) ManagedNewTransactionRunner(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) ArrayList(java.util.ArrayList) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) GetNodeAggregatedCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeAggregatedCountersOutputBuilder) IdPool(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool) WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) TcpFilter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.elementrequestdata.filters.TcpFilter) EgressElementCountersRequestConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfigBuilder) ReleaseIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdOutput) FutureCallback(com.google.common.util.concurrent.FutureCallback) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) GetNodeAggregatedCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeAggregatedCountersOutput) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) UdpFilter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.elementrequestdata.filters.UdpFilter) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) ICountersInterfaceChangeHandler(org.opendaylight.netvirt.statistics.api.ICountersInterfaceChangeHandler) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests) Groups(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.Groups) CreateIdPoolOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolOutput) LoggerFactory(org.slf4j.LoggerFactory) SettableFuture(com.google.common.util.concurrent.SettableFuture) CleanAllElementCounterRequestsInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.CleanAllElementCounterRequestsInput) GetNodeCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeCountersOutputBuilder) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) IdPoolKey(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) CountersBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.CountersBuilder) GetNodeCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeCountersOutput) CounterRequestsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsBuilder) UUID(java.util.UUID) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) GetNodeConnectorCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersOutputBuilder) List(java.util.List) ManagedNewTransactionRunnerImpl(org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl) GroupsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.GroupsBuilder) Entry(java.util.Map.Entry) GetNodeAggregatedCountersInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeAggregatedCountersInput) Optional(java.util.Optional) AcquireElementCountersRequestHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutput) Filters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.elementrequestdata.Filters) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AcquireElementCountersRequestHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) GetNodeConnectorCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeConnectorCountersOutput) HashMap(java.util.HashMap) IngressElementCountersRequestConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfigBuilder) ReleaseElementCountersRequestHandlerInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerInput) HashSet(java.util.HashSet) CreateIdPoolInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.CreateIdPoolInputBuilder) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Logger(org.slf4j.Logger) GetElementCountersByHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutputBuilder) ReleaseIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.ReleaseIdInputBuilder) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) IdPools(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools) RpcResultBuilder(org.opendaylight.yangtools.yang.common.RpcResultBuilder) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) Counters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.counterresult.groups.Counters) Optional(java.util.Optional) AcquireElementCountersRequestHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) UUID(java.util.UUID)

Example 49 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method getNodeAggregatedCounters.

@Override
@SuppressWarnings("checkstyle:illegalCatch")
public ListenableFuture<RpcResult<GetNodeAggregatedCountersOutput>> getNodeAggregatedCounters(GetNodeAggregatedCountersInput input) {
    BigInteger dpId = input.getNodeId();
    LOG.trace("getting aggregated node counters for node {}", dpId);
    GetNodeAggregatedCountersOutputBuilder gnacob = new GetNodeAggregatedCountersOutputBuilder();
    List<CounterResult> aggregatedCounterResults = new ArrayList<>();
    try {
        if (!getNodeAggregatedResult(aggregatedCounterResults, dpId)) {
            statisticsCounters.failedGettingAggregatedNodeCounters();
            return RpcResultBuilder.<GetNodeAggregatedCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get node aggregated counters for node " + dpId).buildFuture();
        }
    } catch (Exception e) {
        LOG.warn("failed to get counter result for node {}", dpId, e);
        return RpcResultBuilder.<GetNodeAggregatedCountersOutput>failed().withError(ErrorType.APPLICATION, "failed to get node aggregated counters for node " + dpId).buildFuture();
    }
    gnacob.setCounterResult(aggregatedCounterResults);
    return RpcResultBuilder.success(gnacob.build()).buildFuture();
}
Also used : ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) GetNodeAggregatedCountersOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeAggregatedCountersOutputBuilder) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) ExecutionException(java.util.concurrent.ExecutionException) GetNodeAggregatedCountersOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetNodeAggregatedCountersOutput)

Example 50 with Counter

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter in project netvirt by opendaylight.

the class StatisticsImpl method getElementCountersByHandler.

@Override
public ListenableFuture<RpcResult<GetElementCountersByHandlerOutput>> getElementCountersByHandler(GetElementCountersByHandlerInput input) {
    InstanceIdentifier<CounterRequests> ingressPath = InstanceIdentifier.builder(IngressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
    InstanceIdentifier<CounterRequests> egressPath = InstanceIdentifier.builder(EgressElementCountersRequestConfig.class).child(CounterRequests.class, new CounterRequestsKey(input.getHandler())).build();
    ReadTransaction tx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> ingressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, ingressPath);
    CheckedFuture<Optional<CounterRequests>, ReadFailedException> egressRequestData = tx.read(LogicalDatastoreType.CONFIGURATION, egressPath);
    List<CounterResult> counters = new ArrayList<>();
    try {
        if (!ingressRequestData.get().isPresent() && !egressRequestData.get().isPresent()) {
            LOG.warn("Handler does not exists");
            return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Handler does not exists").buildFuture();
        }
        if (ingressRequestData.get().isPresent()) {
            CounterRequests ingressCounterRequest = ingressRequestData.get().get();
            CounterResultDataStructure ingressCounterResultDS = createElementCountersResult(ingressCounterRequest);
            if (ingressCounterResultDS == null) {
                LOG.warn("Unable to get counter results");
                statisticsCounters.failedGettingCounterResults();
                return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Unable to get counter results").buildFuture();
            }
            createCounterResults(counters, ingressCounterResultDS, CountersServiceUtils.INGRESS_COUNTER_RESULT_ID);
        }
        if (egressRequestData.get().isPresent()) {
            CounterRequests egressCounterRequest = egressRequestData.get().get();
            CounterResultDataStructure egressCounterResultDS = createElementCountersResult(egressCounterRequest);
            if (egressCounterResultDS == null) {
                LOG.warn("Unable to get counter results");
                statisticsCounters.failedGettingCounterResults();
                return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "Unable to get counter results").buildFuture();
            }
            createCounterResults(counters, egressCounterResultDS, CountersServiceUtils.EGRESS_COUNTER_RESULT_ID);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<GetElementCountersByHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    } finally {
        tx.close();
    }
    GetElementCountersByHandlerOutputBuilder gecbhob = new GetElementCountersByHandlerOutputBuilder();
    gecbhob.setCounterResult(counters);
    return RpcResultBuilder.success(gecbhob.build()).buildFuture();
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) GetElementCountersByHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutput) GetElementCountersByHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.GetElementCountersByHandlerOutputBuilder) Optional(java.util.Optional) CounterRequestsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey) ArrayList(java.util.ArrayList) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests) CounterResult(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult) ReadTransaction(org.opendaylight.mdsal.binding.api.ReadTransaction) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Test (org.junit.Test)19 ExecutionException (java.util.concurrent.ExecutionException)13 Counter (org.opendaylight.infrautils.metrics.Counter)12 ArrayList (java.util.ArrayList)11 BigInteger (java.math.BigInteger)9 MapRegister (org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.MapRegister)9 List (java.util.List)7 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Optional (java.util.Optional)5 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)5 CounterResult (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.result.CounterResult)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Future (java.util.concurrent.Future)4 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)4 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)4 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)4 Optional (com.google.common.base.Optional)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)3