Committed by
Gerrit Code Review
ONOS-2743: Register entire MPLS label space when a link is discovered
Change-Id: Ic57afa75bf57007e6bac2debef0c1a4d3515b0a9
Showing
1 changed file
with
37 additions
and
7 deletions
... | @@ -15,11 +15,13 @@ | ... | @@ -15,11 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.newresource.impl; | 16 | package org.onosproject.net.newresource.impl; |
17 | 17 | ||
18 | +import org.onlab.packet.MplsLabel; | ||
18 | import org.onlab.packet.VlanId; | 19 | import org.onlab.packet.VlanId; |
19 | import org.onlab.util.ItemNotFoundException; | 20 | import org.onlab.util.ItemNotFoundException; |
20 | import org.onosproject.net.ConnectPoint; | 21 | import org.onosproject.net.ConnectPoint; |
21 | import org.onosproject.net.Link; | 22 | import org.onosproject.net.Link; |
22 | import org.onosproject.net.LinkKey; | 23 | import org.onosproject.net.LinkKey; |
24 | +import org.onosproject.net.behaviour.MplsQuery; | ||
23 | import org.onosproject.net.behaviour.VlanQuery; | 25 | import org.onosproject.net.behaviour.VlanQuery; |
24 | import org.onosproject.net.driver.DriverHandler; | 26 | import org.onosproject.net.driver.DriverHandler; |
25 | import org.onosproject.net.driver.DriverService; | 27 | import org.onosproject.net.driver.DriverService; |
... | @@ -30,6 +32,7 @@ import org.onosproject.net.newresource.ResourcePath; | ... | @@ -30,6 +32,7 @@ import org.onosproject.net.newresource.ResourcePath; |
30 | 32 | ||
31 | import java.util.List; | 33 | import java.util.List; |
32 | import java.util.concurrent.ExecutorService; | 34 | import java.util.concurrent.ExecutorService; |
35 | +import java.util.function.Predicate; | ||
33 | import java.util.stream.Collectors; | 36 | import java.util.stream.Collectors; |
34 | import java.util.stream.IntStream; | 37 | import java.util.stream.IntStream; |
35 | 38 | ||
... | @@ -43,6 +46,9 @@ final class ResourceLinkListener implements LinkListener { | ... | @@ -43,6 +46,9 @@ final class ResourceLinkListener implements LinkListener { |
43 | private static final int TOTAL_VLANS = 1024; | 46 | private static final int TOTAL_VLANS = 1024; |
44 | private static final List<VlanId> ENTIRE_VLAN_IDS = getEntireVlans(); | 47 | private static final List<VlanId> ENTIRE_VLAN_IDS = getEntireVlans(); |
45 | 48 | ||
49 | + private static final int TOTAL_MPLS_LABELS = 1048576; | ||
50 | + private static final List<MplsLabel> ENTIRE_MPLS_LABELS = getEntireMplsLabels(); | ||
51 | + | ||
46 | private final ResourceAdminService adminService; | 52 | private final ResourceAdminService adminService; |
47 | private final DriverService driverService; | 53 | private final DriverService driverService; |
48 | private final ExecutorService executor; | 54 | private final ExecutorService executor; |
... | @@ -80,9 +86,15 @@ final class ResourceLinkListener implements LinkListener { | ... | @@ -80,9 +86,15 @@ final class ResourceLinkListener implements LinkListener { |
80 | LinkKey linkKey = LinkKey.linkKey(link); | 86 | LinkKey linkKey = LinkKey.linkKey(link); |
81 | adminService.registerResources(ResourcePath.ROOT, linkKey); | 87 | adminService.registerResources(ResourcePath.ROOT, linkKey); |
82 | 88 | ||
89 | + ResourcePath linkPath = new ResourcePath(linkKey); | ||
83 | // register VLAN IDs against the link | 90 | // register VLAN IDs against the link |
84 | - if (isVlanEnabled(link)) { | 91 | + if (isEnabled(link, this::isVlanEnabled)) { |
85 | - adminService.registerResources(new ResourcePath(linkKey), ENTIRE_VLAN_IDS); | 92 | + adminService.registerResources(linkPath, ENTIRE_VLAN_IDS); |
93 | + } | ||
94 | + | ||
95 | + // register MPLS labels against the link | ||
96 | + if (isEnabled(link, this::isMplsEnabled)) { | ||
97 | + adminService.registerResources(linkPath, ENTIRE_MPLS_LABELS); | ||
86 | } | 98 | } |
87 | }); | 99 | }); |
88 | } | 100 | } |
... | @@ -92,11 +104,8 @@ final class ResourceLinkListener implements LinkListener { | ... | @@ -92,11 +104,8 @@ final class ResourceLinkListener implements LinkListener { |
92 | executor.submit(() -> adminService.unregisterResources(ResourcePath.ROOT, linkKey)); | 104 | executor.submit(() -> adminService.unregisterResources(ResourcePath.ROOT, linkKey)); |
93 | } | 105 | } |
94 | 106 | ||
95 | - private boolean isVlanEnabled(Link link) { | 107 | + private boolean isEnabled(Link link, Predicate<ConnectPoint> predicate) { |
96 | - ConnectPoint src = link.src(); | 108 | + return predicate.test(link.src()) && predicate.test(link.dst()); |
97 | - ConnectPoint dst = link.dst(); | ||
98 | - | ||
99 | - return isVlanEnabled(src) && isVlanEnabled(dst); | ||
100 | } | 109 | } |
101 | 110 | ||
102 | private boolean isVlanEnabled(ConnectPoint cp) { | 111 | private boolean isVlanEnabled(ConnectPoint cp) { |
... | @@ -113,9 +122,30 @@ final class ResourceLinkListener implements LinkListener { | ... | @@ -113,9 +122,30 @@ final class ResourceLinkListener implements LinkListener { |
113 | } | 122 | } |
114 | } | 123 | } |
115 | 124 | ||
125 | + private boolean isMplsEnabled(ConnectPoint cp) { | ||
126 | + try { | ||
127 | + DriverHandler handler = driverService.createHandler(cp.deviceId()); | ||
128 | + if (handler == null) { | ||
129 | + return false; | ||
130 | + } | ||
131 | + | ||
132 | + MplsQuery query = handler.behaviour(MplsQuery.class); | ||
133 | + return query != null && query.isEnabled(cp.port()); | ||
134 | + } catch (ItemNotFoundException e) { | ||
135 | + return false; | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
116 | private static List<VlanId> getEntireVlans() { | 139 | private static List<VlanId> getEntireVlans() { |
117 | return IntStream.range(0, TOTAL_VLANS) | 140 | return IntStream.range(0, TOTAL_VLANS) |
118 | .mapToObj(x -> VlanId.vlanId((short) x)) | 141 | .mapToObj(x -> VlanId.vlanId((short) x)) |
119 | .collect(Collectors.toList()); | 142 | .collect(Collectors.toList()); |
120 | } | 143 | } |
144 | + | ||
145 | + private static List<MplsLabel> getEntireMplsLabels() { | ||
146 | + // potentially many objects are created | ||
147 | + return IntStream.range(0, TOTAL_MPLS_LABELS) | ||
148 | + .mapToObj(MplsLabel::mplsLabel) | ||
149 | + .collect(Collectors.toList()); | ||
150 | + } | ||
121 | } | 151 | } | ... | ... |
-
Please register or login to post a comment