diff options
Diffstat (limited to 'framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli')
7 files changed, 0 insertions, 834 deletions
diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/AddRouteCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/AddRouteCommand.java deleted file mode 100644 index 452a145e..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/AddRouteCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.routing.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.MacAddress; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.routing.FibEntry; -import org.onosproject.routing.FibListener; -import org.onosproject.routing.FibUpdate; -import org.onosproject.routing.StaticRoutingService; - -import java.util.Arrays; -import java.util.Collections; - -@Command(scope = "onos", name = "add-route", description = "Installs static route") -public class AddRouteCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "prefix IP MAC", - description = "prefix nexthopIP nexthopMAC", - required = true, multiValued = true) - String[] fibEntryString = null; - - @Override - protected void execute() { - StaticRoutingService routingService = get(StaticRoutingService.class); - - if (fibEntryString.length < 3) { - return; - } - - IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]); - IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]); - MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]); - FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac); - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.UPDATE, fibEntry); - - FibListener fibListener = routingService.getFibListener(); - fibListener.update(Arrays.asList(fibUpdate), Collections.emptyList()); - } -} diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpNeighborsListCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpNeighborsListCommand.java deleted file mode 100644 index 875a339a..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpNeighborsListCommand.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.routing.cli; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.routing.bgp.BgpInfoService; -import org.onosproject.routing.bgp.BgpSession; - -import java.util.Collection; - -/** - * Command to show the BGP neighbors. - */ -@Command(scope = "onos", name = "bgp-neighbors", - description = "Lists the BGP neighbors") -public class BgpNeighborsListCommand extends AbstractShellCommand { - @Option(name = "-n", aliases = "--neighbor", - description = "BGP neighbor to display information about", - required = false, multiValued = false) - private String bgpNeighbor; - - private static final String FORMAT_NEIGHBOR_LINE1 = - "BGP neighbor is %s, remote AS %d, local AS %d"; - private static final String FORMAT_NEIGHBOR_LINE2 = - " Remote router ID %s, IP %s, BGP version %d, Hold time %d"; - private static final String FORMAT_NEIGHBOR_LINE3 = - " Remote AFI/SAFI IPv4 Unicast %s Multicast %s, IPv6 Unicast %s Multicast %s"; - private static final String FORMAT_NEIGHBOR_LINE4 = - " Local router ID %s, IP %s, BGP version %d, Hold time %d"; - private static final String FORMAT_NEIGHBOR_LINE5 = - " Local AFI/SAFI IPv4 Unicast %s Multicast %s, IPv6 Unicast %s Multicast %s"; - private static final String FORMAT_NEIGHBOR_LINE6 = - " 4 Octet AS Capability: %s %s"; - - @Override - protected void execute() { - BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class); - Collection<BgpSession> bgpSessions = service.getBgpSessions(); - - if (bgpNeighbor != null) { - // Print a single neighbor (if found) - BgpSession foundBgpSession = null; - for (BgpSession bgpSession : bgpSessions) { - if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) { - foundBgpSession = bgpSession; - break; - } - } - if (foundBgpSession != null) { - printNeighbor(foundBgpSession); - } else { - print("BGP neighbor %s not found", bgpNeighbor); - } - return; - } - - // Print all neighbors - printNeighbors(bgpSessions); - } - - /** - * Prints all BGP neighbors. - * - * @param bgpSessions the BGP sessions for the neighbors to print - */ - private void printNeighbors(Collection<BgpSession> bgpSessions) { - if (outputJson()) { - print("%s", json(bgpSessions)); - } else { - for (BgpSession bgpSession : bgpSessions) { - printNeighbor(bgpSession); - } - } - } - - /** - * Prints a BGP neighbor. - * - * @param bgpSession the BGP session for the neighbor to print - */ - private void printNeighbor(BgpSession bgpSession) { - print(FORMAT_NEIGHBOR_LINE1, - bgpSession.remoteInfo().bgpId().toString(), - bgpSession.remoteInfo().asNumber(), - bgpSession.localInfo().asNumber()); - print(FORMAT_NEIGHBOR_LINE2, - bgpSession.remoteInfo().bgpId().toString(), - bgpSession.remoteInfo().address().toString(), - bgpSession.remoteInfo().bgpVersion(), - bgpSession.remoteInfo().holdtime()); - print(FORMAT_NEIGHBOR_LINE3, - bgpSession.remoteInfo().ipv4Unicast() ? "YES" : "NO", - bgpSession.remoteInfo().ipv4Multicast() ? "YES" : "NO", - bgpSession.remoteInfo().ipv6Unicast() ? "YES" : "NO", - bgpSession.remoteInfo().ipv6Multicast() ? "YES" : "NO"); - print(FORMAT_NEIGHBOR_LINE4, - bgpSession.localInfo().bgpId().toString(), - bgpSession.localInfo().address().toString(), - bgpSession.localInfo().bgpVersion(), - bgpSession.localInfo().holdtime()); - print(FORMAT_NEIGHBOR_LINE5, - bgpSession.localInfo().ipv4Unicast() ? "YES" : "NO", - bgpSession.localInfo().ipv4Multicast() ? "YES" : "NO", - bgpSession.localInfo().ipv6Unicast() ? "YES" : "NO", - bgpSession.localInfo().ipv6Multicast() ? "YES" : "NO"); - if (bgpSession.localInfo().as4OctetCapability() || - bgpSession.remoteInfo().as4OctetCapability()) { - print(FORMAT_NEIGHBOR_LINE6, - bgpSession.localInfo().as4OctetCapability() ? "Advertised" : "", - bgpSession.remoteInfo().as4OctetCapability() ? "Received" : ""); - } - } - - /** - * Produces a JSON array of BGP neighbors. - * - * @param bgpSessions the BGP sessions with the data - * @return JSON array with the neighbors - */ - private JsonNode json(Collection<BgpSession> bgpSessions) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - - for (BgpSession bgpSession : bgpSessions) { - result.add(json(mapper, bgpSession)); - } - return result; - } - - /** - * Produces JSON object for a BGP neighbor. - * - * @param mapper the JSON object mapper to use - * @param bgpSession the BGP session with the data - * @return JSON object for the route - */ - private ObjectNode json(ObjectMapper mapper, BgpSession bgpSession) { - ObjectNode result = mapper.createObjectNode(); - - result.put("remoteAddress", bgpSession.remoteInfo().address().toString()); - result.put("remoteBgpVersion", bgpSession.remoteInfo().bgpVersion()); - result.put("remoteAs", bgpSession.remoteInfo().asNumber()); - result.put("remoteAs4", bgpSession.remoteInfo().as4Number()); - result.put("remoteHoldtime", bgpSession.remoteInfo().holdtime()); - result.put("remoteBgpId", bgpSession.remoteInfo().bgpId().toString()); - result.put("remoteIpv4Unicast", bgpSession.remoteInfo().ipv4Unicast()); - result.put("remoteIpv4Multicast", bgpSession.remoteInfo().ipv4Multicast()); - result.put("remoteIpv6Unicast", bgpSession.remoteInfo().ipv6Unicast()); - result.put("remoteIpv6Multicast", bgpSession.remoteInfo().ipv6Multicast()); - // - result.put("localAddress", bgpSession.localInfo().address().toString()); - result.put("localBgpVersion", bgpSession.localInfo().bgpVersion()); - result.put("localAs", bgpSession.localInfo().asNumber()); - result.put("localAs4", bgpSession.localInfo().as4Number()); - result.put("localHoldtime", bgpSession.localInfo().holdtime()); - result.put("localBgpId", bgpSession.localInfo().bgpId().toString()); - result.put("localIpv4Unicast", bgpSession.localInfo().ipv4Unicast()); - result.put("localIpv4Multicast", bgpSession.localInfo().ipv4Multicast()); - result.put("localIpv6Unicast", bgpSession.localInfo().ipv6Unicast()); - result.put("localIpv6Multicast", bgpSession.localInfo().ipv6Multicast()); - - return result; - } -} diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpRoutesListCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpRoutesListCommand.java deleted file mode 100644 index ab8e975a..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpRoutesListCommand.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.routing.cli; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.routing.bgp.BgpInfoService; -import org.onosproject.routing.bgp.BgpRouteEntry; -import org.onosproject.routing.bgp.BgpSession; -import org.onosproject.routing.bgp.BgpConstants; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * Command to show the routes learned through BGP. - */ -@Command(scope = "onos", name = "bgp-routes", - description = "Lists all BGP best routes") -public class BgpRoutesListCommand extends AbstractShellCommand { - @Option(name = "-s", aliases = "--summary", - description = "BGP routes summary", - required = false, multiValued = false) - private boolean routesSummary = false; - - @Option(name = "-n", aliases = "--neighbor", - description = "Routes from a BGP neighbor", - required = false, multiValued = false) - private String bgpNeighbor; - - private static final String FORMAT_SUMMARY_V4 = - "Total BGP IPv4 routes = %d"; - private static final String FORMAT_SUMMARY_V6 = - "Total BGP IPv6 routes = %d"; - private static final String FORMAT_HEADER = - " Network Next Hop Origin LocalPref MED BGP-ID"; - private static final String FORMAT_ROUTE_LINE1 = - " %-18s %-15s %6s %9s %9s %-15s"; - private static final String FORMAT_ROUTE_LINE2 = - " AsPath %s"; - - @Override - protected void execute() { - BgpInfoService service = AbstractShellCommand.get(BgpInfoService.class); - - // Print summary of the routes - if (routesSummary) { - printSummary(service.getBgpRoutes4(), service.getBgpRoutes6()); - return; - } - - BgpSession foundBgpSession = null; - if (bgpNeighbor != null) { - // Print the routes from a single neighbor (if found) - for (BgpSession bgpSession : service.getBgpSessions()) { - if (bgpSession.remoteInfo().bgpId().toString().equals(bgpNeighbor)) { - foundBgpSession = bgpSession; - break; - } - } - if (foundBgpSession == null) { - print("BGP neighbor %s not found", bgpNeighbor); - return; - } - } - - // Print the routes - if (foundBgpSession != null) { - printRoutes(foundBgpSession.getBgpRibIn4(), - foundBgpSession.getBgpRibIn6()); - } else { - printRoutes(service.getBgpRoutes4(), service.getBgpRoutes6()); - } - } - - /** - * Prints summary of the routes. - * - * @param routes4 the IPv4 routes - * @param routes6 the IPv6 routes - */ - private void printSummary(Collection<BgpRouteEntry> routes4, - Collection<BgpRouteEntry> routes6) { - if (outputJson()) { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode result = mapper.createObjectNode(); - result.put("totalRoutes4", routes4.size()); - result.put("totalRoutes6", routes6.size()); - print("%s", result); - } else { - print(FORMAT_SUMMARY_V4, routes4.size()); - print(FORMAT_SUMMARY_V6, routes6.size()); - } - } - - /** - * Prints all routes. - * - * @param routes4 the IPv4 routes to print - * @param routes6 the IPv6 routes to print - */ - private void printRoutes(Collection<BgpRouteEntry> routes4, - Collection<BgpRouteEntry> routes6) { - if (outputJson()) { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode result = mapper.createObjectNode(); - result.set("routes4", json(routes4)); - result.set("routes6", json(routes6)); - print("%s", result); - } else { - // The IPv4 routes - print(FORMAT_HEADER); - for (BgpRouteEntry route : routes4) { - printRoute(route); - } - print(FORMAT_SUMMARY_V4, routes4.size()); - print(""); // Empty separator line - // The IPv6 routes - print(FORMAT_HEADER); - for (BgpRouteEntry route : routes6) { - printRoute(route); - } - print(FORMAT_SUMMARY_V6, routes6.size()); - } - } - - /** - * Prints a BGP route. - * - * @param route the route to print - */ - private void printRoute(BgpRouteEntry route) { - if (route != null) { - print(FORMAT_ROUTE_LINE1, route.prefix(), route.nextHop(), - BgpConstants.Update.Origin.typeToString(route.getOrigin()), - route.getLocalPref(), route.getMultiExitDisc(), - route.getBgpSession().remoteInfo().bgpId()); - print(FORMAT_ROUTE_LINE2, asPath4Cli(route.getAsPath())); - } - } - - /** - * Formats the AS Path as a string that can be shown on the CLI. - * - * @param asPath the AS Path to format - * @return the AS Path as a string - */ - private String asPath4Cli(BgpRouteEntry.AsPath asPath) { - ArrayList<BgpRouteEntry.PathSegment> pathSegments = - asPath.getPathSegments(); - - if (pathSegments.isEmpty()) { - return "[none]"; - } - - final StringBuilder builder = new StringBuilder(); - for (BgpRouteEntry.PathSegment pathSegment : pathSegments) { - String prefix = null; - String suffix = null; - switch (pathSegment.getType()) { - case BgpConstants.Update.AsPath.AS_SET: - prefix = "[AS-Set"; - suffix = "]"; - break; - case BgpConstants.Update.AsPath.AS_SEQUENCE: - break; - case BgpConstants.Update.AsPath.AS_CONFED_SEQUENCE: - prefix = "[AS-Confed-Seq"; - suffix = "]"; - break; - case BgpConstants.Update.AsPath.AS_CONFED_SET: - prefix = "[AS-Confed-Set"; - suffix = "]"; - break; - default: - builder.append(String.format("(type = %s)", - BgpConstants.Update.AsPath.typeToString(pathSegment.getType()))); - break; - } - - if (prefix != null) { - if (builder.length() > 0) { - builder.append(" "); // Separator - } - builder.append(prefix); - } - // Print the AS numbers - for (Long asn : pathSegment.getSegmentAsNumbers()) { - if (builder.length() > 0) { - builder.append(" "); // Separator - } - builder.append(String.format("%d", asn)); - } - if (suffix != null) { - // No need for separator - builder.append(prefix); - } - } - return builder.toString(); - } - - /** - * Produces a JSON array of routes. - * - * @param routes the routes with the data - * @return JSON array with the routes - */ - private JsonNode json(Collection<BgpRouteEntry> routes) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - - for (BgpRouteEntry route : routes) { - result.add(json(mapper, route)); - } - return result; - } - - /** - * Produces JSON object for a route. - * - * @param mapper the JSON object mapper to use - * @param route the route with the data - * @return JSON object for the route - */ - private ObjectNode json(ObjectMapper mapper, BgpRouteEntry route) { - ObjectNode result = mapper.createObjectNode(); - - result.put("prefix", route.prefix().toString()); - result.put("nextHop", route.nextHop().toString()); - result.put("bgpId", - route.getBgpSession().remoteInfo().bgpId().toString()); - result.put("origin", BgpConstants.Update.Origin.typeToString(route.getOrigin())); - result.set("asPath", json(mapper, route.getAsPath())); - result.put("localPref", route.getLocalPref()); - result.put("multiExitDisc", route.getMultiExitDisc()); - - return result; - } - - /** - * Produces JSON object for an AS path. - * - * @param mapper the JSON object mapper to use - * @param asPath the AS path with the data - * @return JSON object for the AS path - */ - private ObjectNode json(ObjectMapper mapper, BgpRouteEntry.AsPath asPath) { - ObjectNode result = mapper.createObjectNode(); - ArrayNode pathSegmentsJson = mapper.createArrayNode(); - for (BgpRouteEntry.PathSegment pathSegment : asPath.getPathSegments()) { - ObjectNode pathSegmentJson = mapper.createObjectNode(); - pathSegmentJson.put("type", - BgpConstants.Update.AsPath.typeToString(pathSegment.getType())); - ArrayNode segmentAsNumbersJson = mapper.createArrayNode(); - for (Long asNumber : pathSegment.getSegmentAsNumbers()) { - segmentAsNumbersJson.add(asNumber); - } - pathSegmentJson.set("segmentAsNumbers", segmentAsNumbersJson); - pathSegmentsJson.add(pathSegmentJson); - } - result.set("pathSegments", pathSegmentsJson); - - return result; - } -} diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java deleted file mode 100644 index 064080fd..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.routing.cli; - -import com.google.common.collect.Lists; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cli.Comparators; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.routing.RoutingService; -import org.onosproject.routing.config.BgpConfig; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -/** - * Lists the BGP speakers configured in the system. - */ -@Command(scope = "onos", name = "bgp-speakers", - description = "Lists all BGP speakers") -public class BgpSpeakersListCommand extends AbstractShellCommand { - - private static final String FORMAT = "port=%s/%s, peers=%s"; - private static final String NAME_FORMAT = "%s: " + FORMAT; - - private static final Comparator<BgpConfig.BgpSpeakerConfig> SPEAKERS_COMPARATOR = (s1, s2) -> - Comparators.CONNECT_POINT_COMPARATOR.compare(s1.connectPoint(), s2.connectPoint()); - - @Override - protected void execute() { - NetworkConfigService configService = get(NetworkConfigService.class); - CoreService coreService = get(CoreService.class); - ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); - - BgpConfig config = configService.getConfig(appId, BgpConfig.class); - if (config == null) { - print("No speakers configured"); - return; - } - - List<BgpConfig.BgpSpeakerConfig> bgpSpeakers = - Lists.newArrayList(config.bgpSpeakers()); - - Collections.sort(bgpSpeakers, SPEAKERS_COMPARATOR); - - if (config.bgpSpeakers().isEmpty()) { - print("No speakers configured"); - } else { - bgpSpeakers.forEach( - s -> { - if (s.name().isPresent()) { - print(NAME_FORMAT, s.name().get(), s.connectPoint().deviceId(), - s.connectPoint().port(), s.peers()); - } else { - print(FORMAT, s.connectPoint().deviceId(), - s.connectPoint().port(), s.peers()); - } - }); - } - } -} diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/RemoveRouteCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/RemoveRouteCommand.java deleted file mode 100644 index 3e216f95..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/RemoveRouteCommand.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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.routing.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.MacAddress; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.routing.FibEntry; -import org.onosproject.routing.FibListener; -import org.onosproject.routing.FibUpdate; -import org.onosproject.routing.StaticRoutingService; - -import java.util.Arrays; -import java.util.Collections; - -@Command(scope = "onos", name = "remove-route", description = "Removes static route") -public class RemoveRouteCommand extends AbstractShellCommand { - @Argument(index = 0, name = "prefix IP MAC", - description = "prefix nexthopIP nexthopMAC", - required = true, multiValued = true) - String[] fibEntryString = null; - - @Override - protected void execute() { - StaticRoutingService routingService = get(StaticRoutingService.class); - - if (fibEntryString.length < 3) { - return; - } - - IpPrefix prefix = IpPrefix.valueOf(fibEntryString[0]); - IpAddress nextHopIp = IpAddress.valueOf(fibEntryString[1]); - MacAddress nextHopMac = MacAddress.valueOf(fibEntryString[2]); - FibEntry fibEntry = new FibEntry(prefix, nextHopIp, nextHopMac); - FibUpdate fibUpdate = new FibUpdate(FibUpdate.Type.DELETE, fibEntry); - - FibListener fibListener = routingService.getFibListener(); - fibListener.update(Collections.emptyList(), Arrays.asList(fibUpdate)); - } -} diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/RoutesListCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/RoutesListCommand.java deleted file mode 100644 index 04fcb8ff..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/RoutesListCommand.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2014-2015 Open Networking Laboratory - * - * 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.routing.cli; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.karaf.shell.commands.Command; -import org.apache.karaf.shell.commands.Option; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.routing.RouteEntry; -import org.onosproject.routing.RoutingService; - -import java.util.Collection; - -/** - * Command to show the list of routes in SDN-IP's routing table. - */ -@Command(scope = "onos", name = "routes", - description = "Lists all SDN-IP best routes") -public class RoutesListCommand extends AbstractShellCommand { - @Option(name = "-s", aliases = "--summary", - description = "SDN-IP routes summary", - required = false, multiValued = false) - private boolean routesSummary = false; - - private static final String FORMAT_SUMMARY_V4 = - "Total SDN-IP IPv4 routes = %d"; - private static final String FORMAT_SUMMARY_V6 = - "Total SDN-IP IPv6 routes = %d"; - private static final String FORMAT_HEADER = - " Network Next Hop"; - private static final String FORMAT_ROUTE = - " %-18s %-15s"; - - @Override - protected void execute() { - RoutingService service = AbstractShellCommand.get(RoutingService.class); - - // Print summary of the routes - if (routesSummary) { - printSummary(service.getRoutes4(), service.getRoutes6()); - return; - } - - // Print all routes - printRoutes(service.getRoutes4(), service.getRoutes6()); - } - - /** - * Prints summary of the routes. - * - * @param routes4 the IPv4 routes - * @param routes6 the IPv6 routes - */ - private void printSummary(Collection<RouteEntry> routes4, - Collection<RouteEntry> routes6) { - if (outputJson()) { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode result = mapper.createObjectNode(); - result.put("totalRoutes4", routes4.size()); - result.put("totalRoutes6", routes6.size()); - print("%s", result); - } else { - print(FORMAT_SUMMARY_V4, routes4.size()); - print(FORMAT_SUMMARY_V6, routes6.size()); - } - } - - /** - * Prints all routes. - * - * @param routes4 the IPv4 routes to print - * @param routes6 the IPv6 routes to print - */ - private void printRoutes(Collection<RouteEntry> routes4, - Collection<RouteEntry> routes6) { - if (outputJson()) { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode result = mapper.createObjectNode(); - result.set("routes4", json(routes4)); - result.set("routes6", json(routes6)); - print("%s", result); - } else { - // The IPv4 routes - print(FORMAT_HEADER); - for (RouteEntry route : routes4) { - printRoute(route); - } - print(FORMAT_SUMMARY_V4, routes4.size()); - print(""); // Empty separator line - // The IPv6 routes - print(FORMAT_HEADER); - for (RouteEntry route : routes6) { - printRoute(route); - } - print(FORMAT_SUMMARY_V6, routes6.size()); - } - } - - /** - * Prints a route. - * - * @param route the route to print - */ - private void printRoute(RouteEntry route) { - if (route != null) { - print(FORMAT_ROUTE, route.prefix(), route.nextHop()); - } - } - - /** - * Produces a JSON array of routes. - * - * @param routes the routes with the data - * @return JSON array with the routes - */ - private JsonNode json(Collection<RouteEntry> routes) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - - for (RouteEntry route : routes) { - result.add(json(mapper, route)); - } - return result; - } - - /** - * Produces JSON object for a route. - * - * @param mapper the JSON object mapper to use - * @param route the route with the data - * @return JSON object for the route - */ - private ObjectNode json(ObjectMapper mapper, RouteEntry route) { - ObjectNode result = mapper.createObjectNode(); - - result.put("prefix", route.prefix().toString()); - result.put("nextHop", route.nextHop().toString()); - - return result; - } -} diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/package-info.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/package-info.java deleted file mode 100644 index cb6781e3..00000000 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2015 Open Networking Laboratory - * - * 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. - */ - -/** - * CLI handlers for routing commands. - */ -package org.onosproject.routing.cli; |