David K. Bainbridge | d77028f | 2017-08-01 12:47:55 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 4d08470 | 2017-08-03 22:45:58 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
David K. Bainbridge | d77028f | 2017-08-01 12:47:55 -0700 | [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 | */ |
developer | e400c58 | 2020-03-24 19:42:08 +0100 | [diff] [blame] | 16 | package org.opencord.igmpproxy.impl; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 17 | |
| 18 | import org.onosproject.core.ApplicationId; |
| 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.config.Config; |
| 21 | import org.onosproject.net.config.basics.BasicElementConfig; |
| 22 | |
| 23 | /** |
| 24 | * Net configuration class for igmpproxy. |
| 25 | */ |
| 26 | public 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"; |
Esin Karaman | 586f1d6 | 2020-06-04 10:15:34 +0000 | [diff] [blame] | 34 | protected static final String DEFAULT_UNI_IGMP_COS = "7"; |
onurka | 85b2d9c | 2021-01-19 22:49:19 +0300 | [diff] [blame^] | 35 | protected static final String DEFAULT_NUMBER_OF_IGMP_REPORT_PROCESSOR_THREADS = "20"; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 36 | protected static final Boolean DEFAULT_FAST_LEAVE = false; |
| 37 | protected static final Boolean DEFAULT_PERIODIC_QUERY = true; |
| 38 | protected static final String DEFAULT_WITH_RA_UPLINK = "true"; |
| 39 | protected static final String DEFAULT_WITH_RA_DOWNLINK = "true"; |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 40 | private static final Boolean DEFAULT_CONNECT_POINT_MODE = true; |
| 41 | private static final Boolean DEFAULT_PIMSSM_INTERWORKING = false; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 42 | private static final Boolean DEFAULT_IGMP_PROVISIONING_SUPPORT = Boolean.FALSE; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 43 | private static final Boolean DEFAULT_IGMP_ON_POD_BASIS = Boolean.FALSE; |
Arjun E K | b0018fd | 2020-04-07 13:26:40 +0000 | [diff] [blame] | 44 | private static final Boolean DEFAULT_OUTGOING_IGMP_WITH_V3 = Boolean.TRUE; |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 45 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 46 | protected static final String CONNECT_POINT_MODE = "globalConnectPointMode"; |
| 47 | protected static final String CONNECT_POINT = "globalConnectPoint"; |
| 48 | private static final String UNSOLICITED_TIMEOUT = "UnsolicitedTimeOut"; |
| 49 | private static final String MAX_RESP = "MaxResp"; |
| 50 | private static final String KEEP_ALIVE_INTERVAL = "KeepAliveInterval"; |
| 51 | private static final String KEEP_ALIVE_COUNT = "KeepAliveCount"; |
| 52 | private static final String LAST_QUERY_INTERVAL = "LastQueryInterval"; |
| 53 | private static final String LAST_QUERY_COUNT = "LastQueryCount"; |
| 54 | private static final String FAST_LEAVE = "FastLeave"; |
| 55 | private static final String PERIODIC_QUERY = "PeriodicQuery"; |
| 56 | private static final String IGMP_COS = "IgmpCos"; |
Esin Karaman | 586f1d6 | 2020-06-04 10:15:34 +0000 | [diff] [blame] | 57 | private static final String IGMP_UNI_COS = "IgmpUniCos"; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 58 | private static final String WITH_RA_UPLINK = "withRAUpLink"; |
| 59 | private static final String WITH_RA_DOWN_LINK = "withRADownLink"; |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 60 | private static final String PIMSSM_INTERWORKING = "pimSSmInterworking"; |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 61 | private static final String SOURCE_DEV_PORT = "sourceDeviceAndPort"; |
| 62 | private static final String ENABLE_IGMP_PROVISIONING = "enableIgmpProvisioning"; |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 63 | private static final String IGMP_ON_POD_BASIS = "igmpOnPodBasis"; |
Arjun E K | b0018fd | 2020-04-07 13:26:40 +0000 | [diff] [blame] | 64 | private static final String OUTGOING_IGMP_WITH_V3 = "outgoingIgmpWithV3"; |
onurka | 85b2d9c | 2021-01-19 22:49:19 +0300 | [diff] [blame^] | 65 | private static final String NUMBER_OF_IGMP_REPORT_PROCESSOR_THREADS = "numberOfIgmpReportProcessorThreads"; |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Gets the value of a string property, protecting for an empty |
| 69 | * JSON object. |
| 70 | * |
onurka | 85b2d9c | 2021-01-19 22:49:19 +0300 | [diff] [blame^] | 71 | * @param name name of the property |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 72 | * @param defaultValue default value if none has been specified |
| 73 | * @return String value if one os found, default value otherwise |
| 74 | */ |
| 75 | private String getStringProperty(String name, String defaultValue) { |
| 76 | if (object == null) { |
| 77 | return defaultValue; |
| 78 | } |
| 79 | return get(name, defaultValue); |
| 80 | } |
| 81 | |
| 82 | public int unsolicitedTimeOut() { |
| 83 | return Integer.parseInt(getStringProperty(UNSOLICITED_TIMEOUT, DEFAULT_UNSOLICITED_TIMEOUT)); |
| 84 | } |
| 85 | |
| 86 | public BasicElementConfig unsolicitedTimeOut(int timeout) { |
| 87 | return (BasicElementConfig) setOrClear(UNSOLICITED_TIMEOUT, timeout); |
| 88 | } |
| 89 | |
| 90 | public int maxResp() { |
| 91 | return Integer.parseInt(getStringProperty(MAX_RESP, DEFAULT_MAX_RESP)); |
| 92 | } |
| 93 | |
| 94 | public BasicElementConfig maxResp(int maxResp) { |
| 95 | return (BasicElementConfig) setOrClear(MAX_RESP, maxResp); |
| 96 | } |
| 97 | |
| 98 | public int keepAliveInterval() { |
| 99 | return Integer.parseInt(getStringProperty(KEEP_ALIVE_INTERVAL, DEFAULT_KEEP_ALIVE_INTERVAL)); |
| 100 | } |
| 101 | |
| 102 | public BasicElementConfig keepAliveInterval(int interval) { |
| 103 | return (BasicElementConfig) setOrClear(KEEP_ALIVE_INTERVAL, interval); |
| 104 | } |
| 105 | |
| 106 | public int keepAliveCount() { |
| 107 | return Integer.parseInt(getStringProperty(KEEP_ALIVE_COUNT, DEFAULT_KEEP_ALIVE_COUNT)); |
| 108 | } |
| 109 | |
| 110 | public BasicElementConfig keepAliveCount(int count) { |
| 111 | return (BasicElementConfig) setOrClear(KEEP_ALIVE_COUNT, count); |
| 112 | } |
| 113 | |
| 114 | public int lastQueryInterval() { |
| 115 | return Integer.parseInt(getStringProperty(LAST_QUERY_INTERVAL, DEFAULT_LAST_QUERY_INTERVAL)); |
| 116 | } |
| 117 | |
| 118 | public BasicElementConfig lastQueryInterval(int interval) { |
| 119 | return (BasicElementConfig) setOrClear(LAST_QUERY_INTERVAL, interval); |
| 120 | } |
| 121 | |
| 122 | public int lastQueryCount() { |
| 123 | return Integer.parseInt(getStringProperty(LAST_QUERY_COUNT, DEFAULT_LAST_QUERY_COUNT)); |
| 124 | } |
| 125 | |
| 126 | public BasicElementConfig lastQueryCount(int count) { |
| 127 | return (BasicElementConfig) setOrClear(LAST_QUERY_COUNT, count); |
| 128 | } |
| 129 | |
| 130 | public boolean fastLeave() { |
| 131 | if (object == null || object.path(FAST_LEAVE) == null) { |
| 132 | return DEFAULT_FAST_LEAVE; |
| 133 | } |
| 134 | return Boolean.parseBoolean(getStringProperty(FAST_LEAVE, DEFAULT_FAST_LEAVE.toString())); |
| 135 | } |
| 136 | |
| 137 | public BasicElementConfig fastLeave(boolean fastLeave) { |
| 138 | return (BasicElementConfig) setOrClear(FAST_LEAVE, fastLeave); |
| 139 | } |
| 140 | |
| 141 | public boolean periodicQuery() { |
| 142 | if (object == null || object.path(PERIODIC_QUERY) == null) { |
| 143 | return DEFAULT_PERIODIC_QUERY; |
| 144 | } |
| 145 | return Boolean.parseBoolean(getStringProperty(PERIODIC_QUERY, DEFAULT_PERIODIC_QUERY.toString())); |
| 146 | } |
| 147 | |
| 148 | public BasicElementConfig periodicQuery(boolean periodicQuery) { |
| 149 | return (BasicElementConfig) setOrClear(PERIODIC_QUERY, periodicQuery); |
| 150 | } |
| 151 | |
| 152 | public byte igmpCos() { |
| 153 | return Byte.parseByte(getStringProperty(IGMP_COS, DEFAULT_IGMP_COS)); |
| 154 | } |
| 155 | |
Esin Karaman | 586f1d6 | 2020-06-04 10:15:34 +0000 | [diff] [blame] | 156 | public byte igmpUniCos() { |
| 157 | return Byte.parseByte(getStringProperty(IGMP_UNI_COS, DEFAULT_UNI_IGMP_COS)); |
| 158 | } |
| 159 | |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 160 | public boolean withRAUplink() { |
| 161 | if (object == null || object.path(WITH_RA_UPLINK) == null) { |
| 162 | return true; |
| 163 | } |
| 164 | return Boolean.parseBoolean(getStringProperty(WITH_RA_UPLINK, DEFAULT_WITH_RA_UPLINK)); |
| 165 | } |
| 166 | |
| 167 | public boolean withRADownlink() { |
| 168 | if (object == null || object.path(WITH_RA_DOWN_LINK) == null) { |
| 169 | return false; |
| 170 | } |
| 171 | return Boolean.parseBoolean(getStringProperty(WITH_RA_DOWN_LINK, DEFAULT_WITH_RA_DOWNLINK)); |
| 172 | } |
| 173 | |
| 174 | public boolean connectPointMode() { |
| 175 | if (object == null || object.path(CONNECT_POINT_MODE) == null) { |
| 176 | return DEFAULT_CONNECT_POINT_MODE; |
| 177 | } |
| 178 | return Boolean.parseBoolean(getStringProperty(CONNECT_POINT_MODE, DEFAULT_CONNECT_POINT_MODE.toString())); |
| 179 | } |
| 180 | |
| 181 | public ConnectPoint connectPoint() { |
| 182 | if (object == null || object.path(CONNECT_POINT) == null) { |
| 183 | return null; |
| 184 | } |
| 185 | |
ke han | 29af27b | 2017-09-08 10:29:12 +0800 | [diff] [blame] | 186 | try { |
| 187 | return ConnectPoint.deviceConnectPoint(getStringProperty(CONNECT_POINT, "")); |
| 188 | } catch (Exception ex) { |
| 189 | return null; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | public boolean pimSsmInterworking() { |
| 194 | if (object == null || object.path(PIMSSM_INTERWORKING) == null) { |
| 195 | return DEFAULT_PIMSSM_INTERWORKING; |
| 196 | } |
| 197 | return Boolean.parseBoolean(getStringProperty(PIMSSM_INTERWORKING, DEFAULT_PIMSSM_INTERWORKING.toString())); |
ke han | 81a38b9 | 2017-03-10 18:41:44 +0800 | [diff] [blame] | 198 | } |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 199 | |
| 200 | public ConnectPoint getSourceDeviceAndPort() { |
| 201 | if (object == null || object.path(SOURCE_DEV_PORT) == null) { |
| 202 | return null; |
| 203 | } |
| 204 | |
| 205 | try { |
| 206 | return ConnectPoint.deviceConnectPoint(getStringProperty(SOURCE_DEV_PORT, "")); |
| 207 | } catch (Exception ex) { |
| 208 | return null; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | public boolean enableIgmpProvisioning() { |
| 213 | if (object == null || object.path(ENABLE_IGMP_PROVISIONING) == null) { |
| 214 | return DEFAULT_IGMP_PROVISIONING_SUPPORT; |
| 215 | } |
| 216 | return Boolean.parseBoolean(getStringProperty(ENABLE_IGMP_PROVISIONING, |
onurka | 85b2d9c | 2021-01-19 22:49:19 +0300 | [diff] [blame^] | 217 | DEFAULT_IGMP_PROVISIONING_SUPPORT.toString())); |
Esin Karaman | eff1039 | 2019-06-27 18:09:13 +0000 | [diff] [blame] | 218 | } |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 219 | |
| 220 | public boolean igmpOnPodBasis() { |
| 221 | if (object == null || object.path(IGMP_ON_POD_BASIS) == null) { |
| 222 | return DEFAULT_IGMP_ON_POD_BASIS; |
| 223 | } |
| 224 | return Boolean.parseBoolean(getStringProperty(IGMP_ON_POD_BASIS, |
onurka | 85b2d9c | 2021-01-19 22:49:19 +0300 | [diff] [blame^] | 225 | DEFAULT_IGMP_ON_POD_BASIS.toString())); |
Esin Karaman | b38700c | 2019-09-17 13:01:25 +0000 | [diff] [blame] | 226 | } |
Arjun E K | b0018fd | 2020-04-07 13:26:40 +0000 | [diff] [blame] | 227 | |
| 228 | public Boolean outgoingIgmpWithV3() { |
| 229 | if (object == null || object.path(OUTGOING_IGMP_WITH_V3) == null) { |
| 230 | return null; |
| 231 | } |
| 232 | return Boolean.parseBoolean(getStringProperty(OUTGOING_IGMP_WITH_V3, DEFAULT_OUTGOING_IGMP_WITH_V3.toString())); |
| 233 | } |
onurka | 85b2d9c | 2021-01-19 22:49:19 +0300 | [diff] [blame^] | 234 | |
| 235 | public int numberOfIgmpReportProcessorThreads() { |
| 236 | return Integer.parseInt(getStringProperty(NUMBER_OF_IGMP_REPORT_PROCESSOR_THREADS, |
| 237 | DEFAULT_NUMBER_OF_IGMP_REPORT_PROCESSOR_THREADS)); |
| 238 | } |
| 239 | } |