blob: 107c2629a4342c09b4ac86c580451a6803befc5a [file] [log] [blame]
David K. Bainbridged77028f2017-08-01 12:47:55 -07001/*
Brian O'Connor4d084702017-08-03 22:45:58 -07002 * Copyright 2017-present Open Networking Foundation
David K. Bainbridged77028f2017-08-01 12:47:55 -07003 *
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 */
ke han81a38b92017-03-10 18:41:44 +080016package org.opencord.igmpproxy;
17
18import org.onosproject.core.ApplicationId;
19import org.onosproject.net.ConnectPoint;
20import org.onosproject.net.config.Config;
21import org.onosproject.net.config.basics.BasicElementConfig;
22
23/**
24 * Net configuration class for igmpproxy.
25 */
26public class IgmpproxyConfig extends Config<ApplicationId> {
27 protected static final String DEFAULT_UNSOLICITED_TIMEOUT = "2";
28 protected static final String DEFAULT_MAX_RESP = "10";
29 protected static final String DEFAULT_KEEP_ALIVE_INTERVAL = "120";
30 protected static final String DEFAULT_KEEP_ALIVE_COUNT = "3";
31 protected static final String DEFAULT_LAST_QUERY_INTERVAL = "2";
32 protected static final String DEFAULT_LAST_QUERY_COUNT = "2";
33 protected static final String DEFAULT_IGMP_COS = "7";
34 protected static final Boolean DEFAULT_FAST_LEAVE = false;
35 protected static final Boolean DEFAULT_PERIODIC_QUERY = true;
36 protected static final String DEFAULT_WITH_RA_UPLINK = "true";
37 protected static final String DEFAULT_WITH_RA_DOWNLINK = "true";
38 protected static final String CONNECT_POINT_MODE = "globalConnectPointMode";
39 protected static final String CONNECT_POINT = "globalConnectPoint";
40 private static final String UNSOLICITED_TIMEOUT = "UnsolicitedTimeOut";
41 private static final String MAX_RESP = "MaxResp";
42 private static final String KEEP_ALIVE_INTERVAL = "KeepAliveInterval";
43 private static final String KEEP_ALIVE_COUNT = "KeepAliveCount";
44 private static final String LAST_QUERY_INTERVAL = "LastQueryInterval";
45 private static final String LAST_QUERY_COUNT = "LastQueryCount";
46 private static final String FAST_LEAVE = "FastLeave";
47 private static final String PERIODIC_QUERY = "PeriodicQuery";
48 private static final String IGMP_COS = "IgmpCos";
49 private static final String WITH_RA_UPLINK = "withRAUpLink";
50 private static final String WITH_RA_DOWN_LINK = "withRADownLink";
51 private static final Boolean DEFAULT_CONNECT_POINT_MODE = true;
52
53 /**
54 * Gets the value of a string property, protecting for an empty
55 * JSON object.
56 *
57 * @param name name of the property
58 * @param defaultValue default value if none has been specified
59 * @return String value if one os found, default value otherwise
60 */
61 private String getStringProperty(String name, String defaultValue) {
62 if (object == null) {
63 return defaultValue;
64 }
65 return get(name, defaultValue);
66 }
67
68 public int unsolicitedTimeOut() {
69 return Integer.parseInt(getStringProperty(UNSOLICITED_TIMEOUT, DEFAULT_UNSOLICITED_TIMEOUT));
70 }
71
72 public BasicElementConfig unsolicitedTimeOut(int timeout) {
73 return (BasicElementConfig) setOrClear(UNSOLICITED_TIMEOUT, timeout);
74 }
75
76 public int maxResp() {
77 return Integer.parseInt(getStringProperty(MAX_RESP, DEFAULT_MAX_RESP));
78 }
79
80 public BasicElementConfig maxResp(int maxResp) {
81 return (BasicElementConfig) setOrClear(MAX_RESP, maxResp);
82 }
83
84 public int keepAliveInterval() {
85 return Integer.parseInt(getStringProperty(KEEP_ALIVE_INTERVAL, DEFAULT_KEEP_ALIVE_INTERVAL));
86 }
87
88 public BasicElementConfig keepAliveInterval(int interval) {
89 return (BasicElementConfig) setOrClear(KEEP_ALIVE_INTERVAL, interval);
90 }
91
92 public int keepAliveCount() {
93 return Integer.parseInt(getStringProperty(KEEP_ALIVE_COUNT, DEFAULT_KEEP_ALIVE_COUNT));
94 }
95
96 public BasicElementConfig keepAliveCount(int count) {
97 return (BasicElementConfig) setOrClear(KEEP_ALIVE_COUNT, count);
98 }
99
100 public int lastQueryInterval() {
101 return Integer.parseInt(getStringProperty(LAST_QUERY_INTERVAL, DEFAULT_LAST_QUERY_INTERVAL));
102 }
103
104 public BasicElementConfig lastQueryInterval(int interval) {
105 return (BasicElementConfig) setOrClear(LAST_QUERY_INTERVAL, interval);
106 }
107
108 public int lastQueryCount() {
109 return Integer.parseInt(getStringProperty(LAST_QUERY_COUNT, DEFAULT_LAST_QUERY_COUNT));
110 }
111
112 public BasicElementConfig lastQueryCount(int count) {
113 return (BasicElementConfig) setOrClear(LAST_QUERY_COUNT, count);
114 }
115
116 public boolean fastLeave() {
117 if (object == null || object.path(FAST_LEAVE) == null) {
118 return DEFAULT_FAST_LEAVE;
119 }
120 return Boolean.parseBoolean(getStringProperty(FAST_LEAVE, DEFAULT_FAST_LEAVE.toString()));
121 }
122
123 public BasicElementConfig fastLeave(boolean fastLeave) {
124 return (BasicElementConfig) setOrClear(FAST_LEAVE, fastLeave);
125 }
126
127 public boolean periodicQuery() {
128 if (object == null || object.path(PERIODIC_QUERY) == null) {
129 return DEFAULT_PERIODIC_QUERY;
130 }
131 return Boolean.parseBoolean(getStringProperty(PERIODIC_QUERY, DEFAULT_PERIODIC_QUERY.toString()));
132 }
133
134 public BasicElementConfig periodicQuery(boolean periodicQuery) {
135 return (BasicElementConfig) setOrClear(PERIODIC_QUERY, periodicQuery);
136 }
137
138 public byte igmpCos() {
139 return Byte.parseByte(getStringProperty(IGMP_COS, DEFAULT_IGMP_COS));
140 }
141
142 public boolean withRAUplink() {
143 if (object == null || object.path(WITH_RA_UPLINK) == null) {
144 return true;
145 }
146 return Boolean.parseBoolean(getStringProperty(WITH_RA_UPLINK, DEFAULT_WITH_RA_UPLINK));
147 }
148
149 public boolean withRADownlink() {
150 if (object == null || object.path(WITH_RA_DOWN_LINK) == null) {
151 return false;
152 }
153 return Boolean.parseBoolean(getStringProperty(WITH_RA_DOWN_LINK, DEFAULT_WITH_RA_DOWNLINK));
154 }
155
156 public boolean connectPointMode() {
157 if (object == null || object.path(CONNECT_POINT_MODE) == null) {
158 return DEFAULT_CONNECT_POINT_MODE;
159 }
160 return Boolean.parseBoolean(getStringProperty(CONNECT_POINT_MODE, DEFAULT_CONNECT_POINT_MODE.toString()));
161 }
162
163 public ConnectPoint connectPoint() {
164 if (object == null || object.path(CONNECT_POINT) == null) {
165 return null;
166 }
167
168 return ConnectPoint.deviceConnectPoint(getStringProperty(CONNECT_POINT, ""));
169 }
170}