Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [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.tetopology.management.impl; |
| 17 | |
| 18 | import org.onlab.packet.Ip4Address; |
| 19 | import org.onosproject.core.ApplicationId; |
Ray Milkey | 6c01374 | 2017-08-15 10:16:43 -0700 | [diff] [blame] | 20 | import org.onosproject.net.config.ConfigException; |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 21 | import org.onosproject.net.config.Config; |
| 22 | |
| 23 | /** |
| 24 | * Configuration for TE Topology parameters. |
| 25 | */ |
| 26 | public class TeTopologyConfig extends Config<ApplicationId> { |
| 27 | private static final String CONFIG_VALUE_ERROR = "Error parsing config value"; |
| 28 | private static final String PROVIDER_ID = "provider-id"; |
Yixiao Chen | 29f0633 | 2016-12-07 16:14:29 -0500 | [diff] [blame] | 29 | private static final String MDSC = "mdsc"; |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 30 | private static final String TENODE_ID_START = "tenode-id-start"; |
| 31 | private static final String TENODE_ID_END = "tenode-id-end"; |
| 32 | |
| 33 | /** |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 34 | * Retrieves TE topology provider identifier. |
| 35 | * |
| 36 | * @return provider Id |
| 37 | * @throws ConfigException if the parameters are not correctly configured |
| 38 | * or conversion of the parameters fails |
| 39 | */ |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 40 | public long providerId() throws ConfigException { |
| 41 | try { |
| 42 | return object.path(PROVIDER_ID).asLong(); |
| 43 | } catch (IllegalArgumentException e) { |
| 44 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 45 | } |
| 46 | } |
| 47 | |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 48 | /** |
| 49 | * Retrieves TE node starting IPv4 address. |
| 50 | * |
| 51 | * @return the IPv4 address |
| 52 | * @throws ConfigException if the parameters are not correctly configured |
| 53 | * or conversion of the parameters fails |
| 54 | */ |
| 55 | public Ip4Address teNodeIpStart() throws ConfigException { |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 56 | try { |
| 57 | return Ip4Address.valueOf(object.path(TENODE_ID_START).asText()); |
| 58 | } catch (IllegalArgumentException e) { |
| 59 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 60 | } |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 61 | } |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 62 | |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 63 | /** |
| 64 | * Retrieves TE node end IPv4 address. |
| 65 | * |
| 66 | * @return the IPv4 address |
| 67 | * @throws ConfigException if the parameters are not correctly configured |
| 68 | * or conversion of the parameters fails |
| 69 | */ |
| 70 | public Ip4Address teNodeIpEnd() throws ConfigException { |
| 71 | try { |
| 72 | return Ip4Address.valueOf(object.path(TENODE_ID_END).asText()); |
| 73 | } catch (IllegalArgumentException e) { |
| 74 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 75 | } |
| 76 | } |
Yixiao Chen | 29f0633 | 2016-12-07 16:14:29 -0500 | [diff] [blame] | 77 | |
Yixiao Chen | 265b3bb | 2017-01-13 10:17:03 -0500 | [diff] [blame] | 78 | /** |
| 79 | * Retrieves if this is a MDSC(Multi-Domain Super Controller). |
| 80 | * |
| 81 | * @return MDSC value |
| 82 | * @throws ConfigException if the parameters are not correctly configured or |
| 83 | * conversion of the parameters fails |
| 84 | */ |
| 85 | public String mdsc() throws ConfigException { |
| 86 | try { |
| 87 | return object.path(MDSC).asText(); |
| 88 | } catch (IllegalArgumentException e) { |
| 89 | throw new ConfigException(CONFIG_VALUE_ERROR, e); |
| 90 | } |
| 91 | } |
Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 92 | |
| 93 | } |