Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-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 | package org.onosproject.cordvtn; |
| 17 | |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 18 | import com.google.common.base.MoreObjects; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.TpPort; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
| 26 | * OvsdbNode implementation. |
| 27 | */ |
| 28 | public class DefaultOvsdbNode implements OvsdbNode { |
| 29 | |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 30 | private final String host; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 31 | private final IpAddress ip; |
| 32 | private final TpPort port; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 33 | private final DeviceId brId; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 34 | |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 35 | public DefaultOvsdbNode(String host, IpAddress ip, TpPort port, DeviceId brId) { |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 36 | this.host = host; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 37 | this.ip = ip; |
| 38 | this.port = port; |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 39 | this.brId = brId; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public IpAddress ip() { |
| 44 | return this.ip; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public TpPort port() { |
| 49 | return this.port; |
| 50 | } |
| 51 | |
| 52 | @Override |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 53 | public String host() { |
| 54 | return this.host; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Override |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 58 | public DeviceId intBrId() { |
| 59 | return this.brId; |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public DeviceId deviceId() { |
Hyunsun Moon | 15e111a | 2015-10-28 16:52:20 -0700 | [diff] [blame] | 64 | return DeviceId.deviceId("ovsdb:" + this.ip.toString()); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 68 | public boolean equals(Object o) { |
| 69 | if (this == o) { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | if (o instanceof DefaultOvsdbNode) { |
| 74 | DefaultOvsdbNode that = (DefaultOvsdbNode) o; |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 75 | if (this.host.equals(that.host) && |
| 76 | this.ip.equals(that.ip) && |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 77 | this.port.equals(that.port) && |
| 78 | this.brId.equals(that.brId)) { |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public int hashCode() { |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 87 | return Objects.hash(host, ip, port); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return MoreObjects.toStringHelper(getClass()) |
| 93 | .add("host", host) |
| 94 | .add("ip", ip) |
| 95 | .add("port", port) |
Hyunsun Moon | 7dca9b3 | 2015-10-08 22:25:30 -0700 | [diff] [blame] | 96 | .add("bridgeId", brId) |
Hyunsun Moon | 9661d64 | 2015-09-23 13:24:35 -0700 | [diff] [blame] | 97 | .toString(); |
Hyunsun Moon | e9d7599 | 2015-09-15 22:39:16 -0700 | [diff] [blame] | 98 | } |
| 99 | } |