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 | */ |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 16 | package org.onosproject.openstacknetworking; |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 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 | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 22 | import org.onosproject.net.config.Config; |
| 23 | import org.slf4j.Logger; |
| 24 | |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 25 | import java.util.Map; |
| 26 | |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 27 | import static org.slf4j.LoggerFactory.getLogger; |
| 28 | |
| 29 | /** |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 30 | * Network Config for OpenstackNetworking application. |
| 31 | * |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 32 | */ |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 33 | public class OpenstackNetworkingConfig extends Config<String> { |
| 34 | |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 35 | 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"; |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 41 | |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 42 | 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 Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 48 | * Returns physical router mac. |
| 49 | * |
| 50 | * @return physical router mac |
| 51 | */ |
| 52 | public String physicalRouterMac() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 53 | return this.get(PHYSICAL_ROUTER_MAC, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns gateway's bridge id. |
| 58 | * |
| 59 | * @return bridge id |
| 60 | */ |
| 61 | public String gatewayBridgeId() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 62 | return this.get(GATEWAY_BRIDGE_ID, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns gateway's external interface name. |
| 67 | * |
| 68 | * @return external interface name |
| 69 | */ |
| 70 | public String gatewayExternalInterfaceName() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 71 | return this.get(GATEWAY_EXTERNAL_INTERFACE_NAME, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Returns gateway's external interface mac. |
| 76 | * |
| 77 | * @return external interface mac |
| 78 | */ |
| 79 | public String gatewayExternalInterfaceMac() { |
Daniel Park | 2319390 | 2016-03-24 18:17:19 +0900 | [diff] [blame] | 80 | return this.get(GATEWAY_EXTERNAL_INTERFACE_MAC, ""); |
Daniel Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 81 | } |
sangho | 4890754 | 2016-03-28 16:07:07 +0900 | [diff] [blame] | 82 | |
| 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 Park | 81a61a1 | 2016-02-26 08:24:44 +0900 | [diff] [blame] | 108 | } |