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