blob: 7949898c44033220e26463190b092f1cebb61ec1 [file] [log] [blame]
Hyunsun Moon483e29f2016-02-05 16:55:33 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Hyunsun Moon483e29f2016-02-05 16:55:33 -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.cordvtn;
17
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.Ip4Address;
20import org.onlab.packet.TpPort;
21
22import java.util.Objects;
23
Hyunsun Moon32f3b8e2016-03-02 19:27:26 -080024import static com.google.common.base.Preconditions.checkNotNull;
25
Hyunsun Moon483e29f2016-02-05 16:55:33 -080026/**
27 * Representation of SSH access information.
28 */
29public final class SshAccessInfo {
30
31 private final Ip4Address remoteIp;
32 private final TpPort port;
33 private final String user;
34 private final String privateKey;
35
36 /**
37 * Creates a new SSH access information.
38 *
39 * @param remoteIp ssh remote ip address
40 * @param port ssh port number
41 * @param user user name
42 * @param privateKey path of ssh private key
43 */
44 public SshAccessInfo(Ip4Address remoteIp, TpPort port, String user, String privateKey) {
Hyunsun Moon32f3b8e2016-03-02 19:27:26 -080045 this.remoteIp = checkNotNull(remoteIp);
46 this.port = checkNotNull(port);
47 this.user = checkNotNull(user);
48 this.privateKey = checkNotNull(privateKey);
Hyunsun Moon483e29f2016-02-05 16:55:33 -080049 }
50
51 /**
52 * Returns the remote IP address.
53 *
54 * @return ip address
55 */
56 public Ip4Address remoteIp() {
57 return this.remoteIp;
58 }
59
60 /**
61 * Returns the port number.
62 *
63 * @return ssh port
64 */
65 public TpPort port() {
66 return this.port;
67 }
68
69 /**
70 * Returns the user name.
71 *
72 * @return user name
73 */
74 public String user() {
75 return this.user;
76 }
77
78 /**
79 * Returns the private key path.
80 *
81 * @return privateKey
82 */
83 public String privateKey() {
84 return privateKey;
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92
93 if (obj instanceof SshAccessInfo) {
94 SshAccessInfo that = (SshAccessInfo) obj;
95 if (Objects.equals(remoteIp, that.remoteIp) &&
96 Objects.equals(port, that.port) &&
97 Objects.equals(user, that.user) &&
98 Objects.equals(privateKey, that.privateKey)) {
99 return true;
100 }
101 }
102 return false;
103 }
104
105 @Override
106 public int hashCode() {
107 return Objects.hash(remoteIp, port, user, privateKey);
108 }
109
110 @Override
111 public String toString() {
112 return MoreObjects.toStringHelper(getClass())
113 .add("remoteIp", remoteIp)
114 .add("port", port)
115 .add("user", user)
116 .add("privateKey", privateKey)
117 .toString();
118 }
119}