Search in sources :

Example 6 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project netvirt by opendaylight.

the class ExternalNetworkGroupInstaller method installExtNetGroupEntries.

public void installExtNetGroupEntries(Uuid subnetId, String macAddress) {
    Subnetmap subnetMap = NatUtil.getSubnetMap(broker, subnetId);
    if (subnetMap == null) {
        LOG.error("installExtNetGroupEntries : Subnetmap is null");
        return;
    }
    if (NatUtil.isIPv6Subnet(subnetMap.getSubnetIp())) {
        LOG.debug("installExtNetGroupEntries : Subnet-id {} is not an IPv4 subnet, hence skipping.", subnetMap.getId());
        return;
    }
    installExtNetGroupEntries(subnetMap, macAddress);
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)

Example 7 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project netvirt by opendaylight.

the class NaptFlowRemovedEventHandler method onFlowRemoved.

@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
    /*
        If the removed flow is from the OUTBOUND NAPT table :
        1) Get the ActionInfo of the flow.
        2) From the ActionInfo of the flow get the internal IP address, port and the protocol.
        3) Get the Metadata matching info of the flow.
        4) From the Metadata matching info of the flow get router ID.
        5) Querry the container intext-ip-port-map using the router ID
           and the internal IP address, port to get the external IP address, port
        6) Instantiate an NaptEntry event and populate the external IP address, port and the router ID.
        7) Place the NaptEntry event to the queue.
*/
    short tableId = flowRemoved.getTableId();
    RemovedFlowReason removedReasonFlag = flowRemoved.getReason();
    if (tableId == NwConstants.OUTBOUND_NAPT_TABLE && RemovedFlowReason.OFPRRIDLETIMEOUT.equals(removedReasonFlag)) {
        LOG.info("onFlowRemoved : triggered for table-{} entry", tableId);
        // Get the internal internal IP address and the port number from the IPv4 match.
        Ipv4Prefix internalIpv4Address = null;
        Layer3Match layer3Match = flowRemoved.getMatch().getLayer3Match();
        if (layer3Match instanceof Ipv4Match) {
            Ipv4Match internalIpv4Match = (Ipv4Match) layer3Match;
            internalIpv4Address = internalIpv4Match.getIpv4Source();
        }
        if (internalIpv4Address == null) {
            LOG.error("onFlowRemoved : Matching internal IP is null while retrieving the " + "value from the Outbound NAPT flow");
            return;
        }
        // Get the internal IP as a string
        String internalIpv4AddressAsString = internalIpv4Address.getValue();
        String[] internalIpv4AddressParts = internalIpv4AddressAsString.split("/");
        String internalIpv4HostAddress = null;
        if (internalIpv4AddressParts.length >= 1) {
            internalIpv4HostAddress = internalIpv4AddressParts[0];
        }
        // Get the protocol from the layer4 match
        NAPTEntryEvent.Protocol protocol = null;
        Integer internalPortNumber = null;
        Layer4Match layer4Match = flowRemoved.getMatch().getLayer4Match();
        if (layer4Match instanceof TcpMatch) {
            TcpMatchFields tcpMatchFields = (TcpMatchFields) layer4Match;
            internalPortNumber = tcpMatchFields.getTcpSourcePort().getValue();
            protocol = NAPTEntryEvent.Protocol.TCP;
        } else if (layer4Match instanceof UdpMatch) {
            UdpMatchFields udpMatchFields = (UdpMatchFields) layer4Match;
            internalPortNumber = udpMatchFields.getUdpSourcePort().getValue();
            protocol = NAPTEntryEvent.Protocol.UDP;
        }
        if (protocol == null) {
            LOG.error("onFlowRemoved : Matching protocol is null while retrieving the value " + "from the Outbound NAPT flow");
            return;
        }
        // Get the router ID from the metadata.
        Long routerId;
        BigInteger metadata = flowRemoved.getMatch().getMetadata().getMetadata();
        if (MetaDataUtil.getNatRouterIdFromMetadata(metadata) != 0) {
            routerId = MetaDataUtil.getNatRouterIdFromMetadata(metadata);
        } else {
            LOG.error("onFlowRemoved : Null exception while retrieving routerId");
            return;
        }
        final String internalIpPortKey = routerId + NatConstants.COLON_SEPARATOR + internalIpv4HostAddress + NatConstants.COLON_SEPARATOR + internalPortNumber;
        // Get the external IP address and the port from the model
        IpPortExternal ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIpv4HostAddress, internalPortNumber.toString(), protocol);
        if (ipPortExternal == null) {
            LOG.error("onFlowRemoved : IpPortExternal not found, BGP vpn might be " + "associated with router");
            // router must be associated with BGP vpn ID
            long bgpVpnId = routerId;
            LOG.debug("onFlowRemoved : BGP VPN ID {}", bgpVpnId);
            String vpnName = NatUtil.getRouterName(dataBroker, bgpVpnId);
            String routerName = NatUtil.getRouterIdfromVpnInstance(dataBroker, vpnName);
            if (routerName == null) {
                LOG.error("onFlowRemoved : Unable to find router for VpnName {}", vpnName);
                return;
            }
            routerId = NatUtil.getVpnId(dataBroker, routerName);
            LOG.debug("onFlowRemoved : Router ID {}", routerId);
            ipPortExternal = NatUtil.getExternalIpPortMap(dataBroker, routerId, internalIpv4HostAddress, internalPortNumber.toString(), protocol);
            if (ipPortExternal == null) {
                LOG.error("onFlowRemoved : IpPortExternal is null while queried from the " + "model for routerId {}", routerId);
                return;
            }
        }
        String externalIpAddress = ipPortExternal.getIpAddress();
        int externalPortNumber = ipPortExternal.getPortNum();
        // Create an NAPT event and place it in the queue.
        NAPTEntryEvent naptEntryEvent = new NAPTEntryEvent(externalIpAddress, externalPortNumber, routerId, NAPTEntryEvent.Operation.DELETE, protocol, null, false, null);
        naptEventdispatcher.addFlowRemovedNaptEvent(naptEntryEvent);
        // Get the DPN ID from the Node
        InstanceIdentifier<Node> nodeRef = flowRemoved.getNode().getValue().firstIdentifierOf(Node.class);
        String dpn = nodeRef.firstKeyOf(Node.class).getId().getValue();
        BigInteger dpnId = getDpnId(dpn);
        String switchFlowRef = NatUtil.getNaptFlowRef(dpnId, tableId, String.valueOf(routerId), internalIpv4HostAddress, internalPortNumber);
        // Inform the MDSAL manager to inform about the flow removal.
        LOG.debug("onFlowRemoved : DPN ID {}, Metadata {}, SwitchFlowRef {}, " + "internalIpv4HostAddress{}", dpnId, routerId, switchFlowRef, internalIpv4AddressAsString);
        FlowEntity snatFlowEntity = NatUtil.buildFlowEntity(dpnId, tableId, switchFlowRef);
        long startTime = System.currentTimeMillis();
        mdsalManager.removeFlow(snatFlowEntity);
        LOG.debug("onFlowRemoved : Elapsed time fo deleting table-{} flow for snat ({}) session:{}ms", tableId, internalIpPortKey, (System.currentTimeMillis() - startTime));
        // Remove the SourceIP:Port key from the Napt packet handler map.
        naptPacketInHandler.removeIncomingPacketMap(internalIpPortKey);
        // Remove the mapping of internal fixed ip/port to external ip/port from the datastore.
        SessionAddress internalSessionAddress = new SessionAddress(internalIpv4HostAddress, internalPortNumber);
        naptManager.releaseIpExtPortMapping(routerId, internalSessionAddress, protocol);
        LOG.info("onFlowRemoved : exit");
    } else {
        LOG.debug("onFlowRemoved : Received flow removed notification due to flowdelete from switch for flowref");
    }
}
Also used : Layer3Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) UdpMatchFields(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.UdpMatchFields) Ipv4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match) TcpMatchFields(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.TcpMatchFields) FlowEntity(org.opendaylight.genius.mdsalutil.FlowEntity) BigInteger(java.math.BigInteger) RemovedFlowReason(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.RemovedFlowReason) TcpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch) Layer4Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer4Match) UdpMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatch) BigInteger(java.math.BigInteger) IpPortExternal(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.ip.port.map.IpPortExternal) Ipv4Prefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)

