Search in sources :

Example 66 with Flow

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.

the class VrfEntryListener method removeInterVPNLinkRouteFlows.

public void removeInterVPNLinkRouteFlows(final InterVpnLinkDataComposite interVpnLink, final String vpnName, final VrfEntry vrfEntry) {
    Preconditions.checkArgument(vrfEntry.getRoutePaths() != null && vrfEntry.getRoutePaths().size() == 1);
    String interVpnLinkName = interVpnLink.getInterVpnLinkName();
    List<BigInteger> targetDpns = interVpnLink.getEndpointDpnsByVpnName(vpnName);
    if (targetDpns.isEmpty()) {
        LOG.warn("Could not find DPNs for VPN {} in InterVpnLink {}", vpnName, interVpnLinkName);
        return;
    }
    java.util.Optional<String> optNextHop = FibUtil.getFirstNextHopAddress(vrfEntry);
    java.util.Optional<Long> optLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
    // delete from FIB
    // 
    optNextHop.ifPresent(nextHop -> {
        String flowRef = getInterVpnFibFlowRef(interVpnLinkName, vrfEntry.getDestPrefix(), nextHop);
        FlowKey flowKey = new FlowKey(new FlowId(flowRef));
        Flow flow = new FlowBuilder().setKey(flowKey).setId(new FlowId(flowRef)).setTableId(NwConstants.L3_FIB_TABLE).setFlowName(flowRef).build();
        LOG.trace("Removing flow in FIB table for interVpnLink {} key {}", interVpnLinkName, flowRef);
        for (BigInteger dpId : targetDpns) {
            LOG.debug("Removing flow: VrfEntry=[prefix={} nexthop={}] dpn {} for InterVpnLink {} in FIB", vrfEntry.getDestPrefix(), nextHop, dpId, interVpnLinkName);
            mdsalManager.removeFlow(dpId, flow);
        }
    });
    // delete from LFIB
    // 
    optLabel.ifPresent(label -> {
        LOG.trace("Removing flow in FIB table for interVpnLink {}", interVpnLinkName);
        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
        for (BigInteger dpId : targetDpns) {
            LOG.debug("Removing flow: VrfEntry=[prefix={} label={}] dpn {} for InterVpnLink {} in LFIB", vrfEntry.getDestPrefix(), label, dpId, interVpnLinkName);
            makeLFibTableEntry(dpId, label, /*instructions*/
            null, LFIB_INTERVPN_PRIORITY, NwConstants.DEL_FLOW, tx);
        }
        tx.submit();
    });
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder) BigInteger(java.math.BigInteger) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 67 with Flow

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.

the class ElanServiceTest method checkSMAC.

@Test
public void checkSMAC() throws Exception {
    // Create Elan instance
    createElanInstance(ExpectedObjects.ELAN1, ExpectedObjects.ELAN1_SEGMENT_ID);
    awaitForElanTag(ExpectedObjects.ELAN1);
    // Add Elan interface
    InterfaceInfo interfaceInfo = ELAN_INTERFACES.get(ELAN1 + ":" + DPN1MAC1).getLeft();
    addElanInterface(ExpectedObjects.ELAN1, interfaceInfo, DPN1IP1);
    // Read Elan instance
    InstanceIdentifier<ElanInstance> elanInstanceIid = InstanceIdentifier.builder(ElanInstances.class).child(ElanInstance.class, new ElanInstanceKey(ExpectedObjects.ELAN1)).build();
    ElanInstance actualElanInstances = singleTxdataBroker.syncRead(CONFIGURATION, elanInstanceIid);
    // Read and Compare SMAC flow
    String flowId = new StringBuffer().append(NwConstants.ELAN_SMAC_TABLE).append(actualElanInstances.getElanTag()).append(DPN1_ID).append(interfaceInfo.getInterfaceTag()).append(interfaceInfo.getMacAddress()).toString();
    InstanceIdentifier<Flow> flowInstanceIidSrc = getFlowIid(NwConstants.ELAN_SMAC_TABLE, new FlowId(flowId), DPN1_ID);
    awaitForData(LogicalDatastoreType.CONFIGURATION, flowInstanceIidSrc);
    Flow flowSrc = singleTxdataBroker.syncRead(CONFIGURATION, flowInstanceIidSrc);
    flowSrc = getFlowWithoutCookie(flowSrc);
    Flow expected = ExpectedObjects.checkSmac(flowId, interfaceInfo, actualElanInstances);
    AssertDataObjects.assertEqualBeans(expected, flowSrc);
}
Also used : ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) ElanInstanceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceKey) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow) Test(org.junit.Test)

