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