Search in sources :

Example 46 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 NeutronvpnManager method checkAlarmExtraRoutes.

/**
 * This method setup or down an alarm about extra route fault.
 * When extra routes are configured, through a router, if the number of nexthops is greater than the number of
 * available RDs, then an alarm and an error is generated.<br>
 * <b>Be careful</b> the routeList could be changed.
 *
 * @param vpnId the vpnId of vpn to control.
 * @param routeList the list of router to check, it could be modified.
 */
private void checkAlarmExtraRoutes(Uuid vpnId, List<Routes> routeList) {
    if (!neutronvpnAlarm.isAlarmEnabled()) {
        LOG.debug("checkAlarmExtraRoutes is not enable for vpnId {} routeList {}", vpnId, routeList);
        return;
    }
    VpnInstance vpnInstance = neutronvpnUtils.getVpnInstance(dataBroker, vpnId);
    if (vpnInstance == null || routeList == null || routeList.isEmpty() || !neutronvpnAlarm.isAlarmEnabled()) {
        LOG.debug("checkAlarmExtraRoutes have args null as following : vpnId {} routeList {}", vpnId, routeList);
        return;
    }
    List<Routes> routesError = new ArrayList();
    for (Routes route : routeList) {
        // count  the number of nexthops for each same route.getDestingation().getValue()
        String destination = String.valueOf(route.getDestination().getValue());
        String nextHop = String.valueOf(route.getNexthop().getValue());
        List<String> nextHopList = new ArrayList();
        nextHopList.add(nextHop);
        int nbNextHops = 0;
        for (Routes routeTmp : routeList) {
            String routeDest = String.valueOf(routeTmp.getDestination().getValue());
            if (!destination.equals(routeDest)) {
                continue;
            }
            String routeNextH = String.valueOf(routeTmp.getNexthop().getValue());
            if (nextHop.equals(routeNextH)) {
                continue;
            }
            nbNextHops++;
            nextHopList.add(new String(routeTmp.getNexthop().getValue()));
        }
        final List<String> rdList = new ArrayList();
        if (vpnInstance.getIpv4Family() != null && vpnInstance.getIpv4Family().getRouteDistinguisher() != null) {
            vpnInstance.getIpv4Family().getRouteDistinguisher().stream().forEach(rd -> {
                if (rd != null) {
                    rdList.add(rd);
                }
            });
        }
        if (vpnInstance.getIpv6Family() != null && vpnInstance.getIpv6Family().getRouteDistinguisher() != null) {
            vpnInstance.getIpv6Family().getRouteDistinguisher().stream().forEach(rd -> {
                if (rd != null && !rdList.contains(rd)) {
                    rdList.add(rd);
                }
            });
        }
        // 1. VPN Instance Name
        String typeAlarm = "for vpnId: " + vpnId + " have exceeded next hops for prefixe";
        // 2. Router ID
        Uuid routerUuid = neutronvpnUtils.getRouterforVpn(vpnId);
        StringBuilder detailsAlarm = new StringBuilder("routerUuid: ");
        detailsAlarm.append(routerUuid == null ? vpnId.toString() : routerUuid.getValue());
        // 3. List of RDs associated with the VPN
        detailsAlarm.append(" List of RDs associated with the VPN: ");
        for (String s : rdList) {
            detailsAlarm.append(s);
            detailsAlarm.append(", ");
        }
        // 4. Prefix in question
        detailsAlarm.append(" for prefix: ");
        detailsAlarm.append(route.getDestination().getValue());
        // 5. List of NHs for the prefix
        detailsAlarm.append(" for nextHops: ");
        for (String s : nextHopList) {
            detailsAlarm.append(s);
            detailsAlarm.append(", ");
        }
        if (rdList.size() < nbNextHops) {
            neutronvpnAlarm.raiseNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
            LOG.error("there are too many next hops for prefixe in vpn {}", vpnId);
            routesError.add(route);
        } else {
            neutronvpnAlarm.clearNeutronvpnAlarm(typeAlarm, detailsAlarm.toString());
        }
    }
    // in routesError there are a few route raised in alarm, so they have not to be used
    routeList.removeAll(routesError);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstance(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance) ArrayList(java.util.ArrayList) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes)

Example 47 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 NeutronvpnManager method removeInterVpnRoutes.

/**
 * Removes the corresponding static routes from the specified VPN. These static routes point to an
 * InterVpnLink endpoint and the specified VPN must be the other end of the InterVpnLink.
 *
 * @param vpnName the VPN identifier
 * @param interVpnLinkRoutes The list of static routes
 * @param nexthopsXinterVpnLinks A Map with the correspondence nextHop-InterVpnLink
 */
