Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -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 | */ |
| 16 | package org.onosproject.netconf.cli.impl; |
| 17 | |
| 18 | import org.apache.karaf.shell.commands.Argument; |
| 19 | import org.apache.karaf.shell.commands.Command; |
| 20 | import org.apache.karaf.shell.commands.Option; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 23 | import org.onosproject.net.DeviceId; |
| 24 | import org.onosproject.netconf.NetconfController; |
| 25 | import org.onosproject.netconf.NetconfDevice; |
| 26 | import org.onosproject.netconf.NetconfException; |
| 27 | |
| 28 | /** |
| 29 | * Debug command to start subscription on specified device. |
| 30 | */ |
| 31 | @Command(scope = "onos", name = "netconf-subscription-test", |
| 32 | description = "Debug command to start subscription on specified device") |
| 33 | public class NetconfSubscriptionTestCommand extends AbstractShellCommand { |
| 34 | |
| 35 | // for OSGi |
| 36 | DeviceIdCompleter uriCompleter; |
| 37 | |
| 38 | @Argument(index = 0, name = "deviceId", description = "Device ID", |
| 39 | required = true, multiValued = false) |
| 40 | String uri = null; |
| 41 | |
| 42 | @Option(name = "--end", |
| 43 | description = "Ends subscription instead of starting", |
| 44 | required = false) |
| 45 | boolean end = false; |
| 46 | |
| 47 | |
| 48 | @Override |
| 49 | protected void execute() { |
| 50 | NetconfController controller = get(NetconfController.class); |
| 51 | DeviceId did = DeviceId.deviceId(uri); |
| 52 | |
| 53 | NetconfDevice netconfDevice = controller.getNetconfDevice(did); |
| 54 | if (netconfDevice == null) { |
Yuta HIGUCHI | d31bc6e | 2017-05-03 17:23:34 -0700 | [diff] [blame] | 55 | print("%s not found or not connected to this node", did); |
Yuta HIGUCHI | 57ba1e1 | 2017-04-26 15:51:47 -0700 | [diff] [blame] | 56 | return; |
| 57 | } |
| 58 | |
| 59 | if (!end) { |
| 60 | try { |
| 61 | netconfDevice.getSession().startSubscription(); |
| 62 | } catch (NetconfException e) { |
| 63 | log.error("Exception thrown", e); |
| 64 | print("starting subscription failed (see log for details)"); |
| 65 | } |
| 66 | } else { |
| 67 | try { |
| 68 | netconfDevice.getSession().endSubscription(); |
| 69 | } catch (NetconfException e) { |
| 70 | log.error("Exception thrown", e); |
| 71 | print("ending subscription failed (see log for details)"); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | } |