blob: a2f3c8c180ce53a88e17f03578bad54225502bde [file] [log] [blame]
Pingping Line28ae4c2015-03-13 11:37:03 -07001/*
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.routing.config;
17
18import com.fasterxml.jackson.annotation.JsonProperty;
19import com.google.common.base.MoreObjects;
20
21import java.util.Objects;
22
23import org.onlab.packet.IpPrefix;
24
25/**
26 * Configuration details for an IP prefix entry.
27 */
28public class LocalIpPrefixEntry {
29 private final IpPrefix ipPrefix;
30 private final IpPrefixType type;
31
32 /**
33 * Specifies the type of local IP prefix.
34 */
35 public enum IpPrefixType {
36 /**
37 * Public IP prefixes should be exchanged by eBGP.
38 */
39 PUBLIC,
40 /**
41 * Private IP prefixes should be used only locally and not exchanged
42 * by eBGP.
43 */
44 PRIVATE,
45 /**
46 * For IP prefixes in blacklist.
47 */
48 BLACK_LIST
49 }
50
51 /**
52 * Creates a new IP prefix entry.
53 *
54 * @param ipPrefix an IP prefix as a String
55 * @param type an IP prefix type as an IpPrefixType
56 */
57 public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix,
58 @JsonProperty("type") IpPrefixType type) {
59 this.ipPrefix = IpPrefix.valueOf(ipPrefix);
60 this.type = type;
61 }
62
63 /**
64 * Gets the IP prefix of the IP prefix entry.
65 *
66 * @return the IP prefix
67 */
68 public IpPrefix ipPrefix() {
69 return ipPrefix;
70 }
71
72 /**
73 * Gets the IP prefix type of the IP prefix entry.
74 *
75 * @return the IP prefix type
76 */
77 public IpPrefixType ipPrefixType() {
78 return type;
79 }
80
81 /**
82 * Tests whether the IP version of this entry is IPv4.
83 *
84 * @return true if the IP version of this entry is IPv4, otherwise false.
85 */
86 public boolean isIp4() {
87 return ipPrefix.isIp4();
88 }
89
90 /**
91 * Tests whether the IP version of this entry is IPv6.
92 *
93 * @return true if the IP version of this entry is IPv6, otherwise false.
94 */
95 public boolean isIp6() {
96 return ipPrefix.isIp6();
97 }
98
99 @Override
100 public int hashCode() {
101 return Objects.hash(ipPrefix, type);
102 }
103
104 @Override
105 public boolean equals(Object obj) {
106 if (obj == this) {
107 return true;
108 }
109
110 if (!(obj instanceof LocalIpPrefixEntry)) {
111 return false;
112 }
113
114 LocalIpPrefixEntry that = (LocalIpPrefixEntry) obj;
115 return Objects.equals(this.ipPrefix, that.ipPrefix)
116 && Objects.equals(this.type, that.type);
117 }
118
119 @Override
120 public String toString() {
121 return MoreObjects.toStringHelper(getClass())
122 .add("ipPrefix", ipPrefix)
123 .add("ipPrefixType", type)
124 .toString();
125 }
126}