Search in sources :

Example 51 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 ArpResponderUtil method getEgressActionsForInterface.

/**
 * Get List of Egress Action for the VPN interface.
 *
 * @param ifaceMgrRpcService
 *            Interface Manager RPC reference that invokes API to retrieve
 *            Egress Action
 * @param ifName
 *            VPN Interface for which Egress Action to be retrieved
 * @param actionCounter
 *            Action Key
 * @return List of Egress Actions
 */
public static List<Action> getEgressActionsForInterface(IInterfaceManager ifaceMgrRpcService, ItmRpcService itmRpcService, String ifName, int actionCounter, boolean isTunnelInterface) {
    if (isTunnelInterface && ifaceMgrRpcService.isItmDirectTunnelsEnabled()) {
        try {
            RpcResult result = itmRpcService.getEgressActionsForTunnel(new GetEgressActionsForTunnelInputBuilder().setIntfName(ifName).build()).get();
            Map<ActionKey, Action> listActions = new HashMap<ActionKey, Action>();
            if (!result.isSuccessful()) {
                LOG.error("getEgressActionsForInterface: RPC Call to Get egress actions for interface {} " + "returned with Errors {}", ifName, result.getErrors());
            } else {
                listActions = ((GetEgressActionsForTunnelOutput) result.getResult()).nonnullAction();
            }
            return new ArrayList<Action>(listActions.values());
        } catch (InterruptedException | ExecutionException e) {
            LOG.error("getEgressActionsForInterface: Exception when egress actions for interface {}", ifName, e);
        }
    } else {
        List<ActionInfo> actionInfos = ifaceMgrRpcService.getInterfaceEgressActions(ifName);
        AtomicInteger counter = new AtomicInteger(actionCounter);
        return actionInfos.stream().map(v -> v.buildAction(counter.getAndIncrement())).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : Arrays(java.util.Arrays) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) GetEgressActionsForTunnelOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetEgressActionsForTunnelOutput) LoggerFactory(org.slf4j.LoggerFactory) NxActionResubmitRpcAddGroupCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.nicira.action.rev140714.add.group.input.buckets.bucket.action.action.NxActionResubmitRpcAddGroupCase) ActionNxResubmit(org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit) Future(java.util.concurrent.Future) MatchArpTpa(org.opendaylight.genius.mdsalutil.matches.MatchArpTpa) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) GetEgressActionsForTunnelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetEgressActionsForTunnelInputBuilder) BigInteger(java.math.BigInteger) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) ActionLoadMacToSha(org.opendaylight.genius.mdsalutil.actions.ActionLoadMacToSha) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) ActionMoveSpaToTpa(org.opendaylight.genius.mdsalutil.actions.ActionMoveSpaToTpa) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) ActionLoadIpToSpa(org.opendaylight.genius.mdsalutil.actions.ActionLoadIpToSpa) MatchMetadata(org.opendaylight.genius.mdsalutil.matches.MatchMetadata) InstructionApplyActions(org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions) ActionNxLoadInPort(org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort) Collectors(java.util.stream.Collectors) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) AllocateIdInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInput) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) List(java.util.List) AllocateIdOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutput) Uint64(org.opendaylight.yangtools.yang.common.Uint64) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) HashMap(java.util.HashMap) ActionSetArpOp(org.opendaylight.genius.mdsalutil.actions.ActionSetArpOp) MatchArpOp(org.opendaylight.genius.mdsalutil.matches.MatchArpOp) Supplier(java.util.function.Supplier) ActionSetFieldEthernetSource(org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ActionMoveShaToTha(org.opendaylight.genius.mdsalutil.actions.ActionMoveShaToTha) MatchInfo(org.opendaylight.genius.mdsalutil.MatchInfo) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Logger(org.slf4j.Logger) ElanHelper(org.opendaylight.netvirt.elanmanager.api.ElanHelper) ActionMoveSourceDestinationEth(org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) ExecutionException(java.util.concurrent.ExecutionException) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) BucketInfo(org.opendaylight.genius.mdsalutil.BucketInfo) Collections(java.util.Collections) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) ItmRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) GetEgressActionsForTunnelInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.GetEgressActionsForTunnelInputBuilder) HashMap(java.util.HashMap) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutionException(java.util.concurrent.ExecutionException)

