blob: 90921d0e218b71e9c41a3fb94b66295571549063 [file] [log] [blame]
gauravf0884562016-06-17 02:47:13 +05301/*
2 * Copyright 2016-present 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.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;
gaurav38351de2016-07-27 04:44:33 +053023
24import org.onlab.packet.Ip4Address;
25import org.onlab.packet.MacAddress;
gauravf0884562016-06-17 02:47:13 +053026/**
27 * DHCP Relay Config class.
28 */
29public class DhcpRelayConfig extends Config<ApplicationId> {
30
31 private static final String DHCP_CONNECT_POINT = "dhcpserverConnectPoint";
gaurav38351de2016-07-27 04:44:33 +053032 private static final String DHCP_SERVER_IP = "serverip";
33 private static final String DHCP_SERVER_MAC = "servermac";
gauravf0884562016-06-17 02:47:13 +053034
35 @Override
36 public boolean isValid() {
37
gaurav38351de2016-07-27 04:44:33 +053038 return hasOnlyFields(DHCP_CONNECT_POINT, DHCP_SERVER_IP, DHCP_SERVER_MAC) &&
39 isConnectPoint(DHCP_CONNECT_POINT, MANDATORY) &&
40 isIpAddress(DHCP_SERVER_IP, MANDATORY) &&
41 isMacAddress(DHCP_SERVER_MAC, MANDATORY);
gauravf0884562016-06-17 02:47:13 +053042 }
43
44 /**
45 * Returns the dhcp server connect point.
46 *
47 * @return dhcp server connect point
48 */
49 public ConnectPoint getDhcpServerConnectPoint() {
50 return ConnectPoint.deviceConnectPoint(object.path(DHCP_CONNECT_POINT).asText());
51 }
gaurav38351de2016-07-27 04:44:33 +053052
53 /**
54 * Returns the dhcp server ip.
55 *
56 * @return ip address or null if not set
57 */
58 public Ip4Address getDhcpServerIp() {
59 String ip = get(DHCP_SERVER_IP, null);
60 return ip != null ? Ip4Address.valueOf(ip) : null;
61 }
62
63 /**
64 * Returns the dhcp server mac.
65 *
66 * @return server mac or null if not set
67 */
68 public MacAddress getDhcpServermac() {
69 String mac = get(DHCP_SERVER_MAC, null);
70 return mac != null ? MacAddress.valueOf(mac) : null;
71 }
gauravf0884562016-06-17 02:47:13 +053072}