Search in sources :

Example 81 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of in project netvirt by opendaylight.

the class IVpnLinkServiceImpl method handleStaticRoute.

/*
     * Takes care of an static route to see if flows related to interVpnLink
     * must be installed in tables 20 and 17
     *
     * @param vpnId Vpn to which the route belongs
     * @param route Route to handle. Will only be considered if its nexthop is the VPN's endpoint IpAddress
     *              at the other side of the InterVpnLink
     * @param iVpnLink
     */
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleStaticRoute(String vpnId, Routes route, InterVpnLinkDataComposite ivpnLink) {
    IpAddress nhIpAddr = route.getNexthop();
    String routeNextHop = nhIpAddr.getIpv4Address() != null ? nhIpAddr.getIpv4Address().getValue() : nhIpAddr.getIpv6Address().getValue();
    String destination = String.valueOf(route.getDestination().getValue());
    // is nexthop the other endpoint's IP
    String otherEndpoint = ivpnLink.getOtherEndpoint(vpnId);
    if (!routeNextHop.equals(otherEndpoint)) {
        LOG.debug("VPN {}: Route to {} nexthop={} points to an InterVpnLink endpoint, but its not " + "the other endpoint. Other endpoint is {}", vpnId, destination, routeNextHop, otherEndpoint);
        return;
    }
    // Lets work: 1) write Fibentry, 2) advertise to BGP and 3) check if it must be leaked
    String vpnRd = VpnUtil.getVpnRd(dataBroker, vpnId);
    if (vpnRd == null) {
        LOG.warn("Could not find Route-Distinguisher for VpnName {}", vpnId);
        return;
    }
    int label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnId, destination));
    try {
        InterVpnLinkUtil.handleStaticRoute(ivpnLink, vpnId, destination, routeNextHop, label, dataBroker, fibManager, bgpManager);
    } catch (Exception e) {
        LOG.error("Exception while advertising prefix for intervpn link, {}", e);
    }
}
Also used : IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 82 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of in project netvirt by opendaylight.

the class InterVpnLinkListener method add.