Example 68 with Flow

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.

the class ElanServiceTestBase method getFlowIid.

protected InstanceIdentifier<Flow> getFlowIid(short tableId, FlowId flowid, BigInteger dpnId) {
    FlowKey flowKey = new FlowKey(new FlowId(flowid));
    NodeId nodeId = new NodeId("openflow:" + dpnId);
    Node nodeDpn = new NodeBuilder().setId(nodeId).setKey(new NodeKey(nodeId)).build();
    return InstanceIdentifier.builder(Nodes.class).child(Node.class, nodeDpn.getKey()).augmentation(FlowCapableNode.class).child(Table.class, new TableKey(tableId)).child(Flow.class, flowKey).build();
}
Also used : FlowId(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId) FlowKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) FlowCapableNode(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) TableKey(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey) NodeBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)

Example 69 with Flow

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.

the class DhcpNeutronPortListener method processArpResponderForElanDpns.

/**
 * Handle(Add/Remove) ARP Responder for DHCP IP on all the DPNs when DHCP is
 * enabled/disabled on subnet add or update or delete.
 *
 * @param port
 *            DHCP port for which ARP Responder flow to be added when dhcp
 *            flag is enabled on the subnet or DHCP port for which ARP
 *            Responder flow to be removed when dhcp flag is disabled on the
 *            Subnet
 * @param arpResponderAction
 *            ARP Responder Action to be performed i.e., add or remove flow
 */
private void processArpResponderForElanDpns(Port port, Consumer<ArpResponderInput> arpResponderAction) {
    java.util.Optional<String> ip4Address = DhcpServiceUtils.getIpV4Address(port);
    if (!ip4Address.isPresent()) {
        LOG.warn("There is no IPv4Address for port {}, not performing ARP responder add/remove flow operation", port.getName());
        return;
    }
    ElanHelper.getDpnInterfacesInElanInstance(broker, port.getNetworkId().getValue()).stream().map(ifName -> DhcpServiceUtils.getInterfaceInfo(interfaceManager, ifName)).forEach(interfaceInfo -> {
        ArpResponderInput arpResponderInput = new ArpResponderInput.ArpReponderInputBuilder().setDpId(interfaceInfo.getDpId()).setInterfaceName(interfaceInfo.getInterfaceName()).setLportTag(interfaceInfo.getInterfaceTag()).setSha(port.getMacAddress().getValue()).setSpa(ip4Address.get()).build();
        arpResponderAction.accept(arpResponderInput);
    });
}
Also used : Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports) DhcpMConstants(org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants) LoggerFactory(org.slf4j.LoggerFactory) PortBindingExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) Inject(javax.inject.Inject) AsyncClusteredDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase) PreDestroy(javax.annotation.PreDestroy) ArpReponderInputBuilder(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput.ArpReponderInputBuilder) NeutronConstants(org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants) Locale(java.util.Locale) ArpResponderUtil(org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Named(javax.inject.Named) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) DhcpserviceConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.config.rev150710.DhcpserviceConfig) Logger(org.slf4j.Logger) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) ElanHelper(org.opendaylight.netvirt.elanmanager.api.ElanHelper) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Consumer(java.util.function.Consumer) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) Collections(java.util.Collections) ArpResponderInput(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput) ArpResponderInput(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput) ArpReponderInputBuilder(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput.ArpReponderInputBuilder)

Example 70 with Flow

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow in project netvirt by opendaylight.

the class DhcpNeutronPortListener method update.

