Search in sources :

Example 11 with Listener

use of io.envoyproxy.envoy.config.listener.v3.Listener in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseServerSideListener_uniqueFilterChainMatch.

@Test
public void parseServerSideListener_uniqueFilterChainMatch() throws ResourceInvalidException {
    Filter filter1 = buildHttpConnectionManagerFilter(HttpFilter.newBuilder().setName("http-filter-1").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build());
    FilterChainMatch filterChainMatch1 = FilterChainMatch.newBuilder().addAllSourcePorts(Arrays.asList(80, 8080)).addAllPrefixRanges(Arrays.asList(CidrRange.newBuilder().setAddressPrefix("192.168.0.0").setPrefixLen(UInt32Value.of(16)).build(), CidrRange.newBuilder().setAddressPrefix("10.0.0.0").setPrefixLen(UInt32Value.of(8)).build())).setSourceType(FilterChainMatch.ConnectionSourceType.EXTERNAL).build();
    FilterChain filterChain1 = FilterChain.newBuilder().setName("filter-chain-1").setFilterChainMatch(filterChainMatch1).addFilters(filter1).build();
    Filter filter2 = buildHttpConnectionManagerFilter(HttpFilter.newBuilder().setName("http-filter-2").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build());
    FilterChainMatch filterChainMatch2 = FilterChainMatch.newBuilder().addAllSourcePorts(Arrays.asList(443, 8080)).addAllPrefixRanges(Arrays.asList(CidrRange.newBuilder().setAddressPrefix("2001:DB8::8:800:200C:417A").setPrefixLen(UInt32Value.of(60)).build(), CidrRange.newBuilder().setAddressPrefix("192.168.0.0").setPrefixLen(UInt32Value.of(16)).build())).setSourceType(FilterChainMatch.ConnectionSourceType.ANY).build();
    FilterChain filterChain2 = FilterChain.newBuilder().setName("filter-chain-2").setFilterChainMatch(filterChainMatch2).addFilters(filter2).build();
    Listener listener = Listener.newBuilder().setName("listener1").setTrafficDirection(TrafficDirection.INBOUND).addAllFilterChains(Arrays.asList(filterChain1, filterChain2)).build();
    ClientXdsClient.parseServerSideListener(listener, new HashSet<String>(), null, filterRegistry, null, true);
}
Also used : Listener(io.envoyproxy.envoy.config.listener.v3.Listener) ListenerFilter(io.envoyproxy.envoy.config.listener.v3.ListenerFilter) HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) Filter(io.envoyproxy.envoy.config.listener.v3.Filter) FilterChain(io.envoyproxy.envoy.config.listener.v3.FilterChain) FilterChainMatch(io.envoyproxy.envoy.config.listener.v3.FilterChainMatch) Test(org.junit.Test)

Example 12 with Listener

use of io.envoyproxy.envoy.config.listener.v3.Listener in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseServerSideListener_listenerFiltersPresent.

@Test
public void parseServerSideListener_listenerFiltersPresent() throws ResourceInvalidException {
    Listener listener = Listener.newBuilder().setName("listener1").setTrafficDirection(TrafficDirection.INBOUND).addListenerFilters(ListenerFilter.newBuilder().build()).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("Listener listener1 cannot have listener_filters");
    ClientXdsClient.parseServerSideListener(listener, new HashSet<String>(), null, filterRegistry, null, true);
}
Also used : Listener(io.envoyproxy.envoy.config.listener.v3.Listener) Test(org.junit.Test)

Example 13 with Listener

use of io.envoyproxy.envoy.config.listener.v3.Listener in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseServerSideListener_nonUniqueFilterChainMatch.

