blob: 2cdeb5384d915775c1fd5ef86ebb56a4f3431cc9 [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
andreaeb70a942015-10-16 21:34:46 -07003 *
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";
Konstantinos Kanonakisb3e97042016-11-15 11:33:07 -060039 private static final String NAME = "username";
andreaeb70a942015-10-16 21:34:46 -070040 private static final String PASSWORD = "password";
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060041 private static final String SSHKEY = "sshkey";
andreaeb70a942015-10-16 21:34:46 -070042
43 public Set<NetconfDeviceAddress> getDevicesAddresses() throws ConfigException {
44 Set<NetconfDeviceAddress> devicesAddresses = Sets.newHashSet();
45
46 try {
47 for (JsonNode node : array) {
48 String ip = node.path(IP).asText();
49 IpAddress ipAddr = ip.isEmpty() ? null : IpAddress.valueOf(ip);
50 int port = node.path(PORT).asInt(DEFAULT_TCP_PORT);
51 String name = node.path(NAME).asText();
52 String password = node.path(PASSWORD).asText();
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060053 String sshkey = node.path(SSHKEY).asText();
54 devicesAddresses.add(new NetconfDeviceAddress(ipAddr, port, name, password, sshkey));
andreaeb70a942015-10-16 21:34:46 -070055
56 }
57 } catch (IllegalArgumentException e) {
58 throw new ConfigException(CONFIG_VALUE_ERROR, e);
59 }
60
61 return devicesAddresses;
62 }
63
64 public class NetconfDeviceAddress {
65 private final IpAddress ip;
66 private final int port;
67 private final String name;
68 private final String password;
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060069 private final String sshkey;
andreaeb70a942015-10-16 21:34:46 -070070
71 public NetconfDeviceAddress(IpAddress ip, int port, String name, String password) {
72 this.ip = ip;
73 this.port = port;
74 this.name = name;
75 this.password = password;
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -060076 this.sshkey = "";
77 }
78
79 public NetconfDeviceAddress(IpAddress ip, int port, String name, String password, String sshkey) {
80 this.ip = ip;
81 this.port = port;
82 this.name = name;
83 this.password = password;
84 this.sshkey = sshkey;
andreaeb70a942015-10-16 21:34:46 -070085 }
86
87 public IpAddress ip() {
88 return ip;
89 }
90
91 public int port() {
92 return port;
93 }
94
95 public String name() {
96 return name;
97 }
98
99 public String password() {
100 return password;
101 }
Himanshu Ranjan7c2ee3c2017-02-13 05:10:08 -0600102
103 public String sshkey() {
104 return sshkey;
105 }
andreaeb70a942015-10-16 21:34:46 -0700106 }
107
andreaeb70a942015-10-16 21:34:46 -0700108}