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