Search in sources :

Example 36 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route 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 37 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method deleteSubnetRouteFibEntryFromDS.

public void deleteSubnetRouteFibEntryFromDS(String rd, String prefix, String vpnName) {
    fibManager.removeFibEntry(rd, prefix, null);
    List<VpnInstanceOpDataEntry> vpnsToImportRoute = VpnUtil.getVpnsImportingMyRoute(dataBroker, vpnName);
    for (VpnInstanceOpDataEntry vpnInstance : vpnsToImportRoute) {
        String importingRd = vpnInstance.getVrfId();
        fibManager.removeFibEntry(importingRd, prefix, null);
        LOG.info("SUBNETROUTE: deleteSubnetRouteFibEntryFromDS: Deleted imported subnet route rd {} prefix {}" + " from vpn {} importingRd {}", rd, prefix, vpnInstance.getVpnInstanceName(), importingRd);
    }
    LOG.info("SUBNETROUTE: deleteSubnetRouteFibEntryFromDS: Removed subnetroute FIB for prefix {} rd {}" + " vpnName {}", prefix, rd, vpnName);
}
Also used : VpnInstanceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)

Example 38 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route 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 39 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route 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 40 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route 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

ArrayList (java.util.ArrayList)46 BigInteger (java.math.BigInteger)38 Test (org.junit.Test)35 VpnInstanceOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.VpnInstanceOpDataEntry)31 VrfEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.vrfentries.VrfEntry)28 AbstractRIBSupportTest (org.opendaylight.protocol.bgp.rib.spi.AbstractRIBSupportTest)22 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)21 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)21 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)20 Route (okhttp3.Route)19 ExecutionException (java.util.concurrent.ExecutionException)17 VrfTablesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTablesKey)16 Adjacency (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)14 List (java.util.List)13 RouteOrigin (org.opendaylight.netvirt.fibmanager.api.RouteOrigin)13 Routes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes)13 VrfTables (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.fibentries.VrfTables)12 Prefixes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.vpn.ids.Prefixes)12 InetAddress (java.net.InetAddress)11 FibEntries (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.fibmanager.rev150330.FibEntries)11