Search in sources :

Example 91 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.

the class VpnManagerImpl method addExtraRoute.

@Override
public void addExtraRoute(String vpnName, String destination, String nextHop, String rd, String routerID, Long l3vni, RouteOrigin origin, String intfName, Adjacency operationalAdj, VrfEntry.EncapType encapType, WriteTransaction writeConfigTxn) {
    Boolean writeConfigTxnPresent = true;
    if (writeConfigTxn == null) {
        writeConfigTxnPresent = false;
        writeConfigTxn = dataBroker.newWriteOnlyTransaction();
    }
    // add extra route to vpn mapping; advertise with nexthop as tunnel ip
    VpnUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, VpnExtraRouteHelper.getVpnToExtrarouteVrfIdIdentifier(vpnName, rd != null ? rd : routerID, destination), VpnUtil.getVpnToExtraroute(destination, Collections.singletonList(nextHop)));
    BigInteger dpnId = null;
    if (intfName != null && !intfName.isEmpty()) {
        dpnId = InterfaceUtils.getDpnForInterface(ifaceMgrRpcService, intfName);
        String nextHopIp = InterfaceUtils.getEndpointIpAddressForDPN(dataBroker, dpnId);
        if (nextHopIp == null || nextHopIp.isEmpty()) {
            LOG.error("addExtraRoute: NextHop for interface {} is null / empty." + " Failed advertising extra route for rd {} prefix {} dpn {}", intfName, rd, destination, dpnId);
            return;
        }
        nextHop = nextHopIp;
    }
    String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
    // TODO: This is a limitation to be stated in docs. When configuring static route to go to
    // another VPN, there can only be one nexthop or, at least, the nexthop to the interVpnLink should be in
    // first place.
    Optional<InterVpnLinkDataComposite> optVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nextHop);
    if (optVpnLink.isPresent() && optVpnLink.get().isActive()) {
        InterVpnLinkDataComposite interVpnLink = optVpnLink.get();
        // If the nexthop is the endpoint of Vpn2, then prefix must be advertised to Vpn1 in DC-GW, with nexthops
        // pointing to the DPNs where Vpn1 is instantiated. LFIB in these DPNS must have a flow entry, with lower
        // priority, where if Label matches then sets the lportTag of the Vpn2 endpoint and goes to LportDispatcher
        // This is like leaking one of the Vpn2 routes towards Vpn1
        String srcVpnUuid = interVpnLink.getVpnNameByIpAddress(nextHop);
        String dstVpnUuid = interVpnLink.getOtherVpnNameByIpAddress(nextHop);
        String dstVpnRd = VpnUtil.getVpnRd(dataBroker, dstVpnUuid);
        long newLabel = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(dstVpnRd, destination));
        if (newLabel == 0) {
            LOG.error("addExtraRoute: Unable to fetch label from Id Manager. Bailing out of adding intervpnlink" + " route for destination {}", destination);
            return;
        }
        ivpnLinkService.leakRoute(interVpnLink, srcVpnUuid, dstVpnUuid, destination, newLabel, RouteOrigin.STATIC);
    } else {
        Optional<Routes> optVpnExtraRoutes = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, rd != null ? rd : routerID, destination);
        if (optVpnExtraRoutes.isPresent()) {
            List<String> nhList = optVpnExtraRoutes.get().getNexthopIpList();
            if (nhList != null && nhList.size() > 1) {
                // If nhList is greater than one for vpnextraroute, a call to populatefib doesn't update vrfentry.
                fibManager.refreshVrfEntry(primaryRd, destination);
            } else {
                L3vpnInput input = new L3vpnInput().setNextHop(operationalAdj).setNextHopIp(nextHop).setL3vni(l3vni).setPrimaryRd(primaryRd).setVpnName(vpnName).setDpnId(dpnId).setEncapType(encapType).setRd(rd).setRouteOrigin(origin);
                L3vpnRegistry.getRegisteredPopulator(encapType).populateFib(input, writeConfigTxn);
            }
        }
    }
    if (!writeConfigTxnPresent) {
        writeConfigTxn.submit();
    }
}
Also used : BigInteger(java.math.BigInteger) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.to.extraroutes.vpn.extra.routes.Routes) L3vpnInput(org.opendaylight.netvirt.vpnmanager.populator.input.L3vpnInput) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 92 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId 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)

Example 93 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.

the class IVpnLinkServiceImpl method handleStaticRoutes.

@Override
public void handleStaticRoutes(InterVpnLinkDataComposite ivpnLink) {
    /*
         * Checks if there are any static routes pointing to any of both
         * InterVpnLink's endpoints. Goes through all routers checking if they have
         * a route whose nexthop is an InterVpnLink endpoint
         */
    // Map that corresponds a routerId with the L3VPN that it's been assigned to.
    Map<String, String> routerXL3VpnMap = buildRouterXL3VPNMap();
    // Retrieving all Routers
    InstanceIdentifier<Routers> routersIid = InstanceIdentifier.builder(Neutron.class).child(Routers.class).build();
    Optional<Routers> routerOpData = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routersIid);
    if (!routerOpData.isPresent()) {
        return;
    }
    List<Router> routers = routerOpData.get().getRouter();
    for (Router router : routers) {
        String vpnId = routerXL3VpnMap.get(router.getUuid().getValue());
        if (vpnId == null) {
            LOG.warn("Could not find suitable VPN for router {}", router.getUuid());
            // with next router
            continue;
        }
        List<Routes> routerRoutes = router.getRoutes();
        if (routerRoutes != null) {
            for (Routes route : routerRoutes) {
                handleStaticRoute(vpnId, route, ivpnLink);
            }
        }
    }
}
Also used : Routers(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.Routers) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)

