Jonathan Hart
Committed by Gerrit Code Review

Moved ProxyArp, SDN-IP and BgpRouter to use new config format.

The new config format is based on the new network configuration subsystem.

Includes a few config fixes to NetworkConfigLoader and InterfaceManager.

Change-Id: Id7f766736decb7afb6b63c2731d3baba9fc7c764
Showing 30 changed files with 457 additions and 364 deletions
...@@ -49,6 +49,11 @@ ...@@ -49,6 +49,11 @@
49 </dependency> 49 </dependency>
50 50
51 <dependency> 51 <dependency>
52 + <groupId>org.onosproject</groupId>
53 + <artifactId>onos-incubator-api</artifactId>
54 + </dependency>
55 +
56 + <dependency>
52 <groupId>com.google.guava</groupId> 57 <groupId>com.google.guava</groupId>
53 <artifactId>guava</artifactId> 58 <artifactId>guava</artifactId>
54 </dependency> 59 </dependency>
...@@ -64,6 +69,6 @@ ...@@ -64,6 +69,6 @@
64 <artifactId>onos-app-proxyarp</artifactId> 69 <artifactId>onos-app-proxyarp</artifactId>
65 <version>${project.version}</version> 70 <version>${project.version}</version>
66 </dependency> 71 </dependency>
67 - 72 +
68 </dependencies> 73 </dependencies>
69 </project> 74 </project>
......
...@@ -20,7 +20,6 @@ import com.google.common.collect.HashMultimap; ...@@ -20,7 +20,6 @@ import com.google.common.collect.HashMultimap;
20 import com.google.common.collect.Maps; 20 import com.google.common.collect.Maps;
21 import com.google.common.collect.Multimap; 21 import com.google.common.collect.Multimap;
22 import com.google.common.collect.Multiset; 22 import com.google.common.collect.Multiset;
23 -
24 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
25 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
26 import org.apache.felix.scr.annotations.Deactivate; 25 import org.apache.felix.scr.annotations.Deactivate;
...@@ -29,9 +28,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -29,9 +28,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
29 import org.onlab.packet.Ethernet; 28 import org.onlab.packet.Ethernet;
30 import org.onlab.packet.IpAddress; 29 import org.onlab.packet.IpAddress;
31 import org.onlab.packet.IpPrefix; 30 import org.onlab.packet.IpPrefix;
32 -import org.onosproject.config.NetworkConfigService;
33 import org.onosproject.core.ApplicationId; 31 import org.onosproject.core.ApplicationId;
34 import org.onosproject.core.CoreService; 32 import org.onosproject.core.CoreService;
33 +import org.onosproject.net.config.NetworkConfigService;
34 +import org.onosproject.incubator.net.intf.Interface;
35 +import org.onosproject.incubator.net.intf.InterfaceService;
35 import org.onosproject.net.DeviceId; 36 import org.onosproject.net.DeviceId;
36 import org.onosproject.net.device.DeviceEvent; 37 import org.onosproject.net.device.DeviceEvent;
37 import org.onosproject.net.device.DeviceListener; 38 import org.onosproject.net.device.DeviceListener;
...@@ -56,15 +57,14 @@ import org.onosproject.routing.FibEntry; ...@@ -56,15 +57,14 @@ import org.onosproject.routing.FibEntry;
56 import org.onosproject.routing.FibListener; 57 import org.onosproject.routing.FibListener;
57 import org.onosproject.routing.FibUpdate; 58 import org.onosproject.routing.FibUpdate;
58 import org.onosproject.routing.RoutingService; 59 import org.onosproject.routing.RoutingService;
59 -import org.onosproject.routing.config.BgpSpeaker; 60 +import org.onosproject.routing.config.BgpConfig;
60 -import org.onosproject.routing.config.Interface;
61 -import org.onosproject.routing.config.RoutingConfigurationService;
62 import org.slf4j.Logger; 61 import org.slf4j.Logger;
63 import org.slf4j.LoggerFactory; 62 import org.slf4j.LoggerFactory;
64 63
65 import java.util.Collection; 64 import java.util.Collection;
66 import java.util.HashMap; 65 import java.util.HashMap;
67 import java.util.Map; 66 import java.util.Map;
67 +import java.util.Optional;
68 import java.util.Set; 68 import java.util.Set;
69 69
70 /* For test only - will be removed before Cardinal release 70 /* For test only - will be removed before Cardinal release
...@@ -95,7 +95,10 @@ public class BgpRouter { ...@@ -95,7 +95,10 @@ public class BgpRouter {
95 protected RoutingService routingService; 95 protected RoutingService routingService;
96 96
97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 97 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
98 - protected RoutingConfigurationService configService; 98 + protected InterfaceService interfaceService;
99 +
100 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 + protected NetworkConfigService networkConfigService;
99 102
100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 103 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 protected PacketService packetService; 104 protected PacketService packetService;
...@@ -106,14 +109,6 @@ public class BgpRouter { ...@@ -106,14 +109,6 @@ public class BgpRouter {
106 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 109 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
107 protected DeviceService deviceService; 110 protected DeviceService deviceService;
108 111
109 - //
110 - // NOTE: Unused reference - needed to guarantee that the
111 - // NetworkConfigReader component is activated and the network configuration
112 - // is read.
113 - //
114 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
115 - protected NetworkConfigService networkConfigService;
116 -
117 private ApplicationId appId; 112 private ApplicationId appId;
118 113
119 // Reference count for how many times a next hop is used by a route 114 // Reference count for how many times a next hop is used by a route
...@@ -145,14 +140,25 @@ public class BgpRouter { ...@@ -145,14 +140,25 @@ public class BgpRouter {
145 @Activate 140 @Activate
146 protected void activate() { 141 protected void activate() {
147 appId = coreService.registerApplication(BGP_ROUTER_APP); 142 appId = coreService.registerApplication(BGP_ROUTER_APP);
148 - getDeviceConfiguration(configService.getBgpSpeakers()); 143 +
144 + ApplicationId routerAppId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
145 + BgpConfig bgpConfig =
146 + networkConfigService.getConfig(routerAppId, RoutingService.CONFIG_CLASS);
147 +
148 + if (bgpConfig == null) {
149 + log.error("No BgpConfig found");
150 + return;
151 + }
152 +
153 + getDeviceConfiguration(bgpConfig);
149 154
150 connectivityManager = new TunnellingConnectivityManager(appId, 155 connectivityManager = new TunnellingConnectivityManager(appId,
151 - configService, 156 + bgpConfig,
157 + interfaceService,
152 packetService, 158 packetService,
153 flowObjectiveService); 159 flowObjectiveService);
154 160
155 - icmpHandler = new IcmpHandler(configService, packetService); 161 + icmpHandler = new IcmpHandler(interfaceService, packetService);
156 deviceListener = new InnerDeviceListener(); 162 deviceListener = new InnerDeviceListener();
157 routingService.addFibListener(new InternalFibListener()); 163 routingService.addFibListener(new InternalFibListener());
158 routingService.start(); 164 routingService.start();
...@@ -162,7 +168,7 @@ public class BgpRouter { ...@@ -162,7 +168,7 @@ public class BgpRouter {
162 168
163 // Initialize devices now if they are already connected 169 // Initialize devices now if they are already connected
164 if (deviceService.isAvailable(deviceId)) { 170 if (deviceService.isAvailable(deviceId)) {
165 - processIntfFilters(true, configService.getInterfaces()); 171 + processIntfFilters(true, interfaceService.getInterfaces());
166 } 172 }
167 173
168 if (deviceService.isAvailable(ctrlDeviceId)) { 174 if (deviceService.isAvailable(ctrlDeviceId)) {
...@@ -182,21 +188,36 @@ public class BgpRouter { ...@@ -182,21 +188,36 @@ public class BgpRouter {
182 log.info("BgpRouter stopped"); 188 log.info("BgpRouter stopped");
183 } 189 }
184 190
185 - private void getDeviceConfiguration(Map<String, BgpSpeaker> bgps) { 191 + private void getDeviceConfiguration(BgpConfig bgpConfig) {
186 - if (bgps == null || bgps.values().isEmpty()) { 192 + Optional<BgpConfig.BgpSpeakerConfig> bgpSpeaker =
187 - log.error("BGP speakers configuration is missing"); 193 + bgpConfig.bgpSpeakers().stream().findAny();
194 +
195 + if (!bgpSpeaker.isPresent()) {
196 + log.error("BGP speaker configuration not found");
188 return; 197 return;
189 } 198 }
190 - for (BgpSpeaker s : bgps.values()) { 199 +
191 - ctrlDeviceId = s.connectPoint().deviceId(); 200 + ctrlDeviceId = bgpSpeaker.get().connectPoint().deviceId();
192 - if (s.interfaceAddresses() == null || s.interfaceAddresses().isEmpty()) { 201 +
193 - log.error("BGP Router must have interfaces configured"); 202 + Optional<IpAddress> peerAddress =
194 - return; 203 + bgpSpeaker.get().peers().stream().findAny();
195 - } 204 +
196 - deviceId = s.interfaceAddresses().get(0).connectPoint().deviceId(); 205 + if (!peerAddress.isPresent()) {
197 - break; 206 + log.error("BGP speaker must have peers configured");
207 + return;
208 + }
209 +
210 + Interface intf = interfaceService.getMatchingInterface(peerAddress.get());
211 +
212 + if (intf == null) {
213 + log.error("No interface found for peer");
214 + return;
198 } 215 }
199 216
217 + // Assume all peers are configured on the same device - this is required
218 + // by the BGP router
219 + deviceId = intf.connectPoint().deviceId();
220 +
200 log.info("Router dpid: {}", deviceId); 221 log.info("Router dpid: {}", deviceId);
201 log.info("Control Plane OVS dpid: {}", ctrlDeviceId); 222 log.info("Control Plane OVS dpid: {}", ctrlDeviceId);
202 } 223 }
...@@ -283,7 +304,7 @@ public class BgpRouter { ...@@ -283,7 +304,7 @@ public class BgpRouter {
283 if (nextHopsCount.count(entry.nextHopIp()) == 0) { 304 if (nextHopsCount.count(entry.nextHopIp()) == 0) {
284 // There was no next hop in the multiset 305 // There was no next hop in the multiset
285 306
286 - Interface egressIntf = configService.getMatchingInterface(entry.nextHopIp()); 307 + Interface egressIntf = interfaceService.getMatchingInterface(entry.nextHopIp());
287 if (egressIntf == null) { 308 if (egressIntf == null) {
288 log.warn("no egress interface found for {}", entry); 309 log.warn("no egress interface found for {}", entry);
289 return; 310 return;
...@@ -405,7 +426,7 @@ public class BgpRouter { ...@@ -405,7 +426,7 @@ public class BgpRouter {
405 if (deviceService.isAvailable(event.subject().id())) { 426 if (deviceService.isAvailable(event.subject().id())) {
406 log.info("Device connected {}", event.subject().id()); 427 log.info("Device connected {}", event.subject().id());
407 if (event.subject().id().equals(deviceId)) { 428 if (event.subject().id().equals(deviceId)) {
408 - processIntfFilters(true, configService.getInterfaces()); 429 + processIntfFilters(true, interfaceService.getInterfaces());
409 430
410 /* For test only - will be removed before Cardinal release 431 /* For test only - will be removed before Cardinal release
411 delay(1000); 432 delay(1000);
......
...@@ -19,6 +19,8 @@ import org.onlab.packet.Ethernet; ...@@ -19,6 +19,8 @@ import org.onlab.packet.Ethernet;
19 import org.onlab.packet.ICMP; 19 import org.onlab.packet.ICMP;
20 import org.onlab.packet.IPv4; 20 import org.onlab.packet.IPv4;
21 import org.onlab.packet.IpAddress; 21 import org.onlab.packet.IpAddress;
22 +import org.onosproject.incubator.net.intf.Interface;
23 +import org.onosproject.incubator.net.intf.InterfaceService;
22 import org.onosproject.net.ConnectPoint; 24 import org.onosproject.net.ConnectPoint;
23 import org.onosproject.net.flow.DefaultTrafficTreatment; 25 import org.onosproject.net.flow.DefaultTrafficTreatment;
24 import org.onosproject.net.flow.TrafficTreatment; 26 import org.onosproject.net.flow.TrafficTreatment;
...@@ -29,8 +31,6 @@ import org.onosproject.net.packet.OutboundPacket; ...@@ -29,8 +31,6 @@ import org.onosproject.net.packet.OutboundPacket;
29 import org.onosproject.net.packet.PacketContext; 31 import org.onosproject.net.packet.PacketContext;
30 import org.onosproject.net.packet.PacketProcessor; 32 import org.onosproject.net.packet.PacketProcessor;
31 import org.onosproject.net.packet.PacketService; 33 import org.onosproject.net.packet.PacketService;
32 -import org.onosproject.routing.config.Interface;
33 -import org.onosproject.routing.config.RoutingConfigurationService;
34 import org.slf4j.Logger; 34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory; 35 import org.slf4j.LoggerFactory;
36 36
...@@ -41,14 +41,14 @@ public class IcmpHandler { ...@@ -41,14 +41,14 @@ public class IcmpHandler {
41 private static final Logger log = LoggerFactory.getLogger(IcmpHandler.class); 41 private static final Logger log = LoggerFactory.getLogger(IcmpHandler.class);
42 42
43 private final PacketService packetService; 43 private final PacketService packetService;
44 - private final RoutingConfigurationService configService; 44 + private final InterfaceService interfaceService;
45 45
46 private final IcmpProcessor processor = new IcmpProcessor(); 46 private final IcmpProcessor processor = new IcmpProcessor();
47 47
48 48
49 - public IcmpHandler(RoutingConfigurationService configService, 49 + public IcmpHandler(InterfaceService interfaceService,
50 PacketService packetService) { 50 PacketService packetService) {
51 - this.configService = configService; 51 + this.interfaceService = interfaceService;
52 this.packetService = packetService; 52 this.packetService = packetService;
53 } 53 }
54 54
...@@ -67,7 +67,7 @@ public class IcmpHandler { ...@@ -67,7 +67,7 @@ public class IcmpHandler {
67 IPv4 ipv4 = (IPv4) ethernet.getPayload(); 67 IPv4 ipv4 = (IPv4) ethernet.getPayload();
68 ConnectPoint connectPoint = pkt.receivedFrom(); 68 ConnectPoint connectPoint = pkt.receivedFrom();
69 IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress()); 69 IpAddress destIpAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
70 - Interface targetInterface = configService.getMatchingInterface(destIpAddress); 70 + Interface targetInterface = interfaceService.getMatchingInterface(destIpAddress);
71 71
72 if (targetInterface == null) { 72 if (targetInterface == null) {
73 log.trace("No matching interface for {}", destIpAddress); 73 log.trace("No matching interface for {}", destIpAddress);
......
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
15 */ 15 */
16 package org.onosproject.bgprouter; 16 package org.onosproject.bgprouter;
17 17
18 -import static org.slf4j.LoggerFactory.getLogger;
19 -
20 import org.onlab.packet.Ethernet; 18 import org.onlab.packet.Ethernet;
21 import org.onlab.packet.IPv4; 19 import org.onlab.packet.IPv4;
22 import org.onlab.packet.IpAddress; 20 import org.onlab.packet.IpAddress;
23 import org.onlab.packet.TCP; 21 import org.onlab.packet.TCP;
24 import org.onlab.packet.TpPort; 22 import org.onlab.packet.TpPort;
25 import org.onosproject.core.ApplicationId; 23 import org.onosproject.core.ApplicationId;
24 +import org.onosproject.incubator.net.intf.Interface;
25 +import org.onosproject.incubator.net.intf.InterfaceService;
26 import org.onosproject.net.ConnectPoint; 26 import org.onosproject.net.ConnectPoint;
27 import org.onosproject.net.flow.DefaultTrafficSelector; 27 import org.onosproject.net.flow.DefaultTrafficSelector;
28 import org.onosproject.net.flow.DefaultTrafficTreatment; 28 import org.onosproject.net.flow.DefaultTrafficTreatment;
...@@ -36,12 +36,14 @@ import org.onosproject.net.packet.OutboundPacket; ...@@ -36,12 +36,14 @@ import org.onosproject.net.packet.OutboundPacket;
36 import org.onosproject.net.packet.PacketContext; 36 import org.onosproject.net.packet.PacketContext;
37 import org.onosproject.net.packet.PacketProcessor; 37 import org.onosproject.net.packet.PacketProcessor;
38 import org.onosproject.net.packet.PacketService; 38 import org.onosproject.net.packet.PacketService;
39 -import org.onosproject.routing.config.BgpPeer; 39 +import org.onosproject.routing.config.BgpConfig;
40 -import org.onosproject.routing.config.BgpSpeaker;
41 -import org.onosproject.routing.config.InterfaceAddress;
42 -import org.onosproject.routing.config.RoutingConfigurationService;
43 import org.slf4j.Logger; 40 import org.slf4j.Logger;
44 41
42 +import java.util.Optional;
43 +import java.util.Set;
44 +
45 +import static org.slf4j.LoggerFactory.getLogger;
46 +
45 47
46 /** 48 /**
47 * Manages connectivity between peers by tunnelling BGP traffic through 49 * Manages connectivity between peers by tunnelling BGP traffic through
...@@ -53,34 +55,32 @@ public class TunnellingConnectivityManager { ...@@ -53,34 +55,32 @@ public class TunnellingConnectivityManager {
53 private final Logger log = getLogger(getClass()); 55 private final Logger log = getLogger(getClass());
54 private final ApplicationId appId; 56 private final ApplicationId appId;
55 57
56 - private final BgpSpeaker bgpSpeaker; 58 + private final BgpConfig.BgpSpeakerConfig bgpSpeaker;
57 59
58 private final PacketService packetService; 60 private final PacketService packetService;
59 - private final RoutingConfigurationService configService; 61 + private final InterfaceService interfaceService;
60 private final FlowObjectiveService flowObjectiveService; 62 private final FlowObjectiveService flowObjectiveService;
61 63
62 private final BgpProcessor processor = new BgpProcessor(); 64 private final BgpProcessor processor = new BgpProcessor();
63 65
64 public TunnellingConnectivityManager(ApplicationId appId, 66 public TunnellingConnectivityManager(ApplicationId appId,
65 - RoutingConfigurationService configService, 67 + BgpConfig bgpConfig,
68 + InterfaceService interfaceService,
66 PacketService packetService, 69 PacketService packetService,
67 FlowObjectiveService flowObjectiveService) { 70 FlowObjectiveService flowObjectiveService) {
68 this.appId = appId; 71 this.appId = appId;
69 - this.configService = configService; 72 + this.interfaceService = interfaceService;
70 this.packetService = packetService; 73 this.packetService = packetService;
71 this.flowObjectiveService = flowObjectiveService; 74 this.flowObjectiveService = flowObjectiveService;
72 75
73 - BgpSpeaker bgpSpeaker = null; 76 + Optional<BgpConfig.BgpSpeakerConfig> bgpSpeaker =
74 - for (BgpSpeaker speaker : configService.getBgpSpeakers().values()) { 77 + bgpConfig.bgpSpeakers().stream().findAny();
75 - bgpSpeaker = speaker;
76 - break;
77 - }
78 78
79 - if (bgpSpeaker == null) { 79 + if (!bgpSpeaker.isPresent()) {
80 throw new IllegalArgumentException("Must have at least one BGP speaker configured"); 80 throw new IllegalArgumentException("Must have at least one BGP speaker configured");
81 } 81 }
82 82
83 - this.bgpSpeaker = bgpSpeaker; 83 + this.bgpSpeaker = bgpSpeaker.get();
84 84
85 } 85 }
86 86
...@@ -149,14 +149,19 @@ public class TunnellingConnectivityManager { ...@@ -149,14 +149,19 @@ public class TunnellingConnectivityManager {
149 IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress()); 149 IpAddress dstAddress = IpAddress.valueOf(ipv4.getDestinationAddress());
150 150
151 if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) { 151 if (context.inPacket().receivedFrom().equals(bgpSpeaker.connectPoint())) {
152 - BgpPeer peer = configService.getBgpPeers().get(dstAddress); 152 + if (bgpSpeaker.peers().contains(dstAddress)) {
153 - if (peer != null) { 153 + Interface intf = interfaceService.getMatchingInterface(dstAddress);
154 - outputPort = peer.connectPoint(); 154 + if (intf != null) {
155 + outputPort = intf.connectPoint();
156 + }
155 } 157 }
156 - } 158 + } else {
157 - for (InterfaceAddress addr : bgpSpeaker.interfaceAddresses()) { 159 + Set<Interface> interfaces =
158 - if (addr.ipAddress().equals(dstAddress) && !context.inPacket() 160 + interfaceService.getInterfacesByPort(context.inPacket().receivedFrom());
159 - .receivedFrom().equals(bgpSpeaker.connectPoint())) { 161 +
162 + if (interfaces.stream()
163 + .flatMap(intf -> intf.ipAddresses().stream())
164 + .anyMatch(ia -> ia.ipAddress().equals(dstAddress))) {
160 outputPort = bgpSpeaker.connectPoint(); 165 outputPort = bgpSpeaker.connectPoint();
161 } 166 }
162 } 167 }
......
...@@ -37,6 +37,11 @@ ...@@ -37,6 +37,11 @@
37 </dependency> 37 </dependency>
38 38
39 <dependency> 39 <dependency>
40 + <groupId>org.onosproject</groupId>
41 + <artifactId>onos-incubator-api</artifactId>
42 + </dependency>
43 +
44 + <dependency>
40 <groupId>com.fasterxml.jackson.core</groupId> 45 <groupId>com.fasterxml.jackson.core</groupId>
41 <artifactId>jackson-annotations</artifactId> 46 <artifactId>jackson-annotations</artifactId>
42 </dependency> 47 </dependency>
......
...@@ -18,6 +18,7 @@ package org.onosproject.routing; ...@@ -18,6 +18,7 @@ package org.onosproject.routing;
18 import org.onlab.packet.IpAddress; 18 import org.onlab.packet.IpAddress;
19 import org.onlab.packet.MacAddress; 19 import org.onlab.packet.MacAddress;
20 import org.onosproject.net.ConnectPoint; 20 import org.onosproject.net.ConnectPoint;
21 +import org.onosproject.routing.config.BgpConfig;
21 22
22 import java.util.Collection; 23 import java.util.Collection;
23 24
...@@ -28,6 +29,8 @@ public interface RoutingService { ...@@ -28,6 +29,8 @@ public interface RoutingService {
28 29
29 String ROUTER_APP_ID = "org.onosproject.router"; 30 String ROUTER_APP_ID = "org.onosproject.router";
30 31
32 + Class<BgpConfig> CONFIG_CLASS = BgpConfig.class;
33 +
31 /** 34 /**
32 * Specifies the type of an IP address or an IP prefix location. 35 * Specifies the type of an IP address or an IP prefix location.
33 */ 36 */
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17 -package org.onosproject.routing.config.impl; 17 +package org.onosproject.routing.config;
18 18
19 import com.fasterxml.jackson.databind.JsonNode; 19 import com.fasterxml.jackson.databind.JsonNode;
20 import com.google.common.collect.Sets; 20 import com.google.common.collect.Sets;
...@@ -32,27 +32,11 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -32,27 +32,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
32 */ 32 */
33 public class BgpConfig extends Config<ApplicationId> { 33 public class BgpConfig extends Config<ApplicationId> {
34 34
35 - public static final String PEERS = "bgpPeers";
36 public static final String SPEAKERS = "bgpSpeakers"; 35 public static final String SPEAKERS = "bgpSpeakers";
37 public static final String CONNECT_POINT = "connectPoint"; 36 public static final String CONNECT_POINT = "connectPoint";
38 - public static final String IP_ADDRESS = "ipAddress"; 37 + public static final String PEERS = "peers";
39 - public static final String LISTEN_ADDRESSES = "listenAddresses";
40 38
41 - /** 39 + // TODO add methods for updating config
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 40
57 /** 41 /**
58 * Gets the set of configured BGP speakers. 42 * Gets the set of configured BGP speakers.
...@@ -65,7 +49,7 @@ public class BgpConfig extends Config<ApplicationId> { ...@@ -65,7 +49,7 @@ public class BgpConfig extends Config<ApplicationId> {
65 JsonNode speakersNode = node.get(SPEAKERS); 49 JsonNode speakersNode = node.get(SPEAKERS);
66 speakersNode.forEach(jsonNode -> { 50 speakersNode.forEach(jsonNode -> {
67 Set<IpAddress> listenAddresses = Sets.newHashSet(); 51 Set<IpAddress> listenAddresses = Sets.newHashSet();
68 - jsonNode.path(LISTEN_ADDRESSES).forEach(addressNode -> 52 + jsonNode.path(PEERS).forEach(addressNode ->
69 listenAddresses.add(IpAddress.valueOf(addressNode.asText())) 53 listenAddresses.add(IpAddress.valueOf(addressNode.asText()))
70 ); 54 );
71 speakers.add(new BgpSpeakerConfig( 55 speakers.add(new BgpSpeakerConfig(
...@@ -77,46 +61,24 @@ public class BgpConfig extends Config<ApplicationId> { ...@@ -77,46 +61,24 @@ public class BgpConfig extends Config<ApplicationId> {
77 } 61 }
78 62
79 /** 63 /**
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. 64 * Configuration for a BGP speaker.
103 */ 65 */
104 - public class BgpSpeakerConfig { 66 + public static class BgpSpeakerConfig {
105 67
106 private ConnectPoint connectPoint; 68 private ConnectPoint connectPoint;
107 - private Set<IpAddress> listenAddresses; 69 + private Set<IpAddress> peers;
108 70
109 - public BgpSpeakerConfig(ConnectPoint connectPoint, Set<IpAddress> listenAddresses) { 71 + public BgpSpeakerConfig(ConnectPoint connectPoint, Set<IpAddress> peers) {
110 this.connectPoint = checkNotNull(connectPoint); 72 this.connectPoint = checkNotNull(connectPoint);
111 - this.listenAddresses = checkNotNull(listenAddresses); 73 + this.peers = checkNotNull(peers);
112 } 74 }
113 75
114 public ConnectPoint connectPoint() { 76 public ConnectPoint connectPoint() {
115 return connectPoint; 77 return connectPoint;
116 } 78 }
117 79
118 - public Set<IpAddress> listenAddresses() { 80 + public Set<IpAddress> peers() {
119 - return listenAddresses; 81 + return peers;
120 } 82 }
121 } 83 }
122 } 84 }
......
...@@ -77,7 +77,9 @@ public interface RoutingConfigurationService { ...@@ -77,7 +77,9 @@ public interface RoutingConfigurationService {
77 * Retrieves the entire set of interfaces in the network. 77 * Retrieves the entire set of interfaces in the network.
78 * 78 *
79 * @return the set of interfaces 79 * @return the set of interfaces
80 + * @deprecated in Drake release - use InterfaceService instead
80 */ 81 */
82 + @Deprecated
81 Set<Interface> getInterfaces(); 83 Set<Interface> getInterfaces();
82 84
83 /** 85 /**
...@@ -86,7 +88,7 @@ public interface RoutingConfigurationService { ...@@ -86,7 +88,7 @@ public interface RoutingConfigurationService {
86 * 88 *
87 * @return the set of connect points connected to BGP peers 89 * @return the set of connect points connected to BGP peers
88 */ 90 */
89 - public Set<ConnectPoint> getBgpPeerConnectPoints(); 91 + Set<ConnectPoint> getBgpPeerConnectPoints();
90 92
91 /** 93 /**
92 * Retrieves the interface associated with the given connect point. 94 * Retrieves the interface associated with the given connect point.
...@@ -94,7 +96,9 @@ public interface RoutingConfigurationService { ...@@ -94,7 +96,9 @@ public interface RoutingConfigurationService {
94 * @param connectPoint the connect point to retrieve interface information 96 * @param connectPoint the connect point to retrieve interface information
95 * for 97 * for
96 * @return the interface 98 * @return the interface
99 + * @deprecated in Drake release - use InterfaceService instead
97 */ 100 */
101 + @Deprecated
98 Interface getInterface(ConnectPoint connectPoint); 102 Interface getInterface(ConnectPoint connectPoint);
99 103
100 /** 104 /**
...@@ -102,7 +106,9 @@ public interface RoutingConfigurationService { ...@@ -102,7 +106,9 @@ public interface RoutingConfigurationService {
102 * 106 *
103 * @param ip IP address of the interface 107 * @param ip IP address of the interface
104 * @return the interface 108 * @return the interface
109 + * @deprecated in Drake release - use InterfaceService instead
105 */ 110 */
111 + @Deprecated
106 Interface getInterface(IpAddress ip); 112 Interface getInterface(IpAddress ip);
107 113
108 /** 114 /**
...@@ -111,7 +117,9 @@ public interface RoutingConfigurationService { ...@@ -111,7 +117,9 @@ public interface RoutingConfigurationService {
111 * 117 *
112 * @param ipAddress IP address to match 118 * @param ipAddress IP address to match
113 * @return the matching interface 119 * @return the matching interface
120 + * @deprecated in Drake release - use InterfaceService instead
114 */ 121 */
122 + @Deprecated
115 Interface getMatchingInterface(IpAddress ipAddress); 123 Interface getMatchingInterface(IpAddress ipAddress);
116 124
117 } 125 }
......
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.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 -}
...@@ -22,7 +22,7 @@ import org.onosproject.core.ApplicationId; ...@@ -22,7 +22,7 @@ import org.onosproject.core.ApplicationId;
22 import org.onosproject.core.CoreService; 22 import org.onosproject.core.CoreService;
23 import org.onosproject.net.config.NetworkConfigService; 23 import org.onosproject.net.config.NetworkConfigService;
24 import org.onosproject.routing.RoutingService; 24 import org.onosproject.routing.RoutingService;
25 -import org.onosproject.routing.config.impl.BgpConfig; 25 +import org.onosproject.routing.config.BgpConfig;
26 26
27 /** 27 /**
28 * Lists the BGP speakers configured in the system. 28 * Lists the BGP speakers configured in the system.
...@@ -47,7 +47,7 @@ public class BgpSpeakersListCommand extends AbstractShellCommand { ...@@ -47,7 +47,7 @@ public class BgpSpeakersListCommand extends AbstractShellCommand {
47 print("No speakers configured"); 47 print("No speakers configured");
48 } else { 48 } else {
49 config.bgpSpeakers().forEach( 49 config.bgpSpeakers().forEach(
50 - s -> print(FORMAT, s.connectPoint(), s.listenAddresses())); 50 + s -> print(FORMAT, s.connectPoint(), s.peers()));
51 } 51 }
52 } 52 }
53 } 53 }
......
...@@ -30,16 +30,22 @@ import org.onlab.packet.Ip6Address; ...@@ -30,16 +30,22 @@ 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.core.ApplicationId;
34 +import org.onosproject.core.CoreService;
35 +import org.onosproject.incubator.net.intf.InterfaceService;
36 +import org.onosproject.net.ConnectPoint;
33 import org.onosproject.net.config.ConfigFactory; 37 import org.onosproject.net.config.ConfigFactory;
34 import org.onosproject.net.config.NetworkConfigRegistry; 38 import org.onosproject.net.config.NetworkConfigRegistry;
39 +import org.onosproject.net.config.NetworkConfigService;
35 import org.onosproject.net.config.basics.SubjectFactories; 40 import org.onosproject.net.config.basics.SubjectFactories;
36 -import org.onosproject.net.ConnectPoint;
37 import org.onosproject.net.host.HostService; 41 import org.onosproject.net.host.HostService;
42 +import org.onosproject.routing.config.BgpConfig;
38 import org.onosproject.routing.config.BgpPeer; 43 import org.onosproject.routing.config.BgpPeer;
39 import org.onosproject.routing.config.BgpSpeaker; 44 import org.onosproject.routing.config.BgpSpeaker;
40 import org.onosproject.routing.config.Interface; 45 import org.onosproject.routing.config.Interface;
41 import org.onosproject.routing.config.LocalIpPrefixEntry; 46 import org.onosproject.routing.config.LocalIpPrefixEntry;
42 import org.onosproject.routing.config.RoutingConfigurationService; 47 import org.onosproject.routing.config.RoutingConfigurationService;
48 +import org.onosproject.routing.impl.Router;
43 import org.slf4j.Logger; 49 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory; 50 import org.slf4j.LoggerFactory;
45 51
...@@ -51,6 +57,7 @@ import java.util.HashSet; ...@@ -51,6 +57,7 @@ import java.util.HashSet;
51 import java.util.Map; 57 import java.util.Map;
52 import java.util.Set; 58 import java.util.Set;
53 import java.util.concurrent.ConcurrentHashMap; 59 import java.util.concurrent.ConcurrentHashMap;
60 +import java.util.stream.Collectors;
54 61
55 import static org.onosproject.routing.RouteEntry.createBinaryString; 62 import static org.onosproject.routing.RouteEntry.createBinaryString;
56 63
...@@ -74,6 +81,15 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -74,6 +81,15 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 81 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 protected NetworkConfigRegistry registry; 82 protected NetworkConfigRegistry registry;
76 83
84 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
85 + protected NetworkConfigService configService;
86 +
87 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
88 + protected CoreService coreService;
89 +
90 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 + protected InterfaceService interfaceService;
92 +
77 private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>(); 93 private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
78 private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>(); 94 private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
79 private Set<IpAddress> gatewayIpAddresses = new HashSet<>(); 95 private Set<IpAddress> gatewayIpAddresses = new HashSet<>();
...@@ -178,7 +194,20 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService { ...@@ -178,7 +194,20 @@ public class RoutingConfigurationImpl implements RoutingConfigurationService {
178 194
179 @Override 195 @Override
180 public Set<ConnectPoint> getBgpPeerConnectPoints() { 196 public Set<ConnectPoint> getBgpPeerConnectPoints() {
181 - return Collections.unmodifiableSet(bgpPeerConnectPoints); 197 + // TODO perhaps cache this result in future
198 + ApplicationId routerAppId = coreService.getAppId(Router.ROUTER_APP_ID);
199 + if (routerAppId == null) {
200 + return Collections.emptySet();
201 + }
202 +
203 + BgpConfig bgpConfig = configService.getConfig(routerAppId, BgpConfig.class);
204 +
205 + return bgpConfig.bgpSpeakers().stream()
206 + .flatMap(speaker -> speaker.peers().stream())
207 + .map(peer -> interfaceService.getMatchingInterface(peer))
208 + .filter(intf -> intf != null)
209 + .map(intf -> intf.connectPoint())
210 + .collect(Collectors.toSet());
182 } 211 }
183 212
184 @Override 213 @Override
......
...@@ -35,6 +35,8 @@ import org.onlab.packet.IpAddress; ...@@ -35,6 +35,8 @@ import org.onlab.packet.IpAddress;
35 import org.onlab.packet.IpPrefix; 35 import org.onlab.packet.IpPrefix;
36 import org.onlab.packet.MacAddress; 36 import org.onlab.packet.MacAddress;
37 import org.onosproject.core.CoreService; 37 import org.onosproject.core.CoreService;
38 +import org.onosproject.incubator.net.intf.Interface;
39 +import org.onosproject.incubator.net.intf.InterfaceService;
38 import org.onosproject.net.ConnectPoint; 40 import org.onosproject.net.ConnectPoint;
39 import org.onosproject.net.Host; 41 import org.onosproject.net.Host;
40 import org.onosproject.net.host.HostEvent; 42 import org.onosproject.net.host.HostEvent;
...@@ -49,7 +51,6 @@ import org.onosproject.routing.RouteEntry; ...@@ -49,7 +51,6 @@ import org.onosproject.routing.RouteEntry;
49 import org.onosproject.routing.RouteListener; 51 import org.onosproject.routing.RouteListener;
50 import org.onosproject.routing.RouteUpdate; 52 import org.onosproject.routing.RouteUpdate;
51 import org.onosproject.routing.RoutingService; 53 import org.onosproject.routing.RoutingService;
52 -import org.onosproject.routing.config.Interface;
53 import org.onosproject.routing.config.RoutingConfigurationService; 54 import org.onosproject.routing.config.RoutingConfigurationService;
54 import org.slf4j.Logger; 55 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory; 56 import org.slf4j.LoggerFactory;
...@@ -60,6 +61,7 @@ import java.util.Iterator; ...@@ -60,6 +61,7 @@ import java.util.Iterator;
60 import java.util.LinkedList; 61 import java.util.LinkedList;
61 import java.util.List; 62 import java.util.List;
62 import java.util.Map; 63 import java.util.Map;
64 +import java.util.Optional;
63 import java.util.Set; 65 import java.util.Set;
64 import java.util.concurrent.BlockingQueue; 66 import java.util.concurrent.BlockingQueue;
65 import java.util.concurrent.ConcurrentHashMap; 67 import java.util.concurrent.ConcurrentHashMap;
...@@ -110,6 +112,9 @@ public class Router implements RoutingService { ...@@ -110,6 +112,9 @@ public class Router implements RoutingService {
110 protected BgpService bgpService; 112 protected BgpService bgpService;
111 113
112 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 114 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
115 + protected InterfaceService interfaceService;
116 +
117 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
113 protected RoutingConfigurationService routingConfigurationService; 118 protected RoutingConfigurationService routingConfigurationService;
114 119
115 private ExecutorService bgpUpdatesExecutor; 120 private ExecutorService bgpUpdatesExecutor;
...@@ -603,8 +608,7 @@ public class Router implements RoutingService { ...@@ -603,8 +608,7 @@ public class Router implements RoutingService {
603 RouteEntry routeEntry = getLongestMatchableRouteEntry(dstIpAddress); 608 RouteEntry routeEntry = getLongestMatchableRouteEntry(dstIpAddress);
604 if (routeEntry != null) { 609 if (routeEntry != null) {
605 nextHopIpAddress = routeEntry.nextHop(); 610 nextHopIpAddress = routeEntry.nextHop();
606 - Interface it = routingConfigurationService 611 + Interface it = interfaceService.getMatchingInterface(nextHopIpAddress);
607 - .getMatchingInterface(nextHopIpAddress);
608 if (it != null) { 612 if (it != null) {
609 return it.connectPoint(); 613 return it.connectPoint();
610 } else { 614 } else {
...@@ -700,18 +704,18 @@ public class Router implements RoutingService { ...@@ -700,18 +704,18 @@ public class Router implements RoutingService {
700 private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint, 704 private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint,
701 IpAddress dstIp) { 705 IpAddress dstIp) {
702 LocationType dstIpLocationType = getLocationType(dstIp); 706 LocationType dstIpLocationType = getLocationType(dstIp);
703 - Interface srcInterface = 707 + Optional<Interface> srcInterface =
704 - routingConfigurationService.getInterface(srcConnectPoint); 708 + interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst();
705 709
706 switch (dstIpLocationType) { 710 switch (dstIpLocationType) {
707 case INTERNET: 711 case INTERNET:
708 - if (srcInterface == null) { 712 + if (!srcInterface.isPresent()) {
709 return TrafficType.HOST_TO_INTERNET; 713 return TrafficType.HOST_TO_INTERNET;
710 } else { 714 } else {
711 return TrafficType.INTERNET_TO_INTERNET; 715 return TrafficType.INTERNET_TO_INTERNET;
712 } 716 }
713 case LOCAL: 717 case LOCAL:
714 - if (srcInterface == null) { 718 + if (!srcInterface.isPresent()) {
715 return TrafficType.HOST_TO_HOST; 719 return TrafficType.HOST_TO_HOST;
716 } else { 720 } else {
717 // TODO Currently we only consider local public prefixes. 721 // TODO Currently we only consider local public prefixes.
......
...@@ -32,9 +32,6 @@ ...@@ -32,9 +32,6 @@
32 <action class="org.onosproject.routing.cli.RemoveRouteCommand"/> 32 <action class="org.onosproject.routing.cli.RemoveRouteCommand"/>
33 </command> 33 </command>
34 <command> 34 <command>
35 - <action class="org.onosproject.routing.cli.BgpPeersListCommand"/>
36 - </command>
37 - <command>
38 <action class="org.onosproject.routing.cli.BgpSpeakersListCommand"/> 35 <action class="org.onosproject.routing.cli.BgpSpeakersListCommand"/>
39 </command> 36 </command>
40 </command-bundle> 37 </command-bundle>
......
...@@ -22,8 +22,5 @@ ...@@ -22,8 +22,5 @@
22 <bundle>mvn:${project.groupId}/onos-app-sdnip/${project.version}</bundle> 22 <bundle>mvn:${project.groupId}/onos-app-sdnip/${project.version}</bundle>
23 <bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle> 23 <bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle>
24 <bundle>mvn:${project.groupId}/onos-app-routing/${project.version}</bundle> 24 <bundle>mvn:${project.groupId}/onos-app-routing/${project.version}</bundle>
25 - <!-- NOTE: Temporarily the sdnip app will bring the config bundle
26 - until we can specify dependencies between applictions -->
27 - <bundle>mvn:${project.groupId}/onos-app-config/${project.version}</bundle>
28 </feature> 25 </feature>
29 </features> 26 </features>
......
...@@ -23,6 +23,8 @@ import org.onlab.packet.IpPrefix; ...@@ -23,6 +23,8 @@ import org.onlab.packet.IpPrefix;
23 import org.onlab.packet.MacAddress; 23 import org.onlab.packet.MacAddress;
24 import org.onlab.packet.VlanId; 24 import org.onlab.packet.VlanId;
25 import org.onosproject.core.ApplicationId; 25 import org.onosproject.core.ApplicationId;
26 +import org.onosproject.incubator.net.intf.Interface;
27 +import org.onosproject.incubator.net.intf.InterfaceService;
26 import org.onosproject.net.ConnectPoint; 28 import org.onosproject.net.ConnectPoint;
27 import org.onosproject.net.Host; 29 import org.onosproject.net.Host;
28 import org.onosproject.net.flow.DefaultTrafficSelector; 30 import org.onosproject.net.flow.DefaultTrafficSelector;
...@@ -43,8 +45,6 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint; ...@@ -43,8 +45,6 @@ import org.onosproject.net.intent.constraint.PartialFailureConstraint;
43 import org.onosproject.routing.FibListener; 45 import org.onosproject.routing.FibListener;
44 import org.onosproject.routing.FibUpdate; 46 import org.onosproject.routing.FibUpdate;
45 import org.onosproject.routing.IntentRequestListener; 47 import org.onosproject.routing.IntentRequestListener;
46 -import org.onosproject.routing.config.BgpPeer;
47 -import org.onosproject.routing.config.Interface;
48 import org.onosproject.routing.config.RoutingConfigurationService; 48 import org.onosproject.routing.config.RoutingConfigurationService;
49 import org.slf4j.Logger; 49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory; 50 import org.slf4j.LoggerFactory;
...@@ -81,6 +81,7 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener { ...@@ -81,6 +81,7 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener {
81 private final ApplicationId appId; 81 private final ApplicationId appId;
82 private final IntentService intentService; 82 private final IntentService intentService;
83 private final HostService hostService; 83 private final HostService hostService;
84 + private final InterfaceService interfaceService;
84 private final Map<IntentKey, PointToPointIntent> peerIntents; 85 private final Map<IntentKey, PointToPointIntent> peerIntents;
85 private final Map<IpPrefix, MultiPointToSinglePointIntent> routeIntents; 86 private final Map<IpPrefix, MultiPointToSinglePointIntent> routeIntents;
86 87
...@@ -104,10 +105,12 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener { ...@@ -104,10 +105,12 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener {
104 */ 105 */
105 IntentSynchronizer(ApplicationId appId, IntentService intentService, 106 IntentSynchronizer(ApplicationId appId, IntentService intentService,
106 HostService hostService, 107 HostService hostService,
107 - RoutingConfigurationService configService) { 108 + RoutingConfigurationService configService,
109 + InterfaceService interfaceService) {
108 this.appId = appId; 110 this.appId = appId;
109 this.intentService = intentService; 111 this.intentService = intentService;
110 this.hostService = hostService; 112 this.hostService = hostService;
113 + this.interfaceService = interfaceService;
111 peerIntents = new ConcurrentHashMap<>(); 114 peerIntents = new ConcurrentHashMap<>();
112 routeIntents = new ConcurrentHashMap<>(); 115 routeIntents = new ConcurrentHashMap<>();
113 116
...@@ -122,12 +125,7 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener { ...@@ -122,12 +125,7 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener {
122 * Starts the synchronizer. 125 * Starts the synchronizer.
123 */ 126 */
124 public void start() { 127 public void start() {
125 - bgpIntentsSynchronizerExecutor.execute(new Runnable() { 128 + bgpIntentsSynchronizerExecutor.execute(this::doIntentSynchronizationThread);
126 - @Override
127 - public void run() {
128 - doIntentSynchronizationThread();
129 - }
130 - });
131 } 129 }
132 130
133 /** 131 /**
...@@ -313,24 +311,11 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener { ...@@ -313,24 +311,11 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener {
313 MacAddress nextHopMacAddress) { 311 MacAddress nextHopMacAddress) {
314 312
315 // Find the attachment point (egress interface) of the next hop 313 // Find the attachment point (egress interface) of the next hop
316 - Interface egressInterface; 314 + Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
317 - if (configService.getBgpPeers().containsKey(nextHopIpAddress)) { 315 + if (egressInterface == null) {
318 - // Route to a peer 316 + log.warn("No outgoing interface found for {}",
319 - log.debug("Route to peer {}", nextHopIpAddress); 317 + nextHopIpAddress);
320 - BgpPeer peer = 318 + return null;
321 - configService.getBgpPeers().get(nextHopIpAddress);
322 - egressInterface =
323 - configService.getInterface(peer.connectPoint());
324 - } else {
325 - // Route to non-peer
326 - log.debug("Route to non-peer {}", nextHopIpAddress);
327 - egressInterface =
328 - configService.getMatchingInterface(nextHopIpAddress);
329 - if (egressInterface == null) {
330 - log.warn("No outgoing interface found for {}",
331 - nextHopIpAddress);
332 - return null;
333 - }
334 } 319 }
335 320
336 // 321 //
...@@ -341,7 +326,8 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener { ...@@ -341,7 +326,8 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener {
341 log.debug("Generating intent for prefix {}, next hop mac {}", 326 log.debug("Generating intent for prefix {}, next hop mac {}",
342 prefix, nextHopMacAddress); 327 prefix, nextHopMacAddress);
343 328
344 - for (Interface intf : configService.getInterfaces()) { 329 + for (Interface intf : interfaceService.getInterfaces()) {
330 + // TODO this should be only peering interfaces
345 if (!intf.connectPoint().equals(egressInterface.connectPoint())) { 331 if (!intf.connectPoint().equals(egressInterface.connectPoint())) {
346 ConnectPoint srcPort = intf.connectPoint(); 332 ConnectPoint srcPort = intf.connectPoint();
347 ingressPorts.add(srcPort); 333 ingressPorts.add(srcPort);
......
...@@ -26,9 +26,10 @@ import org.onosproject.cluster.ControllerNode; ...@@ -26,9 +26,10 @@ import org.onosproject.cluster.ControllerNode;
26 import org.onosproject.cluster.LeadershipEvent; 26 import org.onosproject.cluster.LeadershipEvent;
27 import org.onosproject.cluster.LeadershipEventListener; 27 import org.onosproject.cluster.LeadershipEventListener;
28 import org.onosproject.cluster.LeadershipService; 28 import org.onosproject.cluster.LeadershipService;
29 -import org.onosproject.config.NetworkConfigService;
30 import org.onosproject.core.ApplicationId; 29 import org.onosproject.core.ApplicationId;
31 import org.onosproject.core.CoreService; 30 import org.onosproject.core.CoreService;
31 +import org.onosproject.net.config.NetworkConfigService;
32 +import org.onosproject.incubator.net.intf.InterfaceService;
32 import org.onosproject.net.host.HostService; 33 import org.onosproject.net.host.HostService;
33 import org.onosproject.net.intent.IntentService; 34 import org.onosproject.net.intent.IntentService;
34 import org.onosproject.routing.RoutingService; 35 import org.onosproject.routing.RoutingService;
...@@ -70,14 +71,12 @@ public class SdnIp implements SdnIpService { ...@@ -70,14 +71,12 @@ public class SdnIp implements SdnIpService {
70 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 71 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
71 protected RoutingConfigurationService config; 72 protected RoutingConfigurationService config;
72 73
73 - //
74 - // NOTE: Unused reference - needed to guarantee that the
75 - // NetworkConfigReader component is activated and the network configuration
76 - // is read.
77 - //
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 protected NetworkConfigService networkConfigService; 75 protected NetworkConfigService networkConfigService;
80 76
77 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 + protected InterfaceService interfaceService;
79 +
81 private IntentSynchronizer intentSynchronizer; 80 private IntentSynchronizer intentSynchronizer;
82 private PeerConnectivityManager peerConnectivity; 81 private PeerConnectivityManager peerConnectivity;
83 82
...@@ -96,12 +95,15 @@ public class SdnIp implements SdnIpService { ...@@ -96,12 +95,15 @@ public class SdnIp implements SdnIpService {
96 95
97 intentSynchronizer = new IntentSynchronizer(appId, intentService, 96 intentSynchronizer = new IntentSynchronizer(appId, intentService,
98 hostService, 97 hostService,
99 - config); 98 + config,
99 + interfaceService);
100 intentSynchronizer.start(); 100 intentSynchronizer.start();
101 101
102 peerConnectivity = new PeerConnectivityManager(appId, 102 peerConnectivity = new PeerConnectivityManager(appId,
103 intentSynchronizer, 103 intentSynchronizer,
104 - config); 104 + networkConfigService,
105 + coreService.getAppId(RoutingService.ROUTER_APP_ID),
106 + interfaceService);
105 peerConnectivity.start(); 107 peerConnectivity.start();
106 108
107 routingService.addFibListener(intentSynchronizer); 109 routingService.addFibListener(intentSynchronizer);
......
...@@ -28,6 +28,9 @@ import org.onlab.packet.IpPrefix; ...@@ -28,6 +28,9 @@ import org.onlab.packet.IpPrefix;
28 import org.onlab.packet.MacAddress; 28 import org.onlab.packet.MacAddress;
29 import org.onlab.packet.VlanId; 29 import org.onlab.packet.VlanId;
30 import org.onosproject.core.ApplicationId; 30 import org.onosproject.core.ApplicationId;
31 +import org.onosproject.net.config.NetworkConfigService;
32 +import org.onosproject.incubator.net.intf.Interface;
33 +import org.onosproject.incubator.net.intf.InterfaceService;
31 import org.onosproject.net.ConnectPoint; 34 import org.onosproject.net.ConnectPoint;
32 import org.onosproject.net.DeviceId; 35 import org.onosproject.net.DeviceId;
33 import org.onosproject.net.PortNumber; 36 import org.onosproject.net.PortNumber;
...@@ -45,7 +48,6 @@ import org.onosproject.routing.FibEntry; ...@@ -45,7 +48,6 @@ import org.onosproject.routing.FibEntry;
45 import org.onosproject.routing.FibUpdate; 48 import org.onosproject.routing.FibUpdate;
46 import org.onosproject.routing.RouteEntry; 49 import org.onosproject.routing.RouteEntry;
47 import org.onosproject.routing.config.BgpPeer; 50 import org.onosproject.routing.config.BgpPeer;
48 -import org.onosproject.routing.config.Interface;
49 import org.onosproject.routing.config.RoutingConfigurationService; 51 import org.onosproject.routing.config.RoutingConfigurationService;
50 import org.onosproject.sdnip.IntentSynchronizer.IntentKey; 52 import org.onosproject.sdnip.IntentSynchronizer.IntentKey;
51 53
...@@ -56,7 +58,11 @@ import java.util.Map; ...@@ -56,7 +58,11 @@ import java.util.Map;
56 import java.util.Set; 58 import java.util.Set;
57 import java.util.concurrent.ConcurrentHashMap; 59 import java.util.concurrent.ConcurrentHashMap;
58 60
59 -import static org.easymock.EasyMock.*; 61 +import static org.easymock.EasyMock.createMock;
62 +import static org.easymock.EasyMock.expect;
63 +import static org.easymock.EasyMock.replay;
64 +import static org.easymock.EasyMock.reset;
65 +import static org.easymock.EasyMock.verify;
60 import static org.hamcrest.Matchers.is; 66 import static org.hamcrest.Matchers.is;
61 import static org.junit.Assert.assertEquals; 67 import static org.junit.Assert.assertEquals;
62 import static org.junit.Assert.assertFalse; 68 import static org.junit.Assert.assertFalse;
...@@ -71,7 +77,9 @@ import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId; ...@@ -71,7 +77,9 @@ import static org.onosproject.sdnip.TestIntentServiceHelper.eqExceptId;
71 public class IntentSyncTest extends AbstractIntentTest { 77 public class IntentSyncTest extends AbstractIntentTest {
72 78
73 private RoutingConfigurationService routingConfig; 79 private RoutingConfigurationService routingConfig;
80 + private InterfaceService interfaceService;
74 private IntentService intentService; 81 private IntentService intentService;
82 + private NetworkConfigService configService;
75 83
76 private static final ConnectPoint SW1_ETH1 = new ConnectPoint( 84 private static final ConnectPoint SW1_ETH1 = new ConnectPoint(
77 DeviceId.deviceId("of:0000000000000001"), 85 DeviceId.deviceId("of:0000000000000001"),
...@@ -90,6 +98,7 @@ public class IntentSyncTest extends AbstractIntentTest { ...@@ -90,6 +98,7 @@ public class IntentSyncTest extends AbstractIntentTest {
90 PortNumber.portNumber(1)); 98 PortNumber.portNumber(1));
91 99
92 private IntentSynchronizer intentSynchronizer; 100 private IntentSynchronizer intentSynchronizer;
101 + private final Set<Interface> interfaces = Sets.newHashSet();
93 102
94 private static final ApplicationId APPID = new ApplicationId() { 103 private static final ApplicationId APPID = new ApplicationId() {
95 @Override 104 @Override
...@@ -108,17 +117,21 @@ public class IntentSyncTest extends AbstractIntentTest { ...@@ -108,17 +117,21 @@ public class IntentSyncTest extends AbstractIntentTest {
108 super.setUp(); 117 super.setUp();
109 118
110 routingConfig = createMock(RoutingConfigurationService.class); 119 routingConfig = createMock(RoutingConfigurationService.class);
120 + interfaceService = createMock(InterfaceService.class);
121 + configService = createMock(NetworkConfigService.class);
111 122
112 // These will set expectations on routingConfig 123 // These will set expectations on routingConfig
113 setUpInterfaceService(); 124 setUpInterfaceService();
114 setUpBgpPeers(); 125 setUpBgpPeers();
115 126
116 replay(routingConfig); 127 replay(routingConfig);
128 + replay(interfaceService);
117 129
118 intentService = createMock(IntentService.class); 130 intentService = createMock(IntentService.class);
119 131
120 intentSynchronizer = new IntentSynchronizer(APPID, intentService, 132 intentSynchronizer = new IntentSynchronizer(APPID, intentService,
121 - null, routingConfig); 133 + null, routingConfig,
134 + interfaceService);
122 } 135 }
123 136
124 /** 137 /**
...@@ -152,9 +165,6 @@ public class IntentSyncTest extends AbstractIntentTest { ...@@ -152,9 +165,6 @@ public class IntentSyncTest extends AbstractIntentTest {
152 * Sets up InterfaceService. 165 * Sets up InterfaceService.
153 */ 166 */
154 private void setUpInterfaceService() { 167 private void setUpInterfaceService() {
155 -
156 - Set<Interface> interfaces = Sets.newHashSet();
157 -
158 Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet(); 168 Set<InterfaceIpAddress> interfaceIpAddresses1 = Sets.newHashSet();
159 interfaceIpAddresses1.add(new InterfaceIpAddress( 169 interfaceIpAddresses1.add(new InterfaceIpAddress(
160 IpAddress.valueOf("192.168.10.101"), 170 IpAddress.valueOf("192.168.10.101"),
...@@ -190,16 +200,26 @@ public class IntentSyncTest extends AbstractIntentTest { ...@@ -190,16 +200,26 @@ public class IntentSyncTest extends AbstractIntentTest {
190 MacAddress.valueOf("00:00:00:00:00:04"), 200 MacAddress.valueOf("00:00:00:00:00:04"),
191 VlanId.vlanId((short) 1)); 201 VlanId.vlanId((short) 1));
192 202
193 - expect(routingConfig.getInterface(SW4_ETH1)).andReturn( 203 + expect(interfaceService.getInterfacesByPort(SW4_ETH1)).andReturn(
194 - sw4Eth1).anyTimes(); 204 + Collections.singleton(sw4Eth1)).anyTimes();
205 + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.40.1")))
206 + .andReturn(sw4Eth1).anyTimes();
207 +
195 interfaces.add(sw4Eth1); 208 interfaces.add(sw4Eth1);
196 209
197 - expect(routingConfig.getInterface(SW1_ETH1)).andReturn( 210 + expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn(
198 - sw1Eth1).anyTimes(); 211 + Collections.singleton(sw1Eth1)).anyTimes();
199 - expect(routingConfig.getInterface(SW2_ETH1)).andReturn( 212 + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1")))
200 - sw2Eth1).anyTimes(); 213 + .andReturn(sw1Eth1).anyTimes();
201 - expect(routingConfig.getInterface(SW3_ETH1)).andReturn(sw3Eth1).anyTimes(); 214 + expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn(
202 - expect(routingConfig.getInterfaces()).andReturn(interfaces).anyTimes(); 215 + Collections.singleton(sw2Eth1)).anyTimes();
216 + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1")))
217 + .andReturn(sw2Eth1).anyTimes();
218 + expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn(
219 + Collections.singleton(sw3Eth1)).anyTimes();
220 + expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1")))
221 + .andReturn(sw3Eth1).anyTimes();
222 + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
203 } 223 }
204 224
205 /** 225 /**
...@@ -599,8 +619,8 @@ public class IntentSyncTest extends AbstractIntentTest { ...@@ -599,8 +619,8 @@ public class IntentSyncTest extends AbstractIntentTest {
599 treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress)); 619 treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
600 620
601 Set<ConnectPoint> ingressPoints = new HashSet<>(); 621 Set<ConnectPoint> ingressPoints = new HashSet<>();
602 - for (Interface intf : routingConfig.getInterfaces()) { 622 + for (Interface intf : interfaces) {
603 - if (!intf.equals(routingConfig.getInterface(egressPoint))) { 623 + if (!intf.connectPoint().equals(egressPoint)) {
604 ConnectPoint srcPort = intf.connectPoint(); 624 ConnectPoint srcPort = intf.connectPoint();
605 ingressPoints.add(srcPort); 625 ingressPoints.add(srcPort);
606 } 626 }
...@@ -621,7 +641,6 @@ public class IntentSyncTest extends AbstractIntentTest { ...@@ -621,7 +641,6 @@ public class IntentSyncTest extends AbstractIntentTest {
621 * A static MultiPointToSinglePointIntent builder, the returned intent is 641 * A static MultiPointToSinglePointIntent builder, the returned intent is
622 * equal to the input intent except that the id is different. 642 * equal to the input intent except that the id is different.
623 * 643 *
624 - *
625 * @param intent the intent to be used for building a new intent 644 * @param intent the intent to be used for building a new intent
626 * @param routeEntry the relative routeEntry of the intent 645 * @param routeEntry the relative routeEntry of the intent
627 * @return the newly constructed MultiPointToSinglePointIntent 646 * @return the newly constructed MultiPointToSinglePointIntent
......
...@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Component; ...@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Component;
23 import org.apache.felix.scr.annotations.Deactivate; 23 import org.apache.felix.scr.annotations.Deactivate;
24 import org.apache.felix.scr.annotations.Reference; 24 import org.apache.felix.scr.annotations.Reference;
25 import org.apache.felix.scr.annotations.ReferenceCardinality; 25 import org.apache.felix.scr.annotations.ReferenceCardinality;
26 +import org.onosproject.net.config.Config;
26 import org.onosproject.net.config.NetworkConfigEvent; 27 import org.onosproject.net.config.NetworkConfigEvent;
27 import org.onosproject.net.config.NetworkConfigListener; 28 import org.onosproject.net.config.NetworkConfigListener;
28 import org.onosproject.net.config.NetworkConfigService; 29 import org.onosproject.net.config.NetworkConfigService;
...@@ -49,11 +50,11 @@ public class NetworkConfigLoader { ...@@ -49,11 +50,11 @@ public class NetworkConfigLoader {
49 50
50 // FIXME: Add mutual exclusion to make sure this happens only once per startup. 51 // FIXME: Add mutual exclusion to make sure this happens only once per startup.
51 52
52 - private Map<InnerConfigPosition, ObjectNode> jsons = Maps.newHashMap(); 53 + private final Map<InnerConfigPosition, ObjectNode> jsons = Maps.newConcurrentMap();
53 54
54 private final NetworkConfigListener configListener = new InnerConfigListener(); 55 private final NetworkConfigListener configListener = new InnerConfigListener();
55 56
56 - ObjectNode root; 57 + private ObjectNode root;
57 58
58 @Activate 59 @Activate
59 public void activate() { 60 public void activate() {
...@@ -101,24 +102,24 @@ public class NetworkConfigLoader { ...@@ -101,24 +102,24 @@ public class NetworkConfigLoader {
101 * Inner class that allows for tracking of JSON class configurations. 102 * Inner class that allows for tracking of JSON class configurations.
102 */ 103 */
103 private final class InnerConfigPosition { 104 private final class InnerConfigPosition {
104 - private String subjectKey, subject, classKey; 105 + private final String subjectKey, subject, configKey;
105 106
106 - private String getSubjectKey() { 107 + private String subjectKey() {
107 return subjectKey; 108 return subjectKey;
108 } 109 }
109 110
110 - private String getSubject() { 111 + private String subject() {
111 return subject; 112 return subject;
112 } 113 }
113 114
114 - private String getClassKey() { 115 + private String configKey() {
115 - return classKey; 116 + return configKey;
116 } 117 }
117 118
118 - private InnerConfigPosition(String subjectKey, String subject, String classKey) { 119 + private InnerConfigPosition(String subjectKey, String subject, String configKey) {
119 this.subjectKey = subjectKey; 120 this.subjectKey = subjectKey;
120 this.subject = subject; 121 this.subject = subject;
121 - this.classKey = classKey; 122 + this.configKey = configKey;
122 } 123 }
123 124
124 @Override 125 @Override
...@@ -128,15 +129,16 @@ public class NetworkConfigLoader { ...@@ -128,15 +129,16 @@ public class NetworkConfigLoader {
128 } 129 }
129 if (obj instanceof InnerConfigPosition) { 130 if (obj instanceof InnerConfigPosition) {
130 final InnerConfigPosition that = (InnerConfigPosition) obj; 131 final InnerConfigPosition that = (InnerConfigPosition) obj;
131 - return Objects.equals(this.subjectKey, that.subjectKey) && Objects.equals(this.subject, that.subject) 132 + return Objects.equals(this.subjectKey, that.subjectKey)
132 - && Objects.equals(this.classKey, that.classKey); 133 + && Objects.equals(this.subject, that.subject)
134 + && Objects.equals(this.configKey, that.configKey);
133 } 135 }
134 return false; 136 return false;
135 } 137 }
136 138
137 @Override 139 @Override
138 public int hashCode() { 140 public int hashCode() {
139 - return Objects.hash(subjectKey, subject, classKey); 141 + return Objects.hash(subjectKey, subject, configKey);
140 } 142 }
141 } 143 }
142 144
...@@ -174,38 +176,41 @@ public class NetworkConfigLoader { ...@@ -174,38 +176,41 @@ public class NetworkConfigLoader {
174 } 176 }
175 177
176 /** 178 /**
177 - * Apply the configurations associated with all of the config classes that are imported and have not yet been 179 + * Apply the configurations associated with all of the config classes that
178 - * applied. 180 + * are imported and have not yet been applied.
179 */ 181 */
180 - protected void applyConfigurations() { 182 + private void applyConfigurations() {
181 Iterator<Map.Entry<InnerConfigPosition, ObjectNode>> iter = jsons.entrySet().iterator(); 183 Iterator<Map.Entry<InnerConfigPosition, ObjectNode>> iter = jsons.entrySet().iterator();
182 184
183 Map.Entry<InnerConfigPosition, ObjectNode> entry; 185 Map.Entry<InnerConfigPosition, ObjectNode> entry;
184 InnerConfigPosition key; 186 InnerConfigPosition key;
185 ObjectNode node; 187 ObjectNode node;
186 String subjectKey; 188 String subjectKey;
187 - String subject; 189 + String subjectString;
188 - String classKey; 190 + String configKey;
189 191
190 while (iter.hasNext()) { 192 while (iter.hasNext()) {
191 entry = iter.next(); 193 entry = iter.next();
192 node = entry.getValue(); 194 node = entry.getValue();
193 key = entry.getKey(); 195 key = entry.getKey();
194 - subjectKey = key.getSubjectKey(); 196 + subjectKey = key.subjectKey();
195 - subject = key.getSubject(); 197 + subjectString = key.subject();
196 - classKey = key.getClassKey(); 198 + configKey = key.configKey();
199 +
200 + Class<? extends Config> configClass =
201 + networkConfigService.getConfigClass(subjectKey, configKey);
197 //Check that the config class has been imported 202 //Check that the config class has been imported
198 - if (networkConfigService.getConfigClass(subjectKey, subject) != null) { 203 + if (configClass != null) {
204 +
205 + Object subject = networkConfigService.getSubjectFactory(subjectKey).
206 + createSubject(subjectString);
199 207
200 //Apply the configuration 208 //Apply the configuration
201 - networkConfigService.applyConfig(networkConfigService.getSubjectFactory(subjectKey). 209 + networkConfigService.applyConfig(subject, configClass, node);
202 - createSubject(subject),
203 - networkConfigService.getConfigClass(subjectKey, classKey), node);
204 210
205 //Now that it has been applied the corresponding JSON entry is no longer needed 211 //Now that it has been applied the corresponding JSON entry is no longer needed
206 - jsons.remove(key); 212 + iter.remove();
207 } 213 }
208 -
209 } 214 }
210 } 215 }
211 216
......
...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Service; ...@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Service;
24 import org.onlab.packet.IpAddress; 24 import org.onlab.packet.IpAddress;
25 import org.onlab.packet.MacAddress; 25 import org.onlab.packet.MacAddress;
26 import org.onlab.packet.VlanId; 26 import org.onlab.packet.VlanId;
27 +import org.onosproject.incubator.net.intf.InterfaceService;
27 import org.onosproject.net.provider.AbstractListenerProviderRegistry; 28 import org.onosproject.net.provider.AbstractListenerProviderRegistry;
28 import org.onosproject.core.Permission; 29 import org.onosproject.core.Permission;
29 import org.onosproject.net.config.NetworkConfigEvent; 30 import org.onosproject.net.config.NetworkConfigEvent;
...@@ -86,6 +87,9 @@ public class HostManager ...@@ -86,6 +87,9 @@ public class HostManager
86 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 87 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
87 protected NetworkConfigService networkConfigService; 88 protected NetworkConfigService networkConfigService;
88 89
90 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
91 + protected InterfaceService interfaceService;
92 +
89 private HostMonitor monitor; 93 private HostMonitor monitor;
90 94
91 @Activate 95 @Activate
...@@ -93,7 +97,7 @@ public class HostManager ...@@ -93,7 +97,7 @@ public class HostManager
93 store.setDelegate(delegate); 97 store.setDelegate(delegate);
94 eventDispatcher.addSink(HostEvent.class, listenerRegistry); 98 eventDispatcher.addSink(HostEvent.class, listenerRegistry);
95 networkConfigService.addListener(networkConfigListener); 99 networkConfigService.addListener(networkConfigListener);
96 - monitor = new HostMonitor(deviceService, packetService, this); 100 + monitor = new HostMonitor(packetService, this, interfaceService);
97 monitor.start(); 101 monitor.start();
98 log.info("Started"); 102 log.info("Started");
99 } 103 }
......
...@@ -20,26 +20,23 @@ import org.jboss.netty.util.TimerTask; ...@@ -20,26 +20,23 @@ import org.jboss.netty.util.TimerTask;
20 import org.onlab.packet.ARP; 20 import org.onlab.packet.ARP;
21 import org.onlab.packet.Ethernet; 21 import org.onlab.packet.Ethernet;
22 import org.onlab.packet.ICMP6; 22 import org.onlab.packet.ICMP6;
23 -import org.onlab.packet.IpAddress;
24 import org.onlab.packet.IPv6; 23 import org.onlab.packet.IPv6;
24 +import org.onlab.packet.IpAddress;
25 import org.onlab.packet.MacAddress; 25 import org.onlab.packet.MacAddress;
26 import org.onlab.packet.VlanId; 26 import org.onlab.packet.VlanId;
27 import org.onlab.packet.ndp.NeighborDiscoveryOptions; 27 import org.onlab.packet.ndp.NeighborDiscoveryOptions;
28 import org.onlab.packet.ndp.NeighborSolicitation; 28 import org.onlab.packet.ndp.NeighborSolicitation;
29 import org.onlab.util.Timer; 29 import org.onlab.util.Timer;
30 +import org.onosproject.incubator.net.intf.Interface;
31 +import org.onosproject.incubator.net.intf.InterfaceService;
30 import org.onosproject.net.ConnectPoint; 32 import org.onosproject.net.ConnectPoint;
31 -import org.onosproject.net.Device;
32 -import org.onosproject.net.DeviceId;
33 import org.onosproject.net.Host; 33 import org.onosproject.net.Host;
34 -import org.onosproject.net.Port;
35 -import org.onosproject.net.device.DeviceService;
36 import org.onosproject.net.flow.DefaultTrafficTreatment; 34 import org.onosproject.net.flow.DefaultTrafficTreatment;
37 import org.onosproject.net.flow.TrafficTreatment; 35 import org.onosproject.net.flow.TrafficTreatment;
38 import org.onosproject.net.flow.instructions.Instruction; 36 import org.onosproject.net.flow.instructions.Instruction;
39 import org.onosproject.net.flow.instructions.Instructions; 37 import org.onosproject.net.flow.instructions.Instructions;
40 import org.onosproject.net.host.HostProvider; 38 import org.onosproject.net.host.HostProvider;
41 import org.onosproject.net.host.InterfaceIpAddress; 39 import org.onosproject.net.host.InterfaceIpAddress;
42 -import org.onosproject.net.host.PortAddresses;
43 import org.onosproject.net.packet.DefaultOutboundPacket; 40 import org.onosproject.net.packet.DefaultOutboundPacket;
44 import org.onosproject.net.packet.OutboundPacket; 41 import org.onosproject.net.packet.OutboundPacket;
45 import org.onosproject.net.packet.PacketService; 42 import org.onosproject.net.packet.PacketService;
...@@ -63,9 +60,9 @@ import java.util.concurrent.TimeUnit; ...@@ -63,9 +60,9 @@ import java.util.concurrent.TimeUnit;
63 * </p> 60 * </p>
64 */ 61 */
65 public class HostMonitor implements TimerTask { 62 public class HostMonitor implements TimerTask {
66 - private DeviceService deviceService;
67 private PacketService packetService; 63 private PacketService packetService;
68 private HostManager hostManager; 64 private HostManager hostManager;
65 + private InterfaceService interfaceService;
69 66
70 private final Set<IpAddress> monitoredAddresses; 67 private final Set<IpAddress> monitoredAddresses;
71 68
...@@ -80,20 +77,19 @@ public class HostMonitor implements TimerTask { ...@@ -80,20 +77,19 @@ public class HostMonitor implements TimerTask {
80 /** 77 /**
81 * Creates a new host monitor. 78 * Creates a new host monitor.
82 * 79 *
83 - * @param deviceService device service used to find edge ports
84 * @param packetService packet service used to send packets on the data plane 80 * @param packetService packet service used to send packets on the data plane
85 * @param hostManager host manager used to look up host information and 81 * @param hostManager host manager used to look up host information and
86 * probe existing hosts 82 * probe existing hosts
83 + * @param interfaceService interface service for interface information
87 */ 84 */
88 - public HostMonitor(DeviceService deviceService, PacketService packetService, 85 + public HostMonitor(PacketService packetService, HostManager hostManager,
89 - HostManager hostManager) { 86 + InterfaceService interfaceService) {
90 87
91 - this.deviceService = deviceService;
92 this.packetService = packetService; 88 this.packetService = packetService;
93 this.hostManager = hostManager; 89 this.hostManager = hostManager;
90 + this.interfaceService = interfaceService;
94 91
95 - monitoredAddresses = Collections.newSetFromMap( 92 + monitoredAddresses = Collections.newSetFromMap(new ConcurrentHashMap<>());
96 - new ConcurrentHashMap<IpAddress, Boolean>());
97 hostProviders = new ConcurrentHashMap<>(); 93 hostProviders = new ConcurrentHashMap<>();
98 } 94 }
99 95
...@@ -176,29 +172,21 @@ public class HostMonitor implements TimerTask { ...@@ -176,29 +172,21 @@ public class HostMonitor implements TimerTask {
176 * @param targetIp IP address to send the request for 172 * @param targetIp IP address to send the request for
177 */ 173 */
178 private void sendArpNdpRequest(IpAddress targetIp) { 174 private void sendArpNdpRequest(IpAddress targetIp) {
179 - // Find ports with an IP address in the target's subnet and sent ARP/ND 175 + Interface intf = interfaceService.getMatchingInterface(targetIp);
180 - // probes out those ports. 176 +
181 - for (Device device : deviceService.getDevices()) { 177 + if (intf == null) {
182 - for (Port port : deviceService.getPorts(device.id())) { 178 + return;
183 - ConnectPoint cp = new ConnectPoint(device.id(), port.number()); 179 + }
184 - Set<PortAddresses> portAddressSet = 180 +
185 - hostManager.getAddressBindingsForPort(cp); 181 + for (InterfaceIpAddress ia : intf.ipAddresses()) {
186 - 182 + if (ia.subnetAddress().contains(targetIp)) {
187 - for (PortAddresses portAddresses : portAddressSet) { 183 + sendArpNdpProbe(intf.connectPoint(), targetIp, ia.ipAddress(),
188 - for (InterfaceIpAddress ia : portAddresses.ipAddresses()) { 184 + intf.mac(), intf.vlan());
189 - if (ia.subnetAddress().contains(targetIp)) {
190 - sendArpNdpProbe(device.id(), port, targetIp,
191 - ia.ipAddress(),
192 - portAddresses.mac(),
193 - portAddresses.vlan());
194 - }
195 - }
196 - }
197 } 185 }
198 } 186 }
199 } 187 }
200 188
201 - private void sendArpNdpProbe(DeviceId deviceId, Port port, 189 + private void sendArpNdpProbe(ConnectPoint connectPoint,
202 IpAddress targetIp, 190 IpAddress targetIp,
203 IpAddress sourceIp, MacAddress sourceMac, 191 IpAddress sourceIp, MacAddress sourceMac,
204 VlanId vlan) { 192 VlanId vlan) {
...@@ -215,14 +203,14 @@ public class HostMonitor implements TimerTask { ...@@ -215,14 +203,14 @@ public class HostMonitor implements TimerTask {
215 } 203 }
216 204
217 List<Instruction> instructions = new ArrayList<>(); 205 List<Instruction> instructions = new ArrayList<>();
218 - instructions.add(Instructions.createOutput(port.number())); 206 + instructions.add(Instructions.createOutput(connectPoint.port()));
219 207
220 TrafficTreatment treatment = DefaultTrafficTreatment.builder() 208 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
221 - .setOutput(port.number()) 209 + .setOutput(connectPoint.port())
222 .build(); 210 .build();
223 211
224 OutboundPacket outboundPacket = 212 OutboundPacket outboundPacket =
225 - new DefaultOutboundPacket(deviceId, treatment, 213 + new DefaultOutboundPacket(connectPoint.deviceId(), treatment,
226 ByteBuffer.wrap(probePacket.serialize())); 214 ByteBuffer.wrap(probePacket.serialize()));
227 215
228 packetService.emit(outboundPacket); 216 packetService.emit(outboundPacket);
......
...@@ -98,7 +98,7 @@ public class MultiPointToSinglePointIntentCompiler ...@@ -98,7 +98,7 @@ public class MultiPointToSinglePointIntentCompiler
98 partialTree = true; 98 partialTree = true;
99 99
100 for (Link link : path.links()) { 100 for (Link link : path.links()) {
101 - if (links.containsKey(link.src().deviceId())) { 101 + if (links.containsKey(link.dst().deviceId())) {
102 // We've already reached the existing tree with the first 102 // We've already reached the existing tree with the first
103 // part of this path. Add the merging point with different 103 // part of this path. Add the merging point with different
104 // incoming port, but don't add the remainder of the path 104 // incoming port, but don't add the remainder of the path
......
...@@ -26,6 +26,8 @@ import org.onlab.packet.IpAddress; ...@@ -26,6 +26,8 @@ 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.incubator.net.intf.Interface;
30 +import org.onosproject.incubator.net.intf.InterfaceService;
29 import org.onosproject.net.ConnectPoint; 31 import org.onosproject.net.ConnectPoint;
30 import org.onosproject.net.Device; 32 import org.onosproject.net.Device;
31 import org.onosproject.net.DeviceId; 33 import org.onosproject.net.DeviceId;
...@@ -94,7 +96,7 @@ public class HostMonitorTest { ...@@ -94,7 +96,7 @@ public class HostMonitorTest {
94 expectLastCall().once(); 96 expectLastCall().once();
95 replay(hostProvider); 97 replay(hostProvider);
96 98
97 - hostMonitor = new HostMonitor(null, null, hostManager); 99 + hostMonitor = new HostMonitor(null, hostManager, null);
98 100
99 hostMonitor.registerHostProvider(hostProvider); 101 hostMonitor.registerHostProvider(hostProvider);
100 hostMonitor.addMonitoringFor(TARGET_IP_ADDR); 102 hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
...@@ -129,16 +131,20 @@ public class HostMonitorTest { ...@@ -129,16 +131,20 @@ public class HostMonitorTest {
129 new PortAddresses(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE); 131 new PortAddresses(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE);
130 132
131 expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) 133 expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
132 - .andReturn(Collections.<Host>emptySet()).anyTimes(); 134 + .andReturn(Collections.emptySet()).anyTimes();
133 - expect(hostManager.getAddressBindingsForPort(cp))
134 - .andReturn(Collections.singleton(pa)).anyTimes();
135 replay(hostManager); 135 replay(hostManager);
136 136
137 + InterfaceService interfaceService = createMock(InterfaceService.class);
138 + expect(interfaceService.getMatchingInterface(TARGET_IP_ADDR))
139 + .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.NONE))
140 + .anyTimes();
141 + replay(interfaceService);
142 +
137 TestPacketService packetService = new TestPacketService(); 143 TestPacketService packetService = new TestPacketService();
138 144
139 145
140 // Run the test 146 // Run the test
141 - hostMonitor = new HostMonitor(deviceService, packetService, hostManager); 147 + hostMonitor = new HostMonitor(packetService, hostManager, interfaceService);
142 148
143 hostMonitor.addMonitoringFor(TARGET_IP_ADDR); 149 hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
144 hostMonitor.run(null); 150 hostMonitor.run(null);
...@@ -197,16 +203,20 @@ public class HostMonitorTest { ...@@ -197,16 +203,20 @@ public class HostMonitorTest {
197 VlanId.vlanId(vlan)); 203 VlanId.vlanId(vlan));
198 204
199 expect(hostManager.getHostsByIp(TARGET_IP_ADDR)) 205 expect(hostManager.getHostsByIp(TARGET_IP_ADDR))
200 - .andReturn(Collections.<Host>emptySet()).anyTimes(); 206 + .andReturn(Collections.emptySet()).anyTimes();
201 - expect(hostManager.getAddressBindingsForPort(cp))
202 - .andReturn(Collections.singleton(pa)).anyTimes();
203 replay(hostManager); 207 replay(hostManager);
204 208
209 + InterfaceService interfaceService = createMock(InterfaceService.class);
210 + expect(interfaceService.getMatchingInterface(TARGET_IP_ADDR))
211 + .andReturn(new Interface(cp, Collections.singleton(IA1), sourceMac, VlanId.vlanId(vlan)))
212 + .anyTimes();
213 + replay(interfaceService);
214 +
205 TestPacketService packetService = new TestPacketService(); 215 TestPacketService packetService = new TestPacketService();
206 216
207 217
208 // Run the test 218 // Run the test
209 - hostMonitor = new HostMonitor(deviceService, packetService, hostManager); 219 + hostMonitor = new HostMonitor(packetService, hostManager, interfaceService);
210 220
211 hostMonitor.addMonitoringFor(TARGET_IP_ADDR); 221 hostMonitor.addMonitoringFor(TARGET_IP_ADDR);
212 hostMonitor.run(null); 222 hostMonitor.run(null);
......
...@@ -23,8 +23,11 @@ import org.onlab.packet.ARP; ...@@ -23,8 +23,11 @@ import org.onlab.packet.ARP;
23 import org.onlab.packet.Ethernet; 23 import org.onlab.packet.Ethernet;
24 import org.onlab.packet.Ip4Address; 24 import org.onlab.packet.Ip4Address;
25 import org.onlab.packet.Ip4Prefix; 25 import org.onlab.packet.Ip4Prefix;
26 +import org.onlab.packet.IpPrefix;
26 import org.onlab.packet.MacAddress; 27 import org.onlab.packet.MacAddress;
27 import org.onlab.packet.VlanId; 28 import org.onlab.packet.VlanId;
29 +import org.onosproject.incubator.net.intf.Interface;
30 +import org.onosproject.incubator.net.intf.InterfaceService;
28 import org.onosproject.net.ConnectPoint; 31 import org.onosproject.net.ConnectPoint;
29 import org.onosproject.net.DefaultHost; 32 import org.onosproject.net.DefaultHost;
30 import org.onosproject.net.Device; 33 import org.onosproject.net.Device;
...@@ -44,7 +47,6 @@ import org.onosproject.net.flow.instructions.Instruction; ...@@ -44,7 +47,6 @@ import org.onosproject.net.flow.instructions.Instruction;
44 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; 47 import org.onosproject.net.flow.instructions.Instructions.OutputInstruction;
45 import org.onosproject.net.host.HostService; 48 import org.onosproject.net.host.HostService;
46 import org.onosproject.net.host.InterfaceIpAddress; 49 import org.onosproject.net.host.InterfaceIpAddress;
47 -import org.onosproject.net.host.PortAddresses;
48 import org.onosproject.net.link.LinkListener; 50 import org.onosproject.net.link.LinkListener;
49 import org.onosproject.net.link.LinkService; 51 import org.onosproject.net.link.LinkService;
50 import org.onosproject.net.packet.DefaultOutboundPacket; 52 import org.onosproject.net.packet.DefaultOutboundPacket;
...@@ -57,12 +59,17 @@ import org.onosproject.net.proxyarp.ProxyArpStoreDelegate; ...@@ -57,12 +59,17 @@ import org.onosproject.net.proxyarp.ProxyArpStoreDelegate;
57 import java.nio.ByteBuffer; 59 import java.nio.ByteBuffer;
58 import java.util.ArrayList; 60 import java.util.ArrayList;
59 import java.util.Collections; 61 import java.util.Collections;
60 -import java.util.Comparator;
61 import java.util.List; 62 import java.util.List;
62 import java.util.Set; 63 import java.util.Set;
63 64
64 -import static org.easymock.EasyMock.*; 65 +import static org.easymock.EasyMock.anyObject;
65 -import static org.junit.Assert.*; 66 +import static org.easymock.EasyMock.createMock;
67 +import static org.easymock.EasyMock.expect;
68 +import static org.easymock.EasyMock.replay;
69 +import static org.junit.Assert.assertArrayEquals;
70 +import static org.junit.Assert.assertEquals;
71 +import static org.junit.Assert.assertFalse;
72 +import static org.junit.Assert.assertTrue;
66 73
67 /** 74 /**
68 * Tests for the {@link ProxyArpManager} class. 75 * Tests for the {@link ProxyArpManager} class.
...@@ -104,6 +111,7 @@ public class ProxyArpManagerTest { ...@@ -104,6 +111,7 @@ public class ProxyArpManagerTest {
104 private DeviceService deviceService; 111 private DeviceService deviceService;
105 private LinkService linkService; 112 private LinkService linkService;
106 private HostService hostService; 113 private HostService hostService;
114 + private InterfaceService interfaceService;
107 115
108 @Before 116 @Before
109 public void setUp() throws Exception { 117 public void setUp() throws Exception {
...@@ -119,6 +127,9 @@ public class ProxyArpManagerTest { ...@@ -119,6 +127,9 @@ public class ProxyArpManagerTest {
119 hostService = createMock(HostService.class); 127 hostService = createMock(HostService.class);
120 proxyArp.hostService = hostService; 128 proxyArp.hostService = hostService;
121 129
130 + interfaceService = createMock(InterfaceService.class);
131 + proxyArp.interfaceService = interfaceService;
132 +
122 createTopology(); 133 createTopology();
123 proxyArp.deviceService = deviceService; 134 proxyArp.deviceService = deviceService;
124 proxyArp.linkService = linkService; 135 proxyArp.linkService = linkService;
...@@ -207,7 +218,7 @@ public class ProxyArpManagerTest { ...@@ -207,7 +218,7 @@ public class ProxyArpManagerTest {
207 } 218 }
208 219
209 private void addAddressBindings() { 220 private void addAddressBindings() {
210 - Set<PortAddresses> addresses = Sets.newHashSet(); 221 + Set<Interface> interfaces = Sets.newHashSet();
211 222
212 for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { 223 for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) {
213 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); 224 ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1);
...@@ -219,29 +230,28 @@ public class ProxyArpManagerTest { ...@@ -219,29 +230,28 @@ public class ProxyArpManagerTest {
219 Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1"); 230 Ip4Address addr2 = Ip4Address.valueOf("10.0." + (2 * i) + ".1");
220 InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); 231 InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1);
221 InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); 232 InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2);
222 - PortAddresses pa1 = 233 + Interface intf1 = new Interface(cp, Sets.newHashSet(ia1),
223 - new PortAddresses(cp, Sets.newHashSet(ia1), 234 + MacAddress.valueOf(2 * i - 1),
224 - MacAddress.valueOf(2 * i - 1), 235 + VlanId.vlanId((short) 1));
225 - VlanId.vlanId((short) 1)); 236 + Interface intf2 = new Interface(cp, Sets.newHashSet(ia2),
226 - PortAddresses pa2 = 237 + MacAddress.valueOf(2 * i),
227 - new PortAddresses(cp, Sets.newHashSet(ia2), 238 + VlanId.NONE);
228 - MacAddress.valueOf(2 * i), 239 +
229 - VlanId.NONE); 240 + interfaces.add(intf1);
230 - 241 + interfaces.add(intf2);
231 - addresses.add(pa1); 242 +
232 - addresses.add(pa2); 243 + expect(interfaceService.getInterfacesByPort(cp))
233 - 244 + .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes();
234 - expect(hostService.getAddressBindingsForPort(cp))
235 - .andReturn(Sets.newHashSet(pa1, pa2)).anyTimes();
236 } 245 }
237 246
238 - expect(hostService.getAddressBindings()).andReturn(addresses).anyTimes(); 247 + expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes();
239 248
240 for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { 249 for (int i = 1; i <= NUM_FLOOD_PORTS; i++) {
241 ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), 250 ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS),
242 P1); 251 P1);
243 - expect(hostService.getAddressBindingsForPort(cp)) 252 +
244 - .andReturn(Collections.<PortAddresses>emptySet()).anyTimes(); 253 + expect(interfaceService.getInterfacesByPort(cp))
254 + .andReturn(Collections.emptySet()).anyTimes();
245 } 255 }
246 } 256 }
247 257
...@@ -254,6 +264,7 @@ public class ProxyArpManagerTest { ...@@ -254,6 +264,7 @@ public class ProxyArpManagerTest {
254 public void testNotKnown() { 264 public void testNotKnown() {
255 expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet()); 265 expect(hostService.getHostsByIp(IP1)).andReturn(Collections.<Host>emptySet());
256 replay(hostService); 266 replay(hostService);
267 + replay(interfaceService);
257 268
258 assertFalse(proxyArp.isKnown(IP1)); 269 assertFalse(proxyArp.isKnown(IP1));
259 } 270 }
...@@ -271,6 +282,7 @@ public class ProxyArpManagerTest { ...@@ -271,6 +282,7 @@ public class ProxyArpManagerTest {
271 expect(hostService.getHostsByIp(IP1)) 282 expect(hostService.getHostsByIp(IP1))
272 .andReturn(Sets.newHashSet(host1, host2)); 283 .andReturn(Sets.newHashSet(host1, host2));
273 replay(hostService); 284 replay(hostService);
285 + replay(interfaceService);
274 286
275 assertTrue(proxyArp.isKnown(IP1)); 287 assertTrue(proxyArp.isKnown(IP1));
276 } 288 }
...@@ -296,6 +308,7 @@ public class ProxyArpManagerTest { ...@@ -296,6 +308,7 @@ public class ProxyArpManagerTest {
296 expect(hostService.getHost(HID2)).andReturn(requestor); 308 expect(hostService.getHost(HID2)).andReturn(requestor);
297 309
298 replay(hostService); 310 replay(hostService);
311 + replay(interfaceService);
299 312
300 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); 313 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1);
301 314
...@@ -319,11 +332,14 @@ public class ProxyArpManagerTest { ...@@ -319,11 +332,14 @@ public class ProxyArpManagerTest {
319 Collections.singleton(IP2)); 332 Collections.singleton(IP2));
320 333
321 expect(hostService.getHostsByIp(IP1)) 334 expect(hostService.getHostsByIp(IP1))
322 - .andReturn(Collections.<Host>emptySet()); 335 + .andReturn(Collections.emptySet());
336 + expect(interfaceService.getInterfacesByIp(IP2))
337 + .andReturn(Collections.emptySet());
323 expect(hostService.getHost(HID2)).andReturn(requestor); 338 expect(hostService.getHost(HID2)).andReturn(requestor);
324 339
325 340
326 replay(hostService); 341 replay(hostService);
342 + replay(interfaceService);
327 343
328 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); 344 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1);
329 345
...@@ -354,9 +370,12 @@ public class ProxyArpManagerTest { ...@@ -354,9 +370,12 @@ public class ProxyArpManagerTest {
354 370
355 expect(hostService.getHostsByIp(IP1)) 371 expect(hostService.getHostsByIp(IP1))
356 .andReturn(Collections.singleton(replyer)); 372 .andReturn(Collections.singleton(replyer));
373 + expect(interfaceService.getInterfacesByIp(IP2))
374 + .andReturn(Collections.emptySet());
357 expect(hostService.getHost(HID2)).andReturn(requestor); 375 expect(hostService.getHost(HID2)).andReturn(requestor);
358 376
359 replay(hostService); 377 replay(hostService);
378 + replay(interfaceService);
360 379
361 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); 380 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1);
362 381
...@@ -382,6 +401,7 @@ public class ProxyArpManagerTest { ...@@ -382,6 +401,7 @@ public class ProxyArpManagerTest {
382 401
383 expect(hostService.getHost(HID2)).andReturn(requestor); 402 expect(hostService.getHost(HID2)).andReturn(requestor);
384 replay(hostService); 403 replay(hostService);
404 + replay(interfaceService);
385 405
386 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp); 406 Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp);
387 isEdgePointReturn = true; 407 isEdgePointReturn = true;
...@@ -405,6 +425,7 @@ public class ProxyArpManagerTest { ...@@ -405,6 +425,7 @@ public class ProxyArpManagerTest {
405 @Test 425 @Test
406 public void testReplyExternalPortBadRequest() { 426 public void testReplyExternalPortBadRequest() {
407 replay(hostService); // no further host service expectations 427 replay(hostService); // no further host service expectations
428 + replay(interfaceService);
408 429
409 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); 430 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254");
410 431
...@@ -428,8 +449,13 @@ public class ProxyArpManagerTest { ...@@ -428,8 +449,13 @@ public class ProxyArpManagerTest {
428 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100"); 449 Ip4Address theirIp = Ip4Address.valueOf("10.0.1.100");
429 450
430 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet()); 451 expect(hostService.getHostsByIp(theirIp)).andReturn(Collections.emptySet());
452 + expect(interfaceService.getInterfacesByIp(ourIp))
453 + .andReturn(Collections.singleton(new Interface(getLocation(1),
454 + Collections.singleton(new InterfaceIpAddress(ourIp, IpPrefix.valueOf("10.0.1.1/24"))),
455 + ourMac, VLAN1)));
431 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null); 456 expect(hostService.getHost(HostId.hostId(ourMac, VLAN1))).andReturn(null);
432 replay(hostService); 457 replay(hostService);
458 + replay(interfaceService);
433 459
434 // This is a request from something inside our network (like a BGP 460 // This is a request from something inside our network (like a BGP
435 // daemon) to an external host. 461 // daemon) to an external host.
...@@ -462,6 +488,7 @@ public class ProxyArpManagerTest { ...@@ -462,6 +488,7 @@ public class ProxyArpManagerTest {
462 expect(hostService.getHost(HID1)).andReturn(host1); 488 expect(hostService.getHost(HID1)).andReturn(host1);
463 expect(hostService.getHost(HID2)).andReturn(host2); 489 expect(hostService.getHost(HID2)).andReturn(host2);
464 replay(hostService); 490 replay(hostService);
491 + replay(interfaceService);
465 492
466 Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); 493 Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1);
467 494
...@@ -482,6 +509,7 @@ public class ProxyArpManagerTest { ...@@ -482,6 +509,7 @@ public class ProxyArpManagerTest {
482 public void testForwardFlood() { 509 public void testForwardFlood() {
483 expect(hostService.getHost(HID1)).andReturn(null); 510 expect(hostService.getHost(HID1)).andReturn(null);
484 replay(hostService); 511 replay(hostService);
512 + replay(interfaceService);
485 513
486 Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); 514 Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1);
487 515
...@@ -508,12 +536,7 @@ public class ProxyArpManagerTest { ...@@ -508,12 +536,7 @@ public class ProxyArpManagerTest {
508 assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); 536 assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size());
509 537
510 Collections.sort(packetService.packets, 538 Collections.sort(packetService.packets,
511 - new Comparator<OutboundPacket>() { 539 + (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri()));
512 - @Override
513 - public int compare(OutboundPacket o1, OutboundPacket o2) {
514 - return o1.sendThrough().uri().compareTo(o2.sendThrough().uri());
515 - }
516 - });
517 540
518 541
519 for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { 542 for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) {
......
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.incubator.net.config.basics;
18 +
19 +/**
20 + * Signals that an error was encountered while reading/writing configuration.
21 + */
22 +public class ConfigException extends Exception {
23 +
24 + /**
25 + * Constructs a new ConfigException with the given message.
26 + *
27 + * @param message message
28 + */
29 + public ConfigException(String message) {
30 + super(message);
31 + }
32 +
33 + /**
34 + * Constructs a new ConfigException with the given message and cause.
35 + *
36 + * @param message message
37 + * @param cause cause
38 + */
39 + public ConfigException(String message, Throwable cause) {
40 + super(message, cause);
41 + }
42 +}
...@@ -36,19 +36,41 @@ public class InterfaceConfig extends Config<ConnectPoint> { ...@@ -36,19 +36,41 @@ public class InterfaceConfig extends Config<ConnectPoint> {
36 public static final String MAC = "mac"; 36 public static final String MAC = "mac";
37 public static final String VLAN = "vlan"; 37 public static final String VLAN = "vlan";
38 38
39 + public static final String IP_MISSING_ERROR = "Must have at least one IP address";
40 + public static final String MAC_MISSING_ERROR = "Must have a MAC address for each interface";
41 + public static final String CONFIG_VALUE_ERROR = "Error parsing config value";
42 +
39 /** 43 /**
40 * Retrieves all interfaces configured on this port. 44 * Retrieves all interfaces configured on this port.
41 * 45 *
42 * @return set of interfaces 46 * @return set of interfaces
47 + * @throws ConfigException if there is any error in the JSON config
43 */ 48 */
44 - public Set<Interface> getInterfaces() { 49 + public Set<Interface> getInterfaces() throws ConfigException {
45 Set<Interface> interfaces = Sets.newHashSet(); 50 Set<Interface> interfaces = Sets.newHashSet();
46 51
47 - for (JsonNode intfNode : node.path(INTERFACES)) { 52 + try {
48 - interfaces.add(new Interface(subject, 53 + for (JsonNode intfNode : node.path(INTERFACES)) {
49 - getIps(intfNode), 54 + Set<InterfaceIpAddress> ips = getIps(intfNode);
50 - MacAddress.valueOf(intfNode.path(MAC).asText()), 55 + if (ips.isEmpty()) {
51 - VlanId.vlanId(Short.parseShort(intfNode.path(VLAN).asText())))); 56 + throw new ConfigException(IP_MISSING_ERROR);
57 + }
58 +
59 + if (intfNode.path(MAC).isMissingNode()) {
60 + throw new ConfigException(MAC_MISSING_ERROR);
61 + }
62 +
63 + MacAddress mac = MacAddress.valueOf(intfNode.path(MAC).asText());
64 +
65 + VlanId vlan = VlanId.NONE;
66 + if (!intfNode.path(VLAN).isMissingNode()) {
67 + vlan = VlanId.vlanId(Short.valueOf(intfNode.path(VLAN).asText()));
68 + }
69 +
70 + interfaces.add(new Interface(subject, ips, mac, vlan));
71 + }
72 + } catch (IllegalArgumentException e) {
73 + throw new ConfigException(CONFIG_VALUE_ERROR, e);
52 } 74 }
53 75
54 return interfaces; 76 return interfaces;
......
...@@ -25,6 +25,8 @@ import org.onosproject.net.host.InterfaceIpAddress; ...@@ -25,6 +25,8 @@ import org.onosproject.net.host.InterfaceIpAddress;
25 import java.util.Objects; 25 import java.util.Objects;
26 import java.util.Set; 26 import java.util.Set;
27 27
28 +import static com.google.common.base.Preconditions.checkNotNull;
29 +
28 /** 30 /**
29 * An Interface maps network configuration information (such as addresses and 31 * An Interface maps network configuration information (such as addresses and
30 * vlans) to a port in the network. 32 * vlans) to a port in the network.
...@@ -46,10 +48,10 @@ public class Interface { ...@@ -46,10 +48,10 @@ public class Interface {
46 public Interface(ConnectPoint connectPoint, 48 public Interface(ConnectPoint connectPoint,
47 Set<InterfaceIpAddress> ipAddresses, 49 Set<InterfaceIpAddress> ipAddresses,
48 MacAddress macAddress, VlanId vlan) { 50 MacAddress macAddress, VlanId vlan) {
49 - this.connectPoint = connectPoint; 51 + this.connectPoint = checkNotNull(connectPoint);
50 - this.ipAddresses = Sets.newHashSet(ipAddresses); 52 + this.ipAddresses = Sets.newHashSet(checkNotNull(ipAddresses));
51 - this.macAddress = macAddress; 53 + this.macAddress = checkNotNull(macAddress);
52 - this.vlan = vlan; 54 + this.vlan = checkNotNull(vlan);
53 } 55 }
54 56
55 /** 57 /**
......
...@@ -26,19 +26,18 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; ...@@ -26,19 +26,18 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
26 import org.apache.felix.scr.annotations.Service; 26 import org.apache.felix.scr.annotations.Service;
27 import org.onlab.packet.IpAddress; 27 import org.onlab.packet.IpAddress;
28 import org.onlab.packet.VlanId; 28 import org.onlab.packet.VlanId;
29 -import org.onosproject.net.config.NetworkConfigEvent; 29 +import org.onosproject.incubator.net.config.basics.ConfigException;
30 -import org.onosproject.net.config.NetworkConfigListener;
31 -import org.onosproject.net.config.NetworkConfigService;
32 import org.onosproject.incubator.net.config.basics.InterfaceConfig; 30 import org.onosproject.incubator.net.config.basics.InterfaceConfig;
33 import org.onosproject.incubator.net.intf.Interface; 31 import org.onosproject.incubator.net.intf.Interface;
34 import org.onosproject.incubator.net.intf.InterfaceService; 32 import org.onosproject.incubator.net.intf.InterfaceService;
35 import org.onosproject.net.ConnectPoint; 33 import org.onosproject.net.ConnectPoint;
36 -import org.onosproject.net.Device; 34 +import org.onosproject.net.config.NetworkConfigEvent;
37 -import org.onosproject.net.Port; 35 +import org.onosproject.net.config.NetworkConfigListener;
38 -import org.onosproject.net.device.DeviceService; 36 +import org.onosproject.net.config.NetworkConfigService;
39 import org.slf4j.Logger; 37 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory; 38 import org.slf4j.LoggerFactory;
41 39
40 +import java.util.Collections;
42 import java.util.Map; 41 import java.util.Map;
43 import java.util.Optional; 42 import java.util.Optional;
44 import java.util.Set; 43 import java.util.Set;
...@@ -55,11 +54,11 @@ public class InterfaceManager implements InterfaceService { ...@@ -55,11 +54,11 @@ public class InterfaceManager implements InterfaceService {
55 54
56 private final Logger log = LoggerFactory.getLogger(getClass()); 55 private final Logger log = LoggerFactory.getLogger(getClass());
57 56
58 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 57 + private static final Class<ConnectPoint> SUBJECT_CLASS = ConnectPoint.class;
59 - protected NetworkConfigService configService; 58 + private static final Class<InterfaceConfig> CONFIG_CLASS = InterfaceConfig.class;
60 59
61 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 60 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
62 - protected DeviceService deviceService; 61 + protected NetworkConfigService configService;
63 62
64 private final InternalConfigListener listener = new InternalConfigListener(); 63 private final InternalConfigListener listener = new InternalConfigListener();
65 64
...@@ -69,14 +68,12 @@ public class InterfaceManager implements InterfaceService { ...@@ -69,14 +68,12 @@ public class InterfaceManager implements InterfaceService {
69 public void activate() { 68 public void activate() {
70 configService.addListener(listener); 69 configService.addListener(listener);
71 70
72 - for (Device d : deviceService.getDevices()) { 71 + // TODO address concurrency issues here
73 - for (Port p : deviceService.getPorts(d.id())) { 72 + for (ConnectPoint subject : configService.getSubjects(SUBJECT_CLASS, CONFIG_CLASS)) {
74 - InterfaceConfig config = 73 + InterfaceConfig config = configService.getConfig(subject, CONFIG_CLASS);
75 - configService.getConfig(new ConnectPoint(d.id(), p.number()), InterfaceConfig.class);
76 74
77 - if (config != null) { 75 + if (config != null) {
78 - updateInterfaces(config); 76 + updateInterfaces(config);
79 - }
80 } 77 }
81 } 78 }
82 79
...@@ -100,7 +97,11 @@ public class InterfaceManager implements InterfaceService { ...@@ -100,7 +97,11 @@ public class InterfaceManager implements InterfaceService {
100 97
101 @Override 98 @Override
102 public Set<Interface> getInterfacesByPort(ConnectPoint port) { 99 public Set<Interface> getInterfacesByPort(ConnectPoint port) {
103 - return ImmutableSet.copyOf(interfaces.get(port)); 100 + Set<Interface> intfs = interfaces.get(port);
101 + if (intfs == null) {
102 + return Collections.emptySet();
103 + }
104 + return ImmutableSet.copyOf(intfs);
104 } 105 }
105 106
106 @Override 107 @Override
...@@ -108,7 +109,9 @@ public class InterfaceManager implements InterfaceService { ...@@ -108,7 +109,9 @@ public class InterfaceManager implements InterfaceService {
108 return interfaces.values() 109 return interfaces.values()
109 .stream() 110 .stream()
110 .flatMap(set -> set.stream()) 111 .flatMap(set -> set.stream())
111 - .filter(intf -> intf.ipAddresses().contains(ip)) 112 + .filter(intf -> intf.ipAddresses()
113 + .stream()
114 + .anyMatch(ia -> ia.ipAddress().equals(ip)))
112 .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); 115 .collect(collectingAndThen(toSet(), ImmutableSet::copyOf));
113 } 116 }
114 117
...@@ -139,7 +142,11 @@ public class InterfaceManager implements InterfaceService { ...@@ -139,7 +142,11 @@ public class InterfaceManager implements InterfaceService {
139 } 142 }
140 143
141 private void updateInterfaces(InterfaceConfig intfConfig) { 144 private void updateInterfaces(InterfaceConfig intfConfig) {
142 - interfaces.put(intfConfig.subject(), intfConfig.getInterfaces()); 145 + try {
146 + interfaces.put(intfConfig.subject(), intfConfig.getInterfaces());
147 + } catch (ConfigException e) {
148 + log.error("Error in interface config", e);
149 + }
143 } 150 }
144 151
145 private void removeInterfaces(ConnectPoint port) { 152 private void removeInterfaces(ConnectPoint port) {
......