Jonathan Hart
Committed by Gerrit Code Review

Generalize IntentSynchronizer and separate reactive routing code

 * IntentSynchronizer can now handle any intent rather than having use
   case specific APIs
 * IntentSynchronizer does not generate or store intents anymore, it only
   perform synchronization
 * SdnIpFib generates and manages the procative route-based intents
 * ReactiveRoutingFib generates and manages the reactive intents
 * Unit tests have been tightned up to only test single components, rather
   than multiple components together
 * PeerConnectivityManager uses meaningful keys when creating intents

Change-Id: I4bb036ec8d056f43ece46f7dfc71d5e5a136b77d
Showing 21 changed files with 769 additions and 360 deletions
/*
* 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;
/**
* Specifies the type of an IP address or an IP prefix location.
*/
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
}
......@@ -25,27 +25,39 @@ import org.onlab.packet.EthType;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
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.host.HostService;
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.PacketProcessor;
import org.onosproject.net.packet.PacketService;
import org.onosproject.routing.IntentRequestListener;
import org.onosproject.routing.RouteEntry;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.SdnIpService;
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;
......@@ -74,16 +86,32 @@ public class SdnIpReactiveRouting {
protected RoutingService routingService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected SdnIpService sdnIpService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected RoutingConfigurationService config;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected InterfaceService interfaceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected HostService hostService;
private ApplicationId appId;
private IntentRequestListener intentRequestListener;
private ReactiveRoutingProcessor processor =
new ReactiveRoutingProcessor();
@Activate
public void activate() {
appId = coreService.registerApplication(APP_NAME);
intentRequestListener = new ReactiveRoutingFib(appId, hostService,
config, interfaceService,
sdnIpService.getIntentSynchronizationService());
packetService.addProcessor(processor, PacketProcessor.director(2));
requestIntercepts();
log.info("SDN-IP Reactive Routing Started");
......@@ -168,12 +196,11 @@ public class SdnIpReactiveRouting {
IpAddress srcIp =
IpAddress.valueOf(ipv4Packet.getSourceAddress());
MacAddress srcMac = ethPkt.getSourceMAC();
routingService.packetReactiveProcessor(dstIp, srcIp,
srcConnectPoint, srcMac);
packetReactiveProcessor(dstIp, srcIp, srcConnectPoint, srcMac);
// TODO emit packet first or packetReactiveProcessor first
ConnectPoint egressConnectPoint = null;
egressConnectPoint = routingService.getEgressConnectPoint(dstIp);
egressConnectPoint = getEgressConnectPoint(dstIp);
if (egressConnectPoint != null) {
forwardPacketToDst(context, egressConnectPoint);
}
......@@ -185,6 +212,170 @@ public class SdnIpReactiveRouting {
}
/**
* 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
*/
private void packetReactiveProcessor(IpAddress dstIpAddress,
IpAddress srcIpAddress,
ConnectPoint srcConnectPoint,
MacAddress srcMacAddress) {
checkNotNull(dstIpAddress);
checkNotNull(srcIpAddress);
checkNotNull(srcConnectPoint);
checkNotNull(srcMacAddress);
//
// Step1: Try to update the existing intent first if it exists.
//
IpPrefix ipPrefix = null;
RouteEntry routeEntry = null;
if (config.isIpAddressLocal(dstIpAddress)) {
if (dstIpAddress.isIp4()) {
ipPrefix = IpPrefix.valueOf(dstIpAddress,
Ip4Address.BIT_LENGTH);
} else {
ipPrefix = IpPrefix.valueOf(dstIpAddress,
Ip6Address.BIT_LENGTH);
}
} else {
// Get IP prefix from BGP route table
routeEntry = routingService.getLongestMatchableRouteEntry(dstIpAddress);
if (routeEntry != null) {
ipPrefix = routeEntry.prefix();
}
}
if (ipPrefix != null
&& intentRequestListener.mp2pIntentExists(ipPrefix)) {
intentRequestListener.updateExistingMp2pIntent(ipPrefix,
srcConnectPoint);
return;
}
//
// Step2: There is no existing intent for the destination IP address.
// Check whether it is necessary to create a new one. If necessary then
// create a new one.
//
TrafficType trafficType =
trafficTypeClassifier(srcConnectPoint, dstIpAddress);
switch (trafficType) {
case HOST_TO_INTERNET:
// If the destination IP address is outside the local SDN network.
// The Step 1 has already handled it. We do not need to do anything here.
intentRequestListener.setUpConnectivityHostToInternet(srcIpAddress,
ipPrefix, routeEntry.nextHop());
break;
case INTERNET_TO_HOST:
intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress);
break;
case HOST_TO_HOST:
intentRequestListener.setUpConnectivityHostToHost(dstIpAddress,
srcIpAddress, srcMacAddress, srcConnectPoint);
break;
case INTERNET_TO_INTERNET:
log.trace("This is transit traffic, "
+ "the intent should be preinstalled already");
break;
case DROP:
// TODO here should setUpDropPacketIntent(...);
// We need a new type of intent here.
break;
case UNKNOWN:
log.trace("This is unknown traffic, so we do nothing");
break;
default:
break;
}
}
/**
* Classifies the traffic and return the traffic type.
*
* @param srcConnectPoint the connect point where the packet comes from
* @param dstIp the destination IP address in packet
* @return the traffic type which this packet belongs to
*/
private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint,
IpAddress dstIp) {
LocationType dstIpLocationType = getLocationType(dstIp);
Optional<Interface> srcInterface =
interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst();
switch (dstIpLocationType) {
case INTERNET:
if (!srcInterface.isPresent()) {
return TrafficType.HOST_TO_INTERNET;
} else {
return TrafficType.INTERNET_TO_INTERNET;
}
case LOCAL:
if (!srcInterface.isPresent()) {
return TrafficType.HOST_TO_HOST;
} else {
// TODO Currently we only consider local public prefixes.
// In the future, we will consider the local private prefixes.
// If dstIpLocationType is a local private, we should return
// TrafficType.DROP.
return TrafficType.INTERNET_TO_HOST;
}
case NO_ROUTE:
return TrafficType.DROP;
default:
return TrafficType.UNKNOWN;
}
}
/**
* 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
*/
private LocationType getLocationType(IpAddress ipAddress) {
if (config.isIpAddressLocal(ipAddress)) {
return LocationType.LOCAL;
} else if (routingService.getLongestMatchableRouteEntry(ipAddress) != null) {
return LocationType.INTERNET;
} else {
return LocationType.NO_ROUTE;
}
}
public ConnectPoint getEgressConnectPoint(IpAddress dstIpAddress) {
LocationType type = getLocationType(dstIpAddress);
if (type == LocationType.LOCAL) {
Set<Host> hosts = hostService.getHostsByIp(dstIpAddress);
if (!hosts.isEmpty()) {
return hosts.iterator().next().location();
} else {
hostService.startMonitoringIp(dstIpAddress);
return null;
}
} else if (type == LocationType.INTERNET) {
IpAddress nextHopIpAddress = null;
RouteEntry routeEntry = routingService.getLongestMatchableRouteEntry(dstIpAddress);
if (routeEntry != null) {
nextHopIpAddress = routeEntry.nextHop();
Interface it = interfaceService.getMatchingInterface(nextHopIpAddress);
if (it != null) {
return it.connectPoint();
} else {
return null;
}
} else {
return null;
}
} else {
return null;
}
}
/**
* Emits the specified packet onto the network.
*
* @param context the packet context
......
/*
* 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;
/**
* Specifies the type of traffic.
* <p>
* We classify traffic by the first packet of each traffic.
* </p>
*/
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
}
......@@ -47,6 +47,16 @@ public interface IntentRequestListener {
ConnectPoint srcConnectPoint);
/**
* Sets up connectivity for packet from a local host to the Internet.
*
* @param hostIp IP address of the local host
* @param prefix external IP prefix that the host is talking to
* @param nextHopIpAddress IP address of the next hop router for the prefix
*/
void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix,
IpAddress nextHopIpAddress);
/**
* Adds one new ingress connect point into ingress points of an existing
* intent and resubmits the new intent.
* <p>
......
/*
* 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.onosproject.net.intent.Intent;
/**
* Submits and withdraws intents to the IntentService from a single point in
* the cluster at any one time. The provided intents will be synchronized with
* the IntentService on leadership change.
*/
public interface IntentSynchronizationService {
/**
* Submits and intent to the synchronizer.
* <p>
* The intent will be submitted directly to the IntentService if this node
* is the leader, otherwise it will be stored in the synchronizer for
* synchronization if this node becomes the leader.
* </p>
*
* @param intent intent to submit
*/
void submit(Intent intent);
/**
* Withdraws an intent from the synchronizer.
* <p>
* The intent will be withdrawn directly from the IntentService if this node
* is the leader. The intent will be removed from the synchronizer's
* in-memory storage.
* </p>
*
* @param intent intent to withdraw
*/
void withdraw(Intent intent);
}
......@@ -16,8 +16,6 @@
package org.onosproject.routing;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.routing.config.BgpConfig;
import java.util.Collection;
......@@ -32,63 +30,6 @@ public interface RoutingService {
Class<BgpConfig> CONFIG_CLASS = BgpConfig.class;
/**
* Specifies the type of an IP address or an IP prefix location.
*/
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>
*/
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.
*/
void start();
......@@ -101,15 +42,6 @@ public interface RoutingService {
void addFibListener(FibListener fibListener);
/**
* Adds intent creation and submission listener.
*
* @param intentRequestListener listener to send intent creation and
* submission request to
*/
void addIntentRequestListener(IntentRequestListener
intentRequestListener);
/**
* Stops the routing service.
*/
void stop();
......@@ -129,14 +61,6 @@ public interface RoutingService {
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
*/
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
......@@ -145,25 +69,4 @@ public interface RoutingService {
*/
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
*/
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
*/
void packetReactiveProcessor(IpAddress dstIpAddress,
IpAddress srcIpAddress,
ConnectPoint srcConnectPoint,
MacAddress srcMacAddress);
}
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.sdnip;
package org.onosproject.routing;
/**
* Service interface exported by SDN-IP.
......@@ -28,4 +28,12 @@ public interface SdnIpService {
*/
void modifyPrimary(boolean isPrimary);
/**
* Gets the intent synchronization service.
*
* @return intent synchronization service
*/
// TODO fix service resolution in SDN-IP
IntentSynchronizationService getIntentSynchronizationService();
}
......
......@@ -35,9 +35,7 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.Host;
import org.onosproject.net.host.HostEvent;
import org.onosproject.net.host.HostListener;
......@@ -46,7 +44,6 @@ import org.onosproject.routing.BgpService;
import org.onosproject.routing.FibEntry;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.IntentRequestListener;
import org.onosproject.routing.RouteEntry;
import org.onosproject.routing.RouteListener;
import org.onosproject.routing.RouteUpdate;
......@@ -61,7 +58,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
......@@ -100,7 +96,6 @@ public class Router implements RoutingService {
private final Map<IpAddress, MacAddress> ip2Mac = new ConcurrentHashMap<>();
private FibListener fibComponent;
private IntentRequestListener intentRequestListener;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
......@@ -145,12 +140,6 @@ public class Router implements RoutingService {
@Override
public void addFibListener(FibListener fibListener) {
this.fibComponent = checkNotNull(fibListener);
}
@Override
public void addIntentRequestListener(IntentRequestListener intentRequestListener) {
this.intentRequestListener = checkNotNull(intentRequestListener);
}
@Override
......@@ -287,12 +276,10 @@ public class Router implements RoutingService {
void addRibRoute(RouteEntry routeEntry) {
if (routeEntry.isIp4()) {
// IPv4
ribTable4.put(createBinaryString(routeEntry.prefix()),
routeEntry);
ribTable4.put(createBinaryString(routeEntry.prefix()), routeEntry);
} else {
// IPv6
ribTable6.put(createBinaryString(routeEntry.prefix()),
routeEntry);
ribTable6.put(createBinaryString(routeEntry.prefix()), routeEntry);
}
}
......@@ -553,17 +540,6 @@ public class Router implements RoutingService {
}
@Override
public LocationType getLocationType(IpAddress ipAddress) {
if (routingConfigurationService.isIpAddressLocal(ipAddress)) {
return LocationType.LOCAL;
} else if (getLongestMatchableRouteEntry(ipAddress) != null) {
return LocationType.INTERNET;
} else {
return LocationType.NO_ROUTE;
}
}
@Override
public RouteEntry getLongestMatchableRouteEntry(IpAddress ipAddress) {
RouteEntry routeEntry = null;
Iterable<RouteEntry> routeEntries;
......@@ -587,142 +563,4 @@ public class Router implements RoutingService {
return routeEntry;
}
@Override
public ConnectPoint getEgressConnectPoint(IpAddress dstIpAddress) {
LocationType type = getLocationType(dstIpAddress);
if (type == LocationType.LOCAL) {
Set<Host> hosts = hostService.getHostsByIp(dstIpAddress);
if (!hosts.isEmpty()) {
return hosts.iterator().next().location();
} else {
hostService.startMonitoringIp(dstIpAddress);
return null;
}
} else if (type == LocationType.INTERNET) {
IpAddress nextHopIpAddress = null;
RouteEntry routeEntry = getLongestMatchableRouteEntry(dstIpAddress);
if (routeEntry != null) {
nextHopIpAddress = routeEntry.nextHop();
Interface it = interfaceService.getMatchingInterface(nextHopIpAddress);
if (it != null) {
return it.connectPoint();
} else {
return null;
}
} else {
return null;
}
} else {
return null;
}
}
@Override
public void packetReactiveProcessor(IpAddress dstIpAddress,
IpAddress srcIpAddress,
ConnectPoint srcConnectPoint,
MacAddress srcMacAddress) {
checkNotNull(dstIpAddress);
checkNotNull(srcIpAddress);
checkNotNull(srcConnectPoint);
checkNotNull(srcMacAddress);
//
// Step1: Try to update the existing intent first if it exists.
//
IpPrefix ipPrefix = null;
if (routingConfigurationService.isIpAddressLocal(dstIpAddress)) {
if (dstIpAddress.isIp4()) {
ipPrefix = IpPrefix.valueOf(dstIpAddress,
Ip4Address.BIT_LENGTH);
} else {
ipPrefix = IpPrefix.valueOf(dstIpAddress,
Ip6Address.BIT_LENGTH);
}
} else {
// Get IP prefix from BGP route table
RouteEntry routeEntry = getLongestMatchableRouteEntry(dstIpAddress);
if (routeEntry != null) {
ipPrefix = routeEntry.prefix();
}
}
if (ipPrefix != null
&& intentRequestListener.mp2pIntentExists(ipPrefix)) {
intentRequestListener.updateExistingMp2pIntent(ipPrefix,
srcConnectPoint);
return;
}
//
// Step2: There is no existing intent for the destination IP address.
// Check whether it is necessary to create a new one. If necessary then
// create a new one.
//
TrafficType trafficType =
trafficTypeClassifier(srcConnectPoint, dstIpAddress);
switch (trafficType) {
case HOST_TO_INTERNET:
// If the destination IP address is outside the local SDN network.
// The Step 1 has already handled it. We do not need to do anything here.
break;
case INTERNET_TO_HOST:
intentRequestListener.setUpConnectivityInternetToHost(dstIpAddress);
break;
case HOST_TO_HOST:
intentRequestListener.setUpConnectivityHostToHost(dstIpAddress,
srcIpAddress, srcMacAddress, srcConnectPoint);
break;
case INTERNET_TO_INTERNET:
log.trace("This is transit traffic, "
+ "the intent should be preinstalled already");
break;
case DROP:
// TODO here should setUpDropPaccketIntent(...);
// We need a new type of intent here.
break;
case UNKNOWN:
log.trace("This is unknown traffic, so we do nothing");
break;
default:
break;
}
}
/**
* Classifies the traffic and return the traffic type.
*
* @param srcConnectPoint the connect point where the packet comes from
* @param dstIp the destination IP address in packet
* @return the traffic type which this packet belongs to
*/
private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint,
IpAddress dstIp) {
LocationType dstIpLocationType = getLocationType(dstIp);
Optional<Interface> srcInterface =
interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst();
switch (dstIpLocationType) {
case INTERNET:
if (!srcInterface.isPresent()) {
return TrafficType.HOST_TO_INTERNET;
} else {
return TrafficType.INTERNET_TO_INTERNET;
}
case LOCAL:
if (!srcInterface.isPresent()) {
return TrafficType.HOST_TO_HOST;
} else {
// TODO Currently we only consider local public prefixes.
// In the future, we will consider the local private prefixes.
// If dstIpLocationType is a local private, we should return
// TrafficType.DROP.
return TrafficType.INTERNET_TO_HOST;
}
case NO_ROUTE:
return TrafficType.DROP;
default:
return TrafficType.UNKNOWN;
}
}
}
......
......@@ -18,10 +18,7 @@ package org.onosproject.routing.impl;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.IntentRequestListener;
import org.onosproject.routing.RouteEntry;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.StaticRoutingService;
......@@ -49,11 +46,6 @@ public class StaticRouter implements RoutingService, StaticRoutingService {
}
@Override
public void addIntentRequestListener(IntentRequestListener intentRequestListener) {
}
@Override
public void stop() {
}
......@@ -69,27 +61,11 @@ public class StaticRouter implements RoutingService, StaticRoutingService {
}
@Override
public LocationType getLocationType(IpAddress ipAddress) {
return null;
}
@Override
public RouteEntry getLongestMatchableRouteEntry(IpAddress ipAddress) {
return null;
}
@Override
public ConnectPoint getEgressConnectPoint(IpAddress dstIpAddress) {
return null;
}
@Override
public void packetReactiveProcessor(IpAddress dstIpAddress, IpAddress srcIpAddress,
ConnectPoint srcConnectPoint, MacAddress srcMacAddress) {
}
@Override
public FibListener getFibListener() {
return fibListener;
}
......
/*
* 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.sdnip;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.PointToPointIntent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Objects;
import static com.google.common.base.Preconditions.checkArgument;
/**
* Utilities for dealing with intents.
*/
public final class IntentUtils {
private static final Logger log = LoggerFactory.getLogger(IntentUtils.class);
private IntentUtils() {
}
/**
* Checks if two intents represent the same value.
*
* <p>({@link Intent#equals(Object)} only checks ID equality)</p>
*
* <p>Both intents must be of the same type.</p>
*
* @param one first intent
* @param two second intent
* @return true if the two intents represent the same value, otherwise false
*/
public static boolean equals(Intent one, Intent two) {
checkArgument(one.getClass() == two.getClass(),
"Intents are not the same type");
if (!(Objects.equals(one.appId(), two.appId()) &&
Objects.equals(one.key(), two.key()))) {
return false;
}
if (one instanceof MultiPointToSinglePointIntent) {
MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one;
MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two;
return Objects.equals(intent1.selector(), intent2.selector()) &&
Objects.equals(intent1.treatment(), intent2.treatment()) &&
Objects.equals(intent1.ingressPoints(), intent2.ingressPoints()) &&
Objects.equals(intent1.egressPoint(), intent2.egressPoint());
} else if (one instanceof PointToPointIntent) {
PointToPointIntent intent1 = (PointToPointIntent) one;
PointToPointIntent intent2 = (PointToPointIntent) two;
return Objects.equals(intent1.selector(), intent2.selector()) &&
Objects.equals(intent1.treatment(), intent2.treatment()) &&
Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) &&
Objects.equals(intent1.egressPoint(), intent2.egressPoint());
} else {
log.error("Unimplemented intent type");
return false;
}
}
}
......@@ -15,6 +15,8 @@
*/
package org.onosproject.sdnip;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.IPv6;
......@@ -22,16 +24,18 @@ import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.TpPort;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.config.NetworkConfigService;
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.host.InterfaceIpAddress;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.config.BgpConfig;
import org.slf4j.Logger;
......@@ -49,18 +53,26 @@ import static com.google.common.base.Preconditions.checkNotNull;
public class PeerConnectivityManager {
private static final int PRIORITY_OFFSET = 1000;
private static final String SUFFIX_DST = "dst";
private static final String SUFFIX_SRC = "src";
private static final String SUFFIX_ICMP = "icmp";
private static final Logger log = LoggerFactory.getLogger(
PeerConnectivityManager.class);
private static final short BGP_PORT = 179;
private final IntentSynchronizer intentSynchronizer;
private final IntentSynchronizationService intentSynchronizer;
private final NetworkConfigService configService;
private final InterfaceService interfaceService;
private final ApplicationId appId;
private final ApplicationId routerAppId;
// Just putting something random here for now. Figure out exactly what
// indexes we need when we start making use of them.
private final Multimap<BgpConfig.BgpSpeakerConfig, PointToPointIntent> peerIntents;
/**
* Creates a new PeerConnectivityManager.
*
......@@ -71,7 +83,7 @@ public class PeerConnectivityManager {
* @param routerAppId application ID
*/
public PeerConnectivityManager(ApplicationId appId,
IntentSynchronizer intentSynchronizer,
IntentSynchronizationService intentSynchronizer,
NetworkConfigService configService,
ApplicationId routerAppId,
InterfaceService interfaceService) {
......@@ -80,6 +92,8 @@ public class PeerConnectivityManager {
this.configService = configService;
this.routerAppId = routerAppId;
this.interfaceService = interfaceService;
peerIntents = HashMultimap.create();
}
/**
......@@ -100,8 +114,6 @@ public class PeerConnectivityManager {
* BGP speakers and external BGP peers.
*/
private void setUpConnectivity() {
List<PointToPointIntent> intents = new ArrayList<>();
BgpConfig config = configService.getConfig(routerAppId, RoutingService.CONFIG_CLASS);
if (config == null) {
......@@ -113,11 +125,12 @@ public class PeerConnectivityManager {
log.debug("Start to set up BGP paths for BGP speaker: {}",
bgpSpeaker);
intents.addAll(buildSpeakerIntents(bgpSpeaker));
}
buildSpeakerIntents(bgpSpeaker).forEach(i -> {
peerIntents.put(bgpSpeaker, i);
intentSynchronizer.submit(i);
});
// Submit all the intents.
intentSynchronizer.submitPeerIntents(intents);
}
}
private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker) {
......@@ -167,8 +180,8 @@ public class PeerConnectivityManager {
List<PointToPointIntent> intents = new ArrayList<>();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
TrafficSelector selector;
Key key;
byte tcpProtocol;
byte icmpProtocol;
......@@ -188,8 +201,11 @@ public class PeerConnectivityManager {
null,
BGP_PORT);
key = buildKey(ipOne, ipTwo, SUFFIX_DST);
intents.add(PointToPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.treatment(treatment)
.ingressPoint(portOne)
......@@ -204,8 +220,11 @@ public class PeerConnectivityManager {
BGP_PORT,
null);
key = buildKey(ipOne, ipTwo, SUFFIX_SRC);
intents.add(PointToPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.treatment(treatment)
.ingressPoint(portOne)
......@@ -220,8 +239,11 @@ public class PeerConnectivityManager {
null,
BGP_PORT);
key = buildKey(ipTwo, ipOne, SUFFIX_DST);
intents.add(PointToPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.treatment(treatment)
.ingressPoint(portTwo)
......@@ -236,8 +258,11 @@ public class PeerConnectivityManager {
BGP_PORT,
null);
key = buildKey(ipTwo, ipOne, SUFFIX_SRC);
intents.add(PointToPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.treatment(treatment)
.ingressPoint(portTwo)
......@@ -252,8 +277,11 @@ public class PeerConnectivityManager {
null,
null);
key = buildKey(ipOne, ipTwo, SUFFIX_ICMP);
intents.add(PointToPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.treatment(treatment)
.ingressPoint(portOne)
......@@ -268,8 +296,11 @@ public class PeerConnectivityManager {
null,
null);
key = buildKey(ipTwo, ipOne, SUFFIX_ICMP);
intents.add(PointToPointIntent.builder()
.appId(appId)
.key(key)
.selector(selector)
.treatment(treatment)
.ingressPoint(portTwo)
......@@ -316,4 +347,27 @@ public class PeerConnectivityManager {
return builder.build();
}
/**
* Builds an intent Key for a point-to-point intent based off the source
* and destination IP address, as well as a suffix String to distinguish
* between different types of intents between the same source and
* destination.
*
* @param srcIp source IP address
* @param dstIp destination IP address
* @param suffix suffix string
* @return
*/
private Key buildKey(IpAddress srcIp, IpAddress dstIp, String suffix) {
String keyString = new StringBuilder()
.append(srcIp.toString())
.append("-")
.append(dstIp.toString())
.append("-")
.append(suffix)
.toString();
return Key.of(keyString, appId);
}
}
......
......@@ -32,7 +32,9 @@ import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.host.HostService;
import org.onosproject.net.intent.IntentService;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.RoutingService;
import org.onosproject.routing.SdnIpService;
import org.onosproject.routing.config.RoutingConfigurationService;
import org.slf4j.Logger;
......@@ -79,6 +81,7 @@ public class SdnIp implements SdnIpService {
private IntentSynchronizer intentSynchronizer;
private PeerConnectivityManager peerConnectivity;
private SdnIpFib fib;
private LeadershipEventListener leadershipEventListener =
new InnerLeadershipEventListener();
......@@ -93,10 +96,7 @@ public class SdnIp implements SdnIpService {
localControllerNode = clusterService.getLocalNode();
intentSynchronizer = new IntentSynchronizer(appId, intentService,
hostService,
config,
interfaceService);
intentSynchronizer = new IntentSynchronizer(appId, intentService);
intentSynchronizer.start();
peerConnectivity = new PeerConnectivityManager(appId,
......@@ -106,8 +106,9 @@ public class SdnIp implements SdnIpService {
interfaceService);
peerConnectivity.start();
routingService.addFibListener(intentSynchronizer);
routingService.addIntentRequestListener(intentSynchronizer);
fib = new SdnIpFib(appId, interfaceService, intentSynchronizer);
routingService.addFibListener(fib);
routingService.start();
leadershipService.addListener(leadershipEventListener);
......@@ -131,6 +132,11 @@ public class SdnIp implements SdnIpService {
intentSynchronizer.leaderChanged(isPrimary);
}
@Override
public IntentSynchronizationService getIntentSynchronizationService() {
return intentSynchronizer;
}
/**
* Converts DPIDs of the form xx:xx:xx:xx:xx:xx:xx to OpenFlow provider
* device URIs.
......
/*
* 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.sdnip;
import com.google.common.collect.ImmutableList;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.core.ApplicationId;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
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.intent.Constraint;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.net.intent.constraint.PartialFailureConstraint;
import org.onosproject.routing.FibListener;
import org.onosproject.routing.FibUpdate;
import org.onosproject.routing.IntentSynchronizationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkArgument;
/**
* FIB component of SDN-IP.
*/
public class SdnIpFib implements FibListener {
private Logger log = LoggerFactory.getLogger(getClass());
private static final int PRIORITY_OFFSET = 100;
private static final int PRIORITY_MULTIPLIER = 5;
protected static final ImmutableList<Constraint> CONSTRAINTS
= ImmutableList.of(new PartialFailureConstraint());
private final Map<IpPrefix, MultiPointToSinglePointIntent> routeIntents;
private final ApplicationId appId;
private final InterfaceService interfaceService;
private final IntentSynchronizationService intentSynchronizer;
/**
* Class constructor.
*
* @param appId application ID to use when generating intents
* @param interfaceService interface service
* @param intentSynchronizer intent synchronizer
*/
public SdnIpFib(ApplicationId appId, InterfaceService interfaceService,
IntentSynchronizationService intentSynchronizer) {
routeIntents = new ConcurrentHashMap<>();
this.appId = appId;
this.interfaceService = interfaceService;
this.intentSynchronizer = intentSynchronizer;
}
@Override
public void update(Collection<FibUpdate> updates, Collection<FibUpdate> withdraws) {
int submitCount = 0, withdrawCount = 0;
//
// NOTE: Semantically, we MUST withdraw existing intents before
// submitting new intents.
//
synchronized (this) {
MultiPointToSinglePointIntent intent;
//
// Prepare the Intent batch operations for the intents to withdraw
//
for (FibUpdate withdraw : withdraws) {
checkArgument(withdraw.type() == FibUpdate.Type.DELETE,
"FibUpdate with wrong type in withdraws list");
IpPrefix prefix = withdraw.entry().prefix();
intent = routeIntents.remove(prefix);
if (intent == null) {
log.trace("SDN-IP No intent in routeIntents to delete " +
"for prefix: {}", prefix);
continue;
}
intentSynchronizer.withdraw(intent);
withdrawCount++;
}
//
// Prepare the Intent batch operations for the intents to submit
//
for (FibUpdate update : updates) {
checkArgument(update.type() == FibUpdate.Type.UPDATE,
"FibUpdate with wrong type in updates list");
IpPrefix prefix = update.entry().prefix();
intent = generateRouteIntent(prefix, update.entry().nextHopIp(),
update.entry().nextHopMac());
if (intent == null) {
// This preserves the old semantics - if an intent can't be
// generated, we don't do anything with that prefix. But
// perhaps we should withdraw the old intent anyway?
continue;
}
routeIntents.put(prefix, intent);
intentSynchronizer.submit(intent);
submitCount++;
}
log.debug("SDN-IP submitted {}/{}, withdrew = {}/{}", submitCount,
updates.size(), withdrawCount, withdraws.size());
}
}
/**
* Generates a route intent for a prefix, the next hop IP address, and
* the next hop MAC address.
* <p/>
* This method will find the egress interface for the intent.
* Intent will match dst IP prefix and rewrite dst MAC address at all other
* border switches, then forward packets according to dst MAC address.
*
* @param prefix IP prefix of the route to add
* @param nextHopIpAddress IP address of the next hop
* @param nextHopMacAddress MAC address of the next hop
* @return the generated intent, or null if no intent should be submitted
*/
private MultiPointToSinglePointIntent generateRouteIntent(
IpPrefix prefix,
IpAddress nextHopIpAddress,
MacAddress nextHopMacAddress) {
// Find the attachment point (egress interface) of the next hop
Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
if (egressInterface == null) {
log.warn("No outgoing interface found for {}",
nextHopIpAddress);
return null;
}
// Generate the intent itself
Set<ConnectPoint> ingressPorts = new HashSet<>();
ConnectPoint egressPort = egressInterface.connectPoint();
log.debug("Generating intent for prefix {}, next hop mac {}",
prefix, nextHopMacAddress);
for (Interface intf : interfaceService.getInterfaces()) {
// TODO this should be only peering interfaces
if (!intf.connectPoint().equals(egressInterface.connectPoint())) {
ConnectPoint srcPort = intf.connectPoint();
ingressPorts.add(srcPort);
}
}
// Match the destination IP prefix at the first hop
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
if (prefix.isIp4()) {
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchIPDst(prefix);
} else {
selector.matchEthType(Ethernet.TYPE_IPV6);
selector.matchIPv6Dst(prefix);
}
// Rewrite the destination MAC address
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
.setEthDst(nextHopMacAddress);
if (!egressInterface.vlan().equals(VlanId.NONE)) {
treatment.setVlanId(egressInterface.vlan());
// If we set VLAN ID, we have to make sure a VLAN tag exists.
// TODO support no VLAN -> VLAN routing
selector.matchVlanId(VlanId.ANY);
}
int priority =
prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
Key key = Key.of(prefix.toString(), appId);
return MultiPointToSinglePointIntent.builder()
.appId(appId)
.key(key)
.selector(selector.build())
.treatment(treatment.build())
.ingressPoints(ingressPorts)
.egressPoint(egressPort)
.priority(priority)
.constraints(CONSTRAINTS)
.build();
}
}
......@@ -18,7 +18,7 @@ package org.onosproject.sdnip.cli;
import org.apache.karaf.shell.commands.Argument;
import org.apache.karaf.shell.commands.Command;
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.sdnip.SdnIpService;
import org.onosproject.routing.SdnIpService;
/**
* Command to change whether this SDNIP instance is primary or not.
......
......@@ -19,7 +19,6 @@ import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
......@@ -28,13 +27,14 @@ import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.TpPort;
import org.onlab.packet.VlanId;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.incubator.net.intf.InterfaceService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
import org.onosproject.net.config.NetworkConfigService;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
......@@ -42,8 +42,9 @@ import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.host.InterfaceIpAddress;
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.config.BgpConfig;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
......@@ -71,26 +72,15 @@ import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId;
*/
public class PeerConnectivityManagerTest extends AbstractIntentTest {
private static final ApplicationId APPID = new ApplicationId() {
@Override
public short id() {
return 0;
}
@Override
public String name() {
return "foo";
}
};
private static final ApplicationId APPID = TestApplicationId.create("foo");
private static final ApplicationId CONFIG_APP_ID = APPID;
private PeerConnectivityManager peerConnectivityManager;
private IntentSynchronizer intentSynchronizer;
private IntentSynchronizationService intentSynchronizer;
private RoutingConfigurationService routingConfig;
private InterfaceService interfaceService;
private NetworkConfigService networkConfigService;
private IntentService intentService;
private Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers;
private Map<String, Interface> interfaces;
......@@ -98,8 +88,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
private BgpConfig bgpConfig;
private Map<String, Interface> configuredInterfaces;
private Map<IpAddress, BgpPeer> configuredPeers;
private List<PointToPointIntent> intentList;
private final String dpid1 = "00:00:00:00:00:00:00:01";
......@@ -136,7 +124,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
// These will set expectations on routingConfig and interfaceService
bgpSpeakers = setUpBgpSpeakers();
interfaces = Collections.unmodifiableMap(setUpInterfaces());
peers = Collections.unmodifiableMap(setUpPeers());
peers = setUpPeers();
initPeerConnectivity();
intentList = setUpIntentList();
......@@ -169,11 +157,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
* Sets up logical interfaces, which emulate the configured interfaces
* in SDN-IP application.
*
* @return configured interfaces as a MAP from Interface name to Interface
* @return configured interfaces as a map from interface name to Interface
*/
private Map<String, Interface> setUpInterfaces() {
configuredInterfaces = new HashMap<>();
Map<String, Interface> configuredInterfaces = new HashMap<>();
String interfaceSw1Eth1 = "s1-eth1";
InterfaceIpAddress ia1 =
......@@ -242,7 +230,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
private Map<IpAddress, BgpPeer> setUpPeers() {
configuredPeers = new HashMap<>();
Map<IpAddress, BgpPeer> configuredPeers = new HashMap<>();
String peerSw1Eth1 = "192.168.10.1";
configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
......@@ -266,14 +254,12 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
* @return point to point intent list
*/
private List<PointToPointIntent> setUpIntentList() {
intentList = new ArrayList<>();
setUpBgpIntents();
setUpIcmpIntents();
return intentList;
}
/**
......@@ -306,8 +292,12 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
builder.matchTcpDst(TpPort.tpPort(dstTcpPort));
}
Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0]
+ "-" + ((srcTcpPort == null) ? "dst" : "src"), APPID);
PointToPointIntent intent = PointToPointIntent.builder()
.appId(APPID)
.key(key)
.selector(builder.build())
.treatment(noTreatment)
.ingressPoint(srcConnectPoint)
......@@ -392,8 +382,12 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
.matchIPDst(IpPrefix.valueOf(dstPrefix))
.build();
Key key = Key.of(srcPrefix.split("/")[0] + "-" + dstPrefix.split("/")[0]
+ "-" + "icmp", APPID);
PointToPointIntent intent = PointToPointIntent.builder()
.appId(APPID)
.key(key)
.selector(selector)
.treatment(noTreatment)
.ingressPoint(srcConnectPoint)
......@@ -434,19 +428,14 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(bgpConfig);
expect(networkConfigService.getConfig(APPID, BgpConfig.class)).andReturn(bgpConfig).anyTimes();
expect(networkConfigService.getConfig(APPID, BgpConfig.class))
.andReturn(bgpConfig).anyTimes();
replay(networkConfigService);
replay(routingConfig);
replay(interfaceService);
intentService = createMock(IntentService.class);
replay(intentService);
intentSynchronizer = new IntentSynchronizer(APPID, intentService,
null, routingConfig,
interfaceService);
intentSynchronizer.leaderChanged(true);
TestUtils.setField(intentSynchronizer, "isActivatedLeader", true);
intentSynchronizer = createMock(IntentSynchronizationService.class);
replay(intentSynchronizer);
peerConnectivityManager =
new PeerConnectivityManager(APPID, intentSynchronizer,
......@@ -464,20 +453,18 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
@Test
public void testConnectionSetup() {
reset(intentService);
reset(intentSynchronizer);
// Setup the expected intents
for (Intent intent : intentList) {
intentService.submit(eqExceptId(intent));
intentSynchronizer.submit(eqExceptId(intent));
}
replay(intentService);
replay(intentSynchronizer);
// Running the interface to be tested.
peerConnectivityManager.start();
verify(intentService);
verify(intentSynchronizer);
}
/**
......@@ -488,7 +475,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
reset(interfaceService);
expect(interfaceService.getInterfaces()).andReturn(
Sets.<Interface>newHashSet()).anyTimes();
Sets.newHashSet()).anyTimes();
expect(interfaceService.getInterfacesByPort(s2Eth1))
.andReturn(Collections.emptySet()).anyTimes();
expect(interfaceService.getInterfacesByPort(s1Eth1))
......@@ -508,10 +495,10 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
replay(interfaceService);
reset(intentService);
replay(intentService);
reset(intentSynchronizer);
replay(intentSynchronizer);
peerConnectivityManager.start();
verify(intentService);
verify(intentSynchronizer);
}
/**
......@@ -527,10 +514,10 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes();
replay(routingConfig);
reset(intentService);
replay(intentService);
reset(intentSynchronizer);
replay(intentSynchronizer);
peerConnectivityManager.start();
verify(intentService);
verify(intentSynchronizer);
}
/**
......@@ -540,7 +527,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
@Test
public void testNoPeerInterface() {
String peerSw100Eth1 = "192.168.200.1";
configuredPeers.put(IpAddress.valueOf(peerSw100Eth1),
peers.put(IpAddress.valueOf(peerSw100Eth1),
new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
testConnectionSetup();
}
......
This diff is collapsed. Click to expand it.
......@@ -17,7 +17,6 @@ package org.onosproject.sdnip;
import org.easymock.IArgumentMatcher;
import org.onosproject.net.intent.Intent;
import org.onosproject.sdnip.IntentSynchronizer.IntentKey;
import static org.easymock.EasyMock.reportMatcher;
......@@ -53,8 +52,6 @@ public final class TestIntentServiceHelper {
* the solution is to use an EasyMock matcher that verifies that all the
* value properties of the provided intent match the expected values, but
* ignores the intent ID when testing equality.
*
* FIXME this currently does not take key into account
*/
private static final class IdAgnosticIntentMatcher implements
IArgumentMatcher {
......@@ -86,9 +83,7 @@ public final class TestIntentServiceHelper {
Intent providedIntent = (Intent) object;
providedString = providedIntent.toString();
IntentKey thisIntentKey = new IntentKey(intent);
IntentKey providedIntentKey = new IntentKey(providedIntent);
return thisIntentKey.equals(providedIntentKey);
return IntentUtils.equals(intent, providedIntent);
}
}
......
......@@ -574,8 +574,10 @@ public class EventuallyConsistentMapImpl<K, V>
return;
}
try {
log.debug("Received anti-entropy advertisement from {} for {} with {} entries in it",
if (log.isTraceEnabled()) {
log.trace("Received anti-entropy advertisement from {} for {} with {} entries in it",
mapName, ad.sender(), ad.digest().size());
}
antiEntropyCheckLocalItems(ad).forEach(this::notifyListeners);
if (!lightweightAntiEntropy) {
......