Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 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 | package org.onosproject.openstacknetworking.routing; |
| 17 | |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 18 | import com.fasterxml.jackson.databind.JsonNode; |
| 19 | import com.google.common.collect.Maps; |
| 20 | import org.onlab.packet.Ip4Address; |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 21 | import org.onosproject.core.ApplicationId; |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 22 | import org.onosproject.net.DeviceId; |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 23 | import org.onosproject.net.config.Config; |
| 24 | import org.slf4j.Logger; |
| 25 | |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 26 | import java.util.Map; |
| 27 | |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 28 | import static org.slf4j.LoggerFactory.getLogger; |
| 29 | |
| 30 | /** |
| 31 | * Configuration object for OpenstackRouting service. |
| 32 | */ |
| 33 | public 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 Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 40 | 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 Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Returns physical router mac. |
| 72 | * |
| 73 | * @return physical router mac |
| 74 | */ |
| 75 | public String physicalRouterMac() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 76 | return this.get(PHYSICAL_ROUTER_MAC, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns gateway's bridge id. |
| 81 | * |
| 82 | * @return bridge id |
| 83 | */ |
| 84 | public String gatewayBridgeId() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 85 | return this.get(GATEWAY_BRIDGE_ID, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Returns gateway's external interface name. |
| 90 | * |
| 91 | * @return external interface name |
| 92 | */ |
| 93 | public String gatewayExternalInterfaceName() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 94 | return this.get(GATEWAY_EXTERNAL_INTERFACE_NAME, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Returns gateway's external interface mac. |
| 99 | * |
| 100 | * @return external interface mac |
| 101 | */ |
| 102 | public String gatewayExternalInterfaceMac() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 103 | return this.get(GATEWAY_EXTERNAL_INTERFACE_MAC, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 104 | } |
| 105 | } |