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();
...@@ -304,19 +303,22 @@ public class SdnIpReactiveRouting { ...@@ -304,19 +303,22 @@ public class SdnIpReactiveRouting {
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 }
......
...@@ -15,10 +15,18 @@ ...@@ -15,10 +15,18 @@
15 */ 15 */
16 package org.onosproject.routing.config.impl; 16 package org.onosproject.routing.config.impl;
17 17
18 -import com.fasterxml.jackson.databind.ObjectMapper; 18 +import static org.onosproject.routing.RouteEntry.createBinaryString;
19 +
20 +import com.google.common.collect.ImmutableSet;
19 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 21 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
20 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; 22 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
21 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; 23 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
24 +
25 +import java.util.HashSet;
26 +import java.util.Objects;
27 +import java.util.Set;
28 +import java.util.stream.Collectors;
29 +
22 import org.apache.felix.scr.annotations.Activate; 30 import org.apache.felix.scr.annotations.Activate;
23 import org.apache.felix.scr.annotations.Component; 31 import org.apache.felix.scr.annotations.Component;
24 import org.apache.felix.scr.annotations.Deactivate; 32 import org.apache.felix.scr.annotations.Deactivate;
...@@ -35,33 +43,20 @@ import org.onosproject.core.CoreService; ...@@ -35,33 +43,20 @@ import org.onosproject.core.CoreService;
35 import org.onosproject.incubator.net.intf.InterfaceService; 43 import org.onosproject.incubator.net.intf.InterfaceService;
36 import org.onosproject.net.ConnectPoint; 44 import org.onosproject.net.ConnectPoint;
37 import org.onosproject.net.config.ConfigFactory; 45 import org.onosproject.net.config.ConfigFactory;
46 +import org.onosproject.net.config.NetworkConfigEvent;
47 +import org.onosproject.net.config.NetworkConfigListener;
38 import org.onosproject.net.config.NetworkConfigRegistry; 48 import org.onosproject.net.config.NetworkConfigRegistry;
39 import org.onosproject.net.config.NetworkConfigService; 49 import org.onosproject.net.config.NetworkConfigService;
40 import org.onosproject.net.config.basics.SubjectFactories; 50 import org.onosproject.net.config.basics.SubjectFactories;
41 import org.onosproject.routing.config.BgpConfig; 51 import org.onosproject.routing.config.BgpConfig;
42 -import org.onosproject.routing.config.BgpPeer;
43 -import org.onosproject.routing.config.BgpSpeaker;
44 -import org.onosproject.routing.config.RouterConfig;
45 -import org.onosproject.routing.config.Interface;
46 import org.onosproject.routing.config.LocalIpPrefixEntry; 52 import org.onosproject.routing.config.LocalIpPrefixEntry;
53 +import org.onosproject.routing.config.ReactiveRoutingConfig;
54 +import org.onosproject.routing.config.RouterConfig;
47 import org.onosproject.routing.config.RoutingConfigurationService; 55 import org.onosproject.routing.config.RoutingConfigurationService;
48 import org.onosproject.routing.impl.Router; 56 import org.onosproject.routing.impl.Router;
49 import org.slf4j.Logger; 57 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory; 58 import org.slf4j.LoggerFactory;
51 59
52 -import java.io.File;
53 -import java.io.FileNotFoundException;
54 -import java.io.IOException;
55 -import java.util.Collections;
56 -import java.util.HashSet;
57 -import java.util.Map;
58 -import java.util.Objects;
59 -import java.util.Set;
60 -import java.util.concurrent.ConcurrentHashMap;
61 -import java.util.stream.Collectors;
62 -
63 -import static org.onosproject.routing.RouteEntry.createBinaryString;
64 -
65 /** 60 /**
66 * Implementation of RoutingConfigurationService which reads routing 61 * Implementation of RoutingConfigurationService which reads routing
67 * configuration from a file. 62 * configuration from a file.
...@@ -72,10 +67,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -72,10 +67,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
72 67
73 private final Logger log = LoggerFactory.getLogger(getClass()); 68 private final Logger log = LoggerFactory.getLogger(getClass());
74 69
75 - private static final String CONFIG_DIR = "../config";
76 - private static final String DEFAULT_CONFIG_FILE = "sdnip.json";
77 - private String configFileName = DEFAULT_CONFIG_FILE;
78 -
79 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 protected NetworkConfigRegistry registry; 71 protected NetworkConfigRegistry registry;
81 72
...@@ -88,8 +79,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -88,8 +79,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
88 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 79 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
89 protected InterfaceService interfaceService; 80 protected InterfaceService interfaceService;
90 81
91 - private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
92 - private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
93 private Set<IpAddress> gatewayIpAddresses = new HashSet<>(); 82 private Set<IpAddress> gatewayIpAddresses = new HashSet<>();
94 private Set<ConnectPoint> bgpPeerConnectPoints = new HashSet<>(); 83 private Set<ConnectPoint> bgpPeerConnectPoints = new HashSet<>();
95 84
...@@ -101,6 +90,8 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -101,6 +90,8 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
101 new DefaultByteArrayNodeFactory()); 90 new DefaultByteArrayNodeFactory());
102 91
103 private MacAddress virtualGatewayMacAddress; 92 private MacAddress virtualGatewayMacAddress;
93 + private final InternalNetworkConfigListener configListener =
94 + new InternalNetworkConfigListener();
104 95
105 private ConfigFactory<ApplicationId, BgpConfig> bgpConfigFactory = 96 private ConfigFactory<ApplicationId, BgpConfig> bgpConfigFactory =
106 new ConfigFactory<ApplicationId, BgpConfig>( 97 new ConfigFactory<ApplicationId, BgpConfig>(
...@@ -120,94 +111,74 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -120,94 +111,74 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
120 } 111 }
121 }; 112 };
122 113
114 + private ConfigFactory<ApplicationId, ReactiveRoutingConfig>
115 + reactiveRoutingConfigFactory =
116 + new ConfigFactory<ApplicationId, ReactiveRoutingConfig>(
117 + SubjectFactories.APP_SUBJECT_FACTORY,
118 + ReactiveRoutingConfig.class, "reactiveRouting") {
119 + @Override
120 + public ReactiveRoutingConfig createConfig() {
121 + return new ReactiveRoutingConfig();
122 + }
123 + };
124 +
123 @Activate 125 @Activate
124 public void activate() { 126 public void activate() {
127 + configService.addListener(configListener);
125 registry.registerConfigFactory(bgpConfigFactory); 128 registry.registerConfigFactory(bgpConfigFactory);
126 registry.registerConfigFactory(routerConfigFactory); 129 registry.registerConfigFactory(routerConfigFactory);
127 - readConfiguration(); 130 + registry.registerConfigFactory(reactiveRoutingConfigFactory);
131 + setUpConfiguration();
128 log.info("Routing configuration service started"); 132 log.info("Routing configuration service started");
129 } 133 }
130 134
131 @Deactivate 135 @Deactivate
132 public void deactivate() { 136 public void deactivate() {
133 registry.unregisterConfigFactory(bgpConfigFactory); 137 registry.unregisterConfigFactory(bgpConfigFactory);
134 - registry.registerConfigFactory(routerConfigFactory); 138 + registry.unregisterConfigFactory(routerConfigFactory);
139 + registry.unregisterConfigFactory(reactiveRoutingConfigFactory);
140 + configService.removeListener(configListener);
135 log.info("Routing configuration service stopped"); 141 log.info("Routing configuration service stopped");
136 } 142 }
137 143
138 /** 144 /**
139 - * Reads SDN-IP related information contained in the configuration file. 145 + * Set up reactive routing information from configuration.
140 - *
141 - * @param configFilename the name of the configuration file for the SDN-IP
142 - * application
143 */ 146 */
144 - private void readConfiguration(String configFilename) { 147 + private void setUpConfiguration() {
145 - File configFile = new File(CONFIG_DIR, configFilename); 148 + ReactiveRoutingConfig config = configService.getConfig(
146 - ObjectMapper mapper = new ObjectMapper(); 149 + coreService.registerApplication(RoutingConfigurationService
147 - 150 + .REACTIVE_ROUTING_APP_ID),
148 - try { 151 + RoutingConfigurationService.CONFIG_CLASS);
149 - log.info("Loading config: {}", configFile.getAbsolutePath()); 152 + if (config == null) {
150 - Configuration config = mapper.readValue(configFile, 153 + log.warn("No reactive routing config available!");
151 - Configuration.class); 154 + return;
152 - for (BgpSpeaker speaker : config.getBgpSpeakers()) { 155 + }
153 - bgpSpeakers.put(speaker.name(), speaker); 156 + for (LocalIpPrefixEntry entry : config.localIp4PrefixEntries()) {
154 - } 157 + localPrefixTable4.put(createBinaryString(entry.ipPrefix()), entry);
155 - for (BgpPeer peer : config.getPeers()) {
156 - bgpPeers.put(peer.ipAddress(), peer);
157 - bgpPeerConnectPoints.add(peer.connectPoint());
158 - }
159 -
160 - for (LocalIpPrefixEntry entry : config.getLocalIp4PrefixEntries()) {
161 - localPrefixTable4.put(createBinaryString(entry.ipPrefix()),
162 - entry);
163 gatewayIpAddresses.add(entry.getGatewayIpAddress()); 158 gatewayIpAddresses.add(entry.getGatewayIpAddress());
164 } 159 }
165 - for (LocalIpPrefixEntry entry : config.getLocalIp6PrefixEntries()) { 160 + for (LocalIpPrefixEntry entry : config.localIp6PrefixEntries()) {
166 - localPrefixTable6.put(createBinaryString(entry.ipPrefix()), 161 + localPrefixTable6.put(createBinaryString(entry.ipPrefix()), entry);
167 - entry);
168 gatewayIpAddresses.add(entry.getGatewayIpAddress()); 162 gatewayIpAddresses.add(entry.getGatewayIpAddress());
169 } 163 }
170 164
171 - virtualGatewayMacAddress = config.getVirtualGatewayMacAddress(); 165 + virtualGatewayMacAddress = config.virtualGatewayMacAddress();
172 -
173 - } catch (FileNotFoundException e) {
174 - log.warn("Configuration file not found: {}", configFileName);
175 - } catch (IOException e) {
176 - log.error("Error loading configuration", e);
177 - }
178 - }
179 -
180 - /**
181 - * Instructs the configuration reader to read the configuration from the
182 - * file.
183 - */
184 - public void readConfiguration() {
185 - readConfiguration(configFileName);
186 - }
187 166
188 - @Override 167 + // Setup BGP peer connect points
189 - public Map<String, BgpSpeaker> getBgpSpeakers() {
190 - return Collections.unmodifiableMap(bgpSpeakers);
191 - }
192 -
193 - @Override
194 - public Map<IpAddress, BgpPeer> getBgpPeers() {
195 - return Collections.unmodifiableMap(bgpPeers);
196 - }
197 -
198 - @Override
199 - public Set<ConnectPoint> getBgpPeerConnectPoints() {
200 - // TODO perhaps cache this result in future
201 ApplicationId routerAppId = coreService.getAppId(Router.ROUTER_APP_ID); 168 ApplicationId routerAppId = coreService.getAppId(Router.ROUTER_APP_ID);
202 if (routerAppId == null) { 169 if (routerAppId == null) {
203 - return Collections.emptySet(); 170 + log.info("Router application ID is null!");
171 + return;
204 } 172 }
205 173
206 BgpConfig bgpConfig = configService.getConfig(routerAppId, BgpConfig.class); 174 BgpConfig bgpConfig = configService.getConfig(routerAppId, BgpConfig.class);
175 +
207 if (bgpConfig == null) { 176 if (bgpConfig == null) {
208 - return Collections.emptySet(); 177 + log.info("BGP config is null!");
178 + return;
209 } else { 179 } else {
210 - return bgpConfig.bgpSpeakers().stream() 180 + bgpPeerConnectPoints =
181 + bgpConfig.bgpSpeakers().stream()
211 .flatMap(speaker -> speaker.peers().stream()) 182 .flatMap(speaker -> speaker.peers().stream())
212 .map(peer -> interfaceService.getMatchingInterface(peer)) 183 .map(peer -> interfaceService.getMatchingInterface(peer))
213 .filter(Objects::nonNull) 184 .filter(Objects::nonNull)
...@@ -217,11 +188,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -217,11 +188,6 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
217 } 188 }
218 189
219 @Override 190 @Override
220 - public Interface getMatchingInterface(IpAddress ipAddress) {
221 - return null;
222 - }
223 -
224 - @Override
225 public boolean isIpAddressLocal(IpAddress ipAddress) { 191 public boolean isIpAddressLocal(IpAddress ipAddress) {
226 if (ipAddress.isIp4()) { 192 if (ipAddress.isIp4()) {
227 return localPrefixTable4.getValuesForKeysPrefixing( 193 return localPrefixTable4.getValuesForKeysPrefixing(
...@@ -254,4 +220,31 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -254,4 +220,31 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
254 return virtualGatewayMacAddress; 220 return virtualGatewayMacAddress;
255 } 221 }
256 222
223 + private class InternalNetworkConfigListener implements NetworkConfigListener {
224 +
225 + @Override
226 + public void event(NetworkConfigEvent event) {
227 + switch (event.type()) {
228 + case CONFIG_REGISTERED:
229 + break;
230 + case CONFIG_UNREGISTERED:
231 + break;
232 + case CONFIG_ADDED:
233 + case CONFIG_UPDATED:
234 + case CONFIG_REMOVED:
235 + if (event.configClass() == RoutingConfigurationService.CONFIG_CLASS) {
236 + setUpConfiguration();
237 + }
238 + break;
239 + default:
240 + break;
241 + }
242 + }
243 + }
244 +
245 + @Override
246 + public Set<ConnectPoint> getBgpPeerConnectPoints() {
247 + return ImmutableSet.copyOf(bgpPeerConnectPoints);
248 + }
249 +
257 } 250 }
......