Example 8 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project netvirt by opendaylight.

the class ElanUtils method getSourceIpAddress.

public Optional<IpAddress> getSourceIpAddress(Ethernet ethernet) {
    Optional<IpAddress> srcIpAddress = Optional.absent();
    if (ethernet.getPayload() == null) {
        return srcIpAddress;
    }
    byte[] ipAddrBytes = null;
    if (ethernet.getPayload() instanceof IPv4) {
        IPv4 ipv4 = (IPv4) ethernet.getPayload();
        ipAddrBytes = Ints.toByteArray(ipv4.getSourceAddress());
    } else if (ethernet.getPayload() instanceof ARP) {
        ipAddrBytes = ((ARP) ethernet.getPayload()).getSenderProtocolAddress();
    }
    if (ipAddrBytes != null) {
        String ipAddr = NWUtil.toStringIpAddress(ipAddrBytes);
        return Optional.of(IpAddressBuilder.getDefaultInstance(ipAddr));
    }
    return srcIpAddress;
}
Also used : IPv4(org.opendaylight.genius.mdsalutil.packet.IPv4) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) ARP(org.opendaylight.genius.mdsalutil.packet.ARP)

Example 9 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 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)

Example 10 with Ipv4

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.ipv4._case.Ipv4 in project netvirt by opendaylight.