Example 52 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 NaptManager method removeFromIpMapDS.

protected void removeFromIpMapDS(Uint32 segmentId, String internalIp) {
    InstanceIdentifierBuilder<IpMap> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId)).child(IpMap.class, new IpMapKey(internalIp));
    InstanceIdentifier<IpMap> id = idBuilder.build();
    // Get externalIp and decrement the counter
    String externalIp = null;
    Optional<IpMap> ipMap = Optional.empty();
    try {
        ipMap = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("removeFromIpMapDS: Exception while reading IpMap DS for the segmentId {} " + "internalIp {}", segmentId, internalIp, e);
    }
    if (ipMap.isPresent()) {
        externalIp = ipMap.get().getExternalIp();
        LOG.debug("removeFromIpMapDS : externalIP is {}", externalIp);
    } else {
        LOG.warn("removeFromIpMapDS : ipMap not present for the internal IP {}", internalIp);
    }
    if (externalIp != null) {
        updateCounter(segmentId, externalIp, false);
        // remove from ipmap DS
        LOG.debug("removeFromIpMapDS : Removing ipmap from datastore");
        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    } else {
        LOG.warn("removeFromIpMapDS : externalIp not present for the internal IP {}", internalIp);
    }
}
Also used : IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) IpMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey) IpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap)

Example 53 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 NaptManager method updateCounter.

public void updateCounter(Uint32 segmentId, String externalIp, boolean isAdd) {
    short counter = 0;
    InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(segmentId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
    Optional<ExternalIpCounter> externalIpCounter = Optional.empty();
    try {
        externalIpCounter = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("updateCounter: Exception while reading ExternalIpCounter DS for the segmentId {} externalIp {} ", segmentId, externalIp, e);
    }
    if (externalIpCounter.isPresent()) {
        counter = externalIpCounter.get().getCounter().toJava();
        if (isAdd) {
            counter++;
            LOG.debug("updateCounter : externalIp and counter after increment are {} and {}", externalIp, counter);
        } else {
            if (counter > 0) {
                counter--;
            }
            LOG.debug("updateCounter : externalIp and counter after decrement are {} and {}", externalIp, counter);
        }
    } else if (isAdd) {
        counter = 1;
    }
    // update the new counter value for this externalIp
    ExternalIpCounter externalIpCounterData = new ExternalIpCounterBuilder().withKey(new ExternalIpCounterKey(externalIp)).setExternalIp(externalIp).setCounter(counter).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(segmentId, externalIp), externalIpCounterData);
}
Also used : ExternalCountersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalIpCounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterBuilder) ExternalIpCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterKey) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 54 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 bgpcep by opendaylight.

the class TopologyDataChangeCounter method putCount.

private void putCount(final long totalCount) {
    final WriteTransaction wTx = this.transactionChain.newWriteOnlyTransaction();
    final Counter counter = new CounterBuilder().setId(this.counterId).setCount(Uint32.valueOf(totalCount)).build();
    wTx.put(LogicalDatastoreType.OPERATIONAL, this.counterInstanceId, counter);
    wTx.commit().addCallback(new FutureCallback<CommitInfo>() {

        @Override
        public void onSuccess(final CommitInfo result) {
            LOG.debug("Data change count update stored");
        }

        @Override
        public void onFailure(final Throwable trw) {
            LOG.error("Failed to store Data change count");
        }
    }, MoreExecutors.directExecutor());
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) Counter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.Counter) DataChangeCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.DataChangeCounter) CounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.data.change.counter.rev160315.data.change.counter.CounterBuilder) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

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