blob: aa9120aae3a2cc48fab9c4b4256a321807be546b [file] [log] [blame]
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZUb2b2d982015-09-11 15:35:06 -07003 *
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.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20import java.util.Objects;
21
22import 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 */
28public 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