Search in sources :

Example 1 with RouteOrigin

use of org.opendaylight.netvirt.fibmanager.api.RouteOrigin in project netvirt by opendaylight.

the class VpnInterfaceManager method addNewAdjToVpnInterface.

protected void addNewAdjToVpnInterface(InstanceIdentifier<VpnInterfaceOpDataEntry> identifier, String primaryRd, Adjacency adj, BigInteger dpnId, WriteTransaction writeOperTxn, WriteTransaction writeConfigTxn) {
    Optional<VpnInterfaceOpDataEntry> optVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, identifier);
    if (optVpnInterface.isPresent()) {
        VpnInterfaceOpDataEntry currVpnIntf = optVpnInterface.get();
        String prefix = VpnUtil.getIpPrefix(adj.getIpAddress());
        String vpnName = currVpnIntf.getVpnInstanceName();
        VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
        InstanceIdentifier<AdjacenciesOp> adjPath = identifier.augmentation(AdjacenciesOp.class);
        Optional<AdjacenciesOp> optAdjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, adjPath);
        boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(vpnInstanceOpData.getL3vni());
        VrfEntry.EncapType encapType = VpnUtil.getEncapType(isL3VpnOverVxLan);
        long l3vni = vpnInstanceOpData.getL3vni() == null ? 0L : vpnInstanceOpData.getL3vni();
        VpnPopulator populator = L3vpnRegistry.getRegisteredPopulator(encapType);
        List<Adjacency> adjacencies;
        if (optAdjacencies.isPresent()) {
            adjacencies = optAdjacencies.get().getAdjacency();
        } else {
            // This code will be hit in case of first PNF adjacency
            adjacencies = new ArrayList<>();
        }
        long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
        L3vpnInput input = new L3vpnInput().setNextHop(adj).setVpnName(vpnName).setInterfaceName(currVpnIntf.getName()).setPrimaryRd(primaryRd).setRd(primaryRd);
        Adjacency operationalAdjacency = null;
        if (adj.getNextHopIpList() != null && !adj.getNextHopIpList().isEmpty()) {
            RouteOrigin origin = adj.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
            String nh = adj.getNextHopIpList().get(0);
            String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
            synchronized (vpnPrefixKey.intern()) {
                java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nh, dpnId);
                if (rdToAllocate.isPresent()) {
                    input.setRd(rdToAllocate.get());
                    operationalAdjacency = populator.createOperationalAdjacency(input);
                    int label = operationalAdjacency.getLabel().intValue();
                    vpnManager.addExtraRoute(vpnName, adj.getIpAddress(), nh, rdToAllocate.get(), currVpnIntf.getVpnInstanceName(), l3vni, origin, currVpnIntf.getName(), operationalAdjacency, encapType, writeConfigTxn);
                    LOG.info("addNewAdjToVpnInterface: Added extra route ip {} nh {} rd {} vpnname {} label {}" + " Interface {} on dpn {}", adj.getIpAddress(), nh, rdToAllocate.get(), vpnName, label, currVpnIntf.getName(), dpnId);
                } else {
                    LOG.error("addNewAdjToVpnInterface: No rds to allocate extraroute vpn {} prefix {}", vpnName, prefix);
                    return;
                }
                // Keeping the MPLS check for now.
                if (encapType.equals(VrfEntryBase.EncapType.Mplsgre)) {
                    final Adjacency opAdjacency = new AdjacencyBuilder(operationalAdjacency).build();
                    List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
                    vpnsToImportRoute.forEach(vpn -> {
                        if (vpn.getVrfId() != null) {
                            VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpn.getVpnId(), vpnId, prefix, VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), nh, dpnId).ifPresent(rds -> vpnManager.addExtraRoute(VpnUtil.getVpnName(dataBroker, vpn.getVpnId()), adj.getIpAddress(), nh, rds, currVpnIntf.getVpnInstanceName(), l3vni, RouteOrigin.SELF_IMPORTED, currVpnIntf.getName(), opAdjacency, encapType, writeConfigTxn));
                        }
                    });
                }
            }
        } else if (adj.isPhysNetworkFunc()) {
            // PNF adjacency.
            LOG.trace("addNewAdjToVpnInterface: Adding prefix {} to interface {} for vpn {}", prefix, currVpnIntf.getName(), vpnName);
            String parentVpnRd = getParentVpnRdForExternalSubnet(adj);
            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, adj.getSubnetId().getValue()), prefix), VpnUtil.getPrefixToInterface(BigInteger.ZERO, currVpnIntf.getName(), prefix, adj.getSubnetId(), Prefixes.PrefixCue.PhysNetFunc), true);
            fibManager.addOrUpdateFibEntry(adj.getSubnetId().getValue(), adj.getMacAddress(), adj.getIpAddress(), Collections.emptyList(), null, /* EncapType */
            0, /* label */
            0, /*l3vni*/
            null, /* gw-mac */
            parentVpnRd, RouteOrigin.LOCAL, writeConfigTxn);
            input.setRd(adj.getVrfId());
        }
        if (operationalAdjacency == null) {
            operationalAdjacency = populator.createOperationalAdjacency(input);
        }
        adjacencies.add(operationalAdjacency);
        AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(adjacencies);
        VpnInterfaceOpDataEntry newVpnIntf = VpnUtil.getVpnInterfaceOpDataEntry(currVpnIntf.getName(), currVpnIntf.getVpnInstanceName(), aug, dpnId, currVpnIntf.isScheduledForRemove(), currVpnIntf.getLportTag(), currVpnIntf.getGatewayMacAddress());
        writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, identifier, newVpnIntf, true);
    }
}
Also used : AdjacencyBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.AdjacencyBuilder) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) 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) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) 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) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)