@Override
protected void add(InstanceIdentifier<InterVpnLink> identifier, InterVpnLink add) {
    String ivpnLinkName = add.getName();
    LOG.debug("Reacting to IVpnLink {} creation. Vpn1=[name={}  EndpointIp={}]  Vpn2=[name={} endpointIP={}]", ivpnLinkName, add.getFirstEndpoint().getVpnUuid(), add.getFirstEndpoint().getIpAddress(), add.getSecondEndpoint().getVpnUuid(), add.getSecondEndpoint().getIpAddress());
    // Create VpnLink state
    InstanceIdentifier<InterVpnLinkState> vpnLinkStateIid = InterVpnLinkUtil.getInterVpnLinkStateIid(ivpnLinkName);
    InterVpnLinkState vpnLinkState = new InterVpnLinkStateBuilder().setInterVpnLinkName(ivpnLinkName).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnLinkStateIid, vpnLinkState);
    InterVpnLinkKey key = add.getKey();
    Uuid vpn1Uuid = add.getFirstEndpoint().getVpnUuid();
    String vpn1Name = vpn1Uuid.getValue();
    Uuid vpn2Uuid = add.getSecondEndpoint().getVpnUuid();
    String vpn2Name = vpn2Uuid.getValue();
    String vpn1PrimaryRd = VpnUtil.getPrimaryRd(dataBroker, vpn1Name);
    String vpn2PrimaryRd = VpnUtil.getPrimaryRd(dataBroker, vpn1Name);
    if (!VpnUtil.isVpnPendingDelete(dataBroker, vpn1PrimaryRd) && !VpnUtil.isVpnPendingDelete(dataBroker, vpn2PrimaryRd)) {
        if (VpnUtil.getVpnInstance(this.dataBroker, vpn1Name) == null) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 1st endpoint Vpn " + vpn1Name;
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        if (!checkVpnAvailability(key, vpn1Name)) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn1Name + " is already associated to an inter-vpn-link ";
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        // Second VPN
        if (VpnUtil.getVpnInstance(this.dataBroker, vpn2Name) == null) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: could not find 2nd endpoint Vpn " + vpn2Name;
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        if (!checkVpnAvailability(key, vpn2Name)) {
            String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Vpn " + vpn2Name + " is already associated with an inter-vpn-link";
            setInError(vpnLinkStateIid, vpnLinkState, errMsg);
            return;
        }
        interVpnLinkCache.addInterVpnLinkToCaches(add);
        // Wait for VPN Operational data ready
        long vpn1Id = VpnUtil.getVpnId(dataBroker, vpn1Name);
        if (vpn1Id == VpnConstants.INVALID_ID) {
            boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn1Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
            if (!vpn1Ready) {
                String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn1Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
                setInError(vpnLinkStateIid, vpnLinkState, errMsg);
                return;
            }
        }
        long vpn2Id = VpnUtil.getVpnId(dataBroker, vpn2Name);
        if (vpn2Id == VpnConstants.INVALID_ID) {
            boolean vpn1Ready = vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataSyncer.VpnOpDataType.vpnInstanceToId, vpn2Name, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
            if (!vpn1Ready) {
                String errMsg = "InterVpnLink " + ivpnLinkName + " creation error: Operational Data for VPN " + vpn2Name + " not ready after " + VpnConstants.PER_INTERFACE_MAX_WAIT_TIME_IN_MILLISECONDS + " milliseconds";
                setInError(vpnLinkStateIid, vpnLinkState, errMsg);
                return;
            }
        }
        List<BigInteger> firstDpnList = ivpnLinkLocator.selectSuitableDpns(add);
        if (firstDpnList != null && !firstDpnList.isEmpty()) {
            List<BigInteger> secondDpnList = firstDpnList;
            Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
            Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
            FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setDpId(firstDpnList).setLportTag(firstVpnLportTag).build();
            SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setDpId(secondDpnList).setLportTag(secondVpnLportTag).build();
            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Active, firstEndPointState, secondEndPointState, interVpnLinkCache);
            // Note that in the DPN of the firstEndpoint we install the lportTag of the secondEndpoint and viceversa
            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, firstDpnList, vpn2Name, secondVpnLportTag);
            InterVpnLinkUtil.installLPortDispatcherTableFlow(dataBroker, mdsalManager, ivpnLinkName, secondDpnList, vpn1Name, firstVpnLportTag);
            // Update the VPN -> DPNs Map.
            // Note: when a set of DPNs is calculated for Vpn1, these DPNs are added to the VpnToDpn map of Vpn2.
            // Why? because we do the handover from Vpn1 to Vpn2 in those DPNs, so in those DPNs we must know how
            // to reach to Vpn2 targets. If new Vpn2 targets are added later, the Fib will be maintained in these
            // DPNs even if Vpn2 is not physically present there.
            InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, vpn2Name, vpn2PrimaryRd, firstDpnList);
            InterVpnLinkUtil.updateVpnFootprint(vpnFootprintService, vpn1Name, vpn1PrimaryRd, secondDpnList);
            // Program static routes if needed
            Optional<InterVpnLinkDataComposite> interVpnLink = interVpnLinkCache.getInterVpnLinkByName(ivpnLinkName);
            ivpnLinkService.handleStaticRoutes(interVpnLink.get());
            // Now, if the corresponding flags are activated, there will be some routes exchange
            ivpnLinkService.exchangeRoutes(interVpnLink.get());
        } else {
            // If there is no connection to DPNs, the InterVpnLink is created and the InterVpnLinkState is also
            // created with the corresponding LPortTags but no DPN is assigned since there is no DPN operative.
            Long firstVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn1Name);
            Long secondVpnLportTag = allocateVpnLinkLportTag(key.getName() + vpn2Name);
            FirstEndpointState firstEndPointState = new FirstEndpointStateBuilder().setVpnUuid(vpn1Uuid).setLportTag(firstVpnLportTag).setDpId(Collections.emptyList()).build();
            SecondEndpointState secondEndPointState = new SecondEndpointStateBuilder().setVpnUuid(vpn2Uuid).setLportTag(secondVpnLportTag).setDpId(Collections.emptyList()).build();
            InterVpnLinkUtil.updateInterVpnLinkState(dataBroker, ivpnLinkName, InterVpnLinkState.State.Error, firstEndPointState, secondEndPointState, interVpnLinkCache);
        }
    }
}
Also used : InterVpnLinkKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLinkKey) FirstEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointState) InterVpnLinkStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkStateBuilder) FirstEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.FirstEndpointStateBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SecondEndpointStateBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointStateBuilder) BigInteger(java.math.BigInteger) InterVpnLinkState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState) SecondEndpointState(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.inter.vpn.link.state.SecondEndpointState) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 83 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onSubnetAddedToVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetAddedToVpn(Subnetmap subnetmap, boolean isBgpVpn, Long elanTag) {
    Uuid subnetId = subnetmap.getId();
    String subnetIp = subnetmap.getSubnetIp();
    Subnetmap subMap = null;
    SubnetOpDataEntry subOpEntry = null;
    SubnetOpDataEntryBuilder subOpBuilder = null;
    InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = null;
    Optional<SubnetOpDataEntry> optionalSubs = null;
    Preconditions.checkNotNull(subnetId, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetId cannot be null or empty!");
    Preconditions.checkNotNull(subnetIp, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetPrefix cannot be null or empty!");
    Preconditions.checkNotNull(elanTag, LOGGING_PREFIX + " onSubnetAddedToVpn: ElanTag cannot be null or empty!");
    String vpnName;
    if (subnetmap.getVpnId() != null) {
        vpnName = subnetmap.getVpnId().getValue();
        long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
        if (vpnId == VpnConstants.INVALID_ID) {
            vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataType.vpnInstanceToId, vpnName, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
            vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
            if (vpnId == VpnConstants.INVALID_ID) {
                LOG.error("{} onSubnetAddedToVpn: VpnInstance to VPNId mapping not yet available for VpnName {} " + "processing subnet {} with IP {}, bailing out now.", LOGGING_PREFIX, vpnName, subnetId, subnetIp);
                return;
            }
        }
    } else {
        LOG.error("onSubnetAddedToVpn: VpnId {} for subnet {} not found, bailing out", subnetmap.getVpnId(), subnetId);
        return;
    }
    LOG.info("{} onSubnetAddedToVpn: Subnet {} with IP {} being added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            // Please check if subnetId belongs to an External Network
            InstanceIdentifier<Subnetmap> subMapid = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
            Optional<Subnetmap> sm = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subMapid);
            if (!sm.isPresent()) {
                LOG.error("{} onSubnetAddedToVpn: Unable to retrieve subnetmap entry for subnet {} IP {}" + " vpnName {}", LOGGING_PREFIX, subnetId, subnetIp, vpnName);
                return;
            }
            subMap = sm.get();
            if (isBgpVpn) {
                InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(subMap.getNetworkId())).build();
                Optional<Networks> optionalNets = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
                if (optionalNets.isPresent()) {
                    LOG.info("{} onSubnetAddedToVpn: subnet {} with IP {} is an external subnet on external " + "network {}, so ignoring this for SubnetRoute on vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, subMap.getNetworkId().getValue(), vpnName);
                    return;
                }
            }
            // Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
            subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (optionalSubs.isPresent()) {
                LOG.error("{} onSubnetAddedToVpn: SubnetOpDataEntry for subnet {} with ip {} and vpn {} already" + " detected to be present", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
                return;
            }
            LOG.debug("{} onSubnetAddedToVpn: Creating new SubnetOpDataEntry node for subnet {} subnetIp {} " + "vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
            subOpBuilder = new SubnetOpDataEntryBuilder().setKey(new SubnetOpDataEntryKey(subnetId));
            subOpBuilder.setSubnetId(subnetId);
            subOpBuilder.setSubnetCidr(subnetIp);
            String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
            if (isBgpVpn && !VpnUtil.isBgpVpn(vpnName, primaryRd)) {
                LOG.error("{} onSubnetAddedToVpn: The VPN Instance name {} does not have RD. Bailing out for" + " subnet {} subnetIp {} ", LOGGING_PREFIX, vpnName, subnetId.getValue(), subnetIp);
                return;
            }
            subOpBuilder.setVrfId(primaryRd);
            subOpBuilder.setVpnName(vpnName);
            subOpBuilder.setSubnetToDpn(new ArrayList<>());
            subOpBuilder.setRouteAdvState(TaskState.Idle);
            subOpBuilder.setElanTag(elanTag);
            Long l3Vni = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd).getL3vni();
            subOpBuilder.setL3vni(l3Vni);
            subOpEntry = subOpBuilder.build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
            LOG.info("onSubnetAddedToVpn: Added subnetopdataentry to OP Datastore for subnet {}", subnetId.getValue());
        } catch (Exception ex) {
            LOG.error("Creation of SubnetOpDataEntry for subnet {} failed ", subnetId.getValue(), ex);
            // The second part of this method depends on subMap being non-null so fail fast here.
            return;
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
        // In second critical section , Port-Op-Data will be updated.
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            BigInteger dpnId = null;
            SubnetToDpn subDpn = null;
            Map<BigInteger, SubnetToDpn> subDpnMap = new HashMap<>();
            optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get()).setKey(new SubnetOpDataEntryKey(subnetId));
            List<Uuid> portList = subMap.getPortList();
            if (portList != null) {
                for (Uuid port : portList) {
                    Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, port.getValue());
                    if (intfState != null) {
                        try {
                            dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
                        } catch (Exception e) {
                            LOG.error("{} onSubnetAddedToVpn: Unable to obtain dpnId for interface {}," + " subnetroute inclusion for this interface for subnet {} subnetIp {} vpn {}" + " failed with exception", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName, e);
                            continue;
                        }
                        if (dpnId.equals(BigInteger.ZERO)) {
                            LOG.error("{} onSubnetAddedToVpn: Port {} is not assigned DPN yet," + " ignoring subnet {} subnetIP {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
                            continue;
                        }
                        subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, dpnId);
                        if (intfState.getOperStatus() != OperStatus.Up) {
                            LOG.error("{} onSubnetAddedToVpn: Port {} is not UP yet, ignoring subnet {}" + " subnetIp {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
                            continue;
                        }
                        subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, port.getValue());
                        if (intfState.getOperStatus() == OperStatus.Up) {
                            // port is UP
                            subDpnMap.put(dpnId, subDpn);
                        }
                    } else {
                        subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, null);
                    }
                }
                if (subDpnMap.size() > 0) {
                    subOpBuilder.setSubnetToDpn(new ArrayList<>(subDpnMap.values()));
                }
            }
            electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
            subnetId, subMap.getNetworkId(), isBgpVpn);
            subOpEntry = subOpBuilder.build();
            MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
            LOG.info("{} onSubnetAddedToVpn: Added PortOpDataEntry and VpnInterfaces to SubnetOpData" + " for subnet {} subnetIp {} vpn {} TaskState {} lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
        } catch (RuntimeException ex) {
            LOG.error("{} onSubnetAddedToVpn: Creation of SubnetOpDataEntry for subnet {} subnetIp {} vpn {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (RuntimeException e) {
        LOG.error("{} onSubnetAddedToVpn: Unable to handle subnet {} with ip {} added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, e);
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.Networks) ExternalNetworks(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalNetworks) HashMap(java.util.HashMap) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) SubnetOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn) NetworksKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) BigInteger(java.math.BigInteger) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)

