blob: d9d1824b4b19d715c8446cadcd2fa646a5c4d669 [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 *
Thomas Vachuskae10f56b2015-04-15 18:20:08 -070056 * @param ipPrefix an IP prefix as a String
57 * @param type an IP prefix type as an IpPrefixType
58 * @param gatewayIpAddress IP of the gateway
Pingping Line28ae4c2015-03-13 11:37:03 -070059 */
60 public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix,
Pingping Linc9e16bf2015-04-10 14:42:41 -070061 @JsonProperty("type") IpPrefixType type,
62 @JsonProperty("gatewayIp") IpAddress
Thomas Vachuskae10f56b2015-04-15 18:20:08 -070063 gatewayIpAddress) {
Pingping Line28ae4c2015-03-13 11:37:03 -070064 this.ipPrefix = IpPrefix.valueOf(ipPrefix);
65 this.type = type;
Pingping Linc9e16bf2015-04-10 14:42:41 -070066 this.gatewayIpAddress = gatewayIpAddress;
Pingping Line28ae4c2015-03-13 11:37:03 -070067 }
68
69 /**
70 * Gets the IP prefix of the IP prefix entry.
71 *
72 * @return the IP prefix
73 */
74 public IpPrefix ipPrefix() {
75 return ipPrefix;
76 }
77
78 /**
79 * Gets the IP prefix type of the IP prefix entry.
80 *
81 * @return the IP prefix type
82 */
83 public IpPrefixType ipPrefixType() {
84 return type;
85 }
86
87 /**
Pingping Linc9e16bf2015-04-10 14:42:41 -070088 * Gets the gateway IP address of the IP prefix entry.
89 *
90 * @return the gateway IP address
91 */
92 public IpAddress getGatewayIpAddress() {
93 return gatewayIpAddress;
94 }
95
96 /**
Pingping Line28ae4c2015-03-13 11:37:03 -070097 * Tests whether the IP version of this entry is IPv4.
98 *
99 * @return true if the IP version of this entry is IPv4, otherwise false.
100 */
101 public boolean isIp4() {
102 return ipPrefix.isIp4();
103 }
104
105 /**
106 * Tests whether the IP version of this entry is IPv6.
107 *
108 * @return true if the IP version of this entry is IPv6, otherwise false.
109 */
110 public boolean isIp6() {
111 return ipPrefix.isIp6();
112 }
113
114 @Override
115 public int hashCode() {
116 return Objects.hash(ipPrefix, type);
117 }
118
119 @Override
120 public boolean equals(Object obj) {
121 if (obj == this) {
122 return true;
123 }
124
125 if (!(obj instanceof LocalIpPrefixEntry)) {
126 return false;
127 }
128
129 LocalIpPrefixEntry that = (LocalIpPrefixEntry) obj;
130 return Objects.equals(this.ipPrefix, that.ipPrefix)
131 && Objects.equals(this.type, that.type);
132 }
133
134 @Override
135 public String toString() {
136 return MoreObjects.toStringHelper(getClass())
137 .add("ipPrefix", ipPrefix)
138 .add("ipPrefixType", type)
139 .toString();
140 }
141}