Committed by
Gerrit Code Review
[ONOS-4849] NETCONF function for FUJITSU OLT #6
- Add alart command for FUJITSU OLT volt-notification-alertfilter <netconf:target> volt-notification-setalertfilter <netconf:target> <alert-severity> volt-notification-subscribe <netconf:target> {disable} - Update fujitsu-drivers.xml and shell-config.xml in FUJITSU directory - Apply Yuta's and Andrea's suggestion to startSubscription method and other methods which related to startSubscription method. -> Remove startSubscriptionConnection() and createSubscriptionString() method in 4th patch-set. -> Modify cosmetic issue related to Static-string. -> Update "No replay" to "No reply" in VoltGetPonLinksCommand.java Change-Id: I2c8d5484ea0ff9f0b1b970fe8b183bec12193c46
Showing
10 changed files
with
430 additions
and
11 deletions
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/FujitsuVoltAlertConfig.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
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 | + */ | ||
16 | + | ||
17 | +package org.onosproject.drivers.fujitsu; | ||
18 | + | ||
19 | +import org.onosproject.net.DeviceId; | ||
20 | +import org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig; | ||
21 | +import org.onosproject.net.driver.AbstractHandlerBehaviour; | ||
22 | +import org.onosproject.net.driver.DriverHandler; | ||
23 | +import org.onosproject.netconf.NetconfController; | ||
24 | +import org.onosproject.mastership.MastershipService; | ||
25 | +import org.slf4j.Logger; | ||
26 | + | ||
27 | +import java.io.IOException; | ||
28 | +import java.util.Set; | ||
29 | + | ||
30 | +import com.google.common.collect.ImmutableSet; | ||
31 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
32 | +import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; | ||
33 | +import static org.slf4j.LoggerFactory.getLogger; | ||
34 | + | ||
35 | +/** | ||
36 | + * Implementation to get and set parameters available in vOLT | ||
37 | + * through the Netconf protocol. | ||
38 | + */ | ||
39 | +public class FujitsuVoltAlertConfig extends AbstractHandlerBehaviour | ||
40 | + implements VoltAlertConfig { | ||
41 | + | ||
42 | + private final Logger log = getLogger(FujitsuVoltAlertConfig.class); | ||
43 | + private static final String VOLT_ALERTS = "volt-alerts"; | ||
44 | + private static final String ALERT_FILTER = "alert-filter"; | ||
45 | + private static final String NOTIFY_ALERT = "notify-alert"; | ||
46 | + private final Set<String> severityLevels = ImmutableSet.of( | ||
47 | + "none", "info", "minor", "major", "critical"); | ||
48 | + private static final String DISABLE = "disable"; | ||
49 | + | ||
50 | + | ||
51 | + @Override | ||
52 | + public String getAlertFilter() { | ||
53 | + DriverHandler handler = handler(); | ||
54 | + NetconfController controller = handler.get(NetconfController.class); | ||
55 | + MastershipService mastershipService = handler.get(MastershipService.class); | ||
56 | + DeviceId ncDeviceId = handler.data().deviceId(); | ||
57 | + checkNotNull(controller, "Netconf controller is null"); | ||
58 | + String reply = null; | ||
59 | + | ||
60 | + if (!mastershipService.isLocalMaster(ncDeviceId)) { | ||
61 | + log.warn("Not master for {} Use {} to execute command", | ||
62 | + ncDeviceId, | ||
63 | + mastershipService.getMasterFor(ncDeviceId)); | ||
64 | + return reply; | ||
65 | + } | ||
66 | + | ||
67 | + try { | ||
68 | + StringBuilder request = new StringBuilder(); | ||
69 | + request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); | ||
70 | + request.append(ANGLE_RIGHT).append(NEW_LINE); | ||
71 | + request.append(buildStartTag(VOLT_ALERTS)); | ||
72 | + request.append(buildEmptyTag(ALERT_FILTER)); | ||
73 | + request.append(buildEndTag(VOLT_ALERTS)); | ||
74 | + request.append(VOLT_NE_CLOSE); | ||
75 | + | ||
76 | + reply = controller. | ||
77 | + getDevicesMap().get(ncDeviceId).getSession(). | ||
78 | + get(request.toString(), REPORT_ALL); | ||
79 | + } catch (IOException e) { | ||
80 | + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | ||
81 | + } | ||
82 | + return reply; | ||
83 | + } | ||
84 | + | ||
85 | + @Override | ||
86 | + public void setAlertFilter(String severity) { | ||
87 | + DriverHandler handler = handler(); | ||
88 | + NetconfController controller = handler.get(NetconfController.class); | ||
89 | + MastershipService mastershipService = handler.get(MastershipService.class); | ||
90 | + DeviceId ncDeviceId = handler.data().deviceId(); | ||
91 | + checkNotNull(controller, "Netconf controller is null"); | ||
92 | + | ||
93 | + if (!mastershipService.isLocalMaster(ncDeviceId)) { | ||
94 | + log.warn("Not master for {} Use {} to execute command", | ||
95 | + ncDeviceId, | ||
96 | + mastershipService.getMasterFor(ncDeviceId)); | ||
97 | + return; | ||
98 | + } | ||
99 | + | ||
100 | + if (!severityLevels.contains(severity)) { | ||
101 | + log.error("Invalid severity level: " + severity); | ||
102 | + return; | ||
103 | + } | ||
104 | + | ||
105 | + try { | ||
106 | + StringBuilder request = new StringBuilder(); | ||
107 | + request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); | ||
108 | + request.append(ANGLE_RIGHT).append(NEW_LINE); | ||
109 | + request.append(buildStartTag(VOLT_ALERTS)); | ||
110 | + request.append(buildStartTag(ALERT_FILTER, false)); | ||
111 | + request.append(severity); | ||
112 | + request.append(buildEndTag(ALERT_FILTER)); | ||
113 | + request.append(buildEndTag(VOLT_ALERTS)); | ||
114 | + request.append(VOLT_NE_CLOSE); | ||
115 | + | ||
116 | + controller.getDevicesMap().get(ncDeviceId).getSession(). | ||
117 | + editConfig(RUNNING, null, request.toString()); | ||
118 | + } catch (IOException e) { | ||
119 | + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | ||
120 | + } | ||
121 | + } | ||
122 | + | ||
123 | + @Override | ||
124 | + public void subscribe(String mode) { | ||
125 | + DriverHandler handler = handler(); | ||
126 | + NetconfController controller = handler.get(NetconfController.class); | ||
127 | + MastershipService mastershipService = handler.get(MastershipService.class); | ||
128 | + DeviceId ncDeviceId = handler.data().deviceId(); | ||
129 | + checkNotNull(controller, "Netconf controller is null"); | ||
130 | + | ||
131 | + if (!mastershipService.isLocalMaster(ncDeviceId)) { | ||
132 | + log.warn("Not master for {} Use {} to execute command", | ||
133 | + ncDeviceId, | ||
134 | + mastershipService.getMasterFor(ncDeviceId)); | ||
135 | + return; | ||
136 | + } | ||
137 | + | ||
138 | + if (mode != null) { | ||
139 | + if (!DISABLE.equals(mode)) { | ||
140 | + log.error("Invalid mode: " + mode); | ||
141 | + return; | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + try { | ||
146 | + if (mode != null) { | ||
147 | + controller.getDevicesMap().get(ncDeviceId).getSession(). | ||
148 | + endSubscription(); | ||
149 | + } else { | ||
150 | + StringBuilder request = new StringBuilder(); | ||
151 | + request.append(ANGLE_LEFT).append(NOTIFY_ALERT).append(SPACE); | ||
152 | + request.append(VOLT_NE_NAMESPACE).append(SLASH).append(ANGLE_RIGHT); | ||
153 | + | ||
154 | + controller.getDevicesMap().get(ncDeviceId).getSession(). | ||
155 | + startSubscription(request.toString()); | ||
156 | + } | ||
157 | + } catch (IOException e) { | ||
158 | + log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | ||
159 | + } | ||
160 | + } | ||
161 | + | ||
162 | +} |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/behaviour/VoltAlertConfig.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
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 | + */ | ||
16 | +package org.onosproject.drivers.fujitsu.behaviour; | ||
17 | + | ||
18 | +import com.google.common.annotations.Beta; | ||
19 | +import org.onosproject.net.driver.HandlerBehaviour; | ||
20 | + | ||
21 | +/** | ||
22 | + * Device behaviour to obtain and set alert filter in vOLT. | ||
23 | + * Device behaviour to subscribe to receive notifications from vOLT. | ||
24 | + */ | ||
25 | +@Beta | ||
26 | +public interface VoltAlertConfig extends HandlerBehaviour { | ||
27 | + | ||
28 | + /** | ||
29 | + * Get alert filter severity level. | ||
30 | + * | ||
31 | + * @return response string | ||
32 | + */ | ||
33 | + String getAlertFilter(); | ||
34 | + | ||
35 | + /** | ||
36 | + * Set alert filter severity level. | ||
37 | + * | ||
38 | + * @param severity input data in string | ||
39 | + */ | ||
40 | + void setAlertFilter(String severity); | ||
41 | + | ||
42 | + /** | ||
43 | + * Subscribe to receive notifications or unsubscribe. | ||
44 | + * | ||
45 | + * @param mode disable subscription | ||
46 | + */ | ||
47 | + void subscribe(String mode); | ||
48 | +} |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltGetAlertFilterCommand.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
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 | + */ | ||
16 | +package org.onosproject.drivers.fujitsu.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.net.driver.DriverService; | ||
25 | + | ||
26 | +/** | ||
27 | + * Gets alert filter severity level in vOLT. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "volt-notification-alertfilter", | ||
30 | + description = "Gets alert filter severity level in vOLT") | ||
31 | +public class VoltGetAlertFilterCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
34 | + required = true, multiValued = false) | ||
35 | + String uri = null; | ||
36 | + | ||
37 | + private DeviceId deviceId; | ||
38 | + | ||
39 | + @Override | ||
40 | + protected void execute() { | ||
41 | + DriverService service = get(DriverService.class); | ||
42 | + deviceId = DeviceId.deviceId(uri); | ||
43 | + DriverHandler h = service.createHandler(deviceId); | ||
44 | + VoltAlertConfig voltNe = h.behaviour(VoltAlertConfig.class); | ||
45 | + String reply = voltNe.getAlertFilter(); | ||
46 | + if (reply != null) { | ||
47 | + print("%s", reply); | ||
48 | + } else { | ||
49 | + print("No reply from %s", deviceId.toString()); | ||
50 | + } | ||
51 | + } | ||
52 | +} |
... | @@ -50,7 +50,7 @@ public class VoltGetPonLinksCommand extends AbstractShellCommand { | ... | @@ -50,7 +50,7 @@ public class VoltGetPonLinksCommand extends AbstractShellCommand { |
50 | if (reply != null) { | 50 | if (reply != null) { |
51 | print("%s", reply); | 51 | print("%s", reply); |
52 | } else { | 52 | } else { |
53 | - print("No replay from %s", deviceId.toString()); | 53 | + print("No reply from %s", deviceId.toString()); |
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ... | ... |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSetAlertFilterCommand.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
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 | + */ | ||
16 | +package org.onosproject.drivers.fujitsu.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.net.driver.DriverService; | ||
25 | + | ||
26 | +/** | ||
27 | + * Sets alert filter severity level in vOLT. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "volt-notification-setalertfilter", | ||
30 | + description = "Sets alert filter severity level in vOLT") | ||
31 | +public class VoltSetAlertFilterCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
34 | + required = true, multiValued = false) | ||
35 | + String uri = null; | ||
36 | + | ||
37 | + @Argument(index = 1, name = "target", description = "Severity level", | ||
38 | + required = true, multiValued = false) | ||
39 | + String severity = null; | ||
40 | + | ||
41 | + private DeviceId deviceId; | ||
42 | + | ||
43 | + @Override | ||
44 | + protected void execute() { | ||
45 | + DriverService service = get(DriverService.class); | ||
46 | + deviceId = DeviceId.deviceId(uri); | ||
47 | + DriverHandler h = service.createHandler(deviceId); | ||
48 | + VoltAlertConfig volt = h.behaviour(VoltAlertConfig.class); | ||
49 | + volt.setAlertFilter(severity); | ||
50 | + } | ||
51 | +} |
drivers/fujitsu/src/main/java/org/onosproject/drivers/fujitsu/cli/VoltSubscribeCommand.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present Open Networking Laboratory | ||
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 | + */ | ||
16 | +package org.onosproject.drivers.fujitsu.cli; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Argument; | ||
19 | +import org.apache.karaf.shell.commands.Command; | ||
20 | +import org.onosproject.cli.AbstractShellCommand; | ||
21 | +import org.onosproject.net.DeviceId; | ||
22 | +import org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig; | ||
23 | +import org.onosproject.net.driver.DriverHandler; | ||
24 | +import org.onosproject.net.driver.DriverService; | ||
25 | + | ||
26 | +/** | ||
27 | + * Subscribes to receive notifications of vOLT or unsubscribes. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "volt-notification-subscribe", | ||
30 | + description = "Subscribes to receive notifications of vOLT") | ||
31 | +public class VoltSubscribeCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + @Argument(index = 0, name = "uri", description = "Device ID", | ||
34 | + required = true, multiValued = false) | ||
35 | + String uri = null; | ||
36 | + | ||
37 | + @Argument(index = 1, name = "mode", description = "Disable subscription", | ||
38 | + required = false, multiValued = false) | ||
39 | + String mode = null; | ||
40 | + | ||
41 | + private DeviceId deviceId; | ||
42 | + | ||
43 | + @Override | ||
44 | + protected void execute() { | ||
45 | + DriverService service = get(DriverService.class); | ||
46 | + deviceId = DeviceId.deviceId(uri); | ||
47 | + DriverHandler h = service.createHandler(deviceId); | ||
48 | + VoltAlertConfig volt = h.behaviour(VoltAlertConfig.class); | ||
49 | + volt.subscribe(mode); | ||
50 | + } | ||
51 | +} |
... | @@ -59,8 +59,25 @@ | ... | @@ -59,8 +59,25 @@ |
59 | <ref component-id="deviceIdCompleter"/> | 59 | <ref component-id="deviceIdCompleter"/> |
60 | </completers> | 60 | </completers> |
61 | </command> | 61 | </command> |
62 | + <command> | ||
63 | + <action class="org.onosproject.drivers.fujitsu.cli.VoltGetAlertFilterCommand"/> | ||
64 | + <completers> | ||
65 | + <ref component-id="deviceIdCompleter"/> | ||
66 | + </completers> | ||
67 | + </command> | ||
68 | + <command> | ||
69 | + <action class="org.onosproject.drivers.fujitsu.cli.VoltSetAlertFilterCommand"/> | ||
70 | + <completers> | ||
71 | + <ref component-id="deviceIdCompleter"/> | ||
72 | + </completers> | ||
73 | + </command> | ||
74 | + <command> | ||
75 | + <action class="org.onosproject.drivers.fujitsu.cli.VoltSubscribeCommand"/> | ||
76 | + <completers> | ||
77 | + <ref component-id="deviceIdCompleter"/> | ||
78 | + </completers> | ||
79 | + </command> | ||
62 | </command-bundle> | 80 | </command-bundle> |
63 | 81 | ||
64 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> | 82 | <bean id="deviceIdCompleter" class="org.onosproject.cli.net.DeviceIdCompleter"/> |
65 | - | ||
66 | </blueprint> | 83 | </blueprint> | ... | ... |
... | @@ -30,5 +30,7 @@ | ... | @@ -30,5 +30,7 @@ |
30 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltOnuConfig"/> | 30 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltOnuConfig"/> |
31 | <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig" | 31 | <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig" |
32 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltOnuOperConfig"/> | 32 | impl="org.onosproject.drivers.fujitsu.FujitsuVoltOnuOperConfig"/> |
33 | + <behaviour api="org.onosproject.drivers.fujitsu.behaviour.VoltAlertConfig" | ||
34 | + impl="org.onosproject.drivers.fujitsu.FujitsuVoltAlertConfig"/> | ||
33 | </driver> | 35 | </driver> |
34 | </drivers> | 36 | </drivers> | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.netconf; | 17 | package org.onosproject.netconf; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import java.util.List; | 20 | import java.util.List; |
20 | import java.util.concurrent.CompletableFuture; | 21 | import java.util.concurrent.CompletableFuture; |
21 | 22 | ||
... | @@ -60,7 +61,7 @@ public interface NetconfSession { | ... | @@ -60,7 +61,7 @@ public interface NetconfSession { |
60 | throws NetconfException; | 61 | throws NetconfException; |
61 | 62 | ||
62 | /** | 63 | /** |
63 | - * Executes an RPC to the server and wrap the request in RPC header. | 64 | + * Executes an synchronous RPC to the server and wrap the request in RPC header. |
64 | * | 65 | * |
65 | * @param request the XML containing the request to the server. | 66 | * @param request the XML containing the request to the server. |
66 | * @return Server response or ERROR | 67 | * @return Server response or ERROR |
... | @@ -158,6 +159,15 @@ public interface NetconfSession { | ... | @@ -158,6 +159,15 @@ public interface NetconfSession { |
158 | void startSubscription() throws NetconfException; | 159 | void startSubscription() throws NetconfException; |
159 | 160 | ||
160 | /** | 161 | /** |
162 | + * Starts subscription to the device's notifications. | ||
163 | + * | ||
164 | + * @param filterSchema XML subtrees to indicate specific notification | ||
165 | + * @throws NetconfException when there is a problem starting the subscription | ||
166 | + */ | ||
167 | + @Beta | ||
168 | + void startSubscription(String filterSchema) throws NetconfException; | ||
169 | + | ||
170 | + /** | ||
161 | * Ends subscription to the device's notifications. | 171 | * Ends subscription to the device's notifications. |
162 | * | 172 | * |
163 | * @throws NetconfException when there is a problem ending the subscription | 173 | * @throws NetconfException when there is a problem ending the subscription | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.netconf.ctl; | 17 | package org.onosproject.netconf.ctl; |
18 | 18 | ||
19 | +import com.google.common.annotations.Beta; | ||
19 | import ch.ethz.ssh2.Connection; | 20 | import ch.ethz.ssh2.Connection; |
20 | import ch.ethz.ssh2.Session; | 21 | import ch.ethz.ssh2.Session; |
21 | import com.google.common.base.Preconditions; | 22 | import com.google.common.base.Preconditions; |
... | @@ -66,8 +67,8 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -66,8 +67,8 @@ public class NetconfSessionImpl implements NetconfSession { |
66 | private static final String WITH_DEFAULT_CLOSE = "</with-defaults>"; | 67 | private static final String WITH_DEFAULT_CLOSE = "</with-defaults>"; |
67 | private static final String DEFAULT_OPERATION_OPEN = "<default-operation>"; | 68 | private static final String DEFAULT_OPERATION_OPEN = "<default-operation>"; |
68 | private static final String DEFAULT_OPERATION_CLOSE = "</default-operation>"; | 69 | private static final String DEFAULT_OPERATION_CLOSE = "</default-operation>"; |
69 | - private static final String FILTER_OPEN = "<filter type=\"subtree\">"; | 70 | + private static final String SUBTREE_FILTER_OPEN = "<filter type=\"subtree\">"; |
70 | - private static final String FILTER_CLOSE = "</filter>"; | 71 | + private static final String SUBTREE_FILTER_CLOSE = "</filter>"; |
71 | private static final String EDIT_CONFIG_OPEN = "<edit-config>"; | 72 | private static final String EDIT_CONFIG_OPEN = "<edit-config>"; |
72 | private static final String EDIT_CONFIG_CLOSE = "</edit-config>"; | 73 | private static final String EDIT_CONFIG_CLOSE = "</edit-config>"; |
73 | private static final String TARGET_OPEN = "<target>"; | 74 | private static final String TARGET_OPEN = "<target>"; |
... | @@ -80,6 +81,8 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -80,6 +81,8 @@ public class NetconfSessionImpl implements NetconfSession { |
80 | "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\""; | 81 | "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\""; |
81 | private static final String NETCONF_WITH_DEFAULTS_NAMESPACE = | 82 | private static final String NETCONF_WITH_DEFAULTS_NAMESPACE = |
82 | "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""; | 83 | "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""; |
84 | + private static final String SUBSCRIPTION_SUBTREE_FILTER_OPEN = | ||
85 | + "<filter xmlns:base10=\"urn:ietf:params:xml:ns:netconf:base:1.0\" base10:type=\"subtree\">"; | ||
83 | 86 | ||
84 | private final AtomicInteger messageIdInteger = new AtomicInteger(0); | 87 | private final AtomicInteger messageIdInteger = new AtomicInteger(0); |
85 | private Connection netconfConnection; | 88 | private Connection netconfConnection; |
... | @@ -157,11 +160,13 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -157,11 +160,13 @@ public class NetconfSessionImpl implements NetconfSession { |
157 | } | 160 | } |
158 | } | 161 | } |
159 | 162 | ||
160 | - private void startSubscriptionConnection() throws NetconfException { | 163 | + |
164 | + @Beta | ||
165 | + private void startSubscriptionConnection(String filterSchema) throws NetconfException { | ||
161 | if (!serverCapabilities.contains("interleave")) { | 166 | if (!serverCapabilities.contains("interleave")) { |
162 | throw new NetconfException("Device" + deviceInfo + "does not support interleave"); | 167 | throw new NetconfException("Device" + deviceInfo + "does not support interleave"); |
163 | } | 168 | } |
164 | - String reply = sendRequest(createSubscriptionString()); | 169 | + String reply = sendRequest(createSubscriptionString(filterSchema)); |
165 | if (!checkReply(reply)) { | 170 | if (!checkReply(reply)) { |
166 | throw new NetconfException("Subscription not successful with device " | 171 | throw new NetconfException("Subscription not successful with device " |
167 | + deviceInfo + " with reply " + reply); | 172 | + deviceInfo + " with reply " + reply); |
... | @@ -169,18 +174,37 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -169,18 +174,37 @@ public class NetconfSessionImpl implements NetconfSession { |
169 | subscriptionConnected = true; | 174 | subscriptionConnected = true; |
170 | } | 175 | } |
171 | 176 | ||
177 | + @Override | ||
172 | public void startSubscription() throws NetconfException { | 178 | public void startSubscription() throws NetconfException { |
173 | if (!subscriptionConnected) { | 179 | if (!subscriptionConnected) { |
174 | - startSubscriptionConnection(); | 180 | + startSubscriptionConnection(null); |
175 | } | 181 | } |
176 | streamHandler.setEnableNotifications(true); | 182 | streamHandler.setEnableNotifications(true); |
177 | } | 183 | } |
178 | 184 | ||
179 | - private String createSubscriptionString() { | 185 | + @Beta |
186 | + @Override | ||
187 | + public void startSubscription(String filterSchema) throws NetconfException { | ||
188 | + if (!subscriptionConnected) { | ||
189 | + startSubscriptionConnection(filterSchema); | ||
190 | + } | ||
191 | + streamHandler.setEnableNotifications(true); | ||
192 | + } | ||
193 | + | ||
194 | + @Beta | ||
195 | + private String createSubscriptionString(String filterSchema) { | ||
180 | StringBuilder subscriptionbuffer = new StringBuilder(); | 196 | StringBuilder subscriptionbuffer = new StringBuilder(); |
181 | subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); | 197 | subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
182 | subscriptionbuffer.append(" <create-subscription\n"); | 198 | subscriptionbuffer.append(" <create-subscription\n"); |
183 | subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"); | 199 | subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"); |
200 | + // FIXME Only subtree filtering supported at the moment. | ||
201 | + if (filterSchema != null) { | ||
202 | + subscriptionbuffer.append(" "); | ||
203 | + subscriptionbuffer.append(SUBSCRIPTION_SUBTREE_FILTER_OPEN).append(NEW_LINE); | ||
204 | + subscriptionbuffer.append(filterSchema).append(NEW_LINE); | ||
205 | + subscriptionbuffer.append(" "); | ||
206 | + subscriptionbuffer.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE); | ||
207 | + } | ||
184 | subscriptionbuffer.append(" </create-subscription>\n"); | 208 | subscriptionbuffer.append(" </create-subscription>\n"); |
185 | subscriptionbuffer.append("</rpc>\n"); | 209 | subscriptionbuffer.append("</rpc>\n"); |
186 | subscriptionbuffer.append(ENDPATTERN); | 210 | subscriptionbuffer.append(ENDPATTERN); |
... | @@ -323,9 +347,9 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -323,9 +347,9 @@ public class NetconfSessionImpl implements NetconfSession { |
323 | rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); | 347 | rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); |
324 | rpc.append(GET_OPEN).append(NEW_LINE); | 348 | rpc.append(GET_OPEN).append(NEW_LINE); |
325 | if (filterSchema != null) { | 349 | if (filterSchema != null) { |
326 | - rpc.append(FILTER_OPEN).append(NEW_LINE); | 350 | + rpc.append(SUBTREE_FILTER_OPEN).append(NEW_LINE); |
327 | rpc.append(filterSchema).append(NEW_LINE); | 351 | rpc.append(filterSchema).append(NEW_LINE); |
328 | - rpc.append(FILTER_CLOSE).append(NEW_LINE); | 352 | + rpc.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE); |
329 | } | 353 | } |
330 | if (withDefaultsMode != null) { | 354 | if (withDefaultsMode != null) { |
331 | rpc.append(WITH_DEFAULT_OPEN).append(NETCONF_WITH_DEFAULTS_NAMESPACE).append(">"); | 355 | rpc.append(WITH_DEFAULT_OPEN).append(NETCONF_WITH_DEFAULTS_NAMESPACE).append(">"); |
... | @@ -577,7 +601,9 @@ public class NetconfSessionImpl implements NetconfSession { | ... | @@ -577,7 +601,9 @@ public class NetconfSessionImpl implements NetconfSession { |
577 | } | 601 | } |
578 | CompletableFuture<String> completedReply = | 602 | CompletableFuture<String> completedReply = |
579 | replies.get(messageId.get()); | 603 | replies.get(messageId.get()); |
604 | + if (completedReply != null) { | ||
580 | completedReply.complete(event.getMessagePayload()); | 605 | completedReply.complete(event.getMessagePayload()); |
581 | } | 606 | } |
582 | } | 607 | } |
608 | + } | ||
583 | } | 609 | } | ... | ... |
-
Please register or login to post a comment