public void removeInterVpnRoutes(Uuid vpnName, List<Routes> interVpnLinkRoutes, HashMap<String, InterVpnLink> nexthopsXinterVpnLinks) {
    for (Routes route : interVpnLinkRoutes) {
        String nexthop = String.valueOf(route.getNexthop().getValue());
        String destination = String.valueOf(route.getDestination().getValue());
        InterVpnLink interVpnLink = nexthopsXinterVpnLinks.get(nexthop);
        if (isNexthopTheOtherVpnLinkEndpoint(nexthop, vpnName.getValue(), interVpnLink)) {
            RemoveStaticRouteInput rpcInput = new RemoveStaticRouteInputBuilder().setDestination(destination).setNexthop(nexthop).setVpnInstanceName(vpnName.getValue()).build();
            ListenableFutures.addErrorLogging(JdkFutureAdapters.listenInPoolThread(vpnRpcService.removeStaticRoute(rpcInput)), LOG, "Remove VPN routes");
        } else {
            // Any other case is a fault.
            LOG.warn("route with destination {} and nexthop {} does not apply to any InterVpnLink", String.valueOf(route.getDestination().getValue()), nexthop);
            continue;
        }
    }
}
Also used : InterVpnLink(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink) RemoveStaticRouteInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInputBuilder) Routes(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.l3.attributes.Routes) RemoveStaticRouteInput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.vpn.rpc.rev160201.RemoveStaticRouteInput)

Example 48 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project hub-fortify-ssc-integration-service by blackducksoftware.

the class FortifyService method getHeader.

public static Builder getHeader(String userName, String password) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(Level.BASIC);
    OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
    okBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            String credential = Credentials.basic(userName, password);
            if (credential.equals(response.request().header("Authorization"))) {
                try {
                    FortifyExceptionUtil.verifyFortifyResponseCode(response.code(), "Unauthorized access of Fortify Api");
                } catch (IntegrationException e) {
                    throw new IOException(e);
                }
                return null;
            }
            return response.request().newBuilder().header("Authorization", credential).build();
        }
    });
    okBuilder.addInterceptor(logging);
    return okBuilder;
}
Also used : Builder(okhttp3.OkHttpClient.Builder) Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Builder(okhttp3.OkHttpClient.Builder) Request(okhttp3.Request) IOException(java.io.IOException) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 49 with Route

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.Route in project autorest-clientruntime-for-java by Azure.

the class AzureTokenCredentials method applyCredentialsFilter.

@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
    clientBuilder.interceptors().add(new AzureTokenCredentialsInterceptor(this));
    clientBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            String authenticateHeader = response.header("WWW-Authenticate");
            if (authenticateHeader != null && !authenticateHeader.isEmpty()) {
                Pattern pattern = Pattern.compile("resource=\"([a-zA-Z0-9.:/-_]+)\"");
                Matcher matcher = pattern.matcher(authenticateHeader);
                if (matcher.find()) {
                    String resource = matcher.group(1);
                    return response.request().newBuilder().header("Authorization", "Bearer " + getToken(resource)).build();
                }
            }
            // Otherwise cannot satisfy the challenge
            return null;
        }
    });
}
Also used : Response(okhttp3.Response) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Request(okhttp3.Request) IOException(java.io.IOException) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 50 with Route

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

the class MjpegStreamer method httpRequest.

public InputStream httpRequest(String url, final String usr, final String pwd) {
    Request request = new Request.Builder().url(url).build();
    OkHttpClient client = new OkHttpClient.Builder().authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            Log.d(TAG, "Authenticating for response: " + response);
            Log.d(TAG, "Challenges: " + response.challenges());
            // Get username/password from preferences
            String credential = Credentials.basic(usr, pwd);
            return response.request().newBuilder().header("Authorization", credential).build();
        }
    }).build();
    try {
        Log.d(TAG, "1. Sending http request");
        Response response = client.newCall(request).execute();
        Log.d(TAG, "2. Request finished, status = " + response.code());
        if (response.code() == 401) {
            // You must turn off camera User Access Control before this will work
            return null;
        }
        return response.body().byteStream();
    } catch (IOException e) {
        Log.e(TAG, "Request failed-IOException", e);
    // Error connecting to camera
    }
    return null;
}
Also used : Response(okhttp3.Response) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) IOException(java.io.IOException) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

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 Route (okhttp3.Route)20 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)20 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