Route Simplification programming

Change-Id: If3d8aaa3fe2dad5538b10ddc54b97f504d0f1a35
diff --git a/app/src/main/java/org/onosproject/segmentrouting/RouteSimplifierUtils.java b/app/src/main/java/org/onosproject/segmentrouting/RouteSimplifierUtils.java
new file mode 100644
index 0000000..817b32e
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/RouteSimplifierUtils.java
@@ -0,0 +1,68 @@
+/*
+ * 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;
+    }
+
+}