Search in sources :

Example 26 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project bgpcep by opendaylight.

the class AddPathAbstractRouteEntry method fillAdjRibsOut.

@SuppressWarnings("unchecked")
private void fillAdjRibsOut(final boolean isFirstBestPath, final Attributes attributes, final Route routeNonAddPath, final Route routeAddPath, final Identifier routeKeyAddNonPath, final Identifier routeKeyAddPath, final PeerId fromPeerId, final TablesKey localTK, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
    /*
         * We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
         * expose from which client a particular route was learned from in the local RIB, and have
         * the listener perform filtering.
         *
         * We walk the policy set in order to minimize the amount of work we do for multiple peers:
         * if we have two eBGP peers, for example, there is no reason why we should perform the translation
         * multiple times.
         */
    final RIBSupport ribSupport = routeEntryDep.getRibSupport();
    for (final Peer toPeer : this.peerTracker.getPeers()) {
        if (!filterRoutes(fromPeerId, toPeer, localTK)) {
            continue;
        }
        final boolean destPeerSupAddPath = toPeer.supportsAddPathSupported(localTK);
        if (toPeer.getPeerId().getValue().equals("bgp://127.0.0.5")) {
            LOG.debug("Write route {} to peer AdjRibsOut {}", toPeer.getPeerId());
        }
        if (peersSupportsAddPathOrIsFirstBestPath(destPeerSupAddPath, isFirstBestPath)) {
            Optional<Attributes> effAttrib = Optional.empty();
            final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
            if (fromPeer != null && attributes != null) {
                final BGPRouteEntryExportParameters baseExp = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
                effAttrib = routeEntryDep.getRoutingPolicies().applyExportPolicies(baseExp, attributes);
            }
            Route newRoute = null;
            InstanceIdentifier ribOutRoute = null;
            if (destPeerSupAddPath) {
                newRoute = routeAddPath;
                ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddPath);
            } else if (!this.oldNonAddPathBestPathTheSame) {
                ribOutRoute = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKeyAddNonPath);
                newRoute = routeNonAddPath;
            }
            if (effAttrib.isPresent() && newRoute != null) {
                LOG.debug("Write route {} to peer AdjRibsOut {}", newRoute, toPeer.getPeerId());
                tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute, newRoute);
                tx.put(LogicalDatastoreType.OPERATIONAL, ribOutRoute.child(Attributes.class), effAttrib.get());
            } else if (ribOutRoute != null) {
                LOG.trace("Removing {} from transaction for peer {}", ribOutRoute, toPeer.getPeerId());
                tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutRoute);
            }
        }
    }
}
Also used : RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPRouteEntryExportParametersImpl(org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) Route(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route)

Example 27 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project bgpcep by opendaylight.

the class BaseAbstractRouteEntry method fillAdjRibsOut.

