Charles Chan | cab494d | 2016-11-11 16:31:49 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 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 | |
| 17 | package org.onosproject.incubator.net.routing; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onlab.packet.IpPrefix; |
| 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.config.Config; |
| 24 | |
| 25 | import java.util.Set; |
| 26 | |
| 27 | /** |
| 28 | * Route configuration object for Route Service. |
| 29 | */ |
| 30 | public class RouteConfig extends Config<ApplicationId> { |
| 31 | private static final String ROUTES = "routes"; |
| 32 | private static final String PREFIX = "prefix"; |
| 33 | private static final String NEXTHOP = "nextHop"; |
| 34 | |
| 35 | /** |
| 36 | * Returns all routes in this configuration. |
| 37 | * |
| 38 | * @return A set of route. |
| 39 | */ |
| 40 | public Set<Route> getRoutes() { |
| 41 | ImmutableSet.Builder<Route> routes = ImmutableSet.builder(); |
| 42 | array.forEach(route -> { |
| 43 | try { |
| 44 | IpPrefix prefix = IpPrefix.valueOf(route.path(PREFIX).asText()); |
| 45 | IpAddress nextHop = IpAddress.valueOf(route.path(NEXTHOP).asText()); |
| 46 | routes.add(new Route(Route.Source.STATIC, prefix, nextHop)); |
| 47 | } catch (IllegalArgumentException e) { |
| 48 | // Ignores routes that cannot be parsed correctly |
| 49 | } |
| 50 | }); |
| 51 | return routes.build(); |
| 52 | } |
| 53 | } |