CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.ovsdb.controller; |
| 17 | |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 18 | import org.onlab.packet.IpAddress; |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 19 | import org.onlab.util.Identifier; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 22 | |
| 23 | /** |
BitOhenry | 3f28c68 | 2015-11-07 10:40:03 +0800 | [diff] [blame] | 24 | * The class representing a nodeId of node which using ovsdb connection. |
BitOhenry | 6e20489 | 2015-11-04 22:09:04 +0800 | [diff] [blame] | 25 | * This class is immutable. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 26 | */ |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 27 | public final class OvsdbNodeId extends Identifier<String> { |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 28 | private static final String SCHEME = "ovsdb"; |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 29 | private final String ipAddress; |
| 30 | |
| 31 | /** |
BitOhenry | 6e20489 | 2015-11-04 22:09:04 +0800 | [diff] [blame] | 32 | * Creates a new node identifier from an IpAddress ipAddress, a long port. |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 33 | * |
| 34 | * @param ipAddress node IP address |
| 35 | * @param port node port |
| 36 | */ |
| 37 | public OvsdbNodeId(IpAddress ipAddress, long port) { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 38 | // TODO: port is currently not in use, need to remove it later |
| 39 | super(checkNotNull(ipAddress, "ipAddress is not null").toString()); |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 40 | this.ipAddress = ipAddress.toString(); |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public String toString() { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 45 | return SCHEME + ":" + identifier; |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Gets the value of the NodeId. |
| 50 | * |
| 51 | * @return the value of the NodeId. |
| 52 | */ |
| 53 | public String nodeId() { |
Jian Li | 597d7b2 | 2016-02-29 14:06:55 -0800 | [diff] [blame] | 54 | return SCHEME + ":" + identifier; |
CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 55 | } |
| 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 | } |