blob: 439d16e14c07f6738ce2f576f94c790f043936d8 [file] [log] [blame]
Hyunsun Moon8539b042015-11-07 22:08:43 -08001/*
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
18import com.google.common.base.MoreObjects;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.TpPort;
21import org.onosproject.net.DeviceId;
22
23import java.util.Comparator;
24import java.util.Objects;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Representation of a compute infrastructure node for CORD VTN service.
30 */
31public final class CordVtnNode {
32
33 private final String hostname;
34 private final IpAddress ovsdbIp;
35 private final TpPort ovsdbPort;
36 private final DeviceId bridgeId;
37
38 public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR =
39 (node1, node2) -> node1.hostname().compareTo(node2.hostname());
40
41 /**
42 * Creates a new node.
43 *
44 * @param hostname hostname
45 * @param ovsdbIp OVSDB server IP address
46 * @param ovsdbPort OVSDB server port number
47 * @param bridgeId integration bridge identifier
48 */
49 public CordVtnNode(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId) {
50 this.hostname = checkNotNull(hostname);
51 this.ovsdbIp = checkNotNull(ovsdbIp);
52 this.ovsdbPort = checkNotNull(ovsdbPort);
53 this.bridgeId = checkNotNull(bridgeId);
54 }
55
56 /**
57 * Returns the OVSDB server IP address.
58 *
59 * @return ip address
60 */
61 public IpAddress ovsdbIp() {
62 return this.ovsdbIp;
63 }
64
65 /**
66 * Returns the OVSDB server port number.
67 *
68 * @return port number
69 */
70 public TpPort ovsdbPort() {
71 return this.ovsdbPort;
72 }
73
74 /**
75 * Returns the hostname.
76 *
77 * @return hostname
78 */
79 public String hostname() {
80 return this.hostname;
81 }
82
83 /**
84 * Returns the identifier of the integration bridge.
85 *
86 * @return device id
87 */
88 public DeviceId intBrId() {
89 return this.bridgeId;
90 }
91
92 /**
93 * Returns the identifier of the OVSDB device.
94 *
95 * @return device id
96 */
97 public DeviceId ovsdbId() {
98 return DeviceId.deviceId("ovsdb:" + this.ovsdbIp.toString());
99 }
100
101 @Override
102 public boolean equals(Object obj) {
103 if (this == obj) {
104 return true;
105 }
106
107 if (obj instanceof CordVtnNode) {
108 CordVtnNode that = (CordVtnNode) obj;
109 if (Objects.equals(hostname, that.hostname) &&
110 Objects.equals(ovsdbIp, that.ovsdbIp) &&
111 Objects.equals(ovsdbPort, that.ovsdbPort) &&
112 Objects.equals(bridgeId, that.bridgeId)) {
113 return true;
114 }
115 }
116 return false;
117 }
118
119 @Override
120 public int hashCode() {
121 return Objects.hash(hostname, ovsdbIp, ovsdbPort);
122 }
123
124 @Override
125 public String toString() {
126 return MoreObjects.toStringHelper(getClass())
127 .add("host", hostname)
128 .add("ip", ovsdbIp)
129 .add("port", ovsdbPort)
130 .add("bridgeId", bridgeId)
131 .toString();
132 }
133}