Search in sources :

Example 6 with IngressElementCountersRequestConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig in project netvirt by opendaylight.

the class StatisticsImpl method acquireElementCountersRequestHandler.

@Override
public Future<RpcResult<AcquireElementCountersRequestHandlerOutput>> acquireElementCountersRequestHandler(AcquireElementCountersRequestHandlerInput input) {
    AcquireElementCountersRequestHandlerOutputBuilder aecrhob = new AcquireElementCountersRequestHandlerOutputBuilder();
    ReadWriteTransaction transaction = db.newReadWriteTransaction();
    UUID randomNumber = UUID.randomUUID();
    Integer intRequestKey = allocateId(randomNumber.toString());
    if (intRequestKey == null) {
        LOG.warn("failed generating unique request identifier");
        StatisticsPluginImplCounters.failed_generating_unique_request_id.inc();
        return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed generating unique request identifier").buildFuture();
    }
    String requestKey = String.valueOf(intRequestKey);
    try {
        if (input.getIncomingTraffic() != null) {
            CheckedFuture<Optional<EgressElementCountersRequestConfig>, ReadFailedException> eecrc = transaction.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.EECRC_IDENTIFIER);
            Optional<EgressElementCountersRequestConfig> eecrcOpt = eecrc.get();
            if (!eecrcOpt.isPresent()) {
                LOG.warn("failed creating incoming traffic counter request data container in DB");
                StatisticsPluginImplCounters.failed_creating_egress_counter_data_config.inc();
                return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed creating egress counter request data container in DB").buildFuture();
            }
            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());
            transaction.submit();
            aecrhob.setIncomingTrafficHandler(requestKey);
            bindCountersServiceIfUnbound(input.getPortId(), ElementCountersDirection.EGRESS);
        }
        if (input.getOutgoingTraffic() != null) {
            transaction = db.newReadWriteTransaction();
            CheckedFuture<Optional<IngressElementCountersRequestConfig>, ReadFailedException> iecrc = transaction.read(LogicalDatastoreType.CONFIGURATION, CountersServiceUtils.IECRC_IDENTIFIER);
            Optional<IngressElementCountersRequestConfig> iecrcOpt = iecrc.get();
            if (!iecrcOpt.isPresent()) {
                LOG.warn("failed creating outgoing traffc counter request data container in DB");
                StatisticsPluginImplCounters.failed_creating_ingress_counter_data_config.inc();
                return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed creating ingress counter request data container in DB").buildFuture();
            }
            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());
            transaction.submit();
            aecrhob.setIncomingTrafficHandler(requestKey);
            bindCountersServiceIfUnbound(input.getPortId(), ElementCountersDirection.INGRESS);
        }
    } catch (InterruptedException | ExecutionException e) {
        LOG.warn("failed to get counter request data from DB");
        return RpcResultBuilder.<AcquireElementCountersRequestHandlerOutput>failed().withError(ErrorType.APPLICATION, "failed to get counter request data from DB").buildFuture();
    }
    return RpcResultBuilder.success(aecrhob.build()).buildFuture();
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) EgressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig) Optional(com.google.common.base.Optional) IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) AcquireElementCountersRequestHandlerOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutputBuilder) BigInteger(java.math.BigInteger) AcquireElementCountersRequestHandlerOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutput) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction) UUID(java.util.UUID) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with IngressElementCountersRequestConfig

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig in project netvirt by opendaylight.

the class StatisticsImpl method creatIngressEelementCountersContainerInConfig.

private void creatIngressEelementCountersContainerInConfig(ReadWriteTransaction transaction, InstanceIdentifier<IngressElementCountersRequestConfig> ecrcIdentifier) {
    IngressElementCountersRequestConfigBuilder iecrcb = new IngressElementCountersRequestConfigBuilder();
    List<CounterRequests> counterRequests = new ArrayList<>();
    iecrcb.setCounterRequests(counterRequests);
    IngressElementCountersRequestConfig iecrc = iecrcb.build();
    transaction.put(LogicalDatastoreType.CONFIGURATION, ecrcIdentifier, iecrc, WriteTransaction.CREATE_MISSING_PARENTS);
}
Also used : IngressElementCountersRequestConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig) IngressElementCountersRequestConfigBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfigBuilder) ArrayList(java.util.ArrayList) CounterRequests(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)

Aggregations

IngressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfig)7 Optional (com.google.common.base.Optional)5 ExecutionException (java.util.concurrent.ExecutionException)5 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)5 EgressElementCountersRequestConfig (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.EgressElementCountersRequestConfig)5 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)3 CounterRequests (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequests)3 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)2 IngressElementCountersRequestConfigBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.IngressElementCountersRequestConfigBuilder)2 CounterRequestsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsKey)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 UUID (java.util.UUID)1 AcquireElementCountersRequestHandlerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutput)1 AcquireElementCountersRequestHandlerOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.AcquireElementCountersRequestHandlerOutputBuilder)1 CleanAllElementCounterRequestsOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.CleanAllElementCounterRequestsOutput)1 ReleaseElementCountersRequestHandlerOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.ReleaseElementCountersRequestHandlerOutput)1 CounterRequestsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.statistics.rev170120.counterrequestsconfig.CounterRequestsBuilder)1