blob: 0ed84116662df71dcd5b1b8dd008ff311fa75b2a [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() {
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080036 return hasOnlyFields(DHCP_CONNECT_POINT, DHCP_SERVER_IP, DHCP_GATEWAY_IP) &&
gaurav38351de2016-07-27 04:44:33 +053037 isConnectPoint(DHCP_CONNECT_POINT, MANDATORY) &&
38 isIpAddress(DHCP_SERVER_IP, MANDATORY) &&
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080039 isIpAddress(DHCP_GATEWAY_IP, OPTIONAL);
gauravf0884562016-06-17 02:47:13 +053040 }
41
42 /**
43 * Returns the dhcp server connect point.
44 *
45 * @return dhcp server connect point
46 */
47 public ConnectPoint getDhcpServerConnectPoint() {
48 return ConnectPoint.deviceConnectPoint(object.path(DHCP_CONNECT_POINT).asText());
49 }
gaurav38351de2016-07-27 04:44:33 +053050
51 /**
52 * Returns the dhcp server ip.
53 *
54 * @return ip address or null if not set
55 */
56 public Ip4Address getDhcpServerIp() {
57 String ip = get(DHCP_SERVER_IP, null);
58 return ip != null ? Ip4Address.valueOf(ip) : null;
59 }
60
61 /**
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080062 * Returns the optional dhcp gateway ip, if configured. This option is
63 * typically used if the dhcp server is not directly attached to a switch;
64 * For example, the dhcp server may be reached via an external gateway connected
65 * to the dhcpserverConnectPoint.
gaurav38351de2016-07-27 04:44:33 +053066 *
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080067 * @return gateway ip or null if not set
gaurav38351de2016-07-27 04:44:33 +053068 */
Saurav Dasb0ae6ee2017-03-04 16:08:47 -080069 public Ip4Address getDhcpGatewayIp() {
70 String gip = get(DHCP_GATEWAY_IP, null);
71 return gip != null ? Ip4Address.valueOf(gip) : null;
gaurav38351de2016-07-27 04:44:33 +053072 }
gauravf0884562016-06-17 02:47:13 +053073}