Pingping Lin

sdn-ip reactive routing

   This module can handle 3 cases:
   (1) one host wants to talk to another host, both two hosts are in SDN network.
   (2) one host in SDN network wants to talk to another host in Internet.
   (3) one host from Internet wants to talk to another host in SDN network.
   In all cases, we use MultiPointToSinglePointIntent.

Change-Id: I80dd954bd608e52b45b993f3c27e67636a7105d9
Showing 23 changed files with 766 additions and 10 deletions
......@@ -172,7 +172,8 @@ public class BgpRouter {
icmpHandler = new IcmpHandler(configService, packetService);
routingService.start(new InternalFibListener());
routingService.addFibListener(new InternalFibListener());
routingService.start();
connectivityManager.start();
......
......@@ -42,6 +42,7 @@
<module>oecfg</module>
<module>routing</module>
<module>routing-api</module>
<module>reactive-routing</module>
<module>bgprouter</module>
<module>test</module>
</modules>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<app name="org.onosproject.reactive.routing" origin="ON.Lab" version="1.2.0"
features="onos-app-reactive-routing">
<description> ONOS SDN/IP reactive routing </description>
</app>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>onos-app-reactive-routing</artifactId>
<packaging>bundle</packaging>
<description> SDN-IP reactive routing </description>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-apps</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-routing-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-app-routing</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*
* 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.reactive.routing;
import static org.slf4j.LoggerFactory.getLogger;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.packet.DefaultOutboundPacket;
import org.onosproject.net.packet.InboundPacket;
import org.onosproject.net.packet.OutboundPacket;
import org.onosproject.net.packet.PacketContext;
import org.onosproject.net.packet.PacketPriority;
import org.onosproject.net.packet.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.routing.RoutingService;
import org.slf4j.Logger;
/**
* This is reactive routing to handle 3 cases:
* (1) one host wants to talk to another host, both two hosts are in
* SDN network.
* (2) one host in SDN network wants to talk to another host in Internet.
* (3) one host from Internet wants to talk to another host in SDN network.
*/
@Component(immediate = true)
public class SdnIpReactiveRouting {
private static final String APP_NAME = "org.onosproject.reactive.routing";
private final Logger log = getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RoutingService routingService;
private ApplicationId appId;
private ReactiveRoutingProcessor processor =
new ReactiveRoutingProcessor();
@Activate
public void activate() {
appId = coreService.registerApplication(APP_NAME);
packetService.addProcessor(processor,
PacketProcessor.ADVISOR_MAX + 2);
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
// TODO: to support IPv6 later
selector.matchEthType(Ethernet.TYPE_IPV4);
packetService.requestPackets(selector.build(),
PacketPriority.REACTIVE, appId);
log.info("SDN-IP Reactive Routing Started");
}
@Deactivate
public void deactivate() {
packetService.removeProcessor(processor);
processor = null;
log.info("SDN-IP Reactive Routing Stopped");
}
private class ReactiveRoutingProcessor implements PacketProcessor {
@Override
public void process(PacketContext context) {
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt == null) {
return;
}
// In theory, we do not need to check whether it is Ethernet
// TYPE_IPV4. However, due to the current implementation of the
// packetService, we will receive all packets from all subscribers.
// Hence, we have to check the Ethernet type again here.
if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) {
return;
}
// Parse packet
IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
IpAddress dstIp =
IpAddress.valueOf(ipv4Packet.getDestinationAddress());
IpAddress srcIp =
IpAddress.valueOf(ipv4Packet.getSourceAddress());
ConnectPoint srcConnectPoint = pkt.receivedFrom();
MacAddress srcMac = ethPkt.getSourceMAC();
routingService.packetReactiveProcessor(dstIp, srcIp,
srcConnectPoint, srcMac);
// TODO emit packet first or packetReactiveProcessor first
ConnectPoint egressConnectPoint = null;
egressConnectPoint = routingService.getEgressConnectPoint(dstIp);
if (egressConnectPoint != null) {
forwardPacketToDst(context, egressConnectPoint);
}
}
}
/**
* Emits the specified packet onto the network.
*
* @param context the packet context
* @param connectPoint the connect point where the packet should be
* sent out
*/
private void forwardPacketToDst(PacketContext context,
ConnectPoint connectPoint) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder()
.setOutput(connectPoint.port()).build();
OutboundPacket packet =
new DefaultOutboundPacket(connectPoint.deviceId(), treatment,
context.inPacket().unparsed());
packetService.emit(packet);
log.trace("sending packet: {}", packet);
}
}
/*
* 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.
*/
/**
* Application to enable (1) hosts in local SDN network to talk to other hosts
* in Internet, and (2) hosts in local SDN network to talk to each other.
*/
package org.onosproject.reactive.routing;
/*
* 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;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
/**
* An interface to process intent requests.
*/
public interface IntentRequestListener {
/**
* Sets up connectivity for packet from Internet to a host in local
* SDN network.
*
* @param dstIpAddress IP address of destination host in local SDN network
*/
void setUpConnectivityInternetToHost(IpAddress dstIpAddress);
/**
* Sets up the connectivity for two hosts in local SDN network.
*
* @param dstIpAddress the destination IP address
* @param srcIpAddress the source IP address
* @param srcMacAddress the source MAC address
* @param srcConnectPoint the connectPoint of the source host
*/
void setUpConnectivityHostToHost(IpAddress dstIpAddress,
IpAddress srcIpAddress,
MacAddress srcMacAddress,
ConnectPoint srcConnectPoint);
/**
* Adds one new ingress connect point into ingress points of an existing
* intent and resubmits the new intent.
* <p>
* If there is already an intent for an IP prefix in the system, we do not
* need to create a new one, we only need to update this existing intent by
* adding more ingress points.
* </p>
*
* @param ipPrefix the IP prefix used to search the existing
* MultiPointToSinglePointIntent
* @param ingressConnectPoint the ingress connect point to be added into
* the exiting intent
*/
void updateExistingMp2pIntent(IpPrefix ipPrefix,
ConnectPoint ingressConnectPoint);
/**
* Checks whether there is a MultiPointToSinglePointIntent in memory for a
* given IP prefix.
*
* @param ipPrefix the IP prefix used to search the existing
* MultiPointToSinglePointIntent
* @return true if there is a MultiPointToSinglePointIntent, otherwise false
*/
boolean mp2pIntentExists(IpPrefix ipPrefix);
}
......@@ -17,17 +17,92 @@ package org.onosproject.routing;
import java.util.Collection;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
/**
* Provides a way of interacting with the RIB management component.
*/
public interface RoutingService {
/**
* Specifies the type of an IP address or an IP prefix location.
*/
public static enum LocationType {
/**
* The location of an IP address or an IP prefix is in local SDN network.
*/
LOCAL,
/**
* The location of an IP address or an IP prefix is outside local SDN network.
*/
INTERNET,
/**
* There is no route for this IP address or IP prefix.
*/
NO_ROUTE
}
/**
* Specifies the type of traffic.
* <p>
* We classify traffic by the first packet of each traffic.
* </p>
*/
public enum TrafficType {
/**
* Traffic from a host located in local SDN network wants to
* communicate with destination host located in Internet (outside
* local SDN network).
*/
HOST_TO_INTERNET,
/**
* Traffic from Internet wants to communicate with a host located
* in local SDN network.
*/
INTERNET_TO_HOST,
/**
* Both the source host and destination host of a traffic are in
* local SDN network.
*/
HOST_TO_HOST,
/**
* Traffic from Internet wants to traverse local SDN network.
*/
INTERNET_TO_INTERNET,
/**
* Any traffic wants to communicate with a destination which has
* no route, or traffic from Internet wants to access a local private
* IP address.
*/
DROP,
/**
* Traffic does not belong to the types above.
*/
UNKNOWN
}
/**
* Starts the routing service.
*/
public void start();
/**
* Adds FIB listener.
*
* @param listener listener to send FIB updates to
* @param fibListener listener to send FIB updates to
*/
public void start(FibListener listener);
public void addFibListener(FibListener fibListener);
/**
* Adds intent creation and submission listener.
*
* @param intentRequestListener listener to send intent creation and
* submission request to
*/
public void addIntentRequestListener(IntentRequestListener
intentRequestListener);
/**
* Stops the routing service.
......@@ -47,4 +122,43 @@ public interface RoutingService {
* @return the SDN-IP IPv6 routes
*/
public Collection<RouteEntry> getRoutes6();
/**
* Evaluates the location of an IP address and returns the location type.
*
* @param ipAddress the IP address to evaluate
* @return the IP address location type
*/
public LocationType getLocationType(IpAddress ipAddress);
/**
* Finds out the route entry which has the longest matchable IP prefix.
*
* @param ipAddress IP address used to find out longest matchable IP prefix
* @return a route entry which has the longest matchable IP prefix if
* found, otherwise null
*/
public RouteEntry getLongestMatchableRouteEntry(IpAddress ipAddress);
/**
* Finds out the egress connect point where to emit the first packet
* based on destination IP address.
*
* @param dstIpAddress the destination IP address
* @return the egress connect point if found, otherwise null
*/
public ConnectPoint getEgressConnectPoint(IpAddress dstIpAddress);
/**
* Routes packet reactively.
*
* @param dstIpAddress the destination IP address of a packet
* @param srcIpAddress the source IP address of a packet
* @param srcConnectPoint the connect point where a packet comes from
* @param srcMacAddress the source MAC address of a packet
*/
public void packetReactiveProcessor(IpAddress dstIpAddress,
IpAddress srcIpAddress,
ConnectPoint srcConnectPoint,
MacAddress srcMacAddress);
}
......
/*
* 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.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import java.util.Objects;
import org.onlab.packet.IpPrefix;
/**
* Configuration details for an IP prefix entry.
*/
public class LocalIpPrefixEntry {
private final IpPrefix ipPrefix;
private final IpPrefixType type;
/**
* Specifies the type of local IP prefix.
*/
public enum IpPrefixType {
/**
* Public IP prefixes should be exchanged by eBGP.
*/
PUBLIC,
/**
* Private IP prefixes should be used only locally and not exchanged
* by eBGP.
*/
PRIVATE,
/**
* For IP prefixes in blacklist.
*/
BLACK_LIST
}
/**
* Creates a new IP prefix entry.
*
* @param ipPrefix an IP prefix as a String
* @param type an IP prefix type as an IpPrefixType
*/
public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix,
@JsonProperty("type") IpPrefixType type) {
this.ipPrefix = IpPrefix.valueOf(ipPrefix);
this.type = type;
}
/**
* Gets the IP prefix of the IP prefix entry.
*
* @return the IP prefix
*/
public IpPrefix ipPrefix() {
return ipPrefix;
}
/**
* Gets the IP prefix type of the IP prefix entry.
*
* @return the IP prefix type
*/
public IpPrefixType ipPrefixType() {
return type;
}
/**
* Tests whether the IP version of this entry is IPv4.
*
* @return true if the IP version of this entry is IPv4, otherwise false.
*/
public boolean isIp4() {
return ipPrefix.isIp4();
}
/**
* Tests whether the IP version of this entry is IPv6.
*
* @return true if the IP version of this entry is IPv6, otherwise false.
*/
public boolean isIp6() {
return ipPrefix.isIp6();
}
@Override
public int hashCode() {
return Objects.hash(ipPrefix, type);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof LocalIpPrefixEntry)) {
return false;
}
LocalIpPrefixEntry that = (LocalIpPrefixEntry) obj;
return Objects.equals(this.ipPrefix, that.ipPrefix)
&& Objects.equals(this.type, that.type);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("ipPrefix", ipPrefix)
.add("ipPrefixType", type)
.toString();
}
}
......@@ -16,6 +16,7 @@
package org.onosproject.routing.config;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onosproject.net.ConnectPoint;
import java.util.Map;
......@@ -41,6 +42,22 @@ public interface RoutingConfigurationService {
public Map<IpAddress, BgpPeer> getBgpPeers();
/**
* Evaluates whether an IP address belongs to local SDN network.
*
* @param ipAddress the IP address to evaluate
* @return true if the IP address belongs to local SDN network, otherwise false
*/
public boolean isIpAddressLocal(IpAddress ipAddress);
/**
* Evaluates whether an IP prefix belongs to local SDN network.
*
* @param ipPrefix the IP prefix to evaluate
* @return true if the IP prefix belongs to local SDN network, otherwise false
*/
public boolean isIpPrefixLocal(IpPrefix ipPrefix);
/**
* Retrieves the entire set of interfaces in the network.
*
* @return the set of interfaces
......
......@@ -16,8 +16,10 @@
package org.onosproject.routing.config.impl;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
import org.onosproject.routing.config.LocalIpPrefixEntry;
import java.util.Collections;
import java.util.List;
......@@ -32,6 +34,12 @@ public class Configuration {
private List<BgpSpeaker> bgpSpeakers;
private List<BgpPeer> peers;
// All IP prefixes from the configuration are local
private List<LocalIpPrefixEntry> localIp4PrefixEntries =
Collections.emptyList();
private List<LocalIpPrefixEntry> localIp6PrefixEntries =
Collections.emptyList();
/**
* Default constructor.
*/
......@@ -78,4 +86,51 @@ public class Configuration {
this.peers = peers;
}
/**
* Gets a list of local IPv4 prefix entries configured for local
* SDN network.
* <p>
* IP prefix entries are represented by {@link LocalIpPrefixEntry}
* objects.
* </p>
*
* @return the list of local IPv4 prefix entries
*/
public List<LocalIpPrefixEntry> getLocalIp4PrefixEntries() {
return Collections.unmodifiableList(localIp4PrefixEntries);
}
/**
* Sets a list of IPv4 prefix entries configured for local SDN network.
*
* @param ip4PrefixEntries the list of Ipv4 prefix entries
*/
@JsonProperty("ip4LocalPrefixes")
public void setLocalIp4PrefixEntries(List<LocalIpPrefixEntry> ip4PrefixEntries) {
this.localIp4PrefixEntries = ip4PrefixEntries;
}
/**
* Gets a list of IPv6 prefix entries configured for local SDN network.
* <p>
* IP prefix entries are represented by {@link LocalIpPrefixEntry}
* objects.
* </p>
*
* @return the list of IPv6 prefix entries
*/
public List<LocalIpPrefixEntry> getLocalIp6PrefixEntries() {
return Collections.unmodifiableList(localIp6PrefixEntries);
}
/**
* Sets a list of IPv6 prefix entries configured for local SDN network.
*
* @param ip6PrefixEntries the list of Ipv6 prefix entries
*/
@JsonProperty("ip6LocalPrefixes")
public void setLocalIp6PrefixEntries(List<LocalIpPrefixEntry> ip6PrefixEntries) {
this.localIp6PrefixEntries = ip6PrefixEntries;
}
}
......
......@@ -16,17 +16,25 @@
package org.onosproject.routing.config.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.HostService;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
import org.onosproject.routing.config.Interface;
import org.onosproject.routing.config.LocalIpPrefixEntry;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -39,6 +47,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static org.onosproject.routing.RouteEntry.createBinaryString;
/**
* Implementation of RoutingConfigurationService which reads routing
* configuration from a file.
......@@ -59,6 +69,13 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
private InvertedRadixTree<LocalIpPrefixEntry>
localPrefixTable4 = new ConcurrentInvertedRadixTree<>(
new DefaultByteArrayNodeFactory());
private InvertedRadixTree<LocalIpPrefixEntry>
localPrefixTable6 = new ConcurrentInvertedRadixTree<>(
new DefaultByteArrayNodeFactory());
private HostToInterfaceAdaptor hostAdaptor;
@Activate
......@@ -88,6 +105,16 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
for (BgpPeer peer : config.getPeers()) {
bgpPeers.put(peer.ipAddress(), peer);
}
for (LocalIpPrefixEntry entry : config.getLocalIp4PrefixEntries()) {
localPrefixTable4.put(createBinaryString(entry.ipPrefix()),
entry);
}
for (LocalIpPrefixEntry entry : config.getLocalIp6PrefixEntries()) {
localPrefixTable6.put(createBinaryString(entry.ipPrefix()),
entry);
}
} catch (FileNotFoundException e) {
log.warn("Configuration file not found: {}", configFileName);
} catch (IOException e) {
......@@ -96,7 +123,8 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
}
/**
* Instructs the configuration reader to read the configuration from the file.
* Instructs the configuration reader to read the configuration from the
* file.
*/
public void readConfiguration() {
readConfiguration(configFileName);
......@@ -127,4 +155,27 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
return hostAdaptor.getMatchingInterface(ipAddress);
}
@Override
public boolean isIpAddressLocal(IpAddress ipAddress) {
if (ipAddress.isIp4()) {
return localPrefixTable4.getValuesForKeysPrefixing(
createBinaryString(
IpPrefix.valueOf(ipAddress, Ip4Address.BIT_LENGTH)))
.iterator().hasNext();
} else {
return localPrefixTable6.getValuesForKeysPrefixing(
createBinaryString(
IpPrefix.valueOf(ipAddress, Ip6Address.BIT_LENGTH)))
.iterator().hasNext();
}
}
@Override
public boolean isIpPrefixLocal(IpPrefix ipPrefix) {
return (localPrefixTable4.getValueForExactKey(
createBinaryString(ipPrefix)) != null ||
localPrefixTable6.getValueForExactKey(
createBinaryString(ipPrefix)) != null);
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.routing.impl;
import com.google.common.collect.Sets;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -36,6 +37,7 @@ import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostListener;
import org.onosproject.net.host.HostService;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.onosproject.routing.impl.Router.InternalHostListener;
import org.onosproject.routing.BgpService;
import org.onosproject.routing.FibEntry;
......@@ -57,6 +59,7 @@ public class RouterAsyncArpTest {
private HostService hostService;
private FibListener fibListener;
private RoutingConfigurationService routingConfigurationService;
private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
DeviceId.deviceId("of:0000000000000001"),
......@@ -76,6 +79,8 @@ public class RouterAsyncArpTest {
@Before
public void setUp() throws Exception {
hostService = createMock(HostService.class);
routingConfigurationService =
createMock(RoutingConfigurationService.class);
BgpService bgpService = createMock(BgpService.class);
bgpService.start(anyObject(RouteListener.class));
......@@ -86,10 +91,12 @@ public class RouterAsyncArpTest {
router = new Router();
router.hostService = hostService;
router.routingConfigurationService = routingConfigurationService;
router.bgpService = bgpService;
router.activate();
router.start(fibListener);
router.addFibListener(fibListener);
router.start();
internalHostListener = router.new InternalHostListener();
}
......@@ -121,6 +128,10 @@ public class RouterAsyncArpTest {
hostService.startMonitoringIp(IpAddress.valueOf("192.168.10.1"));
replay(hostService);
reset(routingConfigurationService);
expect(routingConfigurationService.isIpPrefixLocal(
anyObject(IpPrefix.class))).andReturn(false);
replay(routingConfigurationService);
// Initially when we add the route, no FIB update will be sent
replay(fibListener);
......@@ -175,6 +186,10 @@ public class RouterAsyncArpTest {
hostService.startMonitoringIp(IpAddress.valueOf("192.168.20.1"));
replay(hostService);
reset(routingConfigurationService);
expect(routingConfigurationService.isIpPrefixLocal(
anyObject(IpPrefix.class))).andReturn(false);
replay(routingConfigurationService);
// Initially when we add the route, the DELETE FIB update will be sent
// but the UPDATE FIB update will come later when the MAC is resolved
......
......@@ -16,6 +16,7 @@
package org.onosproject.routing.impl;
import com.google.common.collect.Sets;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -42,6 +43,7 @@ import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.RouteEntry;
import org.onosproject.routing.RouteListener;
import org.onosproject.routing.RouteUpdate;
import org.onosproject.routing.config.RoutingConfigurationService;
import java.util.Collections;
......@@ -58,6 +60,7 @@ import static org.junit.Assert.assertTrue;
public class RouterTest {
private HostService hostService;
private RoutingConfigurationService routingConfigurationService;
private FibListener fibListener;
......@@ -82,6 +85,8 @@ public class RouterTest {
@Before
public void setUp() throws Exception {
setUpHostService();
routingConfigurationService =
createMock(RoutingConfigurationService.class);
BgpService bgpService = createMock(BgpService.class);
bgpService.start(anyObject(RouteListener.class));
......@@ -92,10 +97,12 @@ public class RouterTest {
router = new Router();
router.hostService = hostService;
router.routingConfigurationService = routingConfigurationService;
router.bgpService = bgpService;
router.activate();
router.start(fibListener);
router.addFibListener(fibListener);
router.start();
}
@After
......@@ -207,9 +214,13 @@ public class RouterTest {
FibUpdate.Type.UPDATE, updateFibEntry)),
Collections.singletonList(new FibUpdate(
FibUpdate.Type.DELETE, withdrawFibEntry)));
replay(fibListener);
reset(routingConfigurationService);
expect(routingConfigurationService.isIpPrefixLocal(
anyObject(IpPrefix.class))).andReturn(false);
replay(routingConfigurationService);
router.processRouteUpdates(Collections.singletonList(new RouteUpdate(
RouteUpdate.Type.UPDATE, routeEntryUpdate)));
......@@ -256,6 +267,11 @@ public class RouterTest {
// No methods on the FIB listener should be called
replay(fibListener);
reset(routingConfigurationService);
expect(routingConfigurationService.isIpPrefixLocal(
anyObject(IpPrefix.class))).andReturn(true);
replay(routingConfigurationService);
// Call the processRouteUpdates() method in Router class
RouteUpdate routeUpdate = new RouteUpdate(RouteUpdate.Type.UPDATE,
routeEntry);
......
......@@ -29,6 +29,7 @@ import org.onosproject.cluster.LeadershipService;
import org.onosproject.config.NetworkConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.IntentService;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.config.RoutingConfigurationService;
......@@ -53,6 +54,9 @@ public class SdnIp implements SdnIpService {
protected IntentService intentService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -89,6 +93,7 @@ public class SdnIp implements SdnIpService {
localControllerNode = clusterService.getLocalNode();
intentSynchronizer = new IntentSynchronizer(appId, intentService,
hostService,
config);
intentSynchronizer.start();
......@@ -97,7 +102,9 @@ public class SdnIp implements SdnIpService {
config);
peerConnectivity.start();
routingService.start(intentSynchronizer);
routingService.addFibListener(intentSynchronizer);
routingService.addIntentRequestListener(intentSynchronizer);
routingService.start();
leadershipService.addListener(leadershipEventListener);
leadershipService.runForLeadership(appId.name());
......
......@@ -27,4 +27,5 @@ public interface SdnIpService {
* @param isPrimary true if the instance is primary, false if it is not
*/
public void modifyPrimary(boolean isPrimary);
}
......
......@@ -62,5 +62,21 @@
]
}
],
"ip4LocalPrefixes" : [
{
"ipPrefix" : "100.0.0.0/24",
"type" : "PUBLIC"
},
{
"ipPrefix" : "200.0.0.0/8",
"type" : "PUBLIC"
},
{
"ipPrefix" : "192.0.0.0/24",
"type" : "PRIVATE"
}
],
"ip6LocalPrefixes" : [
]
}
......
......@@ -118,7 +118,7 @@ public class IntentSyncTest extends AbstractIntentTest {
intentService = createMock(IntentService.class);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
routingConfig);
null, routingConfig);
}
/**
......
......@@ -555,7 +555,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
replay(intentService);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
routingConfig);
null, routingConfig);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
......
......@@ -188,6 +188,12 @@
<bundle>mvn:org.onosproject/onos-app-optical/@ONOS-VERSION</bundle>
</feature>
<feature name="onos-app-reactive-routing" version="@FEATURE-VERSION"
description="ONOS SDN/IP reactive routing">
<feature>onos-app-sdnip</feature>
<bundle>mvn:org.onosproject/onos-app-reactive-routing/@ONOS-VERSION</bundle>
</feature>
<feature name="onos-app-sdnip" version="@FEATURE-VERSION"
description="SDN-IP peering application">
<feature>onos-api</feature>
......
......@@ -371,6 +371,22 @@ public class IpAddress implements Comparable<IpAddress> {
}
/**
* Generates an IP prefix.
*
* @return the IP prefix of the IP address
*/
public IpPrefix toIpPrefix() {
if (isIp4()) {
return IpPrefix.valueOf(new IpAddress(Version.INET, octets),
Ip4Address.BIT_LENGTH);
} else {
return IpPrefix.valueOf(new IpAddress(Version.INET6, octets),
Ip6Address.BIT_LENGTH);
}
}
/**
* Gets the IP address name for the IP address version.
*
* @param version the IP address version
......