Example 2 with RouteOrigin

use of org.opendaylight.netvirt.fibmanager.api.RouteOrigin in project netvirt by opendaylight.

the class VpnInterfaceManager method importSubnetRouteForNewVpn.

public synchronized void importSubnetRouteForNewVpn(String rd, String prefix, String nextHop, int label, SubnetRoute route, WriteTransaction writeConfigTxn) {
    RouteOrigin origin = RouteOrigin.SELF_IMPORTED;
    VrfEntry vrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, nextHop, origin, null).addAugmentation(SubnetRoute.class, route).build();
    List<VrfEntry> vrfEntryList = Collections.singletonList(vrfEntry);
    InstanceIdentifierBuilder<VrfTables> idBuilder = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
    InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
    VrfTables vrfTableNew = new VrfTablesBuilder().setRouteDistinguisher(rd).setVrfEntry(vrfEntryList).build();
    if (writeConfigTxn != null) {
        writeConfigTxn.merge(LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew, true);
    } else {
        VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew);
    }
    LOG.info("SUBNETROUTE: importSubnetRouteForNewVpn: Created vrfEntry for rd {} prefix {} nexthop {} label {}" + " and elantag {}", rd, prefix, nextHop, label, route.getElantag());
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) VrfTablesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesBuilder) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) SubnetRoute(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRoute) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin)

Example 3 with RouteOrigin

use of org.opendaylight.netvirt.fibmanager.api.RouteOrigin in project netvirt by opendaylight.

the class L3vpnPopulator method addSubnetRouteFibEntry.

