Search in sources :

Example 1 with EncapType

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType 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 EncapType

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.

the class BgpConfigurationManager method addPrefix.

public void addPrefix(String rd, String macAddress, String pfx, List<String> nhList, VrfEntry.EncapType encapType, long lbl, long l3vni, long l2vni, String gatewayMac) {
    for (String nh : nhList) {
        Ipv4Address nexthop = nh != null ? new Ipv4Address(nh) : null;
        Long label = lbl;
        InstanceIdentifier<Networks> iid = InstanceIdentifier.builder(Bgp.class).child(Networks.class, new NetworksKey(pfx, rd)).build();
        NetworksBuilder networksBuilder = new NetworksBuilder().setRd(rd).setPrefixLen(pfx).setNexthop(nexthop).setLabel(label).setEthtag(BgpConstants.DEFAULT_ETH_TAG);
        buildVpnEncapSpecificInfo(networksBuilder, encapType, label, l3vni, l2vni, macAddress, gatewayMac);
        update(iid, networksBuilder.build());
    }
}
Also used : Networks(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks) NetworksKey(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksKey) Ipv4Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address) NetworksBuilder(org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.NetworksBuilder)

Example 3 with EncapType

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.

the class VpnManagerImpl method addExtraRoute.

@Override
public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID, int label, RouteOrigin origin) {
    LOG.info("Adding extra route with destination {}, nextHop {}, label{} and origin {}", destination, nextHop, label, origin);
    VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, rd);
    Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
    VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
    addExtraRoute(vpnName, destination, nextHop, rd, routerID, vpnOpEntry.getL3vni(), origin, /*intfName*/
    null, null, /*Adjacency*/
    encapType, null);
}
Also used : 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)

Example 4 with EncapType

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method addSubnetRouteToFib.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private boolean addSubnetRouteToFib(String rd, String subnetIp, BigInteger nhDpnId, String nextHopIp, String vpnName, Long elanTag, long label, long l3vni, Uuid subnetId, boolean isBgpVpn, String networkName) {
    Preconditions.checkNotNull(rd, LOGGING_PREFIX + " addSubnetRouteToFib: RouteDistinguisher cannot be null or empty!");
    Preconditions.checkNotNull(subnetIp, LOGGING_PREFIX + " addSubnetRouteToFib: SubnetRouteIp cannot be null or empty!");
    Preconditions.checkNotNull(vpnName, LOGGING_PREFIX + " addSubnetRouteToFib: vpnName cannot be null or empty!");
    Preconditions.checkNotNull(elanTag, LOGGING_PREFIX + " addSubnetRouteToFib: elanTag cannot be null or empty!");
    Preconditions.checkNotNull(label, LOGGING_PREFIX + " addSubnetRouteToFib: label cannot be null or empty!");
    VrfEntry.EncapType encapType = VpnUtil.getEncapType(VpnUtil.isL3VpnOverVxLan(l3vni));
    VpnPopulator vpnPopulator = L3vpnRegistry.getRegisteredPopulator(encapType);
    LOG.info("{} addSubnetRouteToFib: Adding SubnetRoute fib entry for vpnName {}, subnetIP {}, elanTag {}", LOGGING_PREFIX, vpnName, subnetIp, elanTag);
    L3vpnInput input = new L3vpnInput().setRouteOrigin(RouteOrigin.CONNECTED).setRd(rd).setVpnName(vpnName).setSubnetIp(subnetIp).setNextHopIp(nextHopIp).setL3vni(l3vni).setLabel(label).setElanTag(elanTag).setDpnId(nhDpnId).setEncapType(encapType).setNetworkName(networkName).setPrimaryRd(rd);
    if (!isBgpVpn) {
        vpnPopulator.populateFib(input, null);
        return true;
    }
    Preconditions.checkNotNull(nextHopIp, LOGGING_PREFIX + "NextHopIp cannot be null or empty!");
    VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnUtil.getPrefixToInterfaceIdentifier(VpnUtil.getVpnId(dataBroker, vpnName), subnetIp), VpnUtil.getPrefixToInterface(nhDpnId, subnetId.getValue(), subnetIp, subnetId, Prefixes.PrefixCue.SubnetRoute));
    vpnPopulator.populateFib(input, null);
    try {
        // BGP manager will handle withdraw and advertise internally if prefix
        // already exist
        bgpManager.advertisePrefix(rd, null, /*macAddress*/
        subnetIp, Collections.singletonList(nextHopIp), encapType, label, l3vni, 0, /*l2vni*/
        null);
    } catch (Exception e) {
        LOG.error("{} addSubnetRouteToFib: Subnet route not advertised for subnet {} subnetIp {} vpnName {} rd {} " + "with dpnid {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, rd, nhDpnId, e);
        return false;
    }
    return true;
}
Also used : VrfEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry) VpnPopulator(org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)

