Showing
28 changed files
with
300 additions
and
425 deletions
| 1 | package org.onlab.onos.ifwd; | 1 | package org.onlab.onos.ifwd; |
| 2 | 2 | ||
| 3 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 4 | - | ||
| 5 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
| 6 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
| 7 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
| 8 | import org.apache.felix.scr.annotations.Reference; | 6 | import org.apache.felix.scr.annotations.Reference; |
| 9 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 7 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 8 | +import org.onlab.onos.ApplicationId; | ||
| 9 | +import org.onlab.onos.CoreService; | ||
| 10 | import org.onlab.onos.net.Host; | 10 | import org.onlab.onos.net.Host; |
| 11 | import org.onlab.onos.net.HostId; | 11 | import org.onlab.onos.net.HostId; |
| 12 | import org.onlab.onos.net.PortNumber; | 12 | import org.onlab.onos.net.PortNumber; |
| ... | @@ -16,7 +16,6 @@ import org.onlab.onos.net.flow.TrafficSelector; | ... | @@ -16,7 +16,6 @@ import org.onlab.onos.net.flow.TrafficSelector; |
| 16 | import org.onlab.onos.net.flow.TrafficTreatment; | 16 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 17 | import org.onlab.onos.net.host.HostService; | 17 | import org.onlab.onos.net.host.HostService; |
| 18 | import org.onlab.onos.net.intent.HostToHostIntent; | 18 | import org.onlab.onos.net.intent.HostToHostIntent; |
| 19 | -import org.onlab.onos.net.intent.IntentId; | ||
| 20 | import org.onlab.onos.net.intent.IntentService; | 19 | import org.onlab.onos.net.intent.IntentService; |
| 21 | import org.onlab.onos.net.packet.DefaultOutboundPacket; | 20 | import org.onlab.onos.net.packet.DefaultOutboundPacket; |
| 22 | import org.onlab.onos.net.packet.InboundPacket; | 21 | import org.onlab.onos.net.packet.InboundPacket; |
| ... | @@ -28,6 +27,8 @@ import org.onlab.onos.net.topology.TopologyService; | ... | @@ -28,6 +27,8 @@ import org.onlab.onos.net.topology.TopologyService; |
| 28 | import org.onlab.packet.Ethernet; | 27 | import org.onlab.packet.Ethernet; |
| 29 | import org.slf4j.Logger; | 28 | import org.slf4j.Logger; |
| 30 | 29 | ||
| 30 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 31 | + | ||
| 31 | /** | 32 | /** |
| 32 | * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. | 33 | * WORK-IN-PROGRESS: Sample reactive forwarding application using intent framework. |
| 33 | */ | 34 | */ |
| ... | @@ -37,6 +38,9 @@ public class IntentReactiveForwarding { | ... | @@ -37,6 +38,9 @@ public class IntentReactiveForwarding { |
| 37 | private final Logger log = getLogger(getClass()); | 38 | private final Logger log = getLogger(getClass()); |
| 38 | 39 | ||
| 39 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 40 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 41 | + protected CoreService coreService; | ||
| 42 | + | ||
| 43 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 40 | protected TopologyService topologyService; | 44 | protected TopologyService topologyService; |
| 41 | 45 | ||
| 42 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 46 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -49,11 +53,11 @@ public class IntentReactiveForwarding { | ... | @@ -49,11 +53,11 @@ public class IntentReactiveForwarding { |
| 49 | protected HostService hostService; | 53 | protected HostService hostService; |
| 50 | 54 | ||
| 51 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); | 55 | private ReactivePacketProcessor processor = new ReactivePacketProcessor(); |
| 52 | - | 56 | + private ApplicationId appId; |
| 53 | - private static long intentId = 0x123000; | ||
| 54 | 57 | ||
| 55 | @Activate | 58 | @Activate |
| 56 | public void activate() { | 59 | public void activate() { |
| 60 | + appId = coreService.registerApplication("org.onlab.onos.ifwd"); | ||
| 57 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); | 61 | packetService.addProcessor(processor, PacketProcessor.ADVISOR_MAX + 2); |
| 58 | log.info("Started"); | 62 | log.info("Started"); |
| 59 | } | 63 | } |
| ... | @@ -126,9 +130,8 @@ public class IntentReactiveForwarding { | ... | @@ -126,9 +130,8 @@ public class IntentReactiveForwarding { |
| 126 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); | 130 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
| 127 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 131 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 128 | 132 | ||
| 129 | - HostToHostIntent intent = | 133 | + HostToHostIntent intent = new HostToHostIntent(appId, srcId, dstId, |
| 130 | - new HostToHostIntent(new IntentId(intentId++), srcId, dstId, | 134 | + selector, treatment); |
| 131 | - selector, treatment); | ||
| 132 | 135 | ||
| 133 | intentService.submit(intent); | 136 | intentService.submit(intent); |
| 134 | } | 137 | } | ... | ... |
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| ... | @@ -10,6 +10,8 @@ import org.apache.felix.scr.annotations.Deactivate; | ... | @@ -10,6 +10,8 @@ import org.apache.felix.scr.annotations.Deactivate; |
| 10 | import org.apache.felix.scr.annotations.Reference; | 10 | import org.apache.felix.scr.annotations.Reference; |
| 11 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 11 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 12 | import org.apache.felix.scr.annotations.Service; | 12 | import org.apache.felix.scr.annotations.Service; |
| 13 | +import org.onlab.onos.ApplicationId; | ||
| 14 | +import org.onlab.onos.CoreService; | ||
| 13 | import org.onlab.onos.net.host.HostService; | 15 | import org.onlab.onos.net.host.HostService; |
| 14 | import org.onlab.onos.net.intent.IntentService; | 16 | import org.onlab.onos.net.intent.IntentService; |
| 15 | import org.onlab.onos.sdnip.bgp.BgpRouteEntry; | 17 | import org.onlab.onos.sdnip.bgp.BgpRouteEntry; |
| ... | @@ -24,9 +26,14 @@ import org.slf4j.Logger; | ... | @@ -24,9 +26,14 @@ import org.slf4j.Logger; |
| 24 | @Service | 26 | @Service |
| 25 | public class SdnIp implements SdnIpService { | 27 | public class SdnIp implements SdnIpService { |
| 26 | 28 | ||
| 29 | + private static final String SDN_ID_APP = "org.onlab.onos.sdnip"; | ||
| 30 | + | ||
| 27 | private final Logger log = getLogger(getClass()); | 31 | private final Logger log = getLogger(getClass()); |
| 28 | 32 | ||
| 29 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 33 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 34 | + protected CoreService coreService; | ||
| 35 | + | ||
| 36 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 30 | protected IntentService intentService; | 37 | protected IntentService intentService; |
| 31 | 38 | ||
| 32 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 39 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| ... | @@ -46,10 +53,11 @@ public class SdnIp implements SdnIpService { | ... | @@ -46,10 +53,11 @@ public class SdnIp implements SdnIpService { |
| 46 | 53 | ||
| 47 | InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService); | 54 | InterfaceService interfaceService = new HostToInterfaceAdaptor(hostService); |
| 48 | 55 | ||
| 49 | - peerConnectivity = new PeerConnectivityManager(config, interfaceService, intentService); | 56 | + ApplicationId appId = coreService.registerApplication(SDN_ID_APP); |
| 57 | + peerConnectivity = new PeerConnectivityManager(appId, config, interfaceService, intentService); | ||
| 50 | peerConnectivity.start(); | 58 | peerConnectivity.start(); |
| 51 | 59 | ||
| 52 | - router = new Router(intentService, hostService, config, interfaceService); | 60 | + router = new Router(appId, intentService, hostService, config, interfaceService); |
| 53 | router.start(); | 61 | router.start(); |
| 54 | 62 | ||
| 55 | bgpSessionManager = new BgpSessionManager(router); | 63 | bgpSessionManager = new BgpSessionManager(router); | ... | ... |
| 1 | package org.onlab.onos.sdnip; | 1 | package org.onlab.onos.sdnip; |
| 2 | 2 | ||
| 3 | -import static org.easymock.EasyMock.createMock; | 3 | +import com.google.common.collect.Sets; |
| 4 | -import static org.easymock.EasyMock.expect; | ||
| 5 | -import static org.easymock.EasyMock.replay; | ||
| 6 | -import static org.easymock.EasyMock.reportMatcher; | ||
| 7 | -import static org.easymock.EasyMock.reset; | ||
| 8 | -import static org.easymock.EasyMock.verify; | ||
| 9 | - | ||
| 10 | -import java.util.ArrayList; | ||
| 11 | -import java.util.Collections; | ||
| 12 | -import java.util.HashMap; | ||
| 13 | -import java.util.LinkedList; | ||
| 14 | -import java.util.List; | ||
| 15 | -import java.util.Map; | ||
| 16 | - | ||
| 17 | import org.easymock.IArgumentMatcher; | 4 | import org.easymock.IArgumentMatcher; |
| 18 | import org.junit.Before; | 5 | import org.junit.Before; |
| 19 | import org.junit.Ignore; | 6 | import org.junit.Ignore; |
| 20 | import org.junit.Test; | 7 | import org.junit.Test; |
| 8 | +import org.onlab.onos.ApplicationId; | ||
| 21 | import org.onlab.onos.net.ConnectPoint; | 9 | import org.onlab.onos.net.ConnectPoint; |
| 22 | import org.onlab.onos.net.DeviceId; | 10 | import org.onlab.onos.net.DeviceId; |
| 23 | import org.onlab.onos.net.PortNumber; | 11 | import org.onlab.onos.net.PortNumber; |
| ... | @@ -25,7 +13,6 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector; | ... | @@ -25,7 +13,6 @@ import org.onlab.onos.net.flow.DefaultTrafficSelector; |
| 25 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; | 13 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 26 | import org.onlab.onos.net.flow.TrafficSelector; | 14 | import org.onlab.onos.net.flow.TrafficSelector; |
| 27 | import org.onlab.onos.net.flow.TrafficTreatment; | 15 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 28 | -import org.onlab.onos.net.intent.IntentId; | ||
| 29 | import org.onlab.onos.net.intent.IntentService; | 16 | import org.onlab.onos.net.intent.IntentService; |
| 30 | import org.onlab.onos.net.intent.PointToPointIntent; | 17 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 31 | import org.onlab.onos.sdnip.bgp.BgpConstants; | 18 | import org.onlab.onos.sdnip.bgp.BgpConstants; |
| ... | @@ -40,13 +27,32 @@ import org.onlab.packet.IpAddress; | ... | @@ -40,13 +27,32 @@ import org.onlab.packet.IpAddress; |
| 40 | import org.onlab.packet.IpPrefix; | 27 | import org.onlab.packet.IpPrefix; |
| 41 | import org.onlab.packet.MacAddress; | 28 | import org.onlab.packet.MacAddress; |
| 42 | 29 | ||
| 43 | -import com.google.common.collect.Sets; | 30 | +import java.util.ArrayList; |
| 31 | +import java.util.Collections; | ||
| 32 | +import java.util.HashMap; | ||
| 33 | +import java.util.LinkedList; | ||
| 34 | +import java.util.List; | ||
| 35 | +import java.util.Map; | ||
| 36 | + | ||
| 37 | +import static org.easymock.EasyMock.*; | ||
| 44 | 38 | ||
| 45 | /** | 39 | /** |
| 46 | * Unit tests for PeerConnectivityManager interface. | 40 | * Unit tests for PeerConnectivityManager interface. |
| 47 | */ | 41 | */ |
| 48 | public class PeerConnectivityManagerTest { | 42 | public class PeerConnectivityManagerTest { |
| 49 | 43 | ||
| 44 | + private static final ApplicationId APPID = new ApplicationId() { | ||
| 45 | + @Override | ||
| 46 | + public short id() { | ||
| 47 | + return 0; | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + @Override | ||
| 51 | + public String name() { | ||
| 52 | + return "foo"; | ||
| 53 | + } | ||
| 54 | + }; | ||
| 55 | + | ||
| 50 | private PeerConnectivityManager peerConnectivityManager; | 56 | private PeerConnectivityManager peerConnectivityManager; |
| 51 | private IntentService intentService; | 57 | private IntentService intentService; |
| 52 | private SdnIpConfigService configInfoService; | 58 | private SdnIpConfigService configInfoService; |
| ... | @@ -81,9 +87,6 @@ public class PeerConnectivityManagerTest { | ... | @@ -81,9 +87,6 @@ public class PeerConnectivityManagerTest { |
| 81 | private final ConnectPoint s2Eth1 = | 87 | private final ConnectPoint s2Eth1 = |
| 82 | new ConnectPoint(deviceId2, PortNumber.portNumber(1)); | 88 | new ConnectPoint(deviceId2, PortNumber.portNumber(1)); |
| 83 | 89 | ||
| 84 | - // We don't compare the intent ID so all expected intents can use the same ID | ||
| 85 | - private final IntentId testIntentId = new IntentId(0); | ||
| 86 | - | ||
| 87 | private final TrafficTreatment noTreatment = | 90 | private final TrafficTreatment noTreatment = |
| 88 | DefaultTrafficTreatment.builder().build(); | 91 | DefaultTrafficTreatment.builder().build(); |
| 89 | 92 | ||
| ... | @@ -257,7 +260,7 @@ public class PeerConnectivityManagerTest { | ... | @@ -257,7 +260,7 @@ public class PeerConnectivityManagerTest { |
| 257 | } | 260 | } |
| 258 | 261 | ||
| 259 | PointToPointIntent intent = new PointToPointIntent( | 262 | PointToPointIntent intent = new PointToPointIntent( |
| 260 | - testIntentId, builder.build(), noTreatment, | 263 | + APPID, builder.build(), noTreatment, |
| 261 | srcConnectPoint, dstConnectPoint); | 264 | srcConnectPoint, dstConnectPoint); |
| 262 | 265 | ||
| 263 | intentList.add(intent); | 266 | intentList.add(intent); |
| ... | @@ -429,7 +432,7 @@ public class PeerConnectivityManagerTest { | ... | @@ -429,7 +432,7 @@ public class PeerConnectivityManagerTest { |
| 429 | .build(); | 432 | .build(); |
| 430 | 433 | ||
| 431 | PointToPointIntent intent = new PointToPointIntent( | 434 | PointToPointIntent intent = new PointToPointIntent( |
| 432 | - testIntentId, selector, noTreatment, | 435 | + APPID, selector, noTreatment, |
| 433 | srcConnectPoint, dstConnectPoint); | 436 | srcConnectPoint, dstConnectPoint); |
| 434 | 437 | ||
| 435 | intentList.add(intent); | 438 | intentList.add(intent); |
| ... | @@ -511,7 +514,7 @@ public class PeerConnectivityManagerTest { | ... | @@ -511,7 +514,7 @@ public class PeerConnectivityManagerTest { |
| 511 | intentService = createMock(IntentService.class); | 514 | intentService = createMock(IntentService.class); |
| 512 | replay(intentService); | 515 | replay(intentService); |
| 513 | 516 | ||
| 514 | - peerConnectivityManager = new PeerConnectivityManager(configInfoService, | 517 | + peerConnectivityManager = new PeerConnectivityManager(APPID, configInfoService, |
| 515 | interfaceService, intentService); | 518 | interfaceService, intentService); |
| 516 | } | 519 | } |
| 517 | 520 | ||
| ... | @@ -557,7 +560,7 @@ public class PeerConnectivityManagerTest { | ... | @@ -557,7 +560,7 @@ public class PeerConnectivityManagerTest { |
| 557 | providedIntentString = providedIntent.toString(); | 560 | providedIntentString = providedIntent.toString(); |
| 558 | 561 | ||
| 559 | PointToPointIntent matchIntent = | 562 | PointToPointIntent matchIntent = |
| 560 | - new PointToPointIntent(providedIntent.id(), | 563 | + new PointToPointIntent(providedIntent.appId(), |
| 561 | intent.selector(), intent.treatment(), | 564 | intent.selector(), intent.treatment(), |
| 562 | intent.ingressPoint(), intent.egressPoint()); | 565 | intent.ingressPoint(), intent.egressPoint()); |
| 563 | 566 | ... | ... |
| ... | @@ -2,6 +2,8 @@ package org.onlab.onos.cli; | ... | @@ -2,6 +2,8 @@ package org.onlab.onos.cli; |
| 2 | 2 | ||
| 3 | import org.apache.karaf.shell.commands.Option; | 3 | import org.apache.karaf.shell.commands.Option; |
| 4 | import org.apache.karaf.shell.console.OsgiCommandSupport; | 4 | import org.apache.karaf.shell.console.OsgiCommandSupport; |
| 5 | +import org.onlab.onos.ApplicationId; | ||
| 6 | +import org.onlab.onos.CoreService; | ||
| 5 | import org.onlab.osgi.DefaultServiceDirectory; | 7 | import org.onlab.osgi.DefaultServiceDirectory; |
| 6 | import org.onlab.osgi.ServiceNotFoundException; | 8 | import org.onlab.osgi.ServiceNotFoundException; |
| 7 | 9 | ||
| ... | @@ -27,6 +29,15 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { | ... | @@ -27,6 +29,15 @@ public abstract class AbstractShellCommand extends OsgiCommandSupport { |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | /** | 31 | /** |
| 32 | + * Returns application ID for the CLI. | ||
| 33 | + * | ||
| 34 | + * @return command-line application identifier | ||
| 35 | + */ | ||
| 36 | + protected ApplicationId appId() { | ||
| 37 | + return get(CoreService.class).registerApplication("org.onlab.onos.cli"); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 30 | * Prints the arguments using the specified format. | 41 | * Prints the arguments using the specified format. |
| 31 | * | 42 | * |
| 32 | * @param format format string; see {@link String#format} | 43 | * @param format format string; see {@link String#format} | ... | ... |
| ... | @@ -9,7 +9,6 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ... | @@ -9,7 +9,6 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 9 | import org.onlab.onos.net.flow.TrafficSelector; | 9 | import org.onlab.onos.net.flow.TrafficSelector; |
| 10 | import org.onlab.onos.net.flow.TrafficTreatment; | 10 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 11 | import org.onlab.onos.net.intent.HostToHostIntent; | 11 | import org.onlab.onos.net.intent.HostToHostIntent; |
| 12 | -import org.onlab.onos.net.intent.IntentId; | ||
| 13 | import org.onlab.onos.net.intent.IntentService; | 12 | import org.onlab.onos.net.intent.IntentService; |
| 14 | 13 | ||
| 15 | /** | 14 | /** |
| ... | @@ -27,8 +26,6 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand { | ... | @@ -27,8 +26,6 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand { |
| 27 | required = true, multiValued = false) | 26 | required = true, multiValued = false) |
| 28 | String two = null; | 27 | String two = null; |
| 29 | 28 | ||
| 30 | - private static long id = 0x7870001; | ||
| 31 | - | ||
| 32 | @Override | 29 | @Override |
| 33 | protected void execute() { | 30 | protected void execute() { |
| 34 | IntentService service = get(IntentService.class); | 31 | IntentService service = get(IntentService.class); |
| ... | @@ -39,9 +36,8 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand { | ... | @@ -39,9 +36,8 @@ public class AddHostToHostIntentCommand extends AbstractShellCommand { |
| 39 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); | 36 | TrafficSelector selector = DefaultTrafficSelector.builder().build(); |
| 40 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 37 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 41 | 38 | ||
| 42 | - HostToHostIntent intent = | 39 | + HostToHostIntent intent = new HostToHostIntent(appId(), oneId, twoId, |
| 43 | - new HostToHostIntent(new IntentId(id++), oneId, twoId, | 40 | + selector, treatment); |
| 44 | - selector, treatment); | ||
| 45 | service.submit(intent); | 41 | service.submit(intent); |
| 46 | } | 42 | } |
| 47 | 43 | ... | ... |
| 1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
| 2 | 2 | ||
| 3 | -import java.util.HashSet; | ||
| 4 | -import java.util.Set; | ||
| 5 | - | ||
| 6 | import org.apache.karaf.shell.commands.Argument; | 3 | import org.apache.karaf.shell.commands.Argument; |
| 7 | import org.apache.karaf.shell.commands.Command; | 4 | import org.apache.karaf.shell.commands.Command; |
| 8 | import org.onlab.onos.cli.AbstractShellCommand; | 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| ... | @@ -14,11 +11,16 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ... | @@ -14,11 +11,16 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 14 | import org.onlab.onos.net.flow.TrafficSelector; | 11 | import org.onlab.onos.net.flow.TrafficSelector; |
| 15 | import org.onlab.onos.net.flow.TrafficTreatment; | 12 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 16 | import org.onlab.onos.net.intent.Intent; | 13 | import org.onlab.onos.net.intent.Intent; |
| 17 | -import org.onlab.onos.net.intent.IntentId; | ||
| 18 | import org.onlab.onos.net.intent.IntentService; | 14 | import org.onlab.onos.net.intent.IntentService; |
| 19 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; | 15 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
| 20 | import org.onlab.packet.Ethernet; | 16 | import org.onlab.packet.Ethernet; |
| 21 | 17 | ||
| 18 | +import java.util.HashSet; | ||
| 19 | +import java.util.Set; | ||
| 20 | + | ||
| 21 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
| 22 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
| 23 | + | ||
| 22 | /** | 24 | /** |
| 23 | * Installs point-to-point connectivity intents. | 25 | * Installs point-to-point connectivity intents. |
| 24 | */ | 26 | */ |
| ... | @@ -31,8 +33,6 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman | ... | @@ -31,8 +33,6 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman |
| 31 | required = true, multiValued = true) | 33 | required = true, multiValued = true) |
| 32 | String[] deviceStrings = null; | 34 | String[] deviceStrings = null; |
| 33 | 35 | ||
| 34 | - private static long id = 0x7070001; | ||
| 35 | - | ||
| 36 | @Override | 36 | @Override |
| 37 | protected void execute() { | 37 | protected void execute() { |
| 38 | IntentService service = get(IntentService.class); | 38 | IntentService service = get(IntentService.class); |
| ... | @@ -42,33 +42,26 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman | ... | @@ -42,33 +42,26 @@ public class AddMultiPointToSinglePointIntentCommand extends AbstractShellComman |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | String egressDeviceString = deviceStrings[deviceStrings.length - 1]; | 44 | String egressDeviceString = deviceStrings[deviceStrings.length - 1]; |
| 45 | - DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); | 45 | + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString)); |
| 46 | - PortNumber egressPortNumber = | 46 | + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
| 47 | - PortNumber.portNumber(getPortNumber(egressDeviceString)); | ||
| 48 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 47 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 49 | Set<ConnectPoint> ingressPoints = new HashSet<>(); | 48 | Set<ConnectPoint> ingressPoints = new HashSet<>(); |
| 50 | 49 | ||
| 51 | for (int index = 0; index < deviceStrings.length - 1; index++) { | 50 | for (int index = 0; index < deviceStrings.length - 1; index++) { |
| 52 | String ingressDeviceString = deviceStrings[index]; | 51 | String ingressDeviceString = deviceStrings[index]; |
| 53 | - DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); | 52 | + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString)); |
| 54 | - PortNumber ingressPortNumber = | 53 | + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString)); |
| 55 | - PortNumber.portNumber(getPortNumber(ingressDeviceString)); | ||
| 56 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); | 54 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); |
| 57 | ingressPoints.add(ingress); | 55 | ingressPoints.add(ingress); |
| 58 | } | 56 | } |
| 59 | 57 | ||
| 60 | - | ||
| 61 | TrafficSelector selector = DefaultTrafficSelector.builder() | 58 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| 62 | .matchEthType(Ethernet.TYPE_IPV4) | 59 | .matchEthType(Ethernet.TYPE_IPV4) |
| 63 | .build(); | 60 | .build(); |
| 64 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 61 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 65 | 62 | ||
| 66 | - Intent intent = | 63 | + Intent intent = new MultiPointToSinglePointIntent(appId(), selector, treatment, |
| 67 | - new MultiPointToSinglePointIntent(new IntentId(id++), | 64 | + ingressPoints, egress); |
| 68 | - selector, | ||
| 69 | - treatment, | ||
| 70 | - ingressPoints, | ||
| 71 | - egress); | ||
| 72 | service.submit(intent); | 65 | service.submit(intent); |
| 73 | } | 66 | } |
| 74 | 67 | ... | ... |
| ... | @@ -11,11 +11,13 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; | ... | @@ -11,11 +11,13 @@ import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
| 11 | import org.onlab.onos.net.flow.TrafficSelector; | 11 | import org.onlab.onos.net.flow.TrafficSelector; |
| 12 | import org.onlab.onos.net.flow.TrafficTreatment; | 12 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 13 | import org.onlab.onos.net.intent.Intent; | 13 | import org.onlab.onos.net.intent.Intent; |
| 14 | -import org.onlab.onos.net.intent.IntentId; | ||
| 15 | import org.onlab.onos.net.intent.IntentService; | 14 | import org.onlab.onos.net.intent.IntentService; |
| 16 | import org.onlab.onos.net.intent.PointToPointIntent; | 15 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 17 | import org.onlab.packet.Ethernet; | 16 | import org.onlab.packet.Ethernet; |
| 18 | 17 | ||
| 18 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
| 19 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
| 20 | + | ||
| 19 | /** | 21 | /** |
| 20 | * Installs point-to-point connectivity intents. | 22 | * Installs point-to-point connectivity intents. |
| 21 | */ | 23 | */ |
| ... | @@ -33,20 +35,16 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { | ... | @@ -33,20 +35,16 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { |
| 33 | required = true, multiValued = false) | 35 | required = true, multiValued = false) |
| 34 | String egressDeviceString = null; | 36 | String egressDeviceString = null; |
| 35 | 37 | ||
| 36 | - private static long id = 0x7470001; | ||
| 37 | - | ||
| 38 | @Override | 38 | @Override |
| 39 | protected void execute() { | 39 | protected void execute() { |
| 40 | IntentService service = get(IntentService.class); | 40 | IntentService service = get(IntentService.class); |
| 41 | 41 | ||
| 42 | - DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); | 42 | + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString)); |
| 43 | - PortNumber ingressPortNumber = | 43 | + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString)); |
| 44 | - PortNumber.portNumber(getPortNumber(ingressDeviceString)); | ||
| 45 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); | 44 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); |
| 46 | 45 | ||
| 47 | - DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); | 46 | + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString)); |
| 48 | - PortNumber egressPortNumber = | 47 | + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
| 49 | - PortNumber.portNumber(getPortNumber(egressDeviceString)); | ||
| 50 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 48 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 51 | 49 | ||
| 52 | TrafficSelector selector = DefaultTrafficSelector.builder() | 50 | TrafficSelector selector = DefaultTrafficSelector.builder() |
| ... | @@ -54,12 +52,8 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { | ... | @@ -54,12 +52,8 @@ public class AddPointToPointIntentCommand extends AbstractShellCommand { |
| 54 | .build(); | 52 | .build(); |
| 55 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); | 53 | TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); |
| 56 | 54 | ||
| 57 | - Intent intent = | 55 | + Intent intent = new PointToPointIntent(appId(), selector, treatment, |
| 58 | - new PointToPointIntent(new IntentId(id++), | 56 | + ingress, egress); |
| 59 | - selector, | ||
| 60 | - treatment, | ||
| 61 | - ingress, | ||
| 62 | - egress); | ||
| 63 | service.submit(intent); | 57 | service.submit(intent); |
| 64 | } | 58 | } |
| 65 | 59 | ... | ... |
| 1 | package org.onlab.onos.cli.net; | 1 | package org.onlab.onos.cli.net; |
| 2 | 2 | ||
| 3 | -import java.util.concurrent.CountDownLatch; | ||
| 4 | -import java.util.concurrent.TimeUnit; | ||
| 5 | - | ||
| 6 | import org.apache.karaf.shell.commands.Argument; | 3 | import org.apache.karaf.shell.commands.Argument; |
| 7 | import org.apache.karaf.shell.commands.Command; | 4 | import org.apache.karaf.shell.commands.Command; |
| 8 | import org.onlab.onos.cli.AbstractShellCommand; | 5 | import org.onlab.onos.cli.AbstractShellCommand; |
| ... | @@ -16,20 +13,25 @@ import org.onlab.onos.net.flow.TrafficTreatment; | ... | @@ -16,20 +13,25 @@ import org.onlab.onos.net.flow.TrafficTreatment; |
| 16 | import org.onlab.onos.net.intent.Intent; | 13 | import org.onlab.onos.net.intent.Intent; |
| 17 | import org.onlab.onos.net.intent.IntentEvent; | 14 | import org.onlab.onos.net.intent.IntentEvent; |
| 18 | import org.onlab.onos.net.intent.IntentEvent.Type; | 15 | import org.onlab.onos.net.intent.IntentEvent.Type; |
| 19 | -import org.onlab.onos.net.intent.IntentId; | ||
| 20 | import org.onlab.onos.net.intent.IntentListener; | 16 | import org.onlab.onos.net.intent.IntentListener; |
| 21 | import org.onlab.onos.net.intent.IntentService; | 17 | import org.onlab.onos.net.intent.IntentService; |
| 22 | import org.onlab.onos.net.intent.PointToPointIntent; | 18 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 23 | import org.onlab.packet.Ethernet; | 19 | import org.onlab.packet.Ethernet; |
| 24 | import org.onlab.packet.MacAddress; | 20 | import org.onlab.packet.MacAddress; |
| 25 | 21 | ||
| 22 | +import java.util.concurrent.CountDownLatch; | ||
| 23 | +import java.util.concurrent.TimeUnit; | ||
| 24 | + | ||
| 25 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
| 26 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
| 27 | + | ||
| 26 | /** | 28 | /** |
| 27 | * Installs point-to-point connectivity intents. | 29 | * Installs point-to-point connectivity intents. |
| 28 | */ | 30 | */ |
| 29 | @Command(scope = "onos", name = "push-test-intents", | 31 | @Command(scope = "onos", name = "push-test-intents", |
| 30 | description = "Installs random intents to test throughput") | 32 | description = "Installs random intents to test throughput") |
| 31 | public class IntentPushTestCommand extends AbstractShellCommand | 33 | public class IntentPushTestCommand extends AbstractShellCommand |
| 32 | - implements IntentListener { | 34 | + implements IntentListener { |
| 33 | 35 | ||
| 34 | @Argument(index = 0, name = "ingressDevice", | 36 | @Argument(index = 0, name = "ingressDevice", |
| 35 | description = "Ingress Device/Port Description", | 37 | description = "Ingress Device/Port Description", |
| ... | @@ -42,8 +44,8 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -42,8 +44,8 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 42 | String egressDeviceString = null; | 44 | String egressDeviceString = null; |
| 43 | 45 | ||
| 44 | @Argument(index = 2, name = "count", | 46 | @Argument(index = 2, name = "count", |
| 45 | - description = "Number of intents to push", | 47 | + description = "Number of intents to push", |
| 46 | - required = true, multiValued = false) | 48 | + required = true, multiValued = false) |
| 47 | String countString = null; | 49 | String countString = null; |
| 48 | 50 | ||
| 49 | 51 | ||
| ... | @@ -57,14 +59,12 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -57,14 +59,12 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 57 | protected void execute() { | 59 | protected void execute() { |
| 58 | service = get(IntentService.class); | 60 | service = get(IntentService.class); |
| 59 | 61 | ||
| 60 | - DeviceId ingressDeviceId = DeviceId.deviceId(getDeviceId(ingressDeviceString)); | 62 | + DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString)); |
| 61 | - PortNumber ingressPortNumber = | 63 | + PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString)); |
| 62 | - PortNumber.portNumber(getPortNumber(ingressDeviceString)); | ||
| 63 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); | 64 | ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber); |
| 64 | 65 | ||
| 65 | - DeviceId egressDeviceId = DeviceId.deviceId(getDeviceId(egressDeviceString)); | 66 | + DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString)); |
| 66 | - PortNumber egressPortNumber = | 67 | + PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString)); |
| 67 | - PortNumber.portNumber(getPortNumber(egressDeviceString)); | ||
| 68 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); | 68 | ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber); |
| 69 | 69 | ||
| 70 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() | 70 | TrafficSelector.Builder selector = DefaultTrafficSelector.builder() |
| ... | @@ -79,14 +79,10 @@ public class IntentPushTestCommand extends AbstractShellCommand | ... | @@ -79,14 +79,10 @@ public class IntentPushTestCommand extends AbstractShellCommand |
| 79 | start = System.currentTimeMillis(); | 79 | start = System.currentTimeMillis(); |
| 80 | for (int i = 0; i < count; i++) { | 80 | for (int i = 0; i < count; i++) { |
| 81 | TrafficSelector s = selector | 81 | TrafficSelector s = selector |
| 82 | - .matchEthSrc(MacAddress.valueOf(i)) | 82 | + .matchEthSrc(MacAddress.valueOf(i)) |
| 83 | - .build(); | 83 | + .build(); |
| 84 | - Intent intent = | 84 | + Intent intent = new PointToPointIntent(appId(), s, treatment, |
| 85 | - new PointToPointIntent(new IntentId(id++), | 85 | + ingress, egress); |
| 86 | - s, | ||
| 87 | - treatment, | ||
| 88 | - ingress, | ||
| 89 | - egress); | ||
| 90 | service.submit(intent); | 86 | service.submit(intent); |
| 91 | } | 87 | } |
| 92 | try { | 88 | try { | ... | ... |
| ... | @@ -26,9 +26,8 @@ public class IntentRemoveCommand extends AbstractShellCommand { | ... | @@ -26,9 +26,8 @@ public class IntentRemoveCommand extends AbstractShellCommand { |
| 26 | if (radix == 16) { | 26 | if (radix == 16) { |
| 27 | id = id.replaceFirst("0x", ""); | 27 | id = id.replaceFirst("0x", ""); |
| 28 | } | 28 | } |
| 29 | - IntentId intentId = new IntentId(Long.parseLong(id, radix)); | ||
| 30 | - | ||
| 31 | 29 | ||
| 30 | + IntentId intentId = IntentId.valueOf(Long.parseLong(id, radix)); | ||
| 32 | Intent intent = service.getIntent(intentId); | 31 | Intent intent = service.getIntent(intentId); |
| 33 | if (intent != null) { | 32 | if (intent != null) { |
| 34 | service.withdraw(intent); | 33 | service.withdraw(intent); | ... | ... |
| ... | @@ -15,7 +15,7 @@ public final class IntentId implements BatchOperationTarget { | ... | @@ -15,7 +15,7 @@ public final class IntentId implements BatchOperationTarget { |
| 15 | * @param fingerprint long value | 15 | * @param fingerprint long value |
| 16 | * @return intent identifier | 16 | * @return intent identifier |
| 17 | */ | 17 | */ |
| 18 | - static IntentId valueOf(long fingerprint) { | 18 | + public static IntentId valueOf(long fingerprint) { |
| 19 | return new IntentId(fingerprint); | 19 | return new IntentId(fingerprint); |
| 20 | } | 20 | } |
| 21 | 21 | ... | ... |
| ... | @@ -27,6 +27,7 @@ public class CoreManager implements CoreService { | ... | @@ -27,6 +27,7 @@ public class CoreManager implements CoreService { |
| 27 | private static Version version = Version.version("1.0.0-SNAPSHOT"); | 27 | private static Version version = Version.version("1.0.0-SNAPSHOT"); |
| 28 | 28 | ||
| 29 | private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); | 29 | private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); |
| 30 | + private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>(); | ||
| 30 | 31 | ||
| 31 | // TODO: work in progress | 32 | // TODO: work in progress |
| 32 | 33 | ||
| ... | @@ -50,9 +51,13 @@ public class CoreManager implements CoreService { | ... | @@ -50,9 +51,13 @@ public class CoreManager implements CoreService { |
| 50 | 51 | ||
| 51 | @Override | 52 | @Override |
| 52 | public ApplicationId registerApplication(String name) { | 53 | public ApplicationId registerApplication(String name) { |
| 53 | - short id = (short) ID_DISPENSER.getAndIncrement(); | 54 | + DefaultApplicationId appId = appIdsByName.get(name); |
| 54 | - DefaultApplicationId appId = new DefaultApplicationId(id, name); | 55 | + if (appId == null) { |
| 55 | - appIds.put(id, appId); | 56 | + short id = (short) ID_DISPENSER.getAndIncrement(); |
| 57 | + appId = new DefaultApplicationId(id, name); | ||
| 58 | + appIds.put(id, appId); | ||
| 59 | + appIdsByName.put(name, appId); | ||
| 60 | + } | ||
| 56 | return appId; | 61 | return appId; |
| 57 | } | 62 | } |
| 58 | 63 | ... | ... |
| ... | @@ -11,11 +11,9 @@ import org.onlab.onos.net.Path; | ... | @@ -11,11 +11,9 @@ import org.onlab.onos.net.Path; |
| 11 | import org.onlab.onos.net.flow.TrafficSelector; | 11 | import org.onlab.onos.net.flow.TrafficSelector; |
| 12 | import org.onlab.onos.net.host.HostService; | 12 | import org.onlab.onos.net.host.HostService; |
| 13 | import org.onlab.onos.net.intent.HostToHostIntent; | 13 | import org.onlab.onos.net.intent.HostToHostIntent; |
| 14 | -import org.onlab.onos.net.intent.IdGenerator; | ||
| 15 | import org.onlab.onos.net.intent.Intent; | 14 | import org.onlab.onos.net.intent.Intent; |
| 16 | import org.onlab.onos.net.intent.IntentCompiler; | 15 | import org.onlab.onos.net.intent.IntentCompiler; |
| 17 | import org.onlab.onos.net.intent.IntentExtensionService; | 16 | import org.onlab.onos.net.intent.IntentExtensionService; |
| 18 | -import org.onlab.onos.net.intent.IntentId; | ||
| 19 | import org.onlab.onos.net.intent.PathIntent; | 17 | import org.onlab.onos.net.intent.PathIntent; |
| 20 | import org.onlab.onos.net.topology.PathService; | 18 | import org.onlab.onos.net.topology.PathService; |
| 21 | 19 | ||
| ... | @@ -41,12 +39,8 @@ public class HostToHostIntentCompiler | ... | @@ -41,12 +39,8 @@ public class HostToHostIntentCompiler |
| 41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 39 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 42 | protected HostService hostService; | 40 | protected HostService hostService; |
| 43 | 41 | ||
| 44 | - protected IdGenerator<IntentId> intentIdGenerator; | ||
| 45 | - | ||
| 46 | @Activate | 42 | @Activate |
| 47 | public void activate() { | 43 | public void activate() { |
| 48 | - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator(); | ||
| 49 | - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); | ||
| 50 | intentManager.registerCompiler(HostToHostIntent.class, this); | 44 | intentManager.registerCompiler(HostToHostIntent.class, this); |
| 51 | } | 45 | } |
| 52 | 46 | ||
| ... | @@ -70,13 +64,10 @@ public class HostToHostIntentCompiler | ... | @@ -70,13 +64,10 @@ public class HostToHostIntentCompiler |
| 70 | // Creates a path intent from the specified path and original connectivity intent. | 64 | // Creates a path intent from the specified path and original connectivity intent. |
| 71 | private Intent createPathIntent(Path path, Host src, Host dst, | 65 | private Intent createPathIntent(Path path, Host src, Host dst, |
| 72 | HostToHostIntent intent) { | 66 | HostToHostIntent intent) { |
| 73 | - | ||
| 74 | TrafficSelector selector = builder(intent.selector()) | 67 | TrafficSelector selector = builder(intent.selector()) |
| 75 | .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); | 68 | .matchEthSrc(src.mac()).matchEthDst(dst.mac()).build(); |
| 76 | - | 69 | + return new PathIntent(intent.appId(), selector, intent.treatment(), |
| 77 | - return new PathIntent(intentIdGenerator.getNewId(), | 70 | + path); |
| 78 | - selector, intent.treatment(), | ||
| 79 | - path.src(), path.dst(), path); | ||
| 80 | } | 71 | } |
| 81 | 72 | ||
| 82 | private Path getPath(HostId one, HostId two) { | 73 | private Path getPath(HostId one, HostId two) { | ... | ... |
| 1 | -package org.onlab.onos.net.intent.impl; | ||
| 2 | - | ||
| 3 | -import org.onlab.onos.net.intent.IntentId; | ||
| 4 | - | ||
| 5 | -/** | ||
| 6 | - * An implementation of {@link org.onlab.onos.net.intent.IdGenerator} of intent ID, | ||
| 7 | - * which uses {@link IdBlockAllocator}. | ||
| 8 | - */ | ||
| 9 | -public class IdBlockAllocatorBasedIntentIdGenerator extends AbstractBlockAllocatorBasedIdGenerator<IntentId> { | ||
| 10 | - | ||
| 11 | - /** | ||
| 12 | - * Constructs an intent ID generator, which uses the specified ID block allocator | ||
| 13 | - * to generate a global unique intent ID. | ||
| 14 | - * | ||
| 15 | - * @param allocator the ID block allocator to use for generating intent IDs | ||
| 16 | - */ | ||
| 17 | - public IdBlockAllocatorBasedIntentIdGenerator(IdBlockAllocator allocator) { | ||
| 18 | - super(allocator); | ||
| 19 | - } | ||
| 20 | - | ||
| 21 | - @Override | ||
| 22 | - protected IntentId convertFrom(long value) { | ||
| 23 | - return new IntentId(value); | ||
| 24 | - } | ||
| 25 | -} |
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import static com.google.common.base.Preconditions.checkNotNull; | 3 | +import com.google.common.collect.ImmutableList; |
| 4 | -import static java.util.concurrent.Executors.newSingleThreadExecutor; | 4 | +import com.google.common.collect.ImmutableMap; |
| 5 | -import static org.onlab.onos.net.intent.IntentState.COMPILING; | 5 | +import com.google.common.collect.Lists; |
| 6 | -import static org.onlab.onos.net.intent.IntentState.FAILED; | ||
| 7 | -import static org.onlab.onos.net.intent.IntentState.INSTALLED; | ||
| 8 | -import static org.onlab.onos.net.intent.IntentState.INSTALLING; | ||
| 9 | -import static org.onlab.onos.net.intent.IntentState.RECOMPILING; | ||
| 10 | -import static org.onlab.onos.net.intent.IntentState.WITHDRAWING; | ||
| 11 | -import static org.onlab.onos.net.intent.IntentState.WITHDRAWN; | ||
| 12 | -import static org.onlab.util.Tools.namedThreads; | ||
| 13 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 14 | - | ||
| 15 | -import java.util.ArrayList; | ||
| 16 | -import java.util.Iterator; | ||
| 17 | -import java.util.List; | ||
| 18 | -import java.util.Map; | ||
| 19 | -import java.util.Objects; | ||
| 20 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 21 | -import java.util.concurrent.ConcurrentMap; | ||
| 22 | -import java.util.concurrent.ExecutionException; | ||
| 23 | -import java.util.concurrent.ExecutorService; | ||
| 24 | -import java.util.concurrent.Future; | ||
| 25 | -import java.util.concurrent.TimeUnit; | ||
| 26 | -import java.util.concurrent.TimeoutException; | ||
| 27 | - | ||
| 28 | import org.apache.felix.scr.annotations.Activate; | 6 | import org.apache.felix.scr.annotations.Activate; |
| 29 | import org.apache.felix.scr.annotations.Component; | 7 | import org.apache.felix.scr.annotations.Component; |
| 30 | import org.apache.felix.scr.annotations.Deactivate; | 8 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -36,7 +14,6 @@ import org.onlab.onos.event.EventDeliveryService; | ... | @@ -36,7 +14,6 @@ import org.onlab.onos.event.EventDeliveryService; |
| 36 | import org.onlab.onos.net.flow.CompletedBatchOperation; | 14 | import org.onlab.onos.net.flow.CompletedBatchOperation; |
| 37 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; | 15 | import org.onlab.onos.net.flow.FlowRuleBatchOperation; |
| 38 | import org.onlab.onos.net.flow.FlowRuleService; | 16 | import org.onlab.onos.net.flow.FlowRuleService; |
| 39 | -import org.onlab.onos.net.intent.InstallableIntent; | ||
| 40 | import org.onlab.onos.net.intent.Intent; | 17 | import org.onlab.onos.net.intent.Intent; |
| 41 | import org.onlab.onos.net.intent.IntentCompiler; | 18 | import org.onlab.onos.net.intent.IntentCompiler; |
| 42 | import org.onlab.onos.net.intent.IntentEvent; | 19 | import org.onlab.onos.net.intent.IntentEvent; |
| ... | @@ -52,9 +29,24 @@ import org.onlab.onos.net.intent.IntentStore; | ... | @@ -52,9 +29,24 @@ import org.onlab.onos.net.intent.IntentStore; |
| 52 | import org.onlab.onos.net.intent.IntentStoreDelegate; | 29 | import org.onlab.onos.net.intent.IntentStoreDelegate; |
| 53 | import org.slf4j.Logger; | 30 | import org.slf4j.Logger; |
| 54 | 31 | ||
| 55 | -import com.google.common.collect.ImmutableList; | 32 | +import java.util.ArrayList; |
| 56 | -import com.google.common.collect.ImmutableMap; | 33 | +import java.util.Iterator; |
| 57 | -import com.google.common.collect.Lists; | 34 | +import java.util.List; |
| 35 | +import java.util.Map; | ||
| 36 | +import java.util.Objects; | ||
| 37 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 38 | +import java.util.concurrent.ConcurrentMap; | ||
| 39 | +import java.util.concurrent.ExecutionException; | ||
| 40 | +import java.util.concurrent.ExecutorService; | ||
| 41 | +import java.util.concurrent.Future; | ||
| 42 | +import java.util.concurrent.TimeUnit; | ||
| 43 | +import java.util.concurrent.TimeoutException; | ||
| 44 | + | ||
| 45 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
| 46 | +import static java.util.concurrent.Executors.newSingleThreadExecutor; | ||
| 47 | +import static org.onlab.onos.net.intent.IntentState.*; | ||
| 48 | +import static org.onlab.util.Tools.namedThreads; | ||
| 49 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 58 | 50 | ||
| 59 | /** | 51 | /** |
| 60 | * An implementation of Intent Manager. | 52 | * An implementation of Intent Manager. |
| ... | @@ -71,8 +63,8 @@ public class IntentManager | ... | @@ -71,8 +63,8 @@ public class IntentManager |
| 71 | // Collections for compiler, installer, and listener are ONOS instance local | 63 | // Collections for compiler, installer, and listener are ONOS instance local |
| 72 | private final ConcurrentMap<Class<? extends Intent>, | 64 | private final ConcurrentMap<Class<? extends Intent>, |
| 73 | IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>(); | 65 | IntentCompiler<? extends Intent>> compilers = new ConcurrentHashMap<>(); |
| 74 | - private final ConcurrentMap<Class<? extends InstallableIntent>, | 66 | + private final ConcurrentMap<Class<? extends Intent>, |
| 75 | - IntentInstaller<? extends InstallableIntent>> installers = new ConcurrentHashMap<>(); | 67 | + IntentInstaller<? extends Intent>> installers = new ConcurrentHashMap<>(); |
| 76 | 68 | ||
| 77 | private final AbstractListenerRegistry<IntentEvent, IntentListener> | 69 | private final AbstractListenerRegistry<IntentEvent, IntentListener> |
| 78 | listenerRegistry = new AbstractListenerRegistry<>(); | 70 | listenerRegistry = new AbstractListenerRegistry<>(); |
| ... | @@ -186,17 +178,17 @@ public class IntentManager | ... | @@ -186,17 +178,17 @@ public class IntentManager |
| 186 | } | 178 | } |
| 187 | 179 | ||
| 188 | @Override | 180 | @Override |
| 189 | - public <T extends InstallableIntent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) { | 181 | + public <T extends Intent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) { |
| 190 | installers.put(cls, installer); | 182 | installers.put(cls, installer); |
| 191 | } | 183 | } |
| 192 | 184 | ||
| 193 | @Override | 185 | @Override |
| 194 | - public <T extends InstallableIntent> void unregisterInstaller(Class<T> cls) { | 186 | + public <T extends Intent> void unregisterInstaller(Class<T> cls) { |
| 195 | installers.remove(cls); | 187 | installers.remove(cls); |
| 196 | } | 188 | } |
| 197 | 189 | ||
| 198 | @Override | 190 | @Override |
| 199 | - public Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> getInstallers() { | 191 | + public Map<Class<? extends Intent>, IntentInstaller<? extends Intent>> getInstallers() { |
| 200 | return ImmutableMap.copyOf(installers); | 192 | return ImmutableMap.copyOf(installers); |
| 201 | } | 193 | } |
| 202 | 194 | ||
| ... | @@ -223,7 +215,7 @@ public class IntentManager | ... | @@ -223,7 +215,7 @@ public class IntentManager |
| 223 | * @param <T> the type of installable intent | 215 | * @param <T> the type of installable intent |
| 224 | * @return intent installer corresponding to the specified installable intent | 216 | * @return intent installer corresponding to the specified installable intent |
| 225 | */ | 217 | */ |
| 226 | - private <T extends InstallableIntent> IntentInstaller<T> getInstaller(T intent) { | 218 | + private <T extends Intent> IntentInstaller<T> getInstaller(T intent) { |
| 227 | @SuppressWarnings("unchecked") | 219 | @SuppressWarnings("unchecked") |
| 228 | IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass()); | 220 | IntentInstaller<T> installer = (IntentInstaller<T>) installers.get(intent.getClass()); |
| 229 | if (installer == null) { | 221 | if (installer == null) { |
| ... | @@ -243,7 +235,7 @@ public class IntentManager | ... | @@ -243,7 +235,7 @@ public class IntentManager |
| 243 | 235 | ||
| 244 | try { | 236 | try { |
| 245 | // Compile the intent into installable derivatives. | 237 | // Compile the intent into installable derivatives. |
| 246 | - List<InstallableIntent> installable = compileIntent(intent); | 238 | + List<Intent> installable = compileIntent(intent); |
| 247 | 239 | ||
| 248 | // If all went well, associate the resulting list of installable | 240 | // If all went well, associate the resulting list of installable |
| 249 | // intents with the top-level intent and proceed to install. | 241 | // intents with the top-level intent and proceed to install. |
| ... | @@ -264,12 +256,12 @@ public class IntentManager | ... | @@ -264,12 +256,12 @@ public class IntentManager |
| 264 | * @param intent intent | 256 | * @param intent intent |
| 265 | * @return result of compilation | 257 | * @return result of compilation |
| 266 | */ | 258 | */ |
| 267 | - private List<InstallableIntent> compileIntent(Intent intent) { | 259 | + private List<Intent> compileIntent(Intent intent) { |
| 268 | - if (intent instanceof InstallableIntent) { | 260 | + if (intent instanceof Intent) { |
| 269 | - return ImmutableList.of((InstallableIntent) intent); | 261 | + return ImmutableList.of((Intent) intent); |
| 270 | } | 262 | } |
| 271 | 263 | ||
| 272 | - List<InstallableIntent> installable = new ArrayList<>(); | 264 | + List<Intent> installable = new ArrayList<>(); |
| 273 | // TODO do we need to registerSubclassCompiler? | 265 | // TODO do we need to registerSubclassCompiler? |
| 274 | for (Intent compiled : getCompiler(intent).compile(intent)) { | 266 | for (Intent compiled : getCompiler(intent).compile(intent)) { |
| 275 | installable.addAll(compileIntent(compiled)); | 267 | installable.addAll(compileIntent(compiled)); |
| ... | @@ -290,12 +282,12 @@ public class IntentManager | ... | @@ -290,12 +282,12 @@ public class IntentManager |
| 290 | 282 | ||
| 291 | List<FlowRuleBatchOperation> installWork = Lists.newArrayList(); | 283 | List<FlowRuleBatchOperation> installWork = Lists.newArrayList(); |
| 292 | try { | 284 | try { |
| 293 | - List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); | 285 | + List<Intent> installables = store.getInstallableIntents(intent.id()); |
| 294 | if (installables != null) { | 286 | if (installables != null) { |
| 295 | - for (InstallableIntent installable : installables) { | 287 | + for (Intent installable : installables) { |
| 296 | registerSubclassInstallerIfNeeded(installable); | 288 | registerSubclassInstallerIfNeeded(installable); |
| 297 | trackerService.addTrackedResources(intent.id(), | 289 | trackerService.addTrackedResources(intent.id(), |
| 298 | - installable.requiredLinks()); | 290 | + installable.resources()); |
| 299 | List<FlowRuleBatchOperation> batch = getInstaller(installable).install(installable); | 291 | List<FlowRuleBatchOperation> batch = getInstaller(installable).install(installable); |
| 300 | installWork.addAll(batch); | 292 | installWork.addAll(batch); |
| 301 | } | 293 | } |
| ... | @@ -324,14 +316,13 @@ public class IntentManager | ... | @@ -324,14 +316,13 @@ public class IntentManager |
| 324 | 316 | ||
| 325 | try { | 317 | try { |
| 326 | // Compile the intent into installable derivatives. | 318 | // Compile the intent into installable derivatives. |
| 327 | - List<InstallableIntent> installable = compileIntent(intent); | 319 | + List<Intent> installable = compileIntent(intent); |
| 328 | 320 | ||
| 329 | // If all went well, compare the existing list of installable | 321 | // If all went well, compare the existing list of installable |
| 330 | // intents with the newly compiled list. If they are the same, | 322 | // intents with the newly compiled list. If they are the same, |
| 331 | // bail, out since the previous approach was determined not to | 323 | // bail, out since the previous approach was determined not to |
| 332 | // be viable. | 324 | // be viable. |
| 333 | - List<InstallableIntent> originalInstallable = | 325 | + List<Intent> originalInstallable = store.getInstallableIntents(intent.id()); |
| 334 | - store.getInstallableIntents(intent.id()); | ||
| 335 | 326 | ||
| 336 | if (Objects.equals(originalInstallable, installable)) { | 327 | if (Objects.equals(originalInstallable, installable)) { |
| 337 | eventDispatcher.post(store.setState(intent, FAILED)); | 328 | eventDispatcher.post(store.setState(intent, FAILED)); |
| ... | @@ -376,9 +367,9 @@ public class IntentManager | ... | @@ -376,9 +367,9 @@ public class IntentManager |
| 376 | private void uninstallIntent(Intent intent, IntentState nextState) { | 367 | private void uninstallIntent(Intent intent, IntentState nextState) { |
| 377 | List<FlowRuleBatchOperation> uninstallWork = Lists.newArrayList(); | 368 | List<FlowRuleBatchOperation> uninstallWork = Lists.newArrayList(); |
| 378 | try { | 369 | try { |
| 379 | - List<InstallableIntent> installables = store.getInstallableIntents(intent.id()); | 370 | + List<Intent> installables = store.getInstallableIntents(intent.id()); |
| 380 | if (installables != null) { | 371 | if (installables != null) { |
| 381 | - for (InstallableIntent installable : installables) { | 372 | + for (Intent installable : installables) { |
| 382 | List<FlowRuleBatchOperation> batches = getInstaller(installable).uninstall(installable); | 373 | List<FlowRuleBatchOperation> batches = getInstaller(installable).uninstall(installable); |
| 383 | uninstallWork.addAll(batches); | 374 | uninstallWork.addAll(batches); |
| 384 | } | 375 | } |
| ... | @@ -422,12 +413,12 @@ public class IntentManager | ... | @@ -422,12 +413,12 @@ public class IntentManager |
| 422 | * | 413 | * |
| 423 | * @param intent intent | 414 | * @param intent intent |
| 424 | */ | 415 | */ |
| 425 | - private void registerSubclassInstallerIfNeeded(InstallableIntent intent) { | 416 | + private void registerSubclassInstallerIfNeeded(Intent intent) { |
| 426 | if (!installers.containsKey(intent.getClass())) { | 417 | if (!installers.containsKey(intent.getClass())) { |
| 427 | Class<?> cls = intent.getClass(); | 418 | Class<?> cls = intent.getClass(); |
| 428 | while (cls != Object.class) { | 419 | while (cls != Object.class) { |
| 429 | - // As long as we're within the InstallableIntent class descendants | 420 | + // As long as we're within the Intent class descendants |
| 430 | - if (InstallableIntent.class.isAssignableFrom(cls)) { | 421 | + if (Intent.class.isAssignableFrom(cls)) { |
| 431 | IntentInstaller<?> installer = installers.get(cls); | 422 | IntentInstaller<?> installer = installers.get(cls); |
| 432 | if (installer != null) { | 423 | if (installer != null) { |
| 433 | installers.put(intent.getClass(), installer); | 424 | installers.put(intent.getClass(), installer); |
| ... | @@ -505,8 +496,8 @@ public class IntentManager | ... | @@ -505,8 +496,8 @@ public class IntentManager |
| 505 | private final IntentState nextState; | 496 | private final IntentState nextState; |
| 506 | 497 | ||
| 507 | public IntentInstallMonitor(Intent intent, | 498 | public IntentInstallMonitor(Intent intent, |
| 508 | - List<FlowRuleBatchOperation> work, | 499 | + List<FlowRuleBatchOperation> work, |
| 509 | - IntentState nextState) { | 500 | + IntentState nextState) { |
| 510 | this.intent = intent; | 501 | this.intent = intent; |
| 511 | this.work = work; | 502 | this.work = work; |
| 512 | // TODO how many Futures can be outstanding? one? | 503 | // TODO how many Futures can be outstanding? one? |
| ... | @@ -531,9 +522,7 @@ public class IntentManager | ... | @@ -531,9 +522,7 @@ public class IntentManager |
| 531 | } | 522 | } |
| 532 | 523 | ||
| 533 | /** | 524 | /** |
| 534 | - * Apply a list of FlowRules. | 525 | + * Applies the next batch. |
| 535 | - * | ||
| 536 | - * @param rules rules to apply | ||
| 537 | */ | 526 | */ |
| 538 | private Future<CompletedBatchOperation> applyNextBatch() { | 527 | private Future<CompletedBatchOperation> applyNextBatch() { |
| 539 | if (work.isEmpty()) { | 528 | if (work.isEmpty()) { | ... | ... |
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import java.util.Arrays; | ||
| 4 | -import java.util.HashSet; | ||
| 5 | -import java.util.List; | ||
| 6 | -import java.util.Set; | ||
| 7 | - | ||
| 8 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
| 9 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
| 10 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -13,16 +8,19 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -13,16 +8,19 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 13 | import org.onlab.onos.net.ConnectPoint; | 8 | import org.onlab.onos.net.ConnectPoint; |
| 14 | import org.onlab.onos.net.Link; | 9 | import org.onlab.onos.net.Link; |
| 15 | import org.onlab.onos.net.Path; | 10 | import org.onlab.onos.net.Path; |
| 16 | -import org.onlab.onos.net.intent.IdGenerator; | ||
| 17 | import org.onlab.onos.net.intent.Intent; | 11 | import org.onlab.onos.net.intent.Intent; |
| 18 | import org.onlab.onos.net.intent.IntentCompiler; | 12 | import org.onlab.onos.net.intent.IntentCompiler; |
| 19 | import org.onlab.onos.net.intent.IntentExtensionService; | 13 | import org.onlab.onos.net.intent.IntentExtensionService; |
| 20 | -import org.onlab.onos.net.intent.IntentId; | ||
| 21 | import org.onlab.onos.net.intent.LinkCollectionIntent; | 14 | import org.onlab.onos.net.intent.LinkCollectionIntent; |
| 22 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; | 15 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
| 23 | import org.onlab.onos.net.intent.PointToPointIntent; | 16 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 24 | import org.onlab.onos.net.topology.PathService; | 17 | import org.onlab.onos.net.topology.PathService; |
| 25 | 18 | ||
| 19 | +import java.util.Arrays; | ||
| 20 | +import java.util.HashSet; | ||
| 21 | +import java.util.List; | ||
| 22 | +import java.util.Set; | ||
| 23 | + | ||
| 26 | /** | 24 | /** |
| 27 | * An intent compiler for | 25 | * An intent compiler for |
| 28 | * {@link org.onlab.onos.net.intent.MultiPointToSinglePointIntent}. | 26 | * {@link org.onlab.onos.net.intent.MultiPointToSinglePointIntent}. |
| ... | @@ -37,12 +35,8 @@ public class MultiPointToSinglePointIntentCompiler | ... | @@ -37,12 +35,8 @@ public class MultiPointToSinglePointIntentCompiler |
| 37 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 35 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 38 | protected PathService pathService; | 36 | protected PathService pathService; |
| 39 | 37 | ||
| 40 | - protected IdGenerator<IntentId> intentIdGenerator; | ||
| 41 | - | ||
| 42 | @Activate | 38 | @Activate |
| 43 | public void activate() { | 39 | public void activate() { |
| 44 | - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator(); | ||
| 45 | - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); | ||
| 46 | intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this); | 40 | intentManager.registerCompiler(MultiPointToSinglePointIntent.class, this); |
| 47 | } | 41 | } |
| 48 | 42 | ||
| ... | @@ -60,9 +54,9 @@ public class MultiPointToSinglePointIntentCompiler | ... | @@ -60,9 +54,9 @@ public class MultiPointToSinglePointIntentCompiler |
| 60 | links.addAll(path.links()); | 54 | links.addAll(path.links()); |
| 61 | } | 55 | } |
| 62 | 56 | ||
| 63 | - Intent result = new LinkCollectionIntent(intentIdGenerator.getNewId(), | 57 | + Intent result = new LinkCollectionIntent(intent.appId(), |
| 64 | - intent.selector(), intent.treatment(), | 58 | + intent.selector(), intent.treatment(), |
| 65 | - links, intent.egressPoint()); | 59 | + links, intent.egressPoint()); |
| 66 | return Arrays.asList(result); | 60 | return Arrays.asList(result); |
| 67 | } | 61 | } |
| 68 | 62 | ... | ... |
| ... | @@ -11,6 +11,7 @@ import org.apache.felix.scr.annotations.Service; | ... | @@ -11,6 +11,7 @@ import org.apache.felix.scr.annotations.Service; |
| 11 | import org.onlab.onos.event.Event; | 11 | import org.onlab.onos.event.Event; |
| 12 | import org.onlab.onos.net.Link; | 12 | import org.onlab.onos.net.Link; |
| 13 | import org.onlab.onos.net.LinkKey; | 13 | import org.onlab.onos.net.LinkKey; |
| 14 | +import org.onlab.onos.net.NetworkResource; | ||
| 14 | import org.onlab.onos.net.intent.IntentId; | 15 | import org.onlab.onos.net.intent.IntentId; |
| 15 | import org.onlab.onos.net.link.LinkEvent; | 16 | import org.onlab.onos.net.link.LinkEvent; |
| 16 | import org.onlab.onos.net.topology.TopologyEvent; | 17 | import org.onlab.onos.net.topology.TopologyEvent; |
| ... | @@ -27,8 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument; | ... | @@ -27,8 +28,8 @@ import static com.google.common.base.Preconditions.checkArgument; |
| 27 | import static com.google.common.base.Preconditions.checkNotNull; | 28 | import static com.google.common.base.Preconditions.checkNotNull; |
| 28 | import static com.google.common.collect.Multimaps.synchronizedSetMultimap; | 29 | import static com.google.common.collect.Multimaps.synchronizedSetMultimap; |
| 29 | import static java.util.concurrent.Executors.newSingleThreadExecutor; | 30 | import static java.util.concurrent.Executors.newSingleThreadExecutor; |
| 30 | -import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED; | ||
| 31 | import static org.onlab.onos.net.LinkKey.linkKey; | 31 | import static org.onlab.onos.net.LinkKey.linkKey; |
| 32 | +import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED; | ||
| 32 | import static org.onlab.util.Tools.namedThreads; | 33 | import static org.onlab.util.Tools.namedThreads; |
| 33 | import static org.slf4j.LoggerFactory.getLogger; | 34 | import static org.slf4j.LoggerFactory.getLogger; |
| 34 | 35 | ||
| ... | @@ -81,16 +82,22 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -81,16 +82,22 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
| 81 | } | 82 | } |
| 82 | 83 | ||
| 83 | @Override | 84 | @Override |
| 84 | - public void addTrackedResources(IntentId intentId, Collection<Link> resources) { | 85 | + public void addTrackedResources(IntentId intentId, |
| 85 | - for (Link link : resources) { | 86 | + Collection<NetworkResource> resources) { |
| 86 | - intentsByLink.put(linkKey(link), intentId); | 87 | + for (NetworkResource resource : resources) { |
| 88 | + if (resource instanceof Link) { | ||
| 89 | + intentsByLink.put(linkKey((Link) resource), intentId); | ||
| 90 | + } | ||
| 87 | } | 91 | } |
| 88 | } | 92 | } |
| 89 | 93 | ||
| 90 | @Override | 94 | @Override |
| 91 | - public void removeTrackedResources(IntentId intentId, Collection<Link> resources) { | 95 | + public void removeTrackedResources(IntentId intentId, |
| 92 | - for (Link link : resources) { | 96 | + Collection<NetworkResource> resources) { |
| 93 | - intentsByLink.remove(linkKey(link), intentId); | 97 | + for (NetworkResource resource : resources) { |
| 98 | + if (resource instanceof Link) { | ||
| 99 | + intentsByLink.remove(linkKey((Link) resource), intentId); | ||
| 100 | + } | ||
| 94 | } | 101 | } |
| 95 | } | 102 | } |
| 96 | 103 | ... | ... |
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import org.onlab.onos.net.Link; | 3 | +import org.onlab.onos.net.NetworkResource; |
| 4 | import org.onlab.onos.net.intent.IntentId; | 4 | import org.onlab.onos.net.intent.IntentId; |
| 5 | 5 | ||
| 6 | import java.util.Collection; | 6 | import java.util.Collection; |
| ... | @@ -28,17 +28,19 @@ public interface ObjectiveTrackerService { | ... | @@ -28,17 +28,19 @@ public interface ObjectiveTrackerService { |
| 28 | /** | 28 | /** |
| 29 | * Adds a path flow to be tracked. | 29 | * Adds a path flow to be tracked. |
| 30 | * | 30 | * |
| 31 | - * @param intentId intent identity on whose behalf the path is being tracked | 31 | + * @param intentId intent identity on whose behalf the path is being tracked |
| 32 | * @param resources resources to track | 32 | * @param resources resources to track |
| 33 | */ | 33 | */ |
| 34 | - public void addTrackedResources(IntentId intentId, Collection<Link> resources); | 34 | + public void addTrackedResources(IntentId intentId, |
| 35 | + Collection<NetworkResource> resources); | ||
| 35 | 36 | ||
| 36 | /** | 37 | /** |
| 37 | * Removes a path flow to be tracked. | 38 | * Removes a path flow to be tracked. |
| 38 | * | 39 | * |
| 39 | - * @param intentId intent identity on whose behalf the path is being tracked | 40 | + * @param intentId intent identity on whose behalf the path is being tracked |
| 40 | * @param resources resources to stop tracking | 41 | * @param resources resources to stop tracking |
| 41 | */ | 42 | */ |
| 42 | - public void removeTrackedResources(IntentId intentId, Collection<Link> resources); | 43 | + public void removeTrackedResources(IntentId intentId, |
| 44 | + Collection<NetworkResource> resources); | ||
| 43 | 45 | ||
| 44 | } | 46 | } | ... | ... |
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import java.util.ArrayList; | ||
| 4 | -import java.util.Arrays; | ||
| 5 | -import java.util.List; | ||
| 6 | -import java.util.Set; | ||
| 7 | - | ||
| 8 | import org.apache.felix.scr.annotations.Activate; | 3 | import org.apache.felix.scr.annotations.Activate; |
| 9 | import org.apache.felix.scr.annotations.Component; | 4 | import org.apache.felix.scr.annotations.Component; |
| 10 | import org.apache.felix.scr.annotations.Deactivate; | 5 | import org.apache.felix.scr.annotations.Deactivate; |
| ... | @@ -16,16 +11,19 @@ import org.onlab.onos.net.DefaultPath; | ... | @@ -16,16 +11,19 @@ import org.onlab.onos.net.DefaultPath; |
| 16 | import org.onlab.onos.net.Link; | 11 | import org.onlab.onos.net.Link; |
| 17 | import org.onlab.onos.net.Path; | 12 | import org.onlab.onos.net.Path; |
| 18 | import org.onlab.onos.net.host.HostService; | 13 | import org.onlab.onos.net.host.HostService; |
| 19 | -import org.onlab.onos.net.intent.IdGenerator; | ||
| 20 | import org.onlab.onos.net.intent.Intent; | 14 | import org.onlab.onos.net.intent.Intent; |
| 21 | import org.onlab.onos.net.intent.IntentCompiler; | 15 | import org.onlab.onos.net.intent.IntentCompiler; |
| 22 | import org.onlab.onos.net.intent.IntentExtensionService; | 16 | import org.onlab.onos.net.intent.IntentExtensionService; |
| 23 | -import org.onlab.onos.net.intent.IntentId; | ||
| 24 | import org.onlab.onos.net.intent.PathIntent; | 17 | import org.onlab.onos.net.intent.PathIntent; |
| 25 | import org.onlab.onos.net.intent.PointToPointIntent; | 18 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 26 | import org.onlab.onos.net.provider.ProviderId; | 19 | import org.onlab.onos.net.provider.ProviderId; |
| 27 | import org.onlab.onos.net.topology.PathService; | 20 | import org.onlab.onos.net.topology.PathService; |
| 28 | 21 | ||
| 22 | +import java.util.ArrayList; | ||
| 23 | +import java.util.Arrays; | ||
| 24 | +import java.util.List; | ||
| 25 | +import java.util.Set; | ||
| 26 | + | ||
| 29 | /** | 27 | /** |
| 30 | * A intent compiler for {@link org.onlab.onos.net.intent.HostToHostIntent}. | 28 | * A intent compiler for {@link org.onlab.onos.net.intent.HostToHostIntent}. |
| 31 | */ | 29 | */ |
| ... | @@ -43,12 +41,8 @@ public class PointToPointIntentCompiler | ... | @@ -43,12 +41,8 @@ public class PointToPointIntentCompiler |
| 43 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 44 | protected HostService hostService; | 42 | protected HostService hostService; |
| 45 | 43 | ||
| 46 | - protected IdGenerator<IntentId> intentIdGenerator; | ||
| 47 | - | ||
| 48 | @Activate | 44 | @Activate |
| 49 | public void activate() { | 45 | public void activate() { |
| 50 | - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator(); | ||
| 51 | - intentIdGenerator = new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); | ||
| 52 | intentManager.registerCompiler(PointToPointIntent.class, this); | 46 | intentManager.registerCompiler(PointToPointIntent.class, this); |
| 53 | } | 47 | } |
| 54 | 48 | ||
| ... | @@ -67,23 +61,21 @@ public class PointToPointIntentCompiler | ... | @@ -67,23 +61,21 @@ public class PointToPointIntentCompiler |
| 67 | links.add(DefaultEdgeLink.createEdgeLink(intent.egressPoint(), false)); | 61 | links.add(DefaultEdgeLink.createEdgeLink(intent.egressPoint(), false)); |
| 68 | 62 | ||
| 69 | return Arrays.asList(createPathIntent(new DefaultPath(PID, links, path.cost() + 2, | 63 | return Arrays.asList(createPathIntent(new DefaultPath(PID, links, path.cost() + 2, |
| 70 | - path.annotations()), | 64 | + path.annotations()), |
| 71 | - intent)); | 65 | + intent)); |
| 72 | } | 66 | } |
| 73 | 67 | ||
| 74 | /** | 68 | /** |
| 75 | * Creates a path intent from the specified path and original | 69 | * Creates a path intent from the specified path and original |
| 76 | * connectivity intent. | 70 | * connectivity intent. |
| 77 | * | 71 | * |
| 78 | - * @param path path to create an intent for | 72 | + * @param path path to create an intent for |
| 79 | * @param intent original intent | 73 | * @param intent original intent |
| 80 | */ | 74 | */ |
| 81 | private Intent createPathIntent(Path path, | 75 | private Intent createPathIntent(Path path, |
| 82 | PointToPointIntent intent) { | 76 | PointToPointIntent intent) { |
| 83 | - | 77 | + return new PathIntent(intent.appId(), |
| 84 | - return new PathIntent(intentIdGenerator.getNewId(), | 78 | + intent.selector(), intent.treatment(), path); |
| 85 | - intent.selector(), intent.treatment(), | ||
| 86 | - path.src(), path.dst(), path); | ||
| 87 | } | 79 | } |
| 88 | 80 | ||
| 89 | /** | 81 | /** | ... | ... |
| 1 | package org.onlab.onos.net.intent; | 1 | package org.onlab.onos.net.intent; |
| 2 | 2 | ||
| 3 | import org.junit.Test; | 3 | import org.junit.Test; |
| 4 | +import org.onlab.onos.ApplicationId; | ||
| 5 | +import org.onlab.onos.TestApplicationId; | ||
| 4 | import org.onlab.onos.net.HostId; | 6 | import org.onlab.onos.net.HostId; |
| 5 | import org.onlab.onos.net.flow.TrafficSelector; | 7 | import org.onlab.onos.net.flow.TrafficSelector; |
| 6 | import org.onlab.onos.net.flow.TrafficTreatment; | 8 | import org.onlab.onos.net.flow.TrafficTreatment; |
| ... | @@ -16,15 +18,13 @@ import static org.onlab.onos.net.NetTestTools.hid; | ... | @@ -16,15 +18,13 @@ import static org.onlab.onos.net.NetTestTools.hid; |
| 16 | */ | 18 | */ |
| 17 | public class TestHostToHostIntent { | 19 | public class TestHostToHostIntent { |
| 18 | 20 | ||
| 21 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 22 | + | ||
| 19 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 23 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 20 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 24 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 21 | 25 | ||
| 22 | - private HostToHostIntent makeHostToHost(long id, HostId one, HostId two) { | 26 | + private HostToHostIntent makeHostToHost(HostId one, HostId two) { |
| 23 | - return new HostToHostIntent(new IntentId(id), | 27 | + return new HostToHostIntent(APPID, one, two, selector, treatment); |
| 24 | - one, | ||
| 25 | - two, | ||
| 26 | - selector, | ||
| 27 | - treatment); | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | /** | 30 | /** |
| ... | @@ -36,8 +36,8 @@ public class TestHostToHostIntent { | ... | @@ -36,8 +36,8 @@ public class TestHostToHostIntent { |
| 36 | 36 | ||
| 37 | HostId one = hid("00:00:00:00:00:01/-1"); | 37 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 38 | HostId two = hid("00:00:00:00:00:02/-1"); | 38 | HostId two = hid("00:00:00:00:00:02/-1"); |
| 39 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 39 | + HostToHostIntent i1 = makeHostToHost(one, two); |
| 40 | - HostToHostIntent i2 = makeHostToHost(12, one, two); | 40 | + HostToHostIntent i2 = makeHostToHost(one, two); |
| 41 | 41 | ||
| 42 | assertThat(i1, is(equalTo(i2))); | 42 | assertThat(i1, is(equalTo(i2))); |
| 43 | } | 43 | } |
| ... | @@ -51,23 +51,8 @@ public class TestHostToHostIntent { | ... | @@ -51,23 +51,8 @@ public class TestHostToHostIntent { |
| 51 | 51 | ||
| 52 | HostId one = hid("00:00:00:00:00:01/-1"); | 52 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 53 | HostId two = hid("00:00:00:00:00:02/-1"); | 53 | HostId two = hid("00:00:00:00:00:02/-1"); |
| 54 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 54 | + HostToHostIntent i1 = makeHostToHost(one, two); |
| 55 | - HostToHostIntent i2 = makeHostToHost(12, two, one); | 55 | + HostToHostIntent i2 = makeHostToHost(two, one); |
| 56 | - | ||
| 57 | - assertThat(i1, is(not(equalTo(i2)))); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - /** | ||
| 61 | - * Tests the equals() method where two HostToHostIntents have different | ||
| 62 | - * ids. These should compare not equal. | ||
| 63 | - */ | ||
| 64 | - | ||
| 65 | - @Test | ||
| 66 | - public void testBaseDifferentEquals() { | ||
| 67 | - HostId one = hid("00:00:00:00:00:01/-1"); | ||
| 68 | - HostId two = hid("00:00:00:00:00:02/-1"); | ||
| 69 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | ||
| 70 | - HostToHostIntent i2 = makeHostToHost(11, one, two); | ||
| 71 | 56 | ||
| 72 | assertThat(i1, is(not(equalTo(i2)))); | 57 | assertThat(i1, is(not(equalTo(i2)))); |
| 73 | } | 58 | } |
| ... | @@ -76,13 +61,12 @@ public class TestHostToHostIntent { | ... | @@ -76,13 +61,12 @@ public class TestHostToHostIntent { |
| 76 | * Tests that the hashCode() values for two equivalent HostToHostIntent | 61 | * Tests that the hashCode() values for two equivalent HostToHostIntent |
| 77 | * objects are the same. | 62 | * objects are the same. |
| 78 | */ | 63 | */ |
| 79 | - | ||
| 80 | @Test | 64 | @Test |
| 81 | public void testHashCodeEquals() { | 65 | public void testHashCodeEquals() { |
| 82 | HostId one = hid("00:00:00:00:00:01/-1"); | 66 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 83 | HostId two = hid("00:00:00:00:00:02/-1"); | 67 | HostId two = hid("00:00:00:00:00:02/-1"); |
| 84 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 68 | + HostToHostIntent i1 = makeHostToHost(one, two); |
| 85 | - HostToHostIntent i2 = makeHostToHost(12, one, two); | 69 | + HostToHostIntent i2 = makeHostToHost(one, two); |
| 86 | 70 | ||
| 87 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); | 71 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
| 88 | } | 72 | } |
| ... | @@ -91,13 +75,12 @@ public class TestHostToHostIntent { | ... | @@ -91,13 +75,12 @@ public class TestHostToHostIntent { |
| 91 | * Tests that the hashCode() values for two distinct LinkCollectionIntent | 75 | * Tests that the hashCode() values for two distinct LinkCollectionIntent |
| 92 | * objects are different. | 76 | * objects are different. |
| 93 | */ | 77 | */ |
| 94 | - | ||
| 95 | @Test | 78 | @Test |
| 96 | public void testHashCodeDifferent() { | 79 | public void testHashCodeDifferent() { |
| 97 | HostId one = hid("00:00:00:00:00:01/-1"); | 80 | HostId one = hid("00:00:00:00:00:01/-1"); |
| 98 | HostId two = hid("00:00:00:00:00:02/-1"); | 81 | HostId two = hid("00:00:00:00:00:02/-1"); |
| 99 | - HostToHostIntent i1 = makeHostToHost(12, one, two); | 82 | + HostToHostIntent i1 = makeHostToHost(one, two); |
| 100 | - HostToHostIntent i2 = makeHostToHost(112, one, two); | 83 | + HostToHostIntent i2 = makeHostToHost(two, one); |
| 101 | 84 | ||
| 102 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); | 85 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); |
| 103 | } | 86 | } | ... | ... |
| ... | @@ -11,6 +11,8 @@ import java.util.Set; | ... | @@ -11,6 +11,8 @@ import java.util.Set; |
| 11 | 11 | ||
| 12 | import org.junit.Before; | 12 | import org.junit.Before; |
| 13 | import org.junit.Test; | 13 | import org.junit.Test; |
| 14 | +import org.onlab.onos.ApplicationId; | ||
| 15 | +import org.onlab.onos.TestApplicationId; | ||
| 14 | import org.onlab.onos.net.ConnectPoint; | 16 | import org.onlab.onos.net.ConnectPoint; |
| 15 | import org.onlab.onos.net.DeviceId; | 17 | import org.onlab.onos.net.DeviceId; |
| 16 | import org.onlab.onos.net.Link; | 18 | import org.onlab.onos.net.Link; |
| ... | @@ -23,6 +25,8 @@ import org.onlab.onos.net.flow.TrafficTreatment; | ... | @@ -23,6 +25,8 @@ import org.onlab.onos.net.flow.TrafficTreatment; |
| 23 | */ | 25 | */ |
| 24 | public class TestLinkCollectionIntent { | 26 | public class TestLinkCollectionIntent { |
| 25 | 27 | ||
| 28 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 29 | + | ||
| 26 | private Link link1 = link("dev1", 1, "dev2", 2); | 30 | private Link link1 = link("dev1", 1, "dev2", 2); |
| 27 | private Link link2 = link("dev1", 1, "dev3", 2); | 31 | private Link link2 = link("dev1", 1, "dev3", 2); |
| 28 | private Link link3 = link("dev2", 1, "dev3", 2); | 32 | private Link link3 = link("dev2", 1, "dev3", 2); |
| ... | @@ -38,10 +42,9 @@ public class TestLinkCollectionIntent { | ... | @@ -38,10 +42,9 @@ public class TestLinkCollectionIntent { |
| 38 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 42 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 39 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 43 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 40 | 44 | ||
| 41 | - private LinkCollectionIntent makeLinkCollection(long id, Set<Link> links, | 45 | + private LinkCollectionIntent makeLinkCollection(Set<Link> links, |
| 42 | ConnectPoint egress) { | 46 | ConnectPoint egress) { |
| 43 | - return new LinkCollectionIntent(new IntentId(id), | 47 | + return new LinkCollectionIntent(APPID, selector, treatment, links, egress); |
| 44 | - selector, treatment, links, egress); | ||
| 45 | } | 48 | } |
| 46 | 49 | ||
| 47 | @Before | 50 | @Before |
| ... | @@ -64,8 +67,8 @@ public class TestLinkCollectionIntent { | ... | @@ -64,8 +67,8 @@ public class TestLinkCollectionIntent { |
| 64 | links2.add(link2); | 67 | links2.add(link2); |
| 65 | links2.add(link1); | 68 | links2.add(link1); |
| 66 | 69 | ||
| 67 | - LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1); | 70 | + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1); |
| 68 | - LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress1); | 71 | + LinkCollectionIntent i2 = makeLinkCollection(links2, egress1); |
| 69 | 72 | ||
| 70 | assertThat(i1, is(equalTo(i2))); | 73 | assertThat(i1, is(equalTo(i2))); |
| 71 | } | 74 | } |
| ... | @@ -82,8 +85,8 @@ public class TestLinkCollectionIntent { | ... | @@ -82,8 +85,8 @@ public class TestLinkCollectionIntent { |
| 82 | links2.add(link3); | 85 | links2.add(link3); |
| 83 | links2.add(link1); | 86 | links2.add(link1); |
| 84 | 87 | ||
| 85 | - LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1); | 88 | + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1); |
| 86 | - LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress1); | 89 | + LinkCollectionIntent i2 = makeLinkCollection(links2, egress1); |
| 87 | 90 | ||
| 88 | assertThat(i1, is(not(equalTo(i2)))); | 91 | assertThat(i1, is(not(equalTo(i2)))); |
| 89 | } | 92 | } |
| ... | @@ -102,26 +105,8 @@ public class TestLinkCollectionIntent { | ... | @@ -102,26 +105,8 @@ public class TestLinkCollectionIntent { |
| 102 | links2.add(link2); | 105 | links2.add(link2); |
| 103 | links2.add(link1); | 106 | links2.add(link1); |
| 104 | 107 | ||
| 105 | - LinkCollectionIntent i1 = makeLinkCollection(12, links1, egress1); | 108 | + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1); |
| 106 | - LinkCollectionIntent i2 = makeLinkCollection(12, links2, egress2); | 109 | + LinkCollectionIntent i2 = makeLinkCollection(links2, egress2); |
| 107 | - | ||
| 108 | - assertThat(i1, is(not(equalTo(i2)))); | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - /** | ||
| 112 | - * Tests the equals() method where two LinkCollectionIntents have different | ||
| 113 | - * ids. These should compare not equal. | ||
| 114 | - */ | ||
| 115 | - @Test | ||
| 116 | - public void testBaseDifferentEquals() { | ||
| 117 | - links1.add(link1); | ||
| 118 | - links1.add(link2); | ||
| 119 | - | ||
| 120 | - links2.add(link2); | ||
| 121 | - links2.add(link1); | ||
| 122 | - | ||
| 123 | - LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1); | ||
| 124 | - LinkCollectionIntent i2 = makeLinkCollection(2, links2, egress1); | ||
| 125 | 110 | ||
| 126 | assertThat(i1, is(not(equalTo(i2)))); | 111 | assertThat(i1, is(not(equalTo(i2)))); |
| 127 | } | 112 | } |
| ... | @@ -140,8 +125,8 @@ public class TestLinkCollectionIntent { | ... | @@ -140,8 +125,8 @@ public class TestLinkCollectionIntent { |
| 140 | links2.add(link2); | 125 | links2.add(link2); |
| 141 | links2.add(link1); | 126 | links2.add(link1); |
| 142 | 127 | ||
| 143 | - LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1); | 128 | + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1); |
| 144 | - LinkCollectionIntent i2 = makeLinkCollection(1, links2, egress1); | 129 | + LinkCollectionIntent i2 = makeLinkCollection(links2, egress1); |
| 145 | 130 | ||
| 146 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); | 131 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
| 147 | } | 132 | } |
| ... | @@ -158,8 +143,8 @@ public class TestLinkCollectionIntent { | ... | @@ -158,8 +143,8 @@ public class TestLinkCollectionIntent { |
| 158 | links2.add(link1); | 143 | links2.add(link1); |
| 159 | links2.add(link3); | 144 | links2.add(link3); |
| 160 | 145 | ||
| 161 | - LinkCollectionIntent i1 = makeLinkCollection(1, links1, egress1); | 146 | + LinkCollectionIntent i1 = makeLinkCollection(links1, egress1); |
| 162 | - LinkCollectionIntent i2 = makeLinkCollection(1, links2, egress2); | 147 | + LinkCollectionIntent i2 = makeLinkCollection(links2, egress2); |
| 163 | 148 | ||
| 164 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); | 149 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); |
| 165 | } | 150 | } | ... | ... |
| 1 | package org.onlab.onos.net.intent; | 1 | package org.onlab.onos.net.intent; |
| 2 | 2 | ||
| 3 | -import java.util.HashSet; | ||
| 4 | -import java.util.Set; | ||
| 5 | - | ||
| 6 | import org.junit.Before; | 3 | import org.junit.Before; |
| 7 | import org.junit.Test; | 4 | import org.junit.Test; |
| 5 | +import org.onlab.onos.ApplicationId; | ||
| 6 | +import org.onlab.onos.TestApplicationId; | ||
| 8 | import org.onlab.onos.net.ConnectPoint; | 7 | import org.onlab.onos.net.ConnectPoint; |
| 9 | import org.onlab.onos.net.flow.TrafficSelector; | 8 | import org.onlab.onos.net.flow.TrafficSelector; |
| 10 | import org.onlab.onos.net.flow.TrafficTreatment; | 9 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 11 | 10 | ||
| 11 | +import java.util.HashSet; | ||
| 12 | +import java.util.Set; | ||
| 13 | + | ||
| 12 | import static org.hamcrest.CoreMatchers.not; | 14 | import static org.hamcrest.CoreMatchers.not; |
| 13 | import static org.hamcrest.MatcherAssert.assertThat; | 15 | import static org.hamcrest.MatcherAssert.assertThat; |
| 14 | import static org.hamcrest.Matchers.equalTo; | 16 | import static org.hamcrest.Matchers.equalTo; |
| ... | @@ -20,6 +22,8 @@ import static org.onlab.onos.net.NetTestTools.connectPoint; | ... | @@ -20,6 +22,8 @@ import static org.onlab.onos.net.NetTestTools.connectPoint; |
| 20 | */ | 22 | */ |
| 21 | public class TestMultiPointToSinglePointIntent { | 23 | public class TestMultiPointToSinglePointIntent { |
| 22 | 24 | ||
| 25 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 26 | + | ||
| 23 | private ConnectPoint point1 = connectPoint("dev1", 1); | 27 | private ConnectPoint point1 = connectPoint("dev1", 1); |
| 24 | private ConnectPoint point2 = connectPoint("dev2", 1); | 28 | private ConnectPoint point2 = connectPoint("dev2", 1); |
| 25 | private ConnectPoint point3 = connectPoint("dev3", 1); | 29 | private ConnectPoint point3 = connectPoint("dev3", 1); |
| ... | @@ -33,19 +37,14 @@ public class TestMultiPointToSinglePointIntent { | ... | @@ -33,19 +37,14 @@ public class TestMultiPointToSinglePointIntent { |
| 33 | /** | 37 | /** |
| 34 | * Creates a MultiPointToSinglePointIntent object. | 38 | * Creates a MultiPointToSinglePointIntent object. |
| 35 | * | 39 | * |
| 36 | - * @param id identifier to use for the new intent | ||
| 37 | * @param ingress set of ingress points | 40 | * @param ingress set of ingress points |
| 38 | - * @param egress egress point | 41 | + * @param egress egress point |
| 39 | * @return MultiPointToSinglePoint intent | 42 | * @return MultiPointToSinglePoint intent |
| 40 | */ | 43 | */ |
| 41 | - private MultiPointToSinglePointIntent makeIntent(long id, | 44 | + private MultiPointToSinglePointIntent makeIntent(Set<ConnectPoint> ingress, |
| 42 | - Set<ConnectPoint> ingress, | 45 | + ConnectPoint egress) { |
| 43 | - ConnectPoint egress) { | 46 | + return new MultiPointToSinglePointIntent(APPID, selector, treatment, |
| 44 | - return new MultiPointToSinglePointIntent(new IntentId(id), | 47 | + ingress, egress); |
| 45 | - selector, | ||
| 46 | - treatment, | ||
| 47 | - ingress, | ||
| 48 | - egress); | ||
| 49 | } | 48 | } |
| 50 | 49 | ||
| 51 | /** | 50 | /** |
| ... | @@ -72,8 +71,8 @@ public class TestMultiPointToSinglePointIntent { | ... | @@ -72,8 +71,8 @@ public class TestMultiPointToSinglePointIntent { |
| 72 | ingress2.add(point3); | 71 | ingress2.add(point3); |
| 73 | ingress2.add(point2); | 72 | ingress2.add(point2); |
| 74 | 73 | ||
| 75 | - Intent i1 = makeIntent(12, ingress1, point1); | 74 | + Intent i1 = makeIntent(ingress1, point1); |
| 76 | - Intent i2 = makeIntent(12, ingress2, point1); | 75 | + Intent i2 = makeIntent(ingress2, point1); |
| 77 | 76 | ||
| 78 | assertThat(i1, is(equalTo(i2))); | 77 | assertThat(i1, is(equalTo(i2))); |
| 79 | } | 78 | } |
| ... | @@ -89,23 +88,8 @@ public class TestMultiPointToSinglePointIntent { | ... | @@ -89,23 +88,8 @@ public class TestMultiPointToSinglePointIntent { |
| 89 | ingress2.add(point3); | 88 | ingress2.add(point3); |
| 90 | ingress2.add(point2); | 89 | ingress2.add(point2); |
| 91 | 90 | ||
| 92 | - Intent i1 = makeIntent(12, ingress1, point1); | 91 | + Intent i1 = makeIntent(ingress1, point1); |
| 93 | - Intent i2 = makeIntent(12, ingress2, point1); | 92 | + Intent i2 = makeIntent(ingress2, point1); |
| 94 | - | ||
| 95 | - assertThat(i1, is(not(equalTo(i2)))); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - /** | ||
| 99 | - * Tests the equals() method where two MultiPointToSinglePoint have different | ||
| 100 | - * ids. These should compare not equal. | ||
| 101 | - */ | ||
| 102 | - @Test | ||
| 103 | - public void testBaseDifferentEquals() { | ||
| 104 | - ingress1.add(point3); | ||
| 105 | - ingress2.add(point3); | ||
| 106 | - | ||
| 107 | - Intent i1 = makeIntent(12, ingress1, point1); | ||
| 108 | - Intent i2 = makeIntent(11, ingress2, point1); | ||
| 109 | 93 | ||
| 110 | assertThat(i1, is(not(equalTo(i2)))); | 94 | assertThat(i1, is(not(equalTo(i2)))); |
| 111 | } | 95 | } |
| ... | @@ -122,8 +106,8 @@ public class TestMultiPointToSinglePointIntent { | ... | @@ -122,8 +106,8 @@ public class TestMultiPointToSinglePointIntent { |
| 122 | ingress2.add(point3); | 106 | ingress2.add(point3); |
| 123 | ingress2.add(point2); | 107 | ingress2.add(point2); |
| 124 | 108 | ||
| 125 | - Intent i1 = makeIntent(12, ingress1, point1); | 109 | + Intent i1 = makeIntent(ingress1, point1); |
| 126 | - Intent i2 = makeIntent(12, ingress2, point1); | 110 | + Intent i2 = makeIntent(ingress2, point1); |
| 127 | 111 | ||
| 128 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); | 112 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
| 129 | } | 113 | } |
| ... | @@ -139,8 +123,8 @@ public class TestMultiPointToSinglePointIntent { | ... | @@ -139,8 +123,8 @@ public class TestMultiPointToSinglePointIntent { |
| 139 | ingress2.add(point3); | 123 | ingress2.add(point3); |
| 140 | ingress2.add(point2); | 124 | ingress2.add(point2); |
| 141 | 125 | ||
| 142 | - Intent i1 = makeIntent(12, ingress1, point1); | 126 | + Intent i1 = makeIntent(ingress1, point1); |
| 143 | - Intent i2 = makeIntent(12, ingress2, point1); | 127 | + Intent i2 = makeIntent(ingress2, point1); |
| 144 | 128 | ||
| 145 | 129 | ||
| 146 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); | 130 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); | ... | ... |
| 1 | package org.onlab.onos.net.intent; | 1 | package org.onlab.onos.net.intent; |
| 2 | 2 | ||
| 3 | import org.junit.Test; | 3 | import org.junit.Test; |
| 4 | +import org.onlab.onos.ApplicationId; | ||
| 5 | +import org.onlab.onos.TestApplicationId; | ||
| 4 | import org.onlab.onos.net.ConnectPoint; | 6 | import org.onlab.onos.net.ConnectPoint; |
| 5 | import org.onlab.onos.net.flow.TrafficSelector; | 7 | import org.onlab.onos.net.flow.TrafficSelector; |
| 6 | import org.onlab.onos.net.flow.TrafficTreatment; | 8 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 7 | 9 | ||
| 8 | import static org.hamcrest.MatcherAssert.assertThat; | 10 | import static org.hamcrest.MatcherAssert.assertThat; |
| 9 | -import static org.hamcrest.Matchers.equalTo; | 11 | +import static org.hamcrest.Matchers.*; |
| 10 | -import static org.hamcrest.Matchers.is; | ||
| 11 | -import static org.hamcrest.Matchers.not; | ||
| 12 | import static org.onlab.onos.net.NetTestTools.connectPoint; | 12 | import static org.onlab.onos.net.NetTestTools.connectPoint; |
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| ... | @@ -16,20 +16,17 @@ import static org.onlab.onos.net.NetTestTools.connectPoint; | ... | @@ -16,20 +16,17 @@ import static org.onlab.onos.net.NetTestTools.connectPoint; |
| 16 | */ | 16 | */ |
| 17 | public class TestPointToPointIntent { | 17 | public class TestPointToPointIntent { |
| 18 | 18 | ||
| 19 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 20 | + | ||
| 19 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 21 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 20 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 22 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 21 | 23 | ||
| 22 | private ConnectPoint point1 = connectPoint("dev1", 1); | 24 | private ConnectPoint point1 = connectPoint("dev1", 1); |
| 23 | private ConnectPoint point2 = connectPoint("dev2", 1); | 25 | private ConnectPoint point2 = connectPoint("dev2", 1); |
| 24 | 26 | ||
| 25 | - private PointToPointIntent makePointToPoint(long id, | 27 | + private PointToPointIntent makePointToPoint(ConnectPoint ingress, |
| 26 | - ConnectPoint ingress, | ||
| 27 | ConnectPoint egress) { | 28 | ConnectPoint egress) { |
| 28 | - return new PointToPointIntent(new IntentId(id), | 29 | + return new PointToPointIntent(APPID, selector, treatment, ingress, egress); |
| 29 | - selector, | ||
| 30 | - treatment, | ||
| 31 | - ingress, | ||
| 32 | - egress); | ||
| 33 | } | 30 | } |
| 34 | 31 | ||
| 35 | /** | 32 | /** |
| ... | @@ -38,8 +35,8 @@ public class TestPointToPointIntent { | ... | @@ -38,8 +35,8 @@ public class TestPointToPointIntent { |
| 38 | */ | 35 | */ |
| 39 | @Test | 36 | @Test |
| 40 | public void testSameEquals() { | 37 | public void testSameEquals() { |
| 41 | - PointToPointIntent i1 = makePointToPoint(12, point1, point2); | 38 | + PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 42 | - PointToPointIntent i2 = makePointToPoint(12, point1, point2); | 39 | + PointToPointIntent i2 = makePointToPoint(point1, point2); |
| 43 | 40 | ||
| 44 | assertThat(i1, is(equalTo(i2))); | 41 | assertThat(i1, is(equalTo(i2))); |
| 45 | } | 42 | } |
| ... | @@ -50,22 +47,8 @@ public class TestPointToPointIntent { | ... | @@ -50,22 +47,8 @@ public class TestPointToPointIntent { |
| 50 | */ | 47 | */ |
| 51 | @Test | 48 | @Test |
| 52 | public void testLinksDifferentEquals() { | 49 | public void testLinksDifferentEquals() { |
| 53 | - | 50 | + PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 54 | - PointToPointIntent i1 = makePointToPoint(12, point1, point2); | 51 | + PointToPointIntent i2 = makePointToPoint(point2, point1); |
| 55 | - PointToPointIntent i2 = makePointToPoint(12, point2, point1); | ||
| 56 | - | ||
| 57 | - assertThat(i1, is(not(equalTo(i2)))); | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - /** | ||
| 61 | - * Tests the equals() method where two HostToHostIntents have different | ||
| 62 | - * ids. These should compare not equal. | ||
| 63 | - */ | ||
| 64 | - @Test | ||
| 65 | - public void testBaseDifferentEquals() { | ||
| 66 | - PointToPointIntent i1 = makePointToPoint(12, point1, point2); | ||
| 67 | - PointToPointIntent i2 = makePointToPoint(11, point1, point2); | ||
| 68 | - | ||
| 69 | 52 | ||
| 70 | assertThat(i1, is(not(equalTo(i2)))); | 53 | assertThat(i1, is(not(equalTo(i2)))); |
| 71 | } | 54 | } |
| ... | @@ -76,8 +59,8 @@ public class TestPointToPointIntent { | ... | @@ -76,8 +59,8 @@ public class TestPointToPointIntent { |
| 76 | */ | 59 | */ |
| 77 | @Test | 60 | @Test |
| 78 | public void testHashCodeEquals() { | 61 | public void testHashCodeEquals() { |
| 79 | - PointToPointIntent i1 = makePointToPoint(12, point1, point2); | 62 | + PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 80 | - PointToPointIntent i2 = makePointToPoint(12, point1, point2); | 63 | + PointToPointIntent i2 = makePointToPoint(point1, point2); |
| 81 | 64 | ||
| 82 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); | 65 | assertThat(i1.hashCode(), is(equalTo(i2.hashCode()))); |
| 83 | } | 66 | } |
| ... | @@ -88,8 +71,8 @@ public class TestPointToPointIntent { | ... | @@ -88,8 +71,8 @@ public class TestPointToPointIntent { |
| 88 | */ | 71 | */ |
| 89 | @Test | 72 | @Test |
| 90 | public void testHashCodeDifferent() { | 73 | public void testHashCodeDifferent() { |
| 91 | - PointToPointIntent i1 = makePointToPoint(12, point1, point2); | 74 | + PointToPointIntent i1 = makePointToPoint(point1, point2); |
| 92 | - PointToPointIntent i2 = makePointToPoint(22, point1, point2); | 75 | + PointToPointIntent i2 = makePointToPoint(point2, point1); |
| 93 | 76 | ||
| 94 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); | 77 | assertThat(i1.hashCode(), is(not(equalTo(i2.hashCode())))); |
| 95 | } | 78 | } | ... | ... |
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import java.util.List; | ||
| 4 | - | ||
| 5 | import org.hamcrest.Matchers; | 3 | import org.hamcrest.Matchers; |
| 6 | import org.junit.Before; | 4 | import org.junit.Before; |
| 7 | import org.junit.Test; | 5 | import org.junit.Test; |
| 6 | +import org.onlab.onos.ApplicationId; | ||
| 7 | +import org.onlab.onos.TestApplicationId; | ||
| 8 | import org.onlab.onos.net.Host; | 8 | import org.onlab.onos.net.Host; |
| 9 | import org.onlab.onos.net.HostId; | 9 | import org.onlab.onos.net.HostId; |
| 10 | import org.onlab.onos.net.flow.TrafficSelector; | 10 | import org.onlab.onos.net.flow.TrafficSelector; |
| ... | @@ -12,16 +12,14 @@ import org.onlab.onos.net.flow.TrafficTreatment; | ... | @@ -12,16 +12,14 @@ import org.onlab.onos.net.flow.TrafficTreatment; |
| 12 | import org.onlab.onos.net.host.HostService; | 12 | import org.onlab.onos.net.host.HostService; |
| 13 | import org.onlab.onos.net.intent.HostToHostIntent; | 13 | import org.onlab.onos.net.intent.HostToHostIntent; |
| 14 | import org.onlab.onos.net.intent.Intent; | 14 | import org.onlab.onos.net.intent.Intent; |
| 15 | -import org.onlab.onos.net.intent.IntentId; | ||
| 16 | import org.onlab.onos.net.intent.IntentTestsMocks; | 15 | import org.onlab.onos.net.intent.IntentTestsMocks; |
| 17 | import org.onlab.onos.net.intent.PathIntent; | 16 | import org.onlab.onos.net.intent.PathIntent; |
| 18 | import org.onlab.packet.MacAddress; | 17 | import org.onlab.packet.MacAddress; |
| 19 | import org.onlab.packet.VlanId; | 18 | import org.onlab.packet.VlanId; |
| 20 | 19 | ||
| 21 | -import static org.easymock.EasyMock.createMock; | 20 | +import java.util.List; |
| 22 | -import static org.easymock.EasyMock.eq; | 21 | + |
| 23 | -import static org.easymock.EasyMock.expect; | 22 | +import static org.easymock.EasyMock.*; |
| 24 | -import static org.easymock.EasyMock.replay; | ||
| 25 | import static org.hamcrest.CoreMatchers.notNullValue; | 23 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 26 | import static org.hamcrest.MatcherAssert.assertThat; | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 27 | import static org.hamcrest.Matchers.hasSize; | 25 | import static org.hamcrest.Matchers.hasSize; |
| ... | @@ -40,6 +38,8 @@ public class TestHostToHostIntentCompiler { | ... | @@ -40,6 +38,8 @@ public class TestHostToHostIntentCompiler { |
| 40 | private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN; | 38 | private static final String HOST_ONE = HOST_ONE_MAC + "/" + HOST_ONE_VLAN; |
| 41 | private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN; | 39 | private static final String HOST_TWO = HOST_TWO_MAC + "/" + HOST_TWO_VLAN; |
| 42 | 40 | ||
| 41 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 42 | + | ||
| 43 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 43 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 44 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 44 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 45 | 45 | ||
| ... | @@ -73,11 +73,8 @@ public class TestHostToHostIntentCompiler { | ... | @@ -73,11 +73,8 @@ public class TestHostToHostIntentCompiler { |
| 73 | * @return HostToHostIntent for the two hosts | 73 | * @return HostToHostIntent for the two hosts |
| 74 | */ | 74 | */ |
| 75 | private HostToHostIntent makeIntent(String oneIdString, String twoIdString) { | 75 | private HostToHostIntent makeIntent(String oneIdString, String twoIdString) { |
| 76 | - return new HostToHostIntent(new IntentId(12), | 76 | + return new HostToHostIntent(APPID, hid(oneIdString), hid(twoIdString), |
| 77 | - hid(oneIdString), | 77 | + selector, treatment); |
| 78 | - hid(twoIdString), | ||
| 79 | - selector, | ||
| 80 | - treatment); | ||
| 81 | } | 78 | } |
| 82 | 79 | ||
| 83 | /** | 80 | /** |
| ... | @@ -91,9 +88,6 @@ public class TestHostToHostIntentCompiler { | ... | @@ -91,9 +88,6 @@ public class TestHostToHostIntentCompiler { |
| 91 | new HostToHostIntentCompiler(); | 88 | new HostToHostIntentCompiler(); |
| 92 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); | 89 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
| 93 | compiler.hostService = mockHostService; | 90 | compiler.hostService = mockHostService; |
| 94 | - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator(); | ||
| 95 | - compiler.intentIdGenerator = | ||
| 96 | - new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); | ||
| 97 | return compiler; | 91 | return compiler; |
| 98 | } | 92 | } |
| 99 | 93 | ... | ... |
core/net/src/test/java/org/onlab/onos/net/intent/impl/TestMultiPointToSinglePointIntentCompiler.java
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import java.util.HashSet; | ||
| 4 | -import java.util.List; | ||
| 5 | -import java.util.Set; | ||
| 6 | - | ||
| 7 | import org.hamcrest.Matchers; | 3 | import org.hamcrest.Matchers; |
| 8 | import org.junit.Test; | 4 | import org.junit.Test; |
| 5 | +import org.onlab.onos.ApplicationId; | ||
| 6 | +import org.onlab.onos.TestApplicationId; | ||
| 9 | import org.onlab.onos.net.ConnectPoint; | 7 | import org.onlab.onos.net.ConnectPoint; |
| 10 | import org.onlab.onos.net.ElementId; | 8 | import org.onlab.onos.net.ElementId; |
| 11 | import org.onlab.onos.net.Path; | 9 | import org.onlab.onos.net.Path; |
| 12 | import org.onlab.onos.net.flow.TrafficSelector; | 10 | import org.onlab.onos.net.flow.TrafficSelector; |
| 13 | import org.onlab.onos.net.flow.TrafficTreatment; | 11 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 14 | import org.onlab.onos.net.intent.Intent; | 12 | import org.onlab.onos.net.intent.Intent; |
| 15 | -import org.onlab.onos.net.intent.IntentId; | ||
| 16 | import org.onlab.onos.net.intent.IntentTestsMocks; | 13 | import org.onlab.onos.net.intent.IntentTestsMocks; |
| 17 | import org.onlab.onos.net.intent.LinkCollectionIntent; | 14 | import org.onlab.onos.net.intent.LinkCollectionIntent; |
| 18 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; | 15 | import org.onlab.onos.net.intent.MultiPointToSinglePointIntent; |
| 19 | import org.onlab.onos.net.topology.LinkWeight; | 16 | import org.onlab.onos.net.topology.LinkWeight; |
| 20 | import org.onlab.onos.net.topology.PathService; | 17 | import org.onlab.onos.net.topology.PathService; |
| 21 | 18 | ||
| 19 | +import java.util.HashSet; | ||
| 20 | +import java.util.List; | ||
| 21 | +import java.util.Set; | ||
| 22 | + | ||
| 22 | import static org.hamcrest.CoreMatchers.notNullValue; | 23 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; | 24 | import static org.hamcrest.MatcherAssert.assertThat; |
| 24 | import static org.hamcrest.Matchers.hasSize; | 25 | import static org.hamcrest.Matchers.hasSize; |
| ... | @@ -32,6 +33,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM | ... | @@ -32,6 +33,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM |
| 32 | */ | 33 | */ |
| 33 | public class TestMultiPointToSinglePointIntentCompiler { | 34 | public class TestMultiPointToSinglePointIntentCompiler { |
| 34 | 35 | ||
| 36 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 37 | + | ||
| 35 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 38 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 36 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 39 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 37 | 40 | ||
| ... | @@ -74,7 +77,7 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -74,7 +77,7 @@ public class TestMultiPointToSinglePointIntentCompiler { |
| 74 | * and an egress point. | 77 | * and an egress point. |
| 75 | * | 78 | * |
| 76 | * @param ingressIds array of ingress device ids | 79 | * @param ingressIds array of ingress device ids |
| 77 | - * @param egressId device id of the egress point | 80 | + * @param egressId device id of the egress point |
| 78 | * @return MultiPointToSinglePoint intent | 81 | * @return MultiPointToSinglePoint intent |
| 79 | */ | 82 | */ |
| 80 | private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) { | 83 | private MultiPointToSinglePointIntent makeIntent(String[] ingressIds, String egressId) { |
| ... | @@ -82,15 +85,11 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -82,15 +85,11 @@ public class TestMultiPointToSinglePointIntentCompiler { |
| 82 | ConnectPoint egressPoint = connectPoint(egressId, 1); | 85 | ConnectPoint egressPoint = connectPoint(egressId, 1); |
| 83 | 86 | ||
| 84 | for (String ingressId : ingressIds) { | 87 | for (String ingressId : ingressIds) { |
| 85 | - ingressPoints.add(connectPoint(ingressId, 1)); | 88 | + ingressPoints.add(connectPoint(ingressId, 1)); |
| 86 | } | 89 | } |
| 87 | 90 | ||
| 88 | - return new MultiPointToSinglePointIntent( | 91 | + return new MultiPointToSinglePointIntent(APPID, selector, treatment, |
| 89 | - new IntentId(12), | 92 | + ingressPoints, egressPoint); |
| 90 | - selector, | ||
| 91 | - treatment, | ||
| 92 | - ingressPoints, | ||
| 93 | - egressPoint); | ||
| 94 | } | 93 | } |
| 95 | 94 | ||
| 96 | /** | 95 | /** |
| ... | @@ -103,9 +102,6 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -103,9 +102,6 @@ public class TestMultiPointToSinglePointIntentCompiler { |
| 103 | MultiPointToSinglePointIntentCompiler compiler = | 102 | MultiPointToSinglePointIntentCompiler compiler = |
| 104 | new MultiPointToSinglePointIntentCompiler(); | 103 | new MultiPointToSinglePointIntentCompiler(); |
| 105 | compiler.pathService = new MockPathService(hops); | 104 | compiler.pathService = new MockPathService(hops); |
| 106 | - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator(); | ||
| 107 | - compiler.intentIdGenerator = | ||
| 108 | - new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); | ||
| 109 | return compiler; | 105 | return compiler; |
| 110 | } | 106 | } |
| 111 | 107 | ||
| ... | @@ -122,7 +118,7 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -122,7 +118,7 @@ public class TestMultiPointToSinglePointIntentCompiler { |
| 122 | assertThat(intent, is(notNullValue())); | 118 | assertThat(intent, is(notNullValue())); |
| 123 | 119 | ||
| 124 | String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", | 120 | String[] hops = {"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8", |
| 125 | - egress}; | 121 | + egress}; |
| 126 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); | 122 | MultiPointToSinglePointIntentCompiler compiler = makeCompiler(hops); |
| 127 | assertThat(compiler, is(notNullValue())); | 123 | assertThat(compiler, is(notNullValue())); |
| 128 | 124 | ||
| ... | @@ -184,7 +180,7 @@ public class TestMultiPointToSinglePointIntentCompiler { | ... | @@ -184,7 +180,7 @@ public class TestMultiPointToSinglePointIntentCompiler { |
| 184 | @Test | 180 | @Test |
| 185 | public void testMultiIngressCompilation() { | 181 | public void testMultiIngressCompilation() { |
| 186 | String[] ingress = {"i1", "i2", "i3", "i4", "i5", | 182 | String[] ingress = {"i1", "i2", "i3", "i4", "i5", |
| 187 | - "i6", "i7", "i8", "i9", "i10"}; | 183 | + "i6", "i7", "i8", "i9", "i10"}; |
| 188 | String egress = "e"; | 184 | String egress = "e"; |
| 189 | 185 | ||
| 190 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); | 186 | MultiPointToSinglePointIntent intent = makeIntent(ingress, egress); | ... | ... |
| 1 | package org.onlab.onos.net.intent.impl; | 1 | package org.onlab.onos.net.intent.impl; |
| 2 | 2 | ||
| 3 | -import java.util.List; | ||
| 4 | - | ||
| 5 | import org.hamcrest.Matchers; | 3 | import org.hamcrest.Matchers; |
| 6 | import org.junit.Test; | 4 | import org.junit.Test; |
| 5 | +import org.onlab.onos.ApplicationId; | ||
| 6 | +import org.onlab.onos.TestApplicationId; | ||
| 7 | import org.onlab.onos.net.flow.TrafficSelector; | 7 | import org.onlab.onos.net.flow.TrafficSelector; |
| 8 | import org.onlab.onos.net.flow.TrafficTreatment; | 8 | import org.onlab.onos.net.flow.TrafficTreatment; |
| 9 | import org.onlab.onos.net.intent.Intent; | 9 | import org.onlab.onos.net.intent.Intent; |
| 10 | -import org.onlab.onos.net.intent.IntentId; | ||
| 11 | import org.onlab.onos.net.intent.IntentTestsMocks; | 10 | import org.onlab.onos.net.intent.IntentTestsMocks; |
| 12 | import org.onlab.onos.net.intent.PathIntent; | 11 | import org.onlab.onos.net.intent.PathIntent; |
| 13 | import org.onlab.onos.net.intent.PointToPointIntent; | 12 | import org.onlab.onos.net.intent.PointToPointIntent; |
| 14 | 13 | ||
| 14 | +import java.util.List; | ||
| 15 | + | ||
| 15 | import static org.hamcrest.CoreMatchers.notNullValue; | 16 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 16 | import static org.hamcrest.MatcherAssert.assertThat; | 17 | import static org.hamcrest.MatcherAssert.assertThat; |
| 17 | import static org.hamcrest.Matchers.hasSize; | 18 | import static org.hamcrest.Matchers.hasSize; |
| ... | @@ -24,6 +25,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM | ... | @@ -24,6 +25,8 @@ import static org.onlab.onos.net.intent.LinksHaveEntryWithSourceDestinationPairM |
| 24 | */ | 25 | */ |
| 25 | public class TestPointToPointIntentCompiler { | 26 | public class TestPointToPointIntentCompiler { |
| 26 | 27 | ||
| 28 | + private static final ApplicationId APPID = new TestApplicationId("foo"); | ||
| 29 | + | ||
| 27 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); | 30 | private TrafficSelector selector = new IntentTestsMocks.MockSelector(); |
| 28 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); | 31 | private TrafficTreatment treatment = new IntentTestsMocks.MockTreatment(); |
| 29 | 32 | ||
| ... | @@ -31,14 +34,12 @@ public class TestPointToPointIntentCompiler { | ... | @@ -31,14 +34,12 @@ public class TestPointToPointIntentCompiler { |
| 31 | * Creates a PointToPoint intent based on ingress and egress device Ids. | 34 | * Creates a PointToPoint intent based on ingress and egress device Ids. |
| 32 | * | 35 | * |
| 33 | * @param ingressIdString string for id of ingress device | 36 | * @param ingressIdString string for id of ingress device |
| 34 | - * @param egressIdString string for id of egress device | 37 | + * @param egressIdString string for id of egress device |
| 35 | * @return PointToPointIntent for the two devices | 38 | * @return PointToPointIntent for the two devices |
| 36 | */ | 39 | */ |
| 37 | private PointToPointIntent makeIntent(String ingressIdString, | 40 | private PointToPointIntent makeIntent(String ingressIdString, |
| 38 | String egressIdString) { | 41 | String egressIdString) { |
| 39 | - return new PointToPointIntent(new IntentId(12), | 42 | + return new PointToPointIntent(APPID, selector, treatment, |
| 40 | - selector, | ||
| 41 | - treatment, | ||
| 42 | connectPoint(ingressIdString, 1), | 43 | connectPoint(ingressIdString, 1), |
| 43 | connectPoint(egressIdString, 1)); | 44 | connectPoint(egressIdString, 1)); |
| 44 | } | 45 | } |
| ... | @@ -53,9 +54,6 @@ public class TestPointToPointIntentCompiler { | ... | @@ -53,9 +54,6 @@ public class TestPointToPointIntentCompiler { |
| 53 | PointToPointIntentCompiler compiler = | 54 | PointToPointIntentCompiler compiler = |
| 54 | new PointToPointIntentCompiler(); | 55 | new PointToPointIntentCompiler(); |
| 55 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); | 56 | compiler.pathService = new IntentTestsMocks.MockPathService(hops); |
| 56 | - IdBlockAllocator idBlockAllocator = new DummyIdBlockAllocator(); | ||
| 57 | - compiler.intentIdGenerator = | ||
| 58 | - new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); | ||
| 59 | return compiler; | 57 | return compiler; |
| 60 | } | 58 | } |
| 61 | 59 | ... | ... |
| 1 | package org.onlab.onos.store.intent.impl; | 1 | package org.onlab.onos.store.intent.impl; |
| 2 | 2 | ||
| 3 | -import static org.onlab.onos.net.intent.IntentState.FAILED; | 3 | +import com.google.common.collect.ImmutableSet; |
| 4 | -import static org.onlab.onos.net.intent.IntentState.INSTALLED; | ||
| 5 | -import static org.onlab.onos.net.intent.IntentState.SUBMITTED; | ||
| 6 | -import static org.onlab.onos.net.intent.IntentState.WITHDRAWN; | ||
| 7 | -import static org.slf4j.LoggerFactory.getLogger; | ||
| 8 | - | ||
| 9 | -import java.util.List; | ||
| 10 | -import java.util.Map; | ||
| 11 | -import java.util.concurrent.ConcurrentHashMap; | ||
| 12 | - | ||
| 13 | import org.apache.felix.scr.annotations.Activate; | 4 | import org.apache.felix.scr.annotations.Activate; |
| 14 | import org.apache.felix.scr.annotations.Component; | 5 | import org.apache.felix.scr.annotations.Component; |
| 15 | import org.apache.felix.scr.annotations.Deactivate; | 6 | import org.apache.felix.scr.annotations.Deactivate; |
| 16 | import org.apache.felix.scr.annotations.Service; | 7 | import org.apache.felix.scr.annotations.Service; |
| 17 | -import org.onlab.onos.net.intent.InstallableIntent; | ||
| 18 | import org.onlab.onos.net.intent.Intent; | 8 | import org.onlab.onos.net.intent.Intent; |
| 19 | import org.onlab.onos.net.intent.IntentEvent; | 9 | import org.onlab.onos.net.intent.IntentEvent; |
| 20 | import org.onlab.onos.net.intent.IntentId; | 10 | import org.onlab.onos.net.intent.IntentId; |
| ... | @@ -24,7 +14,12 @@ import org.onlab.onos.net.intent.IntentStoreDelegate; | ... | @@ -24,7 +14,12 @@ import org.onlab.onos.net.intent.IntentStoreDelegate; |
| 24 | import org.onlab.onos.store.AbstractStore; | 14 | import org.onlab.onos.store.AbstractStore; |
| 25 | import org.slf4j.Logger; | 15 | import org.slf4j.Logger; |
| 26 | 16 | ||
| 27 | -import com.google.common.collect.ImmutableSet; | 17 | +import java.util.List; |
| 18 | +import java.util.Map; | ||
| 19 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 20 | + | ||
| 21 | +import static org.onlab.onos.net.intent.IntentState.*; | ||
| 22 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 28 | 23 | ||
| 29 | //FIXME: I LIE I AM NOT DISTRIBUTED | 24 | //FIXME: I LIE I AM NOT DISTRIBUTED |
| 30 | @Component(immediate = true) | 25 | @Component(immediate = true) |
| ... | @@ -36,8 +31,7 @@ public class DistributedIntentStore | ... | @@ -36,8 +31,7 @@ public class DistributedIntentStore |
| 36 | private final Logger log = getLogger(getClass()); | 31 | private final Logger log = getLogger(getClass()); |
| 37 | private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); | 32 | private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>(); |
| 38 | private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); | 33 | private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>(); |
| 39 | - private final Map<IntentId, List<InstallableIntent>> installable = | 34 | + private final Map<IntentId, List<Intent>> installable = new ConcurrentHashMap<>(); |
| 40 | - new ConcurrentHashMap<>(); | ||
| 41 | 35 | ||
| 42 | @Activate | 36 | @Activate |
| 43 | public void activate() { | 37 | public void activate() { |
| ... | @@ -97,12 +91,12 @@ public class DistributedIntentStore | ... | @@ -97,12 +91,12 @@ public class DistributedIntentStore |
| 97 | } | 91 | } |
| 98 | 92 | ||
| 99 | @Override | 93 | @Override |
| 100 | - public void addInstallableIntents(IntentId intentId, List<InstallableIntent> result) { | 94 | + public void addInstallableIntents(IntentId intentId, List<Intent> result) { |
| 101 | installable.put(intentId, result); | 95 | installable.put(intentId, result); |
| 102 | } | 96 | } |
| 103 | 97 | ||
| 104 | @Override | 98 | @Override |
| 105 | - public List<InstallableIntent> getInstallableIntents(IntentId intentId) { | 99 | + public List<Intent> getInstallableIntents(IntentId intentId) { |
| 106 | return installable.get(intentId); | 100 | return installable.get(intentId); |
| 107 | } | 101 | } |
| 108 | 102 | ... | ... |
-
Please register or login to post a comment