blob: aa36d889921e467bfb2a42d3a417f3d288ec4e6b [file] [log] [blame]
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -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 */
16package org.onosproject.netconf.cli.impl;
17
Ray Milkey86ad7bb2018-09-27 12:32:28 -070018import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
Ray Milkeyec20a292018-10-11 15:53:33 -070020import org.apache.karaf.shell.api.action.Completion;
Ray Milkey86ad7bb2018-09-27 12:32:28 -070021import org.apache.karaf.shell.api.action.Option;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070023import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.cli.net.DeviceIdCompleter;
25import org.onosproject.net.DeviceId;
26import org.onosproject.netconf.NetconfController;
27import org.onosproject.netconf.NetconfDevice;
28import org.onosproject.netconf.NetconfException;
29
30/**
31 * Debug command to start subscription on specified device.
32 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070033@Service
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070034@Command(scope = "onos", name = "netconf-subscription-test",
35 description = "Debug command to start subscription on specified device")
36public class NetconfSubscriptionTestCommand extends AbstractShellCommand {
37
38 // for OSGi
39 DeviceIdCompleter uriCompleter;
40
41 @Argument(index = 0, name = "deviceId", description = "Device ID",
42 required = true, multiValued = false)
Ray Milkeyec20a292018-10-11 15:53:33 -070043 @Completion(DeviceIdCompleter.class)
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070044 String uri = null;
45
46 @Option(name = "--end",
47 description = "Ends subscription instead of starting",
48 required = false)
49 boolean end = false;
50
51
52 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070053 protected void doExecute() {
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070054 NetconfController controller = get(NetconfController.class);
55 DeviceId did = DeviceId.deviceId(uri);
56
57 NetconfDevice netconfDevice = controller.getNetconfDevice(did);
58 if (netconfDevice == null) {
Yuta HIGUCHId31bc6e2017-05-03 17:23:34 -070059 print("%s not found or not connected to this node", did);
Yuta HIGUCHI57ba1e12017-04-26 15:51:47 -070060 return;
61 }
62
63 if (!end) {
64 try {
65 netconfDevice.getSession().startSubscription();
66 } catch (NetconfException e) {
67 log.error("Exception thrown", e);
68 print("starting subscription failed (see log for details)");
69 }
70 } else {
71 try {
72 netconfDevice.getSession().endSubscription();
73 } catch (NetconfException e) {
74 log.error("Exception thrown", e);
75 print("ending subscription failed (see log for details)");
76 }
77 }
78 }
79
80}