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