Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.segmentrouting.cli; |
| 18 | |
| 19 | |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 20 | import org.apache.karaf.shell.api.action.Argument; |
| 21 | import org.apache.karaf.shell.api.action.Command; |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 22 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 23 | import org.onlab.osgi.ServiceNotFoundException; |
| 24 | import org.onosproject.cli.AbstractShellCommand; |
| 25 | import org.onosproject.segmentrouting.SegmentRoutingService; |
| 26 | |
| 27 | /** |
| 28 | * Command to invalidate next id from SR internal stores. |
| 29 | */ |
Ray Milkey | 52ca4e9 | 2018-09-28 10:58:28 -0700 | [diff] [blame] | 30 | @Service |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 31 | @Command(scope = "onos", name = "sr-next-invalidate", |
| 32 | description = "Invalidate given next id from SR internal stores") |
| 33 | public class InvalidateNextCommand extends AbstractShellCommand { |
| 34 | |
| 35 | private static final String CONFIRM_PHRASE = "please"; |
| 36 | |
| 37 | @Argument(name = "nextId", description = "Next ID", index = 0) |
| 38 | private String nextId = null; |
| 39 | |
| 40 | @Argument(name = "confirm", description = "Confirmation phrase", index = 1) |
| 41 | private String please = null; |
| 42 | |
| 43 | @Override |
Ray Milkey | db38bc8 | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 44 | protected void doExecute() { |
Charles Chan | 0b1dd7e | 2018-08-19 19:21:46 -0700 | [diff] [blame] | 45 | if (please == null || !please.equals(CONFIRM_PHRASE)) { |
| 46 | print("WARNING: System may enter an unpredictable state if the next ID is force invalidated." + |
| 47 | "Enter confirmation phrase to continue."); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | try { |
| 52 | SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class); |
| 53 | srService.invalidateNextObj(Integer.parseInt(nextId)); |
| 54 | } catch (ServiceNotFoundException e) { |
| 55 | print("SegmentRoutingService unavailable"); |
| 56 | } |
| 57 | } |
| 58 | } |