Search in sources :

Example 16 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class ElanServiceProvider method addEtreeInterface.

@Override
public void addEtreeInterface(String etreeInstanceName, String interfaceName, EtreeInterfaceType interfaceType, List<String> staticMacAddresses, String description) {
    Optional<ElanInstance> existingElanInstance = elanInstanceCache.get(etreeInstanceName);
    if (existingElanInstance.isPresent() && existingElanInstance.get().getAugmentation(EtreeInstance.class) != null) {
        EtreeInterface etreeInterface = new EtreeInterfaceBuilder().setEtreeInterfaceType(interfaceType).build();
        ElanInterface elanInterface;
        if (staticMacAddresses == null) {
            elanInterface = new ElanInterfaceBuilder().setElanInstanceName(etreeInstanceName).setDescription(description).setName(interfaceName).setKey(new ElanInterfaceKey(interfaceName)).addAugmentation(EtreeInterface.class, etreeInterface).build();
        } else {
            List<StaticMacEntries> staticMacEntries = ElanUtils.getStaticMacEntries(staticMacAddresses);
            elanInterface = new ElanInterfaceBuilder().setElanInstanceName(etreeInstanceName).setDescription(description).setName(interfaceName).setStaticMacEntries(staticMacEntries).setKey(new ElanInterfaceKey(interfaceName)).addAugmentation(EtreeInterface.class, etreeInterface).build();
        }
        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, ElanUtils.getElanInterfaceConfigurationDataPathId(interfaceName), elanInterface);
        LOG.debug("Creating the new Etree Interface {}", elanInterface);
    }
}
Also used : ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance) ElanInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface) EtreeInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInterface) ElanInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder) EtreeInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeInterfaceBuilder) StaticMacEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries) ElanInterfaceKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceKey)

Example 17 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class ElanSmacFlowEventListener method onFlowRemoved.

@Override
public void onFlowRemoved(FlowRemoved flowRemoved) {
    short tableId = flowRemoved.getTableId();
    if (tableId == NwConstants.ELAN_SMAC_TABLE) {
        BigInteger metadata = flowRemoved.getMatch().getMetadata().getMetadata();
        long elanTag = MetaDataUtil.getElanTagFromMetadata(metadata);
        ElanTagName elanTagInfo = elanUtils.getElanInfoByElanTag(elanTag);
        if (elanTagInfo == null) {
            return;
        }
        final String srcMacAddress = flowRemoved.getMatch().getEthernetMatch().getEthernetSource().getAddress().getValue().toUpperCase(Locale.getDefault());
        int portTag = MetaDataUtil.getLportFromMetadata(metadata).intValue();
        if (portTag == 0) {
            LOG.debug("Flow removed event on SMAC flow entry. But having port Tag as 0 ");
            return;
        }
        Optional<IfIndexInterface> existingInterfaceInfo = elanUtils.getInterfaceInfoByInterfaceTag(portTag);
        if (!existingInterfaceInfo.isPresent()) {
            LOG.debug("Interface is not available for port Tag {}", portTag);
            return;
        }
        String interfaceName = existingInterfaceInfo.get().getInterfaceName();
        PhysAddress physAddress = new PhysAddress(srcMacAddress);
        if (interfaceName == null) {
            LOG.error("LPort record not found for tag {}", portTag);
            return;
        }
        jobCoordinator.enqueueJob(ElanUtils.getElanInterfaceJobKey(interfaceName), () -> {
            List<ListenableFuture<Void>> elanFutures = new ArrayList<>();
            MacEntry macEntry = elanUtils.getInterfaceMacEntriesOperationalDataPath(interfaceName, physAddress);
            InterfaceInfo interfaceInfo = interfaceManager.getInterfaceInfo(interfaceName);
            String elanInstanceName = elanTagInfo.getName();
            LOG.info("Deleting the Mac-Entry:{} present on ElanInstance:{}", macEntry, elanInstanceName);
            if (macEntry != null && interfaceInfo != null) {
                ListenableFuture<Void> result = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> elanUtils.deleteMacFlows(elanInstanceCache.get(elanInstanceName).orNull(), interfaceInfo, macEntry, tx));
                elanFutures.add(result);
                addCallBack(result, srcMacAddress);
            }
            InstanceIdentifier<MacEntry> macEntryIdForElanInterface = ElanUtils.getInterfaceMacEntriesIdentifierOperationalDataPath(interfaceName, physAddress);
            Optional<MacEntry> existingInterfaceMacEntry = ElanUtils.read(broker, LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
            if (existingInterfaceMacEntry.isPresent()) {
                ListenableFuture<Void> future = txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
                    tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInterface);
                    MacEntry macEntryInElanInstance = elanUtils.getMacEntryForElanInstance(elanInstanceName, physAddress).orNull();
                    if (macEntryInElanInstance != null && macEntryInElanInstance.getInterface().equals(interfaceName)) {
                        InstanceIdentifier<MacEntry> macEntryIdForElanInstance = ElanUtils.getMacEntryOperationalDataPath(elanInstanceName, physAddress);
                        tx.delete(LogicalDatastoreType.OPERATIONAL, macEntryIdForElanInstance);
                    }
                });
                elanFutures.add(future);
                addCallBack(future, srcMacAddress);
            }
            return elanFutures;
        }, ElanConstants.JOB_MAX_RETRIES);
    }
}
Also used : ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) MacEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.forwarding.entries.MacEntry) IfIndexInterface(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface) ArrayList(java.util.ArrayList) BigInteger(java.math.BigInteger) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) InterfaceInfo(org.opendaylight.genius.interfacemanager.globals.InterfaceInfo) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)