@Test
public void parseServerSideListener_nonUniqueFilterChainMatch() throws ResourceInvalidException {
    Filter filter1 = buildHttpConnectionManagerFilter(HttpFilter.newBuilder().setName("http-filter-1").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build());
    FilterChainMatch filterChainMatch1 = FilterChainMatch.newBuilder().addAllSourcePorts(Arrays.asList(80, 8080)).addAllPrefixRanges(Arrays.asList(CidrRange.newBuilder().setAddressPrefix("192.168.0.0").setPrefixLen(UInt32Value.of(16)).build(), CidrRange.newBuilder().setAddressPrefix("10.0.0.0").setPrefixLen(UInt32Value.of(8)).build())).build();
    FilterChain filterChain1 = FilterChain.newBuilder().setName("filter-chain-1").setFilterChainMatch(filterChainMatch1).addFilters(filter1).build();
    Filter filter2 = buildHttpConnectionManagerFilter(HttpFilter.newBuilder().setName("http-filter-2").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build());
    FilterChainMatch filterChainMatch2 = FilterChainMatch.newBuilder().addAllSourcePorts(Arrays.asList(443, 8080)).addAllPrefixRanges(Arrays.asList(CidrRange.newBuilder().setAddressPrefix("2001:DB8::8:800:200C:417A").setPrefixLen(UInt32Value.of(60)).build(), CidrRange.newBuilder().setAddressPrefix("192.168.0.0").setPrefixLen(UInt32Value.of(16)).build())).build();
    FilterChain filterChain2 = FilterChain.newBuilder().setName("filter-chain-2").setFilterChainMatch(filterChainMatch2).addFilters(filter2).build();
    Listener listener = Listener.newBuilder().setName("listener1").setTrafficDirection(TrafficDirection.INBOUND).addAllFilterChains(Arrays.asList(filterChain1, filterChain2)).build();
    thrown.expect(ResourceInvalidException.class);
    thrown.expectMessage("FilterChainMatch must be unique. Found duplicate:");
    ClientXdsClient.parseServerSideListener(listener, new HashSet<String>(), null, filterRegistry, null, true);
}
Also used : Listener(io.envoyproxy.envoy.config.listener.v3.Listener) ListenerFilter(io.envoyproxy.envoy.config.listener.v3.ListenerFilter) HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) Filter(io.envoyproxy.envoy.config.listener.v3.Filter) FilterChain(io.envoyproxy.envoy.config.listener.v3.FilterChain) FilterChainMatch(io.envoyproxy.envoy.config.listener.v3.FilterChainMatch) Test(org.junit.Test)

Example 14 with Listener

use of io.envoyproxy.envoy.config.listener.v3.Listener in project grpc-java by grpc.

the class ClientXdsClient method handleLdsResponse.

@Override
public void handleLdsResponse(ServerInfo serverInfo, String versionInfo, List<Any> resources, String nonce) {
    syncContext.throwIfNotInThisSynchronizationContext();
    Map<String, ParsedResource> parsedResources = new HashMap<>(resources.size());
    Set<String> unpackedResources = new HashSet<>(resources.size());
    Set<String> invalidResources = new HashSet<>();
    List<String> errors = new ArrayList<>();
    Set<String> retainedRdsResources = new HashSet<>();
    for (int i = 0; i < resources.size(); i++) {
        Any resource = resources.get(i);
        // Unpack the Listener.
        boolean isResourceV3 = resource.getTypeUrl().equals(ResourceType.LDS.typeUrl());
        Listener listener;
        try {
            listener = unpackCompatibleType(resource, Listener.class, ResourceType.LDS.typeUrl(), ResourceType.LDS.typeUrlV2());
        } catch (InvalidProtocolBufferException e) {
            errors.add("LDS response Resource index " + i + " - can't decode Listener: " + e);
            continue;
        }
        if (!isResourceNameValid(listener.getName(), resource.getTypeUrl())) {
            errors.add("Unsupported resource name: " + listener.getName() + " for type: " + ResourceType.LDS);
            continue;
        }
        String listenerName = canonifyResourceName(listener.getName());
        unpackedResources.add(listenerName);
        // Process Listener into LdsUpdate.
        LdsUpdate ldsUpdate;
        try {
            if (listener.hasApiListener()) {
                ldsUpdate = processClientSideListener(listener, retainedRdsResources, enableFaultInjection && isResourceV3);
            } else {
                ldsUpdate = processServerSideListener(listener, retainedRdsResources, enableRbac && isResourceV3);
            }
        } catch (ResourceInvalidException e) {
            errors.add("LDS response Listener '" + listenerName + "' validation error: " + e.getMessage());
            invalidResources.add(listenerName);
            continue;
        }
        // LdsUpdate parsed successfully.
        parsedResources.put(listenerName, new ParsedResource(ldsUpdate, resource));
    }
    logger.log(XdsLogLevel.INFO, "Received LDS Response version {0} nonce {1}. Parsed resources: {2}", versionInfo, nonce, unpackedResources);
    handleResourceUpdate(serverInfo, ResourceType.LDS, parsedResources, invalidResources, retainedRdsResources, versionInfo, nonce, errors);
}
Also used : Listener(io.envoyproxy.envoy.config.listener.v3.Listener) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Any(com.google.protobuf.Any) LbEndpoint(io.grpc.xds.Endpoints.LbEndpoint) HashSet(java.util.HashSet)

