blob: 7c9f126b8bd266cc8fd3e08558c027cb30ed2491 [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 */
16package org.onosproject.openstacknetworking.routing;
17
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 Park81a61a12016-02-26 08:24:44 +090021import org.onosproject.core.ApplicationId;
Daniel Park23193902016-03-24 18:17:19 +090022import org.onosproject.net.DeviceId;
Daniel Park81a61a12016-02-26 08:24:44 +090023import org.onosproject.net.config.Config;
24import org.slf4j.Logger;
25
Daniel Park23193902016-03-24 18:17:19 +090026import java.util.Map;
27
Daniel Park81a61a12016-02-26 08:24:44 +090028import static org.slf4j.LoggerFactory.getLogger;
29
30/**
31 * Configuration object for OpenstackRouting service.
32 */
33public class OpenstackRoutingConfig extends Config<ApplicationId> {
34 protected final Logger log = getLogger(getClass());
35
36 public static final String PHYSICAL_ROUTER_MAC = "physicalRouterMac";
37 public static final String GATEWAY_BRIDGE_ID = "gatewayBridgeId";
38 public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName";
39 public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac";
Daniel Park23193902016-03-24 18:17:19 +090040 public static final String NODES = "nodes";
41 public static final String DATAPLANE_IP = "dataPlaneIp";
42 public static final String BRIDGE_ID = "bridgeId";
43
44
45 /**
46 * Returns the data plane IP map of nodes read from network config.
47 *
48 * @return data plane IP map
49 */
50 public Map<DeviceId, Ip4Address> nodes() {
51 Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
52
53 JsonNode jsonNodes = object.get(NODES);
54 if (jsonNodes == null) {
55 log.error("There's no node information");
56 return null;
57 }
58
59 jsonNodes.forEach(jsonNode -> {
60 try {
61 nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
62 Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
63 } catch (IllegalArgumentException | NullPointerException e) {
64 log.error("Failed to read {}", e.toString());
65 }
66 });
67 return nodeMap;
68 }
Daniel Park81a61a12016-02-26 08:24:44 +090069
70 /**
71 * Returns physical router mac.
72 *
73 * @return physical router mac
74 */
75 public String physicalRouterMac() {
Daniel Park23193902016-03-24 18:17:19 +090076 return this.get(PHYSICAL_ROUTER_MAC, "");
Daniel Park81a61a12016-02-26 08:24:44 +090077 }
78
79 /**
80 * Returns gateway's bridge id.
81 *
82 * @return bridge id
83 */
84 public String gatewayBridgeId() {
Daniel Park23193902016-03-24 18:17:19 +090085 return this.get(GATEWAY_BRIDGE_ID, "");
Daniel Park81a61a12016-02-26 08:24:44 +090086 }
87
88 /**
89 * Returns gateway's external interface name.
90 *
91 * @return external interface name
92 */
93 public String gatewayExternalInterfaceName() {
Daniel Park23193902016-03-24 18:17:19 +090094 return this.get(GATEWAY_EXTERNAL_INTERFACE_NAME, "");
Daniel Park81a61a12016-02-26 08:24:44 +090095 }
96
97 /**
98 * Returns gateway's external interface mac.
99 *
100 * @return external interface mac
101 */
102 public String gatewayExternalInterfaceMac() {
Daniel Park23193902016-03-24 18:17:19 +0900103 return this.get(GATEWAY_EXTERNAL_INTERFACE_MAC, "");
Daniel Park81a61a12016-02-26 08:24:44 +0900104 }
105}