Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [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 | |
| 17 | package org.onosproject.pim.impl; |
| 18 | |
| 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.config.Config; |
| 21 | |
| 22 | import java.util.Optional; |
| 23 | |
| 24 | /** |
| 25 | * Configuration for a PIM interface. |
| 26 | */ |
| 27 | public class PimInterfaceConfig extends Config<ConnectPoint> { |
| 28 | |
| 29 | private static final String INTERFACE_NAME = "interfaceName"; |
| 30 | private static final String ENABLED = "enabled"; |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 31 | private static final String HELLO_INTERVAL = "helloInterval"; |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 32 | private static final String HOLD_TIME = "holdTime"; |
| 33 | private static final String PRIORITY = "priority"; |
| 34 | private static final String PROPAGATION_DELAY = "propagationDelay"; |
| 35 | private static final String OVERRIDE_INTERVAL = "overrideInterval"; |
| 36 | |
| 37 | /** |
| 38 | * Gets the name of the interface. This links the PIM configuration with |
| 39 | * an existing ONOS interface. |
| 40 | * |
| 41 | * @return interface name |
| 42 | */ |
| 43 | public String getInterfaceName() { |
| 44 | return node.path(INTERFACE_NAME).asText(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns whether PIM is enabled on the interface or not. |
| 49 | * |
| 50 | * @return true if PIM is enabled, otherwise false |
| 51 | */ |
| 52 | public boolean isEnabled() { |
| 53 | return node.path(ENABLED).asBoolean(false); |
| 54 | } |
| 55 | |
| 56 | /** |
Jonathan Hart | 6be7095 | 2016-02-12 21:11:26 -0800 | [diff] [blame] | 57 | * Gets the hello interval of the interface. |
| 58 | * |
| 59 | * @return hello interval |
| 60 | */ |
| 61 | public Optional<Integer> getHelloInterval() { |
| 62 | if (node.path(HELLO_INTERVAL).isMissingNode()) { |
| 63 | return Optional.empty(); |
| 64 | } |
| 65 | return Optional.of(Integer.parseInt(node.path(HELLO_INTERVAL).asText())); |
| 66 | } |
| 67 | |
| 68 | /** |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 69 | * Gets the HELLO hold time of the interface. |
| 70 | * |
| 71 | * @return hold time |
| 72 | */ |
| 73 | public Optional<Short> getHoldTime() { |
| 74 | if (node.path(HOLD_TIME).isMissingNode()) { |
| 75 | return Optional.empty(); |
| 76 | } |
| 77 | return Optional.of(Short.parseShort(node.path(HOLD_TIME).asText())); |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Gets the priority of the interface. |
| 82 | * |
| 83 | * @return priority |
| 84 | */ |
| 85 | public Optional<Integer> getPriority() { |
| 86 | if (node.path(PRIORITY).isMissingNode()) { |
| 87 | return Optional.empty(); |
| 88 | } |
| 89 | return Optional.of(node.path(PRIORITY).asInt()); |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Gets the propagation delay of the interface. |
| 94 | * |
| 95 | * @return propagation delay |
| 96 | */ |
| 97 | public Optional<Short> getPropagationDelay() { |
| 98 | if (node.path(PROPAGATION_DELAY).isMissingNode()) { |
| 99 | return Optional.empty(); |
| 100 | } |
| 101 | return Optional.of(Short.parseShort(node.path(PROPAGATION_DELAY).asText())); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Gets the override interval of the interface. |
| 106 | * |
| 107 | * @return override interval |
| 108 | */ |
| 109 | public Optional<Short> getOverrideInterval() { |
| 110 | if (node.path(OVERRIDE_INTERVAL).isMissingNode()) { |
| 111 | return Optional.empty(); |
| 112 | } |
| 113 | return Optional.of(Short.parseShort(node.path(OVERRIDE_INTERVAL).asText())); |
| 114 | } |
Jonathan Hart | 9eb45bb | 2016-02-12 10:59:11 -0800 | [diff] [blame] | 115 | |
| 116 | @Override |
| 117 | public boolean isValid() { |
| 118 | if (!hasOnlyFields(INTERFACE_NAME, ENABLED, HELLO_INTERVAL, HOLD_TIME, |
| 119 | PRIORITY, PROPAGATION_DELAY, OVERRIDE_INTERVAL)) { |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | return isString(INTERFACE_NAME, FieldPresence.MANDATORY) && |
| 124 | isBoolean(ENABLED, FieldPresence.MANDATORY) && |
| 125 | isIntegralNumber(HELLO_INTERVAL, FieldPresence.OPTIONAL) && |
| 126 | isIntegralNumber(HOLD_TIME, FieldPresence.OPTIONAL) && |
| 127 | isIntegralNumber(PRIORITY, FieldPresence.OPTIONAL) && |
| 128 | isIntegralNumber(PROPAGATION_DELAY, FieldPresence.OPTIONAL) && |
| 129 | isIntegralNumber(OVERRIDE_INTERVAL, FieldPresence.OPTIONAL); |
| 130 | } |
Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame] | 131 | } |