@Override
protected void update(InstanceIdentifier<Port> identifier, Port original, Port update) {
    LOG.trace("Port changed to {}", update);
    // With Ipv6 changes we can get ipv4 subnets later. The below check is to support such scenario.
    if (original.getFixedIps().size() < update.getFixedIps().size()) {
        final String interfaceName = update.getUuid().getValue();
        List<FixedIps> updatedFixedIps = update.getFixedIps();
        // Need to check only the newly added fixed ip.
        updatedFixedIps.removeAll(original.getFixedIps());
        Subnet subnet = dhcpManager.getNeutronSubnet(updatedFixedIps);
        if (null == subnet || !subnet.isEnableDhcp()) {
            LOG.trace("Subnet is null/not ipv4 or not enabled {}", subnet);
            return;
        }
        // Binding the DHCP service for an existing port because of subnet change.
        jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
            LOG.debug("Binding DHCP service for interface {}", interfaceName);
            DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx);
        })), DhcpMConstants.RETRY_COUNT);
        jobCoordinator.enqueueJob(DhcpServiceUtils.getJobKey(interfaceName), () -> {
            BigInteger dpnId = interfaceManager.getDpnForInterface(interfaceName);
            if (dpnId == null || dpnId.equals(DhcpMConstants.INVALID_DPID)) {
                LOG.trace("Unable to install the DHCP flow since dpn is not available");
                return Collections.emptyList();
            }
            return Collections.singletonList(txRunner.callWithNewReadWriteTransactionAndSubmit(tx -> dhcpManager.installDhcpEntries(dpnId, DhcpServiceUtils.getAndUpdateVmMacAddress(tx, interfaceName, dhcpManager), tx)));
        }, DhcpMConstants.RETRY_COUNT);
    }
    if (!isVnicTypeDirectOrMacVtap(update)) {
        LOG.trace("Port updated is normal {}", update.getUuid());
        if (isVnicTypeDirectOrMacVtap(original)) {
            LOG.trace("Original Port was direct/macvtap {} so removing flows and cache entry if any", update.getUuid());
            removePort(original);
        }
        return;
    }
    if (!isVnicTypeDirectOrMacVtap(original)) {
        LOG.trace("Original port was normal and updated is direct. Calling addPort()");
        addPort(update);
        return;
    }
    String macOriginal = getMacAddress(original);
    String macUpdated = getMacAddress(update);
    String segmentationIdOriginal = DhcpServiceUtils.getSegmentationId(original.getNetworkId(), broker);
    String segmentationIdUpdated = DhcpServiceUtils.getSegmentationId(update.getNetworkId(), broker);
    if (macOriginal != null && !macOriginal.equalsIgnoreCase(macUpdated) && segmentationIdOriginal != null && !segmentationIdOriginal.equalsIgnoreCase(segmentationIdUpdated)) {
        LOG.trace("Mac/segment id has changed");
        dhcpExternalTunnelManager.removeVniMacToPortCache(new BigInteger(segmentationIdOriginal), macOriginal);
        dhcpExternalTunnelManager.updateVniMacToPortCache(new BigInteger(segmentationIdUpdated), macUpdated, update);
    }
}
Also used : Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports) DhcpMConstants(org.opendaylight.netvirt.dhcpservice.api.DhcpMConstants) LoggerFactory(org.slf4j.LoggerFactory) PortBindingExtension(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.binding.rev150712.PortBindingExtension) IElanService(org.opendaylight.netvirt.elanmanager.api.IElanService) Singleton(javax.inject.Singleton) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) Inject(javax.inject.Inject) AsyncClusteredDataTreeChangeListenerBase(org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase) PreDestroy(javax.annotation.PreDestroy) ArpReponderInputBuilder(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput.ArpReponderInputBuilder) NeutronConstants(org.opendaylight.netvirt.neutronvpn.api.utils.NeutronConstants) Locale(java.util.Locale) ArpResponderUtil(org.opendaylight.netvirt.elan.arp.responder.ArpResponderUtil) ManagedNewTransactionRunnerImpl(org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) Named(javax.inject.Named) IInterfaceManager(org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager) DhcpserviceConfig(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.config.rev150710.DhcpserviceConfig) Logger(org.slf4j.Logger) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) ElanHelper(org.opendaylight.netvirt.elanmanager.api.ElanHelper) ManagedNewTransactionRunner(org.opendaylight.genius.infra.ManagedNewTransactionRunner) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Consumer(java.util.function.Consumer) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) PostConstruct(javax.annotation.PostConstruct) Collections(java.util.Collections) ArpResponderInput(org.opendaylight.netvirt.elan.arp.responder.ArpResponderInput) BigInteger(java.math.BigInteger) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)

Aggregations

Flow (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow)155 ArrayList (java.util.ArrayList)127 BigInteger (java.math.BigInteger)83 Test (org.junit.Test)67 FlowId (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId)65 FlowBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder)55 FlowKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey)51 TableKey (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey)47 MatchInfo (org.opendaylight.genius.mdsalutil.MatchInfo)44 FlowCapableNode (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode)41 List (java.util.List)36 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)35 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)35 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)33 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)31 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)30 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)30 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)28 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)24 Table (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table)24