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
682 additions
and
640 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> | ... | ... |
... | @@ -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 = |
203 | + bgpSpeaker.get().peers().stream().findAny(); | ||
204 | + | ||
205 | + if (!peerAddress.isPresent()) { | ||
206 | + log.error("BGP speaker must have peers configured"); | ||
194 | return; | 207 | return; |
195 | } | 208 | } |
196 | - deviceId = s.interfaceAddresses().get(0).connectPoint().deviceId(); | 209 | + |
197 | - break; | 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(); | ||
155 | } | 156 | } |
156 | } | 157 | } |
157 | - for (InterfaceAddress addr : bgpSpeaker.interfaceAddresses()) { | 158 | + } else { |
158 | - if (addr.ipAddress().equals(dstAddress) && !context.inPacket() | 159 | + Set<Interface> interfaces = |
159 | - .receivedFrom().equals(bgpSpeaker.connectPoint())) { | 160 | + interfaceService.getInterfacesByPort(context.inPacket().receivedFrom()); |
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,25 +311,12 @@ public class IntentSynchronizer implements FibListener, IntentRequestListener { | ... | @@ -313,25 +311,12 @@ 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)) { | ||
318 | - // Route to a peer | ||
319 | - log.debug("Route to peer {}", nextHopIpAddress); | ||
320 | - BgpPeer peer = | ||
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) { | 315 | if (egressInterface == null) { |
330 | log.warn("No outgoing interface found for {}", | 316 | log.warn("No outgoing interface found for {}", |
331 | nextHopIpAddress); | 317 | nextHopIpAddress); |
332 | return null; | 318 | return null; |
333 | } | 319 | } |
334 | - } | ||
335 | 320 | ||
336 | // | 321 | // |
337 | // Generate the intent itself | 322 | // Generate the intent itself |
... | @@ -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); | ... | ... |
... | @@ -22,6 +22,9 @@ import org.onlab.packet.IpAddress; | ... | @@ -22,6 +22,9 @@ import org.onlab.packet.IpAddress; |
22 | import org.onlab.packet.IpPrefix; | 22 | import org.onlab.packet.IpPrefix; |
23 | import org.onlab.packet.TpPort; | 23 | import org.onlab.packet.TpPort; |
24 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
25 | +import org.onosproject.net.config.NetworkConfigService; | ||
26 | +import org.onosproject.incubator.net.intf.Interface; | ||
27 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
25 | import org.onosproject.net.ConnectPoint; | 28 | import org.onosproject.net.ConnectPoint; |
26 | import org.onosproject.net.flow.DefaultTrafficSelector; | 29 | import org.onosproject.net.flow.DefaultTrafficSelector; |
27 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 30 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
... | @@ -29,11 +32,8 @@ import org.onosproject.net.flow.TrafficSelector; | ... | @@ -29,11 +32,8 @@ import org.onosproject.net.flow.TrafficSelector; |
29 | import org.onosproject.net.flow.TrafficTreatment; | 32 | import org.onosproject.net.flow.TrafficTreatment; |
30 | import org.onosproject.net.host.InterfaceIpAddress; | 33 | import org.onosproject.net.host.InterfaceIpAddress; |
31 | import org.onosproject.net.intent.PointToPointIntent; | 34 | import org.onosproject.net.intent.PointToPointIntent; |
32 | -import org.onosproject.routing.config.BgpPeer; | 35 | +import org.onosproject.routing.RoutingService; |
33 | -import org.onosproject.routing.config.BgpSpeaker; | 36 | +import org.onosproject.routing.config.BgpConfig; |
34 | -import org.onosproject.routing.config.Interface; | ||
35 | -import org.onosproject.routing.config.InterfaceAddress; | ||
36 | -import org.onosproject.routing.config.RoutingConfigurationService; | ||
37 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
38 | import org.slf4j.LoggerFactory; | 38 | import org.slf4j.LoggerFactory; |
39 | 39 | ||
... | @@ -41,6 +41,8 @@ import java.util.ArrayList; | ... | @@ -41,6 +41,8 @@ import java.util.ArrayList; |
41 | import java.util.Collection; | 41 | import java.util.Collection; |
42 | import java.util.List; | 42 | import java.util.List; |
43 | 43 | ||
44 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
45 | + | ||
44 | /** | 46 | /** |
45 | * Manages the connectivity requirements between peers. | 47 | * Manages the connectivity requirements between peers. |
46 | */ | 48 | */ |
... | @@ -53,9 +55,11 @@ public class PeerConnectivityManager { | ... | @@ -53,9 +55,11 @@ public class PeerConnectivityManager { |
53 | private static final short BGP_PORT = 179; | 55 | private static final short BGP_PORT = 179; |
54 | 56 | ||
55 | private final IntentSynchronizer intentSynchronizer; | 57 | private final IntentSynchronizer intentSynchronizer; |
56 | - private final RoutingConfigurationService configService; | 58 | + private final NetworkConfigService configService; |
59 | + private final InterfaceService interfaceService; | ||
57 | 60 | ||
58 | private final ApplicationId appId; | 61 | private final ApplicationId appId; |
62 | + private final ApplicationId routerAppId; | ||
59 | 63 | ||
60 | /** | 64 | /** |
61 | * Creates a new PeerConnectivityManager. | 65 | * Creates a new PeerConnectivityManager. |
... | @@ -66,28 +70,20 @@ public class PeerConnectivityManager { | ... | @@ -66,28 +70,20 @@ public class PeerConnectivityManager { |
66 | */ | 70 | */ |
67 | public PeerConnectivityManager(ApplicationId appId, | 71 | public PeerConnectivityManager(ApplicationId appId, |
68 | IntentSynchronizer intentSynchronizer, | 72 | IntentSynchronizer intentSynchronizer, |
69 | - RoutingConfigurationService configService) { | 73 | + NetworkConfigService configService, |
74 | + ApplicationId routerAppId, | ||
75 | + InterfaceService interfaceService) { | ||
70 | this.appId = appId; | 76 | this.appId = appId; |
71 | this.intentSynchronizer = intentSynchronizer; | 77 | this.intentSynchronizer = intentSynchronizer; |
72 | this.configService = configService; | 78 | this.configService = configService; |
79 | + this.routerAppId = routerAppId; | ||
80 | + this.interfaceService = interfaceService; | ||
73 | } | 81 | } |
74 | 82 | ||
75 | /** | 83 | /** |
76 | * Starts the peer connectivity manager. | 84 | * Starts the peer connectivity manager. |
77 | */ | 85 | */ |
78 | public void start() { | 86 | public void start() { |
79 | - if (configService.getInterfaces().isEmpty()) { | ||
80 | - log.warn("No interfaces found in configuration file"); | ||
81 | - } | ||
82 | - | ||
83 | - if (configService.getBgpPeers().isEmpty()) { | ||
84 | - log.warn("No BGP peers found in configuration file"); | ||
85 | - } | ||
86 | - | ||
87 | - if (configService.getBgpSpeakers().isEmpty()) { | ||
88 | - log.error("No BGP speakers found in configuration file"); | ||
89 | - } | ||
90 | - | ||
91 | setUpConnectivity(); | 87 | setUpConnectivity(); |
92 | } | 88 | } |
93 | 89 | ||
... | @@ -99,78 +95,74 @@ public class PeerConnectivityManager { | ... | @@ -99,78 +95,74 @@ public class PeerConnectivityManager { |
99 | 95 | ||
100 | /** | 96 | /** |
101 | * Sets up paths to establish connectivity between all internal | 97 | * Sets up paths to establish connectivity between all internal |
102 | - * {@link BgpSpeaker}s and all external {@link BgpPeer}s. | 98 | + * BGP speakers and external BGP peers. |
103 | */ | 99 | */ |
104 | private void setUpConnectivity() { | 100 | private void setUpConnectivity() { |
105 | List<PointToPointIntent> intents = new ArrayList<>(); | 101 | List<PointToPointIntent> intents = new ArrayList<>(); |
106 | 102 | ||
107 | - for (BgpSpeaker bgpSpeaker : configService.getBgpSpeakers() | 103 | + BgpConfig config = configService.getConfig(routerAppId, RoutingService.CONFIG_CLASS); |
108 | - .values()) { | ||
109 | - log.debug("Start to set up BGP paths for BGP speaker: {}", | ||
110 | - bgpSpeaker); | ||
111 | 104 | ||
112 | - for (BgpPeer bgpPeer : configService.getBgpPeers().values()) { | 105 | + if (config == null) { |
106 | + log.warn("No BgpConfig found"); | ||
107 | + return; | ||
108 | + } | ||
113 | 109 | ||
114 | - log.debug("Start to set up BGP paths between BGP speaker: {} " | 110 | + for (BgpConfig.BgpSpeakerConfig bgpSpeaker : config.bgpSpeakers()) { |
115 | - + "to BGP peer: {}", bgpSpeaker, bgpPeer); | 111 | + log.debug("Start to set up BGP paths for BGP speaker: {}", |
112 | + bgpSpeaker); | ||
116 | 113 | ||
117 | - intents.addAll(buildPeerIntents(bgpSpeaker, bgpPeer)); | 114 | + intents.addAll(buildSpeakerIntents(bgpSpeaker)); |
118 | - } | ||
119 | } | 115 | } |
120 | 116 | ||
121 | // Submit all the intents. | 117 | // Submit all the intents. |
122 | intentSynchronizer.submitPeerIntents(intents); | 118 | intentSynchronizer.submitPeerIntents(intents); |
123 | } | 119 | } |
124 | 120 | ||
125 | - /** | 121 | + private Collection<PointToPointIntent> buildSpeakerIntents(BgpConfig.BgpSpeakerConfig speaker) { |
126 | - * Builds the required intents between a given internal BGP speaker and | ||
127 | - * external BGP peer. | ||
128 | - * | ||
129 | - * @param bgpSpeaker the BGP speaker | ||
130 | - * @param bgpPeer the BGP peer | ||
131 | - * @return the intents to install | ||
132 | - */ | ||
133 | - private Collection<PointToPointIntent> buildPeerIntents( | ||
134 | - BgpSpeaker bgpSpeaker, | ||
135 | - BgpPeer bgpPeer) { | ||
136 | List<PointToPointIntent> intents = new ArrayList<>(); | 122 | List<PointToPointIntent> intents = new ArrayList<>(); |
137 | 123 | ||
138 | - ConnectPoint bgpdConnectPoint = bgpSpeaker.connectPoint(); | 124 | + for (IpAddress peerAddress : speaker.peers()) { |
125 | + Interface peeringInterface = interfaceService.getMatchingInterface(peerAddress); | ||
139 | 126 | ||
140 | - List<InterfaceAddress> interfaceAddresses = | 127 | + if (peeringInterface == null) { |
141 | - bgpSpeaker.interfaceAddresses(); | 128 | + log.debug("No peering interface found for peer {} on speaker {}", |
142 | - | 129 | + peerAddress, speaker); |
143 | - IpAddress bgpdAddress = null; | ||
144 | - for (InterfaceAddress interfaceAddress : interfaceAddresses) { | ||
145 | - Interface peerInterface = configService.getInterface(interfaceAddress.ipAddress()); | ||
146 | - if (peerInterface == null) { | ||
147 | continue; | 130 | continue; |
148 | } | 131 | } |
149 | 132 | ||
150 | - for (InterfaceIpAddress interfaceIpAddress : peerInterface.ipAddresses()) { | 133 | + IpAddress peeringAddress = null; |
151 | - // Only add intents where the peer and ONOS's addresses are | 134 | + for (InterfaceIpAddress address : peeringInterface.ipAddresses()) { |
152 | - // in the same subnet | 135 | + if (address.subnetAddress().contains(peerAddress)) { |
153 | - if (interfaceIpAddress.subnetAddress().contains(bgpPeer.ipAddress())) { | 136 | + peeringAddress = address.ipAddress(); |
154 | - bgpdAddress = interfaceAddress.ipAddress(); | ||
155 | break; | 137 | break; |
156 | } | 138 | } |
157 | } | 139 | } |
158 | - if (bgpdAddress != null) { | 140 | + |
159 | - break; | 141 | + checkNotNull(peeringAddress); |
160 | - } | 142 | + |
143 | + intents.addAll(buildIntents(speaker.connectPoint(), peeringAddress, | ||
144 | + peeringInterface.connectPoint(), peerAddress)); | ||
161 | } | 145 | } |
162 | - if (bgpdAddress == null) { | 146 | + |
163 | - log.debug("No IP address found for peer {} on interface {}", | ||
164 | - bgpPeer, bgpPeer.connectPoint()); | ||
165 | return intents; | 147 | return intents; |
166 | } | 148 | } |
167 | 149 | ||
168 | - IpAddress bgpdPeerAddress = bgpPeer.ipAddress(); | 150 | + /** |
169 | - ConnectPoint bgpdPeerConnectPoint = bgpPeer.connectPoint(); | 151 | + * Builds the required intents between the two pairs of connect points and |
152 | + * IP addresses. | ||
153 | + * | ||
154 | + * @param portOne the first connect point | ||
155 | + * @param ipOne the first IP address | ||
156 | + * @param portTwo the second connect point | ||
157 | + * @param ipTwo the second IP address | ||
158 | + * @return the intents to install | ||
159 | + */ | ||
160 | + private Collection<PointToPointIntent> buildIntents(ConnectPoint portOne, | ||
161 | + IpAddress ipOne, | ||
162 | + ConnectPoint portTwo, | ||
163 | + IpAddress ipTwo) { | ||
170 | 164 | ||
171 | - if (bgpdAddress.version() != bgpdPeerAddress.version()) { | 165 | + List<PointToPointIntent> intents = new ArrayList<>(); |
172 | - return intents; | ||
173 | - } | ||
174 | 166 | ||
175 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | 167 | TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); |
176 | 168 | ||
... | @@ -179,7 +171,7 @@ public class PeerConnectivityManager { | ... | @@ -179,7 +171,7 @@ public class PeerConnectivityManager { |
179 | byte tcpProtocol; | 171 | byte tcpProtocol; |
180 | byte icmpProtocol; | 172 | byte icmpProtocol; |
181 | 173 | ||
182 | - if (bgpdAddress.isIp4()) { | 174 | + if (ipOne.isIp4()) { |
183 | tcpProtocol = IPv4.PROTOCOL_TCP; | 175 | tcpProtocol = IPv4.PROTOCOL_TCP; |
184 | icmpProtocol = IPv4.PROTOCOL_ICMP; | 176 | icmpProtocol = IPv4.PROTOCOL_ICMP; |
185 | } else { | 177 | } else { |
... | @@ -189,26 +181,24 @@ public class PeerConnectivityManager { | ... | @@ -189,26 +181,24 @@ public class PeerConnectivityManager { |
189 | 181 | ||
190 | // Path from BGP speaker to BGP peer matching destination TCP port 179 | 182 | // Path from BGP speaker to BGP peer matching destination TCP port 179 |
191 | selector = buildSelector(tcpProtocol, | 183 | selector = buildSelector(tcpProtocol, |
192 | - bgpdAddress, | 184 | + ipOne, |
193 | - bgpdPeerAddress, | 185 | + ipTwo, |
194 | null, | 186 | null, |
195 | BGP_PORT); | 187 | BGP_PORT); |
196 | 188 | ||
197 | - int priority = PRIORITY_OFFSET; | ||
198 | - | ||
199 | intents.add(PointToPointIntent.builder() | 189 | intents.add(PointToPointIntent.builder() |
200 | .appId(appId) | 190 | .appId(appId) |
201 | .selector(selector) | 191 | .selector(selector) |
202 | .treatment(treatment) | 192 | .treatment(treatment) |
203 | - .ingressPoint(bgpdConnectPoint) | 193 | + .ingressPoint(portOne) |
204 | - .egressPoint(bgpdPeerConnectPoint) | 194 | + .egressPoint(portTwo) |
205 | - .priority(priority) | 195 | + .priority(PRIORITY_OFFSET) |
206 | .build()); | 196 | .build()); |
207 | 197 | ||
208 | // Path from BGP speaker to BGP peer matching source TCP port 179 | 198 | // Path from BGP speaker to BGP peer matching source TCP port 179 |
209 | selector = buildSelector(tcpProtocol, | 199 | selector = buildSelector(tcpProtocol, |
210 | - bgpdAddress, | 200 | + ipOne, |
211 | - bgpdPeerAddress, | 201 | + ipTwo, |
212 | BGP_PORT, | 202 | BGP_PORT, |
213 | null); | 203 | null); |
214 | 204 | ||
... | @@ -216,15 +206,15 @@ public class PeerConnectivityManager { | ... | @@ -216,15 +206,15 @@ public class PeerConnectivityManager { |
216 | .appId(appId) | 206 | .appId(appId) |
217 | .selector(selector) | 207 | .selector(selector) |
218 | .treatment(treatment) | 208 | .treatment(treatment) |
219 | - .ingressPoint(bgpdConnectPoint) | 209 | + .ingressPoint(portOne) |
220 | - .egressPoint(bgpdPeerConnectPoint) | 210 | + .egressPoint(portTwo) |
221 | - .priority(priority) | 211 | + .priority(PRIORITY_OFFSET) |
222 | .build()); | 212 | .build()); |
223 | 213 | ||
224 | // Path from BGP peer to BGP speaker matching destination TCP port 179 | 214 | // Path from BGP peer to BGP speaker matching destination TCP port 179 |
225 | selector = buildSelector(tcpProtocol, | 215 | selector = buildSelector(tcpProtocol, |
226 | - bgpdPeerAddress, | 216 | + ipTwo, |
227 | - bgpdAddress, | 217 | + ipOne, |
228 | null, | 218 | null, |
229 | BGP_PORT); | 219 | BGP_PORT); |
230 | 220 | ||
... | @@ -232,15 +222,15 @@ public class PeerConnectivityManager { | ... | @@ -232,15 +222,15 @@ public class PeerConnectivityManager { |
232 | .appId(appId) | 222 | .appId(appId) |
233 | .selector(selector) | 223 | .selector(selector) |
234 | .treatment(treatment) | 224 | .treatment(treatment) |
235 | - .ingressPoint(bgpdPeerConnectPoint) | 225 | + .ingressPoint(portTwo) |
236 | - .egressPoint(bgpdConnectPoint) | 226 | + .egressPoint(portOne) |
237 | - .priority(priority) | 227 | + .priority(PRIORITY_OFFSET) |
238 | .build()); | 228 | .build()); |
239 | 229 | ||
240 | // Path from BGP peer to BGP speaker matching source TCP port 179 | 230 | // Path from BGP peer to BGP speaker matching source TCP port 179 |
241 | selector = buildSelector(tcpProtocol, | 231 | selector = buildSelector(tcpProtocol, |
242 | - bgpdPeerAddress, | 232 | + ipTwo, |
243 | - bgpdAddress, | 233 | + ipOne, |
244 | BGP_PORT, | 234 | BGP_PORT, |
245 | null); | 235 | null); |
246 | 236 | ||
... | @@ -248,15 +238,15 @@ public class PeerConnectivityManager { | ... | @@ -248,15 +238,15 @@ public class PeerConnectivityManager { |
248 | .appId(appId) | 238 | .appId(appId) |
249 | .selector(selector) | 239 | .selector(selector) |
250 | .treatment(treatment) | 240 | .treatment(treatment) |
251 | - .ingressPoint(bgpdPeerConnectPoint) | 241 | + .ingressPoint(portTwo) |
252 | - .egressPoint(bgpdConnectPoint) | 242 | + .egressPoint(portOne) |
253 | - .priority(priority) | 243 | + .priority(PRIORITY_OFFSET) |
254 | .build()); | 244 | .build()); |
255 | 245 | ||
256 | // ICMP path from BGP speaker to BGP peer | 246 | // ICMP path from BGP speaker to BGP peer |
257 | selector = buildSelector(icmpProtocol, | 247 | selector = buildSelector(icmpProtocol, |
258 | - bgpdAddress, | 248 | + ipOne, |
259 | - bgpdPeerAddress, | 249 | + ipTwo, |
260 | null, | 250 | null, |
261 | null); | 251 | null); |
262 | 252 | ||
... | @@ -264,15 +254,15 @@ public class PeerConnectivityManager { | ... | @@ -264,15 +254,15 @@ public class PeerConnectivityManager { |
264 | .appId(appId) | 254 | .appId(appId) |
265 | .selector(selector) | 255 | .selector(selector) |
266 | .treatment(treatment) | 256 | .treatment(treatment) |
267 | - .ingressPoint(bgpdConnectPoint) | 257 | + .ingressPoint(portOne) |
268 | - .egressPoint(bgpdPeerConnectPoint) | 258 | + .egressPoint(portTwo) |
269 | - .priority(priority) | 259 | + .priority(PRIORITY_OFFSET) |
270 | .build()); | 260 | .build()); |
271 | 261 | ||
272 | // ICMP path from BGP peer to BGP speaker | 262 | // ICMP path from BGP peer to BGP speaker |
273 | selector = buildSelector(icmpProtocol, | 263 | selector = buildSelector(icmpProtocol, |
274 | - bgpdPeerAddress, | 264 | + ipTwo, |
275 | - bgpdAddress, | 265 | + ipOne, |
276 | null, | 266 | null, |
277 | null); | 267 | null); |
278 | 268 | ||
... | @@ -280,9 +270,9 @@ public class PeerConnectivityManager { | ... | @@ -280,9 +270,9 @@ public class PeerConnectivityManager { |
280 | .appId(appId) | 270 | .appId(appId) |
281 | .selector(selector) | 271 | .selector(selector) |
282 | .treatment(treatment) | 272 | .treatment(treatment) |
283 | - .ingressPoint(bgpdPeerConnectPoint) | 273 | + .ingressPoint(portTwo) |
284 | - .egressPoint(bgpdConnectPoint) | 274 | + .egressPoint(portOne) |
285 | - .priority(priority) | 275 | + .priority(PRIORITY_OFFSET) |
286 | .build()); | 276 | .build()); |
287 | 277 | ||
288 | return intents; | 278 | return intents; |
... | @@ -301,24 +291,16 @@ public class PeerConnectivityManager { | ... | @@ -301,24 +291,16 @@ public class PeerConnectivityManager { |
301 | private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, | 291 | private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, |
302 | IpAddress dstIp, Short srcTcpPort, | 292 | IpAddress dstIp, Short srcTcpPort, |
303 | Short dstTcpPort) { | 293 | Short dstTcpPort) { |
304 | - TrafficSelector.Builder builder = null; | 294 | + TrafficSelector.Builder builder = DefaultTrafficSelector.builder() |
295 | + .matchEthType(Ethernet.TYPE_IPV4) | ||
296 | + .matchIPProtocol(ipProto); | ||
305 | 297 | ||
306 | if (dstIp.isIp4()) { | 298 | if (dstIp.isIp4()) { |
307 | - builder = DefaultTrafficSelector.builder() | 299 | + builder.matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) |
308 | - .matchEthType(Ethernet.TYPE_IPV4) | 300 | + .matchIPDst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET_MASK_LENGTH)); |
309 | - .matchIPProtocol(ipProto) | ||
310 | - .matchIPSrc(IpPrefix.valueOf(srcIp, | ||
311 | - IpPrefix.MAX_INET_MASK_LENGTH)) | ||
312 | - .matchIPDst(IpPrefix.valueOf(dstIp, | ||
313 | - IpPrefix.MAX_INET_MASK_LENGTH)); | ||
314 | } else { | 301 | } else { |
315 | - builder = DefaultTrafficSelector.builder() | 302 | + builder.matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) |
316 | - .matchEthType(Ethernet.TYPE_IPV6) | 303 | + .matchIPv6Dst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET6_MASK_LENGTH)); |
317 | - .matchIPProtocol(ipProto) | ||
318 | - .matchIPv6Src(IpPrefix.valueOf(srcIp, | ||
319 | - IpPrefix.MAX_INET6_MASK_LENGTH)) | ||
320 | - .matchIPv6Dst(IpPrefix.valueOf(dstIp, | ||
321 | - IpPrefix.MAX_INET6_MASK_LENGTH)); | ||
322 | } | 304 | } |
323 | 305 | ||
324 | if (srcTcpPort != null) { | 306 | if (srcTcpPort != null) { | ... | ... |
... | @@ -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 | ... | ... |
... | @@ -29,6 +29,9 @@ import org.onlab.packet.MacAddress; | ... | @@ -29,6 +29,9 @@ import org.onlab.packet.MacAddress; |
29 | import org.onlab.packet.TpPort; | 29 | import org.onlab.packet.TpPort; |
30 | import org.onlab.packet.VlanId; | 30 | import org.onlab.packet.VlanId; |
31 | import org.onosproject.core.ApplicationId; | 31 | import org.onosproject.core.ApplicationId; |
32 | +import org.onosproject.net.config.NetworkConfigService; | ||
33 | +import org.onosproject.incubator.net.intf.Interface; | ||
34 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
32 | import org.onosproject.net.ConnectPoint; | 35 | import org.onosproject.net.ConnectPoint; |
33 | import org.onosproject.net.DeviceId; | 36 | import org.onosproject.net.DeviceId; |
34 | import org.onosproject.net.PortNumber; | 37 | import org.onosproject.net.PortNumber; |
... | @@ -41,9 +44,9 @@ import org.onosproject.net.intent.AbstractIntentTest; | ... | @@ -41,9 +44,9 @@ import org.onosproject.net.intent.AbstractIntentTest; |
41 | import org.onosproject.net.intent.Intent; | 44 | import org.onosproject.net.intent.Intent; |
42 | import org.onosproject.net.intent.IntentService; | 45 | import org.onosproject.net.intent.IntentService; |
43 | import org.onosproject.net.intent.PointToPointIntent; | 46 | import org.onosproject.net.intent.PointToPointIntent; |
47 | +import org.onosproject.routing.config.BgpConfig; | ||
44 | import org.onosproject.routing.config.BgpPeer; | 48 | import org.onosproject.routing.config.BgpPeer; |
45 | import org.onosproject.routing.config.BgpSpeaker; | 49 | import org.onosproject.routing.config.BgpSpeaker; |
46 | -import org.onosproject.routing.config.Interface; | ||
47 | import org.onosproject.routing.config.InterfaceAddress; | 50 | import org.onosproject.routing.config.InterfaceAddress; |
48 | import org.onosproject.routing.config.RoutingConfigurationService; | 51 | import org.onosproject.routing.config.RoutingConfigurationService; |
49 | 52 | ||
... | @@ -53,6 +56,7 @@ import java.util.HashMap; | ... | @@ -53,6 +56,7 @@ import java.util.HashMap; |
53 | import java.util.LinkedList; | 56 | import java.util.LinkedList; |
54 | import java.util.List; | 57 | import java.util.List; |
55 | import java.util.Map; | 58 | import java.util.Map; |
59 | +import java.util.Set; | ||
56 | 60 | ||
57 | import static org.easymock.EasyMock.createMock; | 61 | import static org.easymock.EasyMock.createMock; |
58 | import static org.easymock.EasyMock.expect; | 62 | import static org.easymock.EasyMock.expect; |
... | @@ -78,16 +82,21 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -78,16 +82,21 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
78 | } | 82 | } |
79 | }; | 83 | }; |
80 | 84 | ||
85 | + private static final ApplicationId CONFIG_APP_ID = APPID; | ||
86 | + | ||
81 | private PeerConnectivityManager peerConnectivityManager; | 87 | private PeerConnectivityManager peerConnectivityManager; |
82 | private IntentSynchronizer intentSynchronizer; | 88 | private IntentSynchronizer intentSynchronizer; |
83 | private RoutingConfigurationService routingConfig; | 89 | private RoutingConfigurationService routingConfig; |
90 | + private InterfaceService interfaceService; | ||
91 | + private NetworkConfigService networkConfigService; | ||
84 | private IntentService intentService; | 92 | private IntentService intentService; |
85 | 93 | ||
86 | - private Map<String, BgpSpeaker> bgpSpeakers; | 94 | + private Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers; |
87 | private Map<String, Interface> interfaces; | 95 | private Map<String, Interface> interfaces; |
88 | private Map<IpAddress, BgpPeer> peers; | 96 | private Map<IpAddress, BgpPeer> peers; |
89 | 97 | ||
90 | - private Map<String, BgpSpeaker> configuredBgpSpeakers; | 98 | + private BgpConfig bgpConfig; |
99 | + | ||
91 | private Map<String, Interface> configuredInterfaces; | 100 | private Map<String, Interface> configuredInterfaces; |
92 | private Map<IpAddress, BgpPeer> configuredPeers; | 101 | private Map<IpAddress, BgpPeer> configuredPeers; |
93 | private List<PointToPointIntent> intentList; | 102 | private List<PointToPointIntent> intentList; |
... | @@ -119,9 +128,12 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -119,9 +128,12 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
119 | public void setUp() throws Exception { | 128 | public void setUp() throws Exception { |
120 | super.setUp(); | 129 | super.setUp(); |
121 | routingConfig = createMock(RoutingConfigurationService.class); | 130 | routingConfig = createMock(RoutingConfigurationService.class); |
131 | + interfaceService = createMock(InterfaceService.class); | ||
132 | + networkConfigService = createMock(NetworkConfigService.class); | ||
133 | + bgpConfig = createMock(BgpConfig.class); | ||
122 | 134 | ||
123 | - // These will set expectations on routingConfig | 135 | + // These will set expectations on routingConfig and interfaceService |
124 | - bgpSpeakers = Collections.unmodifiableMap(setUpBgpSpeakers()); | 136 | + bgpSpeakers = setUpBgpSpeakers(); |
125 | interfaces = Collections.unmodifiableMap(setUpInterfaces()); | 137 | interfaces = Collections.unmodifiableMap(setUpInterfaces()); |
126 | peers = Collections.unmodifiableMap(setUpPeers()); | 138 | peers = Collections.unmodifiableMap(setUpPeers()); |
127 | 139 | ||
... | @@ -134,31 +146,20 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -134,31 +146,20 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
134 | * | 146 | * |
135 | * @return configured BGP speakers as a map from speaker name to speaker | 147 | * @return configured BGP speakers as a map from speaker name to speaker |
136 | */ | 148 | */ |
137 | - private Map<String, BgpSpeaker> setUpBgpSpeakers() { | 149 | + private Set<BgpConfig.BgpSpeakerConfig> setUpBgpSpeakers() { |
138 | - | 150 | + |
139 | - configuredBgpSpeakers = new HashMap<>(); | 151 | + BgpConfig.BgpSpeakerConfig speaker1 = new BgpConfig.BgpSpeakerConfig( |
140 | - | 152 | + s1Eth100, Collections.singleton(IpAddress.valueOf("192.168.10.1"))); |
141 | - BgpSpeaker bgpSpeaker1 = new BgpSpeaker( | 153 | + |
142 | - "bgpSpeaker1", | 154 | + BgpConfig.BgpSpeakerConfig speaker2 = new BgpConfig.BgpSpeakerConfig( |
143 | - "00:00:00:00:00:00:00:01", 100, | 155 | + s1Eth100, Sets.newHashSet(IpAddress.valueOf("192.168.20.1"), |
144 | - "00:00:00:00:00:01"); | 156 | + IpAddress.valueOf("192.168.30.1"))); |
145 | - List<InterfaceAddress> interfaceAddresses1 = new LinkedList<>(); | 157 | + |
146 | - interfaceAddresses1.add(new InterfaceAddress(dpid1, 1, "192.168.10.101")); | 158 | + Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Sets.newHashSet(); |
147 | - bgpSpeaker1.setInterfaceAddresses(interfaceAddresses1); | 159 | + bgpSpeakers.add(speaker1); |
148 | - configuredBgpSpeakers.put(bgpSpeaker1.name(), bgpSpeaker1); | 160 | + bgpSpeakers.add(speaker2); |
149 | - | 161 | + |
150 | - // BGP speaker2 is attached to the same switch port with speaker1 | 162 | + return bgpSpeakers; |
151 | - BgpSpeaker bgpSpeaker2 = new BgpSpeaker( | ||
152 | - "bgpSpeaker2", | ||
153 | - "00:00:00:00:00:00:00:01", 100, | ||
154 | - "00:00:00:00:00:02"); | ||
155 | - List<InterfaceAddress> interfaceAddresses2 = new LinkedList<>(); | ||
156 | - interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.20.101")); | ||
157 | - interfaceAddresses2.add(new InterfaceAddress(dpid2, 1, "192.168.30.101")); | ||
158 | - bgpSpeaker2.setInterfaceAddresses(interfaceAddresses2); | ||
159 | - configuredBgpSpeakers.put(bgpSpeaker2.name(), bgpSpeaker2); | ||
160 | - | ||
161 | - return configuredBgpSpeakers; | ||
162 | } | 163 | } |
163 | 164 | ||
164 | /** | 165 | /** |
... | @@ -201,26 +202,31 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -201,26 +202,31 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
201 | VlanId.NONE); | 202 | VlanId.NONE); |
202 | configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); | 203 | configuredInterfaces.put(interfaceSw2Eth1intf2, intfsw2eth1intf2); |
203 | 204 | ||
204 | - expect(routingConfig.getInterface(s1Eth1)) | 205 | + expect(interfaceService.getInterfacesByPort(s1Eth1)) |
206 | + .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); | ||
207 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))) | ||
208 | + .andReturn(Collections.singleton(intfsw1eth1)).anyTimes(); | ||
209 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))) | ||
205 | .andReturn(intfsw1eth1).anyTimes(); | 210 | .andReturn(intfsw1eth1).anyTimes(); |
206 | - expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101"))) | 211 | + expect(interfaceService.getInterfacesByPort(s2Eth1)) |
207 | - .andReturn(intfsw1eth1).anyTimes(); | 212 | + .andReturn(Collections.singleton(intfsw2eth1)).anyTimes(); |
208 | - expect(routingConfig.getInterface(s2Eth1)) | 213 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))) |
209 | - .andReturn(intfsw2eth1).anyTimes(); | 214 | + .andReturn(Collections.singleton(intfsw2eth1)).anyTimes(); |
210 | - expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101"))) | 215 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1"))) |
211 | .andReturn(intfsw2eth1).anyTimes(); | 216 | .andReturn(intfsw2eth1).anyTimes(); |
212 | - //expect(routingConfig.getInterface(s2Eth1)) | 217 | + |
213 | - // .andReturn(intfsw2eth1intf2).anyTimes(); | 218 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101"))) |
214 | - expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101"))) | 219 | + .andReturn(Collections.singleton(intfsw2eth1intf2)).anyTimes(); |
220 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) | ||
215 | .andReturn(intfsw2eth1intf2).anyTimes(); | 221 | .andReturn(intfsw2eth1intf2).anyTimes(); |
216 | 222 | ||
217 | // Non-existent interface used during one of the tests | 223 | // Non-existent interface used during one of the tests |
218 | - expect(routingConfig.getInterface(new ConnectPoint( | 224 | + expect(interfaceService.getInterfacesByPort(new ConnectPoint( |
219 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), | 225 | DeviceId.deviceId(SdnIp.dpidToUri("00:00:00:00:00:00:01:00")), |
220 | PortNumber.portNumber(1)))) | 226 | PortNumber.portNumber(1)))) |
221 | .andReturn(null).anyTimes(); | 227 | .andReturn(null).anyTimes(); |
222 | 228 | ||
223 | - expect(routingConfig.getInterfaces()).andReturn( | 229 | + expect(interfaceService.getInterfaces()).andReturn( |
224 | Sets.newHashSet(configuredInterfaces.values())).anyTimes(); | 230 | Sets.newHashSet(configuredInterfaces.values())).anyTimes(); |
225 | 231 | ||
226 | return configuredInterfaces; | 232 | return configuredInterfaces; |
... | @@ -398,7 +404,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -398,7 +404,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
398 | * Sets up intents for ICMP paths. | 404 | * Sets up intents for ICMP paths. |
399 | */ | 405 | */ |
400 | private void setUpIcmpIntents() { | 406 | private void setUpIcmpIntents() { |
401 | - | ||
402 | // Start to build intents between BGP speaker1 and BGP peer1 | 407 | // Start to build intents between BGP speaker1 and BGP peer1 |
403 | icmpPathintentConstructor( | 408 | icmpPathintentConstructor( |
404 | "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1); | 409 | "192.168.10.101/32", "192.168.10.1/32", s1Eth100, s1Eth1); |
... | @@ -415,7 +420,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -415,7 +420,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
415 | "192.168.30.101/32", "192.168.30.1/32", s1Eth100, s2Eth1); | 420 | "192.168.30.101/32", "192.168.30.1/32", s1Eth100, s2Eth1); |
416 | icmpPathintentConstructor( | 421 | icmpPathintentConstructor( |
417 | "192.168.30.1/32", "192.168.30.101/32", s2Eth1, s1Eth100); | 422 | "192.168.30.1/32", "192.168.30.101/32", s2Eth1, s1Eth100); |
418 | - | ||
419 | } | 423 | } |
420 | 424 | ||
421 | /** | 425 | /** |
... | @@ -424,22 +428,28 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -424,22 +428,28 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
424 | * @throws TestUtilsException if exceptions when using TestUtils | 428 | * @throws TestUtilsException if exceptions when using TestUtils |
425 | */ | 429 | */ |
426 | private void initPeerConnectivity() throws TestUtilsException { | 430 | private void initPeerConnectivity() throws TestUtilsException { |
427 | - | ||
428 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); | 431 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
429 | - expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); | 432 | + expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); |
433 | + replay(bgpConfig); | ||
434 | + expect(networkConfigService.getConfig(APPID, BgpConfig.class)).andReturn(bgpConfig).anyTimes(); | ||
435 | + replay(networkConfigService); | ||
430 | replay(routingConfig); | 436 | replay(routingConfig); |
437 | + replay(interfaceService); | ||
431 | 438 | ||
432 | intentService = createMock(IntentService.class); | 439 | intentService = createMock(IntentService.class); |
433 | replay(intentService); | 440 | replay(intentService); |
434 | 441 | ||
435 | intentSynchronizer = new IntentSynchronizer(APPID, intentService, | 442 | intentSynchronizer = new IntentSynchronizer(APPID, intentService, |
436 | - null, routingConfig); | 443 | + null, routingConfig, |
444 | + interfaceService); | ||
437 | intentSynchronizer.leaderChanged(true); | 445 | intentSynchronizer.leaderChanged(true); |
438 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); | 446 | TestUtils.setField(intentSynchronizer, "isActivatedLeader", true); |
439 | 447 | ||
440 | peerConnectivityManager = | 448 | peerConnectivityManager = |
441 | new PeerConnectivityManager(APPID, intentSynchronizer, | 449 | new PeerConnectivityManager(APPID, intentSynchronizer, |
442 | - routingConfig); | 450 | + networkConfigService, |
451 | + CONFIG_APP_ID, | ||
452 | + interfaceService); | ||
443 | } | 453 | } |
444 | 454 | ||
445 | /** | 455 | /** |
... | @@ -472,42 +482,28 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -472,42 +482,28 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
472 | */ | 482 | */ |
473 | @Test | 483 | @Test |
474 | public void testNullInterfaces() { | 484 | public void testNullInterfaces() { |
475 | - reset(routingConfig); | 485 | + reset(interfaceService); |
476 | - expect(routingConfig.getInterfaces()).andReturn( | 486 | + |
487 | + expect(interfaceService.getInterfaces()).andReturn( | ||
477 | Sets.<Interface>newHashSet()).anyTimes(); | 488 | Sets.<Interface>newHashSet()).anyTimes(); |
478 | - expect(routingConfig.getInterface(s2Eth1)) | 489 | + expect(interfaceService.getInterfacesByPort(s2Eth1)) |
479 | - .andReturn(null).anyTimes(); | 490 | + .andReturn(Collections.emptySet()).anyTimes(); |
480 | - expect(routingConfig.getInterface(s1Eth1)) | 491 | + expect(interfaceService.getInterfacesByPort(s1Eth1)) |
481 | - .andReturn(null).anyTimes(); | 492 | + .andReturn(Collections.emptySet()).anyTimes(); |
482 | - expect(routingConfig.getInterface(IpAddress.valueOf("192.168.10.101"))) | 493 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.10.101"))) |
494 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
495 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.10.1"))) | ||
483 | .andReturn(null).anyTimes(); | 496 | .andReturn(null).anyTimes(); |
484 | - expect(routingConfig.getInterface(IpAddress.valueOf("192.168.20.101"))) | 497 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.20.101"))) |
498 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
499 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.20.1"))) | ||
485 | .andReturn(null).anyTimes(); | 500 | .andReturn(null).anyTimes(); |
486 | - expect(routingConfig.getInterface(IpAddress.valueOf("192.168.30.101"))) | 501 | + expect(interfaceService.getInterfacesByIp(IpAddress.valueOf("192.168.30.101"))) |
502 | + .andReturn(Collections.emptySet()).anyTimes(); | ||
503 | + expect(interfaceService.getMatchingInterface(IpAddress.valueOf("192.168.30.1"))) | ||
487 | .andReturn(null).anyTimes(); | 504 | .andReturn(null).anyTimes(); |
488 | 505 | ||
489 | - expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); | 506 | + replay(interfaceService); |
490 | - expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); | ||
491 | - replay(routingConfig); | ||
492 | - | ||
493 | - reset(intentService); | ||
494 | - replay(intentService); | ||
495 | - peerConnectivityManager.start(); | ||
496 | - verify(intentService); | ||
497 | - } | ||
498 | - | ||
499 | - /** | ||
500 | - * Tests a corner case, when there are no BGP peers in the configuration. | ||
501 | - */ | ||
502 | - @Test | ||
503 | - public void testNullBgpPeers() { | ||
504 | - reset(routingConfig); | ||
505 | - expect(routingConfig.getInterfaces()).andReturn( | ||
506 | - Sets.newHashSet(interfaces.values())).anyTimes(); | ||
507 | - | ||
508 | - expect(routingConfig.getBgpPeers()).andReturn(new HashMap<>()).anyTimes(); | ||
509 | - expect(routingConfig.getBgpSpeakers()).andReturn(bgpSpeakers).anyTimes(); | ||
510 | - replay(routingConfig); | ||
511 | 507 | ||
512 | reset(intentService); | 508 | reset(intentService); |
513 | replay(intentService); | 509 | replay(intentService); |
... | @@ -521,12 +517,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -521,12 +517,11 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
521 | @Test | 517 | @Test |
522 | public void testNullBgpSpeakers() { | 518 | public void testNullBgpSpeakers() { |
523 | reset(routingConfig); | 519 | reset(routingConfig); |
524 | - expect(routingConfig.getInterfaces()).andReturn( | 520 | + reset(bgpConfig); |
525 | - Sets.newHashSet(interfaces.values())).anyTimes(); | ||
526 | 521 | ||
522 | + expect(bgpConfig.bgpSpeakers()).andReturn(Collections.emptySet()).anyTimes(); | ||
523 | + replay(bgpConfig); | ||
527 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); | 524 | expect(routingConfig.getBgpPeers()).andReturn(peers).anyTimes(); |
528 | - expect(routingConfig.getBgpSpeakers()).andReturn( | ||
529 | - Collections.emptyMap()).anyTimes(); | ||
530 | replay(routingConfig); | 525 | replay(routingConfig); |
531 | 526 | ||
532 | reset(intentService); | 527 | reset(intentService); |
... | @@ -562,7 +557,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -562,7 +557,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
562 | interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201")); | 557 | interfaceAddresses100.add(new InterfaceAddress(dpid1, 1, "192.168.10.201")); |
563 | interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201")); | 558 | interfaceAddresses100.add(new InterfaceAddress(dpid2, 1, "192.168.20.201")); |
564 | bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100); | 559 | bgpSpeaker100.setInterfaceAddresses(interfaceAddresses100); |
565 | - configuredBgpSpeakers.put(bgpSpeaker100.name(), bgpSpeaker100); | ||
566 | testConnectionSetup(); | 560 | testConnectionSetup(); |
567 | } | 561 | } |
568 | } | 562 | } | ... | ... |
... | @@ -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()); | ||
184 | - Set<PortAddresses> portAddressSet = | ||
185 | - hostManager.getAddressBindingsForPort(cp); | ||
186 | - | ||
187 | - for (PortAddresses portAddresses : portAddressSet) { | ||
188 | - for (InterfaceIpAddress ia : portAddresses.ipAddresses()) { | ||
189 | - if (ia.subnetAddress().contains(targetIp)) { | ||
190 | - sendArpNdpProbe(device.id(), port, targetIp, | ||
191 | - ia.ipAddress(), | ||
192 | - portAddresses.mac(), | ||
193 | - portAddresses.vlan()); | ||
194 | - } | ||
195 | - } | ||
196 | } | 179 | } |
180 | + | ||
181 | + for (InterfaceIpAddress ia : intf.ipAddresses()) { | ||
182 | + if (ia.subnetAddress().contains(targetIp)) { | ||
183 | + sendArpNdpProbe(intf.connectPoint(), targetIp, ia.ipAddress(), | ||
184 | + intf.mac(), intf.vlan()); | ||
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 | ... | ... |
... | @@ -34,6 +34,8 @@ import org.onlab.packet.ndp.NeighborAdvertisement; | ... | @@ -34,6 +34,8 @@ import org.onlab.packet.ndp.NeighborAdvertisement; |
34 | import org.onlab.packet.ndp.NeighborDiscoveryOptions; | 34 | import org.onlab.packet.ndp.NeighborDiscoveryOptions; |
35 | import org.onlab.packet.ndp.NeighborSolicitation; | 35 | import org.onlab.packet.ndp.NeighborSolicitation; |
36 | import org.onosproject.core.Permission; | 36 | import org.onosproject.core.Permission; |
37 | +import org.onosproject.incubator.net.intf.Interface; | ||
38 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
37 | import org.onosproject.net.ConnectPoint; | 39 | import org.onosproject.net.ConnectPoint; |
38 | import org.onosproject.net.Host; | 40 | import org.onosproject.net.Host; |
39 | import org.onosproject.net.device.DeviceService; | 41 | import org.onosproject.net.device.DeviceService; |
... | @@ -41,8 +43,6 @@ import org.onosproject.net.edge.EdgePortService; | ... | @@ -41,8 +43,6 @@ import org.onosproject.net.edge.EdgePortService; |
41 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
42 | import org.onosproject.net.flow.TrafficTreatment; | 44 | import org.onosproject.net.flow.TrafficTreatment; |
43 | import org.onosproject.net.host.HostService; | 45 | import org.onosproject.net.host.HostService; |
44 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
45 | -import org.onosproject.net.host.PortAddresses; | ||
46 | import org.onosproject.net.link.LinkService; | 46 | import org.onosproject.net.link.LinkService; |
47 | import org.onosproject.net.packet.DefaultOutboundPacket; | 47 | import org.onosproject.net.packet.DefaultOutboundPacket; |
48 | import org.onosproject.net.packet.InboundPacket; | 48 | import org.onosproject.net.packet.InboundPacket; |
... | @@ -53,9 +53,7 @@ import org.onosproject.net.proxyarp.ProxyArpStore; | ... | @@ -53,9 +53,7 @@ import org.onosproject.net.proxyarp.ProxyArpStore; |
53 | import org.slf4j.Logger; | 53 | import org.slf4j.Logger; |
54 | 54 | ||
55 | import java.nio.ByteBuffer; | 55 | import java.nio.ByteBuffer; |
56 | -import java.util.HashSet; | ||
57 | import java.util.Set; | 56 | import java.util.Set; |
58 | -import java.util.stream.Collectors; | ||
59 | 57 | ||
60 | import static com.google.common.base.Preconditions.checkArgument; | 58 | import static com.google.common.base.Preconditions.checkArgument; |
61 | import static com.google.common.base.Preconditions.checkNotNull; | 59 | import static com.google.common.base.Preconditions.checkNotNull; |
... | @@ -95,17 +93,15 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -95,17 +93,15 @@ public class ProxyArpManager implements ProxyArpService { |
95 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 93 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
96 | protected ProxyArpStore store; | 94 | protected ProxyArpStore store; |
97 | 95 | ||
98 | - /** | 96 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
99 | - * Listens to both device service and link service to determine | 97 | + protected InterfaceService interfaceService; |
100 | - * whether a port is internal or external. | 98 | + |
101 | - */ | ||
102 | @Activate | 99 | @Activate |
103 | public void activate() { | 100 | public void activate() { |
104 | store.setDelegate(this::sendTo); | 101 | store.setDelegate(this::sendTo); |
105 | log.info("Started"); | 102 | log.info("Started"); |
106 | } | 103 | } |
107 | 104 | ||
108 | - | ||
109 | @Deactivate | 105 | @Deactivate |
110 | public void deactivate() { | 106 | public void deactivate() { |
111 | store.setDelegate(null); | 107 | store.setDelegate(null); |
... | @@ -140,21 +136,18 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -140,21 +136,18 @@ public class ProxyArpManager implements ProxyArpService { |
140 | 136 | ||
141 | VlanId vlan = vlanId(eth.getVlanID()); | 137 | VlanId vlan = vlanId(eth.getVlanID()); |
142 | 138 | ||
143 | - if (isOutsidePort(inPort)) { | 139 | + if (hasIpAddress(inPort)) { |
144 | // If the request came from outside the network, only reply if it was | 140 | // If the request came from outside the network, only reply if it was |
145 | // for one of our external addresses. | 141 | // for one of our external addresses. |
146 | - Set<PortAddresses> addressSet = | ||
147 | - hostService.getAddressBindingsForPort(inPort); | ||
148 | 142 | ||
149 | - for (PortAddresses addresses : addressSet) { | 143 | + interfaceService.getInterfacesByPort(inPort) |
150 | - for (InterfaceIpAddress ia : addresses.ipAddresses()) { | 144 | + .stream() |
151 | - if (ia.ipAddress().equals(targetAddress)) { | 145 | + .filter(intf -> intf.ipAddresses() |
152 | - Ethernet arpReply = | 146 | + .stream() |
153 | - ARP.buildArpReply(targetAddress, addresses.mac(), eth); | 147 | + .anyMatch(ia -> ia.ipAddress().equals(targetAddress))) |
154 | - sendTo(arpReply, inPort); | 148 | + .forEach(intf -> buildAndSendArp(targetAddress, intf.mac(), eth, inPort)); |
155 | - } | 149 | + |
156 | - } | 150 | + // Stop here and don't proxy ARPs if the port has an IP address |
157 | - } | ||
158 | return; | 151 | return; |
159 | } | 152 | } |
160 | 153 | ||
... | @@ -175,8 +168,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -175,8 +168,7 @@ public class ProxyArpManager implements ProxyArpService { |
175 | 168 | ||
176 | if (src != null && dst != null) { | 169 | if (src != null && dst != null) { |
177 | // We know the target host so we can respond | 170 | // We know the target host so we can respond |
178 | - Ethernet arpReply = ARP.buildArpReply(targetAddress, dst.mac(), eth); | 171 | + buildAndSendArp(targetAddress, dst.mac(), eth, inPort); |
179 | - sendTo(arpReply, inPort); | ||
180 | return; | 172 | return; |
181 | } | 173 | } |
182 | 174 | ||
... | @@ -185,27 +177,23 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -185,27 +177,23 @@ public class ProxyArpManager implements ProxyArpService { |
185 | // address. Forward it over to the correct port. | 177 | // address. Forward it over to the correct port. |
186 | Ip4Address source = | 178 | Ip4Address source = |
187 | Ip4Address.valueOf(arp.getSenderProtocolAddress()); | 179 | Ip4Address.valueOf(arp.getSenderProtocolAddress()); |
188 | - Set<PortAddresses> sourceAddresses = findPortsInSubnet(source); | 180 | + |
189 | boolean matched = false; | 181 | boolean matched = false; |
190 | - for (PortAddresses pa : sourceAddresses) { | 182 | + Set<Interface> interfaces = interfaceService.getInterfacesByIp(source); |
191 | - for (InterfaceIpAddress ia : pa.ipAddresses()) { | 183 | + for (Interface intf : interfaces) { |
192 | - if (ia.ipAddress().equals(source) && | 184 | + if (intf.vlan().equals(vlan)) { |
193 | - pa.vlan().equals(vlan)) { | ||
194 | matched = true; | 185 | matched = true; |
195 | - sendTo(eth, pa.connectPoint()); | 186 | + sendTo(eth, intf.connectPoint()); |
196 | break; | 187 | break; |
197 | } | 188 | } |
198 | } | 189 | } |
199 | - } | ||
200 | 190 | ||
201 | if (matched) { | 191 | if (matched) { |
202 | return; | 192 | return; |
203 | } | 193 | } |
204 | 194 | ||
205 | - // | ||
206 | // The request couldn't be resolved. | 195 | // The request couldn't be resolved. |
207 | // Flood the request on all ports except the incoming port. | 196 | // Flood the request on all ports except the incoming port. |
208 | - // | ||
209 | flood(eth, inPort); | 197 | flood(eth, inPort); |
210 | } | 198 | } |
211 | 199 | ||
... | @@ -219,43 +207,15 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -219,43 +207,15 @@ public class ProxyArpManager implements ProxyArpService { |
219 | 207 | ||
220 | // If the request came from outside the network, only reply if it was | 208 | // If the request came from outside the network, only reply if it was |
221 | // for one of our external addresses. | 209 | // for one of our external addresses. |
222 | - if (isOutsidePort(inPort)) { | 210 | + if (hasIpAddress(inPort)) { |
223 | - Set<PortAddresses> addressSet = | 211 | + interfaceService.getInterfacesByPort(inPort) |
224 | - hostService.getAddressBindingsForPort(inPort); | 212 | + .stream() |
225 | - | 213 | + .filter(intf -> intf.ipAddresses() |
226 | - for (PortAddresses addresses : addressSet) { | 214 | + .stream() |
227 | - for (InterfaceIpAddress ia : addresses.ipAddresses()) { | 215 | + .anyMatch(ia -> ia.ipAddress().equals(targetAddress))) |
228 | - if (ia.ipAddress().equals(targetAddress)) { | 216 | + .forEach(intf -> buildAndSendNdp(targetAddress, intf.mac(), eth, inPort)); |
229 | - Ethernet ndpReply = | ||
230 | - buildNdpReply(targetAddress, addresses.mac(), eth); | ||
231 | - sendTo(ndpReply, inPort); | ||
232 | - } | ||
233 | - } | ||
234 | - } | ||
235 | - return; | ||
236 | - } else { | ||
237 | - // If the source address matches one of our external addresses | ||
238 | - // it could be a request from an internal host to an external | ||
239 | - // address. Forward it over to the correct ports. | ||
240 | - Ip6Address source = | ||
241 | - Ip6Address.valueOf(ipv6.getSourceAddress()); | ||
242 | - Set<PortAddresses> sourceAddresses = findPortsInSubnet(source); | ||
243 | - boolean matched = false; | ||
244 | - for (PortAddresses pa : sourceAddresses) { | ||
245 | - for (InterfaceIpAddress ia : pa.ipAddresses()) { | ||
246 | - if (ia.ipAddress().equals(source) && | ||
247 | - pa.vlan().equals(vlan)) { | ||
248 | - matched = true; | ||
249 | - sendTo(eth, pa.connectPoint()); | ||
250 | - break; | ||
251 | - } | ||
252 | - } | ||
253 | - } | ||
254 | - | ||
255 | - if (matched) { | ||
256 | return; | 217 | return; |
257 | } | 218 | } |
258 | - } | ||
259 | 219 | ||
260 | // Continue with normal proxy ARP case | 220 | // Continue with normal proxy ARP case |
261 | 221 | ||
... | @@ -272,22 +232,48 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -272,22 +232,48 @@ public class ProxyArpManager implements ProxyArpService { |
272 | } | 232 | } |
273 | } | 233 | } |
274 | 234 | ||
275 | - if (src == null || dst == null) { | 235 | + if (src != null || dst != null) { |
276 | - // | 236 | + // We know the target host so we can respond |
237 | + buildAndSendNdp(targetAddress, dst.mac(), eth, inPort); | ||
238 | + return; | ||
239 | + } | ||
240 | + | ||
241 | + // If the source address matches one of our external addresses | ||
242 | + // it could be a request from an internal host to an external | ||
243 | + // address. Forward it over to the correct port. | ||
244 | + Ip6Address source = | ||
245 | + Ip6Address.valueOf(ipv6.getSourceAddress()); | ||
246 | + | ||
247 | + boolean matched = false; | ||
248 | + | ||
249 | + Set<Interface> interfaces = interfaceService.getInterfacesByIp(source); | ||
250 | + for (Interface intf : interfaces) { | ||
251 | + if (intf.vlan().equals(vlan)) { | ||
252 | + matched = true; | ||
253 | + sendTo(eth, intf.connectPoint()); | ||
254 | + break; | ||
255 | + } | ||
256 | + } | ||
257 | + | ||
258 | + if (matched) { | ||
259 | + return; | ||
260 | + } | ||
261 | + | ||
277 | // The request couldn't be resolved. | 262 | // The request couldn't be resolved. |
278 | // Flood the request on all ports except the incoming ports. | 263 | // Flood the request on all ports except the incoming ports. |
279 | - // | ||
280 | flood(eth, inPort); | 264 | flood(eth, inPort); |
281 | - return; | ||
282 | } | 265 | } |
266 | + //TODO checkpoint | ||
283 | 267 | ||
284 | - // | 268 | + private void buildAndSendArp(Ip4Address srcIp, MacAddress srcMac, |
285 | - // Reply on the port the request was received on | 269 | + Ethernet request, ConnectPoint port) { |
286 | - // | 270 | + sendTo(ARP.buildArpReply(srcIp, srcMac, request), port); |
287 | - Ethernet ndpReply = buildNdpReply(targetAddress, dst.mac(), eth); | 271 | + } |
288 | - sendTo(ndpReply, inPort); | 272 | + |
273 | + private void buildAndSendNdp(Ip6Address srcIp, MacAddress srcMac, | ||
274 | + Ethernet request, ConnectPoint port) { | ||
275 | + sendTo(buildNdpReply(srcIp, srcMac, request), port); | ||
289 | } | 276 | } |
290 | - //TODO checkpoint | ||
291 | 277 | ||
292 | /** | 278 | /** |
293 | * Outputs the given packet out the given port. | 279 | * Outputs the given packet out the given port. |
... | @@ -314,30 +300,18 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -314,30 +300,18 @@ public class ProxyArpManager implements ProxyArpService { |
314 | } | 300 | } |
315 | 301 | ||
316 | /** | 302 | /** |
317 | - * Finds ports with an address in the subnet of the target address. | 303 | + * Returns whether the given port has any IP addresses configured or not. |
318 | - * | ||
319 | - * @param target the target address to find a matching port for | ||
320 | - * @return a set of PortAddresses describing ports in the subnet | ||
321 | - */ | ||
322 | - private Set<PortAddresses> findPortsInSubnet(IpAddress target) { | ||
323 | - Set<PortAddresses> result = new HashSet<>(); | ||
324 | - for (PortAddresses addresses : hostService.getAddressBindings()) { | ||
325 | - result.addAll(addresses.ipAddresses().stream().filter(ia -> ia.subnetAddress().contains(target)). | ||
326 | - map(ia -> addresses).collect(Collectors.toList())); | ||
327 | - } | ||
328 | - return result; | ||
329 | - } | ||
330 | - | ||
331 | - /** | ||
332 | - * Returns whether the given port is an outside-facing port with an IP | ||
333 | - * address configured. | ||
334 | * | 304 | * |
335 | * @param port the port to check | 305 | * @param port the port to check |
336 | - * @return true if the port is an outside-facing port, otherwise false | 306 | + * @return true if the port has at least one IP address configured, |
307 | + * otherwise false | ||
337 | */ | 308 | */ |
338 | - private boolean isOutsidePort(ConnectPoint port) { | 309 | + private boolean hasIpAddress(ConnectPoint port) { |
339 | - // TODO: Is this sufficient to identify outside-facing ports: just having IP addresses on a port? | 310 | + return interfaceService.getInterfacesByPort(port) |
340 | - return !hostService.getAddressBindingsForPort(port).isEmpty(); | 311 | + .stream() |
312 | + .map(intf -> intf.ipAddresses()) | ||
313 | + .findAny() | ||
314 | + .isPresent(); | ||
341 | } | 315 | } |
342 | 316 | ||
343 | @Override | 317 | @Override |
... | @@ -418,7 +392,7 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -418,7 +392,7 @@ public class ProxyArpManager implements ProxyArpService { |
418 | ByteBuffer buf = ByteBuffer.wrap(request.serialize()); | 392 | ByteBuffer buf = ByteBuffer.wrap(request.serialize()); |
419 | 393 | ||
420 | for (ConnectPoint connectPoint : edgeService.getEdgePoints()) { | 394 | for (ConnectPoint connectPoint : edgeService.getEdgePoints()) { |
421 | - if (isOutsidePort(connectPoint) || connectPoint.equals(inPort)) { | 395 | + if (hasIpAddress(connectPoint) || connectPoint.equals(inPort)) { |
422 | continue; | 396 | continue; |
423 | } | 397 | } |
424 | 398 | ||
... | @@ -427,7 +401,6 @@ public class ProxyArpManager implements ProxyArpService { | ... | @@ -427,7 +401,6 @@ public class ProxyArpManager implements ProxyArpService { |
427 | packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), | 401 | packetService.emit(new DefaultOutboundPacket(connectPoint.deviceId(), |
428 | builder.build(), buf)); | 402 | builder.build(), buf)); |
429 | } | 403 | } |
430 | - | ||
431 | } | 404 | } |
432 | 405 | ||
433 | /** | 406 | /** | ... | ... |
... | @@ -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), | ||
224 | MacAddress.valueOf(2 * i - 1), | 234 | MacAddress.valueOf(2 * i - 1), |
225 | VlanId.vlanId((short) 1)); | 235 | VlanId.vlanId((short) 1)); |
226 | - PortAddresses pa2 = | 236 | + Interface intf2 = new Interface(cp, Sets.newHashSet(ia2), |
227 | - new PortAddresses(cp, Sets.newHashSet(ia2), | ||
228 | MacAddress.valueOf(2 * i), | 237 | MacAddress.valueOf(2 * i), |
229 | VlanId.NONE); | 238 | VlanId.NONE); |
230 | 239 | ||
231 | - addresses.add(pa1); | 240 | + interfaces.add(intf1); |
232 | - addresses.add(pa2); | 241 | + interfaces.add(intf2); |
233 | 242 | ||
234 | - expect(hostService.getAddressBindingsForPort(cp)) | 243 | + expect(interfaceService.getInterfacesByPort(cp)) |
235 | - .andReturn(Sets.newHashSet(pa1, pa2)).anyTimes(); | 244 | + .andReturn(Sets.newHashSet(intf1, intf2)).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++) { | ... | ... |
incubator/api/src/main/java/org/onosproject/incubator/net/config/basics/ConfigException.java
0 → 100644
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 | ||
52 | + try { | ||
47 | for (JsonNode intfNode : node.path(INTERFACES)) { | 53 | for (JsonNode intfNode : node.path(INTERFACES)) { |
48 | - interfaces.add(new Interface(subject, | 54 | + Set<InterfaceIpAddress> ips = getIps(intfNode); |
49 | - getIps(intfNode), | 55 | + if (ips.isEmpty()) { |
50 | - MacAddress.valueOf(intfNode.path(MAC).asText()), | 56 | + throw new ConfigException(IP_MISSING_ERROR); |
51 | - VlanId.vlanId(Short.parseShort(intfNode.path(VLAN).asText())))); | 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,16 +68,14 @@ public class InterfaceManager implements InterfaceService { | ... | @@ -69,16 +68,14 @@ 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 | } | 77 | } |
80 | } | 78 | } |
81 | - } | ||
82 | 79 | ||
83 | log.info("Started"); | 80 | log.info("Started"); |
84 | } | 81 | } |
... | @@ -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) { |
145 | + try { | ||
142 | interfaces.put(intfConfig.subject(), intfConfig.getInterfaces()); | 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) { | ... | ... |
-
Please register or login to post a comment