blob: 85b8c9a1a2a1f14a6639d1a2d68c7077f9759919 [file] [log] [blame]
Harshada Chaundkar670a4a92019-05-30 16:27:29 +00001/*
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
17package org.onosproject.dhcprelay.config;
18
19import org.onosproject.core.ApplicationId;
20import org.onosproject.net.DeviceId;
21import org.onosproject.net.config.Config;
22import java.util.Set;
23import com.fasterxml.jackson.databind.JsonNode;
24
25import com.google.common.collect.Sets;
26
27/**
28 * Dhcp Host Auto Relearn Config.
29 */
30public 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}