blob: a1db8641b8fdb910cce780dc0602e195d790c6a7 [file] [log] [blame]
Marc De Leenheer57a5af02016-12-02 20:54:41 -08001/*
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 */
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;
24import org.onosproject.tl1.impl.DefaultTl1Device;
25import org.onosproject.tl1.Tl1Device;
26
27import java.util.Set;
28
29/**
30 * Configuration for TL1 provider.
31 */
32public class Tl1ProviderConfig extends Config<ApplicationId> {
33 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
34 private static final String IP = "ip";
35 private static final String PORT = "port";
36 private static final String USERNAME = "username";
37 private static final String PASSWORD = "password";
38
39 Set<Tl1Device> readDevices() throws ConfigException {
40 Set<Tl1Device> devices = Sets.newHashSet();
41
42 try {
43 for (JsonNode node : array) {
44 String ip = node.path(IP).asText();
45 IpAddress ipAddress = IpAddress.valueOf(ip);
46 int port = node.path(PORT).asInt();
47 String username = node.path(USERNAME).asText();
48 String password = node.path(PASSWORD).asText();
49 devices.add(new DefaultTl1Device(ipAddress, port, username, password));
50 }
51 } catch (IllegalArgumentException e) {
52 throw new ConfigException(CONFIG_VALUE_ERROR, e);
53 }
54
55 return devices;
56 }
57}