Search in sources :

Example 1 with VipState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.neutron.vip.states.VipState in project netvirt by opendaylight.

the class NatArpNotificationHandler method onArpRequestReceived.

@Override
public void onArpRequestReceived(ArpRequestReceived notification) {
    LOG.debug("NatArpNotificationHandler received {}", notification);
    IpAddress srcIp = notification.getSrcIpaddress();
    if (srcIp == null || !Objects.equals(srcIp, notification.getDstIpaddress())) {
        LOG.debug("NatArpNotificationHandler: ignoring ARP packet, not gratuitous {}", notification);
        return;
    }
    // Since the point of all this is to learn VIPs those are by definition
    // not the IP addresses assigned to a port by neutron configuration.
    ElanInterface arpSenderIfc = elanService.getElanInterfaceByElanInterfaceName(notification.getInterface());
    if (ipBelongsToElanInterface(arpSenderIfc, srcIp)) {
        LOG.debug("NatArpNotificationHandler: ignoring GARP packet. No need to NAT a port's static IP. {}", notification);
        return;
    }
    ElanInterface targetIfc = null;
    for (String ifcName : elanService.getElanInterfaces(arpSenderIfc.getElanInstanceName())) {
        ElanInterface elanInterface = elanService.getElanInterfaceByElanInterfaceName(ifcName);
        if (ipBelongsToElanInterface(elanInterface, srcIp)) {
            targetIfc = elanInterface;
            break;
        }
    }
    if (null == targetIfc) {
        LOG.warn("NatArpNotificationHandler: GARP does not correspond to an interface in this elan {}", notification);
        return;
    }
    RouterInterface routerInterface = NatUtil.getConfiguredRouterInterface(dataBroker, targetIfc.getName());
    if (null == routerInterface) {
        LOG.warn("NatArpNotificationHandler: Could not retrieve router ifc for {}", targetIfc);
        return;
    }
    VipState newVipState = this.vipStateTracker.buildVipState(srcIp.getIpv4Address().getValue(), notification.getDpnId(), targetIfc.getName());
    VipState cachedState = null;
    try {
        cachedState = this.vipStateTracker.get(newVipState.getIp()).orElse(null);
    } catch (ReadFailedException e) {
        LOG.warn("NatArpNotificationHandler failed to read vip state {}", notification, e);
    }
    if (null == cachedState) {
        this.southboundEventHandlers.handleAdd(targetIfc.getName(), notification.getDpnId(), routerInterface, newVipState);
    } else if (!cachedState.getDpnId().equals(newVipState.getDpnId())) {
        this.southboundEventHandlers.handleRemove(cachedState.getIfcName(), cachedState.getDpnId(), routerInterface);
        this.southboundEventHandlers.handleAdd(targetIfc.getName(), notification.getDpnId(), routerInterface, newVipState);
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) ElanInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface) RouterInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces.RouterInterface) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) VipState(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.neutron.vip.states.VipState)

Example 2 with VipState

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.neutron.vip.states.VipState in project netvirt by opendaylight.

the class NatSouthboundEventHandlers method processInterfaceAdded.

@SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", justification = "https://github.com/spotbugs/spotbugs/issues/811")
private void processInterfaceAdded(String portName, String routerId, Uint64 dpnId, VipState vipState) {
    LOG.trace("processInterfaceAdded : Processing Interface Add Event for interface {}", portName);
    List<InternalToExternalPortMap> intExtPortMapList = getIntExtPortMapListForPortName(portName, routerId);
    if (intExtPortMapList.isEmpty()) {
        LOG.debug("processInterfaceAdded : Ip Mapping list is empty/null for portname {}", portName);
        return;
    }
    InstanceIdentifier<RouterPorts> portIid = NatUtil.buildRouterPortsIdentifier(routerId);
    FluentFuture<?> future = txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION, tx -> {
        for (InternalToExternalPortMap intExtPortMap : intExtPortMapList) {
            floatingIPListener.createNATFlowEntries(portName, intExtPortMap, portIid, routerId, dpnId, tx);
        }
    });
    future.transform((ignored) -> {
        if (vipState != null) {
            return this.vipStateTracker.writeVipState(vipState);
        }
        return null;
    }, MoreExecutors.directExecutor());
}
Also used : RouterPorts(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts) InternalToExternalPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)1 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)1 ElanInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface)1 RouterInterface (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces.RouterInterface)1 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)1 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)1 VipState (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.neutron.vip.states.VipState)1