blob: 3f62db4f59877f44928df0fd52c5deae72a44ff5 [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
Pingping Linc9e16bf2015-04-10 14:42:41 -070023import org.onlab.packet.IpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070024import org.onlab.packet.IpPrefix;
25
26/**
27 * Configuration details for an IP prefix entry.
28 */
29public class LocalIpPrefixEntry {
30 private final IpPrefix ipPrefix;
31 private final IpPrefixType type;
Pingping Linc9e16bf2015-04-10 14:42:41 -070032 private final IpAddress gatewayIpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070033
34 /**
35 * Specifies the type of local IP prefix.
36 */
37 public enum IpPrefixType {
38 /**
39 * Public IP prefixes should be exchanged by eBGP.
40 */
41 PUBLIC,
42 /**
43 * Private IP prefixes should be used only locally and not exchanged
44 * by eBGP.
45 */
46 PRIVATE,
47 /**
48 * For IP prefixes in blacklist.
49 */
50 BLACK_LIST
51 }
52
53 /**
54 * Creates a new IP prefix entry.
55 *
56 * @param ipPrefix an IP prefix as a String
57 * @param type an IP prefix type as an IpPrefixType
58 */
59 public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix,
Pingping Linc9e16bf2015-04-10 14:42:41 -070060 @JsonProperty("type") IpPrefixType type,
61 @JsonProperty("gatewayIp") IpAddress
62 gatewayIpAddress) {
Pingping Line28ae4c2015-03-13 11:37:03 -070063 this.ipPrefix = IpPrefix.valueOf(ipPrefix);
64 this.type = type;
Pingping Linc9e16bf2015-04-10 14:42:41 -070065 this.gatewayIpAddress = gatewayIpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070066 }
67
68 /**
69 * Gets the IP prefix of the IP prefix entry.
70 *
71 * @return the IP prefix
72 */
73 public IpPrefix ipPrefix() {
74 return ipPrefix;
75 }
76
77 /**
78 * Gets the IP prefix type of the IP prefix entry.
79 *
80 * @return the IP prefix type
81 */
82 public IpPrefixType ipPrefixType() {
83 return type;
84 }
85
86 /**
Pingping Linc9e16bf2015-04-10 14:42:41 -070087 * Gets the gateway IP address of the IP prefix entry.
88 *
89 * @return the gateway IP address
90 */
91 public IpAddress getGatewayIpAddress() {
92 return gatewayIpAddress;
93 }
94
95 /**
Pingping Line28ae4c2015-03-13 11:37:03 -070096 * Tests whether the IP version of this entry is IPv4.
97 *
98 * @return true if the IP version of this entry is IPv4, otherwise false.
99 */
100 public boolean isIp4() {
101 return ipPrefix.isIp4();
102 }
103
104 /**
105 * Tests whether the IP version of this entry is IPv6.
106 *
107 * @return true if the IP version of this entry is IPv6, otherwise false.
108 */
109 public boolean isIp6() {
110 return ipPrefix.isIp6();
111 }
112
113 @Override
114 public int hashCode() {
115 return Objects.hash(ipPrefix, type);
116 }
117
118 @Override
119 public boolean equals(Object obj) {
120 if (obj == this) {
121 return true;
122 }
123
124 if (!(obj instanceof LocalIpPrefixEntry)) {
125 return false;
126 }
127
128 LocalIpPrefixEntry that = (LocalIpPrefixEntry) obj;
129 return Objects.equals(this.ipPrefix, that.ipPrefix)
130 && Objects.equals(this.type, that.type);
131 }
132
133 @Override
134 public String toString() {
135 return MoreObjects.toStringHelper(getClass())
136 .add("ipPrefix", ipPrefix)
137 .add("ipPrefixType", type)
138 .toString();
139 }
140}