Jonathan Hart | 249b4cf | 2017-02-03 18:02:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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.routing.config; |
| 18 | |
| 19 | import com.google.common.collect.Sets; |
| 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.config.NetworkConfigService; |
| 22 | import org.onosproject.routing.RoutingService; |
| 23 | import org.slf4j.Logger; |
| 24 | import org.slf4j.LoggerFactory; |
| 25 | |
| 26 | import java.util.Collections; |
| 27 | import java.util.Set; |
| 28 | |
| 29 | /** |
| 30 | * Helper class to manage retrieving config from multiple Config sections. |
| 31 | * Should be unnecessary once old config is removed. |
| 32 | */ |
| 33 | public final class RouterConfigHelper { |
| 34 | |
| 35 | private static final String WARNING = |
| 36 | "Config apps/org.onosproject.routing/router is deprecated " |
| 37 | + "and will be removed in a future release."; |
| 38 | private static final String WARNING2 = |
| 39 | "Use apps/org.onosproject.routing/routers instead"; |
| 40 | |
| 41 | private static final Logger log = LoggerFactory.getLogger(RouterConfigHelper.class); |
| 42 | |
| 43 | private RouterConfigHelper() { |
| 44 | // make checkstyle happy |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Retrieves the router configurations. |
| 49 | * |
| 50 | * @param configService network config service |
| 51 | * @param routingAppId routing app ID |
| 52 | * @return set of router configurations |
| 53 | */ |
| 54 | public static Set<RoutersConfig.Router> getRouterConfigurations( |
| 55 | NetworkConfigService configService, ApplicationId routingAppId) { |
| 56 | |
| 57 | RouterConfig config = configService.getConfig( |
| 58 | routingAppId, RoutingService.ROUTER_CONFIG_CLASS); |
| 59 | RoutersConfig multiConfig = configService.getConfig(routingAppId, RoutersConfig.class); |
| 60 | |
| 61 | if (config != null) { |
| 62 | log.warn(WARNING); |
| 63 | log.warn(WARNING2); |
| 64 | |
| 65 | return Collections.singleton( |
| 66 | new RoutersConfig.Router(config.getControlPlaneConnectPoint(), |
| 67 | config.getOspfEnabled(), |
| 68 | Sets.newHashSet(config.getInterfaces()))); |
| 69 | } else if (multiConfig != null) { |
| 70 | return multiConfig.getRouters(); |
| 71 | } else { |
| 72 | return Collections.emptySet(); |
| 73 | } |
| 74 | } |
| 75 | } |