From 8e4b107d998ae349de59486ec84d1b33ecade710 Mon Sep 17 00:00:00 2001 From: Carmelo Cascone Date: Thu, 5 Sep 2019 20:52:13 -0700 Subject: [PATCH 1/2] Remove Srv6 related parts from app --- .gitignore | 1 + Makefile | 2 +- .../ngsdn/tutorial/Ipv6RoutingComponent.java | 52 +-- .../ngsdn/tutorial/L2BridgingComponent.java | 8 +- .../ngsdn/tutorial/MainComponent.java | 18 +- .../ngsdn/tutorial/NdpReplyComponent.java | 6 +- .../ngsdn/tutorial/Srv6Component.java | 318 ------------------ .../ngsdn/tutorial/cli/Srv6ClearCommand.java | 55 --- .../ngsdn/tutorial/cli/Srv6InsertCommand.java | 80 ----- .../ngsdn/tutorial/cli/Srv6SidCompleter.java | 59 ---- .../ngsdn/tutorial/cli/package-info.java | 1 + ...iceConfig.java => FabricDeviceConfig.java} | 22 +- mininet/netcfg.json | 12 +- 13 files changed, 36 insertions(+), 598 deletions(-) delete mode 100644 app/src/main/java/org/onosproject/ngsdn/tutorial/Srv6Component.java delete mode 100644 app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6ClearCommand.java delete mode 100644 app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6InsertCommand.java delete mode 100644 app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6SidCompleter.java create mode 100644 app/src/main/java/org/onosproject/ngsdn/tutorial/cli/package-info.java rename app/src/main/java/org/onosproject/ngsdn/tutorial/common/{Srv6DeviceConfig.java => FabricDeviceConfig.java} (71%) diff --git a/.gitignore b/.gitignore index c68fcfc..0699013 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ app/src/main/resources/bmv2.json ptf/bmv2.log ptf/ptf.log ptf/ptf.pcap +**/*.iml diff --git a/Makefile b/Makefile index 54c4a16..d3028e5 100644 --- a/Makefile +++ b/Makefile @@ -113,7 +113,7 @@ app-install: $(info *** Installing and activating app in ONOS...) ${onos_curl} -X POST -HContent-Type:application/octet-stream \ '${onos_url}/v1/applications?activate=true' \ - --data-binary @app/target/srv6-tutorial-1.0-SNAPSHOT.oar + --data-binary @app/target/ngsdn-tutorial-1.0-SNAPSHOT.oar @echo app-uninstall: diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/Ipv6RoutingComponent.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/Ipv6RoutingComponent.java index 9cd01da..7389a0b 100644 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/Ipv6RoutingComponent.java +++ b/app/src/main/java/org/onosproject/ngsdn/tutorial/Ipv6RoutingComponent.java @@ -60,7 +60,7 @@ import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; -import org.onosproject.ngsdn.tutorial.common.Srv6DeviceConfig; +import org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig; import org.onosproject.ngsdn.tutorial.common.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -571,11 +571,6 @@ private void setUpSpineRoutes(DeviceId spineId) { final MacAddress leafMac = getMyStationMac(leafId); final Set subnetsToRoute = getInterfaceIpv6Prefixes(leafId); - // Since we're here, we also add a route for SRv6, to forward - // packets with IPv6 dst the SID of a leaf switch. - final Ip6Address leafSid = getDeviceSid(leafId); - subnetsToRoute.add(Ip6Prefix.valueOf(leafSid, 128)); - // Create a group with only one member. int groupId = macToGroupId(leafMac); @@ -628,24 +623,6 @@ private void setUpLeafRoutes(DeviceId leafId) { .collect(Collectors.toList()); insertInOrder(ecmpGroup, flowRules); - - // Since we're here, we also add a route for SRv6, to forward - // packets with IPv6 dst the SID of a spine switch, in this case using a - // single-member group. - stream(deviceService.getDevices()) - .map(Device::id) - .filter(this::isSpine) - .forEach(spineId -> { - MacAddress spineMac = getMyStationMac(spineId); - Ip6Address spineSid = getDeviceSid(spineId); - int spineGroupId = macToGroupId(spineMac); - GroupDescription group = createNextHopGroup( - spineGroupId, Collections.singleton(spineMac), leafId); - FlowRule routingRule = createRoutingRule( - leafId, Ip6Prefix.valueOf(spineSid, 128), - spineGroupId); - insertInOrder(group, Collections.singleton(routingRule)); - }); } //-------------------------------------------------------------------------- @@ -660,7 +637,7 @@ private void setUpLeafRoutes(DeviceId leafId) { * @return true if the device is a spine, false otherwise */ private boolean isSpine(DeviceId deviceId) { - return getDeviceConfig(deviceId).map(Srv6DeviceConfig::isSpine) + return getDeviceConfig(deviceId).map(FabricDeviceConfig::isSpine) .orElseThrow(() -> new ItemNotFoundException( "Missing isSpine config for " + deviceId)); } @@ -684,20 +661,20 @@ private boolean isLeaf(DeviceId deviceId) { */ private MacAddress getMyStationMac(DeviceId deviceId) { return getDeviceConfig(deviceId) - .map(Srv6DeviceConfig::myStationMac) + .map(FabricDeviceConfig::myStationMac) .orElseThrow(() -> new ItemNotFoundException( "Missing myStationMac config for " + deviceId)); } /** - * Returns the Srv6 config object for the given device. + * Returns the fabric config object for the given device. * * @param deviceId the device ID - * @return Srv6 device config + * @return fabric device config */ - private Optional getDeviceConfig(DeviceId deviceId) { - Srv6DeviceConfig config = networkConfigService.getConfig( - deviceId, Srv6DeviceConfig.class); + private Optional getDeviceConfig(DeviceId deviceId) { + FabricDeviceConfig config = networkConfigService.getConfig( + deviceId, FabricDeviceConfig.class); return Optional.ofNullable(config); } @@ -749,19 +726,6 @@ private void insertInOrder(GroupDescription group, Collection flowRule } } - /** - * Gets Srv6 SID for the given device. - * - * @param deviceId the device ID - * @return SID for the device - */ - private Ip6Address getDeviceSid(DeviceId deviceId) { - return getDeviceConfig(deviceId) - .map(Srv6DeviceConfig::mySid) - .orElseThrow(() -> new ItemNotFoundException( - "Missing mySid config for " + deviceId)); - } - /** * Sets up IPv6 routing on all devices known by ONOS and for which this ONOS * node instance is currently master. diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/L2BridgingComponent.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/L2BridgingComponent.java index 7c933e7..51207d9 100644 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/L2BridgingComponent.java +++ b/app/src/main/java/org/onosproject/ngsdn/tutorial/L2BridgingComponent.java @@ -47,7 +47,7 @@ import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; -import org.onosproject.ngsdn.tutorial.common.Srv6DeviceConfig; +import org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig; import org.onosproject.ngsdn.tutorial.common.Utils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -423,15 +423,15 @@ private boolean isSpine(DeviceId deviceId) { // "devices": { // "device:spine1": { // ... - // "srv6DeviceConfig": { + // "fabricDeviceConfig": { // "myStationMac": "...", // "mySid": "...", // "isSpine": true // } // }, // ... - final Srv6DeviceConfig cfg = configService.getConfig( - deviceId, Srv6DeviceConfig.class); + final FabricDeviceConfig cfg = configService.getConfig( + deviceId, FabricDeviceConfig.class); return cfg != null && cfg.isSpine(); } diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/MainComponent.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/MainComponent.java index 517e1bd..190fd97 100644 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/MainComponent.java +++ b/app/src/main/java/org/onosproject/ngsdn/tutorial/MainComponent.java @@ -20,7 +20,7 @@ import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; -import org.onosproject.ngsdn.tutorial.common.Srv6DeviceConfig; +import org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig; import org.onosproject.ngsdn.tutorial.pipeconf.PipeconfLoader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,7 +36,7 @@ import static org.onosproject.ngsdn.tutorial.common.Utils.sleep; /** - * A component which among other things registers the Srv6DeviceConfig to the + * A component which among other things registers the fabricDeviceConfig to the * netcfg subsystem. */ @Component(immediate = true, service = MainComponent.class) @@ -68,12 +68,12 @@ public class MainComponent { @Reference(cardinality = ReferenceCardinality.MANDATORY) private ComponentConfigService compCfgService; - private final ConfigFactory srv6ConfigFactory = - new ConfigFactory( - SubjectFactories.DEVICE_SUBJECT_FACTORY, Srv6DeviceConfig.class, Srv6DeviceConfig.CONFIG_KEY) { + private final ConfigFactory fabricConfigFactory = + new ConfigFactory( + SubjectFactories.DEVICE_SUBJECT_FACTORY, FabricDeviceConfig.class, FabricDeviceConfig.CONFIG_KEY) { @Override - public Srv6DeviceConfig createConfig() { - return new Srv6DeviceConfig(); + public FabricDeviceConfig createConfig() { + return new FabricDeviceConfig(); } }; @@ -97,13 +97,13 @@ protected void activate() { compCfgService.preSetProperty("org.onosproject.provider.host.impl.HostLocationProvider", "requestIpv6ND", "true", false); - configRegistry.registerConfigFactory(srv6ConfigFactory); + configRegistry.registerConfigFactory(fabricConfigFactory); log.info("Started"); } @Deactivate protected void deactivate() { - configRegistry.unregisterConfigFactory(srv6ConfigFactory); + configRegistry.unregisterConfigFactory(fabricConfigFactory); cleanUp(); diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/NdpReplyComponent.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/NdpReplyComponent.java index 3a59871..260982e 100644 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/NdpReplyComponent.java +++ b/app/src/main/java/org/onosproject/ngsdn/tutorial/NdpReplyComponent.java @@ -50,7 +50,7 @@ import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.osgi.service.component.annotations.ReferenceCardinality; -import org.onosproject.ngsdn.tutorial.common.Srv6DeviceConfig; +import org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -122,10 +122,10 @@ private void setUpAllDevices() { } private void setUpDevice(DeviceId deviceId) { - Srv6DeviceConfig config = configService.getConfig(deviceId, Srv6DeviceConfig.class); + FabricDeviceConfig config = configService.getConfig(deviceId, FabricDeviceConfig.class); if (config == null) { // Config not available yet - throw new ItemNotFoundException("Missing Srv6Config for " + deviceId); + throw new ItemNotFoundException("Missing FabricDeviceConfig for " + deviceId); } final MacAddress deviceMac = config.myStationMac(); diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/Srv6Component.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/Srv6Component.java deleted file mode 100644 index de24385..0000000 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/Srv6Component.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright 2019-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.ngsdn.tutorial; - -import com.google.common.collect.Lists; -import org.onlab.packet.Ip6Address; -import org.onosproject.core.ApplicationId; -import org.onosproject.mastership.MastershipService; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleOperations; -import org.onosproject.net.flow.FlowRuleService; -import org.onosproject.net.flow.criteria.PiCriterion; -import org.onosproject.net.pi.model.PiActionId; -import org.onosproject.net.pi.model.PiActionParamId; -import org.onosproject.net.pi.model.PiMatchFieldId; -import org.onosproject.net.pi.model.PiTableId; -import org.onosproject.net.pi.runtime.PiAction; -import org.onosproject.net.pi.runtime.PiActionParam; -import org.onosproject.net.pi.runtime.PiTableAction; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Deactivate; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.component.annotations.ReferenceCardinality; -import org.onosproject.ngsdn.tutorial.common.Srv6DeviceConfig; -import org.onosproject.ngsdn.tutorial.common.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.List; -import java.util.Optional; - -import static com.google.common.collect.Streams.stream; -import static org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY; - -/** - * Application which handles SRv6 segment routing. - */ -@Component( - immediate = true, - enabled = true, - service = Srv6Component.class -) -public class Srv6Component { - - private static final Logger log = LoggerFactory.getLogger(Srv6Component.class); - - //-------------------------------------------------------------------------- - // ONOS CORE SERVICE BINDING - // - // These variables are set by the Karaf runtime environment before calling - // the activate() method. - //-------------------------------------------------------------------------- - - @Reference(cardinality = ReferenceCardinality.MANDATORY) - private FlowRuleService flowRuleService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY) - private MastershipService mastershipService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY) - private DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY) - private NetworkConfigService networkConfigService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY) - private MainComponent mainComponent; - - private final DeviceListener deviceListener = new Srv6Component.InternalDeviceListener(); - - private ApplicationId appId; - - //-------------------------------------------------------------------------- - // COMPONENT ACTIVATION. - // - // When loading/unloading the app the Karaf runtime environment will call - // activate()/deactivate(). - //-------------------------------------------------------------------------- - - @Activate - protected void activate() { - appId = mainComponent.getAppId(); - - // Register listeners to be informed about device and host events. - deviceService.addListener(deviceListener); - - // Schedule set up for all devices. - mainComponent.scheduleTask(this::setUpAllDevices, INITIAL_SETUP_DELAY); - - log.info("Started"); - } - - @Deactivate - protected void deactivate() { - deviceService.removeListener(deviceListener); - - log.info("Stopped"); - } - - //-------------------------------------------------------------------------- - // METHODS TO COMPLETE. - // - // Complete the implementation wherever you see TODO. - //-------------------------------------------------------------------------- - - /** - * Populate the My SID table from the network configuration for the - * specified device. - * - * @param deviceId the device Id - */ - private void setUpMySidTable(DeviceId deviceId) { - - Ip6Address mySid = getMySid(deviceId); - - log.info("Adding mySid rule on {} (sid {})...", deviceId, mySid); - - // TODO EXERCISE 4 - // Fill in the table ID for the SRv6 my segment identifier table - // ---- START SOLUTION ---- - String tableId = "IngressPipeImpl.srv6_my_sid"; - // ---- END SOLUTION ---- - - // TODO EXERCISE 4 - // Modify the field and action id to match your P4Info - // ---- START SOLUTION ---- - PiCriterion match = PiCriterion.builder() - .matchLpm( - PiMatchFieldId.of("hdr.ipv6.dst_addr"), - mySid.toOctets(), 128) - .build(); - - PiTableAction action = PiAction.builder() - .withId(PiActionId.of("IngressPipeImpl.srv6_end")) - .build(); - // ---- END SOLUTION ---- - - FlowRule myStationRule = Utils.buildFlowRule( - deviceId, appId, tableId, match, action); - - flowRuleService.applyFlowRules(myStationRule); - } - - /** - * Insert a SRv6 transit insert policy that will inject an SRv6 header for - * packets destined to destIp. - * - * @param deviceId device ID - * @param destIp target IP address for the SRv6 policy - * @param prefixLength prefix length for the target IP - * @param segmentList list of SRv6 SIDs that make up the path - */ - public void insertSrv6InsertRule(DeviceId deviceId, Ip6Address destIp, int prefixLength, - List segmentList) { - if (segmentList.size() < 2 || segmentList.size() > 3) { - throw new RuntimeException("List of " + segmentList.size() + " segments is not supported"); - } - - // TODO EXERCISE 4 - // Fill in the table ID for the SRv6 transit table. - // ---- START SOLUTION ---- - String tableId = "IngressPipeImpl.srv6_transit"; - // ---- END SOLUTION ---- - - // TODO EXERCISE 4 - // Modify match field, action id, and action parameter to match your P4Info. - // ---- START SOLUTION ---- - PiCriterion match = PiCriterion.builder() - .matchLpm(PiMatchFieldId.of("hdr.ipv6.dst_addr"), destIp.toOctets(), prefixLength) - .build(); - - List actionParams = Lists.newArrayList(); - - for (int i = 0; i < segmentList.size(); i++) { - PiActionParamId paramId = PiActionParamId.of("s" + (i + 1)); - PiActionParam param = new PiActionParam(paramId, segmentList.get(i).toOctets()); - actionParams.add(param); - } - - PiAction action = PiAction.builder() - .withId(PiActionId.of("IngressPipeImpl.srv6_t_insert_" + segmentList.size())) - .withParameters(actionParams) - .build(); - // ---- END SOLUTION ---- - - final FlowRule rule = Utils.buildFlowRule( - deviceId, appId, tableId, match, action); - - flowRuleService.applyFlowRules(rule); - } - - /** - * Remove all SRv6 transit insert polices for the specified device. - * - * @param deviceId device ID - */ - public void clearSrv6InsertRules(DeviceId deviceId) { - // TODO: fill in the table ID for the SRv6 transit table - // ---- START SOLUTION ---- - String tableId = "IngressPipeImpl.srv6_transit"; - // ---- END SOLUTION ---- - - FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); - stream(flowRuleService.getFlowEntries(deviceId)) - .filter(fe -> fe.appId() == appId.id()) - .filter(fe -> fe.table().equals(PiTableId.of(tableId))) - .forEach(ops::remove); - flowRuleService.apply(ops.build()); - } - - // ---------- END METHODS TO COMPLETE ---------------- - - //-------------------------------------------------------------------------- - // EVENT LISTENERS - // - // Events are processed only if isRelevant() returns true. - //-------------------------------------------------------------------------- - - /** - * Listener of device events. - */ - public class InternalDeviceListener implements DeviceListener { - - @Override - public boolean isRelevant(DeviceEvent event) { - switch (event.type()) { - case DEVICE_ADDED: - case DEVICE_AVAILABILITY_CHANGED: - break; - default: - // Ignore other events. - return false; - } - // Process only if this controller instance is the master. - final DeviceId deviceId = event.subject().id(); - return mastershipService.isLocalMaster(deviceId); - } - - @Override - public void event(DeviceEvent event) { - final DeviceId deviceId = event.subject().id(); - if (deviceService.isAvailable(deviceId)) { - // A P4Runtime device is considered available in ONOS when there - // is a StreamChannel session open and the pipeline - // configuration has been set. - mainComponent.getExecutorService().execute(() -> { - log.info("{} event! deviceId={}", event.type(), deviceId); - - setUpMySidTable(event.subject().id()); - }); - } - } - } - - - //-------------------------------------------------------------------------- - // UTILITY METHODS - //-------------------------------------------------------------------------- - - /** - * Sets up SRv6 My SID table on all devices known by ONOS and for which this - * ONOS node instance is currently master. - */ - private synchronized void setUpAllDevices() { - // Set up host routes - stream(deviceService.getAvailableDevices()) - .map(Device::id) - .filter(mastershipService::isLocalMaster) - .forEach(deviceId -> { - log.info("*** SRV6 - Starting initial set up for {}...", deviceId); - this.setUpMySidTable(deviceId); - }); - } - - /** - * Returns the Srv6 config for the given device. - * - * @param deviceId the device ID - * @return Srv6 device config - */ - private Optional getDeviceConfig(DeviceId deviceId) { - Srv6DeviceConfig config = networkConfigService.getConfig(deviceId, Srv6DeviceConfig.class); - return Optional.ofNullable(config); - } - - /** - * Returns Srv6 SID for the given device. - * - * @param deviceId the device ID - * @return SID for the device - */ - private Ip6Address getMySid(DeviceId deviceId) { - return getDeviceConfig(deviceId) - .map(Srv6DeviceConfig::mySid) - .orElseThrow(() -> new RuntimeException( - "Missing mySid config for " + deviceId)); - } -} diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6ClearCommand.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6ClearCommand.java deleted file mode 100644 index b8b1ccd..0000000 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6ClearCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2019-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.ngsdn.tutorial.cli; - -import org.apache.karaf.shell.api.action.Argument; -import org.apache.karaf.shell.api.action.Command; -import org.apache.karaf.shell.api.action.Completion; -import org.apache.karaf.shell.api.action.lifecycle.Service; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cli.net.DeviceIdCompleter; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.device.DeviceService; -import org.onosproject.ngsdn.tutorial.Srv6Component; - -/** - * SRv6 Transit Clear Command - */ -@Service -@Command(scope = "onos", name = "srv6-clear", - description = "Clears all t_insert rules from the SRv6 Transit table") -public class Srv6ClearCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "uri", description = "Device ID", - required = true, multiValued = false) - @Completion(DeviceIdCompleter.class) - String uri = null; - - @Override - protected void doExecute() { - DeviceService deviceService = get(DeviceService.class); - Srv6Component app = get(Srv6Component.class); - - Device device = deviceService.getDevice(DeviceId.deviceId(uri)); - if (device == null) { - print("Device \"%s\" is not found", uri); - return; - } - app.clearSrv6InsertRules(device.id()); - } - -} diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6InsertCommand.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6InsertCommand.java deleted file mode 100644 index b2c0a8e..0000000 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6InsertCommand.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2019-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.ngsdn.tutorial.cli; - -import org.apache.karaf.shell.api.action.Argument; -import org.apache.karaf.shell.api.action.Command; -import org.apache.karaf.shell.api.action.Completion; -import org.apache.karaf.shell.api.action.lifecycle.Service; -import org.onlab.packet.Ip6Address; -import org.onlab.packet.IpAddress; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cli.net.DeviceIdCompleter; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.device.DeviceService; -import org.onosproject.ngsdn.tutorial.Srv6Component; - -import java.util.List; -import java.util.stream.Collectors; - -/** - * SRv6 Transit Insert Command - */ -@Service -@Command(scope = "onos", name = "srv6-insert", - description = "Insert a t_insert rule into the SRv6 Transit table") -public class Srv6InsertCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "uri", description = "Device ID", - required = true, multiValued = false) - @Completion(DeviceIdCompleter.class) - String uri = null; - - @Argument(index = 1, name = "segments", - description = "SRv6 Segments (space separated list); last segment is target IP address", - required = false, multiValued = true) - @Completion(Srv6SidCompleter.class) - List segments = null; - - @Override - protected void doExecute() { - DeviceService deviceService = get(DeviceService.class); - Srv6Component app = get(Srv6Component.class); - - Device device = deviceService.getDevice(DeviceId.deviceId(uri)); - if (device == null) { - print("Device \"%s\" is not found", uri); - return; - } - if (segments.size() == 0) { - print("No segments listed"); - return; - } - List sids = segments.stream() - .map(Ip6Address::valueOf) - .collect(Collectors.toList()); - Ip6Address destIp = sids.get(sids.size() - 1); - - print("Installing path on device %s: %s", - uri, sids.stream() - .map(IpAddress::toString) - .collect(Collectors.joining(", "))); - app.insertSrv6InsertRule(device.id(), destIp, 128, sids); - - } - -} diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6SidCompleter.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6SidCompleter.java deleted file mode 100644 index a62703e..0000000 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/Srv6SidCompleter.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2019-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.ngsdn.tutorial.cli; - -import org.apache.karaf.shell.api.action.lifecycle.Service; -import org.apache.karaf.shell.api.console.CommandLine; -import org.apache.karaf.shell.api.console.Completer; -import org.apache.karaf.shell.api.console.Session; -import org.apache.karaf.shell.support.completers.StringsCompleter; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.net.device.DeviceService; -import org.onosproject.ngsdn.tutorial.common.Srv6DeviceConfig; - -import java.util.List; -import java.util.Objects; -import java.util.SortedSet; - -import static com.google.common.collect.Streams.stream; - -/** - * Completer for SIDs based on device config. - */ -@Service -public class Srv6SidCompleter implements Completer { - - @Override - public int complete(Session session, CommandLine commandLine, List candidates) { - DeviceService deviceService = AbstractShellCommand.get(DeviceService.class); - NetworkConfigService netCfgService = AbstractShellCommand.get(NetworkConfigService.class); - - // Delegate string completer - StringsCompleter delegate = new StringsCompleter(); - SortedSet strings = delegate.getStrings(); - - stream(deviceService.getDevices()) - .map(d -> netCfgService.getConfig(d.id(), Srv6DeviceConfig.class)) - .filter(Objects::nonNull) - .map(Srv6DeviceConfig::mySid) - .filter(Objects::nonNull) - .forEach(sid -> strings.add(sid.toString())); - - // Now let the completer do the work for figuring out what to offer. - return delegate.complete(session, commandLine, candidates); - } -} diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/package-info.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/package-info.java new file mode 100644 index 0000000..e7170fd --- /dev/null +++ b/app/src/main/java/org/onosproject/ngsdn/tutorial/cli/package-info.java @@ -0,0 +1 @@ +package org.onosproject.ngsdn.tutorial.cli; \ No newline at end of file diff --git a/app/src/main/java/org/onosproject/ngsdn/tutorial/common/Srv6DeviceConfig.java b/app/src/main/java/org/onosproject/ngsdn/tutorial/common/FabricDeviceConfig.java similarity index 71% rename from app/src/main/java/org/onosproject/ngsdn/tutorial/common/Srv6DeviceConfig.java rename to app/src/main/java/org/onosproject/ngsdn/tutorial/common/FabricDeviceConfig.java index 12a354a..7bf963c 100644 --- a/app/src/main/java/org/onosproject/ngsdn/tutorial/common/Srv6DeviceConfig.java +++ b/app/src/main/java/org/onosproject/ngsdn/tutorial/common/FabricDeviceConfig.java @@ -22,20 +22,18 @@ import org.onosproject.net.config.Config; /** - * Device configuration object for the SRv6 tutorial application. + * Device configuration object for the fabric tutorial application. */ -public class Srv6DeviceConfig extends Config { +public class FabricDeviceConfig extends Config { - public static final String CONFIG_KEY = "srv6DeviceConfig"; + public static final String CONFIG_KEY = "fabricDeviceConfig"; private static final String MY_STATION_MAC = "myStationMac"; - private static final String MY_SID = "mySid"; private static final String IS_SPINE = "isSpine"; @Override public boolean isValid() { - return hasOnlyFields(MY_STATION_MAC, MY_SID, IS_SPINE) && - myStationMac() != null && - mySid() != null; + return hasOnlyFields(MY_STATION_MAC, IS_SPINE) && + myStationMac() != null; } /** @@ -48,16 +46,6 @@ public MacAddress myStationMac() { return mac != null ? MacAddress.valueOf(mac) : null; } - /** - * Gets the SRv6 segment ID (SID) of the switch. - * - * @return IP address of the router. Or null if not configured. - */ - public Ip6Address mySid() { - String ip = get(MY_SID, null); - return ip != null ? Ip6Address.valueOf(ip) : null; - } - /** * Checks if the switch is a spine switch. * diff --git a/mininet/netcfg.json b/mininet/netcfg.json index 571e04e..a75de1b 100644 --- a/mininet/netcfg.json +++ b/mininet/netcfg.json @@ -6,9 +6,8 @@ "driver": "stratum-bmv2", "pipeconf": "org.onosproject.ngsdn-tutorial" }, - "srv6DeviceConfig": { + "fabricDeviceConfig": { "myStationMac": "00:aa:00:00:00:01", - "mySid": "3:101:2::", "isSpine": false } }, @@ -18,9 +17,8 @@ "driver": "stratum-bmv2", "pipeconf": "org.onosproject.ngsdn-tutorial" }, - "srv6DeviceConfig": { + "fabricDeviceConfig": { "myStationMac": "00:aa:00:00:00:02", - "mySid": "3:102:2::", "isSpine": false } }, @@ -30,9 +28,8 @@ "driver": "stratum-bmv2", "pipeconf": "org.onosproject.ngsdn-tutorial" }, - "srv6DeviceConfig": { + "fabricDeviceConfig": { "myStationMac": "00:bb:00:00:00:01", - "mySid": "3:201:2::", "isSpine": true } }, @@ -42,9 +39,8 @@ "driver": "stratum-bmv2", "pipeconf": "org.onosproject.ngsdn-tutorial" }, - "srv6DeviceConfig": { + "fabricDeviceConfig": { "myStationMac": "00:bb:00:00:00:02", - "mySid": "3:202:2::", "isSpine": true } } From 5ed1a5d8d1a2e57a5765473658ae4cc7c19bc1ee Mon Sep 17 00:00:00 2001 From: Carmelo Cascone Date: Thu, 5 Sep 2019 20:57:39 -0700 Subject: [PATCH 2/2] ignore *.pyc --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0699013..2868cf0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ ptf/bmv2.log ptf/ptf.log ptf/ptf.pcap **/*.iml +**/*.pyc