public void addSubnetRouteFibEntry(L3vpnInput input) {
    String rd = input.getRd();
    String vpnName = input.getVpnName();
    String prefix = input.getSubnetIp();
    String nextHop = input.getNextHopIp();
    long label = input.getLabel();
    long l3vni = input.getL3vni();
    long elantag = input.getElanTag();
    BigInteger dpnId = input.getDpnId();
    String networkName = input.getNetworkName();
    String gwMacAddress = input.getGatewayMac();
    SubnetRoute route = new SubnetRouteBuilder().setElantag(elantag).build();
    // Only case when a route is considered as directly connected
    RouteOrigin origin = RouteOrigin.CONNECTED;
    VrfEntry vrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, nextHop, origin, networkName).addAugmentation(SubnetRoute.class, route).setL3vni(l3vni).setGatewayMacAddress(gwMacAddress).build();
    LOG.debug("Created vrfEntry for {} nexthop {} label {} and elantag {}", prefix, nextHop, label, elantag);
    InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
    Optional<VrfEntry> entry = MDSALUtil.read(broker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
    if (!entry.isPresent()) {
        List<VrfEntry> vrfEntryList = Collections.singletonList(vrfEntry);
        InstanceIdentifier.InstanceIdentifierBuilder<VrfTables> idBuilder = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd));
        InstanceIdentifier<VrfTables> vrfTableId = idBuilder.build();
        VrfTables vrfTableNew = new VrfTablesBuilder().setRouteDistinguisher(rd).setVrfEntry(vrfEntryList).build();
        VpnUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, vrfTableId, vrfTableNew);
        LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Added vrfEntry for {} nexthop {} label {} rd {}" + " vpnName {}", prefix, nextHop, label, rd, vpnName);
    } else {
        // Found in MDSAL database
        VpnUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, vrfEntryId, vrfEntry);
        LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Updated vrfEntry for {} nexthop {} label {} rd {}" + " vpnName {}", prefix, nextHop, label, rd, vpnName);
    }
    // Will be handled appropriately with the iRT patch for EVPN
    if (input.getEncapType().equals(VrfEntryBase.EncapType.Mplsgre)) {
        long vpnId = VpnUtil.getVpnId(broker, vpnName);
        addToLabelMapper(label, dpnId, prefix, Collections.singletonList(nextHop), vpnId, null, elantag, true, rd);
        List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(broker, vpnName);
        if (vpnsToImportRoute.size() > 0) {
            VrfEntry importingVrfEntry = FibHelper.getVrfEntryBuilder(prefix, label, nextHop, RouteOrigin.SELF_IMPORTED, networkName).addAugmentation(SubnetRoute.class, route).build();
            List<VrfEntry> importingVrfEntryList = Collections.singletonList(importingVrfEntry);
            for (VpnInstanceOpDataEntry vpnInstance : vpnsToImportRoute) {
                String importingRd = vpnInstance.getVrfId();
                InstanceIdentifier<VrfTables> importingVrfTableId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(importingRd)).build();
                VrfTables importingVrfTable = new VrfTablesBuilder().setRouteDistinguisher(importingRd).setVrfEntry(importingVrfEntryList).build();
                VpnUtil.syncUpdate(broker, LogicalDatastoreType.CONFIGURATION, importingVrfTableId, importingVrfTable);
                LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Exported route rd {} prefix {} nexthop {}" + " label {} to vpn {} importingRd {}", rd, prefix, nextHop, label, vpnInstance.getVpnInstanceName(), importingRd);
            }
        }
    }
    LOG.info("SUBNETROUTE: addSubnetRouteFibEntryToDS: Created vrfEntry for {} nexthop {} label {} and elantag {}" + "rd {} vpnName {}", prefix, nextHop, label, elantag, rd, vpnName);
}
Also used : VrfTablesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesBuilder) SubnetRoute(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRoute) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) SubnetRouteBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRouteBuilder) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) BigInteger(java.math.BigInteger) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Example 4 with RouteOrigin

use of org.opendaylight.netvirt.fibmanager.api.RouteOrigin in project netvirt by opendaylight.

the class VpnInterfaceManager method processVpnInterfaceAdjacencies.

