gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.dhcprelay; |
| 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.config.Config; |
| 21 | |
| 22 | import static org.onosproject.net.config.Config.FieldPresence.MANDATORY; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 23 | |
| 24 | import org.onlab.packet.Ip4Address; |
| 25 | import org.onlab.packet.MacAddress; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 26 | /** |
| 27 | * DHCP Relay Config class. |
| 28 | */ |
| 29 | public class DhcpRelayConfig extends Config<ApplicationId> { |
| 30 | |
| 31 | private static final String DHCP_CONNECT_POINT = "dhcpserverConnectPoint"; |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 32 | private static final String DHCP_SERVER_IP = "serverip"; |
| 33 | private static final String DHCP_SERVER_MAC = "servermac"; |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 34 | |
| 35 | @Override |
| 36 | public boolean isValid() { |
| 37 | |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 38 | 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); |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 42 | } |
| 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 | } |
gaurav | 38351de | 2016-07-27 04:44:33 +0530 | [diff] [blame] | 52 | |
| 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 | } |
gaurav | f088456 | 2016-06-17 02:47:13 +0530 | [diff] [blame] | 72 | } |