blob: 11a5d7ae53d2215e5591ad22ccfb51c723a81efe [file] [log] [blame]
gauravf0884562016-06-17 02:47:13 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
gauravf0884562016-06-17 02:47:13 +05303 *
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.dhcprelay;
17
18import org.onosproject.core.ApplicationId;
19import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.config.Config;
21
22import static org.onosproject.net.config.Config.FieldPresence.MANDATORY;
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080023import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL;
gaurav38351de2016-07-27 04:44:33 +053024import org.onlab.packet.Ip4Address;
gauravf0884562016-06-17 02:47:13 +053025/**
26 * DHCP Relay Config class.
27 */
28public class DhcpRelayConfig extends Config<ApplicationId> {
29
30 private static final String DHCP_CONNECT_POINT = "dhcpserverConnectPoint";
gaurav38351de2016-07-27 04:44:33 +053031 private static final String DHCP_SERVER_IP = "serverip";
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080032 private static final String DHCP_GATEWAY_IP = "gatewayip";
gauravf0884562016-06-17 02:47:13 +053033
34 @Override
35 public boolean isValid() {
36
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080037 return hasOnlyFields(DHCP_CONNECT_POINT, DHCP_SERVER_IP, DHCP_GATEWAY_IP) &&
gaurav38351de2016-07-27 04:44:33 +053038 isConnectPoint(DHCP_CONNECT_POINT, MANDATORY) &&
39 isIpAddress(DHCP_SERVER_IP, MANDATORY) &&
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080040 isIpAddress(DHCP_GATEWAY_IP, OPTIONAL);
gauravf0884562016-06-17 02:47:13 +053041 }
42
43 /**
44 * Returns the dhcp server connect point.
45 *
46 * @return dhcp server connect point
47 */
48 public ConnectPoint getDhcpServerConnectPoint() {
49 return ConnectPoint.deviceConnectPoint(object.path(DHCP_CONNECT_POINT).asText());
50 }
gaurav38351de2016-07-27 04:44:33 +053051
52 /**
53 * Returns the dhcp server ip.
54 *
55 * @return ip address or null if not set
56 */
57 public Ip4Address getDhcpServerIp() {
58 String ip = get(DHCP_SERVER_IP, null);
59 return ip != null ? Ip4Address.valueOf(ip) : null;
60 }
61
62 /**
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080063 * Returns the optional dhcp gateway ip, if configured. This option is
64 * typically used if the dhcp server is not directly attached to a switch;
65 * For example, the dhcp server may be reached via an external gateway connected
66 * to the dhcpserverConnectPoint.
gaurav38351de2016-07-27 04:44:33 +053067 *
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080068 * @return gateway ip or null if not set
gaurav38351de2016-07-27 04:44:33 +053069 */
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080070 public Ip4Address getDhcpGatewayIp() {
71 String gip = get(DHCP_GATEWAY_IP, null);
72 return gip != null ? Ip4Address.valueOf(gip) : null;
gaurav38351de2016-07-27 04:44:33 +053073 }
gauravf0884562016-06-17 02:47:13 +053074}