Harshada Chaundkar | 670a4a9 | 2019-05-30 16:27:29 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 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 | |
| 17 | package org.onosproject.dhcprelay.config; |
| 18 | |
| 19 | import org.onosproject.core.ApplicationId; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | import org.onosproject.net.config.Config; |
| 22 | import java.util.Set; |
| 23 | import com.fasterxml.jackson.databind.JsonNode; |
| 24 | |
| 25 | import com.google.common.collect.Sets; |
| 26 | |
| 27 | /** |
| 28 | * Dhcp Host Auto Relearn Config. |
| 29 | */ |
| 30 | public class HostAutoRelearnConfig extends Config<ApplicationId> { |
| 31 | public static final String KEY = "hostAutoRelearnEnabledDevices"; |
| 32 | |
| 33 | @Override |
| 34 | public boolean isValid() { |
| 35 | if (array == null) { |
| 36 | return false; |
| 37 | } |
| 38 | try { |
| 39 | for (JsonNode node : array) { |
| 40 | DeviceId.deviceId(node.asText()); |
| 41 | } |
| 42 | } catch (IllegalArgumentException ex) { |
| 43 | return false; |
| 44 | } |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns Set of Devices on which Host Auto Relearn is enabled. |
| 50 | * |
| 51 | * @return Set of DeviceId where Host Auto Relearn is enabled. |
| 52 | */ |
| 53 | |
| 54 | public Set<DeviceId> hostAutoRelearnEnabledDevices() { |
| 55 | Set<DeviceId> enabledDevices = Sets.newHashSet(); |
| 56 | |
| 57 | array.forEach(node -> { |
| 58 | DeviceId deviceId = DeviceId.deviceId(node.asText()); |
| 59 | enabledDevices.add(deviceId); |
| 60 | }); |
| 61 | |
| 62 | return enabledDevices; |
| 63 | } |
| 64 | } |