Example 5 with EncapType

use of org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.EncapType in project netvirt by opendaylight.

the class L3vpnOverMplsGrePopulator method populateFib.

@Override
public void populateFib(L3vpnInput input, WriteTransaction writeConfigTxn) {
    if (input.getRouteOrigin() == RouteOrigin.CONNECTED) {
        LOG.info("populateFib : Found SubnetRoute for subnet {} rd {}", input.getSubnetIp(), input.getPrimaryRd());
        addSubnetRouteFibEntry(input);
        return;
    }
    Adjacency nextHop = input.getNextHop();
    long label = nextHop.getLabel();
    String vpnName = input.getVpnName();
    String primaryRd = input.getPrimaryRd();
    String rd = input.getRd();
    String nextHopIp = input.getNextHopIp();
    VrfEntry.EncapType encapType = input.getEncapType();
    LOG.info("populateFib : Found Interface Adjacency with prefix {} rd {}", nextHop.getIpAddress(), primaryRd);
    List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(broker, vpnName);
    long vpnId = VpnUtil.getVpnId(broker, vpnName);
    // it is a valid case for nextHopIpAddress to be null
    String nextHopIpAddress = nextHop.getIpAddress();
    // and internalVpnForExtraRoute (where rd is DpnId)
    if (VpnUtil.isEligibleForBgp(primaryRd, input.getVpnName(), input.getDpnId(), input.getNetworkName())) {
        // the DpnId is set as rd in case of extra routes present in router based VPN
        addToLabelMapper(label, input.getDpnId(), nextHopIpAddress, Arrays.asList(nextHopIp), vpnId, input.getInterfaceName(), null, false, primaryRd);
        Objects.requireNonNull(input.getRouteOrigin(), "RouteOrigin is mandatory");
        addPrefixToBGP(rd, primaryRd, null, /*macAddress*/
        nextHopIpAddress, nextHopIp, encapType, label, 0, /*l3vni*/
        input.getGatewayMac(), input.getRouteOrigin(), writeConfigTxn);
        // TODO: ERT - check for VPNs importing my route
        for (VpnInstanceOpDataEntry vpn : vpnsToImportRoute) {
            String vpnRd = vpn.getVrfId();
            if (vpnRd != null) {
                fibManager.addOrUpdateFibEntry(vpnRd, null, /*macAddress*/
                nextHopIpAddress, Arrays.asList(nextHopIp), encapType, (int) label, 0, /*l3vni*/
                input.getGatewayMac(), null, /*parentVpnRd*/
                RouteOrigin.SELF_IMPORTED, writeConfigTxn);
                LOG.info("populateFib: Exported route with rd {} prefix {} nexthop {} label {}" + " to VPN {} for interface {} on dpn {}", vpnRd, nextHop.getIpAddress(), nextHopIp, label, vpn, input.getInterfaceName(), input.getDpnId());
            }
        }
    } else {
        // ### add FIB route directly
        fibManager.addOrUpdateFibEntry(vpnName, null, /*macAddress*/
        nextHopIpAddress, Arrays.asList(nextHopIp), encapType, (int) label, 0, /*l3vni*/
        input.getGatewayMac(), null, /*parentVpnRd*/
        input.getRouteOrigin(), writeConfigTxn);
        LOG.info("populateFib: Added internal FIB entry for prefix {} nexthop {} label {}" + " to VPN {} for interface {} on dpn {}", nextHop.getIpAddress(), nextHopIp, label, vpnName, input.getInterfaceName(), input.getDpnId());
    }
}
Also used : 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) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

Aggregations

VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)10 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)7 ExecutionException (java.util.concurrent.ExecutionException)4 L3vpnInput (org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput)4 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)4 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)4 MacVrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntry)4 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)4 VpnPopulator (org.opendaylight.netvirt.vpnmanager.populator.intfc.VpnPopulator)3 Networks (org.opendaylight.yang.gen.v1.urn.ericsson.params.xml.ns.yang.ebgp.rev150901.bgp.Networks)3 MacVrfEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntryBuilder)3 MacVrfEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.macvrfentries.MacVrfEntryKey)3 AdjacenciesOp (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp)3 ArrayList (java.util.ArrayList)2 RouteOrigin (org.opendaylight.netvirt.fibmanager.api.RouteOrigin)2 InterVpnLinkDataComposite (org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)2 VrfEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryBuilder)2 VrfEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntryKey)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1