@SuppressWarnings("checkstyle:IllegalCatch")
protected void processVpnInterfaceAdjacencies(BigInteger dpnId, final int lportTag, String vpnName, String primaryRd, String interfaceName, final long vpnId, WriteTransaction writeConfigTxn, WriteTransaction writeOperTxn, final WriteTransaction writeInvTxn, Interface interfaceState) {
    InstanceIdentifier<VpnInterface> identifier = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
    // Read NextHops
    InstanceIdentifier<Adjacencies> path = identifier.augmentation(Adjacencies.class);
    Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
    if (!adjacencies.isPresent()) {
        addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, null, /*adjacencies*/
        lportTag, null, /*gwMac*/
        writeOperTxn);
        return;
    }
    // Get the rd of the vpn instance
    String nextHopIp = null;
    try {
        nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
    } catch (Exception e) {
        LOG.error("processVpnInterfaceAdjacencies: Unable to retrieve endpoint ip address for " + "dpnId {} for vpnInterface {} vpnName {}", dpnId, interfaceName, vpnName);
    }
    List<String> nhList = new ArrayList<>();
    if (nextHopIp != null) {
        nhList.add(nextHopIp);
        LOG.debug("processVpnInterfaceAdjacencies: NextHop for interface {} on dpn {} in vpn {} is {}", interfaceName, dpnId, vpnName, nhList);
    }
    Optional<String> gwMac = Optional.absent();
    String vpnInterfaceSubnetGwMacAddress = null;
    VpnInstanceOpDataEntry vpnInstanceOpData = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd);
    Long l3vni = vpnInstanceOpData.getL3vni();
    boolean isL3VpnOverVxLan = VpnUtil.isL3VpnOverVxLan(l3vni);
    VrfEntry.EncapType encapType = isL3VpnOverVxLan ? VrfEntry.EncapType.Vxlan : VrfEntry.EncapType.Mplsgre;
    VpnPopulator registeredPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
    List<Adjacency> nextHops = adjacencies.get().getAdjacency();
    List<Adjacency> value = new ArrayList<>();
    for (Adjacency nextHop : nextHops) {
        String rd = primaryRd;
        String nexthopIpValue = nextHop.getIpAddress().split("/")[0];
        if (vpnInstanceOpData.getBgpvpnType() == VpnInstanceOpDataEntry.BgpvpnType.BGPVPNInternet && NWUtil.isIpv4Address(nexthopIpValue)) {
            String prefix = nextHop.getIpAddress() == null ? "null" : VpnUtil.getIpPrefix(nextHop.getIpAddress());
            LOG.debug("processVpnInterfaceAdjacencies: UnsupportedOperation : Not Adding prefix {} to interface {}" + " as InternetVpn has an IPV4 address {}", prefix, interfaceName, vpnName);
            continue;
        }
        if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
            Prefixes.PrefixCue prefixCue = nextHop.isPhysNetworkFunc() ? Prefixes.PrefixCue.PhysNetFunc : Prefixes.PrefixCue.None;
            LOG.debug("processVpnInterfaceAdjacencies: Adding prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
            writeOperTxn.merge(LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), prefix), VpnUtil.getPrefixToInterface(dpnId, interfaceName, prefix, nextHop.getSubnetId(), prefixCue), true);
            final Uuid subnetId = nextHop.getSubnetId();
            String gatewayIp = nextHop.getSubnetGatewayIp();
            if (gatewayIp == null) {
                Optional<String> gatewayIpOptional = VpnUtil.getVpnSubnetGatewayIp(dataBroker, subnetId);
                if (gatewayIpOptional.isPresent()) {
                    gatewayIp = gatewayIpOptional.get();
                }
            }
            if (gatewayIp != null) {
                gwMac = getMacAddressForSubnetIp(vpnName, interfaceName, gatewayIp);
                if (gwMac.isPresent()) {
                    // A valid mac-address is available for this subnet-gateway-ip
                    // Use this for programming ARP_RESPONDER table here.  And save this
                    // info into vpnInterface operational, so it can used in VrfEntryProcessor
                    // to populate L3_GW_MAC_TABLE there.
                    arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
                    vpnInterfaceSubnetGwMacAddress = gwMac.get();
                } else {
                    // A valid mac-address is not available for this subnet-gateway-ip
                    // Use the connected-mac-address to configure ARP_RESPONDER Table.
                    // Save this connected-mac-address as gateway-mac-address for the
                    // VrfEntryProcessor to use this later to populate the L3_GW_MAC_TABLE.
                    gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
                    if (gwMac.isPresent()) {
                        VpnUtil.setupGwMacIfExternalVpn(dataBroker, mdsalManager, dpnId, interfaceName, vpnId, writeInvTxn, NwConstants.ADD_FLOW, gwMac.get());
                        arpResponderHandler.addArpResponderFlow(dpnId, lportTag, interfaceName, gatewayIp, gwMac.get());
                    } else {
                        LOG.error("processVpnInterfaceAdjacencies: Gateway MAC for subnet ID {} could not be " + "obtained, cannot create ARP responder flow for interface name {}, vpnName {}, " + "gwIp {}", subnetId, interfaceName, vpnName, gatewayIp);
                    }
                }
            } else {
                LOG.warn("processVpnInterfaceAdjacencies: Gateway IP for subnet ID {} could not be obtained, " + "cannot create ARP responder flow for interface name {}, vpnName {}", subnetId, interfaceName, vpnName);
                gwMac = InterfaceUtils.getMacAddressFromInterfaceState(interfaceState);
            }
            LOG.info("processVpnInterfaceAdjacencies: Added prefix {} to interface {} with nextHops {} on dpn {}" + " for vpn {}", prefix, interfaceName, nhList, dpnId, vpnName);
        } else {
            // Extra route adjacency
            String prefix = VpnUtil.getIpPrefix(nextHop.getIpAddress());
            String vpnPrefixKey = VpnUtil.getVpnNamePrefixKey(vpnName, prefix);
            synchronized (vpnPrefixKey.intern()) {
                java.util.Optional<String> rdToAllocate = VpnUtil.allocateRdForExtraRouteAndUpdateUsedRdsMap(dataBroker, vpnId, null, prefix, vpnName, nextHop.getNextHopIpList().get(0), dpnId);
                if (rdToAllocate.isPresent()) {
                    rd = rdToAllocate.get();
                    LOG.info("processVpnInterfaceAdjacencies: The rd {} is allocated for the extraroute {}", rd, prefix);
                } else {
                    LOG.error("processVpnInterfaceAdjacencies: No rds to allocate extraroute {}", prefix);
                    continue;
                }
            }
            LOG.info("processVpnInterfaceAdjacencies: Added prefix {} and nextHopList {} as extra-route for vpn{}" + " interface {} on dpn {}", nextHop.getIpAddress(), nextHop.getNextHopIpList(), vpnName, interfaceName, dpnId);
        }
        // Please note that primary adjacency will use a subnet-gateway-mac-address that
        // can be different from the gateway-mac-address within the VRFEntry as the
        // gateway-mac-address is a superset.
        RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
        L3vpnInput input = new L3vpnInput().setNextHop(nextHop).setRd(rd).setVpnName(vpnName).setInterfaceName(interfaceName).setNextHopIp(nextHopIp).setPrimaryRd(primaryRd).setSubnetGatewayMacAddress(vpnInterfaceSubnetGwMacAddress).setRouteOrigin(origin);
        Adjacency operationalAdjacency = null;
        try {
            operationalAdjacency = registeredPopulator.createOperationalAdjacency(input);
        } catch (NullPointerException e) {
            LOG.error("processVpnInterfaceAdjacencies: failed to create operational adjacency: input: {}, {}", input, e.getMessage());
            return;
        }
        if (nextHop.getAdjacencyType() != AdjacencyType.PrimaryAdjacency) {
            vpnManager.addExtraRoute(vpnName, nextHop.getIpAddress(), nextHop.getNextHopIpList().get(0), rd, vpnName, l3vni, origin, interfaceName, operationalAdjacency, encapType, writeConfigTxn);
        }
        value.add(operationalAdjacency);
    }
    AdjacenciesOp aug = VpnUtil.getVpnInterfaceOpDataEntryAugmentation(value);
    addVpnInterfaceToOperational(vpnName, interfaceName, dpnId, aug, lportTag, gwMac.isPresent() ? gwMac.get() : null, writeOperTxn);
    L3vpnInput input = new L3vpnInput().setNextHopIp(nextHopIp).setL3vni(l3vni).setPrimaryRd(primaryRd).setGatewayMac(gwMac.orNull()).setInterfaceName(interfaceName).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType);
    for (Adjacency nextHop : aug.getAdjacency()) {
        // Adjacencies other than primary Adjacencies are handled in the addExtraRoute call above.
        if (nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
            RouteOrigin origin = nextHop.getAdjacencyType() == AdjacencyType.PrimaryAdjacency ? RouteOrigin.LOCAL : RouteOrigin.STATIC;
            input.setNextHop(nextHop).setRd(nextHop.getVrfId()).setRouteOrigin(origin);
            registeredPopulator.populateFib(input, writeConfigTxn);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) Prefixes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes) Adjacencies(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.Adjacencies) ExecutionException(java.util.concurrent.ExecutionException) 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) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInterface(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)

