blob: b4b8adbb1d14bfa4f031416e00e135cabf6ef002 [file] [log] [blame]
Yi Tseng51f1be92017-09-01 17:24:57 -07001/*
2 * Copyright 2017-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 com.google.common.collect.ArrayListMultimap;
20import com.google.common.collect.Multimap;
21import org.onlab.packet.VlanId;
22import org.onosproject.core.ApplicationId;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.config.Config;
25
26import java.util.concurrent.atomic.AtomicBoolean;
27
28public class IgnoreDhcpConfig extends Config<ApplicationId> {
29 public static final String KEY = "ignoreDhcp";
30 private static final String DEVICE_ID = "deviceId";
31 private static final String VLAN_ID = "vlan";
32
33 @Override
34 public boolean isValid() {
35 AtomicBoolean valid = new AtomicBoolean(true);
36 if (array == null) {
37 return false;
38 }
39 array.forEach(node -> {
40 valid.compareAndSet(true, node.has(DEVICE_ID) && node.has(VLAN_ID));
41 });
42 return valid.get();
43 }
44
45 public Multimap<DeviceId, VlanId> ignoredVlans() {
46 Multimap<DeviceId, VlanId> ignored = ArrayListMultimap.create();
47
48 array.forEach(node -> {
49 DeviceId deviceId = DeviceId.deviceId(node.get(DEVICE_ID).asText());
50 VlanId vlanId = VlanId.vlanId((short) node.get(VLAN_ID).asInt());
51 ignored.put(deviceId, vlanId);
52 });
53
54 return ignored;
55 }
56}