blob: d539c58ce5600ee099fded89e0033f56785bfc06 [file] [log] [blame]
Daniel Park81a61a12016-02-26 08:24:44 +09001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Daniel Park81a61a12016-02-26 08:24:44 +09003 *
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 */
sangho48907542016-03-28 16:07:07 +090016package org.onosproject.openstacknetworking;
Daniel Park81a61a12016-02-26 08:24:44 +090017
Daniel Park23193902016-03-24 18:17:19 +090018import com.fasterxml.jackson.databind.JsonNode;
19import com.google.common.collect.Maps;
20import org.onlab.packet.Ip4Address;
Daniel Park23193902016-03-24 18:17:19 +090021import org.onosproject.net.DeviceId;
Daniel Park81a61a12016-02-26 08:24:44 +090022import org.onosproject.net.config.Config;
23import org.slf4j.Logger;
24
Daniel Park23193902016-03-24 18:17:19 +090025import java.util.Map;
26
Daniel Park81a61a12016-02-26 08:24:44 +090027import static org.slf4j.LoggerFactory.getLogger;
28
29/**
sangho48907542016-03-28 16:07:07 +090030 * Network Config for OpenstackNetworking application.
31 *
Daniel Park81a61a12016-02-26 08:24:44 +090032 */
sangho48907542016-03-28 16:07:07 +090033public class OpenstackNetworkingConfig extends Config<String> {
34
Daniel Park81a61a12016-02-26 08:24:44 +090035 protected final Logger log = getLogger(getClass());
36
37 public static final String PHYSICAL_ROUTER_MAC = "physicalRouterMac";
38 public static final String GATEWAY_BRIDGE_ID = "gatewayBridgeId";
39 public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName";
40 public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac";
sangho48907542016-03-28 16:07:07 +090041
Daniel Park23193902016-03-24 18:17:19 +090042 public static final String NODES = "nodes";
43 public static final String DATAPLANE_IP = "dataPlaneIp";
44 public static final String BRIDGE_ID = "bridgeId";
45
46
47 /**
Daniel Park81a61a12016-02-26 08:24:44 +090048 * Returns physical router mac.
49 *
50 * @return physical router mac
51 */
52 public String physicalRouterMac() {
Daniel Park23193902016-03-24 18:17:19 +090053 return this.get(PHYSICAL_ROUTER_MAC, "");
Daniel Park81a61a12016-02-26 08:24:44 +090054 }
55
56 /**
57 * Returns gateway's bridge id.
58 *
59 * @return bridge id
60 */
61 public String gatewayBridgeId() {
Daniel Park23193902016-03-24 18:17:19 +090062 return this.get(GATEWAY_BRIDGE_ID, "");
Daniel Park81a61a12016-02-26 08:24:44 +090063 }
64
65 /**
66 * Returns gateway's external interface name.
67 *
68 * @return external interface name
69 */
70 public String gatewayExternalInterfaceName() {
Daniel Park23193902016-03-24 18:17:19 +090071 return this.get(GATEWAY_EXTERNAL_INTERFACE_NAME, "");
Daniel Park81a61a12016-02-26 08:24:44 +090072 }
73
74 /**
75 * Returns gateway's external interface mac.
76 *
77 * @return external interface mac
78 */
79 public String gatewayExternalInterfaceMac() {
Daniel Park23193902016-03-24 18:17:19 +090080 return this.get(GATEWAY_EXTERNAL_INTERFACE_MAC, "");
Daniel Park81a61a12016-02-26 08:24:44 +090081 }
sangho48907542016-03-28 16:07:07 +090082
83 /**
84 * Returns the data plane IP map of nodes read from network config.
85 *
86 * @return data plane IP map
87 */
88 public Map<DeviceId, Ip4Address> nodes() {
89 Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
90
91 JsonNode jsonNodes = object.get(NODES);
92 if (jsonNodes == null) {
93 log.error("There's no node information");
94 return null;
95 }
96
97 jsonNodes.forEach(jsonNode -> {
98 try {
99 nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
100 Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
101 } catch (IllegalArgumentException | NullPointerException e) {
102 log.error("Failed to read {}", e.toString());
103 }
104 });
105 return nodeMap;
106 }
107
Daniel Park81a61a12016-02-26 08:24:44 +0900108}