Committed by
Sho Shimizu
Abondon the concept of resources under a link
Resources under a link are tied to resources under both ends of the link, and resources under a port are thought to be first-class objects compared to concept of link resources. We will deal with only device related resources from now on. Change-Id: I6aa418d1bf64b28374f325db0bc7e393f770dcdd
Showing
10 changed files
with
127 additions
and
213 deletions
... | @@ -18,9 +18,7 @@ package org.onosproject.net.newresource; | ... | @@ -18,9 +18,7 @@ package org.onosproject.net.newresource; |
18 | import com.google.common.testing.EqualsTester; | 18 | import com.google.common.testing.EqualsTester; |
19 | import org.junit.Test; | 19 | import org.junit.Test; |
20 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
21 | -import org.onosproject.net.ConnectPoint; | ||
22 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
23 | -import org.onosproject.net.LinkKey; | ||
24 | import org.onosproject.net.PortNumber; | 22 | import org.onosproject.net.PortNumber; |
25 | import org.onosproject.net.intent.IntentId; | 23 | import org.onosproject.net.intent.IntentId; |
26 | 24 | ||
... | @@ -29,18 +27,14 @@ public class ResourceAllocationTest { | ... | @@ -29,18 +27,14 @@ public class ResourceAllocationTest { |
29 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); | 27 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); |
30 | private static final DeviceId D2 = DeviceId.deviceId("of:002"); | 28 | private static final DeviceId D2 = DeviceId.deviceId("of:002"); |
31 | private static final PortNumber P1 = PortNumber.portNumber(1); | 29 | private static final PortNumber P1 = PortNumber.portNumber(1); |
32 | - private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); | ||
33 | - private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); | ||
34 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | 30 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
35 | private static final IntentId IID1 = IntentId.valueOf(30); | 31 | private static final IntentId IID1 = IntentId.valueOf(30); |
36 | - private static final LinkKey LK1 = LinkKey.linkKey(CP1_1, CP2_1); | ||
37 | - private static final LinkKey LK2 = LinkKey.linkKey(CP2_1, CP1_1); | ||
38 | 32 | ||
39 | @Test | 33 | @Test |
40 | public void testEquals() { | 34 | public void testEquals() { |
41 | - ResourceAllocation alloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); | 35 | + ResourceAllocation alloc1 = new ResourceAllocation(ResourcePath.discrete(D1, P1, VLAN1), IID1); |
42 | - ResourceAllocation sameAsAlloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); | 36 | + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(ResourcePath.discrete(D1, P1, VLAN1), IID1); |
43 | - ResourceAllocation alloc2 = new ResourceAllocation(ResourcePath.discrete(LK2, VLAN1), IID1); | 37 | + ResourceAllocation alloc2 = new ResourceAllocation(ResourcePath.discrete(D2, P1, VLAN1), IID1); |
44 | 38 | ||
45 | new EqualsTester() | 39 | new EqualsTester() |
46 | .addEqualityGroup(alloc1, sameAsAlloc1) | 40 | .addEqualityGroup(alloc1, sameAsAlloc1) | ... | ... |
... | @@ -19,9 +19,7 @@ import com.google.common.testing.EqualsTester; | ... | @@ -19,9 +19,7 @@ import com.google.common.testing.EqualsTester; |
19 | import org.junit.Test; | 19 | import org.junit.Test; |
20 | import org.onlab.packet.VlanId; | 20 | import org.onlab.packet.VlanId; |
21 | import org.onlab.util.Bandwidth; | 21 | import org.onlab.util.Bandwidth; |
22 | -import org.onosproject.net.ConnectPoint; | ||
23 | import org.onosproject.net.DeviceId; | 22 | import org.onosproject.net.DeviceId; |
24 | -import org.onosproject.net.LinkKey; | ||
25 | import org.onosproject.net.PortNumber; | 23 | import org.onosproject.net.PortNumber; |
26 | 24 | ||
27 | import java.util.Optional; | 25 | import java.util.Optional; |
... | @@ -35,19 +33,17 @@ public class ResourcePathTest { | ... | @@ -35,19 +33,17 @@ public class ResourcePathTest { |
35 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); | 33 | private static final DeviceId D1 = DeviceId.deviceId("of:001"); |
36 | private static final DeviceId D2 = DeviceId.deviceId("of:002"); | 34 | private static final DeviceId D2 = DeviceId.deviceId("of:002"); |
37 | private static final PortNumber P1 = PortNumber.portNumber(1); | 35 | private static final PortNumber P1 = PortNumber.portNumber(1); |
38 | - private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); | ||
39 | - private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); | ||
40 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); | 36 | private static final VlanId VLAN1 = VlanId.vlanId((short) 100); |
41 | private static final Bandwidth BW1 = Bandwidth.gbps(2); | 37 | private static final Bandwidth BW1 = Bandwidth.gbps(2); |
42 | private static final Bandwidth BW2 = Bandwidth.gbps(1); | 38 | private static final Bandwidth BW2 = Bandwidth.gbps(1); |
43 | 39 | ||
44 | @Test | 40 | @Test |
45 | public void testEquals() { | 41 | public void testEquals() { |
46 | - ResourcePath resource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | 42 | + ResourcePath resource1 = ResourcePath.discrete(D1, P1, VLAN1); |
47 | - ResourcePath sameAsResource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | 43 | + ResourcePath sameAsResource1 = ResourcePath.discrete(D1, P1, VLAN1); |
48 | - ResourcePath resource2 = ResourcePath.discrete(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); | 44 | + ResourcePath resource2 = ResourcePath.discrete(D2, P1, VLAN1); |
49 | - ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); | 45 | + ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), D1, P1, BW1); |
50 | - ResourcePath sameAsResource3 = ResourcePath.continuous(BW2.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); | 46 | + ResourcePath sameAsResource3 = ResourcePath.continuous(BW2.bps(), D1, P1, BW1); |
51 | 47 | ||
52 | new EqualsTester() | 48 | new EqualsTester() |
53 | .addEqualityGroup(resource1, sameAsResource1) | 49 | .addEqualityGroup(resource1, sameAsResource1) |
... | @@ -72,25 +68,24 @@ public class ResourcePathTest { | ... | @@ -72,25 +68,24 @@ public class ResourcePathTest { |
72 | 68 | ||
73 | @Test | 69 | @Test |
74 | public void testThereIsParent() { | 70 | public void testThereIsParent() { |
75 | - ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); | 71 | + ResourcePath path = ResourcePath.discrete(D1, P1, VLAN1); |
76 | - ResourcePath parent = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); | 72 | + ResourcePath parent = ResourcePath.discrete(D1, P1); |
77 | 73 | ||
78 | assertThat(path.parent(), is(Optional.of(parent))); | 74 | assertThat(path.parent(), is(Optional.of(parent))); |
79 | } | 75 | } |
80 | 76 | ||
81 | @Test | 77 | @Test |
82 | public void testNoParent() { | 78 | public void testNoParent() { |
83 | - ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); | 79 | + ResourcePath path = ResourcePath.discrete(D1); |
84 | 80 | ||
85 | assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT))); | 81 | assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT))); |
86 | } | 82 | } |
87 | 83 | ||
88 | @Test | 84 | @Test |
89 | public void testBase() { | 85 | public void testBase() { |
90 | - LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); | 86 | + ResourcePath path = ResourcePath.discrete(D1); |
91 | - ResourcePath path = ResourcePath.discrete(linkKey); | ||
92 | 87 | ||
93 | - LinkKey child = (LinkKey) path.last(); | 88 | + DeviceId child = (DeviceId) path.last(); |
94 | - assertThat(child, is(linkKey)); | 89 | + assertThat(child, is(D1)); |
95 | } | 90 | } |
96 | } | 91 | } | ... | ... |
... | @@ -34,6 +34,7 @@ import org.onosproject.net.HostId; | ... | @@ -34,6 +34,7 @@ import org.onosproject.net.HostId; |
34 | import org.onosproject.net.Link; | 34 | import org.onosproject.net.Link; |
35 | import org.onosproject.net.LinkKey; | 35 | import org.onosproject.net.LinkKey; |
36 | import org.onosproject.net.NetworkResource; | 36 | import org.onosproject.net.NetworkResource; |
37 | +import org.onosproject.net.PortNumber; | ||
37 | import org.onosproject.net.device.DeviceEvent; | 38 | import org.onosproject.net.device.DeviceEvent; |
38 | import org.onosproject.net.device.DeviceListener; | 39 | import org.onosproject.net.device.DeviceListener; |
39 | import org.onosproject.net.device.DeviceService; | 40 | import org.onosproject.net.device.DeviceService; |
... | @@ -302,11 +303,11 @@ public class ObjectiveTracker implements ObjectiveTrackerService { | ... | @@ -302,11 +303,11 @@ public class ObjectiveTracker implements ObjectiveTrackerService { |
302 | private class InternalResourceListener implements ResourceListener { | 303 | private class InternalResourceListener implements ResourceListener { |
303 | @Override | 304 | @Override |
304 | public void event(ResourceEvent event) { | 305 | public void event(ResourceEvent event) { |
305 | - Optional<Class<?>> linkEvent = event.subject().components().stream() | 306 | + Optional<Class<?>> deviceEvent = event.subject().components().stream() |
306 | .map(Object::getClass) | 307 | .map(Object::getClass) |
307 | - .filter(x -> x == LinkKey.class) | 308 | + .filter(x -> x == PortNumber.class) |
308 | .findFirst(); | 309 | .findFirst(); |
309 | - if (linkEvent.isPresent()) { | 310 | + if (deviceEvent.isPresent()) { |
310 | executorService.execute(() -> { | 311 | executorService.execute(() -> { |
311 | if (delegate == null) { | 312 | if (delegate == null) { |
312 | return; | 313 | return; | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.intent.impl.compiler; | 16 | package org.onosproject.net.intent.impl.compiler; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableList; | ||
18 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
19 | 20 | ||
20 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
... | @@ -59,9 +60,9 @@ import java.util.Iterator; | ... | @@ -59,9 +60,9 @@ import java.util.Iterator; |
59 | import java.util.LinkedList; | 60 | import java.util.LinkedList; |
60 | import java.util.List; | 61 | import java.util.List; |
61 | import java.util.Map; | 62 | import java.util.Map; |
62 | -import java.util.Optional; | ||
63 | import java.util.Set; | 63 | import java.util.Set; |
64 | import java.util.stream.Collectors; | 64 | import java.util.stream.Collectors; |
65 | +import java.util.stream.Stream; | ||
65 | 66 | ||
66 | import static com.google.common.base.Preconditions.checkNotNull; | 67 | import static com.google.common.base.Preconditions.checkNotNull; |
67 | import static org.onosproject.net.LinkKey.linkKey; | 68 | import static org.onosproject.net.LinkKey.linkKey; |
... | @@ -120,11 +121,16 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -120,11 +121,16 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
120 | return Collections.emptyMap(); | 121 | return Collections.emptyMap(); |
121 | } | 122 | } |
122 | 123 | ||
123 | - List<ResourcePath> resources = labels.entrySet().stream() | 124 | + // for short term solution: same label is used for both directions |
124 | - .map(x -> ResourcePath.discrete(linkKey(x.getKey().src(), x.getKey().src()), x.getValue())) | 125 | + // TODO: introduce the concept of Tx and Rx resources of a port |
125 | - .collect(Collectors.toList()); | 126 | + Set<ResourcePath> resources = labels.entrySet().stream() |
127 | + .flatMap(x -> Stream.of( | ||
128 | + ResourcePath.discrete(x.getKey().src().deviceId(), x.getKey().src().port(), x.getValue()), | ||
129 | + ResourcePath.discrete(x.getKey().dst().deviceId(), x.getKey().dst().port(), x.getValue()) | ||
130 | + )) | ||
131 | + .collect(Collectors.toSet()); | ||
126 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = | 132 | List<org.onosproject.net.newresource.ResourceAllocation> allocations = |
127 | - resourceService.allocate(intent.id(), resources); | 133 | + resourceService.allocate(intent.id(), ImmutableList.copyOf(resources)); |
128 | if (allocations.isEmpty()) { | 134 | if (allocations.isEmpty()) { |
129 | Collections.emptyMap(); | 135 | Collections.emptyMap(); |
130 | } | 136 | } |
... | @@ -135,20 +141,23 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { | ... | @@ -135,20 +141,23 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { |
135 | private Map<LinkKey, MplsLabel> findMplsLabels(Set<LinkKey> links) { | 141 | private Map<LinkKey, MplsLabel> findMplsLabels(Set<LinkKey> links) { |
136 | Map<LinkKey, MplsLabel> labels = new HashMap<>(); | 142 | Map<LinkKey, MplsLabel> labels = new HashMap<>(); |
137 | for (LinkKey link : links) { | 143 | for (LinkKey link : links) { |
138 | - Optional<MplsLabel> label = findMplsLabel(link); | 144 | + Set<MplsLabel> forward = findMplsLabel(link.src()); |
139 | - if (label.isPresent()) { | 145 | + Set<MplsLabel> backward = findMplsLabel(link.dst()); |
140 | - labels.put(link, label.get()); | 146 | + Set<MplsLabel> common = Sets.intersection(forward, backward); |
147 | + if (common.isEmpty()) { | ||
148 | + continue; | ||
141 | } | 149 | } |
150 | + labels.put(link, common.iterator().next()); | ||
142 | } | 151 | } |
143 | 152 | ||
144 | return labels; | 153 | return labels; |
145 | } | 154 | } |
146 | 155 | ||
147 | - private Optional<MplsLabel> findMplsLabel(LinkKey link) { | 156 | + private Set<MplsLabel> findMplsLabel(ConnectPoint cp) { |
148 | - return resourceService.getAvailableResources(ResourcePath.discrete(link)).stream() | 157 | + return resourceService.getAvailableResources(ResourcePath.discrete(cp.deviceId(), cp.port())).stream() |
149 | .filter(x -> x.last() instanceof MplsLabel) | 158 | .filter(x -> x.last() instanceof MplsLabel) |
150 | .map(x -> (MplsLabel) x.last()) | 159 | .map(x -> (MplsLabel) x.last()) |
151 | - .findFirst(); | 160 | + .collect(Collectors.toSet()); |
152 | } | 161 | } |
153 | 162 | ||
154 | private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) { | 163 | private MplsLabel getMplsLabel(Map<LinkKey, MplsLabel> labels, LinkKey link) { | ... | ... |
... | @@ -57,9 +57,9 @@ import java.util.Collections; | ... | @@ -57,9 +57,9 @@ import java.util.Collections; |
57 | import java.util.List; | 57 | import java.util.List; |
58 | import java.util.Set; | 58 | import java.util.Set; |
59 | import java.util.stream.Collectors; | 59 | import java.util.stream.Collectors; |
60 | +import java.util.stream.Stream; | ||
60 | 61 | ||
61 | import static com.google.common.base.Preconditions.checkArgument; | 62 | import static com.google.common.base.Preconditions.checkArgument; |
62 | -import static org.onosproject.net.LinkKey.linkKey; | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. | 65 | * An intent compiler for {@link org.onosproject.net.intent.OpticalConnectivityIntent}. |
... | @@ -182,7 +182,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -182,7 +182,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
182 | 182 | ||
183 | IndexedLambda minLambda = findFirstLambda(lambdas); | 183 | IndexedLambda minLambda = findFirstLambda(lambdas); |
184 | List<ResourcePath> lambdaResources = path.links().stream() | 184 | List<ResourcePath> lambdaResources = path.links().stream() |
185 | - .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst()))) | 185 | + .flatMap(x -> Stream.of( |
186 | + ResourcePath.discrete(x.src().deviceId(), x.src().port()), | ||
187 | + ResourcePath.discrete(x.dst().deviceId(), x.dst().port()) | ||
188 | + )) | ||
186 | .map(x -> x.child(minLambda)) | 189 | .map(x -> x.child(minLambda)) |
187 | .collect(Collectors.toList()); | 190 | .collect(Collectors.toList()); |
188 | 191 | ||
... | @@ -197,7 +200,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical | ... | @@ -197,7 +200,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical |
197 | 200 | ||
198 | private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) { | 201 | private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) { |
199 | return links.stream() | 202 | return links.stream() |
200 | - .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst()))) | 203 | + .flatMap(x -> Stream.of( |
204 | + ResourcePath.discrete(x.src().deviceId(), x.src().port()), | ||
205 | + ResourcePath.discrete(x.dst().deviceId(), x.dst().port()) | ||
206 | + )) | ||
201 | .map(resourceService::getAvailableResources) | 207 | .map(resourceService::getAvailableResources) |
202 | .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda)) | 208 | .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda)) |
203 | .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last())) | 209 | .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last())) | ... | ... |
... | @@ -16,13 +16,22 @@ | ... | @@ -16,13 +16,22 @@ |
16 | package org.onosproject.net.newresource.impl; | 16 | package org.onosproject.net.newresource.impl; |
17 | 17 | ||
18 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
19 | +import org.onlab.packet.MplsLabel; | ||
20 | +import org.onlab.packet.VlanId; | ||
21 | +import org.onlab.util.ItemNotFoundException; | ||
19 | import org.onosproject.net.Device; | 22 | import org.onosproject.net.Device; |
23 | +import org.onosproject.net.DeviceId; | ||
20 | import org.onosproject.net.Port; | 24 | import org.onosproject.net.Port; |
21 | import org.onosproject.net.OchPort; | 25 | import org.onosproject.net.OchPort; |
26 | +import org.onosproject.net.PortNumber; | ||
22 | import org.onosproject.net.TributarySlot; | 27 | import org.onosproject.net.TributarySlot; |
23 | import org.onosproject.net.OduSignalType; | 28 | import org.onosproject.net.OduSignalType; |
29 | +import org.onosproject.net.behaviour.MplsQuery; | ||
30 | +import org.onosproject.net.behaviour.VlanQuery; | ||
24 | import org.onosproject.net.device.DeviceEvent; | 31 | import org.onosproject.net.device.DeviceEvent; |
25 | import org.onosproject.net.device.DeviceListener; | 32 | import org.onosproject.net.device.DeviceListener; |
33 | +import org.onosproject.net.driver.DriverHandler; | ||
34 | +import org.onosproject.net.driver.DriverService; | ||
26 | import org.onosproject.net.newresource.ResourceAdminService; | 35 | import org.onosproject.net.newresource.ResourceAdminService; |
27 | import org.onosproject.net.newresource.ResourcePath; | 36 | import org.onosproject.net.newresource.ResourcePath; |
28 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
... | @@ -42,12 +51,19 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -42,12 +51,19 @@ final class ResourceDeviceListener implements DeviceListener { |
42 | 51 | ||
43 | private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); | 52 | private static final Logger log = LoggerFactory.getLogger(ResourceDeviceListener.class); |
44 | 53 | ||
54 | + private static final int MAX_VLAN_ID = VlanId.MAX_VLAN; | ||
55 | + private static final List<VlanId> ENTIRE_VLAN_IDS = getEntireVlans(); | ||
56 | + | ||
57 | + private static final int MAX_MPLS_LABEL = 1048576; | ||
58 | + private static final List<MplsLabel> ENTIRE_MPLS_LABELS = getEntireMplsLabels(); | ||
59 | + | ||
45 | private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8; | 60 | private static final int TOTAL_ODU2_TRIBUTARY_SLOTS = 8; |
46 | private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80; | 61 | private static final int TOTAL_ODU4_TRIBUTARY_SLOTS = 80; |
47 | private static final List<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots(); | 62 | private static final List<TributarySlot> ENTIRE_ODU2_TRIBUTARY_SLOTS = getEntireOdu2TributarySlots(); |
48 | private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); | 63 | private static final List<TributarySlot> ENTIRE_ODU4_TRIBUTARY_SLOTS = getEntireOdu4TributarySlots(); |
49 | 64 | ||
50 | private final ResourceAdminService adminService; | 65 | private final ResourceAdminService adminService; |
66 | + private final DriverService driverService; | ||
51 | private final ExecutorService executor; | 67 | private final ExecutorService executor; |
52 | 68 | ||
53 | /** | 69 | /** |
... | @@ -56,8 +72,10 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -56,8 +72,10 @@ final class ResourceDeviceListener implements DeviceListener { |
56 | * @param adminService instance invoked to register resources | 72 | * @param adminService instance invoked to register resources |
57 | * @param executor executor used for processing resource registration | 73 | * @param executor executor used for processing resource registration |
58 | */ | 74 | */ |
59 | - ResourceDeviceListener(ResourceAdminService adminService, ExecutorService executor) { | 75 | + ResourceDeviceListener(ResourceAdminService adminService, DriverService driverService, |
76 | + ExecutorService executor) { | ||
60 | this.adminService = checkNotNull(adminService); | 77 | this.adminService = checkNotNull(adminService); |
78 | + this.driverService = checkNotNull(driverService); | ||
61 | this.executor = checkNotNull(executor); | 79 | this.executor = checkNotNull(executor); |
62 | } | 80 | } |
63 | 81 | ||
... | @@ -95,6 +113,18 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -95,6 +113,18 @@ final class ResourceDeviceListener implements DeviceListener { |
95 | executor.submit(() -> { | 113 | executor.submit(() -> { |
96 | adminService.registerResources(portPath); | 114 | adminService.registerResources(portPath); |
97 | 115 | ||
116 | + // for VLAN IDs | ||
117 | + if (isVlanEnabled(device.id(), port.number())) { | ||
118 | + adminService.registerResources(Lists.transform(ENTIRE_VLAN_IDS, portPath::child)); | ||
119 | + } | ||
120 | + | ||
121 | + // for MPLS labels | ||
122 | + if (isMplsEnabled(device.id(), port.number())) { | ||
123 | + adminService.registerResources(Lists.transform(ENTIRE_MPLS_LABELS, portPath::child)); | ||
124 | + } | ||
125 | + | ||
126 | + // for Tributary slots | ||
127 | + // TODO: need to define Behaviour to make a query about OCh port | ||
98 | switch (port.type()) { | 128 | switch (port.type()) { |
99 | case OCH: | 129 | case OCH: |
100 | // register ODU TributarySlots against the OCH port | 130 | // register ODU TributarySlots against the OCH port |
... | @@ -124,15 +154,55 @@ final class ResourceDeviceListener implements DeviceListener { | ... | @@ -124,15 +154,55 @@ final class ResourceDeviceListener implements DeviceListener { |
124 | executor.submit(() -> adminService.unregisterResources(resource)); | 154 | executor.submit(() -> adminService.unregisterResources(resource)); |
125 | } | 155 | } |
126 | 156 | ||
157 | + private boolean isVlanEnabled(DeviceId device, PortNumber port) { | ||
158 | + try { | ||
159 | + DriverHandler handler = driverService.createHandler(device); | ||
160 | + if (handler == null) { | ||
161 | + return false; | ||
162 | + } | ||
163 | + | ||
164 | + VlanQuery query = handler.behaviour(VlanQuery.class); | ||
165 | + return query != null && query.isEnabled(port); | ||
166 | + } catch (ItemNotFoundException e) { | ||
167 | + return false; | ||
168 | + } | ||
169 | + } | ||
170 | + | ||
171 | + private boolean isMplsEnabled(DeviceId device, PortNumber port) { | ||
172 | + try { | ||
173 | + DriverHandler handler = driverService.createHandler(device); | ||
174 | + if (handler == null) { | ||
175 | + return false; | ||
176 | + } | ||
177 | + | ||
178 | + MplsQuery query = handler.behaviour(MplsQuery.class); | ||
179 | + return query != null && query.isEnabled(port); | ||
180 | + } catch (ItemNotFoundException e) { | ||
181 | + return false; | ||
182 | + } | ||
183 | + } | ||
184 | + | ||
185 | + private static List<VlanId> getEntireVlans() { | ||
186 | + return IntStream.range(0, MAX_VLAN_ID) | ||
187 | + .mapToObj(x -> VlanId.vlanId((short) x)) | ||
188 | + .collect(Collectors.toList()); | ||
189 | + } | ||
190 | + | ||
191 | + private static List<MplsLabel> getEntireMplsLabels() { | ||
192 | + // potentially many objects are created | ||
193 | + return IntStream.range(0, MAX_MPLS_LABEL) | ||
194 | + .mapToObj(MplsLabel::mplsLabel) | ||
195 | + .collect(Collectors.toList()); | ||
196 | + } | ||
197 | + | ||
127 | private static List<TributarySlot> getEntireOdu2TributarySlots() { | 198 | private static List<TributarySlot> getEntireOdu2TributarySlots() { |
128 | return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS) | 199 | return IntStream.rangeClosed(1, TOTAL_ODU2_TRIBUTARY_SLOTS) |
129 | - .mapToObj(x -> TributarySlot.of(x)) | 200 | + .mapToObj(TributarySlot::of) |
130 | .collect(Collectors.toList()); | 201 | .collect(Collectors.toList()); |
131 | } | 202 | } |
132 | private static List<TributarySlot> getEntireOdu4TributarySlots() { | 203 | private static List<TributarySlot> getEntireOdu4TributarySlots() { |
133 | return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS) | 204 | return IntStream.rangeClosed(1, TOTAL_ODU4_TRIBUTARY_SLOTS) |
134 | - .mapToObj(x -> TributarySlot.of(x)) | 205 | + .mapToObj(TributarySlot::of) |
135 | .collect(Collectors.toList()); | 206 | .collect(Collectors.toList()); |
136 | } | 207 | } |
137 | - | ||
138 | } | 208 | } | ... | ... |
core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java
deleted
100644 → 0
1 | -/* | ||
2 | - * Copyright 2015 Open Networking Laboratory | ||
3 | - * | ||
4 | - * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | - * you may not use this file except in compliance with the License. | ||
6 | - * You may obtain a copy of the License at | ||
7 | - * | ||
8 | - * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | - * | ||
10 | - * Unless required by applicable law or agreed to in writing, software | ||
11 | - * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | - * See the License for the specific language governing permissions and | ||
14 | - * limitations under the License. | ||
15 | - */ | ||
16 | -package org.onosproject.net.newresource.impl; | ||
17 | - | ||
18 | -import com.google.common.collect.Lists; | ||
19 | -import org.onlab.packet.MplsLabel; | ||
20 | -import org.onlab.packet.VlanId; | ||
21 | -import org.onlab.util.ItemNotFoundException; | ||
22 | -import org.onosproject.net.ConnectPoint; | ||
23 | -import org.onosproject.net.Link; | ||
24 | -import org.onosproject.net.LinkKey; | ||
25 | -import org.onosproject.net.behaviour.MplsQuery; | ||
26 | -import org.onosproject.net.behaviour.VlanQuery; | ||
27 | -import org.onosproject.net.driver.DriverHandler; | ||
28 | -import org.onosproject.net.driver.DriverService; | ||
29 | -import org.onosproject.net.link.LinkEvent; | ||
30 | -import org.onosproject.net.link.LinkListener; | ||
31 | -import org.onosproject.net.newresource.ResourceAdminService; | ||
32 | -import org.onosproject.net.newresource.ResourcePath; | ||
33 | - | ||
34 | -import java.util.List; | ||
35 | -import java.util.concurrent.ExecutorService; | ||
36 | -import java.util.function.Predicate; | ||
37 | -import java.util.stream.Collectors; | ||
38 | -import java.util.stream.IntStream; | ||
39 | - | ||
40 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
41 | - | ||
42 | -/** | ||
43 | - * An implementation of LinkListener registering links as resources. | ||
44 | - */ | ||
45 | -final class ResourceLinkListener implements LinkListener { | ||
46 | - | ||
47 | - private static final int TOTAL_VLANS = 1024; | ||
48 | - private static final List<VlanId> ENTIRE_VLAN_IDS = getEntireVlans(); | ||
49 | - | ||
50 | - private static final int TOTAL_MPLS_LABELS = 1048576; | ||
51 | - private static final List<MplsLabel> ENTIRE_MPLS_LABELS = getEntireMplsLabels(); | ||
52 | - | ||
53 | - private final ResourceAdminService adminService; | ||
54 | - private final DriverService driverService; | ||
55 | - private final ExecutorService executor; | ||
56 | - | ||
57 | - /** | ||
58 | - * Creates an instance with the specified ResourceAdminService and ExecutorService. | ||
59 | - * | ||
60 | - * @param adminService instance invoked to register resources | ||
61 | - * @param driverService driver service instance | ||
62 | - * @param executor executor used for processing resource registration | ||
63 | - */ | ||
64 | - ResourceLinkListener(ResourceAdminService adminService, DriverService driverService, ExecutorService executor) { | ||
65 | - this.adminService = checkNotNull(adminService); | ||
66 | - this.driverService = checkNotNull(driverService); | ||
67 | - this.executor = checkNotNull(executor); | ||
68 | - } | ||
69 | - | ||
70 | - @Override | ||
71 | - public void event(LinkEvent event) { | ||
72 | - Link link = event.subject(); | ||
73 | - switch (event.type()) { | ||
74 | - case LINK_ADDED: | ||
75 | - registerLinkResource(link); | ||
76 | - break; | ||
77 | - case LINK_REMOVED: | ||
78 | - unregisterLinkResource(link); | ||
79 | - break; | ||
80 | - default: | ||
81 | - break; | ||
82 | - } | ||
83 | - } | ||
84 | - | ||
85 | - private void registerLinkResource(Link link) { | ||
86 | - executor.submit(() -> { | ||
87 | - // register the link | ||
88 | - LinkKey linkKey = LinkKey.linkKey(link); | ||
89 | - adminService.registerResources(ResourcePath.discrete(linkKey)); | ||
90 | - | ||
91 | - ResourcePath linkPath = ResourcePath.discrete(linkKey); | ||
92 | - // register VLAN IDs against the link | ||
93 | - if (isEnabled(link, this::isVlanEnabled)) { | ||
94 | - adminService.registerResources(Lists.transform(ENTIRE_VLAN_IDS, linkPath::child)); | ||
95 | - } | ||
96 | - | ||
97 | - // register MPLS labels against the link | ||
98 | - if (isEnabled(link, this::isMplsEnabled)) { | ||
99 | - adminService.registerResources(Lists.transform(ENTIRE_MPLS_LABELS, linkPath::child)); | ||
100 | - } | ||
101 | - }); | ||
102 | - } | ||
103 | - | ||
104 | - private void unregisterLinkResource(Link link) { | ||
105 | - LinkKey linkKey = LinkKey.linkKey(link); | ||
106 | - executor.submit(() -> adminService.unregisterResources(ResourcePath.discrete(linkKey))); | ||
107 | - } | ||
108 | - | ||
109 | - private boolean isEnabled(Link link, Predicate<ConnectPoint> predicate) { | ||
110 | - return predicate.test(link.src()) && predicate.test(link.dst()); | ||
111 | - } | ||
112 | - | ||
113 | - private boolean isVlanEnabled(ConnectPoint cp) { | ||
114 | - try { | ||
115 | - DriverHandler handler = driverService.createHandler(cp.deviceId()); | ||
116 | - if (handler == null) { | ||
117 | - return false; | ||
118 | - } | ||
119 | - | ||
120 | - VlanQuery query = handler.behaviour(VlanQuery.class); | ||
121 | - return query != null && query.isEnabled(cp.port()); | ||
122 | - } catch (ItemNotFoundException e) { | ||
123 | - return false; | ||
124 | - } | ||
125 | - } | ||
126 | - | ||
127 | - private boolean isMplsEnabled(ConnectPoint cp) { | ||
128 | - try { | ||
129 | - DriverHandler handler = driverService.createHandler(cp.deviceId()); | ||
130 | - if (handler == null) { | ||
131 | - return false; | ||
132 | - } | ||
133 | - | ||
134 | - MplsQuery query = handler.behaviour(MplsQuery.class); | ||
135 | - return query != null && query.isEnabled(cp.port()); | ||
136 | - } catch (ItemNotFoundException e) { | ||
137 | - return false; | ||
138 | - } | ||
139 | - } | ||
140 | - | ||
141 | - private static List<VlanId> getEntireVlans() { | ||
142 | - return IntStream.range(0, TOTAL_VLANS) | ||
143 | - .mapToObj(x -> VlanId.vlanId((short) x)) | ||
144 | - .collect(Collectors.toList()); | ||
145 | - } | ||
146 | - | ||
147 | - private static List<MplsLabel> getEntireMplsLabels() { | ||
148 | - // potentially many objects are created | ||
149 | - return IntStream.range(0, TOTAL_MPLS_LABELS) | ||
150 | - .mapToObj(MplsLabel::mplsLabel) | ||
151 | - .collect(Collectors.toList()); | ||
152 | - } | ||
153 | -} |
... | @@ -24,8 +24,6 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; | ... | @@ -24,8 +24,6 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; |
24 | import org.onosproject.net.device.DeviceListener; | 24 | import org.onosproject.net.device.DeviceListener; |
25 | import org.onosproject.net.device.DeviceService; | 25 | import org.onosproject.net.device.DeviceService; |
26 | import org.onosproject.net.driver.DriverService; | 26 | import org.onosproject.net.driver.DriverService; |
27 | -import org.onosproject.net.link.LinkListener; | ||
28 | -import org.onosproject.net.link.LinkService; | ||
29 | import org.onosproject.net.newresource.ResourceAdminService; | 27 | import org.onosproject.net.newresource.ResourceAdminService; |
30 | 28 | ||
31 | import java.util.concurrent.ExecutorService; | 29 | import java.util.concurrent.ExecutorService; |
... | @@ -49,25 +47,18 @@ public final class ResourceRegistrar { | ... | @@ -49,25 +47,18 @@ public final class ResourceRegistrar { |
49 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 47 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
50 | protected DeviceService deviceService; | 48 | protected DeviceService deviceService; |
51 | 49 | ||
52 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
53 | - protected LinkService linkService; | ||
54 | - | ||
55 | private DeviceListener deviceListener; | 50 | private DeviceListener deviceListener; |
56 | - private LinkListener linkListener; | ||
57 | private final ExecutorService executor = | 51 | private final ExecutorService executor = |
58 | Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); | 52 | Executors.newSingleThreadExecutor(groupedThreads("onos/resource", "registrar")); |
59 | 53 | ||
60 | @Activate | 54 | @Activate |
61 | public void activate() { | 55 | public void activate() { |
62 | - deviceListener = new ResourceDeviceListener(adminService, executor); | 56 | + deviceListener = new ResourceDeviceListener(adminService, driverService, executor); |
63 | deviceService.addListener(deviceListener); | 57 | deviceService.addListener(deviceListener); |
64 | - linkListener = new ResourceLinkListener(adminService, driverService, executor); | ||
65 | - linkService.addListener(linkListener); | ||
66 | } | 58 | } |
67 | 59 | ||
68 | @Deactivate | 60 | @Deactivate |
69 | public void deactivate() { | 61 | public void deactivate() { |
70 | deviceService.removeListener(deviceListener); | 62 | deviceService.removeListener(deviceListener); |
71 | - linkService.removeListener(linkListener); | ||
72 | } | 63 | } |
73 | } | 64 | } | ... | ... |
... | @@ -29,8 +29,10 @@ import org.onlab.junit.TestUtils.TestUtilsException; | ... | @@ -29,8 +29,10 @@ import org.onlab.junit.TestUtils.TestUtilsException; |
29 | import org.onosproject.core.IdGenerator; | 29 | import org.onosproject.core.IdGenerator; |
30 | import org.onosproject.event.Event; | 30 | import org.onosproject.event.Event; |
31 | import org.onosproject.net.Device; | 31 | import org.onosproject.net.Device; |
32 | +import org.onosproject.net.DeviceId; | ||
32 | import org.onosproject.net.Link; | 33 | import org.onosproject.net.Link; |
33 | import org.onosproject.net.NetworkResource; | 34 | import org.onosproject.net.NetworkResource; |
35 | +import org.onosproject.net.PortNumber; | ||
34 | import org.onosproject.net.device.DeviceEvent; | 36 | import org.onosproject.net.device.DeviceEvent; |
35 | import org.onosproject.net.device.DeviceListener; | 37 | import org.onosproject.net.device.DeviceListener; |
36 | import org.onosproject.net.intent.Intent; | 38 | import org.onosproject.net.intent.Intent; |
... | @@ -52,7 +54,6 @@ import static org.hamcrest.MatcherAssert.assertThat; | ... | @@ -52,7 +54,6 @@ import static org.hamcrest.MatcherAssert.assertThat; |
52 | import static org.hamcrest.Matchers.equalTo; | 54 | import static org.hamcrest.Matchers.equalTo; |
53 | import static org.hamcrest.Matchers.hasSize; | 55 | import static org.hamcrest.Matchers.hasSize; |
54 | import static org.hamcrest.Matchers.is; | 56 | import static org.hamcrest.Matchers.is; |
55 | -import static org.onosproject.net.LinkKey.linkKey; | ||
56 | import static org.onosproject.net.newresource.ResourceEvent.Type.*; | 57 | import static org.onosproject.net.newresource.ResourceEvent.Type.*; |
57 | import static org.onosproject.net.NetTestTools.APP_ID; | 58 | import static org.onosproject.net.NetTestTools.APP_ID; |
58 | import static org.onosproject.net.NetTestTools.device; | 59 | import static org.onosproject.net.NetTestTools.device; |
... | @@ -231,7 +232,7 @@ public class ObjectiveTrackerTest { | ... | @@ -231,7 +232,7 @@ public class ObjectiveTrackerTest { |
231 | @Test | 232 | @Test |
232 | public void testResourceEvent() throws Exception { | 233 | public void testResourceEvent() throws Exception { |
233 | ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, | 234 | ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, |
234 | - ResourcePath.discrete(linkKey(link("a", 1, "b", 1)))); | 235 | + ResourcePath.discrete(DeviceId.deviceId("a"), PortNumber.portNumber(1))); |
235 | resourceListener.event(event); | 236 | resourceListener.event(event); |
236 | 237 | ||
237 | assertThat( | 238 | assertThat( | ... | ... |
... | @@ -374,13 +374,13 @@ public class KryoSerializerTest { | ... | @@ -374,13 +374,13 @@ public class KryoSerializerTest { |
374 | 374 | ||
375 | @Test | 375 | @Test |
376 | public void testResourcePath() { | 376 | public void testResourcePath() { |
377 | - testSerializedEquals(ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1)); | 377 | + testSerializedEquals(ResourcePath.discrete(DID1, P1, VLAN1)); |
378 | } | 378 | } |
379 | 379 | ||
380 | @Test | 380 | @Test |
381 | public void testResourceAllocation() { | 381 | public void testResourceAllocation() { |
382 | testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( | 382 | testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( |
383 | - ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1), | 383 | + ResourcePath.discrete(DID1, P1, VLAN1), |
384 | IntentId.valueOf(30))); | 384 | IntentId.valueOf(30))); |
385 | } | 385 | } |
386 | 386 | ... | ... |
-
Please register or login to post a comment