blob: 0227d89795302711429f4fc17f9d0a4e6b3775fb [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
2 * Copyright 2015 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.provider.netconf.device.impl;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.google.common.annotations.Beta;
21import com.google.common.collect.Sets;
22import org.onlab.packet.IpAddress;
23import org.onosproject.core.ApplicationId;
24import org.onosproject.incubator.net.config.basics.ConfigException;
25import org.onosproject.net.config.Config;
26
27import java.util.Set;
28
29/**
30 * Configuration for Netconf provider.
31 */
32@Beta
33public class NetconfProviderConfig extends Config<ApplicationId> {
34
35 public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
36 private static final String IP = "ip";
37 private static final int DEFAULT_TCP_PORT = 830;
38 private static final String PORT = "port";
39 private static final String NAME = "name";
40 private static final String PASSWORD = "password";
41
42 public Set<NetconfDeviceAddress> getDevicesAddresses() throws ConfigException {
43 Set<NetconfDeviceAddress> devicesAddresses = Sets.newHashSet();
44
45 try {
46 for (JsonNode node : array) {
47 String ip = node.path(IP).asText();
48 IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
49 int port = node.path(PORT).asInt(DEFAULT_TCP_PORT);
50 String name = node.path(NAME).asText();
51 String password = node.path(PASSWORD).asText();
52 devicesAddresses.add(new NetconfDeviceAddress(ipAddr, port, name, password));
53
54 }
55 } catch (IllegalArgumentException e) {
56 throw new ConfigException(CONFIG_VALUE_ERROR, e);
57 }
58
59 return devicesAddresses;
60 }
61
62 public class NetconfDeviceAddress {
63 private final IpAddress ip;
64 private final int port;
65 private final String name;
66 private final String password;
67
68 public NetconfDeviceAddress(IpAddress ip, int port, String name, String password) {
69 this.ip = ip;
70 this.port = port;
71 this.name = name;
72 this.password = password;
73 }
74
75 public IpAddress ip() {
76 return ip;
77 }
78
79 public int port() {
80 return port;
81 }
82
83 public String name() {
84 return name;
85 }
86
87 public String password() {
88 return password;
89 }
90 }
91
andreaeb70a942015-10-16 21:34:46 -070092}