Example 84 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onSubnetDeletedFromVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetDeletedFromVpn(Subnetmap subnetmap, boolean isBgpVpn) {
    Uuid subnetId = subnetmap.getId();
    LOG.info("{} onSubnetDeletedFromVpn: Subnet {} with ip {} being removed from vpnId {}", LOGGING_PREFIX, subnetId, subnetmap.getSubnetIp(), subnetmap.getVpnId());
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.error("{} onSubnetDeletedFromVpn: SubnetOpDataEntry for subnet {} subnetIp {} vpn {}" + " not available in datastore", LOGGING_PREFIX, subnetId.getValue(), subnetId.getValue(), subnetmap.getVpnId());
                return;
            }
            LOG.trace("{} onSubnetDeletedFromVpn: Removing the SubnetOpDataEntry node for subnet {} subnetIp {}" + " vpnName {} rd {} TaskState {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState());
            /* If subnet is deleted (or if its removed from VPN), the ports that are DOWN on that subnet
                 * will continue to be stale in portOpData DS, as subDpnList used for portOpData removal will
                 * contain only ports that are UP. So here we explicitly cleanup the ports of the subnet by
                 * going through the list of ports on the subnet
                 */
            InstanceIdentifier<Subnetmap> subMapid = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
            Optional<Subnetmap> sm = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subMapid);
            if (!sm.isPresent()) {
                LOG.error("{} onSubnetDeletedFromVpn: Stale ports removal: Unable to retrieve subnetmap entry" + " for subnet {} subnetIp {} vpnName {}", LOGGING_PREFIX, subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName());
            } else {
                Subnetmap subMap = sm.get();
                List<Uuid> portList = subMap.getPortList();
                if (portList != null) {
                    for (Uuid port : portList) {
                        InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(port.getValue())).build();
                        LOG.trace("{} onSubnetDeletedFromVpn: Deleting portOpData entry for port {}" + " from subnet {} subnetIp {} vpnName {} TaskState {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getRouteAdvState());
                        MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
                    }
                }
            }
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get());
            String rd = subOpBuilder.getVrfId();
            String subnetIp = subOpBuilder.getSubnetCidr();
            String vpnName = subOpBuilder.getVpnName();
            // Withdraw the routes for all the interfaces on this subnet
            // Remove subnet route entry from FIB
            deleteSubnetRouteFromFib(rd, subnetIp, vpnName, isBgpVpn);
            MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            LOG.info("{} onSubnetDeletedFromVpn: Removed subnetopdataentry successfully from Datastore" + " for subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd);
        } catch (RuntimeException ex) {
            LOG.error("{} onSubnetDeletedFromVpn: Removal of SubnetOpDataEntry for subnet {} subnetIp {}" + " vpnId {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetmap.getSubnetIp(), subnetmap.getVpnId(), ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (RuntimeException e) {
        LOG.error("{} onSubnetDeletedFromVpn: Unable to handle subnet {} with Ip {} removed from vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetmap.getSubnetIp(), subnetmap.getVpnId(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) PortOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)

Example 85 with Of

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.object.Of in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onPortAddedToSubnet.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onPortAddedToSubnet(Subnetmap subnetmap, Uuid portId) {
    Uuid subnetId = subnetmap.getId();
    LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.info("{} onPortAddedToSubnet: Port {} is part of a subnet {} that is not in VPN, ignoring", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
                return;
            }
            String vpnName = optionalSubs.get().getVpnName();
            String subnetIp = optionalSubs.get().getSubnetCidr();
            String rd = optionalSubs.get().getVrfId();
            String routeAdvState = optionalSubs.get().getRouteAdvState().toString();
            LOG.info("{} onPortAddedToSubnet: Port {} being added to subnet {} subnetIp {} vpnName {} rd {} " + "TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
            subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, null);
            Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, portId.getValue());
            if (intfState == null) {
                // Interface State not yet available
                return;
            }
            final BigInteger dpnId;
            try {
                dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
            } catch (Exception e) {
                LOG.error("{} onPortAddedToSubnet: Unable to obtain dpnId for interface {}. subnetroute inclusion" + " for this interface failed for subnet {} subnetIp {} vpn {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, e);
                return;
            }
            if (dpnId.equals(BigInteger.ZERO)) {
                LOG.error("{} onPortAddedToSubnet: Port {} is not assigned DPN yet, ignoring subnetRoute " + "inclusion for the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
                return;
            }
            subOpDpnManager.addPortOpDataEntry(portId.getValue(), subnetId, dpnId);
            if (intfState.getOperStatus() != OperStatus.Up) {
                LOG.error("{} onPortAddedToSubnet: Port {} is not UP yet, ignoring subnetRoute inclusion for " + "the interface into subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd);
                return;
            }
            LOG.debug("{} onPortAddedToSubnet: Port {} added. Updating the SubnetOpDataEntry node for subnet {} " + "subnetIp {} vpnName {} rd {} TaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subnetIp, vpnName, rd, routeAdvState);
            SubnetToDpn subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, portId.getValue());
            if (subDpn == null) {
                LOG.error("{} onPortAddedToSubnet: subnet-to-dpn list is null for subnetId {}. portId {}, " + "vpnName {}, rd {}, subnetIp {}", LOGGING_PREFIX, subnetId.getValue(), portId.getValue(), vpnName, rd, subnetIp);
                return;
            }
            SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
            List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
            subDpnList.add(subDpn);
            subOpBuilder.setSubnetToDpn(subDpnList);
            if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
                if (subOpBuilder.getNhDpnId() == null) {
                    // No nexthop selected yet, elect one now
                    electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
                    subnetId, subnetmap.getNetworkId(), true);
                } else if (!VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue())) {
                    // Already nexthop has been selected, only publishing to bgp required, so publish to bgp
                    getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
                }
            }
            SubnetOpDataEntry subOpEntry = subOpBuilder.build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
            LOG.info("{} onPortAddedToSubnet: Updated subnetopdataentry to OP Datastore for port {} subnet {}" + " subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpBuilder.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
        } catch (Exception ex) {
            LOG.error("{} onPortAddedToSubnet: Updation of subnetOpEntry for port {} subnet {} falied", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (Exception e) {
        LOG.error("{} onPortAddedToSubnet: Unable to handle port {} added to subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) BigInteger(java.math.BigInteger) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) Interface(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn)

Aggregations

ArrayList (java.util.ArrayList)300 Test (org.junit.Test)245 ByteBuf (io.netty.buffer.ByteBuf)224 BigInteger (java.math.BigInteger)110 Instruction (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)109 Action (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action)100 InstructionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder)100 InstructionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder)99 ActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder)98 ApplyActionsCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder)93 ApplyActionsBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder)91 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)89 SetVlanIdActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.vlan.id.action._case.SetVlanIdActionBuilder)85 GroupActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.group.action._case.GroupActionBuilder)83 DropActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropActionBuilder)82 ControllerActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.controller.action._case.ControllerActionBuilder)81 DropAction (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.drop.action._case.DropAction)81 PushMplsActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.mpls.action._case.PushMplsActionBuilder)81 PushPbbActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.pbb.action._case.PushPbbActionBuilder)81 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder)80