blob: 0675a4b8cf833cf2ad6e1ba1d7b930d0521ff264 [file] [log] [blame]
Andrea Campanella241896c2017-05-10 13:11:04 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Andrea Campanella241896c2017-05-10 13:11:04 -07003 *
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.provider.general.device.api;
18
19import com.fasterxml.jackson.databind.JsonNode;
20import com.google.common.annotations.Beta;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.config.Config;
23
24import java.util.HashMap;
25import java.util.Map;
26
27/**
28 * Configuration for General device provider.
29 */
30@Beta
31public class GeneralProviderDeviceConfig extends Config<DeviceId> {
32
33 private static final String DEVICEKEYID = "deviceKeyId";
34
35
36 @Override
37 public boolean isValid() {
38 return true;
39 }
40
41 /**
42 * Gets the information of all protocols associated to the device.
43 *
44 * @return map of protocol name and relative information
45 */
46 public Map<String, DeviceInfoConfig> protocolsInfo() {
47 return getProtocolInfoMap();
48 }
49
50 private Map<String, DeviceInfoConfig> getProtocolInfoMap() {
51 Map<String, DeviceInfoConfig> deviceMap = new HashMap<>();
52 node.fieldNames().forEachRemaining(name -> {
53
54 Map<String, String> configMap = new HashMap<>();
55 JsonNode protocol = node.get(name);
56 protocol.fieldNames().forEachRemaining(info -> configMap.put(info, protocol.get(info).asText()));
57
58 String deviceKeyId = "";
59 if (protocol.has(DEVICEKEYID)) {
60 deviceKeyId = protocol.get(DEVICEKEYID).asText("");
61 }
62
63 deviceMap.put(name, new DeviceInfoConfig(configMap, deviceKeyId));
64 });
65 return deviceMap;
66 }
67
68}