the class NeutronvpnUtils method getIpVersionChoicesFromRouterUuid.

/**
 * Method to get an ipVersionChosen as IPV4 and/or IPV6 or undefined from the subnetmaps of the router.
 * @param routerUuid the Uuid for which find out the IP version associated
 * @return an IpVersionChoice used by the router from its attached subnetmaps. IpVersionChoice.UNDEFINED if any
 */
public IpVersionChoice getIpVersionChoicesFromRouterUuid(Uuid routerUuid) {
    IpVersionChoice rep = IpVersionChoice.UNDEFINED;
    if (routerUuid == null) {
        return rep;
    }
    List<Subnetmap> subnetmapList = getNeutronRouterSubnetMaps(routerUuid);
    if (subnetmapList.isEmpty()) {
        return rep;
    }
    for (Subnetmap sn : subnetmapList) {
        if (sn.getSubnetIp() != null) {
            IpVersionChoice ipVers = getIpVersionFromString(sn.getSubnetIp());
            if (rep.choice != ipVers.choice) {
                rep = rep.addVersion(ipVers);
            }
            if (rep.choice == IpVersionChoice.IPV4AND6.choice) {
                return rep;
            }
        }
    }
    return rep;
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Aggregations

Test (org.junit.Test)89 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)35 ArrayList (java.util.ArrayList)32 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)23 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)22 ByteBuf (io.netty.buffer.ByteBuf)21 Ipv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder)19 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)18 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)17 BigInteger (java.math.BigInteger)16 IpMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.IpMatchBuilder)15 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)14 EthernetMatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder)14 Icmpv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Icmpv6MatchBuilder)14 TunnelIpv4MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.TunnelIpv4MatchBuilder)12 EtherType (org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.EtherType)11 EthernetTypeBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetTypeBuilder)11 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)11 MappingData (org.opendaylight.lispflowmapping.lisp.type.MappingData)10 PortNumber (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber)10