/*
 * Copyright 2018-present Open Networking Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onosproject.segmentrouting;

/**
 * Utility class for route simplification.
 */
import com.google.common.collect.ImmutableList;
import org.onlab.packet.IpPrefix;
import org.onosproject.routeservice.ResolvedRoute;
import org.onosproject.routeservice.Route;

final class RouteSimplifierUtils {

    /**
     * When route with source type listed in leafExclusionRouteTypes,
     * it will programme only on the leaf pair the nexthop attaches to. Other leaves will be ignored.
     */
    private static final ImmutableList<Route.Source> LEAF_EXCLUSION_ROUTE_TYPES =
            ImmutableList.of(Route.Source.DHCP, Route.Source.RIP, Route.Source.DHCPLQ);

    private SegmentRoutingManager srManager;

    RouteSimplifierUtils(SegmentRoutingManager srManager) {

        this.srManager = srManager;
    }

    /**
     * Checking whether the leafExclusionRouteTypes contains the given source type.
     *
     * @return boolean if it containsd the source type.
     * */
    private boolean hasLeafExclusionEnabledForType(Route.Source s) {
        return LEAF_EXCLUSION_ROUTE_TYPES.contains(s);
    }

    /*
     * When route with any source of given prefix is  listed in leafExclusionRouteTypes,
     * it will programme only on the leaf pair the nexthop attaches to. Other leaves will be ignored.
     *
     * @param ipPrefix  ip prefix of the route.
     * @return boolean if contains the prefix of the mentioned source type.
     * */
    public boolean hasLeafExclusionEnabledForPrefix(IpPrefix ipPrefix) {
        for (ResolvedRoute route : srManager.routeService.getAllResolvedRoutes(ipPrefix)) {
            if (hasLeafExclusionEnabledForType(route.route().source())) {
                return true;
            }
        }
        return false;
    }

}

@@ -16,9 +16,9 @@
  201
-8
+9
 -pre
@@ -657,59 +657,8 @@
 g;%0A%0A
-/**%0A * Utility class for route simplification.%0A */%0A
 impo
@@ -830,16 +830,67 @@
 Route;%0A%0A
+/**%0A * Utility class for route simplification.%0A */%0A
 final cl
@@ -915,33 +915,32 @@
 rUtils %7B%0A%0A    /*
-*
 %0A     * When rou
@@ -1516,32 +1516,60 @@
 ce type.%0A     *%0A
+     * @param s source type%0A
      * @return b
@@ -1606,32 +1606,37 @@
 rce type.%0A     *
+%0A    
  */%0A    private 
@@ -1628,22 +1628,21 @@
 */%0A    p
-rivate
+ublic
  boolean
@@ -1751,32 +1751,33 @@
 );%0A    %7D%0A%0A    /*
+*
 %0A     * When rou
@@ -2083,22 +2083,20 @@
 e type.%0A
+
     
- *
  */%0A    

Fix java doc