samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
| 16 | package org.onosproject.dhcp.impl; |
| 17 | |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 18 | import org.onlab.packet.Ip4Address; |
| 19 | import org.onlab.packet.MacAddress; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 20 | import org.onosproject.core.ApplicationId; |
| 21 | import org.onosproject.net.config.Config; |
| 22 | import org.onosproject.net.config.basics.BasicElementConfig; |
| 23 | |
| 24 | /** |
| 25 | * DHCP Config class. |
| 26 | */ |
Thomas Vachuska | a1da42e | 2015-09-09 00:45:22 -0700 | [diff] [blame] | 27 | public class DhcpConfig extends Config<ApplicationId> { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 28 | |
| 29 | public static final String MY_IP = "ip"; |
| 30 | public static final String MY_MAC = "mac"; |
| 31 | public static final String SUBNET_MASK = "subnet"; |
| 32 | public static final String BROADCAST_ADDRESS = "broadcast"; |
| 33 | public static final String ROUTER_ADDRESS = "router"; |
| 34 | public static final String DOMAIN_SERVER = "domain"; |
| 35 | public static final String TTL = "ttl"; |
| 36 | public static final String LEASE_TIME = "lease"; |
| 37 | public static final String RENEW_TIME = "renew"; |
| 38 | public static final String REBIND_TIME = "rebind"; |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 39 | public static final String TIMER_DELAY = "delay"; |
| 40 | public static final String DEFAULT_TIMEOUT = "timeout"; |
| 41 | public static final String START_IP = "startip"; |
| 42 | public static final String END_IP = "endip"; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 43 | |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 44 | public static final int DEFAULT = -1; |
| 45 | |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 46 | /** |
| 47 | * Returns the dhcp server ip. |
| 48 | * |
| 49 | * @return ip address or null if not set |
| 50 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 51 | public Ip4Address ip() { |
| 52 | String ip = get(MY_IP, null); |
| 53 | return ip != null ? Ip4Address.valueOf(ip) : null; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Sets the dhcp server ip. |
| 58 | * |
| 59 | * @param ip new ip address; null to clear |
| 60 | * @return self |
| 61 | */ |
| 62 | public BasicElementConfig ip(String ip) { |
| 63 | return (BasicElementConfig) setOrClear(MY_IP, ip); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns the dhcp server mac. |
| 68 | * |
| 69 | * @return server mac or null if not set |
| 70 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 71 | public MacAddress mac() { |
| 72 | String mac = get(MY_MAC, null); |
| 73 | return mac != null ? MacAddress.valueOf(mac) : null; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Sets the dhcp server mac. |
| 78 | * |
| 79 | * @param mac new mac address; null to clear |
| 80 | * @return self |
| 81 | */ |
| 82 | public BasicElementConfig mac(String mac) { |
| 83 | return (BasicElementConfig) setOrClear(MY_MAC, mac); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Returns the subnet mask. |
| 88 | * |
| 89 | * @return subnet mask or null if not set |
| 90 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 91 | public Ip4Address subnetMask() { |
| 92 | String ip = get(SUBNET_MASK, null); |
| 93 | return ip != null ? Ip4Address.valueOf(ip) : null; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sets the subnet mask. |
| 98 | * |
| 99 | * @param subnet new subnet mask; null to clear |
| 100 | * @return self |
| 101 | */ |
| 102 | public BasicElementConfig subnetMask(String subnet) { |
| 103 | return (BasicElementConfig) setOrClear(SUBNET_MASK, subnet); |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Returns the broadcast address. |
| 108 | * |
| 109 | * @return broadcast address or null if not set |
| 110 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 111 | public Ip4Address broadcastAddress() { |
| 112 | String ip = get(BROADCAST_ADDRESS, null); |
| 113 | return ip != null ? Ip4Address.valueOf(ip) : null; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the broadcast address. |
| 118 | * |
| 119 | * @param broadcast new broadcast address; null to clear |
| 120 | * @return self |
| 121 | */ |
| 122 | public BasicElementConfig broadcastAddress(String broadcast) { |
| 123 | return (BasicElementConfig) setOrClear(BROADCAST_ADDRESS, broadcast); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Returns the Time To Live for the reply packets. |
| 128 | * |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 129 | * @return ttl or -1 if not set |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 130 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 131 | public int ttl() { |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 132 | return get(TTL, DEFAULT); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Sets the Time To Live for the reply packets. |
| 137 | * |
| 138 | * @param ttl new ttl; null to clear |
| 139 | * @return self |
| 140 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 141 | public BasicElementConfig ttl(int ttl) { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 142 | return (BasicElementConfig) setOrClear(TTL, ttl); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Returns the Lease Time offered by the DHCP Server. |
| 147 | * |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 148 | * @return lease time or -1 if not set |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 149 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 150 | public int leaseTime() { |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 151 | return get(LEASE_TIME, DEFAULT); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Sets the Lease Time offered by the DHCP Server. |
| 156 | * |
| 157 | * @param lease new lease time; null to clear |
| 158 | * @return self |
| 159 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 160 | public BasicElementConfig leaseTime(int lease) { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 161 | return (BasicElementConfig) setOrClear(LEASE_TIME, lease); |
| 162 | } |
| 163 | |
| 164 | /** |
| 165 | * Returns the Renew Time offered by the DHCP Server. |
| 166 | * |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 167 | * @return renew time or -1 if not set |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 168 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 169 | public int renewTime() { |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 170 | return get(RENEW_TIME, DEFAULT); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Sets the Renew Time offered by the DHCP Server. |
| 175 | * |
| 176 | * @param renew new renew time; null to clear |
| 177 | * @return self |
| 178 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 179 | public BasicElementConfig renewTime(int renew) { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 180 | return (BasicElementConfig) setOrClear(RENEW_TIME, renew); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Returns the Rebind Time offered by the DHCP Server. |
| 185 | * |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 186 | * @return rebind time or -1 if not set |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 187 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 188 | public int rebindTime() { |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 189 | return get(REBIND_TIME, DEFAULT); |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Sets the Rebind Time offered by the DHCP Server. |
| 194 | * |
| 195 | * @param rebind new rebind time; null to clear |
| 196 | * @return self |
| 197 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 198 | public BasicElementConfig rebindTime(int rebind) { |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 199 | return (BasicElementConfig) setOrClear(REBIND_TIME, rebind); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Returns the Router Address. |
| 204 | * |
| 205 | * @return router address or null if not set |
| 206 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 207 | public Ip4Address routerAddress() { |
| 208 | String ip = get(ROUTER_ADDRESS, null); |
| 209 | return ip != null ? Ip4Address.valueOf(ip) : null; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /** |
| 213 | * Sets the Router Address. |
| 214 | * |
| 215 | * @param router new router address; null to clear |
| 216 | * @return self |
| 217 | */ |
| 218 | public BasicElementConfig routerAddress(String router) { |
| 219 | return (BasicElementConfig) setOrClear(ROUTER_ADDRESS, router); |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Returns the Domain Server Address. |
| 224 | * |
| 225 | * @return domain server address or null if not set |
| 226 | */ |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 227 | public Ip4Address domainServer() { |
| 228 | String ip = get(DOMAIN_SERVER, null); |
| 229 | return ip != null ? Ip4Address.valueOf(ip) : null; |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Sets the Domain Server Address. |
| 234 | * |
| 235 | * @param domain new domain server address; null to clear |
| 236 | * @return self |
| 237 | */ |
| 238 | public BasicElementConfig domainServer(String domain) { |
| 239 | return (BasicElementConfig) setOrClear(DOMAIN_SERVER, domain); |
| 240 | } |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 241 | |
| 242 | /** |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 243 | * Returns the delay in minutes after which the dhcp server will purge expired entries. |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 244 | * |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 245 | * @return time delay or -1 if not set |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 246 | */ |
| 247 | public int timerDelay() { |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 248 | return get(TIMER_DELAY, DEFAULT); |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Sets the delay after which the dhcp server will purge expired entries. |
| 253 | * |
| 254 | * @param delay new time delay; null to clear |
| 255 | * @return self |
| 256 | */ |
| 257 | public BasicElementConfig timerDelay(int delay) { |
| 258 | return (BasicElementConfig) setOrClear(TIMER_DELAY, delay); |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Returns the default timeout for pending assignments. |
| 263 | * |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 264 | * @return default timeout or -1 if not set |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 265 | */ |
| 266 | public int defaultTimeout() { |
samanwita pal | 7ccc2bc | 2015-09-14 19:53:15 -0700 | [diff] [blame^] | 267 | return get(DEFAULT_TIMEOUT, DEFAULT); |
samanwita pal | 2a31340 | 2015-09-14 16:03:22 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Sets the default timeout for pending assignments. |
| 272 | * |
| 273 | * @param defaultTimeout new default timeout; null to clear |
| 274 | * @return self |
| 275 | */ |
| 276 | public BasicElementConfig defaultTimeout(int defaultTimeout) { |
| 277 | return (BasicElementConfig) setOrClear(DEFAULT_TIMEOUT, defaultTimeout); |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * Returns the start IP for the available IP Range. |
| 282 | * |
| 283 | * @return start IP or null if not set |
| 284 | */ |
| 285 | public Ip4Address startIp() { |
| 286 | String ip = get(START_IP, null); |
| 287 | return ip != null ? Ip4Address.valueOf(ip) : null; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Sets the start IP for the available IP Range. |
| 292 | * |
| 293 | * @param startIp new start IP; null to clear |
| 294 | * @return self |
| 295 | */ |
| 296 | public BasicElementConfig startIp(String startIp) { |
| 297 | return (BasicElementConfig) setOrClear(START_IP, startIp); |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Returns the end IP for the available IP Range. |
| 302 | * |
| 303 | * @return end IP or null if not set |
| 304 | */ |
| 305 | public Ip4Address endIp() { |
| 306 | String ip = get(END_IP, null); |
| 307 | return ip != null ? Ip4Address.valueOf(ip) : null; |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Sets the end IP for the available IP Range. |
| 312 | * |
| 313 | * @param endIp new end IP; null to clear |
| 314 | * @return self |
| 315 | */ |
| 316 | public BasicElementConfig endIp(String endIp) { |
| 317 | return (BasicElementConfig) setOrClear(END_IP, endIp); |
| 318 | } |
samanwita pal | f28207b | 2015-09-04 10:41:56 -0700 | [diff] [blame] | 319 | } |