blob: 4353d6238d955e017eedb3a67a310f87d6d92711 [file] [log] [blame]
samanwita palf28207b2015-09-04 10:41:56 -07001/*
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 */
16package org.onosproject.dhcp.impl;
17
samanwita pal2a313402015-09-14 16:03:22 -070018import org.onlab.packet.Ip4Address;
19import org.onlab.packet.MacAddress;
samanwita palf28207b2015-09-04 10:41:56 -070020import org.onosproject.core.ApplicationId;
21import org.onosproject.net.config.Config;
22import org.onosproject.net.config.basics.BasicElementConfig;
23
24/**
25 * DHCP Config class.
26 */
Thomas Vachuskaa1da42e2015-09-09 00:45:22 -070027public class DhcpConfig extends Config<ApplicationId> {
samanwita palf28207b2015-09-04 10:41:56 -070028
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 pal2a313402015-09-14 16:03:22 -070039 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 palf28207b2015-09-04 10:41:56 -070043
samanwita pal7ccc2bc2015-09-14 19:53:15 -070044 public static final int DEFAULT = -1;
45
samanwita palf28207b2015-09-04 10:41:56 -070046 /**
47 * Returns the dhcp server ip.
48 *
49 * @return ip address or null if not set
50 */
samanwita pal2a313402015-09-14 16:03:22 -070051 public Ip4Address ip() {
52 String ip = get(MY_IP, null);
53 return ip != null ? Ip4Address.valueOf(ip) : null;
samanwita palf28207b2015-09-04 10:41:56 -070054 }
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 pal2a313402015-09-14 16:03:22 -070071 public MacAddress mac() {
72 String mac = get(MY_MAC, null);
73 return mac != null ? MacAddress.valueOf(mac) : null;
samanwita palf28207b2015-09-04 10:41:56 -070074 }
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 pal2a313402015-09-14 16:03:22 -070091 public Ip4Address subnetMask() {
92 String ip = get(SUBNET_MASK, null);
93 return ip != null ? Ip4Address.valueOf(ip) : null;
samanwita palf28207b2015-09-04 10:41:56 -070094 }
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 pal2a313402015-09-14 16:03:22 -0700111 public Ip4Address broadcastAddress() {
112 String ip = get(BROADCAST_ADDRESS, null);
113 return ip != null ? Ip4Address.valueOf(ip) : null;
samanwita palf28207b2015-09-04 10:41:56 -0700114 }
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 pal7ccc2bc2015-09-14 19:53:15 -0700129 * @return ttl or -1 if not set
samanwita palf28207b2015-09-04 10:41:56 -0700130 */
samanwita pal2a313402015-09-14 16:03:22 -0700131 public int ttl() {
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700132 return get(TTL, DEFAULT);
samanwita palf28207b2015-09-04 10:41:56 -0700133 }
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 pal2a313402015-09-14 16:03:22 -0700141 public BasicElementConfig ttl(int ttl) {
samanwita palf28207b2015-09-04 10:41:56 -0700142 return (BasicElementConfig) setOrClear(TTL, ttl);
143 }
144
145 /**
146 * Returns the Lease Time offered by the DHCP Server.
147 *
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700148 * @return lease time or -1 if not set
samanwita palf28207b2015-09-04 10:41:56 -0700149 */
samanwita pal2a313402015-09-14 16:03:22 -0700150 public int leaseTime() {
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700151 return get(LEASE_TIME, DEFAULT);
samanwita palf28207b2015-09-04 10:41:56 -0700152 }
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 pal2a313402015-09-14 16:03:22 -0700160 public BasicElementConfig leaseTime(int lease) {
samanwita palf28207b2015-09-04 10:41:56 -0700161 return (BasicElementConfig) setOrClear(LEASE_TIME, lease);
162 }
163
164 /**
165 * Returns the Renew Time offered by the DHCP Server.
166 *
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700167 * @return renew time or -1 if not set
samanwita palf28207b2015-09-04 10:41:56 -0700168 */
samanwita pal2a313402015-09-14 16:03:22 -0700169 public int renewTime() {
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700170 return get(RENEW_TIME, DEFAULT);
samanwita palf28207b2015-09-04 10:41:56 -0700171 }
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 pal2a313402015-09-14 16:03:22 -0700179 public BasicElementConfig renewTime(int renew) {
samanwita palf28207b2015-09-04 10:41:56 -0700180 return (BasicElementConfig) setOrClear(RENEW_TIME, renew);
181 }
182
183 /**
184 * Returns the Rebind Time offered by the DHCP Server.
185 *
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700186 * @return rebind time or -1 if not set
samanwita palf28207b2015-09-04 10:41:56 -0700187 */
samanwita pal2a313402015-09-14 16:03:22 -0700188 public int rebindTime() {
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700189 return get(REBIND_TIME, DEFAULT);
samanwita palf28207b2015-09-04 10:41:56 -0700190 }
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 pal2a313402015-09-14 16:03:22 -0700198 public BasicElementConfig rebindTime(int rebind) {
samanwita palf28207b2015-09-04 10:41:56 -0700199 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 pal2a313402015-09-14 16:03:22 -0700207 public Ip4Address routerAddress() {
208 String ip = get(ROUTER_ADDRESS, null);
209 return ip != null ? Ip4Address.valueOf(ip) : null;
samanwita palf28207b2015-09-04 10:41:56 -0700210 }
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 pal2a313402015-09-14 16:03:22 -0700227 public Ip4Address domainServer() {
228 String ip = get(DOMAIN_SERVER, null);
229 return ip != null ? Ip4Address.valueOf(ip) : null;
samanwita palf28207b2015-09-04 10:41:56 -0700230 }
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 pal2a313402015-09-14 16:03:22 -0700241
242 /**
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700243 * Returns the delay in minutes after which the dhcp server will purge expired entries.
samanwita pal2a313402015-09-14 16:03:22 -0700244 *
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700245 * @return time delay or -1 if not set
samanwita pal2a313402015-09-14 16:03:22 -0700246 */
247 public int timerDelay() {
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700248 return get(TIMER_DELAY, DEFAULT);
samanwita pal2a313402015-09-14 16:03:22 -0700249 }
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 pal7ccc2bc2015-09-14 19:53:15 -0700264 * @return default timeout or -1 if not set
samanwita pal2a313402015-09-14 16:03:22 -0700265 */
266 public int defaultTimeout() {
samanwita pal7ccc2bc2015-09-14 19:53:15 -0700267 return get(DEFAULT_TIMEOUT, DEFAULT);
samanwita pal2a313402015-09-14 16:03:22 -0700268 }
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 palf28207b2015-09-04 10:41:56 -0700319}