blob: 094bea9036033e04af35d539beecddf12476f081 [file] [log] [blame]
Charles Chand5814aa2018-08-19 19:21:46 -07001/*
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
17package org.onosproject.segmentrouting.cli;
18
19
Ray Milkey86ad7bb2018-09-27 12:32:28 -070020import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
Ray Milkey7a2dee52018-09-28 10:58:28 -070022import org.apache.karaf.shell.api.action.lifecycle.Service;
Charles Chand5814aa2018-08-19 19:21:46 -070023import org.onlab.osgi.ServiceNotFoundException;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.segmentrouting.SegmentRoutingService;
26
27/**
28 * Command to invalidate next id from SR internal stores.
29 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070030@Service
Charles Chand5814aa2018-08-19 19:21:46 -070031@Command(scope = "onos", name = "sr-next-invalidate",
32 description = "Invalidate given next id from SR internal stores")
33public 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 Milkey86ad7bb2018-09-27 12:32:28 -070044 protected void doExecute() {
Charles Chand5814aa2018-08-19 19:21:46 -070045 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}