blob: 401007c6fd03abe2b2e48682b19e444048a59f79 [file] [log] [blame]
psneha86e60d32019-03-26 06:31:41 -04001/*
pier382d4ac2019-04-08 16:40:14 +02002 * Copyright 2019-present Open Networking Foundation
psneha86e60d32019-03-26 06:31:41 -04003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.segmentrouting;
18
psneha86e60d32019-03-26 06:31:41 -040019import com.google.common.collect.ImmutableList;
20import org.onlab.packet.IpPrefix;
21import org.onosproject.routeservice.ResolvedRoute;
22import org.onosproject.routeservice.Route;
23
pier382d4ac2019-04-08 16:40:14 +020024/**
25 * Utility class for route simplification.
26 */
psneha86e60d32019-03-26 06:31:41 -040027final class RouteSimplifierUtils {
28
pier382d4ac2019-04-08 16:40:14 +020029 /*
psneha86e60d32019-03-26 06:31:41 -040030 * When route with source type listed in leafExclusionRouteTypes,
31 * it will programme only on the leaf pair the nexthop attaches to. Other leaves will be ignored.
32 */
33 private static final ImmutableList<Route.Source> LEAF_EXCLUSION_ROUTE_TYPES =
34 ImmutableList.of(Route.Source.DHCP, Route.Source.RIP, Route.Source.DHCPLQ);
35
36 private SegmentRoutingManager srManager;
37
38 RouteSimplifierUtils(SegmentRoutingManager srManager) {
39
40 this.srManager = srManager;
41 }
42
43 /**
44 * Checking whether the leafExclusionRouteTypes contains the given source type.
45 *
pier382d4ac2019-04-08 16:40:14 +020046 * @param s source type
psneha86e60d32019-03-26 06:31:41 -040047 * @return boolean if it containsd the source type.
pier382d4ac2019-04-08 16:40:14 +020048 *
49 */
50 public boolean hasLeafExclusionEnabledForType(Route.Source s) {
psneha86e60d32019-03-26 06:31:41 -040051 return LEAF_EXCLUSION_ROUTE_TYPES.contains(s);
52 }
53
pier382d4ac2019-04-08 16:40:14 +020054 /**
psneha86e60d32019-03-26 06:31:41 -040055 * When route with any source of given prefix is listed in leafExclusionRouteTypes,
56 * it will programme only on the leaf pair the nexthop attaches to. Other leaves will be ignored.
57 *
58 * @param ipPrefix ip prefix of the route.
59 * @return boolean if contains the prefix of the mentioned source type.
pier382d4ac2019-04-08 16:40:14 +020060 */
psneha86e60d32019-03-26 06:31:41 -040061 public boolean hasLeafExclusionEnabledForPrefix(IpPrefix ipPrefix) {
62 for (ResolvedRoute route : srManager.routeService.getAllResolvedRoutes(ipPrefix)) {
63 if (hasLeafExclusionEnabledForType(route.route().source())) {
64 return true;
65 }
66 }
67 return false;
68 }
69
70}