Example 18 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class VpnElanInterfaceChangeListener method add.

@Override
protected void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
    String interfaceName = elanInterface.getName();
    if (!elanService.isExternalInterface(interfaceName)) {
        LOG.debug("add: Interface {} is not external. Ignoring", interfaceName);
        return;
    }
    Uuid networkId;
    try {
        networkId = new Uuid(elanInterface.getElanInstanceName());
    } catch (IllegalArgumentException e) {
        LOG.debug("add: ELAN instance {} for interface {} is not Uuid", elanInterface.getElanInstanceName(), elanInterface.getName());
        return;
    }
    Uuid vpnId = VpnUtil.getExternalNetworkVpnId(broker, networkId);
    if (vpnId == null) {
        LOG.debug("add: Network {} is not external or vpn-id missing. Ignoring interface {} on elan {}", networkId.getValue(), elanInterface.getName(), elanInterface.getElanInstanceName());
        return;
    }
    VpnInstanceNames vpnInstance = VpnHelper.getVpnInterfaceVpnInstanceNames(vpnId.getValue(), AssociatedSubnetType.V4AndV6Subnets);
    List<VpnInstanceNames> listVpn = new ArrayList<>();
    listVpn.add(vpnInstance);
    VpnInterface vpnInterface = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(interfaceName)).setVpnInstanceNames(listVpn).setScheduledForRemove(Boolean.FALSE).build();
    InstanceIdentifier<VpnInterface> vpnInterfaceIdentifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
    VpnUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, vpnInterfaceIdentifier, vpnInterface);
    LOG.info("add: Added VPN interface {} with VPN-id {} elanInstance {}", interfaceName, vpnId.getValue(), elanInterface.getElanInstanceName());
}
Also used : VpnInterfaceBuilder(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder) VpnInterfaceKey(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) ArrayList(java.util.ArrayList)

Example 19 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class VpnInterfaceManager method removeAdjacencyFromBgpvpn.

private void removeAdjacencyFromBgpvpn(Adjacency nextHop, List<String> nhList, String vpnName, String primaryRd, BigInteger dpnId, String rd, String interfaceName, WriteTransaction writeConfigTxn) {
    List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
    nhList.forEach((nh) -> {
        // IRT: remove routes from other vpns importing it
        vpnManager.removePrefixFromBGP(primaryRd, rd, vpnName, nextHop.getIpAddress(), nextHop.getNextHopIpList().get(0), nh, dpnId, writeConfigTxn);
        for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
            String vpnRd = vpn.getVrfId();
            if (vpnRd != null) {
                fibManager.removeOrUpdateFibEntry(vpnRd, nextHop.getIpAddress(), nh, writeConfigTxn);
                LOG.info("removeAdjacenciesFromVpn: Removed Exported route with rd {}" + " prefix {} nextHop {} from VPN {} parentVpn {}" + " for interface {} on dpn {}", vpnRd, nextHop.getIpAddress(), nh, vpn.getVpnInstanceName(), vpnName, interfaceName, dpnId);
            }
        }
    });
}
Also used : VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)

Example 20 with Interface

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface in project netvirt by opendaylight.

