Jonathan Hart
Committed by Gerrit Code Review

Add BGP configuration to config subsystem.

Change-Id: I77a5a7922387935f2142c3e74358c5498717a046
...@@ -15,21 +15,23 @@ ...@@ -15,21 +15,23 @@
15 */ 15 */
16 package org.onosproject.routing; 16 package org.onosproject.routing;
17 17
18 -import java.util.Collection;
19 -
20 import org.onlab.packet.IpAddress; 18 import org.onlab.packet.IpAddress;
21 import org.onlab.packet.MacAddress; 19 import org.onlab.packet.MacAddress;
22 import org.onosproject.net.ConnectPoint; 20 import org.onosproject.net.ConnectPoint;
23 21
22 +import java.util.Collection;
23 +
24 /** 24 /**
25 * Provides a way of interacting with the RIB management component. 25 * Provides a way of interacting with the RIB management component.
26 */ 26 */
27 public interface RoutingService { 27 public interface RoutingService {
28 28
29 + String ROUTER_APP_ID = "org.onosproject.router";
30 +
29 /** 31 /**
30 * Specifies the type of an IP address or an IP prefix location. 32 * Specifies the type of an IP address or an IP prefix location.
31 */ 33 */
32 - static enum LocationType { 34 + enum LocationType {
33 /** 35 /**
34 * The location of an IP address or an IP prefix is in local SDN network. 36 * The location of an IP address or an IP prefix is in local SDN network.
35 */ 37 */
......
1 +/*
2 + * Copyright 2015 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.cli;
18 +
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.core.ApplicationId;
22 +import org.onosproject.core.CoreService;
23 +import org.onosproject.incubator.net.config.NetworkConfigService;
24 +import org.onosproject.routing.RoutingService;
25 +import org.onosproject.routing.config.impl.BgpConfig;
26 +
27 +/**
28 + * Lists the BGP peers configured in the system.
29 + */
30 +@Command(scope = "onos", name = "bgp-peers",
31 + description = "Lists all BGP peers")
32 +public class BgpPeersListCommand extends AbstractShellCommand {
33 +
34 + private static final String FORMAT = "%s : %s";
35 +
36 + @Override
37 + protected void execute() {
38 + NetworkConfigService configService = get(NetworkConfigService.class);
39 + CoreService coreService = get(CoreService.class);
40 + ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
41 +
42 + print(appId.toString());
43 +
44 + BgpConfig config = configService.getConfig(appId, BgpConfig.class);
45 +
46 + if (config == null || config.bgpPeers().isEmpty()) {
47 + print("No peers configured");
48 + } else {
49 + config.bgpPeers().forEach(
50 + p -> print(FORMAT, p.ipAddress(), p.connectPoint()));
51 + }
52 + }
53 +}
1 +/*
2 + * Copyright 2015 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.cli;
18 +
19 +import org.apache.karaf.shell.commands.Command;
20 +import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.core.ApplicationId;
22 +import org.onosproject.core.CoreService;
23 +import org.onosproject.incubator.net.config.NetworkConfigService;
24 +import org.onosproject.routing.RoutingService;
25 +import org.onosproject.routing.config.impl.BgpConfig;
26 +
27 +/**
28 + * Lists the BGP speakers configured in the system.
29 + */
30 +@Command(scope = "onos", name = "bgp-speakers",
31 + description = "Lists all BGP speakers")
32 +public class BgpSpeakersListCommand extends AbstractShellCommand {
33 +
34 + private static final String FORMAT = "%s : %s";
35 +
36 + @Override
37 + protected void execute() {
38 + NetworkConfigService configService = get(NetworkConfigService.class);
39 + CoreService coreService = get(CoreService.class);
40 + ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
41 +
42 + print(appId.toString());
43 +
44 + BgpConfig config = configService.getConfig(appId, BgpConfig.class);
45 +
46 + if (config == null || config.bgpSpeakers().isEmpty()) {
47 + print("No speakers configured");
48 + } else {
49 + config.bgpSpeakers().forEach(
50 + s -> print(FORMAT, s.connectPoint(), s.listenAddresses()));
51 + }
52 + }
53 +}
1 +/*
2 + * Copyright 2015 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.impl;
18 +
19 +import com.fasterxml.jackson.databind.JsonNode;
20 +import com.google.common.collect.Sets;
21 +import org.onlab.packet.IpAddress;
22 +import org.onosproject.core.ApplicationId;
23 +import org.onosproject.incubator.net.config.Config;
24 +import org.onosproject.net.ConnectPoint;
25 +
26 +import java.util.Set;
27 +
28 +import static com.google.common.base.Preconditions.checkNotNull;
29 +
30 +/**
31 + * Configuration object for BGP config.
32 + */
33 +public class BgpConfig extends Config<ApplicationId> {
34 +
35 + public static final String PEERS = "bgpPeers";
36 + public static final String SPEAKERS = "bgpSpeakers";
37 + public static final String CONNECT_POINT = "connectPoint";
38 + public static final String IP_ADDRESS = "ipAddress";
39 + public static final String LISTEN_ADDRESSES = "listenAddresses";
40 +
41 + /**
42 + * Gets the set of configured BGP peers.
43 + *
44 + * @return BGP peers
45 + */
46 + public Set<BgpPeerConfig> bgpPeers() {
47 + Set<BgpPeerConfig> peers = Sets.newHashSet();
48 +
49 + JsonNode peersNode = node.get(PEERS);
50 + peersNode.forEach(jsonNode -> peers.add(
51 + new BgpPeerConfig(ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()),
52 + IpAddress.valueOf(jsonNode.path(IP_ADDRESS).asText()))));
53 +
54 + return peers;
55 + }
56 +
57 + /**
58 + * Gets the set of configured BGP speakers.
59 + *
60 + * @return BGP speakers
61 + */
62 + public Set<BgpSpeakerConfig> bgpSpeakers() {
63 + Set<BgpSpeakerConfig> speakers = Sets.newHashSet();
64 +
65 + JsonNode speakersNode = node.get(SPEAKERS);
66 + speakersNode.forEach(jsonNode -> {
67 + Set<IpAddress> listenAddresses = Sets.newHashSet();
68 + jsonNode.path(LISTEN_ADDRESSES).forEach(addressNode ->
69 + listenAddresses.add(IpAddress.valueOf(addressNode.asText()))
70 + );
71 + speakers.add(new BgpSpeakerConfig(
72 + ConnectPoint.deviceConnectPoint(jsonNode.path(CONNECT_POINT).asText()),
73 + listenAddresses));
74 + });
75 +
76 + return speakers;
77 + }
78 +
79 + /**
80 + * Configuration for a BGP peer.
81 + */
82 + public class BgpPeerConfig {
83 + private ConnectPoint connectPoint;
84 + private IpAddress ipAddress;
85 +
86 + public BgpPeerConfig(ConnectPoint connectPoint, IpAddress ipAddress) {
87 + this.connectPoint = connectPoint;
88 + this.ipAddress = ipAddress;
89 + }
90 +
91 + public ConnectPoint connectPoint() {
92 + return connectPoint;
93 + }
94 +
95 + public IpAddress ipAddress() {
96 + return ipAddress;
97 + }
98 +
99 + }
100 +
101 + /**
102 + * Configuration for a BGP speaker.
103 + */
104 + public class BgpSpeakerConfig {
105 +
106 + private ConnectPoint connectPoint;
107 + private Set<IpAddress> listenAddresses;
108 +
109 + public BgpSpeakerConfig(ConnectPoint connectPoint, Set<IpAddress> listenAddresses) {
110 + this.connectPoint = checkNotNull(connectPoint);
111 + this.listenAddresses = checkNotNull(listenAddresses);
112 + }
113 +
114 + public ConnectPoint connectPoint() {
115 + return connectPoint;
116 + }
117 +
118 + public Set<IpAddress> listenAddresses() {
119 + return listenAddresses;
120 + }
121 + }
122 +}
...@@ -19,9 +19,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -19,9 +19,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
19 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 19 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
20 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; 20 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
21 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; 21 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
22 -
23 import org.apache.felix.scr.annotations.Activate; 22 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 23 import org.apache.felix.scr.annotations.Component;
24 +import org.apache.felix.scr.annotations.Deactivate;
25 import org.apache.felix.scr.annotations.Reference; 25 import org.apache.felix.scr.annotations.Reference;
26 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
27 import org.apache.felix.scr.annotations.Service; 27 import org.apache.felix.scr.annotations.Service;
...@@ -30,6 +30,9 @@ import org.onlab.packet.Ip6Address; ...@@ -30,6 +30,9 @@ import org.onlab.packet.Ip6Address;
30 import org.onlab.packet.IpAddress; 30 import org.onlab.packet.IpAddress;
31 import org.onlab.packet.IpPrefix; 31 import org.onlab.packet.IpPrefix;
32 import org.onlab.packet.MacAddress; 32 import org.onlab.packet.MacAddress;
33 +import org.onosproject.incubator.net.config.ConfigFactory;
34 +import org.onosproject.incubator.net.config.NetworkConfigRegistry;
35 +import org.onosproject.incubator.net.config.basics.SubjectFactories;
33 import org.onosproject.net.ConnectPoint; 36 import org.onosproject.net.ConnectPoint;
34 import org.onosproject.net.host.HostService; 37 import org.onosproject.net.host.HostService;
35 import org.onosproject.routing.config.BgpPeer; 38 import org.onosproject.routing.config.BgpPeer;
...@@ -68,6 +71,9 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -68,6 +71,9 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
68 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 71 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
69 protected HostService hostService; 72 protected HostService hostService;
70 73
74 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 + protected NetworkConfigRegistry registry;
76 +
71 private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>(); 77 private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
72 private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>(); 78 private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
73 private Set<IpAddress> gatewayIpAddresses = new HashSet<>(); 79 private Set<IpAddress> gatewayIpAddresses = new HashSet<>();
...@@ -83,13 +89,28 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -83,13 +89,28 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
83 private MacAddress virtualGatewayMacAddress; 89 private MacAddress virtualGatewayMacAddress;
84 private HostToInterfaceAdaptor hostAdaptor; 90 private HostToInterfaceAdaptor hostAdaptor;
85 91
92 + private ConfigFactory configFactory =
93 + new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, BgpConfig.class, "bgp") {
94 + @Override
95 + public BgpConfig createConfig() {
96 + return new BgpConfig();
97 + }
98 + };
99 +
86 @Activate 100 @Activate
87 public void activate() { 101 public void activate() {
102 + registry.registerConfigFactory(configFactory);
88 readConfiguration(); 103 readConfiguration();
89 hostAdaptor = new HostToInterfaceAdaptor(hostService); 104 hostAdaptor = new HostToInterfaceAdaptor(hostService);
90 log.info("Routing configuration service started"); 105 log.info("Routing configuration service started");
91 } 106 }
92 107
108 + @Deactivate
109 + public void deactivate() {
110 + registry.unregisterConfigFactory(configFactory);
111 + log.info("Routing configuration service stopped");
112 + }
113 +
93 /** 114 /**
94 * Reads SDN-IP related information contained in the configuration file. 115 * Reads SDN-IP related information contained in the configuration file.
95 * 116 *
......
...@@ -15,21 +15,14 @@ ...@@ -15,21 +15,14 @@
15 */ 15 */
16 package org.onosproject.routing.impl; 16 package org.onosproject.routing.impl;
17 17
18 -import static com.google.common.base.Preconditions.checkNotNull; 18 +import com.google.common.collect.HashMultimap;
19 - 19 +import com.google.common.collect.Multimaps;
20 -import java.util.Collection; 20 +import com.google.common.collect.SetMultimap;
21 -import java.util.Collections; 21 +import com.google.common.util.concurrent.ThreadFactoryBuilder;
22 -import java.util.Iterator; 22 +import com.googlecode.concurrenttrees.common.KeyValuePair;
23 -import java.util.LinkedList; 23 +import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
24 -import java.util.List; 24 +import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
25 -import java.util.Map; 25 +import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
26 -import java.util.Set;
27 -import java.util.concurrent.BlockingQueue;
28 -import java.util.concurrent.ConcurrentHashMap;
29 -import java.util.concurrent.ExecutorService;
30 -import java.util.concurrent.Executors;
31 -import java.util.concurrent.LinkedBlockingQueue;
32 -
33 import org.apache.felix.scr.annotations.Activate; 26 import org.apache.felix.scr.annotations.Activate;
34 import org.apache.felix.scr.annotations.Component; 27 import org.apache.felix.scr.annotations.Component;
35 import org.apache.felix.scr.annotations.Deactivate; 28 import org.apache.felix.scr.annotations.Deactivate;
...@@ -41,6 +34,7 @@ import org.onlab.packet.Ip6Address; ...@@ -41,6 +34,7 @@ import org.onlab.packet.Ip6Address;
41 import org.onlab.packet.IpAddress; 34 import org.onlab.packet.IpAddress;
42 import org.onlab.packet.IpPrefix; 35 import org.onlab.packet.IpPrefix;
43 import org.onlab.packet.MacAddress; 36 import org.onlab.packet.MacAddress;
37 +import org.onosproject.core.CoreService;
44 import org.onosproject.net.ConnectPoint; 38 import org.onosproject.net.ConnectPoint;
45 import org.onosproject.net.Host; 39 import org.onosproject.net.Host;
46 import org.onosproject.net.host.HostEvent; 40 import org.onosproject.net.host.HostEvent;
...@@ -60,15 +54,20 @@ import org.onosproject.routing.config.RoutingConfigurationService; ...@@ -60,15 +54,20 @@ import org.onosproject.routing.config.RoutingConfigurationService;
60 import org.slf4j.Logger; 54 import org.slf4j.Logger;
61 import org.slf4j.LoggerFactory; 55 import org.slf4j.LoggerFactory;
62 56
63 -import com.google.common.collect.HashMultimap; 57 +import java.util.Collection;
64 -import com.google.common.collect.Multimaps; 58 +import java.util.Collections;
65 -import com.google.common.collect.SetMultimap; 59 +import java.util.Iterator;
66 -import com.google.common.util.concurrent.ThreadFactoryBuilder; 60 +import java.util.LinkedList;
67 -import com.googlecode.concurrenttrees.common.KeyValuePair; 61 +import java.util.List;
68 -import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory; 62 +import java.util.Map;
69 -import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree; 63 +import java.util.Set;
70 -import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree; 64 +import java.util.concurrent.BlockingQueue;
65 +import java.util.concurrent.ConcurrentHashMap;
66 +import java.util.concurrent.ExecutorService;
67 +import java.util.concurrent.Executors;
68 +import java.util.concurrent.LinkedBlockingQueue;
71 69
70 +import static com.google.common.base.Preconditions.checkNotNull;
72 import static org.onosproject.routing.RouteEntry.createBinaryString; 71 import static org.onosproject.routing.RouteEntry.createBinaryString;
73 72
74 /** 73 /**
...@@ -102,6 +101,9 @@ public class Router implements RoutingService { ...@@ -102,6 +101,9 @@ public class Router implements RoutingService {
102 private IntentRequestListener intentRequestListener; 101 private IntentRequestListener intentRequestListener;
103 102
104 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 103 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
104 + protected CoreService coreService;
105 +
106 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
105 protected HostService hostService; 107 protected HostService hostService;
106 108
107 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 109 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -123,6 +125,8 @@ public class Router implements RoutingService { ...@@ -123,6 +125,8 @@ public class Router implements RoutingService {
123 routesWaitingOnArp = Multimaps.synchronizedSetMultimap( 125 routesWaitingOnArp = Multimaps.synchronizedSetMultimap(
124 HashMultimap.<IpAddress, RouteEntry>create()); 126 HashMultimap.<IpAddress, RouteEntry>create());
125 127
128 + coreService.registerApplication(ROUTER_APP_ID);
129 +
126 bgpUpdatesExecutor = Executors.newSingleThreadExecutor( 130 bgpUpdatesExecutor = Executors.newSingleThreadExecutor(
127 new ThreadFactoryBuilder() 131 new ThreadFactoryBuilder()
128 .setNameFormat("sdnip-bgp-updates-%d").build()); 132 .setNameFormat("sdnip-bgp-updates-%d").build());
......
...@@ -31,5 +31,11 @@ ...@@ -31,5 +31,11 @@
31 <command> 31 <command>
32 <action class="org.onosproject.routing.cli.RemoveRouteCommand"/> 32 <action class="org.onosproject.routing.cli.RemoveRouteCommand"/>
33 </command> 33 </command>
34 + <command>
35 + <action class="org.onosproject.routing.cli.BgpPeersListCommand"/>
36 + </command>
37 + <command>
38 + <action class="org.onosproject.routing.cli.BgpSpeakersListCommand"/>
39 + </command>
34 </command-bundle> 40 </command-bundle>
35 </blueprint> 41 </blueprint>
......
...@@ -26,6 +26,7 @@ import org.onlab.packet.IpAddress; ...@@ -26,6 +26,7 @@ import org.onlab.packet.IpAddress;
26 import org.onlab.packet.IpPrefix; 26 import org.onlab.packet.IpPrefix;
27 import org.onlab.packet.MacAddress; 27 import org.onlab.packet.MacAddress;
28 import org.onlab.packet.VlanId; 28 import org.onlab.packet.VlanId;
29 +import org.onosproject.core.CoreService;
29 import org.onosproject.net.ConnectPoint; 30 import org.onosproject.net.ConnectPoint;
30 import org.onosproject.net.DefaultHost; 31 import org.onosproject.net.DefaultHost;
31 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
...@@ -90,6 +91,7 @@ public class RouterAsyncArpTest { ...@@ -90,6 +91,7 @@ public class RouterAsyncArpTest {
90 fibListener = createMock(FibListener.class); 91 fibListener = createMock(FibListener.class);
91 92
92 router = new Router(); 93 router = new Router();
94 + router.coreService = createNiceMock(CoreService.class);
93 router.hostService = hostService; 95 router.hostService = hostService;
94 router.routingConfigurationService = routingConfigurationService; 96 router.routingConfigurationService = routingConfigurationService;
95 router.bgpService = bgpService; 97 router.bgpService = bgpService;
......
...@@ -26,6 +26,7 @@ import org.onlab.packet.IpAddress; ...@@ -26,6 +26,7 @@ import org.onlab.packet.IpAddress;
26 import org.onlab.packet.IpPrefix; 26 import org.onlab.packet.IpPrefix;
27 import org.onlab.packet.MacAddress; 27 import org.onlab.packet.MacAddress;
28 import org.onlab.packet.VlanId; 28 import org.onlab.packet.VlanId;
29 +import org.onosproject.core.CoreService;
29 import org.onosproject.net.ConnectPoint; 30 import org.onosproject.net.ConnectPoint;
30 import org.onosproject.net.DefaultHost; 31 import org.onosproject.net.DefaultHost;
31 import org.onosproject.net.DeviceId; 32 import org.onosproject.net.DeviceId;
...@@ -96,6 +97,7 @@ public class RouterTest { ...@@ -96,6 +97,7 @@ public class RouterTest {
96 fibListener = createMock(FibListener.class); 97 fibListener = createMock(FibListener.class);
97 98
98 router = new Router(); 99 router = new Router();
100 + router.coreService = createNiceMock(CoreService.class);
99 router.hostService = hostService; 101 router.hostService = hostService;
100 router.routingConfigurationService = routingConfigurationService; 102 router.routingConfigurationService = routingConfigurationService;
101 router.bgpService = bgpService; 103 router.bgpService = bgpService;
......