blob: c11ba42ebe84d11bc9ff3845119c8b3b589e04b6 [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;
Hyunsun Moonb219fc42016-01-14 03:42:47 -080037 private final String phyPortName;
38 private final IpAddress localIp;
Hyunsun Moon8539b042015-11-07 22:08:43 -080039
40 public static final Comparator<CordVtnNode> CORDVTN_NODE_COMPARATOR =
41 (node1, node2) -> node1.hostname().compareTo(node2.hostname());
42
43 /**
44 * Creates a new node.
45 *
46 * @param hostname hostname
47 * @param ovsdbIp OVSDB server IP address
48 * @param ovsdbPort OVSDB server port number
49 * @param bridgeId integration bridge identifier
Hyunsun Moonb219fc42016-01-14 03:42:47 -080050 * @param phyPortName physical port name
51 * @param localIp local ip address of data plane
Hyunsun Moon8539b042015-11-07 22:08:43 -080052 */
Hyunsun Moonb219fc42016-01-14 03:42:47 -080053 public CordVtnNode(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort,
54 DeviceId bridgeId, String phyPortName, IpAddress localIp) {
Hyunsun Moon8539b042015-11-07 22:08:43 -080055 this.hostname = checkNotNull(hostname);
56 this.ovsdbIp = checkNotNull(ovsdbIp);
57 this.ovsdbPort = checkNotNull(ovsdbPort);
58 this.bridgeId = checkNotNull(bridgeId);
Hyunsun Moonb219fc42016-01-14 03:42:47 -080059 this.phyPortName = checkNotNull(phyPortName);
60 this.localIp = checkNotNull(localIp);
Hyunsun Moon8539b042015-11-07 22:08:43 -080061 }
62
63 /**
64 * Returns the OVSDB server IP address.
65 *
66 * @return ip address
67 */
68 public IpAddress ovsdbIp() {
69 return this.ovsdbIp;
70 }
71
72 /**
73 * Returns the OVSDB server port number.
74 *
75 * @return port number
76 */
77 public TpPort ovsdbPort() {
78 return this.ovsdbPort;
79 }
80
81 /**
82 * Returns the hostname.
83 *
84 * @return hostname
85 */
86 public String hostname() {
87 return this.hostname;
88 }
89
90 /**
91 * Returns the identifier of the integration bridge.
92 *
93 * @return device id
94 */
95 public DeviceId intBrId() {
96 return this.bridgeId;
97 }
98
99 /**
100 * Returns the identifier of the OVSDB device.
101 *
102 * @return device id
103 */
104 public DeviceId ovsdbId() {
105 return DeviceId.deviceId("ovsdb:" + this.ovsdbIp.toString());
106 }
107
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800108 /**
109 * Returns physical port name.
110 *
111 * @return physical port name
112 */
113 public String phyPortName() {
114 return this.phyPortName;
115 }
116
117 /**
118 * Returns local IP address.
119 *
120 * @return ip address
121 */
122 public IpAddress localIp() {
123 return this.localIp;
124 }
125
Hyunsun Moon8539b042015-11-07 22:08:43 -0800126 @Override
127 public boolean equals(Object obj) {
128 if (this == obj) {
129 return true;
130 }
131
132 if (obj instanceof CordVtnNode) {
133 CordVtnNode that = (CordVtnNode) obj;
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800134 if (Objects.equals(hostname, that.hostname)) {
Hyunsun Moon8539b042015-11-07 22:08:43 -0800135 return true;
136 }
137 }
138 return false;
139 }
140
141 @Override
142 public int hashCode() {
143 return Objects.hash(hostname, ovsdbIp, ovsdbPort);
144 }
145
146 @Override
147 public String toString() {
148 return MoreObjects.toStringHelper(getClass())
149 .add("host", hostname)
150 .add("ip", ovsdbIp)
151 .add("port", ovsdbPort)
152 .add("bridgeId", bridgeId)
Hyunsun Moonb219fc42016-01-14 03:42:47 -0800153 .add("phyPortName", phyPortName)
154 .add("localIp", localIp)
Hyunsun Moon8539b042015-11-07 22:08:43 -0800155 .toString();
156 }
157}