Implemented control plane redirect for control traffic.
Modified SoftRouterPipeline to support new flow objectives. Change-Id: Ia93bc927832444ba1f7cf20b276e4866789c9d30
Showing
9 changed files
with
347 additions
and
148 deletions
| ... | @@ -17,6 +17,7 @@ package org.onosproject.routing; | ... | @@ -17,6 +17,7 @@ package org.onosproject.routing; |
| 17 | 17 | ||
| 18 | import org.onlab.packet.IpAddress; | 18 | import org.onlab.packet.IpAddress; |
| 19 | import org.onosproject.routing.config.BgpConfig; | 19 | import org.onosproject.routing.config.BgpConfig; |
| 20 | +import org.onosproject.routing.config.RouterConfig; | ||
| 20 | 21 | ||
| 21 | import java.util.Collection; | 22 | import java.util.Collection; |
| 22 | 23 | ||
| ... | @@ -28,6 +29,7 @@ public interface RoutingService { | ... | @@ -28,6 +29,7 @@ public interface RoutingService { |
| 28 | String ROUTER_APP_ID = "org.onosproject.router"; | 29 | String ROUTER_APP_ID = "org.onosproject.router"; |
| 29 | 30 | ||
| 30 | Class<BgpConfig> CONFIG_CLASS = BgpConfig.class; | 31 | Class<BgpConfig> CONFIG_CLASS = BgpConfig.class; |
| 32 | + Class<RouterConfig> ROUTER_CONFIG_CLASS = RouterConfig.class; | ||
| 31 | 33 | ||
| 32 | /** | 34 | /** |
| 33 | * Starts the routing service. | 35 | * Starts the routing service. | ... | ... |
| ... | @@ -42,8 +42,6 @@ public class BgpConfig extends Config<ApplicationId> { | ... | @@ -42,8 +42,6 @@ public class BgpConfig extends Config<ApplicationId> { |
| 42 | public static final String NAME = "name"; | 42 | public static final String NAME = "name"; |
| 43 | public static final String PEERS = "peers"; | 43 | public static final String PEERS = "peers"; |
| 44 | 44 | ||
| 45 | - // TODO add methods for updating config | ||
| 46 | - | ||
| 47 | /** | 45 | /** |
| 48 | * Gets the set of configured BGP speakers. | 46 | * Gets the set of configured BGP speakers. |
| 49 | * | 47 | * | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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 | + | ||
| 17 | +package org.onosproject.routing.config; | ||
| 18 | + | ||
| 19 | +import org.onosproject.core.ApplicationId; | ||
| 20 | +import org.onosproject.net.ConnectPoint; | ||
| 21 | +import org.onosproject.net.config.Config; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Routing configuration. | ||
| 25 | + */ | ||
| 26 | +public class RouterConfig extends Config<ApplicationId> { | ||
| 27 | + | ||
| 28 | + public static final String CP_CONNECT_POINT = "controlPlaneConnectPoint"; | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * Returns the routing control plane connect point. | ||
| 32 | + * | ||
| 33 | + * @return control plane connect point | ||
| 34 | + */ | ||
| 35 | + public ConnectPoint getControlPlaneConnectPoint() { | ||
| 36 | + return ConnectPoint.deviceConnectPoint(object.path(CP_CONNECT_POINT).asText()); | ||
| 37 | + } | ||
| 38 | +} |
| ... | @@ -41,6 +41,7 @@ import org.onosproject.net.config.basics.SubjectFactories; | ... | @@ -41,6 +41,7 @@ import org.onosproject.net.config.basics.SubjectFactories; |
| 41 | import org.onosproject.routing.config.BgpConfig; | 41 | import org.onosproject.routing.config.BgpConfig; |
| 42 | import org.onosproject.routing.config.BgpPeer; | 42 | import org.onosproject.routing.config.BgpPeer; |
| 43 | import org.onosproject.routing.config.BgpSpeaker; | 43 | import org.onosproject.routing.config.BgpSpeaker; |
| 44 | +import org.onosproject.routing.config.RouterConfig; | ||
| 44 | import org.onosproject.routing.config.Interface; | 45 | import org.onosproject.routing.config.Interface; |
| 45 | import org.onosproject.routing.config.LocalIpPrefixEntry; | 46 | import org.onosproject.routing.config.LocalIpPrefixEntry; |
| 46 | import org.onosproject.routing.config.RoutingConfigurationService; | 47 | import org.onosproject.routing.config.RoutingConfigurationService; |
| ... | @@ -100,24 +101,36 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { | ... | @@ -100,24 +101,36 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { |
| 100 | 101 | ||
| 101 | private MacAddress virtualGatewayMacAddress; | 102 | private MacAddress virtualGatewayMacAddress; |
| 102 | 103 | ||
| 103 | - private ConfigFactory configFactory = | 104 | + private ConfigFactory<ApplicationId, BgpConfig> bgpConfigFactory = |
| 104 | - new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, BgpConfig.class, "bgp") { | 105 | + new ConfigFactory<ApplicationId, BgpConfig>( |
| 106 | + SubjectFactories.APP_SUBJECT_FACTORY, BgpConfig.class, "bgp") { | ||
| 105 | @Override | 107 | @Override |
| 106 | public BgpConfig createConfig() { | 108 | public BgpConfig createConfig() { |
| 107 | return new BgpConfig(); | 109 | return new BgpConfig(); |
| 108 | } | 110 | } |
| 109 | }; | 111 | }; |
| 110 | 112 | ||
| 113 | + private ConfigFactory<ApplicationId, RouterConfig> routerConfigFactory = | ||
| 114 | + new ConfigFactory<ApplicationId, RouterConfig>( | ||
| 115 | + SubjectFactories.APP_SUBJECT_FACTORY, RouterConfig.class, "router") { | ||
| 116 | + @Override | ||
| 117 | + public RouterConfig createConfig() { | ||
| 118 | + return new RouterConfig(); | ||
| 119 | + } | ||
| 120 | + }; | ||
| 121 | + | ||
| 111 | @Activate | 122 | @Activate |
| 112 | public void activate() { | 123 | public void activate() { |
| 113 | - registry.registerConfigFactory(configFactory); | 124 | + registry.registerConfigFactory(bgpConfigFactory); |
| 125 | + registry.registerConfigFactory(routerConfigFactory); | ||
| 114 | readConfiguration(); | 126 | readConfiguration(); |
| 115 | log.info("Routing configuration service started"); | 127 | log.info("Routing configuration service started"); |
| 116 | } | 128 | } |
| 117 | 129 | ||
| 118 | @Deactivate | 130 | @Deactivate |
| 119 | public void deactivate() { | 131 | public void deactivate() { |
| 120 | - registry.unregisterConfigFactory(configFactory); | 132 | + registry.unregisterConfigFactory(bgpConfigFactory); |
| 133 | + registry.registerConfigFactory(routerConfigFactory); | ||
| 121 | log.info("Routing configuration service stopped"); | 134 | log.info("Routing configuration service stopped"); |
| 122 | } | 135 | } |
| 123 | 136 | ... | ... |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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 | + | ||
| 17 | +package org.onosproject.routing.impl; | ||
| 18 | + | ||
| 19 | +import org.apache.felix.scr.annotations.Activate; | ||
| 20 | +import org.apache.felix.scr.annotations.Component; | ||
| 21 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 22 | +import org.apache.felix.scr.annotations.Reference; | ||
| 23 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 24 | +import org.onlab.packet.EthType; | ||
| 25 | +import org.onosproject.core.ApplicationId; | ||
| 26 | +import org.onosproject.core.CoreService; | ||
| 27 | +import org.onosproject.incubator.net.intf.Interface; | ||
| 28 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
| 29 | +import org.onosproject.net.ConnectPoint; | ||
| 30 | +import org.onosproject.net.DeviceId; | ||
| 31 | +import org.onosproject.net.PortNumber; | ||
| 32 | +import org.onosproject.net.config.NetworkConfigEvent; | ||
| 33 | +import org.onosproject.net.config.NetworkConfigListener; | ||
| 34 | +import org.onosproject.net.config.NetworkConfigService; | ||
| 35 | +import org.onosproject.net.device.DeviceEvent; | ||
| 36 | +import org.onosproject.net.device.DeviceListener; | ||
| 37 | +import org.onosproject.net.device.DeviceService; | ||
| 38 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 39 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 40 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 41 | +import org.onosproject.net.flow.TrafficTreatment; | ||
| 42 | +import org.onosproject.net.flowobjective.DefaultForwardingObjective; | ||
| 43 | +import org.onosproject.net.flowobjective.FlowObjectiveService; | ||
| 44 | +import org.onosproject.net.flowobjective.ForwardingObjective; | ||
| 45 | +import org.onosproject.net.host.InterfaceIpAddress; | ||
| 46 | +import org.onosproject.routing.RoutingService; | ||
| 47 | +import org.onosproject.routing.config.RouterConfig; | ||
| 48 | +import org.slf4j.Logger; | ||
| 49 | + | ||
| 50 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 51 | + | ||
| 52 | +/** | ||
| 53 | + * Manages connectivity between peers redirecting control traffic to a routing | ||
| 54 | + * control plane available on the dataplane. | ||
| 55 | + */ | ||
| 56 | +@Component(immediate = true, enabled = false) | ||
| 57 | +public class ControlPlaneRedirectManager { | ||
| 58 | + | ||
| 59 | + private final Logger log = getLogger(getClass()); | ||
| 60 | + | ||
| 61 | + private static final int PRIORITY = 40001; | ||
| 62 | + | ||
| 63 | + private static final String APP_NAME = "org.onosproject.cpredirect"; | ||
| 64 | + private ApplicationId appId; | ||
| 65 | + | ||
| 66 | + private ConnectPoint controlPlaneConnectPoint; | ||
| 67 | + | ||
| 68 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 69 | + protected CoreService coreService; | ||
| 70 | + | ||
| 71 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 72 | + protected DeviceService deviceService; | ||
| 73 | + | ||
| 74 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 75 | + protected InterfaceService interfaceService; | ||
| 76 | + | ||
| 77 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 78 | + protected FlowObjectiveService flowObjectiveService; | ||
| 79 | + | ||
| 80 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 81 | + protected NetworkConfigService networkConfigService; | ||
| 82 | + | ||
| 83 | + private final InternalDeviceListener deviceListener = new InternalDeviceListener(); | ||
| 84 | + private final InternalNetworkConfigListener networkConfigListener = | ||
| 85 | + new InternalNetworkConfigListener(); | ||
| 86 | + | ||
| 87 | + @Activate | ||
| 88 | + public void activate() { | ||
| 89 | + this.appId = coreService.registerApplication(APP_NAME); | ||
| 90 | + | ||
| 91 | + deviceService.addListener(deviceListener); | ||
| 92 | + networkConfigService.addListener(networkConfigListener); | ||
| 93 | + | ||
| 94 | + updateConfig(); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Deactivate | ||
| 98 | + public void deactivate() { | ||
| 99 | + deviceService.removeListener(deviceListener); | ||
| 100 | + networkConfigService.removeListener(networkConfigListener); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + private void updateConfig() { | ||
| 104 | + ApplicationId routingAppId = | ||
| 105 | + coreService.registerApplication(RoutingService.ROUTER_APP_ID); | ||
| 106 | + | ||
| 107 | + RouterConfig config = networkConfigService.getConfig( | ||
| 108 | + routingAppId, RoutingService.ROUTER_CONFIG_CLASS); | ||
| 109 | + | ||
| 110 | + if (config == null) { | ||
| 111 | + log.info("Router config not available"); | ||
| 112 | + return; | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + if (!config.getControlPlaneConnectPoint().equals(controlPlaneConnectPoint)) { | ||
| 116 | + this.controlPlaneConnectPoint = config.getControlPlaneConnectPoint(); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + if (controlPlaneConnectPoint != null && | ||
| 120 | + deviceService.isAvailable(controlPlaneConnectPoint.deviceId())) { | ||
| 121 | + notifySwitchAvailable(); | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + private void notifySwitchAvailable() { | ||
| 126 | + DeviceId deviceId = controlPlaneConnectPoint.deviceId(); | ||
| 127 | + | ||
| 128 | + interfaceService.getInterfaces().stream() | ||
| 129 | + .filter(intf -> intf.connectPoint().deviceId().equals(deviceId)) | ||
| 130 | + .forEach(this::addInterfaceForwarding); | ||
| 131 | + | ||
| 132 | + log.info("Sent interface objectives to {}", controlPlaneConnectPoint.deviceId()); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + private void addInterfaceForwarding(Interface intf) { | ||
| 136 | + log.debug("Adding interface objectives for {}", intf); | ||
| 137 | + | ||
| 138 | + DeviceId deviceId = controlPlaneConnectPoint.deviceId(); | ||
| 139 | + PortNumber controlPlanePort = controlPlaneConnectPoint.port(); | ||
| 140 | + | ||
| 141 | + for (InterfaceIpAddress ip : intf.ipAddresses()) { | ||
| 142 | + // IPv4 to router | ||
| 143 | + TrafficSelector toSelector = DefaultTrafficSelector.builder() | ||
| 144 | + .matchInPort(intf.connectPoint().port()) | ||
| 145 | + .matchEthDst(intf.mac()) | ||
| 146 | + .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) | ||
| 147 | + .matchVlanId(intf.vlan()) | ||
| 148 | + .matchIPDst(ip.ipAddress().toIpPrefix()) | ||
| 149 | + .build(); | ||
| 150 | + | ||
| 151 | + TrafficTreatment toTreatment = DefaultTrafficTreatment.builder() | ||
| 152 | + .setOutput(controlPlanePort) | ||
| 153 | + .build(); | ||
| 154 | + | ||
| 155 | + flowObjectiveService.forward(deviceId, | ||
| 156 | + buildForwardingObjective(toSelector, toTreatment)); | ||
| 157 | + | ||
| 158 | + // IPv4 from router | ||
| 159 | + TrafficSelector fromSelector = DefaultTrafficSelector.builder() | ||
| 160 | + .matchInPort(controlPlanePort) | ||
| 161 | + .matchEthSrc(intf.mac()) | ||
| 162 | + .matchVlanId(intf.vlan()) | ||
| 163 | + .matchEthType(EthType.EtherType.IPV4.ethType().toShort()) | ||
| 164 | + .matchIPSrc(ip.ipAddress().toIpPrefix()) | ||
| 165 | + .build(); | ||
| 166 | + | ||
| 167 | + TrafficTreatment intfTreatment = DefaultTrafficTreatment.builder() | ||
| 168 | + .setOutput(intf.connectPoint().port()) | ||
| 169 | + .build(); | ||
| 170 | + | ||
| 171 | + flowObjectiveService.forward(deviceId, | ||
| 172 | + buildForwardingObjective(fromSelector, intfTreatment)); | ||
| 173 | + | ||
| 174 | + | ||
| 175 | + // ARP to router | ||
| 176 | + toSelector = DefaultTrafficSelector.builder() | ||
| 177 | + .matchInPort(intf.connectPoint().port()) | ||
| 178 | + .matchEthType(EthType.EtherType.ARP.ethType().toShort()) | ||
| 179 | + .matchVlanId(intf.vlan()) | ||
| 180 | + .build(); | ||
| 181 | + | ||
| 182 | + toTreatment = DefaultTrafficTreatment.builder() | ||
| 183 | + .setOutput(controlPlanePort) | ||
| 184 | + .punt() | ||
| 185 | + .build(); | ||
| 186 | + | ||
| 187 | + flowObjectiveService.forward(deviceId, | ||
| 188 | + buildForwardingObjective(toSelector, toTreatment)); | ||
| 189 | + | ||
| 190 | + // ARP from router | ||
| 191 | + fromSelector = DefaultTrafficSelector.builder() | ||
| 192 | + .matchInPort(controlPlanePort) | ||
| 193 | + .matchEthSrc(intf.mac()) | ||
| 194 | + .matchVlanId(intf.vlan()) | ||
| 195 | + .matchEthType(EthType.EtherType.ARP.ethType().toShort()) | ||
| 196 | + .build(); | ||
| 197 | + | ||
| 198 | + intfTreatment = DefaultTrafficTreatment.builder() | ||
| 199 | + .setOutput(intf.connectPoint().port()) | ||
| 200 | + .punt() | ||
| 201 | + .build(); | ||
| 202 | + | ||
| 203 | + flowObjectiveService.forward(deviceId, | ||
| 204 | + buildForwardingObjective(fromSelector, intfTreatment)); | ||
| 205 | + } | ||
| 206 | + } | ||
| 207 | + | ||
| 208 | + private ForwardingObjective buildForwardingObjective(TrafficSelector selector, | ||
| 209 | + TrafficTreatment treatment) { | ||
| 210 | + | ||
| 211 | + return DefaultForwardingObjective.builder() | ||
| 212 | + .withSelector(selector) | ||
| 213 | + .withTreatment(treatment) | ||
| 214 | + .fromApp(appId) | ||
| 215 | + .withPriority(PRIORITY) | ||
| 216 | + .withFlag(ForwardingObjective.Flag.VERSATILE) | ||
| 217 | + .add(); | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + private class InternalDeviceListener implements DeviceListener { | ||
| 221 | + @Override | ||
| 222 | + public void event(DeviceEvent event) { | ||
| 223 | + if (controlPlaneConnectPoint != null && | ||
| 224 | + event.subject().id().equals(controlPlaneConnectPoint.deviceId())) { | ||
| 225 | + switch (event.type()) { | ||
| 226 | + case DEVICE_ADDED: | ||
| 227 | + case DEVICE_AVAILABILITY_CHANGED: | ||
| 228 | + if (deviceService.isAvailable(event.subject().id())) { | ||
| 229 | + log.info("Device connected {}", event.subject().id()); | ||
| 230 | + notifySwitchAvailable(); | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + break; | ||
| 234 | + case DEVICE_UPDATED: | ||
| 235 | + case DEVICE_REMOVED: | ||
| 236 | + case DEVICE_SUSPENDED: | ||
| 237 | + case PORT_ADDED: | ||
| 238 | + case PORT_UPDATED: | ||
| 239 | + case PORT_REMOVED: | ||
| 240 | + default: | ||
| 241 | + break; | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + } | ||
| 245 | + } | ||
| 246 | + | ||
| 247 | + private class InternalNetworkConfigListener implements NetworkConfigListener { | ||
| 248 | + @Override | ||
| 249 | + public void event(NetworkConfigEvent event) { | ||
| 250 | + if (event.subject().equals(RoutingService.ROUTER_CONFIG_CLASS)) { | ||
| 251 | + switch (event.type()) { | ||
| 252 | + case CONFIG_ADDED: | ||
| 253 | + case CONFIG_UPDATED: | ||
| 254 | + updateConfig(); | ||
| 255 | + break; | ||
| 256 | + case CONFIG_REGISTERED: | ||
| 257 | + case CONFIG_UNREGISTERED: | ||
| 258 | + case CONFIG_REMOVED: | ||
| 259 | + default: | ||
| 260 | + break; | ||
| 261 | + } | ||
| 262 | + } | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | +} |
| ... | @@ -350,10 +350,9 @@ public class SingleSwitchFibInstaller { | ... | @@ -350,10 +350,9 @@ public class SingleSwitchFibInstaller { |
| 350 | fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) | 350 | fob.withKey(Criteria.matchInPort(intf.connectPoint().port())) |
| 351 | .addCondition(Criteria.matchEthDst(intf.mac())) | 351 | .addCondition(Criteria.matchEthDst(intf.mac())) |
| 352 | .addCondition(Criteria.matchVlanId(intf.vlan())); | 352 | .addCondition(Criteria.matchVlanId(intf.vlan())); |
| 353 | - intf.ipAddresses().stream() | 353 | + |
| 354 | - .forEach(ipaddr -> fob.addCondition( | 354 | + fob.withPriority(PRIORITY_OFFSET); |
| 355 | - Criteria.matchIPDst( | 355 | + |
| 356 | - IpPrefix.valueOf(ipaddr.ipAddress(), 32)))); | ||
| 357 | fob.permit().fromApp(appId); | 356 | fob.permit().fromApp(appId); |
| 358 | flowObjectiveService.filter( | 357 | flowObjectiveService.filter( |
| 359 | deviceId, | 358 | deviceId, | ... | ... |
| ... | @@ -51,6 +51,7 @@ public class Vrouter { | ... | @@ -51,6 +51,7 @@ public class Vrouter { |
| 51 | .add("org.onosproject.routing.fpm.FpmManager") | 51 | .add("org.onosproject.routing.fpm.FpmManager") |
| 52 | .add("org.onosproject.routing.impl.Router") | 52 | .add("org.onosproject.routing.impl.Router") |
| 53 | .add("org.onosproject.routing.impl.SingleSwitchFibInstaller") | 53 | .add("org.onosproject.routing.impl.SingleSwitchFibInstaller") |
| 54 | + .add("org.onosproject.routing.impl.ControlPlaneRedirectManager") | ||
| 54 | .build(); | 55 | .build(); |
| 55 | 56 | ||
| 56 | @Activate | 57 | @Activate | ... | ... |
| ... | @@ -17,13 +17,11 @@ package org.onosproject.driver.pipeline; | ... | @@ -17,13 +17,11 @@ package org.onosproject.driver.pipeline; |
| 17 | 17 | ||
| 18 | import org.onlab.osgi.ServiceDirectory; | 18 | import org.onlab.osgi.ServiceDirectory; |
| 19 | import org.onlab.packet.Ethernet; | 19 | import org.onlab.packet.Ethernet; |
| 20 | -import org.onlab.packet.MacAddress; | ||
| 21 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
| 22 | import org.onlab.util.KryoNamespace; | 21 | import org.onlab.util.KryoNamespace; |
| 23 | import org.onosproject.core.ApplicationId; | 22 | import org.onosproject.core.ApplicationId; |
| 24 | import org.onosproject.core.CoreService; | 23 | import org.onosproject.core.CoreService; |
| 25 | import org.onosproject.net.DeviceId; | 24 | import org.onosproject.net.DeviceId; |
| 26 | -import org.onosproject.net.PortNumber; | ||
| 27 | import org.onosproject.net.behaviour.NextGroup; | 25 | import org.onosproject.net.behaviour.NextGroup; |
| 28 | import org.onosproject.net.behaviour.Pipeliner; | 26 | import org.onosproject.net.behaviour.Pipeliner; |
| 29 | import org.onosproject.net.behaviour.PipelinerContext; | 27 | import org.onosproject.net.behaviour.PipelinerContext; |
| ... | @@ -56,7 +54,6 @@ import org.slf4j.Logger; | ... | @@ -56,7 +54,6 @@ import org.slf4j.Logger; |
| 56 | import java.util.ArrayList; | 54 | import java.util.ArrayList; |
| 57 | import java.util.Collection; | 55 | import java.util.Collection; |
| 58 | import java.util.Collections; | 56 | import java.util.Collections; |
| 59 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 60 | 57 | ||
| 61 | import static org.slf4j.LoggerFactory.getLogger; | 58 | import static org.slf4j.LoggerFactory.getLogger; |
| 62 | 59 | ||
| ... | @@ -81,8 +78,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -81,8 +78,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 81 | protected DeviceId deviceId; | 78 | protected DeviceId deviceId; |
| 82 | protected ApplicationId appId; | 79 | protected ApplicationId appId; |
| 83 | private ApplicationId driverId; | 80 | private ApplicationId driverId; |
| 84 | - private Collection<Filter> filters; | ||
| 85 | - private Collection<ForwardingObjective> pendingVersatiles; | ||
| 86 | 81 | ||
| 87 | private KryoNamespace appKryo = new KryoNamespace.Builder() | 82 | private KryoNamespace appKryo = new KryoNamespace.Builder() |
| 88 | .register(DummyGroup.class) | 83 | .register(DummyGroup.class) |
| ... | @@ -101,9 +96,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -101,9 +96,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 101 | flowObjectiveStore = context.store(); | 96 | flowObjectiveStore = context.store(); |
| 102 | driverId = coreService.registerApplication( | 97 | driverId = coreService.registerApplication( |
| 103 | "org.onosproject.driver.SoftRouterPipeline"); | 98 | "org.onosproject.driver.SoftRouterPipeline"); |
| 104 | - filters = Collections.newSetFromMap(new ConcurrentHashMap<Filter, Boolean>()); | 99 | + |
| 105 | - pendingVersatiles = Collections.newSetFromMap( | ||
| 106 | - new ConcurrentHashMap<ForwardingObjective, Boolean>()); | ||
| 107 | initializePipeline(); | 100 | initializePipeline(); |
| 108 | } | 101 | } |
| 109 | 102 | ||
| ... | @@ -192,7 +185,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -192,7 +185,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 192 | } | 185 | } |
| 193 | } | 186 | } |
| 194 | 187 | ||
| 195 | - | ||
| 196 | private void initializePipeline() { | 188 | private void initializePipeline() { |
| 197 | //Drop rules for both tables | 189 | //Drop rules for both tables |
| 198 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 190 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| ... | @@ -239,8 +231,10 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -239,8 +231,10 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 239 | ApplicationId applicationId) { | 231 | ApplicationId applicationId) { |
| 240 | // This driver only processes filtering criteria defined with switch | 232 | // This driver only processes filtering criteria defined with switch |
| 241 | // ports as the key | 233 | // ports as the key |
| 242 | - PortCriterion p; EthCriterion e = null; VlanIdCriterion v = null; | 234 | + PortCriterion p; |
| 243 | - Collection<IPCriterion> ips = new ArrayList<IPCriterion>(); | 235 | + EthCriterion e = null; |
| 236 | + VlanIdCriterion v = null; | ||
| 237 | + | ||
| 244 | if (!filt.key().equals(Criteria.dummy()) && | 238 | if (!filt.key().equals(Criteria.dummy()) && |
| 245 | filt.key().type() == Criterion.Type.IN_PORT) { | 239 | filt.key().type() == Criterion.Type.IN_PORT) { |
| 246 | p = (PortCriterion) filt.key(); | 240 | p = (PortCriterion) filt.key(); |
| ... | @@ -258,8 +252,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -258,8 +252,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 258 | e = (EthCriterion) c; | 252 | e = (EthCriterion) c; |
| 259 | } else if (c.type() == Criterion.Type.VLAN_VID) { | 253 | } else if (c.type() == Criterion.Type.VLAN_VID) { |
| 260 | v = (VlanIdCriterion) c; | 254 | v = (VlanIdCriterion) c; |
| 261 | - } else if (c.type() == Criterion.Type.IPV4_DST) { | ||
| 262 | - ips.add((IPCriterion) c); | ||
| 263 | } else { | 255 | } else { |
| 264 | log.error("Unsupported filter {}", c); | 256 | log.error("Unsupported filter {}", c); |
| 265 | fail(filt, ObjectiveError.UNSUPPORTED); | 257 | fail(filt, ObjectiveError.UNSUPPORTED); |
| ... | @@ -272,13 +264,14 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -272,13 +264,14 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 272 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 264 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); |
| 273 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 265 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| 274 | selector.matchInPort(p.port()); | 266 | selector.matchInPort(p.port()); |
| 275 | - selector.matchVlanId(v.vlanId()); | 267 | + |
| 276 | selector.matchEthDst(e.mac()); | 268 | selector.matchEthDst(e.mac()); |
| 269 | + selector.matchVlanId(v.vlanId()); | ||
| 277 | selector.matchEthType(Ethernet.TYPE_IPV4); | 270 | selector.matchEthType(Ethernet.TYPE_IPV4); |
| 278 | if (!v.vlanId().equals(VlanId.NONE)) { | 271 | if (!v.vlanId().equals(VlanId.NONE)) { |
| 279 | treatment.popVlan(); | 272 | treatment.popVlan(); |
| 280 | } | 273 | } |
| 281 | - treatment.transition(FIB_TABLE); // all other IPs to the FIB table | 274 | + treatment.transition(FIB_TABLE); |
| 282 | FlowRule rule = DefaultFlowRule.builder() | 275 | FlowRule rule = DefaultFlowRule.builder() |
| 283 | .forDevice(deviceId) | 276 | .forDevice(deviceId) |
| 284 | .withSelector(selector.build()) | 277 | .withSelector(selector.build()) |
| ... | @@ -289,38 +282,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -289,38 +282,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 289 | .forTable(FILTER_TABLE).build(); | 282 | .forTable(FILTER_TABLE).build(); |
| 290 | ops = ops.add(rule); | 283 | ops = ops.add(rule); |
| 291 | 284 | ||
| 292 | - for (IPCriterion ipaddr : ips) { | ||
| 293 | - log.debug("adding IP filtering rules in FILTER table: {}", ipaddr.ip()); | ||
| 294 | - selector = DefaultTrafficSelector.builder(); | ||
| 295 | - treatment = DefaultTrafficTreatment.builder(); | ||
| 296 | - selector.matchInPort(p.port()); | ||
| 297 | - selector.matchVlanId(v.vlanId()); | ||
| 298 | - selector.matchEthDst(e.mac()); | ||
| 299 | - selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 300 | - selector.matchIPDst(ipaddr.ip()); // router IPs to the controller | ||
| 301 | - treatment.setOutput(PortNumber.CONTROLLER); | ||
| 302 | - rule = DefaultFlowRule.builder() | ||
| 303 | - .forDevice(deviceId) | ||
| 304 | - .withSelector(selector.build()) | ||
| 305 | - .withTreatment(treatment.build()) | ||
| 306 | - .withPriority(HIGHEST_PRIORITY) | ||
| 307 | - .fromApp(applicationId) | ||
| 308 | - .makePermanent() | ||
| 309 | - .forTable(FILTER_TABLE).build(); | ||
| 310 | - ops = ops.add(rule); | ||
| 311 | - } | ||
| 312 | - | ||
| 313 | - // cache for later use | ||
| 314 | - Filter filter = new Filter(p, e, v, ips); | ||
| 315 | - filters.add(filter); | ||
| 316 | - // apply any pending versatile forwarding objectives | ||
| 317 | - for (ForwardingObjective fwd : pendingVersatiles) { | ||
| 318 | - Collection<FlowRule> ret = processVersatilesWithFilters(filter, fwd); | ||
| 319 | - for (FlowRule fr : ret) { | ||
| 320 | - ops.add(fr); | ||
| 321 | - } | ||
| 322 | - } | ||
| 323 | - | ||
| 324 | ops = install ? ops.add(rule) : ops.remove(rule); | 285 | ops = install ? ops.add(rule) : ops.remove(rule); |
| 325 | // apply filtering flow rules | 286 | // apply filtering flow rules |
| 326 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { | 287 | flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { |
| ... | @@ -360,69 +321,20 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -360,69 +321,20 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 360 | * subsystem. May return empty collection in case of failures. | 321 | * subsystem. May return empty collection in case of failures. |
| 361 | */ | 322 | */ |
| 362 | private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { | 323 | private Collection<FlowRule> processVersatile(ForwardingObjective fwd) { |
| 363 | - if (filters.isEmpty()) { | 324 | + Collection<FlowRule> flowrules = new ArrayList<>(); |
| 364 | - pendingVersatiles.add(fwd); | ||
| 365 | - return Collections.emptySet(); | ||
| 366 | - } | ||
| 367 | - Collection<FlowRule> flowrules = new ArrayList<FlowRule>(); | ||
| 368 | - for (Filter filter : filters) { | ||
| 369 | - flowrules.addAll(processVersatilesWithFilters(filter, fwd)); | ||
| 370 | - } | ||
| 371 | - return flowrules; | ||
| 372 | - } | ||
| 373 | 325 | ||
| 374 | - private Collection<FlowRule> processVersatilesWithFilters( | 326 | + FlowRule rule = DefaultFlowRule.builder() |
| 375 | - Filter filt, ForwardingObjective fwd) { | 327 | + .withSelector(fwd.selector()) |
| 376 | - log.info("Processing versatile forwarding objective"); | 328 | + .withTreatment(fwd.treatment()) |
| 377 | - Collection<FlowRule> flows = new ArrayList<FlowRule>(); | 329 | + .makePermanent() |
| 378 | - TrafficSelector match = fwd.selector(); | 330 | + .forDevice(deviceId) |
| 379 | - EthTypeCriterion ethType = | 331 | + .fromApp(fwd.appId()) |
| 380 | - (EthTypeCriterion) match.getCriterion(Criterion.Type.ETH_TYPE); | 332 | + .withPriority(fwd.priority()) |
| 381 | - if (ethType == null) { | 333 | + .build(); |
| 382 | - log.error("Versatile forwarding objective must include ethType"); | ||
| 383 | - fail(fwd, ObjectiveError.UNKNOWN); | ||
| 384 | - return Collections.emptySet(); | ||
| 385 | - } | ||
| 386 | 334 | ||
| 387 | - if (ethType.ethType().toShort() == Ethernet.TYPE_ARP) { | 335 | + flowrules.add(rule); |
| 388 | - // need to install ARP request & reply flow rules for each interface filter | 336 | + |
| 389 | - | 337 | + return flowrules; |
| 390 | - // rule for ARP replies | ||
| 391 | - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 392 | - selector.matchInPort(filt.port()); | ||
| 393 | - selector.matchVlanId(filt.vlanId()); | ||
| 394 | - selector.matchEthDst(filt.mac()); | ||
| 395 | - selector.matchEthType(Ethernet.TYPE_ARP); | ||
| 396 | - FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() | ||
| 397 | - .fromApp(fwd.appId()) | ||
| 398 | - .withPriority(fwd.priority()) | ||
| 399 | - .forDevice(deviceId) | ||
| 400 | - .withSelector(selector.build()) | ||
| 401 | - .withTreatment(fwd.treatment()) | ||
| 402 | - .makePermanent() | ||
| 403 | - .forTable(FILTER_TABLE); | ||
| 404 | - flows.add(ruleBuilder.build()); | ||
| 405 | - | ||
| 406 | - //rule for ARP requests | ||
| 407 | - selector = DefaultTrafficSelector.builder(); | ||
| 408 | - selector.matchInPort(filt.port()); | ||
| 409 | - selector.matchVlanId(filt.vlanId()); | ||
| 410 | - selector.matchEthDst(MacAddress.BROADCAST); | ||
| 411 | - selector.matchEthType(Ethernet.TYPE_ARP); | ||
| 412 | - ruleBuilder = DefaultFlowRule.builder() | ||
| 413 | - .fromApp(fwd.appId()) | ||
| 414 | - .withPriority(fwd.priority()) | ||
| 415 | - .forDevice(deviceId) | ||
| 416 | - .withSelector(selector.build()) | ||
| 417 | - .withTreatment(fwd.treatment()) | ||
| 418 | - .makePermanent() | ||
| 419 | - .forTable(FILTER_TABLE); | ||
| 420 | - flows.add(ruleBuilder.build()); | ||
| 421 | - | ||
| 422 | - return flows; | ||
| 423 | - } | ||
| 424 | - // not handling other versatile flows | ||
| 425 | - return Collections.emptySet(); | ||
| 426 | } | 338 | } |
| 427 | 339 | ||
| 428 | /** | 340 | /** |
| ... | @@ -500,35 +412,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe | ... | @@ -500,35 +412,6 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe |
| 500 | new DummyGroup(treatment)); | 412 | new DummyGroup(treatment)); |
| 501 | } | 413 | } |
| 502 | 414 | ||
| 503 | - private class Filter { | ||
| 504 | - private PortCriterion port; | ||
| 505 | - private VlanIdCriterion vlan; | ||
| 506 | - private EthCriterion eth; | ||
| 507 | - | ||
| 508 | - @SuppressWarnings("unused") | ||
| 509 | - private Collection<IPCriterion> ips; | ||
| 510 | - | ||
| 511 | - public Filter(PortCriterion p, EthCriterion e, VlanIdCriterion v, | ||
| 512 | - Collection<IPCriterion> ips) { | ||
| 513 | - this.eth = e; | ||
| 514 | - this.port = p; | ||
| 515 | - this.vlan = v; | ||
| 516 | - this.ips = ips; | ||
| 517 | - } | ||
| 518 | - | ||
| 519 | - public PortNumber port() { | ||
| 520 | - return port.port(); | ||
| 521 | - } | ||
| 522 | - | ||
| 523 | - public VlanId vlanId() { | ||
| 524 | - return vlan.vlanId(); | ||
| 525 | - } | ||
| 526 | - | ||
| 527 | - public MacAddress mac() { | ||
| 528 | - return eth.mac(); | ||
| 529 | - } | ||
| 530 | - } | ||
| 531 | - | ||
| 532 | private class DummyGroup implements NextGroup { | 415 | private class DummyGroup implements NextGroup { |
| 533 | TrafficTreatment nextActions; | 416 | TrafficTreatment nextActions; |
| 534 | 417 | ... | ... |
| ... | @@ -98,7 +98,7 @@ public class ComponentManager implements ComponentService { | ... | @@ -98,7 +98,7 @@ public class ComponentManager implements ComponentService { |
| 98 | 98 | ||
| 99 | org.apache.felix.scr.Component component = components[0]; | 99 | org.apache.felix.scr.Component component = components[0]; |
| 100 | 100 | ||
| 101 | - if (component.getState() != org.apache.felix.scr.Component.STATE_ACTIVE) { | 101 | + if (component.getState() == org.apache.felix.scr.Component.STATE_DISABLED) { |
| 102 | log.info("Enabling component {}", name); | 102 | log.info("Enabling component {}", name); |
| 103 | component.enable(); | 103 | component.enable(); |
| 104 | } | 104 | } | ... | ... |
-
Please register or login to post a comment