Sho SHIMIZU | b2b2d98 | 2015-09-11 15:35:06 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | b2b2d98 | 2015-09-11 15:35:06 -0700 | [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.vtnrsc; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | import java.util.Objects; |
| 21 | |
| 22 | import org.onlab.packet.IpAddress; |
| 23 | |
| 24 | /** |
| 25 | * The continuous IP address range between the start address and the end address |
| 26 | * for the allocation pools. |
| 27 | */ |
| 28 | public final class DefaultAllocationPool implements AllocationPool { |
| 29 | |
| 30 | private final IpAddress startIp; |
| 31 | private final IpAddress endIp; |
| 32 | |
| 33 | /** |
| 34 | * Creates an AllocationPool by using the start IP address and the end IP |
| 35 | * address. |
| 36 | * |
| 37 | * @param startIp the start IP address of the allocation pool |
| 38 | * @param endIp the end IP address of the allocation pool |
| 39 | */ |
| 40 | public DefaultAllocationPool(IpAddress startIp, IpAddress endIp) { |
| 41 | checkNotNull(startIp, "StartIp cannot be null"); |
| 42 | checkNotNull(endIp, "EndIp cannot be null"); |
| 43 | this.startIp = startIp; |
| 44 | this.endIp = endIp; |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public IpAddress startIp() { |
| 49 | return startIp; |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public IpAddress endIp() { |
| 54 | return endIp; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hash(startIp, endIp); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object obj) { |
| 64 | if (this == obj) { |
| 65 | return true; |
| 66 | } |
| 67 | if (obj instanceof DefaultAllocationPool) { |
| 68 | final DefaultAllocationPool other = (DefaultAllocationPool) obj; |
| 69 | return Objects.equals(this.startIp, other.startIp) |
| 70 | && Objects.equals(this.endIp, other.endIp); |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public String toString() { |
| 77 | return toStringHelper(this).add("startIp", startIp).add("endIp", endIp) |
| 78 | .toString(); |
| 79 | } |
| 80 | } |
| 81 | |