Implement CLI commands to view and delete SR internal stores
sr-next-dst (renamed from sr-next-hops)
sr-next-port
sr-next-vlan
sr-next-mcast (renamed from sr-mcast-next)
sr-next-pw
sr-next-xconnect
sr-next-invalidate <next-id>
Change-Id: Id5178f786bb97e26ddb86015105dd19604ac0817
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/InvalidateNextCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/InvalidateNextCommand.java
new file mode 100644
index 0000000..aa3f78b
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/InvalidateNextCommand.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.segmentrouting.cli;
+
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.onlab.osgi.ServiceNotFoundException;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.segmentrouting.SegmentRoutingService;
+
+/**
+ * Command to invalidate next id from SR internal stores.
+ */
+@Command(scope = "onos", name = "sr-next-invalidate",
+ description = "Invalidate given next id from SR internal stores")
+public class InvalidateNextCommand extends AbstractShellCommand {
+
+ private static final String CONFIRM_PHRASE = "please";
+
+ @Argument(name = "nextId", description = "Next ID", index = 0)
+ private String nextId = null;
+
+ @Argument(name = "confirm", description = "Confirmation phrase", index = 1)
+ private String please = null;
+
+ @Override
+ protected void execute() {
+ if (please == null || !please.equals(CONFIRM_PHRASE)) {
+ print("WARNING: System may enter an unpredictable state if the next ID is force invalidated." +
+ "Enter confirmation phrase to continue.");
+ return;
+ }
+
+ try {
+ SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
+ srService.invalidateNextObj(Integer.parseInt(nextId));
+ } catch (ServiceNotFoundException e) {
+ print("SegmentRoutingService unavailable");
+ }
+ }
+}
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java
index cefb244..569f097 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/McastNextListCommand.java
@@ -37,7 +37,7 @@
/**
* Command to show the list of mcast nextids.
*/
-@Command(scope = "onos", name = "sr-mcast-next",
+@Command(scope = "onos", name = "sr-next-mcast",
description = "Lists all mcast nextids")
public class McastNextListCommand extends AbstractShellCommand {
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/NextHopCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/NextDstCommand.java
similarity index 93%
rename from app/src/main/java/org/onosproject/segmentrouting/cli/NextHopCommand.java
rename to app/src/main/java/org/onosproject/segmentrouting/cli/NextDstCommand.java
index 2b43de5..07950a7 100644
--- a/app/src/main/java/org/onosproject/segmentrouting/cli/NextHopCommand.java
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/NextDstCommand.java
@@ -29,12 +29,11 @@
/**
* Command to read the current state of the DestinationSetNextObjectiveStore.
- *
*/
-@Command(scope = "onos", name = "sr-next-hops",
+@Command(scope = "onos", name = "sr-next-dst",
description = "Displays the current next-hops seen by each switch "
+ "towards a set of destinations and the next-id it maps to")
-public class NextHopCommand extends AbstractShellCommand {
+public class NextDstCommand extends AbstractShellCommand {
private static final String FORMAT_MAPPING = " %s";
@@ -42,7 +41,7 @@
protected void execute() {
SegmentRoutingService srService =
AbstractShellCommand.get(SegmentRoutingService.class);
- printDestinationSet(srService.getDestinationSet());
+ printDestinationSet(srService.getDstNextObjStore());
}
private void printDestinationSet(Map<DestinationSetNextObjectiveStoreKey,
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/NextPortCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/NextPortCommand.java
new file mode 100644
index 0000000..5be9d77
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/NextPortCommand.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.segmentrouting.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.segmentrouting.SegmentRoutingService;
+import org.onosproject.segmentrouting.storekey.PortNextObjectiveStoreKey;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Command to read the current state of the portNextObjStore.
+ */
+@Command(scope = "onos", name = "sr-next-port",
+ description = "Displays the current port / next-id it mapping")
+public class NextPortCommand extends AbstractShellCommand {
+ @Override
+ protected void execute() {
+ SegmentRoutingService srService =
+ AbstractShellCommand.get(SegmentRoutingService.class);
+ print(srService.getPortNextObjStore());
+ }
+
+ private void print(Map<PortNextObjectiveStoreKey, Integer> portNextObjStore) {
+ ArrayList<PortNextObjectiveStoreKey> a = new ArrayList<>(portNextObjStore.keySet());
+ a.sort(Comparator
+ .comparing((PortNextObjectiveStoreKey o) -> o.deviceId().toString())
+ .thenComparing((PortNextObjectiveStoreKey o) -> o.portNumber().toLong()));
+
+ StringBuilder builder = new StringBuilder();
+ a.forEach(k ->
+ builder.append("\n")
+ .append(k)
+ .append(" --> ")
+ .append(portNextObjStore.get(k))
+ );
+ print(builder.toString());
+ }
+}
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/NextVlanCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/NextVlanCommand.java
new file mode 100644
index 0000000..0295a90
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/NextVlanCommand.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.segmentrouting.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.segmentrouting.SegmentRoutingService;
+import org.onosproject.segmentrouting.storekey.VlanNextObjectiveStoreKey;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Command to read the current state of the vlanNextObjStore.
+ */
+@Command(scope = "onos", name = "sr-next-vlan",
+ description = "Displays the current vlan / next-id it mapping")
+public class NextVlanCommand extends AbstractShellCommand {
+ @Override
+ protected void execute() {
+ SegmentRoutingService srService =
+ AbstractShellCommand.get(SegmentRoutingService.class);
+ print(srService.getVlanNextObjStore());
+ }
+
+ private void print(Map<VlanNextObjectiveStoreKey, Integer> vlanNextObjStore) {
+ ArrayList<VlanNextObjectiveStoreKey> a = new ArrayList<>(vlanNextObjStore.keySet());
+ a.sort(Comparator
+ .comparing((VlanNextObjectiveStoreKey o) -> o.deviceId().toString())
+ .thenComparing((VlanNextObjectiveStoreKey o) -> o.vlanId().toShort()));
+
+ StringBuilder builder = new StringBuilder();
+ a.forEach(k ->
+ builder.append("\n")
+ .append(k)
+ .append(" --> ")
+ .append(vlanNextObjStore.get(k))
+ );
+ print(builder.toString());
+ }
+}
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/PseudowireNextListCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/PseudowireNextListCommand.java
new file mode 100644
index 0000000..d37d3e8
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/PseudowireNextListCommand.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.segmentrouting.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.flowobjective.NextObjective;
+import org.onosproject.segmentrouting.SegmentRoutingService;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Command to read the current state of the pseudowire next stores.
+ */
+@Command(scope = "onos", name = "sr-next-pw",
+ description = "Displays the current next-id for pseudowire")
+public class PseudowireNextListCommand extends AbstractShellCommand {
+ @Override
+ protected void execute() {
+ SegmentRoutingService srService =
+ AbstractShellCommand.get(SegmentRoutingService.class);
+ print(srService.getPwInitNext());
+ print(srService.getPwTermNext());
+ }
+
+ private void print(Map<String, NextObjective> nextStore) {
+ ArrayList<String> a = new ArrayList<>(nextStore.keySet());
+ a.sort(Comparator.comparing((String o) -> o));
+
+ StringBuilder builder = new StringBuilder();
+ a.forEach(k ->
+ builder.append("\n")
+ .append(k)
+ .append(" --> ")
+ .append(nextStore.get(k).id())
+ );
+ print(builder.toString());
+ }
+}
diff --git a/app/src/main/java/org/onosproject/segmentrouting/cli/XconnectNextListCommand.java b/app/src/main/java/org/onosproject/segmentrouting/cli/XconnectNextListCommand.java
new file mode 100644
index 0000000..f7a6b51
--- /dev/null
+++ b/app/src/main/java/org/onosproject/segmentrouting/cli/XconnectNextListCommand.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2018-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.segmentrouting.cli;
+
+import org.apache.karaf.shell.commands.Command;
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.flowobjective.NextObjective;
+import org.onosproject.segmentrouting.xconnect.api.XconnectKey;
+import org.onosproject.segmentrouting.xconnect.api.XconnectService;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Map;
+
+/**
+ * Command to read the current state of the xconnect next stores.
+ */
+@Command(scope = "onos", name = "sr-next-xconnect",
+ description = "Displays the current next-id for xconnect")
+public class XconnectNextListCommand extends AbstractShellCommand {
+ @Override
+ protected void execute() {
+ XconnectService xconnectService =
+ AbstractShellCommand.get(XconnectService.class);
+ print(xconnectService.getNext());
+ }
+
+ private void print(Map<XconnectKey, NextObjective> nextStore) {
+ ArrayList<XconnectKey> a = new ArrayList<>(nextStore.keySet());
+ a.sort(Comparator
+ .comparing((XconnectKey o) -> o.deviceId().toString())
+ .thenComparing((XconnectKey o) -> o.vlanId().toShort()));
+
+ StringBuilder builder = new StringBuilder();
+ a.forEach(k ->
+ builder.append("\n")
+ .append(k)
+ .append(" --> ")
+ .append(nextStore.get(k).id())
+ );
+ print(builder.toString());
+ }
+}