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