Pingping Lin
Committed by Gerrit Code Review

move the reactive routing to new config subsystem

Change-Id: I3e570138afb800c5bd7dbef872cbf9044732fa49
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ 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.
-->
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
<feature name="onos-app-reactive-routing" version="${project.version}"
description="${project.description}">
<feature>onos-api</feature>
<bundle>mvn:${project.groupId}/onos-app-reactive-routing/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle>
<bundle>mvn:${project.groupId}/onos-app-routing/${project.version}</bundle>
</feature>
</features>
......@@ -16,8 +16,17 @@
package org.onosproject.reactive.routing;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
......@@ -39,17 +48,9 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import org.onosproject.routing.IntentRequestListener;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* FIB component for reactive routing intents.
*/
......@@ -64,7 +65,6 @@ public class ReactiveRoutingFib implements IntentRequestListener {
private final ApplicationId appId;
private final HostService hostService;
private final RoutingConfigurationService configService;
private final InterfaceService interfaceService;
private final IntentSynchronizationService intentSynchronizer;
......@@ -75,17 +75,14 @@ public class ReactiveRoutingFib implements IntentRequestListener {
*
* @param appId application ID to use to generate intents
* @param hostService host service
* @param configService routing configuration service
* @param interfaceService interface service
* @param intentSynchronizer intent synchronization service
*/
public ReactiveRoutingFib(ApplicationId appId, HostService hostService,
RoutingConfigurationService configService,
InterfaceService interfaceService,
IntentSynchronizationService intentSynchronizer) {
this.appId = appId;
this.hostService = hostService;
this.configService = configService;
this.interfaceService = interfaceService;
this.intentSynchronizer = intentSynchronizer;
......@@ -95,8 +92,6 @@ public class ReactiveRoutingFib implements IntentRequestListener {
@Override
public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
checkNotNull(hostIpAddress);
Set<ConnectPoint> ingressPoints =
configService.getBgpPeerConnectPoints();
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
......@@ -130,6 +125,24 @@ public class ReactiveRoutingFib implements IntentRequestListener {
Key key = Key.of(ipPrefix.toString(), appId);
int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER
+ PRIORITY_OFFSET;
Set<ConnectPoint> interfaceConnectPoints =
interfaceService.getInterfaces().stream()
.map(intf -> intf.connectPoint()).collect(Collectors.toSet());
if (interfaceConnectPoints.isEmpty()) {
log.error("The interface connect points are empty!");
return;
}
Set<ConnectPoint> ingressPoints = new HashSet<>();
for (ConnectPoint connectPoint : interfaceConnectPoints) {
if (!connectPoint.equals(egressPoint)) {
ingressPoints.add(connectPoint);
}
}
MultiPointToSinglePointIntent intent =
MultiPointToSinglePointIntent.builder()
.appId(appId)
......@@ -150,7 +163,8 @@ public class ReactiveRoutingFib implements IntentRequestListener {
public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix,
IpAddress nextHopIpAddress) {
// Find the attachment point (egress interface) of the next hop
Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
Interface egressInterface =
interfaceService.getMatchingInterface(nextHopIpAddress);
if (egressInterface == null) {
log.warn("No outgoing interface found for {}",
nextHopIpAddress);
......
......@@ -15,6 +15,16 @@
*/
package org.onosproject.reactive.routing;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.packet.Ethernet.TYPE_ARP;
import static org.onlab.packet.Ethernet.TYPE_IPV4;
import static org.onosproject.net.packet.PacketPriority.REACTIVE;
import static org.slf4j.LoggerFactory.getLogger;
import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -53,16 +63,6 @@ import org.onosproject.routing.RoutingService;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger;
import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.packet.Ethernet.TYPE_ARP;
import static org.onlab.packet.Ethernet.TYPE_IPV4;
import static org.onosproject.net.packet.PacketPriority.REACTIVE;
import static org.slf4j.LoggerFactory.getLogger;
/**
* This is reactive routing to handle 3 cases:
* (1) one host wants to talk to another host, both two hosts are in
......@@ -107,9 +107,8 @@ public class SdnIpReactiveRouting {
@Activate
public void activate() {
appId = coreService.registerApplication(APP_NAME);
intentRequestListener = new ReactiveRoutingFib(appId, hostService,
config, interfaceService, intentSynchronizer);
interfaceService, intentSynchronizer);
packetService.addProcessor(processor, PacketProcessor.director(2));
requestIntercepts();
......@@ -300,23 +299,26 @@ public class SdnIpReactiveRouting {
* @return the traffic type which this packet belongs to
*/
private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint,
IpAddress dstIp) {
IpAddress dstIp) {
LocationType dstIpLocationType = getLocationType(dstIp);
Optional<Interface> srcInterface =
interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst();
Set<ConnectPoint> ingressPoints = config.getBgpPeerConnectPoints();
Set<ConnectPoint> bgpPeerConnectPoints = config.getBgpPeerConnectPoints();
switch (dstIpLocationType) {
case INTERNET:
if (srcInterface.isPresent() &&
(!ingressPoints.contains(srcConnectPoint))) {
(!bgpPeerConnectPoints.contains(srcConnectPoint))) {
return TrafficType.HOST_TO_INTERNET;
} else {
return TrafficType.INTERNET_TO_INTERNET;
}
case LOCAL:
if (srcInterface.isPresent() &&
(!ingressPoints.contains(srcConnectPoint))) {
(!bgpPeerConnectPoints.contains(srcConnectPoint))) {
return TrafficType.HOST_TO_HOST;
} else {
// TODO Currently we only consider local public prefixes.
......@@ -394,6 +396,5 @@ public class SdnIpReactiveRouting {
packetService.emit(packet);
log.trace("sending packet: {}", packet);
}
}
......
......@@ -15,7 +15,6 @@
*/
package org.onosproject.routing.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import java.util.Objects;
......@@ -53,15 +52,14 @@ public class LocalIpPrefixEntry {
/**
* Creates a new IP prefix entry.
*
* @param ipPrefix an IP prefix as a String
* @param ipPrefix an IP prefix
* @param type an IP prefix type as an IpPrefixType
* @param gatewayIpAddress IP of the gateway
*/
public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix,
@JsonProperty("type") IpPrefixType type,
@JsonProperty("gatewayIp") IpAddress
gatewayIpAddress) {
this.ipPrefix = IpPrefix.valueOf(ipPrefix);
public LocalIpPrefixEntry(IpPrefix ipPrefix,
IpPrefixType type,
IpAddress gatewayIpAddress) {
this.ipPrefix = ipPrefix;
this.type = type;
this.gatewayIpAddress = gatewayIpAddress;
}
......
/*
* Copyright 2016 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.config;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Sets;
import java.util.Set;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.Config;
import org.onosproject.routing.config.LocalIpPrefixEntry.IpPrefixType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Configuration object for prefix config.
*/
public class ReactiveRoutingConfig extends Config<ApplicationId> {
private final Logger log = LoggerFactory.getLogger(getClass());
public static final String IP4LOCALPREFIXES = "ip4LocalPrefixes";
public static final String IP6LOCALPREFIXES = "ip6LocalPrefixes";
public static final String IPPREFIX = "ipPrefix";
public static final String TYPE = "type";
public static final String GATEWAYIP = "gatewayIp";
public static final String VIRTUALGATEWAYMACADDRESS =
"virtualGatewayMacAddress";
/**
* Gets the set of configured local IPv4 prefixes.
*
* @return IPv4 prefixes
*/
public Set<LocalIpPrefixEntry> localIp4PrefixEntries() {
Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
JsonNode prefixesNode = object.get(IP4LOCALPREFIXES);
if (prefixesNode == null) {
log.warn("ip4LocalPrefixes is null!");
return prefixes;
}
prefixesNode.forEach(jsonNode -> {
prefixes.add(new LocalIpPrefixEntry(
IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
});
return prefixes;
}
/**
* Gets the set of configured local IPv6 prefixes.
*
* @return IPv6 prefixes
*/
public Set<LocalIpPrefixEntry> localIp6PrefixEntries() {
Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
JsonNode prefixesNode = object.get(IP6LOCALPREFIXES);
if (prefixesNode == null) {
log.warn("ip6LocalPrefixes is null!");
return prefixes;
}
prefixesNode.forEach(jsonNode -> {
prefixes.add(new LocalIpPrefixEntry(
IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
});
return prefixes;
}
/**
* Gets of the virtual gateway MAC address.
*
*/
public MacAddress virtualGatewayMacAddress() {
return MacAddress.valueOf(
object.get(VIRTUALGATEWAYMACADDRESS).asText());
}
}
......@@ -15,38 +15,23 @@
*/
package org.onosproject.routing.config;
import java.util.Set;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
import java.util.Map;
import java.util.Set;
/**
* Provides information about the routing configuration.
*/
public interface RoutingConfigurationService {
/**
* Gets the list of BGP speakers inside the SDN network.
*
* @return the map of BGP speaker names to BGP speaker objects
*/
Map<String, BgpSpeaker> getBgpSpeakers();
String REACTIVE_ROUTING_APP_ID = "org.onosproject.reactive.routing";
Class<ReactiveRoutingConfig> CONFIG_CLASS = ReactiveRoutingConfig.class;
/**
* Gets the list of configured BGP peers.
*
* @return the map from peer IP address to BgpPeer object
*/
Map<IpAddress, BgpPeer> getBgpPeers();
/**
* Gets the MAC address configured for virtual gateway in SDN network.
*
* @return the MAC address of virtual gateway
*/
MacAddress getVirtualGatewayMacAddress();
/**
......@@ -81,15 +66,5 @@ public interface RoutingConfigurationService {
*/
Set<ConnectPoint> getBgpPeerConnectPoints();
/**
* Retrieves the interface that matches the given IP address. Matching
* means that the IP address is in one of the interface's assigned subnets.
*
* @param ipAddress IP address to match
* @return the matching interface
* @deprecated in Drake release - use InterfaceService instead
*/
@Deprecated
Interface getMatchingInterface(IpAddress ipAddress);
}
......