blob: 78443cc2e60e6908e4e143fdcf8cdaa2731c06a6 [file] [log] [blame]
Daniel Park23193902016-03-24 18:17:19 +09001/*
2 * Copyright 2016 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 */
16package org.onosproject.openstacknetworking.switching;
17
18import com.fasterxml.jackson.databind.JsonNode;
19import com.google.common.collect.Maps;
20import org.onlab.packet.Ip4Address;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.config.Config;
24import org.slf4j.Logger;
25
26import java.util.Map;
27
28import static org.slf4j.LoggerFactory.getLogger;
29
30/**
31 * Configuration object for OpenstackSwitching service.
32 */
33public class OpenstackSwitchingConfig extends Config<ApplicationId> {
34
35 protected final Logger log = getLogger(getClass());
36
37 public static final String NODES = "nodes";
38 public static final String DATAPLANE_IP = "dataPlaneIp";
39 public static final String BRIDGE_ID = "bridgeId";
40
41 /**
42 * Returns the data plane IP map of nodes read from network config.
43 *
44 * @return data plane IP map
45 */
46 public Map<DeviceId, Ip4Address> nodes() {
47 Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
48
49 JsonNode jsonNodes = object.get(NODES);
50 if (jsonNodes == null) {
51 log.error("There's no node information");
52 return null;
53 }
54
55 jsonNodes.forEach(jsonNode -> {
56 try {
57 nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
58 Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
59 } catch (IllegalArgumentException | NullPointerException e) {
60 log.error("Failed to read {}", e.getMessage());
61 }
62 });
63 return nodeMap;
64 }
65}