blob: ddfd1dba956ccdbdf0444707eee521a24eff0767 [file] [log] [blame]
Jonathan Hart249b4cf2017-02-03 18:02:58 -08001/*
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
17package org.onosproject.routing.config;
18
19import com.google.common.collect.Sets;
20import org.onosproject.core.ApplicationId;
21import org.onosproject.net.config.NetworkConfigService;
22import org.onosproject.routing.RoutingService;
23import org.slf4j.Logger;
24import org.slf4j.LoggerFactory;
25
26import java.util.Collections;
27import 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 */
33public 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}