@@ -137,6 +137,72 @@ func marshalAny(m proto.Message) *anypb.Any {
137137 return a
138138}
139139
140+ // filterChainWontMatch returns a filter chain that won't match if running the
141+ // test locally.
142+ func filterChainWontMatch (routeName string , addressPrefix string , srcPorts []uint32 ) * v3listenerpb.FilterChain {
143+ hcm := & v3httppb.HttpConnectionManager {
144+ RouteSpecifier : & v3httppb.HttpConnectionManager_Rds {
145+ Rds : & v3httppb.Rds {
146+ ConfigSource : & v3corepb.ConfigSource {
147+ ConfigSourceSpecifier : & v3corepb.ConfigSource_Ads {Ads : & v3corepb.AggregatedConfigSource {}},
148+ },
149+ RouteConfigName : routeName ,
150+ },
151+ },
152+ HttpFilters : []* v3httppb.HttpFilter {RouterHTTPFilter },
153+ }
154+ return & v3listenerpb.FilterChain {
155+ Name : routeName + "-wont-match" ,
156+ FilterChainMatch : & v3listenerpb.FilterChainMatch {
157+ PrefixRanges : []* v3corepb.CidrRange {
158+ {
159+ AddressPrefix : addressPrefix ,
160+ PrefixLen : & wrapperspb.UInt32Value {
161+ Value : uint32 (0 ),
162+ },
163+ },
164+ },
165+ SourceType : v3listenerpb .FilterChainMatch_SAME_IP_OR_LOOPBACK ,
166+ SourcePorts : srcPorts ,
167+ SourcePrefixRanges : []* v3corepb.CidrRange {
168+ {
169+ AddressPrefix : addressPrefix ,
170+ PrefixLen : & wrapperspb.UInt32Value {
171+ Value : uint32 (0 ),
172+ },
173+ },
174+ },
175+ },
176+ Filters : []* v3listenerpb.Filter {
177+ {
178+ Name : "filter-1" ,
179+ ConfigType : & v3listenerpb.Filter_TypedConfig {TypedConfig : marshalAny (hcm )},
180+ },
181+ },
182+ }
183+ }
184+
185+ // ListenerResourceThreeRouteResources returns a listener resource that points
186+ // to three route configurations. Only the filter chain that points to the first
187+ // route config can be matched to.
188+ func ListenerResourceThreeRouteResources (host string , port uint32 , secLevel SecurityLevel , routeName string ) * v3listenerpb.Listener {
189+ lis := defaultServerListenerCommon (host , port , secLevel , routeName , false )
190+ lis .FilterChains = append (lis .FilterChains , filterChainWontMatch ("routeName2" , "1.1.1.1" , []uint32 {1 }))
191+ lis .FilterChains = append (lis .FilterChains , filterChainWontMatch ("routeName3" , "2.2.2.2" , []uint32 {2 }))
192+ return lis
193+ }
194+
195+ // ListenerResourceFallbackToDefault returns a listener resource that contains a
196+ // filter chain that will never get chosen to process traffic and a default
197+ // filter chain. The default filter chain points to routeName2.
198+ func ListenerResourceFallbackToDefault (host string , port uint32 , secLevel SecurityLevel ) * v3listenerpb.Listener {
199+ lis := defaultServerListenerCommon (host , port , secLevel , "" , false )
200+ lis .FilterChains = nil
201+ lis .FilterChains = append (lis .FilterChains , filterChainWontMatch ("routeName" , "1.1.1.1" , []uint32 {1 }))
202+ lis .DefaultFilterChain = filterChainWontMatch ("routeName2" , "2.2.2.2" , []uint32 {2 })
203+ return lis
204+ }
205+
140206// DefaultServerListener returns a basic xds Listener resource to be used on the
141207// server side. The returned Listener resource contains an inline route
142208// configuration with the name of routeName.
@@ -290,13 +356,6 @@ func defaultServerListenerCommon(host string, port uint32, secLevel SecurityLeve
290356 }
291357}
292358
293- // DefaultServerListenerWithRouteConfigName returns a basic xds Listener
294- // resource to be used on the server side. The returned Listener resource
295- // contains a RouteCongiguration resource name that needs to be resolved.
296- func DefaultServerListenerWithRouteConfigName (host string , port uint32 , secLevel SecurityLevel , routeName string ) * v3listenerpb.Listener {
297- return defaultServerListenerCommon (host , port , secLevel , routeName , false )
298- }
299-
300359// HTTPFilter constructs an xds HttpFilter with the provided name and config.
301360func HTTPFilter (name string , config proto.Message ) * v3httppb.HttpFilter {
302361 return & v3httppb.HttpFilter {
@@ -356,7 +415,6 @@ type RouteConfigOptions struct {
356415 ListenerName string
357416 // ClusterSpecifierType determines the cluster specifier type.
358417 ClusterSpecifierType RouteConfigClusterSpecifierType
359-
360418 // ClusterName is name of the cluster resource used when the cluster
361419 // specifier type is set to RouteConfigClusterSpecifierTypeCluster.
362420 //
@@ -722,3 +780,65 @@ func EndpointResourceWithOptions(opts EndpointOptions) *v3endpointpb.ClusterLoad
722780 }
723781 return cla
724782}
783+
784+ // DefaultServerListenerWithRouteConfigName returns a basic xds Listener
785+ // resource to be used on the server side. The returned Listener resource
786+ // contains a RouteCongiguration resource name that needs to be resolved.
787+ func DefaultServerListenerWithRouteConfigName (host string , port uint32 , secLevel SecurityLevel , routeName string ) * v3listenerpb.Listener {
788+ return defaultServerListenerCommon (host , port , secLevel , routeName , false )
789+ }
790+
791+ // RouteConfigNoRouteMatch returns an xDS RouteConfig resource which a route
792+ // with no route match. This will be NACKed by the xDS Client.
793+ func RouteConfigNoRouteMatch (routeName string ) * v3routepb.RouteConfiguration {
794+ return & v3routepb.RouteConfiguration {
795+ Name : routeName ,
796+ VirtualHosts : []* v3routepb.VirtualHost {{
797+ // This "*" string matches on any incoming authority. This is to ensure any
798+ // incoming RPC matches to Route_NonForwardingAction and will proceed as
799+ // normal.
800+ Domains : []string {"*" },
801+ Routes : []* v3routepb.Route {{
802+ Action : & v3routepb.Route_NonForwardingAction {},
803+ }}}}}
804+ }
805+
806+ // RouteConfigNonForwardingAction returns an xDS RouteConfig resource which
807+ // specifies to route to a route specifying non forwarding action. This is
808+ // intended to be used on the server side for RDS requests, and corresponds to
809+ // the inline route configuration in DefaultServerListener.
810+ func RouteConfigNonForwardingAction (routeName string ) * v3routepb.RouteConfiguration {
811+ return & v3routepb.RouteConfiguration {
812+ Name : routeName ,
813+ VirtualHosts : []* v3routepb.VirtualHost {{
814+ // This "*" string matches on any incoming authority. This is to ensure any
815+ // incoming RPC matches to Route_NonForwardingAction and will proceed as
816+ // normal.
817+ Domains : []string {"*" },
818+ Routes : []* v3routepb.Route {{
819+ Match : & v3routepb.RouteMatch {
820+ PathSpecifier : & v3routepb.RouteMatch_Prefix {Prefix : "/" },
821+ },
822+ Action : & v3routepb.Route_NonForwardingAction {},
823+ }}}}}
824+ }
825+
826+ // RouteConfigFilterAction returns an xDS RouteConfig resource which specifies
827+ // to route to a route specifying route filter action. Since this is not type
828+ // non forwarding action, this should fail requests that match to this server
829+ // side.
830+ func RouteConfigFilterAction (routeName string ) * v3routepb.RouteConfiguration {
831+ return & v3routepb.RouteConfiguration {
832+ Name : routeName ,
833+ VirtualHosts : []* v3routepb.VirtualHost {{
834+ // This "*" string matches on any incoming authority. This is to
835+ // ensure any incoming RPC matches to Route_Route and will fail with
836+ // UNAVAILABLE.
837+ Domains : []string {"*" },
838+ Routes : []* v3routepb.Route {{
839+ Match : & v3routepb.RouteMatch {
840+ PathSpecifier : & v3routepb.RouteMatch_Prefix {Prefix : "/" },
841+ },
842+ Action : & v3routepb.Route_FilterAction {},
843+ }}}}}
844+ }
0 commit comments