Example 15 with Listener

use of io.envoyproxy.envoy.config.listener.v3.Listener in project grpc-java by grpc.

the class FakeControlPlaneXdsIntegrationTest method serverListener.

private static Listener serverListener(String name) {
    HttpFilter routerFilter = HttpFilter.newBuilder().setName("terminal-filter").setTypedConfig(Any.pack(Router.newBuilder().build())).setIsOptional(true).build();
    VirtualHost virtualHost = io.envoyproxy.envoy.config.route.v3.VirtualHost.newBuilder().setName("virtual-host-0").addDomains("*").addRoutes(Route.newBuilder().setMatch(RouteMatch.newBuilder().setPrefix("/").build()).setNonForwardingAction(NonForwardingAction.newBuilder().build()).build()).build();
    RouteConfiguration routeConfig = RouteConfiguration.newBuilder().addVirtualHosts(virtualHost).build();
    Filter filter = Filter.newBuilder().setName("network-filter-0").setTypedConfig(Any.pack(HttpConnectionManager.newBuilder().setRouteConfig(routeConfig).addAllHttpFilters(Collections.singletonList(routerFilter)).build())).build();
    FilterChainMatch filterChainMatch = FilterChainMatch.newBuilder().setSourceType(FilterChainMatch.ConnectionSourceType.ANY).build();
    FilterChain filterChain = FilterChain.newBuilder().setName("filter-chain-0").setFilterChainMatch(filterChainMatch).addFilters(filter).build();
    return Listener.newBuilder().setName(name).setTrafficDirection(TrafficDirection.INBOUND).addFilterChains(filterChain).build();
}
Also used : Filter(io.envoyproxy.envoy.config.listener.v3.Filter) HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) RouteConfiguration(io.envoyproxy.envoy.config.route.v3.RouteConfiguration) FilterChain(io.envoyproxy.envoy.config.listener.v3.FilterChain) FilterChainMatch(io.envoyproxy.envoy.config.listener.v3.FilterChainMatch) HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) VirtualHost(io.envoyproxy.envoy.config.route.v3.VirtualHost)

Aggregations

Listener (io.envoyproxy.envoy.config.listener.v3.Listener)9 Test (org.junit.Test)7 HttpFilter (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter)5 Filter (io.envoyproxy.envoy.config.listener.v3.Filter)4 FilterChain (io.envoyproxy.envoy.config.listener.v3.FilterChain)4 FilterChainMatch (io.envoyproxy.envoy.config.listener.v3.FilterChainMatch)4 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)4 Engine (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Engine)4 Host (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Host)4 Listener (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Listener)4 Server (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Server)4 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)4 ListenerFilter (io.envoyproxy.envoy.config.listener.v3.ListenerFilter)3 ApiListener (io.envoyproxy.envoy.config.listener.v3.ApiListener)2 ArrayList (java.util.ArrayList)2 Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Listener (edu.mit.csail.sdg.alloy4.Listener)1 OurBorder (edu.mit.csail.sdg.alloy4.OurBorder)1 OurTree (edu.mit.csail.sdg.alloy4.OurTree)1