Pingping Lin
Committed by Gerrit Code Review

move the reactive routing to new config subsystem

Change-Id: I3e570138afb800c5bd7dbef872cbf9044732fa49
1 +<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2 +<!--
3 + ~ Copyright 2015 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
18 + <feature name="onos-app-reactive-routing" version="${project.version}"
19 + description="${project.description}">
20 + <feature>onos-api</feature>
21 + <bundle>mvn:${project.groupId}/onos-app-reactive-routing/${project.version}</bundle>
22 + <bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle>
23 + <bundle>mvn:${project.groupId}/onos-app-routing/${project.version}</bundle>
24 + </feature>
25 +</features>
...@@ -16,8 +16,17 @@ ...@@ -16,8 +16,17 @@
16 16
17 package org.onosproject.reactive.routing; 17 package org.onosproject.reactive.routing;
18 18
19 +import static com.google.common.base.Preconditions.checkNotNull;
20 +
19 import com.google.common.collect.ImmutableList; 21 import com.google.common.collect.ImmutableList;
20 import com.google.common.collect.Maps; 22 import com.google.common.collect.Maps;
23 +
24 +import java.util.Collections;
25 +import java.util.HashSet;
26 +import java.util.Map;
27 +import java.util.Set;
28 +import java.util.stream.Collectors;
29 +
21 import org.onlab.packet.Ethernet; 30 import org.onlab.packet.Ethernet;
22 import org.onlab.packet.IpAddress; 31 import org.onlab.packet.IpAddress;
23 import org.onlab.packet.IpPrefix; 32 import org.onlab.packet.IpPrefix;
...@@ -39,17 +48,9 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; ...@@ -39,17 +48,9 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent;
39 import org.onosproject.net.intent.constraint.PartialFailureConstraint; 48 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
40 import org.onosproject.routing.IntentRequestListener; 49 import org.onosproject.routing.IntentRequestListener;
41 import org.onosproject.routing.IntentSynchronizationService; 50 import org.onosproject.routing.IntentSynchronizationService;
42 -import org.onosproject.routing.config.RoutingConfigurationService;
43 import org.slf4j.Logger; 51 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory; 52 import org.slf4j.LoggerFactory;
45 53
46 -import java.util.Collections;
47 -import java.util.HashSet;
48 -import java.util.Map;
49 -import java.util.Set;
50 -
51 -import static com.google.common.base.Preconditions.checkNotNull;
52 -
53 /** 54 /**
54 * FIB component for reactive routing intents. 55 * FIB component for reactive routing intents.
55 */ 56 */
...@@ -64,7 +65,6 @@ public class ReactiveRoutingFib implements IntentRequestListener { ...@@ -64,7 +65,6 @@ public class ReactiveRoutingFib implements IntentRequestListener {
64 65
65 private final ApplicationId appId; 66 private final ApplicationId appId;
66 private final HostService hostService; 67 private final HostService hostService;
67 - private final RoutingConfigurationService configService;
68 private final InterfaceService interfaceService; 68 private final InterfaceService interfaceService;
69 private final IntentSynchronizationService intentSynchronizer; 69 private final IntentSynchronizationService intentSynchronizer;
70 70
...@@ -75,17 +75,14 @@ public class ReactiveRoutingFib implements IntentRequestListener { ...@@ -75,17 +75,14 @@ public class ReactiveRoutingFib implements IntentRequestListener {
75 * 75 *
76 * @param appId application ID to use to generate intents 76 * @param appId application ID to use to generate intents
77 * @param hostService host service 77 * @param hostService host service
78 - * @param configService routing configuration service
79 * @param interfaceService interface service 78 * @param interfaceService interface service
80 * @param intentSynchronizer intent synchronization service 79 * @param intentSynchronizer intent synchronization service
81 */ 80 */
82 public ReactiveRoutingFib(ApplicationId appId, HostService hostService, 81 public ReactiveRoutingFib(ApplicationId appId, HostService hostService,
83 - RoutingConfigurationService configService,
84 InterfaceService interfaceService, 82 InterfaceService interfaceService,
85 IntentSynchronizationService intentSynchronizer) { 83 IntentSynchronizationService intentSynchronizer) {
86 this.appId = appId; 84 this.appId = appId;
87 this.hostService = hostService; 85 this.hostService = hostService;
88 - this.configService = configService;
89 this.interfaceService = interfaceService; 86 this.interfaceService = interfaceService;
90 this.intentSynchronizer = intentSynchronizer; 87 this.intentSynchronizer = intentSynchronizer;
91 88
...@@ -95,8 +92,6 @@ public class ReactiveRoutingFib implements IntentRequestListener { ...@@ -95,8 +92,6 @@ public class ReactiveRoutingFib implements IntentRequestListener {
95 @Override 92 @Override
96 public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) { 93 public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
97 checkNotNull(hostIpAddress); 94 checkNotNull(hostIpAddress);
98 - Set<ConnectPoint> ingressPoints =
99 - configService.getBgpPeerConnectPoints();
100 95
101 TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); 96 TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
102 97
...@@ -130,6 +125,24 @@ public class ReactiveRoutingFib implements IntentRequestListener { ...@@ -130,6 +125,24 @@ public class ReactiveRoutingFib implements IntentRequestListener {
130 Key key = Key.of(ipPrefix.toString(), appId); 125 Key key = Key.of(ipPrefix.toString(), appId);
131 int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER 126 int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER
132 + PRIORITY_OFFSET; 127 + PRIORITY_OFFSET;
128 +
129 + Set<ConnectPoint> interfaceConnectPoints =
130 + interfaceService.getInterfaces().stream()
131 + .map(intf -> intf.connectPoint()).collect(Collectors.toSet());
132 +
133 + if (interfaceConnectPoints.isEmpty()) {
134 + log.error("The interface connect points are empty!");
135 + return;
136 + }
137 +
138 + Set<ConnectPoint> ingressPoints = new HashSet<>();
139 +
140 + for (ConnectPoint connectPoint : interfaceConnectPoints) {
141 + if (!connectPoint.equals(egressPoint)) {
142 + ingressPoints.add(connectPoint);
143 + }
144 + }
145 +
133 MultiPointToSinglePointIntent intent = 146 MultiPointToSinglePointIntent intent =
134 MultiPointToSinglePointIntent.builder() 147 MultiPointToSinglePointIntent.builder()
135 .appId(appId) 148 .appId(appId)
...@@ -150,7 +163,8 @@ public class ReactiveRoutingFib implements IntentRequestListener { ...@@ -150,7 +163,8 @@ public class ReactiveRoutingFib implements IntentRequestListener {
150 public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix, 163 public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix,
151 IpAddress nextHopIpAddress) { 164 IpAddress nextHopIpAddress) {
152 // Find the attachment point (egress interface) of the next hop 165 // Find the attachment point (egress interface) of the next hop
153 - Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress); 166 + Interface egressInterface =
167 + interfaceService.getMatchingInterface(nextHopIpAddress);
154 if (egressInterface == null) { 168 if (egressInterface == null) {
155 log.warn("No outgoing interface found for {}", 169 log.warn("No outgoing interface found for {}",
156 nextHopIpAddress); 170 nextHopIpAddress);
......
...@@ -15,6 +15,16 @@ ...@@ -15,6 +15,16 @@
15 */ 15 */
16 package org.onosproject.reactive.routing; 16 package org.onosproject.reactive.routing;
17 17
18 +import static com.google.common.base.Preconditions.checkNotNull;
19 +import static org.onlab.packet.Ethernet.TYPE_ARP;
20 +import static org.onlab.packet.Ethernet.TYPE_IPV4;
21 +import static org.onosproject.net.packet.PacketPriority.REACTIVE;
22 +import static org.slf4j.LoggerFactory.getLogger;
23 +
24 +import java.nio.ByteBuffer;
25 +import java.util.Optional;
26 +import java.util.Set;
27 +
18 import org.apache.felix.scr.annotations.Activate; 28 import org.apache.felix.scr.annotations.Activate;
19 import org.apache.felix.scr.annotations.Component; 29 import org.apache.felix.scr.annotations.Component;
20 import org.apache.felix.scr.annotations.Deactivate; 30 import org.apache.felix.scr.annotations.Deactivate;
...@@ -53,16 +63,6 @@ import org.onosproject.routing.RoutingService; ...@@ -53,16 +63,6 @@ import org.onosproject.routing.RoutingService;
53 import org.onosproject.routing.config.RoutingConfigurationService; 63 import org.onosproject.routing.config.RoutingConfigurationService;
54 import org.slf4j.Logger; 64 import org.slf4j.Logger;
55 65
56 -import java.nio.ByteBuffer;
57 -import java.util.Optional;
58 -import java.util.Set;
59 -
60 -import static com.google.common.base.Preconditions.checkNotNull;
61 -import static org.onlab.packet.Ethernet.TYPE_ARP;
62 -import static org.onlab.packet.Ethernet.TYPE_IPV4;
63 -import static org.onosproject.net.packet.PacketPriority.REACTIVE;
64 -import static org.slf4j.LoggerFactory.getLogger;
65 -
66 /** 66 /**
67 * This is reactive routing to handle 3 cases: 67 * This is reactive routing to handle 3 cases:
68 * (1) one host wants to talk to another host, both two hosts are in 68 * (1) one host wants to talk to another host, both two hosts are in
...@@ -107,9 +107,8 @@ public class SdnIpReactiveRouting { ...@@ -107,9 +107,8 @@ public class SdnIpReactiveRouting {
107 @Activate 107 @Activate
108 public void activate() { 108 public void activate() {
109 appId = coreService.registerApplication(APP_NAME); 109 appId = coreService.registerApplication(APP_NAME);
110 -
111 intentRequestListener = new ReactiveRoutingFib(appId, hostService, 110 intentRequestListener = new ReactiveRoutingFib(appId, hostService,
112 - config, interfaceService, intentSynchronizer); 111 + interfaceService, intentSynchronizer);
113 112
114 packetService.addProcessor(processor, PacketProcessor.director(2)); 113 packetService.addProcessor(processor, PacketProcessor.director(2));
115 requestIntercepts(); 114 requestIntercepts();
...@@ -300,23 +299,26 @@ public class SdnIpReactiveRouting { ...@@ -300,23 +299,26 @@ public class SdnIpReactiveRouting {
300 * @return the traffic type which this packet belongs to 299 * @return the traffic type which this packet belongs to
301 */ 300 */
302 private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint, 301 private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint,
303 - IpAddress dstIp) { 302 + IpAddress dstIp) {
304 LocationType dstIpLocationType = getLocationType(dstIp); 303 LocationType dstIpLocationType = getLocationType(dstIp);
305 Optional<Interface> srcInterface = 304 Optional<Interface> srcInterface =
306 interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst(); 305 interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst();
307 - Set<ConnectPoint> ingressPoints = config.getBgpPeerConnectPoints(); 306 +
307 + Set<ConnectPoint> bgpPeerConnectPoints = config.getBgpPeerConnectPoints();
308 +
309 +
308 310
309 switch (dstIpLocationType) { 311 switch (dstIpLocationType) {
310 case INTERNET: 312 case INTERNET:
311 if (srcInterface.isPresent() && 313 if (srcInterface.isPresent() &&
312 - (!ingressPoints.contains(srcConnectPoint))) { 314 + (!bgpPeerConnectPoints.contains(srcConnectPoint))) {
313 return TrafficType.HOST_TO_INTERNET; 315 return TrafficType.HOST_TO_INTERNET;
314 } else { 316 } else {
315 return TrafficType.INTERNET_TO_INTERNET; 317 return TrafficType.INTERNET_TO_INTERNET;
316 } 318 }
317 case LOCAL: 319 case LOCAL:
318 if (srcInterface.isPresent() && 320 if (srcInterface.isPresent() &&
319 - (!ingressPoints.contains(srcConnectPoint))) { 321 + (!bgpPeerConnectPoints.contains(srcConnectPoint))) {
320 return TrafficType.HOST_TO_HOST; 322 return TrafficType.HOST_TO_HOST;
321 } else { 323 } else {
322 // TODO Currently we only consider local public prefixes. 324 // TODO Currently we only consider local public prefixes.
...@@ -394,6 +396,5 @@ public class SdnIpReactiveRouting { ...@@ -394,6 +396,5 @@ public class SdnIpReactiveRouting {
394 packetService.emit(packet); 396 packetService.emit(packet);
395 log.trace("sending packet: {}", packet); 397 log.trace("sending packet: {}", packet);
396 } 398 }
397 -
398 } 399 }
399 400
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.routing.config; 16 package org.onosproject.routing.config;
17 17
18 -import com.fasterxml.jackson.annotation.JsonProperty;
19 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
20 19
21 import java.util.Objects; 20 import java.util.Objects;
...@@ -53,15 +52,14 @@ public class LocalIpPrefixEntry { ...@@ -53,15 +52,14 @@ public class LocalIpPrefixEntry {
53 /** 52 /**
54 * Creates a new IP prefix entry. 53 * Creates a new IP prefix entry.
55 * 54 *
56 - * @param ipPrefix an IP prefix as a String 55 + * @param ipPrefix an IP prefix
57 * @param type an IP prefix type as an IpPrefixType 56 * @param type an IP prefix type as an IpPrefixType
58 * @param gatewayIpAddress IP of the gateway 57 * @param gatewayIpAddress IP of the gateway
59 */ 58 */
60 - public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix, 59 + public LocalIpPrefixEntry(IpPrefix ipPrefix,
61 - @JsonProperty("type") IpPrefixType type, 60 + IpPrefixType type,
62 - @JsonProperty("gatewayIp") IpAddress 61 + IpAddress gatewayIpAddress) {
63 - gatewayIpAddress) { 62 + this.ipPrefix = ipPrefix;
64 - this.ipPrefix = IpPrefix.valueOf(ipPrefix);
65 this.type = type; 63 this.type = type;
66 this.gatewayIpAddress = gatewayIpAddress; 64 this.gatewayIpAddress = gatewayIpAddress;
67 } 65 }
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.routing.config;
18 +
19 +import com.fasterxml.jackson.databind.JsonNode;
20 +import com.google.common.collect.Sets;
21 +
22 +import java.util.Set;
23 +
24 +import org.onlab.packet.IpAddress;
25 +import org.onlab.packet.IpPrefix;
26 +import org.onlab.packet.MacAddress;
27 +import org.onosproject.core.ApplicationId;
28 +import org.onosproject.net.config.Config;
29 +import org.onosproject.routing.config.LocalIpPrefixEntry.IpPrefixType;
30 +import org.slf4j.Logger;
31 +import org.slf4j.LoggerFactory;
32 +
33 +/**
34 + * Configuration object for prefix config.
35 + */
36 +public class ReactiveRoutingConfig extends Config<ApplicationId> {
37 +
38 + private final Logger log = LoggerFactory.getLogger(getClass());
39 +
40 + public static final String IP4LOCALPREFIXES = "ip4LocalPrefixes";
41 + public static final String IP6LOCALPREFIXES = "ip6LocalPrefixes";
42 + public static final String IPPREFIX = "ipPrefix";
43 + public static final String TYPE = "type";
44 + public static final String GATEWAYIP = "gatewayIp";
45 + public static final String VIRTUALGATEWAYMACADDRESS =
46 + "virtualGatewayMacAddress";
47 +
48 + /**
49 + * Gets the set of configured local IPv4 prefixes.
50 + *
51 + * @return IPv4 prefixes
52 + */
53 + public Set<LocalIpPrefixEntry> localIp4PrefixEntries() {
54 + Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
55 +
56 + JsonNode prefixesNode = object.get(IP4LOCALPREFIXES);
57 + if (prefixesNode == null) {
58 + log.warn("ip4LocalPrefixes is null!");
59 + return prefixes;
60 + }
61 +
62 + prefixesNode.forEach(jsonNode -> {
63 +
64 + prefixes.add(new LocalIpPrefixEntry(
65 + IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
66 + IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
67 + IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
68 + });
69 +
70 + return prefixes;
71 + }
72 +
73 + /**
74 + * Gets the set of configured local IPv6 prefixes.
75 + *
76 + * @return IPv6 prefixes
77 + */
78 + public Set<LocalIpPrefixEntry> localIp6PrefixEntries() {
79 + Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
80 +
81 + JsonNode prefixesNode = object.get(IP6LOCALPREFIXES);
82 +
83 + if (prefixesNode == null) {
84 + log.warn("ip6LocalPrefixes is null!");
85 + return prefixes;
86 + }
87 +
88 + prefixesNode.forEach(jsonNode -> {
89 +
90 + prefixes.add(new LocalIpPrefixEntry(
91 + IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
92 + IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
93 + IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
94 + });
95 +
96 + return prefixes;
97 + }
98 +
99 + /**
100 + * Gets of the virtual gateway MAC address.
101 + *
102 + */
103 + public MacAddress virtualGatewayMacAddress() {
104 + return MacAddress.valueOf(
105 + object.get(VIRTUALGATEWAYMACADDRESS).asText());
106 + }
107 +}
...@@ -15,38 +15,23 @@ ...@@ -15,38 +15,23 @@
15 */ 15 */
16 package org.onosproject.routing.config; 16 package org.onosproject.routing.config;
17 17
18 +import java.util.Set;
19 +
18 import org.onlab.packet.IpAddress; 20 import org.onlab.packet.IpAddress;
19 import org.onlab.packet.IpPrefix; 21 import org.onlab.packet.IpPrefix;
20 import org.onlab.packet.MacAddress; 22 import org.onlab.packet.MacAddress;
21 import org.onosproject.net.ConnectPoint; 23 import org.onosproject.net.ConnectPoint;
22 24
23 -import java.util.Map;
24 -import java.util.Set;
25 -
26 /** 25 /**
27 * Provides information about the routing configuration. 26 * Provides information about the routing configuration.
28 */ 27 */
29 public interface RoutingConfigurationService { 28 public interface RoutingConfigurationService {
30 29
31 - /** 30 + String REACTIVE_ROUTING_APP_ID = "org.onosproject.reactive.routing";
32 - * Gets the list of BGP speakers inside the SDN network. 31 +
33 - * 32 + Class<ReactiveRoutingConfig> CONFIG_CLASS = ReactiveRoutingConfig.class;
34 - * @return the map of BGP speaker names to BGP speaker objects
35 - */
36 - Map<String, BgpSpeaker> getBgpSpeakers();
37 33
38 - /**
39 - * Gets the list of configured BGP peers.
40 - *
41 - * @return the map from peer IP address to BgpPeer object
42 - */
43 - Map<IpAddress, BgpPeer> getBgpPeers();
44 34
45 - /**
46 - * Gets the MAC address configured for virtual gateway in SDN network.
47 - *
48 - * @return the MAC address of virtual gateway
49 - */
50 MacAddress getVirtualGatewayMacAddress(); 35 MacAddress getVirtualGatewayMacAddress();
51 36
52 /** 37 /**
...@@ -81,15 +66,5 @@ public interface RoutingConfigurationService { ...@@ -81,15 +66,5 @@ public interface RoutingConfigurationService {
81 */ 66 */
82 Set<ConnectPoint> getBgpPeerConnectPoints(); 67 Set<ConnectPoint> getBgpPeerConnectPoints();
83 68
84 - /**
85 - * Retrieves the interface that matches the given IP address. Matching
86 - * means that the IP address is in one of the interface's assigned subnets.
87 - *
88 - * @param ipAddress IP address to match
89 - * @return the matching interface
90 - * @deprecated in Drake release - use InterfaceService instead
91 - */
92 - @Deprecated
93 - Interface getMatchingInterface(IpAddress ipAddress);
94 69
95 } 70 }
......