Example 5 with RouteOrigin

use of org.opendaylight.netvirt.fibmanager.api.RouteOrigin in project netvirt by opendaylight.

the class IVpnLinkServiceImpl method leakRoute.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public void leakRoute(InterVpnLinkDataComposite interVpnLink, String srcVpnUuid, String dstVpnUuid, String prefix, Long label, RouteOrigin forcedOrigin) {
    String ivpnLinkName = interVpnLink.getInterVpnLinkName();
    // The source VPN must participate in the InterVpnLink
    Preconditions.checkArgument(interVpnLink.isVpnLinked(srcVpnUuid), "The source VPN {} does not participate in the interVpnLink {}", srcVpnUuid, ivpnLinkName);
    // The destination VPN must participate in the InterVpnLink
    Preconditions.checkArgument(interVpnLink.isVpnLinked(dstVpnUuid), "The destination VPN {} does not participate in the interVpnLink {}", dstVpnUuid, ivpnLinkName);
    String endpointIp = interVpnLink.getOtherEndpointIpAddr(dstVpnUuid);
    String leakedOrigin = forcedOrigin != null ? forcedOrigin.getValue() : RouteOrigin.INTERVPN.getValue();
    FibHelper.buildRoutePath(endpointIp, label);
    VrfEntry newVrfEntry = new VrfEntryBuilder().setKey(new VrfEntryKey(prefix)).setDestPrefix(prefix).setRoutePaths(Collections.singletonList(FibHelper.buildRoutePath(endpointIp, label))).setOrigin(leakedOrigin).build();
    String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
    InstanceIdentifier<VrfEntry> newVrfEntryIid = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(dstVpnRd)).child(VrfEntry.class, new VrfEntryKey(newVrfEntry.getDestPrefix())).build();
    VpnUtil.asyncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, newVrfEntryIid, newVrfEntry);
    // Finally, route is advertised it to the DC-GW. But while in the FibEntries the nexthop is the other
    // endpoint's IP, in the DC-GW the nexthop for those prefixes are the IPs of those DPNs where the target
    // VPN has been instantiated
    List<BigInteger> srcDpnList = interVpnLink.getEndpointDpnsByVpnName(srcVpnUuid);
    List<String> nexthops = srcDpnList.stream().map(dpnId -> InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId)).collect(Collectors.toList());
    LOG.debug("Advertising route in VPN={} [prefix={} label={}  nexthops={}] to DC-GW", dstVpnRd, newVrfEntry.getDestPrefix(), label.intValue(), nexthops);
    try {
        bgpManager.advertisePrefix(dstVpnRd, null, /*macAddress*/
        prefix, nexthops, VrfEntry.EncapType.Mplsgre, label.intValue(), 0, /*l3vni*/
        0, /*l2vni*/
        null);
    } catch (Exception e) {
        LOG.error("Exception while advertising prefix {} on vpnRd {} for intervpn link", prefix, dstVpnRd, e);
    }
}
Also used : IFibManager(org.opendaylight.netvirt.fibmanager.api.IFibManager) VpnUtil(org.opendaylight.netvirt.vpnmanager.VpnUtil) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) Singleton(javax.inject.Singleton) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PreDestroy(javax.annotation.PreDestroy) InterVpnLinkCache(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkCache) InterfaceUtils(org.opendaylight.netvirt.vpnmanager.api.InterfaceUtils) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite) Optional(com.google.common.base.Optional) VpnConstants(org.opendaylight.netvirt.vpnmanager.VpnConstants) Map(java.util.Map) IBgpManager(org.opendaylight.netvirt.bgpmanager.api.IBgpManager) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) IVpnLinkService(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.IVpnLinkService) VpnMaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.VpnMaps) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) RouteOrigin(org.opendaylight.netvirt.fibmanager.api.RouteOrigin) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) VrfTables(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) Collectors(java.util.stream.Collectors) IdManagerService(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) VrfEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder) PostConstruct(javax.annotation.PostConstruct) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Preconditions(com.google.common.base.Preconditions) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey) Collections(java.util.Collections) FibHelper(org.opendaylight.netvirt.fibmanager.api.FibHelper) VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VrfTablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey) FibEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries) BigInteger(java.math.BigInteger) VrfEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder) VrfEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey)

Aggregations

RouteOrigin (org.opendaylight.netvirt.fibmanager.api.RouteOrigin)5 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)5 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)3 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)3 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)3 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 L3vpnInput (org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)2 VpnPopulator (org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator)2 SubnetRoute (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.SubnetRoute)2 VrfTablesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesBuilder)2 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)2 Optional (com.google.common.base.Optional)1 Preconditions (com.google.common.base.Preconditions)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 Predicate (java.util.function.Predicate)1