blob: 3c7b909906be0994ef5f658941923f9beb318fef [file] [log] [blame]
Jonathan Hart5af5f142016-01-28 18:45:27 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jonathan Hart5af5f142016-01-28 18:45:27 -08003 *
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
17package org.onosproject.pim.impl;
18
19import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.config.Config;
21
22import java.util.Optional;
23
24/**
25 * Configuration for a PIM interface.
26 */
27public class PimInterfaceConfig extends Config<ConnectPoint> {
28
29 private static final String INTERFACE_NAME = "interfaceName";
30 private static final String ENABLED = "enabled";
Jonathan Hart6be70952016-02-12 21:11:26 -080031 private static final String HELLO_INTERVAL = "helloInterval";
Jonathan Hart5af5f142016-01-28 18:45:27 -080032 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 Hart6be70952016-02-12 21:11:26 -080057 * 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 Hart5af5f142016-01-28 18:45:27 -080069 * 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 Hart9eb45bb2016-02-12 10:59:11 -0800115
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 Hart5af5f142016-01-28 18:45:27 -0800131}