Search in sources :

Example 1 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, String ifName, int actionCounter) {
    List<ActionInfo> actionInfos = ifaceMgrRpcService.getInterfaceEgressActions(ifName);
    AtomicInteger counter = new AtomicInteger(actionCounter);
    return actionInfos.stream().map(v -> v.buildAction(counter.getAndIncrement())).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) ActionDrop(org.opendaylight.genius.mdsalutil.actions.ActionDrop) 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) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) 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) ActionPuntToController(org.opendaylight.genius.mdsalutil.actions.ActionPuntToController) 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) GroupEntity(org.opendaylight.genius.mdsalutil.GroupEntity) 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) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) AllocateIdInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) GroupTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActionInfo(org.opendaylight.genius.mdsalutil.ActionInfo)

Example 2 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 openflowplugin by opendaylight.

the class TransactionChainManagerTest method testEnableCounter1.

/**
 * Test of {@link TransactionChainManager#enableSubmit()}: no submit - counter is not active.
 */
@Test
public void testEnableCounter1() throws Exception {
    final Node data = new NodeBuilder().setId(nodeId).build();
    txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
    txChainManager.writeToTransaction(LogicalDatastoreType.CONFIGURATION, path, data, false);
    Mockito.verify(txChain).newReadWriteTransaction();
    Mockito.verify(writeTx, Mockito.times(2)).put(LogicalDatastoreType.CONFIGURATION, path, data, false);
    Mockito.verify(writeTx, Mockito.never()).submit();
}
Also used : Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) NodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder) Test(org.junit.Test)

Example 3 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 handleInternalVpnSubnetRoutePacket.

private void handleInternalVpnSubnetRoutePacket(Uint64 metadata, byte[] dstIp, String srcIpStr, String dstIpStr, String vpnIdVpnInstanceName, long elanTag) throws InterruptedException, ExecutionException, UnknownHostException {
    String vmVpnInterfaceName = vpnUtil.getVpnInterfaceName(metadata);
    if (isTunnel(vmVpnInterfaceName)) {
        handlePacketFromTunnelToExternalNetwork(vpnIdVpnInstanceName, srcIpStr, dstIp, dstIpStr, elanTag);
    }
    VpnInterface vmVpnInterface = vpnUtil.getVpnInterface(vmVpnInterfaceName);
    if (vmVpnInterface == null) {
        LOG.error("Vpn interface {} doesn't exist.", vmVpnInterfaceName);
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(srcIpStr + "." + dstIpStr);
        counter.increment();
        return;
    }
    if (VpnHelper.doesVpnInterfaceBelongToVpnInstance(vpnIdVpnInstanceName, new ArrayList<>(vmVpnInterface.nonnullVpnInstanceNames().values())) && !vpnUtil.isBgpVpnInternet(vpnIdVpnInstanceName)) {
        LOG.trace("Unknown IP is in internal network");
        handlePacketToInternalNetwork(dstIp, dstIpStr, elanTag, srcIpStr);
    } else {
        LOG.trace("Unknown IP is in external network");
        String vpnName = vpnUtil.getInternetVpnFromVpnInstanceList(new ArrayList<>(vmVpnInterface.nonnullVpnInstanceNames().values()));
        if (vpnName != null) {
            handlePacketToExternalNetwork(new Uuid(vpnIdVpnInstanceName), vpnName, dstIp, dstIpStr, elanTag);
        } else {
            vpnName = VpnHelper.getFirstVpnNameFromVpnInterface(vmVpnInterface);
            LOG.trace("Unknown IP is in external network, but internet VPN not found." + " fallback to first VPN");
            handlePacketToExternalNetwork(new Uuid(vpnIdVpnInstanceName), vpnName, dstIp, dstIpStr, elanTag);
        }
    }
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) ArrayList(java.util.ArrayList)

Example 4 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 handlePacketToExternalNetwork.