Example 94 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.

the class VpnRpcServiceImpl method addStaticRoute.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Future<RpcResult<AddStaticRouteOutput>> addStaticRoute(AddStaticRouteInput input) {
    SettableFuture<RpcResult<AddStaticRouteOutput>> result = SettableFuture.create();
    String destination = input.getDestination();
    String vpnInstanceName = input.getVpnInstanceName();
    String nexthop = input.getNexthop();
    Long label = input.getLabel();
    LOG.info("Adding static route for Vpn {} with destination {}, nexthop {} and label {}", vpnInstanceName, destination, nexthop, label);
    Collection<RpcError> rpcErrors = validateAddStaticRouteInput(input);
    if (!rpcErrors.isEmpty()) {
        result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withRpcErrors(rpcErrors).build());
        return result;
    }
    if (label == null || label == 0) {
        label = (long) VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(vpnInstanceName, destination));
        if (label == 0) {
            String message = "Unable to retrieve a new Label for the new Route";
            result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
            return result;
        }
    }
    String vpnRd = VpnUtil.getVpnRd(dataBroker, input.getVpnInstanceName());
    VpnInstanceOpDataEntry vpnOpEntry = VpnUtil.getVpnInstanceOpData(dataBroker, vpnRd);
    Boolean isVxlan = VpnUtil.isL3VpnOverVxLan(vpnOpEntry.getL3vni());
    VrfEntry.EncapType encapType = VpnUtil.getEncapType(isVxlan);
    if (vpnRd == null) {
        String message = "Could not find Route-Distinguisher for VpnName " + vpnInstanceName;
        result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(RpcError.ErrorType.APPLICATION, message).build());
        return result;
    }
    Optional<InterVpnLinkDataComposite> optIVpnLink = interVpnLinkCache.getInterVpnLinkByEndpoint(nexthop);
    if (optIVpnLink.isPresent()) {
        try {
            InterVpnLinkUtil.handleStaticRoute(optIVpnLink.get(), vpnInstanceName, destination, nexthop, label.intValue(), dataBroker, fibManager, bgpManager);
        } catch (Exception e) {
            result.set(RpcResultBuilder.<AddStaticRouteOutput>failed().withError(ErrorType.APPLICATION, formatAndLog(LOG::warn, "Could not advertise route [vpn={}, prefix={}, label={}, nexthop={}] to BGP: {}", vpnRd, destination, label, nexthop, e.getMessage(), e)).build());
            return result;
        }
    } else {
        vpnManager.addExtraRoute(vpnInstanceName, destination, nexthop, vpnRd, null, /* routerId */
        vpnOpEntry.getL3vni(), RouteOrigin.STATIC, null, /* intfName */
        null, /*Adjacency*/
        encapType, null);
    }
    AddStaticRouteOutput labelOutput = new AddStaticRouteOutputBuilder().setLabel(label).build();
    result.set(RpcResultBuilder.success(labelOutput).build());
    return result;
}
Also used : RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) AddStaticRouteOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteOutput) 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) AddStaticRouteOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.AddStaticRouteOutputBuilder) InterVpnLinkDataComposite(org.opendaylight.netvirt.vpnmanager.api.intervpnlink.InterVpnLinkDataComposite)

Example 95 with RouterId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev171207.RouterId in project netvirt by opendaylight.

the class ArpNotificationHandler method getSubnetId.

private String getSubnetId(String vpnName, String ip) {
    // Check if this IP belongs to a router_interface
    VpnPortipToPort vpnPortipToPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnName, ip);
    if (vpnPortipToPort != null && vpnPortipToPort.isSubnetIp()) {
        List<Adjacency> adjacecnyList = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, vpnPortipToPort.getPortName());
        for (Adjacency adjacency : adjacecnyList) {
            if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
                return adjacency.getSubnetId().getValue();
            }
        }
    }
    // Check if this IP belongs to a router_gateway
    List<Uuid> routerIds = VpnUtil.getExternalNetworkRouterIds(dataBroker, new Uuid(vpnName));
    for (Uuid routerId : routerIds) {
        Uuid subnetId = VpnUtil.getSubnetFromExternalRouterByIp(dataBroker, routerId, ip);
        if (subnetId != null) {
            return subnetId.getValue();
        }
    }
    return null;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)86 BigInteger (java.math.BigInteger)35 ArrayList (java.util.ArrayList)34 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)23 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)22 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)20 Routers (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers)20 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)19 ProviderTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProviderTypes)19 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)17 ExecutionException (java.util.concurrent.ExecutionException)16 FlowEntity (org.opendaylight.genius.mdsalutil.FlowEntity)14 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)12 ExternalIps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps)12 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)12 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)11 InternalToExternalPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.router.ports.ports.InternalToExternalPortMap)11 HashSet (java.util.HashSet)10 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)10 RouterPorts (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.floating.ip.info.RouterPorts)10