blob: 2e36a5006c0af99d47e08887935560af3bb7a977 [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";
ke han29af27b2017-09-08 10:29:12 +080038 private static final Boolean DEFAULT_CONNECT_POINT_MODE = true;
39 private static final Boolean DEFAULT_PIMSSM_INTERWORKING = false;
Esin Karamaneff10392019-06-27 18:09:13 +000040 private static final Boolean DEFAULT_IGMP_PROVISIONING_SUPPORT = Boolean.FALSE;
ke han29af27b2017-09-08 10:29:12 +080041
ke han81a38b92017-03-10 18:41:44 +080042 protected static final String CONNECT_POINT_MODE = "globalConnectPointMode";
43 protected static final String CONNECT_POINT = "globalConnectPoint";
44 private static final String UNSOLICITED_TIMEOUT = "UnsolicitedTimeOut";
45 private static final String MAX_RESP = "MaxResp";
46 private static final String KEEP_ALIVE_INTERVAL = "KeepAliveInterval";
47 private static final String KEEP_ALIVE_COUNT = "KeepAliveCount";
48 private static final String LAST_QUERY_INTERVAL = "LastQueryInterval";
49 private static final String LAST_QUERY_COUNT = "LastQueryCount";
50 private static final String FAST_LEAVE = "FastLeave";
51 private static final String PERIODIC_QUERY = "PeriodicQuery";
52 private static final String IGMP_COS = "IgmpCos";
53 private static final String WITH_RA_UPLINK = "withRAUpLink";
54 private static final String WITH_RA_DOWN_LINK = "withRADownLink";
ke han29af27b2017-09-08 10:29:12 +080055 private static final String PIMSSM_INTERWORKING = "pimSSmInterworking";
Esin Karamaneff10392019-06-27 18:09:13 +000056 private static final String SOURCE_DEV_PORT = "sourceDeviceAndPort";
57 private static final String ENABLE_IGMP_PROVISIONING = "enableIgmpProvisioning";
58
ke han81a38b92017-03-10 18:41:44 +080059
60 /**
61 * Gets the value of a string property, protecting for an empty
62 * JSON object.
63 *
64 * @param name name of the property
65 * @param defaultValue default value if none has been specified
66 * @return String value if one os found, default value otherwise
67 */
68 private String getStringProperty(String name, String defaultValue) {
69 if (object == null) {
70 return defaultValue;
71 }
72 return get(name, defaultValue);
73 }
74
75 public int unsolicitedTimeOut() {
76 return Integer.parseInt(getStringProperty(UNSOLICITED_TIMEOUT, DEFAULT_UNSOLICITED_TIMEOUT));
77 }
78
79 public BasicElementConfig unsolicitedTimeOut(int timeout) {
80 return (BasicElementConfig) setOrClear(UNSOLICITED_TIMEOUT, timeout);
81 }
82
83 public int maxResp() {
84 return Integer.parseInt(getStringProperty(MAX_RESP, DEFAULT_MAX_RESP));
85 }
86
87 public BasicElementConfig maxResp(int maxResp) {
88 return (BasicElementConfig) setOrClear(MAX_RESP, maxResp);
89 }
90
91 public int keepAliveInterval() {
92 return Integer.parseInt(getStringProperty(KEEP_ALIVE_INTERVAL, DEFAULT_KEEP_ALIVE_INTERVAL));
93 }
94
95 public BasicElementConfig keepAliveInterval(int interval) {
96 return (BasicElementConfig) setOrClear(KEEP_ALIVE_INTERVAL, interval);
97 }
98
99 public int keepAliveCount() {
100 return Integer.parseInt(getStringProperty(KEEP_ALIVE_COUNT, DEFAULT_KEEP_ALIVE_COUNT));
101 }
102
103 public BasicElementConfig keepAliveCount(int count) {
104 return (BasicElementConfig) setOrClear(KEEP_ALIVE_COUNT, count);
105 }
106
107 public int lastQueryInterval() {
108 return Integer.parseInt(getStringProperty(LAST_QUERY_INTERVAL, DEFAULT_LAST_QUERY_INTERVAL));
109 }
110
111 public BasicElementConfig lastQueryInterval(int interval) {
112 return (BasicElementConfig) setOrClear(LAST_QUERY_INTERVAL, interval);
113 }
114
115 public int lastQueryCount() {
116 return Integer.parseInt(getStringProperty(LAST_QUERY_COUNT, DEFAULT_LAST_QUERY_COUNT));
117 }
118
119 public BasicElementConfig lastQueryCount(int count) {
120 return (BasicElementConfig) setOrClear(LAST_QUERY_COUNT, count);
121 }
122
123 public boolean fastLeave() {
124 if (object == null || object.path(FAST_LEAVE) == null) {
125 return DEFAULT_FAST_LEAVE;
126 }
127 return Boolean.parseBoolean(getStringProperty(FAST_LEAVE, DEFAULT_FAST_LEAVE.toString()));
128 }
129
130 public BasicElementConfig fastLeave(boolean fastLeave) {
131 return (BasicElementConfig) setOrClear(FAST_LEAVE, fastLeave);
132 }
133
134 public boolean periodicQuery() {
135 if (object == null || object.path(PERIODIC_QUERY) == null) {
136 return DEFAULT_PERIODIC_QUERY;
137 }
138 return Boolean.parseBoolean(getStringProperty(PERIODIC_QUERY, DEFAULT_PERIODIC_QUERY.toString()));
139 }
140
141 public BasicElementConfig periodicQuery(boolean periodicQuery) {
142 return (BasicElementConfig) setOrClear(PERIODIC_QUERY, periodicQuery);
143 }
144
145 public byte igmpCos() {
146 return Byte.parseByte(getStringProperty(IGMP_COS, DEFAULT_IGMP_COS));
147 }
148
149 public boolean withRAUplink() {
150 if (object == null || object.path(WITH_RA_UPLINK) == null) {
151 return true;
152 }
153 return Boolean.parseBoolean(getStringProperty(WITH_RA_UPLINK, DEFAULT_WITH_RA_UPLINK));
154 }
155
156 public boolean withRADownlink() {
157 if (object == null || object.path(WITH_RA_DOWN_LINK) == null) {
158 return false;
159 }
160 return Boolean.parseBoolean(getStringProperty(WITH_RA_DOWN_LINK, DEFAULT_WITH_RA_DOWNLINK));
161 }
162
163 public boolean connectPointMode() {
164 if (object == null || object.path(CONNECT_POINT_MODE) == null) {
165 return DEFAULT_CONNECT_POINT_MODE;
166 }
167 return Boolean.parseBoolean(getStringProperty(CONNECT_POINT_MODE, DEFAULT_CONNECT_POINT_MODE.toString()));
168 }
169
170 public ConnectPoint connectPoint() {
171 if (object == null || object.path(CONNECT_POINT) == null) {
172 return null;
173 }
174
ke han29af27b2017-09-08 10:29:12 +0800175 try {
176 return ConnectPoint.deviceConnectPoint(getStringProperty(CONNECT_POINT, ""));
177 } catch (Exception ex) {
178 return null;
179 }
180 }
181
182 public boolean pimSsmInterworking() {
183 if (object == null || object.path(PIMSSM_INTERWORKING) == null) {
184 return DEFAULT_PIMSSM_INTERWORKING;
185 }
186 return Boolean.parseBoolean(getStringProperty(PIMSSM_INTERWORKING, DEFAULT_PIMSSM_INTERWORKING.toString()));
ke han81a38b92017-03-10 18:41:44 +0800187 }
Esin Karamaneff10392019-06-27 18:09:13 +0000188
189 public ConnectPoint getSourceDeviceAndPort() {
190 if (object == null || object.path(SOURCE_DEV_PORT) == null) {
191 return null;
192 }
193
194 try {
195 return ConnectPoint.deviceConnectPoint(getStringProperty(SOURCE_DEV_PORT, ""));
196 } catch (Exception ex) {
197 return null;
198 }
199 }
200
201 public boolean enableIgmpProvisioning() {
202 if (object == null || object.path(ENABLE_IGMP_PROVISIONING) == null) {
203 return DEFAULT_IGMP_PROVISIONING_SUPPORT;
204 }
205 return Boolean.parseBoolean(getStringProperty(ENABLE_IGMP_PROVISIONING,
206 DEFAULT_IGMP_PROVISIONING_SUPPORT.toString()));
207 }
ke han81a38b92017-03-10 18:41:44 +0800208}