blob: 46f6e29cb56c6359fe40df8f03d8d2f6207f0981 [file] [log] [blame]
Hyunsun Moond0e932a2015-09-15 22:39:16 -07001/*
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 */
16package org.onosproject.cordvtn;
17
Hyunsun Moon2b530322015-09-23 13:24:35 -070018import com.google.common.base.MoreObjects;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070019import org.onlab.packet.IpAddress;
20import org.onlab.packet.TpPort;
21import org.onosproject.net.DeviceId;
22
23import java.util.Objects;
24
25/**
26 * OvsdbNode implementation.
27 */
28public class DefaultOvsdbNode implements OvsdbNode {
29
Hyunsun Moon2b530322015-09-23 13:24:35 -070030 private final String host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070031 private final IpAddress ip;
32 private final TpPort port;
Hyunsun Moon1f145552015-10-08 22:25:30 -070033 private final DeviceId brId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070034
Hyunsun Moon1f145552015-10-08 22:25:30 -070035 public DefaultOvsdbNode(String host, IpAddress ip, TpPort port, DeviceId brId) {
Hyunsun Moon2b530322015-09-23 13:24:35 -070036 this.host = host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070037 this.ip = ip;
38 this.port = port;
Hyunsun Moon1f145552015-10-08 22:25:30 -070039 this.brId = brId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070040 }
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 Moon2b530322015-09-23 13:24:35 -070053 public String host() {
54 return this.host;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070055 }
56
57 @Override
Hyunsun Moon1f145552015-10-08 22:25:30 -070058 public DeviceId intBrId() {
59 return this.brId;
Hyunsun Moond0e932a2015-09-15 22:39:16 -070060 }
61
62 @Override
63 public DeviceId deviceId() {
Hyunsun Moon3bce3932015-10-28 16:52:20 -070064 return DeviceId.deviceId("ovsdb:" + this.ip.toString());
Hyunsun Moond0e932a2015-09-15 22:39:16 -070065 }
66
67 @Override
Hyunsun Moond0e932a2015-09-15 22:39:16 -070068 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 Moon2b530322015-09-23 13:24:35 -070075 if (this.host.equals(that.host) &&
76 this.ip.equals(that.ip) &&
Hyunsun Moon1f145552015-10-08 22:25:30 -070077 this.port.equals(that.port) &&
78 this.brId.equals(that.brId)) {
Hyunsun Moond0e932a2015-09-15 22:39:16 -070079 return true;
80 }
81 }
82 return false;
83 }
84
85 @Override
86 public int hashCode() {
Hyunsun Moon2b530322015-09-23 13:24:35 -070087 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 Moon1f145552015-10-08 22:25:30 -070096 .add("bridgeId", brId)
Hyunsun Moon2b530322015-09-23 13:24:35 -070097 .toString();
Hyunsun Moond0e932a2015-09-15 22:39:16 -070098 }
99}