@VisibleForTesting
@SuppressWarnings("unchecked")
private void fillAdjRibsOut(@Nullable final Attributes attributes, @Nullable final Route route, final Identifier routeKey, final PeerId fromPeerId, final RouteEntryDependenciesContainer routeEntryDep, final WriteTransaction tx) {
    /*
         * We need to keep track of routers and populate adj-ribs-out, too. If we do not, we need to
         * expose from which client a particular route was learned from in the local RIB, and have
         * the listener perform filtering.
         *
         * We walk the policy set in order to minimize the amount of work we do for multiple peers:
         * if we have two eBGP peers, for example, there is no reason why we should perform the translation
         * multiple times.
         */
    final TablesKey localTK = routeEntryDep.getLocalTablesKey();
    final BGPRibRoutingPolicy routingPolicies = routeEntryDep.getRoutingPolicies();
    final RIBSupport ribSupport = routeEntryDep.getRibSupport();
    for (final Peer toPeer : this.peerTracker.getPeers()) {
        if (!filterRoutes(fromPeerId, toPeer, localTK)) {
            continue;
        }
        Optional<Attributes> effAttr = Optional.empty();
        final Peer fromPeer = this.peerTracker.getPeer(fromPeerId);
        if (fromPeer != null && attributes != null) {
            final BGPRouteEntryExportParameters routeEntry = new BGPRouteEntryExportParametersImpl(fromPeer, toPeer);
            effAttr = routingPolicies.applyExportPolicies(routeEntry, attributes);
        }
        final InstanceIdentifier ribOutTarget = ribSupport.createRouteIdentifier(toPeer.getRibOutIId(localTK), routeKey);
        if (effAttr.isPresent() && route != null) {
            LOG.debug("Write route {} to peer AdjRibsOut {}", route, toPeer.getPeerId());
            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget, route);
            tx.put(LogicalDatastoreType.OPERATIONAL, ribOutTarget.child(Attributes.class), effAttr.get());
        } else {
            LOG.trace("Removing {} from transaction for peer {}", ribOutTarget, toPeer.getPeerId());
            tx.delete(LogicalDatastoreType.OPERATIONAL, ribOutTarget);
        }
    }
}
Also used : BGPRibRoutingPolicy(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy) TablesKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey) RIBSupport(org.opendaylight.protocol.bgp.rib.spi.RIBSupport) Peer(org.opendaylight.protocol.bgp.rib.spi.Peer) Attributes(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) KeyedInstanceIdentifier(org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier) BGPRouteEntryExportParametersImpl(org.opendaylight.protocol.bgp.mode.impl.BGPRouteEntryExportParametersImpl) BGPRouteEntryExportParameters(org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 28 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class VpnInterfaceManager method processExternalVpnInterface.

private void processExternalVpnInterface(String interfaceName, String vpnName, long vpnId, BigInteger dpId, int lportTag, WriteTransaction writeInvTxn, int addOrRemove) {
    Uuid extNetworkId;
    try {
        // vpn instance of ext-net interface is the network-id
        extNetworkId = new Uuid(vpnName);
    } catch (IllegalArgumentException e) {
        LOG.error("processExternalVpnInterface: VPN instance {} is not Uuid. Processing external vpn interface {}" + " on dpn {} failed", vpnName, interfaceName, dpId);
        return;
    }
    List<Uuid> routerIds = VpnUtil.getExternalNetworkRouterIds(dataBroker, extNetworkId);
    if (routerIds == null || routerIds.isEmpty()) {
        LOG.info("processExternalVpnInterface: No router is associated with {}." + " Bailing out of processing external vpn interface {} on dpn {} for vpn {}", extNetworkId.getValue(), interfaceName, dpId, vpnName);
        return;
    }
    LOG.info("processExternalVpnInterface: Router-ids {} associated with exernal vpn-interface {} on dpn {}" + " for vpn {}", routerIds, interfaceName, dpId, vpnName);
    for (Uuid routerId : routerIds) {
        String routerName = routerId.getValue();
        BigInteger primarySwitch = VpnUtil.getPrimarySwitchForRouter(dataBroker, routerName);
        if (Objects.equals(primarySwitch, dpId)) {
            Routers router = VpnUtil.getExternalRouter(dataBroker, routerName);
            if (router != null) {
                if (addOrRemove == NwConstants.ADD_FLOW) {
                    vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), router.getExtGwMacAddress(), dpId, interfaceName, lportTag, writeInvTxn);
                } else {
                    vpnManager.removeArpResponderFlowsToExternalNetworkIps(routerName, VpnUtil.getIpsListFromExternalIps(router.getExternalIps()), dpId, interfaceName, lportTag);
                }
            } else {
                LOG.error("processExternalVpnInterface: No external-router found for router-id {}. Bailing out of" + " processing external vpn-interface {} on dpn {} for vpn {}", routerName, interfaceName, dpId, vpnName);
            }
        }
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) BigInteger(java.math.BigInteger)

Example 29 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class VpnUtil method getAssociatedExternalRouter.

public static String getAssociatedExternalRouter(DataBroker dataBroker, String extIp) {
    InstanceIdentifier<ExtRouters> extRouterInstanceIndentifier = InstanceIdentifier.builder(ExtRouters.class).build();
    Optional<ExtRouters> extRouterData = read(dataBroker, LogicalDatastoreType.CONFIGURATION, extRouterInstanceIndentifier);
    if (extRouterData.isPresent()) {
        for (Routers routerData : extRouterData.get().getRouters()) {
            List<ExternalIps> externalIps = routerData.getExternalIps();
            for (ExternalIps externalIp : externalIps) {
                if (externalIp.getIpAddress().equals(extIp)) {
                    return routerData.getRouterName();
                }
            }
        }
    }
    return null;
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters) ExternalIps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)

Example 30 with Routers

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers in project netvirt by opendaylight.

the class VpnUtil method getAssociatedExternalNetwork.

static String getAssociatedExternalNetwork(DataBroker dataBroker, String routerId) {
    InstanceIdentifier<Routers> id = buildRouterIdentifier(routerId);
    Optional<Routers> routerData = read(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
    if (routerData.isPresent()) {
        Uuid networkId = routerData.get().getNetworkId();
        if (networkId != null) {
            return networkId.getValue();
        }
    }
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers) ExtRouters(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)33 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)26 BigInteger (java.math.BigInteger)22 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)16 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)12 ArrayList (java.util.ArrayList)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)7 UnknownHostException (java.net.UnknownHostException)6 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 RoutersBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.RoutersBuilder)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)5 InetAddress (java.net.InetAddress)4 List (java.util.List)4 ExtRouters (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExtRouters)4 IpPortMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMapping)4 IntextIpProtocolType (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType)4 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)3