blob: bed44fbbd4faf8e15a8dc1a1a3121bb91f9a7568 [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
CNlucius74fd4942015-07-20 14:28:04 +080018import org.onlab.packet.IpAddress;
Jian Li597d7b22016-02-29 14:06:55 -080019import org.onlab.util.Identifier;
20
21import static com.google.common.base.Preconditions.checkNotNull;
CNlucius74fd4942015-07-20 14:28:04 +080022
23/**
BitOhenry3f28c682015-11-07 10:40:03 +080024 * The class representing a nodeId of node which using ovsdb connection.
BitOhenry6e204892015-11-04 22:09:04 +080025 * This class is immutable.
CNlucius74fd4942015-07-20 14:28:04 +080026 */
Jian Li597d7b22016-02-29 14:06:55 -080027public final class OvsdbNodeId extends Identifier<String> {
CNlucius74fd4942015-07-20 14:28:04 +080028 private static final String SCHEME = "ovsdb";
CNlucius74fd4942015-07-20 14:28:04 +080029 private final String ipAddress;
30
31 /**
BitOhenry6e204892015-11-04 22:09:04 +080032 * Creates a new node identifier from an IpAddress ipAddress, a long port.
CNlucius74fd4942015-07-20 14:28:04 +080033 *
34 * @param ipAddress node IP address
35 * @param port node port
36 */
37 public OvsdbNodeId(IpAddress ipAddress, long port) {
Jian Li597d7b22016-02-29 14:06:55 -080038 // TODO: port is currently not in use, need to remove it later
39 super(checkNotNull(ipAddress, "ipAddress is not null").toString());
CNlucius74fd4942015-07-20 14:28:04 +080040 this.ipAddress = ipAddress.toString();
CNlucius74fd4942015-07-20 14:28:04 +080041 }
42
43 @Override
44 public String toString() {
Jian Li597d7b22016-02-29 14:06:55 -080045 return SCHEME + ":" + identifier;
CNlucius74fd4942015-07-20 14:28:04 +080046 }
47
48 /**
49 * Gets the value of the NodeId.
50 *
51 * @return the value of the NodeId.
52 */
53 public String nodeId() {
Jian Li597d7b22016-02-29 14:06:55 -080054 return SCHEME + ":" + identifier;
CNlucius74fd4942015-07-20 14:28:04 +080055 }
56
57 /**
58 * Get the IP address of the node.
59 *
60 * @return the IP address of the node
61 */
62 public String getIpAddress() {
63 return ipAddress;
64 }
65}