blob: 2c1a440bc85d645114ba1e1b08e32c303e03cdaf [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/**
25 * The class representing a OpenStack Compute or Network nodeId. This class is
26 * immutable.
27 */
28public final class OvsdbNodeId {
29 private static final String SCHEME = "ovsdb";
30 private final String nodeId;
31 private final String ipAddress;
32
33 /**
34 * Creates a new node identifier from a IpAddress ipAddress, a long port.
35 *
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();
42 this.nodeId = ipAddress + ":" + port;
43 }
44
45 @Override
46 public int hashCode() {
47 return Objects.hash(nodeId);
48 }
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}