private void handlePacketToExternalNetwork(Uuid vpnInstanceNameUuid, String routerId, byte[] dstIp, String dstIpStr, long elanTag) throws UnknownHostException {
    Routers externalRouter = vpnUtil.getExternalRouter(routerId);
    if (externalRouter == null) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label("." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Can't find external router with id {}", LOGGING_PREFIX, routerId);
        return;
    }
    Map<ExternalIpsKey, ExternalIps> externalIpsMap = externalRouter.getExternalIps();
    if (externalIpsMap == null || externalIpsMap.isEmpty()) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label("." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have any external ips.", LOGGING_PREFIX, externalRouter.getRouterName());
        return;
    }
    java.util.Optional<ExternalIps> externalIp = externalRouter.getExternalIps().values().stream().filter(eip -> vpnInstanceNameUuid.equals(eip.getSubnetId())).findFirst();
    if (!externalIp.isPresent()) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(externalIp.get().getIpAddress() + "." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Router {} doesn't have an external ip for subnet id {}.", LOGGING_PREFIX, externalRouter.getRouterName(), vpnInstanceNameUuid);
        return;
    }
    Uint64 dpnId = centralizedSwitchProvider.getPrimarySwitchForRouter(externalRouter.getRouterName());
    if (Uint64.ZERO.equals(dpnId)) {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(externalIp.get().getIpAddress() + "." + dstIpStr);
        counter.increment();
        LOG.debug("{} handlePacketToExternalNetwork: Could not find primary switch for router {}.", LOGGING_PREFIX, externalRouter.getRouterName());
        return;
    }
    transmitArpOrNsPacket(dpnId, externalIp.get().getIpAddress(), externalRouter.getExtGwMacAddress(), dstIp, dstIpStr, elanTag);
    Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_processed.toString()).label(externalIp.get().getIpAddress() + "." + dstIpStr);
    counter.increment();
}
Also used : SingleTransactionDataBroker(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker) MetricDescriptor(org.opendaylight.infrautils.metrics.MetricDescriptor) BitBufferHelper(org.opendaylight.openflowplugin.libraries.liblldp.BitBufferHelper) LoggerFactory(org.slf4j.LoggerFactory) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) InetAddress(java.net.InetAddress) PacketProcessingService(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingService) Nullable(org.eclipse.jdt.annotation.Nullable) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Map(java.util.Map) LoggingFutures(org.opendaylight.infrautils.utils.concurrent.LoggingFutures) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ArpUtils(org.opendaylight.netvirt.vpnmanager.iplearn.ipv4.ArpUtils) ICentralizedSwitchProvider(org.opendaylight.netvirt.vpnmanager.api.ICentralizedSwitchProvider) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) VpnIds(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.id.to.vpn.instance.VpnIds) Packet(org.opendaylight.openflowplugin.libraries.liblldp.Packet) Ethernet(org.opendaylight.genius.mdsalutil.packet.Ethernet) CounterUtility(org.opendaylight.netvirt.vpnmanager.utilities.CounterUtility) VpnHelper(org.opendaylight.netvirt.vpnmanager.api.VpnHelper) List(java.util.List) IpPrefixBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefixBuilder) ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) Labeled(org.opendaylight.infrautils.metrics.Labeled) Ipv6NdUtilService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.ipv6.nd.util.rev170210.Ipv6NdUtilService) Optional(java.util.Optional) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) PacketReceived(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceived) VpnInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.vpn.interfaces.VpnInterface) NWUtil(org.opendaylight.genius.mdsalutil.NWUtil) MetricProvider(org.opendaylight.infrautils.metrics.MetricProvider) Uint64(org.opendaylight.yangtools.yang.common.Uint64) OdlInterfaceRpcService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService) PacketProcessingListener(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketProcessingListener) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap) Inject(javax.inject.Inject) IfTunnel(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) BufferException(org.opendaylight.openflowplugin.libraries.liblldp.BufferException) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) Uint32(org.opendaylight.yangtools.yang.common.Uint32) Logger(org.slf4j.Logger) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) Ints(com.google.common.primitives.Ints) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) LogicalDatastoreType(org.opendaylight.mdsal.common.api.LogicalDatastoreType) Counter(org.opendaylight.infrautils.metrics.Counter) HexEncode(org.opendaylight.openflowplugin.libraries.liblldp.HexEncode) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) MetaDataUtil(org.opendaylight.genius.mdsalutil.MetaDataUtil) DataBroker(org.opendaylight.mdsal.binding.api.DataBroker) IpAddressBuilder(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder) ExternalIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIpsKey) Counter(org.opendaylight.infrautils.metrics.Counter) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps) Uint64(org.opendaylight.yangtools.yang.common.Uint64)

Example 5 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 handleBgpVpnSubnetRoute.

private void handleBgpVpnSubnetRoute(String srcMac, byte[] dstIp, String dstIpStr, String srcIpStr, long elanTag) throws UnknownHostException {
    LOG.info("{} handleBgpVpnSubnetRoute: Processing IP Packet received with Source IP {} and Target IP {}" + " and elan Tag {}", LOGGING_PREFIX, srcIpStr, dstIpStr, elanTag);
    SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(elanTag, dstIpStr);
    if (targetSubnetForPacketOut != null) {
        // Handle subnet routes ip requests
        transmitArpOrNsPacket(targetSubnetForPacketOut.getNhDpnId(), srcIpStr, srcMac, dstIp, dstIpStr, elanTag);
    } else {
        Counter counter = packetInCounter.label(CounterUtility.subnet_route_packet_failed.toString()).label(srcIpStr + "." + dstIpStr);
        counter.increment();
        LOG.debug("{} handleBgpVpnSubnetRoute: Could not find target subnet for packet out {}", LOGGING_PREFIX, dstIpStr);
    }
}
Also used : Counter(org.opendaylight.infrautils.metrics.Counter) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

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