blob: 817b32eac7b58426f087e67523cf74c5bef28e89 [file] [log] [blame]
psneha86e60d32019-03-26 06:31:41 -04001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
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
19/**
20 * Utility class for route simplification.
21 */
22import com.google.common.collect.ImmutableList;
23import org.onlab.packet.IpPrefix;
24import org.onosproject.routeservice.ResolvedRoute;
25import org.onosproject.routeservice.Route;
26
27final class RouteSimplifierUtils {
28
29 /**
30 * 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 *
46 * @return boolean if it containsd the source type.
47 * */
48 private boolean hasLeafExclusionEnabledForType(Route.Source s) {
49 return LEAF_EXCLUSION_ROUTE_TYPES.contains(s);
50 }
51
52 /*
53 * When route with any source of given prefix is listed in leafExclusionRouteTypes,
54 * it will programme only on the leaf pair the nexthop attaches to. Other leaves will be ignored.
55 *
56 * @param ipPrefix ip prefix of the route.
57 * @return boolean if contains the prefix of the mentioned source type.
58 * */
59 public boolean hasLeafExclusionEnabledForPrefix(IpPrefix ipPrefix) {
60 for (ResolvedRoute route : srManager.routeService.getAllResolvedRoutes(ipPrefix)) {
61 if (hasLeafExclusionEnabledForType(route.route().source())) {
62 return true;
63 }
64 }
65 return false;
66 }
67
68}