blob: d7a5f61a8de1cb18b60f0b2ec5daa09d013db762 [file] [log] [blame]
CNlucius74fd4942015-07-20 14:28:04 +08001/*
2 * Copyright 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.ovsdb.controller;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Objects;
21
22import org.onlab.packet.IpAddress;
23
24/**
BitOhenry6e204892015-11-04 22:09:04 +080025 * The class representing a OpenStack Compute or Network nodeId.
26 * This class is immutable.
CNlucius74fd4942015-07-20 14:28:04 +080027 */
28public final class OvsdbNodeId {
29 private static final String SCHEME = "ovsdb";
30 private final String nodeId;
31 private final String ipAddress;
32
33 /**
BitOhenry6e204892015-11-04 22:09:04 +080034 * Creates a new node identifier from an IpAddress ipAddress, a long port.
CNlucius74fd4942015-07-20 14:28:04 +080035 *
36 * @param ipAddress node IP address
37 * @param port node port
38 */
39 public OvsdbNodeId(IpAddress ipAddress, long port) {
40 checkNotNull(ipAddress, "ipAddress is not null");
41 this.ipAddress = ipAddress.toString();
jiangrui866c2f22015-10-28 18:58:34 +080042 this.nodeId = ipAddress.toString();
CNlucius74fd4942015-07-20 14:28:04 +080043 }
44
45 @Override
46 public int hashCode() {
HIGUCHI Yutaca9cc8e2015-10-29 23:26:51 -070047 return nodeId.hashCode();
CNlucius74fd4942015-07-20 14:28:04 +080048 }
49
50 @Override
51 public boolean equals(Object other) {
52 if (!(other instanceof OvsdbNodeId)) {
53 return false;
54 }
55
56 OvsdbNodeId otherNodeId = (OvsdbNodeId) other;
57
58 return Objects.equals(otherNodeId.nodeId, this.nodeId);
59 }
60
61 @Override
62 public String toString() {
63 return SCHEME + ":" + nodeId;
64 }
65
66 /**
67 * Gets the value of the NodeId.
68 *
69 * @return the value of the NodeId.
70 */
71 public String nodeId() {
72 return SCHEME + ":" + nodeId;
73 }
74
75 /**
76 * Get the IP address of the node.
77 *
78 * @return the IP address of the node
79 */
80 public String getIpAddress() {
81 return ipAddress;
82 }
83}