Jonathan Hart | 5af5f14 | 2016-01-28 18:45:27 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 Open Networking Laboratory |
| 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"; |
| 31 | private static final String HOLD_TIME = "holdTime"; |
| 32 | private static final String PRIORITY = "priority"; |
| 33 | private static final String PROPAGATION_DELAY = "propagationDelay"; |
| 34 | private static final String OVERRIDE_INTERVAL = "overrideInterval"; |
| 35 | |
| 36 | /** |
| 37 | * Gets the name of the interface. This links the PIM configuration with |
| 38 | * an existing ONOS interface. |
| 39 | * |
| 40 | * @return interface name |
| 41 | */ |
| 42 | public String getInterfaceName() { |
| 43 | return node.path(INTERFACE_NAME).asText(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Returns whether PIM is enabled on the interface or not. |
| 48 | * |
| 49 | * @return true if PIM is enabled, otherwise false |
| 50 | */ |
| 51 | public boolean isEnabled() { |
| 52 | return node.path(ENABLED).asBoolean(false); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Gets the HELLO hold time of the interface. |
| 57 | * |
| 58 | * @return hold time |
| 59 | */ |
| 60 | public Optional<Short> getHoldTime() { |
| 61 | if (node.path(HOLD_TIME).isMissingNode()) { |
| 62 | return Optional.empty(); |
| 63 | } |
| 64 | return Optional.of(Short.parseShort(node.path(HOLD_TIME).asText())); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Gets the priority of the interface. |
| 69 | * |
| 70 | * @return priority |
| 71 | */ |
| 72 | public Optional<Integer> getPriority() { |
| 73 | if (node.path(PRIORITY).isMissingNode()) { |
| 74 | return Optional.empty(); |
| 75 | } |
| 76 | return Optional.of(node.path(PRIORITY).asInt()); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Gets the propagation delay of the interface. |
| 81 | * |
| 82 | * @return propagation delay |
| 83 | */ |
| 84 | public Optional<Short> getPropagationDelay() { |
| 85 | if (node.path(PROPAGATION_DELAY).isMissingNode()) { |
| 86 | return Optional.empty(); |
| 87 | } |
| 88 | return Optional.of(Short.parseShort(node.path(PROPAGATION_DELAY).asText())); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets the override interval of the interface. |
| 93 | * |
| 94 | * @return override interval |
| 95 | */ |
| 96 | public Optional<Short> getOverrideInterval() { |
| 97 | if (node.path(OVERRIDE_INTERVAL).isMissingNode()) { |
| 98 | return Optional.empty(); |
| 99 | } |
| 100 | return Optional.of(Short.parseShort(node.path(OVERRIDE_INTERVAL).asText())); |
| 101 | } |
| 102 | } |