blob: e265eaa92e462ea1eb496f13fd38bd0dcba15fca [file] [log] [blame]
Marc De Leenheer57a5af02016-12-02 20:54:41 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Marc De Leenheer57a5af02016-12-02 20:54:41 -08003 *
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 */
16package org.onosproject.provider.tl1.device.impl;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.google.common.collect.Sets;
20import org.onlab.packet.IpAddress;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.incubator.net.config.basics.ConfigException;
23import org.onosproject.net.config.Config;
Yuta HIGUCHIc6358352017-06-23 11:56:27 -070024import org.onosproject.tl1.DefaultTl1Device;
Marc De Leenheer57a5af02016-12-02 20:54:41 -080025import org.onosproject.tl1.Tl1Device;
26
27import java.util.Set;
28
29/**
30 * Configuration for TL1 provider.
Andrea Campanella59b549d2017-04-14 21:58:16 +020031 * @deprecated 1.10.0 Kingfisher
32 *
Marc De Leenheer57a5af02016-12-02 20:54:41 -080033 */
Andrea Campanella59b549d2017-04-14 21:58:16 +020034@Deprecated
Marc De Leenheer57a5af02016-12-02 20:54:41 -080035public class Tl1ProviderConfig extends Config<ApplicationId> {
36 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
37 private static final String IP = "ip";
38 private static final String PORT = "port";
39 private static final String USERNAME = "username";
40 private static final String PASSWORD = "password";
41
42 Set<Tl1Device> readDevices() throws ConfigException {
43 Set<Tl1Device> devices = Sets.newHashSet();
44
45 try {
46 for (JsonNode node : array) {
47 String ip = node.path(IP).asText();
48 IpAddress ipAddress = IpAddress.valueOf(ip);
49 int port = node.path(PORT).asInt();
50 String username = node.path(USERNAME).asText();
51 String password = node.path(PASSWORD).asText();
52 devices.add(new DefaultTl1Device(ipAddress, port, username, password));
53 }
54 } catch (IllegalArgumentException e) {
55 throw new ConfigException(CONFIG_VALUE_ERROR, e);
56 }
57
58 return devices;
59 }
60}