the class VpnInterfaceManager method updateVpnInterfaceOnTepAdd.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void updateVpnInterfaceOnTepAdd(VpnInterfaceOpDataEntry vpnInterface, StateTunnelList stateTunnelList, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn) {
    String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
    BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
    AdjacenciesOp adjacencies = vpnInterface.getAugmentation(AdjacenciesOp.class);
    List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency() : new ArrayList<>();
    if (adjList.isEmpty()) {
        LOG.trace("updateVpnInterfaceOnTepAdd: Adjacencies are empty for vpnInterface {} on dpn {}", vpnInterface, srcDpnId);
        return;
    }
    String prefix = null;
    long label = 0;
    List<Adjacency> value = new ArrayList<>();
    boolean isNextHopAddReqd = false;
    String vpnName = vpnInterface.getVpnInstanceName();
    long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
    String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
    LOG.info("updateVpnInterfaceOnTepAdd: AdjacencyList for interface {} on dpn {} vpn {} is {}", vpnInterface.getName(), vpnInterface.getDpnId(), vpnInterface.getVpnInstanceName(), adjList);
    for (Adjacency adj : adjList) {
        String rd = adj.getVrfId();
        rd = rd != null ? rd : vpnName;
        prefix = adj.getIpAddress();
        label = adj.getLabel();
        List<String> nhList = Collections.singletonList(srcTepIp);
        List<String> nextHopList = adj.getNextHopIpList();
        // Secondary adj nexthop is already pointing to primary adj IP address.
        if (nextHopList != null && !nextHopList.isEmpty() && nextHopList.get(0).equalsIgnoreCase(srcTepIp)) {
        /* everything right already */
        } else {
            isNextHopAddReqd = true;
        }
        if (adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            value.add(new AdjacencyBuilder(adj).setNextHopIpList(nhList).build());
        } else {
            Optional<VrfEntry> vrfEntryOptional = FibHelper.getVrfEntry(dataBroker, primaryRd, prefix);
            if (!vrfEntryOptional.isPresent()) {
                continue;
            }
            nhList = FibHelper.getNextHopListFromRoutePaths(vrfEntryOptional.get());
            if (!nhList.contains(srcTepIp)) {
                nhList.add(srcTepIp);
                isNextHopAddReqd = true;
            }
            value.add(adj);
        }
        if (isNextHopAddReqd) {
            updateLabelMapper(label, nhList);
            LOG.info("updateVpnInterfaceOnTepAdd: Updated label mapper : label {} dpn {} prefix {} nexthoplist {}" + " vpn {} vpnid {} rd {} interface {}", label, srcDpnId, prefix, nhList, vpnInterface.getVpnInstanceName(), vpnId, rd, vpnInterface.getName());
            // Update the VRF entry with nextHop
            fibManager.updateRoutePathForFibEntry(primaryRd, prefix, srcTepIp, label, true, writeConfigTxn);
            // Get the list of VPN's importing this route(prefix) .
            // Then update the VRF entry with nhList
            List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
            for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
                String vpnRd = vpn.getVrfId();
                if (vpnRd != null) {
                    fibManager.updateRoutePathForFibEntry(vpnRd, prefix, srcTepIp, label, true, writeConfigTxn);
                    LOG.info("updateVpnInterfaceOnTepAdd: Exported route with rd {} prefix {} nhList {} label {}" + " interface {} dpn {} from vpn {} to VPN {} vpnRd {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName, vpn.getVpnInstanceName(), vpnRd);
                }
            }
            // since there is a nexthop change.
            try {
                if (!rd.equalsIgnoreCase(vpnName)) {
                    bgpManager.advertisePrefix(rd, null, /*macAddress*/
                    prefix, nhList, VrfEntry.EncapType.Mplsgre, (int) label, 0, /*evi*/
                    0, /*l2vni*/
                    null);
                }
                LOG.info("updateVpnInterfaceOnTepAdd: Advertised rd {} prefix {} nhList {} label {}" + " for interface {} on dpn {} vpn {}", rd, prefix, nhList, label, vpnInterface.getName(), srcDpnId, vpnName);
            } catch (Exception ex) {
                LOG.error("updateVpnInterfaceOnTepAdd: Exception when advertising prefix {} nh {} label {}" + " on rd {} for interface {} on dpn {} vpn {}", prefix, nhList, label, rd, vpnInterface.getName(), srcDpnId, vpnName, ex);
            }
        }
    }
    AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
    VpnInterfaceOpDataEntry opInterface = new VpnInterfaceOpDataEntryBuilder(vpnInterface).setKey(new VpnInterfaceOpDataEntryKey(vpnInterface.getName(), vpnName)).addAugmentation(AdjacenciesOp.class, aug).build();
    InstanceIdentifier<VpnInterfaceOpDataEntry> interfaceId = VpnUtil.getVpnInterfaceOpDataEntryIdentifier(vpnInterface.getName(), vpnName);
    writeOperTxn.put(LogicalDatastoreType.OPERATIONAL, interfaceId, opInterface, WriteTransaction.CREATE_MISSING_PARENTS);
    LOG.info("updateVpnInterfaceOnTepAdd: interface {} updated successully on tep add on dpn {} vpn {}", vpnInterface.getName(), srcDpnId, vpnName);
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder) ArrayList(java.util.ArrayList) ExecutionException(java.util.concurrent.ExecutionException) VpnInterfaceOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryBuilder) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VpnInterfaceOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntryKey) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) BigInteger(java.math.BigInteger) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Aggregations

BigInteger (java.math.BigInteger)131 ArrayList (java.util.ArrayList)117 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface)69 ExecutionException (java.util.concurrent.ExecutionException)64 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)56 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)52 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)47 List (java.util.List)45 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)44 ParentRefs (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs)40 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)39 IfTunnel (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel)39 Logger (org.slf4j.Logger)39 LoggerFactory (org.slf4j.LoggerFactory)39 Collections (java.util.Collections)38 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)37 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)34 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)33 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)33 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)32