Committed by
Brian O'Connor
ONOS-5236 - Adapt SDN-IP to the new intent framework APIs
Change-Id: I89b60602247a25a1879e4394a60c57d480881f74
Showing
10 changed files
with
563 additions
and
1149 deletions
| ... | @@ -21,6 +21,8 @@ import org.apache.felix.scr.annotations.Component; | ... | @@ -21,6 +21,8 @@ import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | +import org.onlab.packet.Ethernet; | ||
| 25 | +import org.onlab.packet.VlanId; | ||
| 24 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
| 25 | import org.onosproject.core.CoreService; | 27 | import org.onosproject.core.CoreService; |
| 26 | import org.onosproject.incubator.net.intf.Interface; | 28 | import org.onosproject.incubator.net.intf.Interface; |
| ... | @@ -42,8 +44,6 @@ import org.onosproject.routing.config.BgpConfig; | ... | @@ -42,8 +44,6 @@ import org.onosproject.routing.config.BgpConfig; |
| 42 | import java.util.HashSet; | 44 | import java.util.HashSet; |
| 43 | import java.util.Set; | 45 | import java.util.Set; |
| 44 | 46 | ||
| 45 | -import static org.onosproject.net.HostId.hostId; | ||
| 46 | - | ||
| 47 | /** | 47 | /** |
| 48 | * Manages neighbour message handlers for the use case of internal BGP speakers | 48 | * Manages neighbour message handlers for the use case of internal BGP speakers |
| 49 | * connected to the network at some point that are exchanging neighbour | 49 | * connected to the network at some point that are exchanging neighbour |
| ... | @@ -154,11 +154,18 @@ public class BgpSpeakerNeighbourHandler { | ... | @@ -154,11 +154,18 @@ public class BgpSpeakerNeighbourHandler { |
| 154 | case REPLY: | 154 | case REPLY: |
| 155 | // Proxy replies over to our internal BGP speaker if the host | 155 | // Proxy replies over to our internal BGP speaker if the host |
| 156 | // is known to us | 156 | // is known to us |
| 157 | - Host h = hostService.getHost(hostId(context.dstMac(), context.vlan())); | 157 | + Host h = hostService.getHostsByMac(context.dstMac()).stream() |
| 158 | - | 158 | + .findFirst() |
| 159 | + .get(); | ||
| 159 | if (h == null) { | 160 | if (h == null) { |
| 160 | context.drop(); | 161 | context.drop(); |
| 161 | } else { | 162 | } else { |
| 163 | + VlanId bgpSpeakerVlanId = h.vlan(); | ||
| 164 | + if (!bgpSpeakerVlanId.equals(VlanId.NONE)) { | ||
| 165 | + context.packet().setVlanID(bgpSpeakerVlanId.toShort()); | ||
| 166 | + } else { | ||
| 167 | + context.packet().setVlanID(Ethernet.VLAN_UNTAGGED); | ||
| 168 | + } | ||
| 162 | context.forward(h.location()); | 169 | context.forward(h.location()); |
| 163 | } | 170 | } |
| 164 | break; | 171 | break; |
| ... | @@ -179,9 +186,6 @@ public class BgpSpeakerNeighbourHandler { | ... | @@ -179,9 +186,6 @@ public class BgpSpeakerNeighbourHandler { |
| 179 | // For messages coming from a BGP speaker, look at the sender address | 186 | // For messages coming from a BGP speaker, look at the sender address |
| 180 | // to find the interface to proxy to | 187 | // to find the interface to proxy to |
| 181 | interfaceService.getInterfacesByIp(context.sender()) | 188 | interfaceService.getInterfacesByIp(context.sender()) |
| 182 | - .stream() | ||
| 183 | - .filter(intf -> intf.vlan().equals(context.vlan())) | ||
| 184 | - .map(intf -> intf.connectPoint()) | ||
| 185 | .forEach(context::forward); | 189 | .forEach(context::forward); |
| 186 | } | 190 | } |
| 187 | } | 191 | } | ... | ... |
| ... | @@ -239,16 +239,9 @@ public class PeerConnectivityManager { | ... | @@ -239,16 +239,9 @@ public class PeerConnectivityManager { |
| 239 | } | 239 | } |
| 240 | 240 | ||
| 241 | // Add VLAN treatment for traffic going from BGP speaker to BGP peer | 241 | // Add VLAN treatment for traffic going from BGP speaker to BGP peer |
| 242 | - if (!vlanOne.equals(vlanTwo)) { | 242 | + treatmentToPeer = applyVlanTreatment(vlanOne, vlanTwo, treatmentToPeer); |
| 243 | - if (vlanTwo.equals(VlanId.NONE)) { | ||
| 244 | - treatmentToPeer.popVlan(); | ||
| 245 | - } else { | ||
| 246 | - treatmentToPeer.setVlanId(vlanTwo); | ||
| 247 | - } | ||
| 248 | - } | ||
| 249 | 243 | ||
| 250 | // Path from BGP speaker to BGP peer matching destination TCP port 179 | 244 | // Path from BGP speaker to BGP peer matching destination TCP port 179 |
| 251 | - | ||
| 252 | selector = buildSelector(tcpProtocol, | 245 | selector = buildSelector(tcpProtocol, |
| 253 | vlanOne, | 246 | vlanOne, |
| 254 | ipOne, | 247 | ipOne, |
| ... | @@ -309,13 +302,7 @@ public class PeerConnectivityManager { | ... | @@ -309,13 +302,7 @@ public class PeerConnectivityManager { |
| 309 | .build()); | 302 | .build()); |
| 310 | 303 | ||
| 311 | // Add VLAN treatment for traffic going from BGP peer to BGP speaker | 304 | // Add VLAN treatment for traffic going from BGP peer to BGP speaker |
| 312 | - if (!vlanTwo.equals(vlanOne)) { | 305 | + treatmentToSpeaker = applyVlanTreatment(vlanTwo, vlanOne, treatmentToSpeaker); |
| 313 | - if (vlanOne.equals(VlanId.NONE)) { | ||
| 314 | - treatmentToSpeaker.popVlan(); | ||
| 315 | - } else { | ||
| 316 | - treatmentToSpeaker.setVlanId(vlanOne); | ||
| 317 | - } | ||
| 318 | - } | ||
| 319 | 306 | ||
| 320 | // Path from BGP peer to BGP speaker matching destination TCP port 179 | 307 | // Path from BGP peer to BGP speaker matching destination TCP port 179 |
| 321 | selector = buildSelector(tcpProtocol, | 308 | selector = buildSelector(tcpProtocol, |
| ... | @@ -396,9 +383,9 @@ public class PeerConnectivityManager { | ... | @@ -396,9 +383,9 @@ public class PeerConnectivityManager { |
| 396 | Short dstTcpPort) { | 383 | Short dstTcpPort) { |
| 397 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); | 384 | TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); |
| 398 | 385 | ||
| 399 | - // Match on any VLAN Id if a VLAN Id configured on the ingress interface | 386 | + // Match on VLAN Id if a VLAN Id configured on the ingress interface |
| 400 | if (!ingressVlanId.equals(VlanId.NONE)) { | 387 | if (!ingressVlanId.equals(VlanId.NONE)) { |
| 401 | - builder.matchVlanId(VlanId.ANY); | 388 | + builder.matchVlanId(ingressVlanId); |
| 402 | } | 389 | } |
| 403 | 390 | ||
| 404 | if (dstIp.isIp4()) { | 391 | if (dstIp.isIp4()) { |
| ... | @@ -422,6 +409,31 @@ public class PeerConnectivityManager { | ... | @@ -422,6 +409,31 @@ public class PeerConnectivityManager { |
| 422 | return builder.build(); | 409 | return builder.build(); |
| 423 | } | 410 | } |
| 424 | 411 | ||
| 412 | + /* | ||
| 413 | + * Adds the VLAN Id treatment before building the intents, depending on how | ||
| 414 | + * the VLAN Ids of the BGP speakers and the BGP peers are configured. | ||
| 415 | + */ | ||
| 416 | + private TrafficTreatment.Builder applyVlanTreatment(VlanId vlanOne, | ||
| 417 | + VlanId vlanTwo, | ||
| 418 | + TrafficTreatment.Builder treatment) { | ||
| 419 | + if (!vlanOne.equals(vlanTwo)) { | ||
| 420 | + // VLANs are different. Do some VLAN treatment | ||
| 421 | + if (vlanTwo.equals(VlanId.NONE)) { | ||
| 422 | + // VLAN two is none. VLAN one is set. Do a pop | ||
| 423 | + treatment.popVlan(); | ||
| 424 | + } else { | ||
| 425 | + // Either both VLANs are set or vlanOne is not | ||
| 426 | + if (vlanOne.equals(VlanId.NONE)) { | ||
| 427 | + // VLAN one is none. VLAN two is set. Push the VLAN header | ||
| 428 | + treatment.pushVlan(); | ||
| 429 | + } | ||
| 430 | + // Set the VLAN Id to the egress VLAN Id | ||
| 431 | + treatment.setVlanId(vlanTwo); | ||
| 432 | + } | ||
| 433 | + } | ||
| 434 | + return treatment; | ||
| 435 | + } | ||
| 436 | + | ||
| 425 | /** | 437 | /** |
| 426 | * Builds an intent Key for a point-to-point intent based off the source | 438 | * Builds an intent Key for a point-to-point intent based off the source |
| 427 | * and destination IP address, as well as a suffix String to distinguish | 439 | * and destination IP address, as well as a suffix String to distinguish | ... | ... |
| ... | @@ -39,6 +39,7 @@ import org.onosproject.incubator.net.routing.RouteEvent; | ... | @@ -39,6 +39,7 @@ import org.onosproject.incubator.net.routing.RouteEvent; |
| 39 | import org.onosproject.incubator.net.routing.RouteListener; | 39 | import org.onosproject.incubator.net.routing.RouteListener; |
| 40 | import org.onosproject.incubator.net.routing.RouteService; | 40 | import org.onosproject.incubator.net.routing.RouteService; |
| 41 | import org.onosproject.net.ConnectPoint; | 41 | import org.onosproject.net.ConnectPoint; |
| 42 | +import org.onosproject.net.FilteredConnectPoint; | ||
| 42 | import org.onosproject.net.flow.DefaultTrafficSelector; | 43 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 43 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 44 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 44 | import org.onosproject.net.flow.TrafficSelector; | 45 | import org.onosproject.net.flow.TrafficSelector; |
| ... | @@ -51,7 +52,6 @@ import org.onosproject.routing.IntentSynchronizationService; | ... | @@ -51,7 +52,6 @@ import org.onosproject.routing.IntentSynchronizationService; |
| 51 | import org.slf4j.Logger; | 52 | import org.slf4j.Logger; |
| 52 | import org.slf4j.LoggerFactory; | 53 | import org.slf4j.LoggerFactory; |
| 53 | 54 | ||
| 54 | -import java.util.HashSet; | ||
| 55 | import java.util.Map; | 55 | import java.util.Map; |
| 56 | import java.util.Set; | 56 | import java.util.Set; |
| 57 | import java.util.concurrent.ConcurrentHashMap; | 57 | import java.util.concurrent.ConcurrentHashMap; |
| ... | @@ -160,66 +160,33 @@ public class SdnIpFib { | ... | @@ -160,66 +160,33 @@ public class SdnIpFib { |
| 160 | } | 160 | } |
| 161 | ConnectPoint egressPort = egressInterface.connectPoint(); | 161 | ConnectPoint egressPort = egressInterface.connectPoint(); |
| 162 | 162 | ||
| 163 | - Set<Interface> ingressInterfaces = new HashSet<>(); | ||
| 164 | - Set<ConnectPoint> ingressPorts = new HashSet<>(); | ||
| 165 | log.debug("Generating intent for prefix {}, next hop mac {}", | 163 | log.debug("Generating intent for prefix {}, next hop mac {}", |
| 166 | prefix, nextHopMacAddress); | 164 | prefix, nextHopMacAddress); |
| 167 | 165 | ||
| 168 | - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | 166 | + Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); |
| 169 | 167 | ||
| 170 | - // Get ingress interfaces and ports | ||
| 171 | // TODO this should be only peering interfaces | 168 | // TODO this should be only peering interfaces |
| 172 | interfaceService.getInterfaces().stream() | 169 | interfaceService.getInterfaces().stream() |
| 173 | - .filter(intf -> !intf.equals(egressInterface)) | ||
| 174 | - .filter(intf -> !intf.connectPoint().equals(egressPort)) | ||
| 175 | .forEach(intf -> { | 170 | .forEach(intf -> { |
| 176 | - ingressInterfaces.add(intf); | 171 | + // Get ony ingress interfaces with IPs configured |
| 177 | - ConnectPoint ingressPort = intf.connectPoint(); | 172 | + if (validIngressIntf(intf, egressInterface)) { |
| 178 | - ingressPorts.add(ingressPort); | 173 | + TrafficSelector.Builder selector = |
| 174 | + buildIngressTrafficSelector(intf, prefix); | ||
| 175 | + FilteredConnectPoint ingressFilteredCP = | ||
| 176 | + new FilteredConnectPoint(intf.connectPoint(), selector.build()); | ||
| 177 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 178 | + } | ||
| 179 | }); | 179 | }); |
| 180 | 180 | ||
| 181 | - // By default the ingress traffic is not tagged | 181 | + // Build treatment: rewrite the destination MAC address |
| 182 | - VlanId ingressVlanId = VlanId.NONE; | ||
| 183 | - | ||
| 184 | - // Match VLAN Id ANY if the source VLAN Id is not null | ||
| 185 | - // TODO need to be able to set a different VLAN Id per ingress interface | ||
| 186 | - for (Interface intf : ingressInterfaces) { | ||
| 187 | - if (!intf.vlan().equals(VlanId.NONE)) { | ||
| 188 | - selector.matchVlanId(VlanId.ANY); | ||
| 189 | - ingressVlanId = intf.vlan(); | ||
| 190 | - } | ||
| 191 | - } | ||
| 192 | - | ||
| 193 | - // Match the destination IP prefix at the first hop | ||
| 194 | - if (prefix.isIp4()) { | ||
| 195 | - selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 196 | - // if it is default route, then we do not need match destination | ||
| 197 | - // IP address | ||
| 198 | - if (prefix.prefixLength() != 0) { | ||
| 199 | - selector.matchIPDst(prefix); | ||
| 200 | - } | ||
| 201 | - } else { | ||
| 202 | - selector.matchEthType(Ethernet.TYPE_IPV6); | ||
| 203 | - // if it is default route, then we do not need match destination | ||
| 204 | - // IP address | ||
| 205 | - if (prefix.prefixLength() != 0) { | ||
| 206 | - selector.matchIPv6Dst(prefix); | ||
| 207 | - } | ||
| 208 | - } | ||
| 209 | - | ||
| 210 | - // Rewrite the destination MAC address | ||
| 211 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() | 182 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder() |
| 212 | .setEthDst(nextHopMacAddress); | 183 | .setEthDst(nextHopMacAddress); |
| 213 | 184 | ||
| 214 | - // Set egress VLAN Id | 185 | + // Build the egress selector for VLAN Id |
| 215 | - // TODO need to make the comparison with different ingress VLAN Ids | 186 | + TrafficSelector.Builder selector = |
| 216 | - if (!ingressVlanId.equals(egressInterface.vlan())) { | 187 | + buildTrafficSelector(egressInterface); |
| 217 | - if (egressInterface.vlan().equals(VlanId.NONE)) { | 188 | + FilteredConnectPoint egressFilteredCP = |
| 218 | - treatment.popVlan(); | 189 | + new FilteredConnectPoint(egressPort, selector.build()); |
| 219 | - } else { | ||
| 220 | - treatment.setVlanId(egressInterface.vlan()); | ||
| 221 | - } | ||
| 222 | - } | ||
| 223 | 190 | ||
| 224 | // Set priority | 191 | // Set priority |
| 225 | int priority = | 192 | int priority = |
| ... | @@ -231,25 +198,38 @@ public class SdnIpFib { | ... | @@ -231,25 +198,38 @@ public class SdnIpFib { |
| 231 | return MultiPointToSinglePointIntent.builder() | 198 | return MultiPointToSinglePointIntent.builder() |
| 232 | .appId(appId) | 199 | .appId(appId) |
| 233 | .key(key) | 200 | .key(key) |
| 234 | - .selector(selector.build()) | 201 | + .filteredIngressPoints(ingressFilteredCPs) |
| 202 | + .filteredEgressPoint(egressFilteredCP) | ||
| 235 | .treatment(treatment.build()) | 203 | .treatment(treatment.build()) |
| 236 | - .ingressPoints(ingressPorts) | ||
| 237 | - .egressPoint(egressPort) | ||
| 238 | .priority(priority) | 204 | .priority(priority) |
| 239 | .constraints(CONSTRAINTS) | 205 | .constraints(CONSTRAINTS) |
| 240 | .build(); | 206 | .build(); |
| 241 | } | 207 | } |
| 242 | 208 | ||
| 243 | - private void updateInterface(Interface intf) { | 209 | + private void addInterface(Interface intf) { |
| 244 | synchronized (this) { | 210 | synchronized (this) { |
| 245 | for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { | 211 | for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { |
| 212 | + // Retrieve the IP prefix and affected intent | ||
| 213 | + IpPrefix prefix = entry.getKey(); | ||
| 246 | MultiPointToSinglePointIntent intent = entry.getValue(); | 214 | MultiPointToSinglePointIntent intent = entry.getValue(); |
| 247 | - Set<ConnectPoint> ingress = Sets.newHashSet(intent.ingressPoints()); | ||
| 248 | - ingress.add(intf.connectPoint()); | ||
| 249 | 215 | ||
| 216 | + // Add new ingress FilteredConnectPoint | ||
| 217 | + Set<FilteredConnectPoint> ingressFilteredCPs = | ||
| 218 | + Sets.newHashSet(intent.filteredIngressPoints()); | ||
| 219 | + | ||
| 220 | + // Create the new traffic selector | ||
| 221 | + TrafficSelector.Builder selector = | ||
| 222 | + buildIngressTrafficSelector(intf, prefix); | ||
| 223 | + | ||
| 224 | + // Create the Filtered ConnectPoint and add it to the existing set | ||
| 225 | + FilteredConnectPoint newIngressFilteredCP = | ||
| 226 | + new FilteredConnectPoint(intf.connectPoint(), selector.build()); | ||
| 227 | + ingressFilteredCPs.add(newIngressFilteredCP); | ||
| 228 | + | ||
| 229 | + // Create new intent | ||
| 250 | MultiPointToSinglePointIntent newIntent = | 230 | MultiPointToSinglePointIntent newIntent = |
| 251 | MultiPointToSinglePointIntent.builder(intent) | 231 | MultiPointToSinglePointIntent.builder(intent) |
| 252 | - .ingressPoints(ingress) | 232 | + .filteredIngressPoints(ingressFilteredCPs) |
| 253 | .build(); | 233 | .build(); |
| 254 | 234 | ||
| 255 | routeIntents.put(entry.getKey(), newIntent); | 235 | routeIntents.put(entry.getKey(), newIntent); |
| ... | @@ -258,33 +238,119 @@ public class SdnIpFib { | ... | @@ -258,33 +238,119 @@ public class SdnIpFib { |
| 258 | } | 238 | } |
| 259 | } | 239 | } |
| 260 | 240 | ||
| 241 | + /* | ||
| 242 | + * Handles the case in which an existing interface gets removed. | ||
| 243 | + */ | ||
| 261 | private void removeInterface(Interface intf) { | 244 | private void removeInterface(Interface intf) { |
| 262 | synchronized (this) { | 245 | synchronized (this) { |
| 263 | for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { | 246 | for (Map.Entry<IpPrefix, MultiPointToSinglePointIntent> entry : routeIntents.entrySet()) { |
| 247 | + // Retrieve the IP prefix and intent possibly affected | ||
| 248 | + IpPrefix prefix = entry.getKey(); | ||
| 264 | MultiPointToSinglePointIntent intent = entry.getValue(); | 249 | MultiPointToSinglePointIntent intent = entry.getValue(); |
| 265 | - if (intent.egressPoint().equals(intf.connectPoint())) { | 250 | + |
| 266 | - // This intent just lost its head. Remove it and let | 251 | + // The interface removed might be an ingress interface, so the |
| 267 | - // higher layer routing reroute. | 252 | + // selector needs to match on the interface tagging params and |
| 253 | + // on the prefix | ||
| 254 | + TrafficSelector.Builder ingressSelector = | ||
| 255 | + buildIngressTrafficSelector(intf, prefix); | ||
| 256 | + FilteredConnectPoint removedIngressFilteredCP = | ||
| 257 | + new FilteredConnectPoint(intf.connectPoint(), | ||
| 258 | + ingressSelector.build()); | ||
| 259 | + | ||
| 260 | + // The interface removed might be an egress interface, so the | ||
| 261 | + // selector needs to match only on the interface tagging params | ||
| 262 | + TrafficSelector.Builder selector = buildTrafficSelector(intf); | ||
| 263 | + FilteredConnectPoint removedEgressFilteredCP = | ||
| 264 | + new FilteredConnectPoint(intf.connectPoint(), selector.build()); | ||
| 265 | + | ||
| 266 | + if (intent.filteredEgressPoint().equals(removedEgressFilteredCP)) { | ||
| 267 | + // The interface is an egress interface for the intent. | ||
| 268 | + // This intent just lost its head. Remove it and let higher | ||
| 269 | + // layer routing reroute | ||
| 268 | intentSynchronizer.withdraw(routeIntents.remove(entry.getKey())); | 270 | intentSynchronizer.withdraw(routeIntents.remove(entry.getKey())); |
| 269 | } else { | 271 | } else { |
| 270 | - if (intent.ingressPoints().contains(intf.connectPoint())) { | 272 | + if (intent.filteredIngressPoints().contains(removedIngressFilteredCP)) { |
| 271 | - | 273 | + // The FilteredConnectPoint is an ingress |
| 272 | - Set<ConnectPoint> ingress = Sets.newHashSet(intent.ingressPoints()); | 274 | + // FilteredConnectPoint for the intent |
| 273 | - ingress.remove(intf.connectPoint()); | 275 | + Set<FilteredConnectPoint> ingressFilteredCPs = |
| 274 | - | 276 | + Sets.newHashSet(intent.filteredIngressPoints()); |
| 275 | - MultiPointToSinglePointIntent newIntent = | 277 | + |
| 276 | - MultiPointToSinglePointIntent.builder(intent) | 278 | + // Remove FilteredConnectPoint from the existing set |
| 277 | - .ingressPoints(ingress) | 279 | + ingressFilteredCPs.remove(removedIngressFilteredCP); |
| 278 | - .build(); | 280 | + |
| 279 | - | 281 | + if (!ingressFilteredCPs.isEmpty()) { |
| 280 | - routeIntents.put(entry.getKey(), newIntent); | 282 | + // There are still ingress points. Create a new |
| 281 | - intentSynchronizer.submit(newIntent); | 283 | + // intent and resubmit |
| 284 | + MultiPointToSinglePointIntent newIntent = | ||
| 285 | + MultiPointToSinglePointIntent.builder(intent) | ||
| 286 | + .filteredIngressPoints(ingressFilteredCPs) | ||
| 287 | + .build(); | ||
| 288 | + | ||
| 289 | + routeIntents.put(entry.getKey(), newIntent); | ||
| 290 | + intentSynchronizer.submit(newIntent); | ||
| 291 | + } else { | ||
| 292 | + // No more ingress FilteredConnectPoint. Withdraw | ||
| 293 | + //the intent | ||
| 294 | + intentSynchronizer.withdraw(routeIntents.remove(entry.getKey())); | ||
| 295 | + } | ||
| 282 | } | 296 | } |
| 283 | } | 297 | } |
| 284 | } | 298 | } |
| 285 | } | 299 | } |
| 286 | } | 300 | } |
| 287 | 301 | ||
| 302 | + /* | ||
| 303 | + * Builds an ingress traffic selector builder given an ingress interface and | ||
| 304 | + * the IP prefix to be reached. | ||
| 305 | + */ | ||
| 306 | + private TrafficSelector.Builder buildIngressTrafficSelector(Interface intf, IpPrefix prefix) { | ||
| 307 | + TrafficSelector.Builder selector = buildTrafficSelector(intf); | ||
| 308 | + | ||
| 309 | + // Match the destination IP prefix at the first hop | ||
| 310 | + if (prefix.isIp4()) { | ||
| 311 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 312 | + // if it is default route, then we do not need match destination | ||
| 313 | + // IP address | ||
| 314 | + if (prefix.prefixLength() != 0) { | ||
| 315 | + selector.matchIPDst(prefix); | ||
| 316 | + } | ||
| 317 | + } else { | ||
| 318 | + selector.matchEthType(Ethernet.TYPE_IPV6); | ||
| 319 | + // if it is default route, then we do not need match destination | ||
| 320 | + // IP address | ||
| 321 | + if (prefix.prefixLength() != 0) { | ||
| 322 | + selector.matchIPv6Dst(prefix); | ||
| 323 | + } | ||
| 324 | + } | ||
| 325 | + return selector; | ||
| 326 | + } | ||
| 327 | + | ||
| 328 | + /* | ||
| 329 | + * Builds a traffic selector builder based on interface tagging settings. | ||
| 330 | + */ | ||
| 331 | + private TrafficSelector.Builder buildTrafficSelector(Interface intf) { | ||
| 332 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 333 | + | ||
| 334 | + // TODO: Consider other tag types | ||
| 335 | + // Match the VlanId if specified in the network interface configuration | ||
| 336 | + VlanId vlanId = intf.vlan(); | ||
| 337 | + if (!vlanId.equals(VlanId.NONE)) { | ||
| 338 | + selector.matchVlanId(vlanId); | ||
| 339 | + } | ||
| 340 | + return selector; | ||
| 341 | + } | ||
| 342 | + | ||
| 343 | + // Check if the interface is an ingress interface with IPs configured | ||
| 344 | + private boolean validIngressIntf(Interface intf, Interface egressInterface) { | ||
| 345 | + if (!intf.equals(egressInterface) && | ||
| 346 | + !intf.ipAddressesList().isEmpty() && | ||
| 347 | + // TODO: An egress point might have two routers connected on different interfaces | ||
| 348 | + !intf.connectPoint().equals(egressInterface.connectPoint())) { | ||
| 349 | + return true; | ||
| 350 | + } | ||
| 351 | + return false; | ||
| 352 | + } | ||
| 353 | + | ||
| 288 | private class InternalRouteListener implements RouteListener { | 354 | private class InternalRouteListener implements RouteListener { |
| 289 | @Override | 355 | @Override |
| 290 | public void event(RouteEvent event) { | 356 | public void event(RouteEvent event) { |
| ... | @@ -308,9 +374,11 @@ public class SdnIpFib { | ... | @@ -308,9 +374,11 @@ public class SdnIpFib { |
| 308 | public void event(InterfaceEvent event) { | 374 | public void event(InterfaceEvent event) { |
| 309 | switch (event.type()) { | 375 | switch (event.type()) { |
| 310 | case INTERFACE_ADDED: | 376 | case INTERFACE_ADDED: |
| 311 | - updateInterface(event.subject()); | 377 | + addInterface(event.subject()); |
| 312 | break; | 378 | break; |
| 313 | case INTERFACE_UPDATED: | 379 | case INTERFACE_UPDATED: |
| 380 | + removeInterface(event.prevSubject()); | ||
| 381 | + addInterface(event.subject()); | ||
| 314 | break; | 382 | break; |
| 315 | case INTERFACE_REMOVED: | 383 | case INTERFACE_REMOVED: |
| 316 | removeInterface(event.subject()); | 384 | removeInterface(event.subject()); | ... | ... |
| ... | @@ -316,7 +316,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -316,7 +316,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 316 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); | 316 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
| 317 | 317 | ||
| 318 | if (!srcVlanId.equals(VlanId.NONE)) { | 318 | if (!srcVlanId.equals(VlanId.NONE)) { |
| 319 | - builder.matchVlanId(VlanId.ANY); | 319 | + builder.matchVlanId(srcVlanId); |
| 320 | } | 320 | } |
| 321 | 321 | ||
| 322 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 322 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); |
| ... | @@ -495,7 +495,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { | ... | @@ -495,7 +495,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest { |
| 495 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); | 495 | .matchIPDst(IpPrefix.valueOf(dstPrefix)); |
| 496 | 496 | ||
| 497 | if (!srcVlanId.equals(VlanId.NONE)) { | 497 | if (!srcVlanId.equals(VlanId.NONE)) { |
| 498 | - builder.matchVlanId(VlanId.ANY); | 498 | + builder.matchVlanId(srcVlanId); |
| 499 | } | 499 | } |
| 500 | 500 | ||
| 501 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | 501 | TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); | ... | ... |
| 1 | -/* | ||
| 2 | - * Copyright 2016-present 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.sdnip; | ||
| 18 | - | ||
| 19 | -import com.google.common.collect.Lists; | ||
| 20 | -import com.google.common.collect.Sets; | ||
| 21 | -import org.junit.Before; | ||
| 22 | -import org.junit.Test; | ||
| 23 | -import org.onlab.packet.Ethernet; | ||
| 24 | -import org.onlab.packet.Ip4Address; | ||
| 25 | -import org.onlab.packet.Ip4Prefix; | ||
| 26 | -import org.onlab.packet.IpPrefix; | ||
| 27 | -import org.onlab.packet.MacAddress; | ||
| 28 | -import org.onlab.packet.VlanId; | ||
| 29 | -import org.onosproject.TestApplicationId; | ||
| 30 | -import org.onosproject.core.ApplicationId; | ||
| 31 | -import org.onosproject.core.CoreServiceAdapter; | ||
| 32 | -import org.onosproject.incubator.net.intf.Interface; | ||
| 33 | -import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 34 | -import org.onosproject.incubator.net.intf.InterfaceService; | ||
| 35 | -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
| 36 | -import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
| 37 | -import org.onosproject.incubator.net.routing.RouteEvent; | ||
| 38 | -import org.onosproject.incubator.net.routing.RouteListener; | ||
| 39 | -import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
| 40 | -import org.onosproject.net.ConnectPoint; | ||
| 41 | -import org.onosproject.net.DeviceId; | ||
| 42 | -import org.onosproject.net.PortNumber; | ||
| 43 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 44 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 45 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 46 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 47 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
| 48 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
| 49 | -import org.onosproject.net.intent.Key; | ||
| 50 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
| 51 | -import org.onosproject.routing.IntentSynchronizationService; | ||
| 52 | - | ||
| 53 | -import java.util.Collections; | ||
| 54 | -import java.util.HashSet; | ||
| 55 | -import java.util.List; | ||
| 56 | -import java.util.Set; | ||
| 57 | - | ||
| 58 | -import static org.easymock.EasyMock.*; | ||
| 59 | -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
| 60 | - | ||
| 61 | -/** | ||
| 62 | - * Unit tests for SdnIpFib. | ||
| 63 | - */ | ||
| 64 | -public class SdnIpFibNoVlanstoVlanTest extends AbstractIntentTest { | ||
| 65 | - | ||
| 66 | - private InterfaceService interfaceService; | ||
| 67 | - | ||
| 68 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
| 69 | - DeviceId.deviceId("of:0000000000000001"), | ||
| 70 | - PortNumber.portNumber(1)); | ||
| 71 | - | ||
| 72 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
| 73 | - DeviceId.deviceId("of:0000000000000002"), | ||
| 74 | - PortNumber.portNumber(1)); | ||
| 75 | - | ||
| 76 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
| 77 | - DeviceId.deviceId("of:0000000000000003"), | ||
| 78 | - PortNumber.portNumber(1)); | ||
| 79 | - | ||
| 80 | - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
| 81 | - | ||
| 82 | - private SdnIpFib sdnipFib; | ||
| 83 | - private IntentSynchronizationService intentSynchronizer; | ||
| 84 | - private final Set<Interface> interfaces = Sets.newHashSet(); | ||
| 85 | - | ||
| 86 | - private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
| 87 | - | ||
| 88 | - private RouteListener routeListener; | ||
| 89 | - private InterfaceListener interfaceListener; | ||
| 90 | - | ||
| 91 | - @Before | ||
| 92 | - public void setUp() throws Exception { | ||
| 93 | - super.setUp(); | ||
| 94 | - | ||
| 95 | - interfaceService = createMock(InterfaceService.class); | ||
| 96 | - | ||
| 97 | - interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 98 | - expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
| 99 | - | ||
| 100 | - // These will set expectations on routingConfig and interfaceService | ||
| 101 | - setUpInterfaceService(); | ||
| 102 | - | ||
| 103 | - replay(interfaceService); | ||
| 104 | - | ||
| 105 | - intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
| 106 | - | ||
| 107 | - sdnipFib = new SdnIpFib(); | ||
| 108 | - sdnipFib.routeService = new TestRouteService(); | ||
| 109 | - sdnipFib.coreService = new TestCoreService(); | ||
| 110 | - sdnipFib.interfaceService = interfaceService; | ||
| 111 | - sdnipFib.intentSynchronizer = intentSynchronizer; | ||
| 112 | - | ||
| 113 | - sdnipFib.activate(); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | - * Sets up the interface service. | ||
| 118 | - */ | ||
| 119 | - private void setUpInterfaceService() { | ||
| 120 | - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
| 121 | - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
| 122 | - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
| 123 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
| 124 | - VlanId.NONE); | ||
| 125 | - interfaces.add(sw1Eth1); | ||
| 126 | - | ||
| 127 | - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
| 128 | - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
| 129 | - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
| 130 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
| 131 | - VlanId.NONE); | ||
| 132 | - interfaces.add(sw2Eth1); | ||
| 133 | - | ||
| 134 | - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
| 135 | - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
| 136 | - Lists.newArrayList(interfaceIpAddress3), | ||
| 137 | - MacAddress.valueOf("00:00:00:00:00:03"), | ||
| 138 | - VlanId.vlanId((short) 1)); | ||
| 139 | - interfaces.add(sw3Eth1); | ||
| 140 | - | ||
| 141 | - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
| 142 | - Collections.singleton(sw1Eth1)).anyTimes(); | ||
| 143 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
| 144 | - .andReturn(sw1Eth1).anyTimes(); | ||
| 145 | - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
| 146 | - Collections.singleton(sw2Eth1)).anyTimes(); | ||
| 147 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
| 148 | - .andReturn(sw2Eth1).anyTimes(); | ||
| 149 | - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
| 150 | - Collections.singleton(sw3Eth1)).anyTimes(); | ||
| 151 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
| 152 | - .andReturn(sw3Eth1).anyTimes(); | ||
| 153 | - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - /** | ||
| 157 | - * Tests adding a route. Ingresses with no VLAN and next hop with VLAN. | ||
| 158 | - * | ||
| 159 | - * We verify that the synchronizer records the correct state and that the | ||
| 160 | - * correct intent is submitted to the IntentService. | ||
| 161 | - */ | ||
| 162 | - @Test | ||
| 163 | - public void testRouteAdd() { | ||
| 164 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
| 165 | - Ip4Address.valueOf("192.168.30.1"), | ||
| 166 | - MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 167 | - | ||
| 168 | - // Construct a MultiPointToSinglePointIntent intent | ||
| 169 | - TrafficSelector.Builder selectorBuilder = | ||
| 170 | - DefaultTrafficSelector.builder(); | ||
| 171 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4) | ||
| 172 | - .matchIPDst(PREFIX1); | ||
| 173 | - | ||
| 174 | - TrafficTreatment.Builder treatmentBuilder = | ||
| 175 | - DefaultTrafficTreatment.builder(); | ||
| 176 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
| 177 | - .setVlanId(VlanId.vlanId((short) 1)); | ||
| 178 | - | ||
| 179 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 180 | - ingressPoints.add(SW1_ETH1); | ||
| 181 | - ingressPoints.add(SW2_ETH1); | ||
| 182 | - | ||
| 183 | - MultiPointToSinglePointIntent intent = | ||
| 184 | - MultiPointToSinglePointIntent.builder() | ||
| 185 | - .appId(APPID) | ||
| 186 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
| 187 | - .selector(selectorBuilder.build()) | ||
| 188 | - .treatment(treatmentBuilder.build()) | ||
| 189 | - .ingressPoints(ingressPoints) | ||
| 190 | - .egressPoint(SW3_ETH1) | ||
| 191 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
| 192 | - .build(); | ||
| 193 | - | ||
| 194 | - // Setup the expected intents | ||
| 195 | - intentSynchronizer.submit(eqExceptId(intent)); | ||
| 196 | - | ||
| 197 | - replay(intentSynchronizer); | ||
| 198 | - | ||
| 199 | - // Send in the added event | ||
| 200 | - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
| 201 | - | ||
| 202 | - verify(intentSynchronizer); | ||
| 203 | - } | ||
| 204 | - | ||
| 205 | - private class TestCoreService extends CoreServiceAdapter { | ||
| 206 | - @Override | ||
| 207 | - public ApplicationId getAppId(String name) { | ||
| 208 | - return APPID; | ||
| 209 | - } | ||
| 210 | - } | ||
| 211 | - | ||
| 212 | - private class TestRouteService extends RouteServiceAdapter { | ||
| 213 | - @Override | ||
| 214 | - public void addListener(RouteListener routeListener) { | ||
| 215 | - SdnIpFibNoVlanstoVlanTest.this.routeListener = routeListener; | ||
| 216 | - } | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | - private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
| 220 | - @Override | ||
| 221 | - public void addListener(InterfaceListener listener) { | ||
| 222 | - SdnIpFibNoVlanstoVlanTest.this.interfaceListener = listener; | ||
| 223 | - } | ||
| 224 | - } | ||
| 225 | -} |
| 1 | /* | 1 | /* |
| 2 | - * Copyright 2016-present Open Networking Laboratory | 2 | + * Copyright 2015-present Open Networking Laboratory |
| 3 | * | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
| ... | @@ -23,6 +23,7 @@ import org.junit.Test; | ... | @@ -23,6 +23,7 @@ import org.junit.Test; |
| 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.IpAddress; | ||
| 26 | import org.onlab.packet.IpPrefix; | 27 | import org.onlab.packet.IpPrefix; |
| 27 | import org.onlab.packet.MacAddress; | 28 | import org.onlab.packet.MacAddress; |
| 28 | import org.onlab.packet.VlanId; | 29 | import org.onlab.packet.VlanId; |
| ... | @@ -40,6 +41,7 @@ import org.onosproject.incubator.net.routing.RouteListener; | ... | @@ -40,6 +41,7 @@ import org.onosproject.incubator.net.routing.RouteListener; |
| 40 | import org.onosproject.incubator.net.routing.RouteServiceAdapter; | 41 | import org.onosproject.incubator.net.routing.RouteServiceAdapter; |
| 41 | import org.onosproject.net.ConnectPoint; | 42 | import org.onosproject.net.ConnectPoint; |
| 42 | import org.onosproject.net.DeviceId; | 43 | import org.onosproject.net.DeviceId; |
| 44 | +import org.onosproject.net.FilteredConnectPoint; | ||
| 43 | import org.onosproject.net.PortNumber; | 45 | import org.onosproject.net.PortNumber; |
| 44 | import org.onosproject.net.flow.DefaultTrafficSelector; | 46 | import org.onosproject.net.flow.DefaultTrafficSelector; |
| 45 | import org.onosproject.net.flow.DefaultTrafficTreatment; | 47 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| ... | @@ -52,7 +54,6 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ... | @@ -52,7 +54,6 @@ import org.onosproject.net.intent.MultiPointToSinglePointIntent; |
| 52 | import org.onosproject.routing.IntentSynchronizationService; | 54 | import org.onosproject.routing.IntentSynchronizationService; |
| 53 | 55 | ||
| 54 | import java.util.Collections; | 56 | import java.util.Collections; |
| 55 | -import java.util.HashSet; | ||
| 56 | import java.util.List; | 57 | import java.util.List; |
| 57 | import java.util.Set; | 58 | import java.util.Set; |
| 58 | 59 | ||
| ... | @@ -68,7 +69,7 @@ import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ... | @@ -68,7 +69,7 @@ import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; |
| 68 | /** | 69 | /** |
| 69 | * Unit tests for SdnIpFib. | 70 | * Unit tests for SdnIpFib. |
| 70 | */ | 71 | */ |
| 71 | -public class SdnIpFibNoVlansTest extends AbstractIntentTest { | 72 | +public class SdnIpFibTest extends AbstractIntentTest { |
| 72 | 73 | ||
| 73 | private InterfaceService interfaceService; | 74 | private InterfaceService interfaceService; |
| 74 | 75 | ||
| ... | @@ -88,7 +89,30 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -88,7 +89,30 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 88 | DeviceId.deviceId("of:0000000000000004"), | 89 | DeviceId.deviceId("of:0000000000000004"), |
| 89 | PortNumber.portNumber(1)); | 90 | PortNumber.portNumber(1)); |
| 90 | 91 | ||
| 92 | + private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); | ||
| 93 | + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); | ||
| 94 | + private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03"); | ||
| 95 | + private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04"); | ||
| 96 | + | ||
| 97 | + private static final VlanId NO_VLAN = VlanId.NONE; | ||
| 98 | + private static final VlanId VLAN10 = VlanId.vlanId(Short.valueOf("10")); | ||
| 99 | + private static final VlanId VLAN20 = VlanId.vlanId(Short.valueOf("20")); | ||
| 100 | + | ||
| 101 | + private static final InterfaceIpAddress IIP1 = | ||
| 102 | + InterfaceIpAddress.valueOf("192.168.10.101/24"); | ||
| 103 | + private static final InterfaceIpAddress IIP2 = | ||
| 104 | + InterfaceIpAddress.valueOf("192.168.20.101/24"); | ||
| 105 | + private static final InterfaceIpAddress IIP3 = | ||
| 106 | + InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
| 107 | + private static final InterfaceIpAddress IIP4 = | ||
| 108 | + InterfaceIpAddress.valueOf("192.168.40.101/24"); | ||
| 109 | + | ||
| 110 | + private static final IpAddress IP1 = Ip4Address.valueOf("192.168.10.1"); | ||
| 111 | + private static final IpAddress IP2 = Ip4Address.valueOf("192.168.20.1"); | ||
| 112 | + private static final IpAddress IP3 = Ip4Address.valueOf("192.168.30.1"); | ||
| 113 | + | ||
| 91 | private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | 114 | private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); |
| 115 | + private static final IpPrefix PREFIX2 = Ip4Prefix.valueOf("1.1.2.0/24"); | ||
| 92 | 116 | ||
| 93 | private SdnIpFib sdnipFib; | 117 | private SdnIpFib sdnipFib; |
| 94 | private IntentSynchronizationService intentSynchronizer; | 118 | private IntentSynchronizationService intentSynchronizer; |
| ... | @@ -128,77 +152,72 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -128,77 +152,72 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 128 | * Sets up the interface service. | 152 | * Sets up the interface service. |
| 129 | */ | 153 | */ |
| 130 | private void setUpInterfaceService() { | 154 | private void setUpInterfaceService() { |
| 131 | - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | 155 | + List<InterfaceIpAddress> iIps1 = Lists.newArrayList(); |
| 132 | - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | 156 | + iIps1.add(IIP1); |
| 133 | - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | 157 | + Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, iIps1, MAC1, VLAN10); |
| 134 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
| 135 | - VlanId.NONE); | ||
| 136 | interfaces.add(sw1Eth1); | 158 | interfaces.add(sw1Eth1); |
| 137 | 159 | ||
| 138 | - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | 160 | + List<InterfaceIpAddress> iIps2 = Lists.newArrayList(); |
| 139 | - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | 161 | + iIps2.add(IIP2); |
| 140 | - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | 162 | + Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, iIps2, MAC2, VLAN20); |
| 141 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
| 142 | - VlanId.NONE); | ||
| 143 | interfaces.add(sw2Eth1); | 163 | interfaces.add(sw2Eth1); |
| 144 | 164 | ||
| 145 | - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | 165 | + List<InterfaceIpAddress> iIps3 = Lists.newArrayList(); |
| 146 | - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | 166 | + iIps3.add(IIP3); |
| 147 | - Lists.newArrayList(interfaceIpAddress3), | 167 | + Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, iIps3, MAC3, NO_VLAN); |
| 148 | - MacAddress.valueOf("00:00:00:00:00:03"), | ||
| 149 | - VlanId.NONE); | ||
| 150 | interfaces.add(sw3Eth1); | 168 | interfaces.add(sw3Eth1); |
| 151 | 169 | ||
| 152 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | 170 | expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( |
| 153 | Collections.singleton(sw1Eth1)).anyTimes(); | 171 | Collections.singleton(sw1Eth1)).anyTimes(); |
| 154 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | 172 | + expect(interfaceService.getMatchingInterface(IP1)) |
| 155 | .andReturn(sw1Eth1).anyTimes(); | 173 | .andReturn(sw1Eth1).anyTimes(); |
| 156 | expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | 174 | expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( |
| 157 | Collections.singleton(sw2Eth1)).anyTimes(); | 175 | Collections.singleton(sw2Eth1)).anyTimes(); |
| 158 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | 176 | + expect(interfaceService.getMatchingInterface(IP2)) |
| 159 | .andReturn(sw2Eth1).anyTimes(); | 177 | .andReturn(sw2Eth1).anyTimes(); |
| 160 | expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | 178 | expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( |
| 161 | Collections.singleton(sw3Eth1)).anyTimes(); | 179 | Collections.singleton(sw3Eth1)).anyTimes(); |
| 162 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | 180 | + expect(interfaceService.getMatchingInterface(IP3)) |
| 163 | .andReturn(sw3Eth1).anyTimes(); | 181 | .andReturn(sw3Eth1).anyTimes(); |
| 164 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | 182 | expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); |
| 165 | } | 183 | } |
| 166 | 184 | ||
| 167 | /** | 185 | /** |
| 168 | - * Tests adding a route. All interfaces have no VLAN Ids configured. | 186 | + * Tests adding a route. The egress interface has no VLAN configured. |
| 169 | * | 187 | * |
| 170 | * We verify that the synchronizer records the correct state and that the | 188 | * We verify that the synchronizer records the correct state and that the |
| 171 | * correct intent is submitted to the IntentService. | 189 | * correct intent is submitted to the IntentService. |
| 172 | */ | 190 | */ |
| 173 | @Test | 191 | @Test |
| 174 | - public void testRouteAddNoVlans() { | 192 | + public void testRouteAddToNoVlan() { |
| 175 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | 193 | + // Build the expected route |
| 176 | - Ip4Address.valueOf("192.168.30.1"), | 194 | + ResolvedRoute route = new ResolvedRoute(PREFIX1, IP3, MAC3); |
| 177 | - MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 178 | 195 | ||
| 179 | - // Construct a MultiPointToSinglePointIntent intent | 196 | + MultiPointToSinglePointIntent intent = |
| 180 | - TrafficSelector.Builder selectorBuilder = | 197 | + createIntentToThreeSrcOneTwo(PREFIX1); |
| 181 | - DefaultTrafficSelector.builder(); | ||
| 182 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); | ||
| 183 | 198 | ||
| 184 | - TrafficTreatment.Builder treatmentBuilder = | 199 | + // Setup the expected intents |
| 185 | - DefaultTrafficTreatment.builder(); | 200 | + intentSynchronizer.submit(eqExceptId(intent)); |
| 186 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); | 201 | + replay(intentSynchronizer); |
| 187 | 202 | ||
| 188 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | 203 | + // Send in the added event |
| 189 | - ingressPoints.add(SW1_ETH1); | 204 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); |
| 190 | - ingressPoints.add(SW2_ETH1); | ||
| 191 | 205 | ||
| 192 | - MultiPointToSinglePointIntent intent = | 206 | + verify(intentSynchronizer); |
| 193 | - MultiPointToSinglePointIntent.builder() | 207 | + } |
| 194 | - .appId(APPID) | 208 | + |
| 195 | - .key(Key.of(PREFIX1.toString(), APPID)) | 209 | + /** |
| 196 | - .selector(selectorBuilder.build()) | 210 | + * Tests adding a route. The egress interface has a VLAN configured. |
| 197 | - .treatment(treatmentBuilder.build()) | 211 | + * |
| 198 | - .ingressPoints(ingressPoints) | 212 | + * We verify that the synchronizer records the correct state and that the |
| 199 | - .egressPoint(SW3_ETH1) | 213 | + * correct intent is submitted to the IntentService. |
| 200 | - .constraints(SdnIpFib.CONSTRAINTS) | 214 | + */ |
| 201 | - .build(); | 215 | + @Test |
| 216 | + public void testRouteAddToVlan() { | ||
| 217 | + // Build the expected route | ||
| 218 | + ResolvedRoute route = new ResolvedRoute(PREFIX2, IP1, MAC1); | ||
| 219 | + | ||
| 220 | + MultiPointToSinglePointIntent intent = createIntentToOne(PREFIX2); | ||
| 202 | 221 | ||
| 203 | // Setup the expected intents | 222 | // Setup the expected intents |
| 204 | intentSynchronizer.submit(eqExceptId(intent)); | 223 | intentSynchronizer.submit(eqExceptId(intent)); |
| ... | @@ -213,52 +232,68 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -213,52 +232,68 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 213 | /** | 232 | /** |
| 214 | * Tests updating a route. | 233 | * Tests updating a route. |
| 215 | * | 234 | * |
| 235 | + * We first add a route from a next-hop with no vlan. We then announce the | ||
| 236 | + * same route from another next-hop with a vlan. | ||
| 237 | + * | ||
| 216 | * We verify that the synchronizer records the correct state and that the | 238 | * We verify that the synchronizer records the correct state and that the |
| 217 | * correct intent is submitted to the IntentService. | 239 | * correct intent is submitted to the IntentService. |
| 218 | */ | 240 | */ |
| 219 | @Test | 241 | @Test |
| 220 | - public void testRouteUpdate() { | 242 | + public void testRouteUpdatesToVlan() { |
| 221 | - // Add a route first | 243 | + // Add a route first to a destination with no VLAN |
| 222 | - testRouteAddNoVlans(); | 244 | + testRouteAddToNoVlan(); |
| 223 | 245 | ||
| 224 | - // Start to construct a new route entry and new intent | 246 | + // Build the new route entries for prefix1 and prefix2 |
| 225 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | 247 | + ResolvedRoute routePrefixOne = new ResolvedRoute(PREFIX1, IP1, MAC1); |
| 226 | - Ip4Address.valueOf("192.168.20.1"), | ||
| 227 | - MacAddress.valueOf("00:00:00:00:00:02")); | ||
| 228 | 248 | ||
| 229 | - // Construct a new MultiPointToSinglePointIntent intent | 249 | + // Create the new expected intents |
| 230 | - TrafficSelector.Builder selectorBuilderNew = | 250 | + MultiPointToSinglePointIntent newPrefixOneIntent = createIntentToOne(PREFIX1); |
| 231 | - DefaultTrafficSelector.builder(); | ||
| 232 | - selectorBuilderNew.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); | ||
| 233 | 251 | ||
| 234 | - TrafficTreatment.Builder treatmentBuilderNew = | 252 | + // Set up test expectation |
| 235 | - DefaultTrafficTreatment.builder(); | 253 | + reset(intentSynchronizer); |
| 236 | - treatmentBuilderNew.setEthDst(MacAddress.valueOf("00:00:00:00:00:02")); | ||
| 237 | 254 | ||
| 238 | - Set<ConnectPoint> ingressPointsNew = new HashSet<>(); | 255 | + // Setup the expected intents |
| 239 | - ingressPointsNew.add(SW1_ETH1); | 256 | + intentSynchronizer.submit(eqExceptId(newPrefixOneIntent)); |
| 240 | - ingressPointsNew.add(SW3_ETH1); | 257 | + replay(intentSynchronizer); |
| 241 | 258 | ||
| 242 | - MultiPointToSinglePointIntent intentNew = | 259 | + // Send in the update events |
| 243 | - MultiPointToSinglePointIntent.builder() | 260 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, |
| 244 | - .appId(APPID) | 261 | + routePrefixOne)); |
| 245 | - .key(Key.of(PREFIX1.toString(), APPID)) | 262 | + |
| 246 | - .selector(selectorBuilderNew.build()) | 263 | + verify(intentSynchronizer); |
| 247 | - .treatment(treatmentBuilderNew.build()) | 264 | + } |
| 248 | - .ingressPoints(ingressPointsNew) | 265 | + |
| 249 | - .egressPoint(SW2_ETH1) | 266 | + /** |
| 250 | - .constraints(SdnIpFib.CONSTRAINTS) | 267 | + * Tests updating a route. |
| 251 | - .build(); | 268 | + * |
| 269 | + * We first add a route from a next-hop with a vlan. We then announce the | ||
| 270 | + * same route from another next-hop with no vlan. | ||
| 271 | + * | ||
| 272 | + * We verify that the synchronizer records the correct state and that the | ||
| 273 | + * correct intent is submitted to the IntentService. | ||
| 274 | + */ | ||
| 275 | + @Test | ||
| 276 | + public void testRouteUpdatesToNoVlan() { | ||
| 277 | + // Add a route first to a destination with no VLAN | ||
| 278 | + testRouteAddToVlan(); | ||
| 279 | + | ||
| 280 | + // Build the new route entries for prefix1 and prefix2 | ||
| 281 | + ResolvedRoute routePrefix = new ResolvedRoute(PREFIX2, IP3, MAC3); | ||
| 282 | + | ||
| 283 | + // Create the new expected intents | ||
| 284 | + MultiPointToSinglePointIntent newPrefixIntent = | ||
| 285 | + createIntentToThreeSrcOneTwo(PREFIX2); | ||
| 252 | 286 | ||
| 253 | // Set up test expectation | 287 | // Set up test expectation |
| 254 | reset(intentSynchronizer); | 288 | reset(intentSynchronizer); |
| 255 | 289 | ||
| 256 | // Setup the expected intents | 290 | // Setup the expected intents |
| 257 | - intentSynchronizer.submit(eqExceptId(intentNew)); | 291 | + intentSynchronizer.submit(eqExceptId(newPrefixIntent)); |
| 258 | replay(intentSynchronizer); | 292 | replay(intentSynchronizer); |
| 259 | 293 | ||
| 260 | - // Send in the update event | 294 | + // Send in the update events |
| 261 | - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, route)); | 295 | + routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_UPDATED, |
| 296 | + routePrefix)); | ||
| 262 | 297 | ||
| 263 | verify(intentSynchronizer); | 298 | verify(intentSynchronizer); |
| 264 | } | 299 | } |
| ... | @@ -272,39 +307,19 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -272,39 +307,19 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 272 | @Test | 307 | @Test |
| 273 | public void testRouteDelete() { | 308 | public void testRouteDelete() { |
| 274 | // Add a route first | 309 | // Add a route first |
| 275 | - testRouteAddNoVlans(); | 310 | + testRouteAddToNoVlan(); |
| 276 | 311 | ||
| 277 | // Construct the existing route entry | 312 | // Construct the existing route entry |
| 278 | ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); | 313 | ResolvedRoute route = new ResolvedRoute(PREFIX1, null, null); |
| 279 | 314 | ||
| 280 | - // Construct the existing MultiPointToSinglePoint intent | 315 | + // Create existing intent |
| 281 | - TrafficSelector.Builder selectorBuilder = | 316 | + MultiPointToSinglePointIntent removedIntent = |
| 282 | - DefaultTrafficSelector.builder(); | 317 | + createIntentToThreeSrcOneTwo(PREFIX1); |
| 283 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); | ||
| 284 | - | ||
| 285 | - TrafficTreatment.Builder treatmentBuilder = | ||
| 286 | - DefaultTrafficTreatment.builder(); | ||
| 287 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 288 | - | ||
| 289 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 290 | - ingressPoints.add(SW1_ETH1); | ||
| 291 | - ingressPoints.add(SW2_ETH1); | ||
| 292 | - | ||
| 293 | - MultiPointToSinglePointIntent addedIntent = | ||
| 294 | - MultiPointToSinglePointIntent.builder() | ||
| 295 | - .appId(APPID) | ||
| 296 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
| 297 | - .selector(selectorBuilder.build()) | ||
| 298 | - .treatment(treatmentBuilder.build()) | ||
| 299 | - .ingressPoints(ingressPoints) | ||
| 300 | - .egressPoint(SW3_ETH1) | ||
| 301 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
| 302 | - .build(); | ||
| 303 | 318 | ||
| 304 | // Set up expectation | 319 | // Set up expectation |
| 305 | reset(intentSynchronizer); | 320 | reset(intentSynchronizer); |
| 306 | // Setup the expected intents | 321 | // Setup the expected intents |
| 307 | - intentSynchronizer.withdraw(eqExceptId(addedIntent)); | 322 | + intentSynchronizer.withdraw(eqExceptId(removedIntent)); |
| 308 | replay(intentSynchronizer); | 323 | replay(intentSynchronizer); |
| 309 | 324 | ||
| 310 | // Send in the removed event | 325 | // Send in the removed event |
| ... | @@ -313,35 +328,20 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -313,35 +328,20 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 313 | verify(intentSynchronizer); | 328 | verify(intentSynchronizer); |
| 314 | } | 329 | } |
| 315 | 330 | ||
| 331 | + /** | ||
| 332 | + * Tests adding a new interface. | ||
| 333 | + * | ||
| 334 | + * We verify that the synchronizer records the correct state and that the | ||
| 335 | + * correct intent is withdrawn from the IntentService. | ||
| 336 | + */ | ||
| 316 | @Test | 337 | @Test |
| 317 | public void testAddInterface() { | 338 | public void testAddInterface() { |
| 318 | // Add a route first | 339 | // Add a route first |
| 319 | - testRouteAddNoVlans(); | 340 | + testRouteAddToNoVlan(); |
| 320 | - | ||
| 321 | - // Construct the existing MultiPointToSinglePoint intent | ||
| 322 | - TrafficSelector.Builder selectorBuilder = | ||
| 323 | - DefaultTrafficSelector.builder(); | ||
| 324 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); | ||
| 325 | - | ||
| 326 | - TrafficTreatment.Builder treatmentBuilder = | ||
| 327 | - DefaultTrafficTreatment.builder(); | ||
| 328 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 329 | - | ||
| 330 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 331 | - ingressPoints.add(SW1_ETH1); | ||
| 332 | - ingressPoints.add(SW2_ETH1); | ||
| 333 | - ingressPoints.add(SW4_ETH1); | ||
| 334 | 341 | ||
| 342 | + // Create the new expected intent | ||
| 335 | MultiPointToSinglePointIntent addedIntent = | 343 | MultiPointToSinglePointIntent addedIntent = |
| 336 | - MultiPointToSinglePointIntent.builder() | 344 | + createIntentToThreeSrcOneTwoFour(PREFIX1); |
| 337 | - .appId(APPID) | ||
| 338 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
| 339 | - .selector(selectorBuilder.build()) | ||
| 340 | - .treatment(treatmentBuilder.build()) | ||
| 341 | - .ingressPoints(ingressPoints) | ||
| 342 | - .egressPoint(SW3_ETH1) | ||
| 343 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
| 344 | - .build(); | ||
| 345 | 345 | ||
| 346 | reset(intentSynchronizer); | 346 | reset(intentSynchronizer); |
| 347 | 347 | ||
| ... | @@ -350,57 +350,274 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -350,57 +350,274 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 350 | 350 | ||
| 351 | replay(intentSynchronizer); | 351 | replay(intentSynchronizer); |
| 352 | 352 | ||
| 353 | + // Create the new interface and add notify it | ||
| 353 | Interface intf = new Interface("sw4-eth1", SW4_ETH1, | 354 | Interface intf = new Interface("sw4-eth1", SW4_ETH1, |
| 354 | - Collections.singletonList(InterfaceIpAddress.valueOf("192.168.40.101/24")), | 355 | + Collections.singletonList(IIP4), |
| 355 | - MacAddress.valueOf("00:00:00:00:00:04"), VlanId.NONE); | 356 | + MAC4, NO_VLAN); |
| 356 | - InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf); | 357 | + InterfaceEvent intfEvent = |
| 358 | + new InterfaceEvent(InterfaceEvent.Type.INTERFACE_ADDED, intf); | ||
| 359 | + | ||
| 360 | + interfaceListener.event(intfEvent); | ||
| 361 | + | ||
| 362 | + verify(intentSynchronizer); | ||
| 363 | + } | ||
| 364 | + | ||
| 365 | + /** | ||
| 366 | + * Tests removing an existing interface. | ||
| 367 | + * | ||
| 368 | + * We first push an intent with destination sw3 and source sw1 and sw2. We | ||
| 369 | + * then remove the ingress interface on sw1. | ||
| 370 | + * | ||
| 371 | + * We verify that the synchronizer records the correct state and that the | ||
| 372 | + * correct intent is withdrawn from the IntentService. | ||
| 373 | + */ | ||
| 374 | + @Test | ||
| 375 | + public void testRemoveIngressInterface() { | ||
| 376 | + // Add a route first | ||
| 377 | + testRouteAddToNoVlan(); | ||
| 378 | + | ||
| 379 | + // Create the new expected intent | ||
| 380 | + MultiPointToSinglePointIntent remainingIntent = | ||
| 381 | + createIntentToThreeSrcTwo(PREFIX1); | ||
| 382 | + | ||
| 383 | + reset(intentSynchronizer); | ||
| 384 | + | ||
| 385 | + intentSynchronizer.submit(eqExceptId(remainingIntent)); | ||
| 386 | + expectLastCall().once(); | ||
| 387 | + | ||
| 388 | + replay(intentSynchronizer); | ||
| 389 | + | ||
| 390 | + // Define the existing ingress interface and remove it | ||
| 391 | + Interface intf = new Interface("sw1-eth1", SW1_ETH1, | ||
| 392 | + Collections.singletonList(IIP1), | ||
| 393 | + MAC1, VLAN10); | ||
| 394 | + InterfaceEvent intfEvent = | ||
| 395 | + new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); | ||
| 357 | interfaceListener.event(intfEvent); | 396 | interfaceListener.event(intfEvent); |
| 358 | 397 | ||
| 359 | verify(intentSynchronizer); | 398 | verify(intentSynchronizer); |
| 360 | } | 399 | } |
| 361 | 400 | ||
| 401 | + /** | ||
| 402 | + * Tests removing an existing egress interface. | ||
| 403 | + * | ||
| 404 | + * We first push an intent with destination sw3 and source sw1 and sw2. We | ||
| 405 | + * then remove the egress interface on sw3. | ||
| 406 | + * | ||
| 407 | + * We verify that the synchronizer records the correct state and that the | ||
| 408 | + * correct intent is withdrawn from the IntentService. | ||
| 409 | + */ | ||
| 362 | @Test | 410 | @Test |
| 363 | - public void testRemoveInterface() { | 411 | + public void testRemoveEgressInterface() { |
| 364 | // Add a route first | 412 | // Add a route first |
| 365 | - testRouteAddNoVlans(); | 413 | + testRouteAddToNoVlan(); |
| 414 | + | ||
| 415 | + // Create existing intent | ||
| 416 | + MultiPointToSinglePointIntent removedIntent = | ||
| 417 | + createIntentToThreeSrcOneTwo(PREFIX1); | ||
| 366 | 418 | ||
| 367 | - // Construct the existing MultiPointToSinglePoint intent | 419 | + // Set up expectation |
| 368 | - TrafficSelector.Builder selectorBuilder = | 420 | + reset(intentSynchronizer); |
| 369 | - DefaultTrafficSelector.builder(); | 421 | + // Setup the expected intents |
| 370 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1); | 422 | + intentSynchronizer.withdraw(eqExceptId(removedIntent)); |
| 423 | + replay(intentSynchronizer); | ||
| 424 | + | ||
| 425 | + // Define the existing egress interface and remove it | ||
| 426 | + Interface intf = new Interface("sw3-eth1", SW3_ETH1, | ||
| 427 | + Collections.singletonList(IIP3), | ||
| 428 | + MAC3, VlanId.NONE); | ||
| 429 | + InterfaceEvent intfEvent = | ||
| 430 | + new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); | ||
| 431 | + interfaceListener.event(intfEvent); | ||
| 371 | 432 | ||
| 433 | + verify(intentSynchronizer); | ||
| 434 | + } | ||
| 435 | + | ||
| 436 | + /* | ||
| 437 | + * Builds a MultiPointToSinglePointIntent with dest sw1 (VLAN Id) and src | ||
| 438 | + * sw2, sw3. | ||
| 439 | + */ | ||
| 440 | + private MultiPointToSinglePointIntent createIntentToOne(IpPrefix ipPrefix) { | ||
| 441 | + // Build the expected treatment | ||
| 372 | TrafficTreatment.Builder treatmentBuilder = | 442 | TrafficTreatment.Builder treatmentBuilder = |
| 373 | DefaultTrafficTreatment.builder(); | 443 | DefaultTrafficTreatment.builder(); |
| 374 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); | 444 | + treatmentBuilder.setEthDst(MAC1); |
| 445 | + | ||
| 446 | + // Build the expected egress FilteredConnectPoint | ||
| 447 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 448 | + selector.matchVlanId(VLAN10); | ||
| 449 | + FilteredConnectPoint egressFilteredCP = | ||
| 450 | + new FilteredConnectPoint(SW1_ETH1, selector.build()); | ||
| 451 | + | ||
| 452 | + // Build the expected selectors | ||
| 453 | + Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); | ||
| 454 | + | ||
| 455 | + // Build the expected ingress FilteredConnectPoint for sw2 | ||
| 456 | + selector = DefaultTrafficSelector.builder(); | ||
| 457 | + selector.matchVlanId(VLAN20); | ||
| 458 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 459 | + selector.matchIPDst(ipPrefix); | ||
| 460 | + FilteredConnectPoint ingressFilteredCP = | ||
| 461 | + new FilteredConnectPoint(SW2_ETH1, selector.build()); | ||
| 462 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 463 | + | ||
| 464 | + // Build the expected ingress FilteredConnectPoint for sw3 | ||
| 465 | + selector = DefaultTrafficSelector.builder(); | ||
| 466 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 467 | + selector.matchIPDst(ipPrefix); | ||
| 468 | + ingressFilteredCP = new FilteredConnectPoint(SW3_ETH1, selector.build()); | ||
| 469 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 470 | + | ||
| 471 | + // Build the expected intent | ||
| 472 | + MultiPointToSinglePointIntent intent = | ||
| 473 | + MultiPointToSinglePointIntent.builder() | ||
| 474 | + .appId(APPID) | ||
| 475 | + .key(Key.of(ipPrefix.toString(), APPID)) | ||
| 476 | + .filteredIngressPoints(ingressFilteredCPs) | ||
| 477 | + .filteredEgressPoint(egressFilteredCP) | ||
| 478 | + .treatment(treatmentBuilder.build()) | ||
| 479 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
| 480 | + .build(); | ||
| 375 | 481 | ||
| 376 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | 482 | + return intent; |
| 377 | - ingressPoints.add(SW2_ETH1); | 483 | + } |
| 378 | 484 | ||
| 379 | - MultiPointToSinglePointIntent addedIntent = | 485 | + /* |
| 486 | + * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src | ||
| 487 | + * sw1, sw2. | ||
| 488 | + */ | ||
| 489 | + private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwo(IpPrefix ipPrefix) { | ||
| 490 | + // Build the expected treatment | ||
| 491 | + TrafficTreatment.Builder treatmentBuilder = | ||
| 492 | + DefaultTrafficTreatment.builder(); | ||
| 493 | + treatmentBuilder.setEthDst(MAC3); | ||
| 494 | + | ||
| 495 | + // Build the expected egress FilteredConnectPoint | ||
| 496 | + FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); | ||
| 497 | + | ||
| 498 | + // Build the expected selectors | ||
| 499 | + Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); | ||
| 500 | + | ||
| 501 | + // Build the expected ingress FilteredConnectPoint for sw1 | ||
| 502 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 503 | + selector.matchVlanId(VLAN10); | ||
| 504 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 505 | + selector.matchIPDst(ipPrefix); | ||
| 506 | + FilteredConnectPoint ingressFilteredCP = | ||
| 507 | + new FilteredConnectPoint(SW1_ETH1, selector.build()); | ||
| 508 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 509 | + | ||
| 510 | + // Build the expected ingress FilteredConnectPoint for sw2 | ||
| 511 | + selector = DefaultTrafficSelector.builder(); | ||
| 512 | + selector.matchVlanId(VLAN20); | ||
| 513 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 514 | + selector.matchIPDst(ipPrefix); | ||
| 515 | + ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build()); | ||
| 516 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 517 | + | ||
| 518 | + // Build the expected intent | ||
| 519 | + MultiPointToSinglePointIntent intent = | ||
| 380 | MultiPointToSinglePointIntent.builder() | 520 | MultiPointToSinglePointIntent.builder() |
| 381 | .appId(APPID) | 521 | .appId(APPID) |
| 382 | - .key(Key.of(PREFIX1.toString(), APPID)) | 522 | + .key(Key.of(ipPrefix.toString(), APPID)) |
| 383 | - .selector(selectorBuilder.build()) | 523 | + .filteredIngressPoints(ingressFilteredCPs) |
| 524 | + .filteredEgressPoint(egressFilteredCP) | ||
| 384 | .treatment(treatmentBuilder.build()) | 525 | .treatment(treatmentBuilder.build()) |
| 385 | - .ingressPoints(ingressPoints) | ||
| 386 | - .egressPoint(SW3_ETH1) | ||
| 387 | .constraints(SdnIpFib.CONSTRAINTS) | 526 | .constraints(SdnIpFib.CONSTRAINTS) |
| 388 | .build(); | 527 | .build(); |
| 389 | 528 | ||
| 390 | - reset(intentSynchronizer); | 529 | + return intent; |
| 530 | + } | ||
| 391 | 531 | ||
| 392 | - intentSynchronizer.submit(eqExceptId(addedIntent)); | 532 | + /* |
| 393 | - expectLastCall().once(); | 533 | + * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src |
| 534 | + * sw2. | ||
| 535 | + */ | ||
| 536 | + private MultiPointToSinglePointIntent createIntentToThreeSrcTwo(IpPrefix ipPrefix) { | ||
| 537 | + // Build the expected treatment | ||
| 538 | + TrafficTreatment.Builder treatmentBuilder = | ||
| 539 | + DefaultTrafficTreatment.builder(); | ||
| 540 | + treatmentBuilder.setEthDst(MAC3); | ||
| 541 | + | ||
| 542 | + // Build the expected egress FilteredConnectPoint | ||
| 543 | + FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); | ||
| 544 | + | ||
| 545 | + // Build the expected ingress FilteredConnectPoint for sw2 | ||
| 546 | + Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); | ||
| 547 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 548 | + selector.matchVlanId(VLAN20); | ||
| 549 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 550 | + selector.matchIPDst(ipPrefix); | ||
| 551 | + FilteredConnectPoint ingressFilteredCP = | ||
| 552 | + new FilteredConnectPoint(SW2_ETH1, selector.build()); | ||
| 553 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 554 | + | ||
| 555 | + // Build the expected intent | ||
| 556 | + MultiPointToSinglePointIntent intent = | ||
| 557 | + MultiPointToSinglePointIntent.builder() | ||
| 558 | + .appId(APPID) | ||
| 559 | + .key(Key.of(ipPrefix.toString(), APPID)) | ||
| 560 | + .filteredIngressPoints(ingressFilteredCPs) | ||
| 561 | + .filteredEgressPoint(egressFilteredCP) | ||
| 562 | + .treatment(treatmentBuilder.build()) | ||
| 563 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
| 564 | + .build(); | ||
| 394 | 565 | ||
| 395 | - replay(intentSynchronizer); | 566 | + return intent; |
| 567 | + } | ||
| 396 | 568 | ||
| 397 | - Interface intf = new Interface("sw1-eth1", SW1_ETH1, | 569 | + /* |
| 398 | - Collections.singletonList(InterfaceIpAddress.valueOf("192.168.10.101/24")), | 570 | + * Builds a MultiPointToSinglePointIntent with dest sw3 (no VLAN Id) and src |
| 399 | - MacAddress.valueOf("00:00:00:00:00:01"), VlanId.NONE); | 571 | + * sw1, sw2, sw4. |
| 400 | - InterfaceEvent intfEvent = new InterfaceEvent(InterfaceEvent.Type.INTERFACE_REMOVED, intf); | 572 | + */ |
| 401 | - interfaceListener.event(intfEvent); | 573 | + private MultiPointToSinglePointIntent createIntentToThreeSrcOneTwoFour(IpPrefix ipPrefix) { |
| 574 | + // Build the expected treatment | ||
| 575 | + TrafficTreatment.Builder treatmentBuilder = | ||
| 576 | + DefaultTrafficTreatment.builder(); | ||
| 577 | + treatmentBuilder.setEthDst(MAC3); | ||
| 578 | + | ||
| 579 | + // Build the expected egress FilteredConnectPoint | ||
| 580 | + FilteredConnectPoint egressFilteredCP = new FilteredConnectPoint(SW3_ETH1); | ||
| 581 | + | ||
| 582 | + // Build the expected selectors | ||
| 583 | + Set<FilteredConnectPoint> ingressFilteredCPs = Sets.newHashSet(); | ||
| 584 | + | ||
| 585 | + // Build the expected ingress FilteredConnectPoint for sw1 | ||
| 586 | + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); | ||
| 587 | + selector.matchVlanId(VLAN10); | ||
| 588 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 589 | + selector.matchIPDst(ipPrefix); | ||
| 590 | + FilteredConnectPoint ingressFilteredCP = | ||
| 591 | + new FilteredConnectPoint(SW1_ETH1, selector.build()); | ||
| 592 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 593 | + | ||
| 594 | + // Build the expected ingress FilteredConnectPoint for sw2 | ||
| 595 | + selector = DefaultTrafficSelector.builder(); | ||
| 596 | + selector.matchVlanId(VLAN20); | ||
| 597 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 598 | + selector.matchIPDst(ipPrefix); | ||
| 599 | + ingressFilteredCP = new FilteredConnectPoint(SW2_ETH1, selector.build()); | ||
| 600 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 601 | + | ||
| 602 | + // Build the expected ingress FilteredConnectPoint for sw4 | ||
| 603 | + selector = DefaultTrafficSelector.builder(); | ||
| 604 | + selector.matchEthType(Ethernet.TYPE_IPV4); | ||
| 605 | + selector.matchIPDst(ipPrefix); | ||
| 606 | + ingressFilteredCP = new FilteredConnectPoint(SW4_ETH1, selector.build()); | ||
| 607 | + ingressFilteredCPs.add(ingressFilteredCP); | ||
| 608 | + | ||
| 609 | + // Build the expected intent | ||
| 610 | + MultiPointToSinglePointIntent intent = | ||
| 611 | + MultiPointToSinglePointIntent.builder() | ||
| 612 | + .appId(APPID) | ||
| 613 | + .key(Key.of(ipPrefix.toString(), APPID)) | ||
| 614 | + .filteredIngressPoints(ingressFilteredCPs) | ||
| 615 | + .filteredEgressPoint(egressFilteredCP) | ||
| 616 | + .treatment(treatmentBuilder.build()) | ||
| 617 | + .constraints(SdnIpFib.CONSTRAINTS) | ||
| 618 | + .build(); | ||
| 402 | 619 | ||
| 403 | - verify(intentSynchronizer); | 620 | + return intent; |
| 404 | } | 621 | } |
| 405 | 622 | ||
| 406 | private class TestCoreService extends CoreServiceAdapter { | 623 | private class TestCoreService extends CoreServiceAdapter { |
| ... | @@ -413,14 +630,14 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { | ... | @@ -413,14 +630,14 @@ public class SdnIpFibNoVlansTest extends AbstractIntentTest { |
| 413 | private class TestRouteService extends RouteServiceAdapter { | 630 | private class TestRouteService extends RouteServiceAdapter { |
| 414 | @Override | 631 | @Override |
| 415 | public void addListener(RouteListener routeListener) { | 632 | public void addListener(RouteListener routeListener) { |
| 416 | - SdnIpFibNoVlansTest.this.routeListener = routeListener; | 633 | + SdnIpFibTest.this.routeListener = routeListener; |
| 417 | } | 634 | } |
| 418 | } | 635 | } |
| 419 | 636 | ||
| 420 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | 637 | private class InterfaceServiceDelegate extends InterfaceServiceAdapter { |
| 421 | @Override | 638 | @Override |
| 422 | public void addListener(InterfaceListener listener) { | 639 | public void addListener(InterfaceListener listener) { |
| 423 | - SdnIpFibNoVlansTest.this.interfaceListener = listener; | 640 | + SdnIpFibTest.this.interfaceListener = listener; |
| 424 | } | 641 | } |
| 425 | } | 642 | } |
| 426 | } | 643 | } | ... | ... |
apps/sdnip/src/test/java/org/onosproject/sdnip/SdnIpFibVlansToVlanDifferentTest.java
deleted
100644 → 0
| 1 | -/* | ||
| 2 | - * Copyright 2016-present 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.sdnip; | ||
| 18 | - | ||
| 19 | -import com.google.common.collect.Lists; | ||
| 20 | -import com.google.common.collect.Sets; | ||
| 21 | -import org.junit.Before; | ||
| 22 | -import org.junit.Test; | ||
| 23 | -import org.onlab.packet.Ethernet; | ||
| 24 | -import org.onlab.packet.Ip4Address; | ||
| 25 | -import org.onlab.packet.Ip4Prefix; | ||
| 26 | -import org.onlab.packet.IpPrefix; | ||
| 27 | -import org.onlab.packet.MacAddress; | ||
| 28 | -import org.onlab.packet.VlanId; | ||
| 29 | -import org.onosproject.TestApplicationId; | ||
| 30 | -import org.onosproject.core.ApplicationId; | ||
| 31 | -import org.onosproject.core.CoreServiceAdapter; | ||
| 32 | -import org.onosproject.incubator.net.intf.Interface; | ||
| 33 | -import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 34 | -import org.onosproject.incubator.net.intf.InterfaceService; | ||
| 35 | -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
| 36 | -import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
| 37 | -import org.onosproject.incubator.net.routing.RouteEvent; | ||
| 38 | -import org.onosproject.incubator.net.routing.RouteListener; | ||
| 39 | -import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
| 40 | -import org.onosproject.net.ConnectPoint; | ||
| 41 | -import org.onosproject.net.DeviceId; | ||
| 42 | -import org.onosproject.net.PortNumber; | ||
| 43 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 44 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 45 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 46 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 47 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
| 48 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
| 49 | -import org.onosproject.net.intent.Key; | ||
| 50 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
| 51 | -import org.onosproject.routing.IntentSynchronizationService; | ||
| 52 | - | ||
| 53 | -import java.util.Collections; | ||
| 54 | -import java.util.HashSet; | ||
| 55 | -import java.util.List; | ||
| 56 | -import java.util.Set; | ||
| 57 | - | ||
| 58 | -import static org.easymock.EasyMock.*; | ||
| 59 | -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
| 60 | - | ||
| 61 | -/** | ||
| 62 | - * Unit tests for SdnIpFib. | ||
| 63 | - */ | ||
| 64 | -public class SdnIpFibVlansToVlanDifferentTest extends AbstractIntentTest { | ||
| 65 | - | ||
| 66 | - private InterfaceService interfaceService; | ||
| 67 | - | ||
| 68 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
| 69 | - DeviceId.deviceId("of:0000000000000001"), | ||
| 70 | - PortNumber.portNumber(1)); | ||
| 71 | - | ||
| 72 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
| 73 | - DeviceId.deviceId("of:0000000000000002"), | ||
| 74 | - PortNumber.portNumber(1)); | ||
| 75 | - | ||
| 76 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
| 77 | - DeviceId.deviceId("of:0000000000000003"), | ||
| 78 | - PortNumber.portNumber(1)); | ||
| 79 | - | ||
| 80 | - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
| 81 | - | ||
| 82 | - private SdnIpFib sdnipFib; | ||
| 83 | - private IntentSynchronizationService intentSynchronizer; | ||
| 84 | - private final Set<Interface> interfaces = Sets.newHashSet(); | ||
| 85 | - | ||
| 86 | - private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
| 87 | - | ||
| 88 | - private RouteListener routeListener; | ||
| 89 | - private InterfaceListener interfaceListener; | ||
| 90 | - | ||
| 91 | - @Before | ||
| 92 | - public void setUp() throws Exception { | ||
| 93 | - super.setUp(); | ||
| 94 | - | ||
| 95 | - interfaceService = createMock(InterfaceService.class); | ||
| 96 | - | ||
| 97 | - interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 98 | - expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
| 99 | - | ||
| 100 | - // These will set expectations on routingConfig and interfaceService | ||
| 101 | - setUpInterfaceService(); | ||
| 102 | - | ||
| 103 | - replay(interfaceService); | ||
| 104 | - | ||
| 105 | - intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
| 106 | - | ||
| 107 | - sdnipFib = new SdnIpFib(); | ||
| 108 | - sdnipFib.routeService = new TestRouteService(); | ||
| 109 | - sdnipFib.coreService = new TestCoreService(); | ||
| 110 | - sdnipFib.interfaceService = interfaceService; | ||
| 111 | - sdnipFib.intentSynchronizer = intentSynchronizer; | ||
| 112 | - | ||
| 113 | - sdnipFib.activate(); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | - * Sets up the interface service. | ||
| 118 | - */ | ||
| 119 | - private void setUpInterfaceService() { | ||
| 120 | - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
| 121 | - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
| 122 | - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
| 123 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
| 124 | - VlanId.vlanId((short) 1)); | ||
| 125 | - interfaces.add(sw1Eth1); | ||
| 126 | - | ||
| 127 | - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
| 128 | - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
| 129 | - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
| 130 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
| 131 | - VlanId.vlanId((short) 1)); | ||
| 132 | - interfaces.add(sw2Eth1); | ||
| 133 | - | ||
| 134 | - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
| 135 | - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
| 136 | - Lists.newArrayList(interfaceIpAddress3), | ||
| 137 | - MacAddress.valueOf("00:00:00:00:00:03"), | ||
| 138 | - VlanId.vlanId((short) 2)); | ||
| 139 | - interfaces.add(sw3Eth1); | ||
| 140 | - | ||
| 141 | - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
| 142 | - Collections.singleton(sw1Eth1)).anyTimes(); | ||
| 143 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
| 144 | - .andReturn(sw1Eth1).anyTimes(); | ||
| 145 | - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
| 146 | - Collections.singleton(sw2Eth1)).anyTimes(); | ||
| 147 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
| 148 | - .andReturn(sw2Eth1).anyTimes(); | ||
| 149 | - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
| 150 | - Collections.singleton(sw3Eth1)).anyTimes(); | ||
| 151 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
| 152 | - .andReturn(sw3Eth1).anyTimes(); | ||
| 153 | - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - /** | ||
| 157 | - * Tests adding a route. Ingresses with VLAN and next hop with no VLAN. | ||
| 158 | - * | ||
| 159 | - * We verify that the synchronizer records the correct state and that the | ||
| 160 | - * correct intent is submitted to the IntentService. | ||
| 161 | - */ | ||
| 162 | - @Test | ||
| 163 | - public void testRouteAdd() { | ||
| 164 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
| 165 | - Ip4Address.valueOf("192.168.30.1"), | ||
| 166 | - MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 167 | - | ||
| 168 | - // Construct a MultiPointToSinglePointIntent intent | ||
| 169 | - TrafficSelector.Builder selectorBuilder = | ||
| 170 | - DefaultTrafficSelector.builder(); | ||
| 171 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1) | ||
| 172 | - .matchVlanId(VlanId.ANY); | ||
| 173 | - | ||
| 174 | - TrafficTreatment.Builder treatmentBuilder = | ||
| 175 | - DefaultTrafficTreatment.builder(); | ||
| 176 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
| 177 | - .setVlanId(VlanId.vlanId((short) 2)); | ||
| 178 | - | ||
| 179 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 180 | - ingressPoints.add(SW1_ETH1); | ||
| 181 | - ingressPoints.add(SW2_ETH1); | ||
| 182 | - | ||
| 183 | - MultiPointToSinglePointIntent intent = | ||
| 184 | - MultiPointToSinglePointIntent.builder() | ||
| 185 | - .appId(APPID) | ||
| 186 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
| 187 | - .selector(selectorBuilder.build()) | ||
| 188 | - .treatment(treatmentBuilder.build()) | ||
| 189 | - .ingressPoints(ingressPoints) | ||
| 190 | - .egressPoint(SW3_ETH1) | ||
| 191 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
| 192 | - .build(); | ||
| 193 | - | ||
| 194 | - // Setup the expected intents | ||
| 195 | - intentSynchronizer.submit(eqExceptId(intent)); | ||
| 196 | - replay(intentSynchronizer); | ||
| 197 | - | ||
| 198 | - // Send in the added event | ||
| 199 | - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
| 200 | - | ||
| 201 | - verify(intentSynchronizer); | ||
| 202 | - } | ||
| 203 | - | ||
| 204 | - private class TestCoreService extends CoreServiceAdapter { | ||
| 205 | - @Override | ||
| 206 | - public ApplicationId getAppId(String name) { | ||
| 207 | - return APPID; | ||
| 208 | - } | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - private class TestRouteService extends RouteServiceAdapter { | ||
| 212 | - @Override | ||
| 213 | - public void addListener(RouteListener routeListener) { | ||
| 214 | - SdnIpFibVlansToVlanDifferentTest.this.routeListener = routeListener; | ||
| 215 | - } | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
| 219 | - @Override | ||
| 220 | - public void addListener(InterfaceListener listener) { | ||
| 221 | - SdnIpFibVlansToVlanDifferentTest.this.interfaceListener = listener; | ||
| 222 | - } | ||
| 223 | - } | ||
| 224 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2016-present 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.sdnip; | ||
| 18 | - | ||
| 19 | -import com.google.common.collect.Lists; | ||
| 20 | -import com.google.common.collect.Sets; | ||
| 21 | -import org.junit.Before; | ||
| 22 | -import org.junit.Test; | ||
| 23 | -import org.onlab.packet.Ethernet; | ||
| 24 | -import org.onlab.packet.Ip4Address; | ||
| 25 | -import org.onlab.packet.Ip4Prefix; | ||
| 26 | -import org.onlab.packet.IpPrefix; | ||
| 27 | -import org.onlab.packet.MacAddress; | ||
| 28 | -import org.onlab.packet.VlanId; | ||
| 29 | -import org.onosproject.TestApplicationId; | ||
| 30 | -import org.onosproject.core.ApplicationId; | ||
| 31 | -import org.onosproject.core.CoreServiceAdapter; | ||
| 32 | -import org.onosproject.incubator.net.intf.Interface; | ||
| 33 | -import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 34 | -import org.onosproject.incubator.net.intf.InterfaceService; | ||
| 35 | -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
| 36 | -import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
| 37 | -import org.onosproject.incubator.net.routing.RouteEvent; | ||
| 38 | -import org.onosproject.incubator.net.routing.RouteListener; | ||
| 39 | -import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
| 40 | -import org.onosproject.net.ConnectPoint; | ||
| 41 | -import org.onosproject.net.DeviceId; | ||
| 42 | -import org.onosproject.net.PortNumber; | ||
| 43 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 44 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 45 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 46 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 47 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
| 48 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
| 49 | -import org.onosproject.net.intent.Key; | ||
| 50 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
| 51 | -import org.onosproject.routing.IntentSynchronizationService; | ||
| 52 | - | ||
| 53 | -import java.util.Collections; | ||
| 54 | -import java.util.HashSet; | ||
| 55 | -import java.util.List; | ||
| 56 | -import java.util.Set; | ||
| 57 | - | ||
| 58 | -import static org.easymock.EasyMock.*; | ||
| 59 | -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
| 60 | - | ||
| 61 | -/** | ||
| 62 | - * Unit tests for SdnIpFib. | ||
| 63 | - */ | ||
| 64 | -public class SdnIpFibVlansToVlanSameTest extends AbstractIntentTest { | ||
| 65 | - | ||
| 66 | - private InterfaceService interfaceService; | ||
| 67 | - | ||
| 68 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
| 69 | - DeviceId.deviceId("of:0000000000000001"), | ||
| 70 | - PortNumber.portNumber(1)); | ||
| 71 | - | ||
| 72 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
| 73 | - DeviceId.deviceId("of:0000000000000002"), | ||
| 74 | - PortNumber.portNumber(1)); | ||
| 75 | - | ||
| 76 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
| 77 | - DeviceId.deviceId("of:0000000000000003"), | ||
| 78 | - PortNumber.portNumber(1)); | ||
| 79 | - | ||
| 80 | - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
| 81 | - | ||
| 82 | - private SdnIpFib sdnipFib; | ||
| 83 | - private IntentSynchronizationService intentSynchronizer; | ||
| 84 | - private final Set<Interface> interfaces = Sets.newHashSet(); | ||
| 85 | - | ||
| 86 | - private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
| 87 | - | ||
| 88 | - private RouteListener routeListener; | ||
| 89 | - private InterfaceListener interfaceListener; | ||
| 90 | - | ||
| 91 | - @Before | ||
| 92 | - public void setUp() throws Exception { | ||
| 93 | - super.setUp(); | ||
| 94 | - | ||
| 95 | - interfaceService = createMock(InterfaceService.class); | ||
| 96 | - | ||
| 97 | - interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 98 | - expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
| 99 | - | ||
| 100 | - // These will set expectations on routingConfig and interfaceService | ||
| 101 | - setUpInterfaceService(); | ||
| 102 | - | ||
| 103 | - replay(interfaceService); | ||
| 104 | - | ||
| 105 | - intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
| 106 | - | ||
| 107 | - sdnipFib = new SdnIpFib(); | ||
| 108 | - sdnipFib.routeService = new TestRouteService(); | ||
| 109 | - sdnipFib.coreService = new TestCoreService(); | ||
| 110 | - sdnipFib.interfaceService = interfaceService; | ||
| 111 | - sdnipFib.intentSynchronizer = intentSynchronizer; | ||
| 112 | - | ||
| 113 | - sdnipFib.activate(); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | - * Sets up the interface service. | ||
| 118 | - */ | ||
| 119 | - private void setUpInterfaceService() { | ||
| 120 | - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
| 121 | - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
| 122 | - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
| 123 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
| 124 | - VlanId.vlanId((short) 1)); | ||
| 125 | - interfaces.add(sw1Eth1); | ||
| 126 | - | ||
| 127 | - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
| 128 | - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
| 129 | - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
| 130 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
| 131 | - VlanId.vlanId((short) 1)); | ||
| 132 | - interfaces.add(sw2Eth1); | ||
| 133 | - | ||
| 134 | - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
| 135 | - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
| 136 | - Lists.newArrayList(interfaceIpAddress3), | ||
| 137 | - MacAddress.valueOf("00:00:00:00:00:03"), | ||
| 138 | - VlanId.vlanId((short) 1)); | ||
| 139 | - interfaces.add(sw3Eth1); | ||
| 140 | - | ||
| 141 | - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
| 142 | - Collections.singleton(sw1Eth1)).anyTimes(); | ||
| 143 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
| 144 | - .andReturn(sw1Eth1).anyTimes(); | ||
| 145 | - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
| 146 | - Collections.singleton(sw2Eth1)).anyTimes(); | ||
| 147 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
| 148 | - .andReturn(sw2Eth1).anyTimes(); | ||
| 149 | - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
| 150 | - Collections.singleton(sw3Eth1)).anyTimes(); | ||
| 151 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
| 152 | - .andReturn(sw3Eth1).anyTimes(); | ||
| 153 | - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - /** | ||
| 157 | - * Tests adding a route. Ingresses with VLAN and next hop with no VLAN. | ||
| 158 | - * | ||
| 159 | - * We verify that the synchronizer records the correct state and that the | ||
| 160 | - * correct intent is submitted to the IntentService. | ||
| 161 | - */ | ||
| 162 | - @Test | ||
| 163 | - public void testRouteAdd() { | ||
| 164 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
| 165 | - Ip4Address.valueOf("192.168.30.1"), | ||
| 166 | - MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 167 | - | ||
| 168 | - // Construct a MultiPointToSinglePointIntent intent | ||
| 169 | - TrafficSelector.Builder selectorBuilder = | ||
| 170 | - DefaultTrafficSelector.builder(); | ||
| 171 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1) | ||
| 172 | - .matchVlanId(VlanId.ANY); | ||
| 173 | - | ||
| 174 | - TrafficTreatment.Builder treatmentBuilder = | ||
| 175 | - DefaultTrafficTreatment.builder(); | ||
| 176 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 177 | - | ||
| 178 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 179 | - ingressPoints.add(SW1_ETH1); | ||
| 180 | - ingressPoints.add(SW2_ETH1); | ||
| 181 | - | ||
| 182 | - MultiPointToSinglePointIntent intent = | ||
| 183 | - MultiPointToSinglePointIntent.builder() | ||
| 184 | - .appId(APPID) | ||
| 185 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
| 186 | - .selector(selectorBuilder.build()) | ||
| 187 | - .treatment(treatmentBuilder.build()) | ||
| 188 | - .ingressPoints(ingressPoints) | ||
| 189 | - .egressPoint(SW3_ETH1) | ||
| 190 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
| 191 | - .build(); | ||
| 192 | - | ||
| 193 | - // Setup the expected intents | ||
| 194 | - intentSynchronizer.submit(eqExceptId(intent)); | ||
| 195 | - replay(intentSynchronizer); | ||
| 196 | - | ||
| 197 | - // Send in the added event | ||
| 198 | - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
| 199 | - | ||
| 200 | - verify(intentSynchronizer); | ||
| 201 | - } | ||
| 202 | - | ||
| 203 | - private class TestCoreService extends CoreServiceAdapter { | ||
| 204 | - @Override | ||
| 205 | - public ApplicationId getAppId(String name) { | ||
| 206 | - return APPID; | ||
| 207 | - } | ||
| 208 | - } | ||
| 209 | - | ||
| 210 | - private class TestRouteService extends RouteServiceAdapter { | ||
| 211 | - @Override | ||
| 212 | - public void addListener(RouteListener routeListener) { | ||
| 213 | - SdnIpFibVlansToVlanSameTest.this.routeListener = routeListener; | ||
| 214 | - } | ||
| 215 | - } | ||
| 216 | - | ||
| 217 | - private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
| 218 | - @Override | ||
| 219 | - public void addListener(InterfaceListener listener) { | ||
| 220 | - SdnIpFibVlansToVlanSameTest.this.interfaceListener = listener; | ||
| 221 | - } | ||
| 222 | - } | ||
| 223 | -} |
| 1 | -/* | ||
| 2 | - * Copyright 2016-present 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.sdnip; | ||
| 18 | - | ||
| 19 | -import com.google.common.collect.Lists; | ||
| 20 | -import com.google.common.collect.Sets; | ||
| 21 | -import org.junit.Before; | ||
| 22 | -import org.junit.Test; | ||
| 23 | -import org.onlab.packet.Ethernet; | ||
| 24 | -import org.onlab.packet.Ip4Address; | ||
| 25 | -import org.onlab.packet.Ip4Prefix; | ||
| 26 | -import org.onlab.packet.IpPrefix; | ||
| 27 | -import org.onlab.packet.MacAddress; | ||
| 28 | -import org.onlab.packet.VlanId; | ||
| 29 | -import org.onosproject.TestApplicationId; | ||
| 30 | -import org.onosproject.core.ApplicationId; | ||
| 31 | -import org.onosproject.core.CoreServiceAdapter; | ||
| 32 | -import org.onosproject.incubator.net.intf.Interface; | ||
| 33 | -import org.onosproject.incubator.net.intf.InterfaceListener; | ||
| 34 | -import org.onosproject.incubator.net.intf.InterfaceService; | ||
| 35 | -import org.onosproject.incubator.net.intf.InterfaceServiceAdapter; | ||
| 36 | -import org.onosproject.incubator.net.routing.ResolvedRoute; | ||
| 37 | -import org.onosproject.incubator.net.routing.RouteEvent; | ||
| 38 | -import org.onosproject.incubator.net.routing.RouteListener; | ||
| 39 | -import org.onosproject.incubator.net.routing.RouteServiceAdapter; | ||
| 40 | -import org.onosproject.net.ConnectPoint; | ||
| 41 | -import org.onosproject.net.DeviceId; | ||
| 42 | -import org.onosproject.net.PortNumber; | ||
| 43 | -import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 44 | -import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 45 | -import org.onosproject.net.flow.TrafficSelector; | ||
| 46 | -import org.onosproject.net.flow.TrafficTreatment; | ||
| 47 | -import org.onosproject.net.host.InterfaceIpAddress; | ||
| 48 | -import org.onosproject.net.intent.AbstractIntentTest; | ||
| 49 | -import org.onosproject.net.intent.Key; | ||
| 50 | -import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
| 51 | -import org.onosproject.routing.IntentSynchronizationService; | ||
| 52 | - | ||
| 53 | -import java.util.Collections; | ||
| 54 | -import java.util.HashSet; | ||
| 55 | -import java.util.List; | ||
| 56 | -import java.util.Set; | ||
| 57 | - | ||
| 58 | -import static org.easymock.EasyMock.*; | ||
| 59 | -import static org.onosproject.routing.TestIntentServiceHelper.eqExceptId; | ||
| 60 | - | ||
| 61 | -/** | ||
| 62 | - * Unit tests for SdnIpFib. | ||
| 63 | - */ | ||
| 64 | -public class SdnIpFibVlanstoNoVlanTest extends AbstractIntentTest { | ||
| 65 | - | ||
| 66 | - private InterfaceService interfaceService; | ||
| 67 | - | ||
| 68 | - private static final ConnectPoint SW1_ETH1 = new ConnectPoint( | ||
| 69 | - DeviceId.deviceId("of:0000000000000001"), | ||
| 70 | - PortNumber.portNumber(1)); | ||
| 71 | - | ||
| 72 | - private static final ConnectPoint SW2_ETH1 = new ConnectPoint( | ||
| 73 | - DeviceId.deviceId("of:0000000000000002"), | ||
| 74 | - PortNumber.portNumber(1)); | ||
| 75 | - | ||
| 76 | - private static final ConnectPoint SW3_ETH1 = new ConnectPoint( | ||
| 77 | - DeviceId.deviceId("of:0000000000000003"), | ||
| 78 | - PortNumber.portNumber(1)); | ||
| 79 | - | ||
| 80 | - private static final IpPrefix PREFIX1 = Ip4Prefix.valueOf("1.1.1.0/24"); | ||
| 81 | - | ||
| 82 | - private SdnIpFib sdnipFib; | ||
| 83 | - private IntentSynchronizationService intentSynchronizer; | ||
| 84 | - private final Set<Interface> interfaces = Sets.newHashSet(); | ||
| 85 | - | ||
| 86 | - private static final ApplicationId APPID = TestApplicationId.create("SDNIP"); | ||
| 87 | - | ||
| 88 | - private RouteListener routeListener; | ||
| 89 | - private InterfaceListener interfaceListener; | ||
| 90 | - | ||
| 91 | - @Before | ||
| 92 | - public void setUp() throws Exception { | ||
| 93 | - super.setUp(); | ||
| 94 | - | ||
| 95 | - interfaceService = createMock(InterfaceService.class); | ||
| 96 | - | ||
| 97 | - interfaceService.addListener(anyObject(InterfaceListener.class)); | ||
| 98 | - expectLastCall().andDelegateTo(new InterfaceServiceDelegate()); | ||
| 99 | - | ||
| 100 | - // These will set expectations on routingConfig and interfaceService | ||
| 101 | - setUpInterfaceService(); | ||
| 102 | - | ||
| 103 | - replay(interfaceService); | ||
| 104 | - | ||
| 105 | - intentSynchronizer = createMock(IntentSynchronizationService.class); | ||
| 106 | - | ||
| 107 | - sdnipFib = new SdnIpFib(); | ||
| 108 | - sdnipFib.routeService = new TestRouteService(); | ||
| 109 | - sdnipFib.coreService = new TestCoreService(); | ||
| 110 | - sdnipFib.interfaceService = interfaceService; | ||
| 111 | - sdnipFib.intentSynchronizer = intentSynchronizer; | ||
| 112 | - | ||
| 113 | - sdnipFib.activate(); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - /** | ||
| 117 | - * Sets up the interface service. | ||
| 118 | - */ | ||
| 119 | - private void setUpInterfaceService() { | ||
| 120 | - List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList(); | ||
| 121 | - interfaceIpAddresses1.add(InterfaceIpAddress.valueOf("192.168.10.101/24")); | ||
| 122 | - Interface sw1Eth1 = new Interface("sw1-eth1", SW1_ETH1, | ||
| 123 | - interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"), | ||
| 124 | - VlanId.vlanId((short) 1)); | ||
| 125 | - interfaces.add(sw1Eth1); | ||
| 126 | - | ||
| 127 | - List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList(); | ||
| 128 | - interfaceIpAddresses2.add(InterfaceIpAddress.valueOf("192.168.20.101/24")); | ||
| 129 | - Interface sw2Eth1 = new Interface("sw2-eth1", SW2_ETH1, | ||
| 130 | - interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"), | ||
| 131 | - VlanId.vlanId((short) 1)); | ||
| 132 | - interfaces.add(sw2Eth1); | ||
| 133 | - | ||
| 134 | - InterfaceIpAddress interfaceIpAddress3 = InterfaceIpAddress.valueOf("192.168.30.101/24"); | ||
| 135 | - Interface sw3Eth1 = new Interface("sw3-eth1", SW3_ETH1, | ||
| 136 | - Lists.newArrayList(interfaceIpAddress3), | ||
| 137 | - MacAddress.valueOf("00:00:00:00:00:03"), | ||
| 138 | - VlanId.NONE); | ||
| 139 | - interfaces.add(sw3Eth1); | ||
| 140 | - | ||
| 141 | - expect(interfaceService.getInterfacesByPort(SW1_ETH1)).andReturn( | ||
| 142 | - Collections.singleton(sw1Eth1)).anyTimes(); | ||
| 143 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.10.1"))) | ||
| 144 | - .andReturn(sw1Eth1).anyTimes(); | ||
| 145 | - expect(interfaceService.getInterfacesByPort(SW2_ETH1)).andReturn( | ||
| 146 | - Collections.singleton(sw2Eth1)).anyTimes(); | ||
| 147 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.20.1"))) | ||
| 148 | - .andReturn(sw2Eth1).anyTimes(); | ||
| 149 | - expect(interfaceService.getInterfacesByPort(SW3_ETH1)).andReturn( | ||
| 150 | - Collections.singleton(sw3Eth1)).anyTimes(); | ||
| 151 | - expect(interfaceService.getMatchingInterface(Ip4Address.valueOf("192.168.30.1"))) | ||
| 152 | - .andReturn(sw3Eth1).anyTimes(); | ||
| 153 | - expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); | ||
| 154 | - } | ||
| 155 | - | ||
| 156 | - /** | ||
| 157 | - * Tests adding a route. Ingresses with VLAN and next hop with no VLAN. | ||
| 158 | - * | ||
| 159 | - * We verify that the synchronizer records the correct state and that the | ||
| 160 | - * correct intent is submitted to the IntentService. | ||
| 161 | - */ | ||
| 162 | - @Test | ||
| 163 | - public void testRouteAdd() { | ||
| 164 | - ResolvedRoute route = new ResolvedRoute(PREFIX1, | ||
| 165 | - Ip4Address.valueOf("192.168.30.1"), | ||
| 166 | - MacAddress.valueOf("00:00:00:00:00:03")); | ||
| 167 | - | ||
| 168 | - // Construct a MultiPointToSinglePointIntent intent | ||
| 169 | - TrafficSelector.Builder selectorBuilder = | ||
| 170 | - DefaultTrafficSelector.builder(); | ||
| 171 | - selectorBuilder.matchEthType(Ethernet.TYPE_IPV4).matchIPDst(PREFIX1) | ||
| 172 | - .matchVlanId(VlanId.ANY); | ||
| 173 | - | ||
| 174 | - TrafficTreatment.Builder treatmentBuilder = | ||
| 175 | - DefaultTrafficTreatment.builder(); | ||
| 176 | - treatmentBuilder.setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) | ||
| 177 | - .popVlan(); | ||
| 178 | - | ||
| 179 | - Set<ConnectPoint> ingressPoints = new HashSet<>(); | ||
| 180 | - ingressPoints.add(SW1_ETH1); | ||
| 181 | - ingressPoints.add(SW2_ETH1); | ||
| 182 | - | ||
| 183 | - MultiPointToSinglePointIntent intent = | ||
| 184 | - MultiPointToSinglePointIntent.builder() | ||
| 185 | - .appId(APPID) | ||
| 186 | - .key(Key.of(PREFIX1.toString(), APPID)) | ||
| 187 | - .selector(selectorBuilder.build()) | ||
| 188 | - .treatment(treatmentBuilder.build()) | ||
| 189 | - .ingressPoints(ingressPoints) | ||
| 190 | - .egressPoint(SW3_ETH1) | ||
| 191 | - .constraints(SdnIpFib.CONSTRAINTS) | ||
| 192 | - .build(); | ||
| 193 | - | ||
| 194 | - // Setup the expected intents | ||
| 195 | - intentSynchronizer.submit(eqExceptId(intent)); | ||
| 196 | - replay(intentSynchronizer); | ||
| 197 | - | ||
| 198 | - // Send in the added event | ||
| 199 | - routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route)); | ||
| 200 | - | ||
| 201 | - verify(intentSynchronizer); | ||
| 202 | - } | ||
| 203 | - | ||
| 204 | - private class TestCoreService extends CoreServiceAdapter { | ||
| 205 | - @Override | ||
| 206 | - public ApplicationId getAppId(String name) { | ||
| 207 | - return APPID; | ||
| 208 | - } | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - private class TestRouteService extends RouteServiceAdapter { | ||
| 212 | - @Override | ||
| 213 | - public void addListener(RouteListener routeListener) { | ||
| 214 | - SdnIpFibVlanstoNoVlanTest.this.routeListener = routeListener; | ||
| 215 | - } | ||
| 216 | - } | ||
| 217 | - | ||
| 218 | - private class InterfaceServiceDelegate extends InterfaceServiceAdapter { | ||
| 219 | - @Override | ||
| 220 | - public void addListener(InterfaceListener listener) { | ||
| 221 | - SdnIpFibVlanstoNoVlanTest.this.interfaceListener = listener; | ||
| 222 | - } | ||
| 223 | - } | ||
| 224 | -} |
| ... | @@ -549,7 +549,16 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { | ... | @@ -549,7 +549,16 @@ public class NeighbourResolutionManager implements NeighbourResolutionService { |
| 549 | 549 | ||
| 550 | @Override | 550 | @Override |
| 551 | public void forward(NeighbourMessageContext context, Interface outIntf) { | 551 | public void forward(NeighbourMessageContext context, Interface outIntf) { |
| 552 | - // TODO implement | 552 | + Ethernet packetOut = (Ethernet) context.packet().clone(); |
| 553 | + if (outIntf.vlan().equals(VlanId.NONE)) { | ||
| 554 | + // The egress interface has no VLAN Id. Send out an untagged | ||
| 555 | + // packet | ||
| 556 | + packetOut.setVlanID(Ethernet.VLAN_UNTAGGED); | ||
| 557 | + } else { | ||
| 558 | + // The egress interface has a VLAN set. Send out a tagged packet | ||
| 559 | + packetOut.setVlanID(outIntf.vlan().toShort()); | ||
| 560 | + } | ||
| 561 | + sendTo(packetOut, outIntf.connectPoint()); | ||
| 553 | } | 562 | } |
| 554 | 563 | ||
| 555 | @Override | 564 | @Override | ... | ... |
-
Please register or login to post a comment