Committed by
Gerrit Code Review
ONOS- 2946 Adding ability to view existing packet intercept requests and packet processors.
Change-Id: Id0d82fb4a19506ec607a71856dbf0c33c8e51baf
Showing
10 changed files
with
179 additions
and
19 deletions
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.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Command; | ||
19 | +import org.onosproject.cli.AbstractShellCommand; | ||
20 | +import org.onosproject.net.packet.PacketProcessor; | ||
21 | +import org.onosproject.net.packet.PacketService; | ||
22 | + | ||
23 | +import static org.onosproject.net.packet.PacketProcessor.ADVISOR_MAX; | ||
24 | +import static org.onosproject.net.packet.PacketProcessor.DIRECTOR_MAX; | ||
25 | + | ||
26 | +/** | ||
27 | + * Lists packet processors. | ||
28 | + */ | ||
29 | +@Command(scope = "onos", name = "packet-processors", | ||
30 | + description = "Lists packet processors") | ||
31 | +public class PacketProcessorsListCommand extends AbstractShellCommand { | ||
32 | + | ||
33 | + private static final String FMT = "priority=%s, class=%s"; | ||
34 | + | ||
35 | + @Override | ||
36 | + protected void execute() { | ||
37 | + PacketService service = get(PacketService.class); | ||
38 | + if (outputJson()) { | ||
39 | + // TODO: implement this | ||
40 | + print("Not implemented."); | ||
41 | + } else { | ||
42 | + service.getProcessors().forEach(this::print); | ||
43 | + } | ||
44 | + } | ||
45 | + | ||
46 | + private void print(int priority, PacketProcessor processor) { | ||
47 | + print(FMT, priorityFormat(priority), processor.getClass().getName()); | ||
48 | + } | ||
49 | + | ||
50 | + private String priorityFormat(int priority) { | ||
51 | + if (priority > DIRECTOR_MAX) { | ||
52 | + return "observer(" + (priority - DIRECTOR_MAX - 1) + ")"; | ||
53 | + } else if (priority > ADVISOR_MAX) { | ||
54 | + return "director(" + (priority - ADVISOR_MAX - 1) + ")"; | ||
55 | + } | ||
56 | + return "advisor(" + (priority - 1) + ")"; | ||
57 | + } | ||
58 | + | ||
59 | +} |
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.cli.net; | ||
17 | + | ||
18 | +import org.apache.karaf.shell.commands.Command; | ||
19 | +import org.onosproject.cli.AbstractShellCommand; | ||
20 | +import org.onosproject.net.packet.PacketRequest; | ||
21 | +import org.onosproject.net.packet.PacketService; | ||
22 | + | ||
23 | +/** | ||
24 | + * Lists packet requests. | ||
25 | + */ | ||
26 | +@Command(scope = "onos", name = "packet-requests", | ||
27 | + description = "Lists packet requests") | ||
28 | +public class PacketRequestsListCommand extends AbstractShellCommand { | ||
29 | + | ||
30 | + private static final String FMT = "priority=%s, appId=%s, criteria=%s"; | ||
31 | + | ||
32 | + @Override | ||
33 | + protected void execute() { | ||
34 | + PacketService service = get(PacketService.class); | ||
35 | + if (outputJson()) { | ||
36 | + // TODO: implement this | ||
37 | + print("Not implemented."); | ||
38 | + } else { | ||
39 | + service.getRequests().forEach(this::print); | ||
40 | + } | ||
41 | + } | ||
42 | + | ||
43 | + private void print(PacketRequest request) { | ||
44 | + print(FMT, request.priority(), request.appId().name(), request.selector().criteria()); | ||
45 | + } | ||
46 | + | ||
47 | +} |
... | @@ -351,6 +351,13 @@ | ... | @@ -351,6 +351,13 @@ |
351 | </command> | 351 | </command> |
352 | 352 | ||
353 | <command> | 353 | <command> |
354 | + <action class="org.onosproject.cli.net.PacketRequestsListCommand"/> | ||
355 | + </command> | ||
356 | + <command> | ||
357 | + <action class="org.onosproject.cli.net.PacketProcessorsListCommand"/> | ||
358 | + </command> | ||
359 | + | ||
360 | + <command> | ||
354 | <action class="org.onosproject.cli.net.AddTestFlowsCommand"/> | 361 | <action class="org.onosproject.cli.net.AddTestFlowsCommand"/> |
355 | </command> | 362 | </command> |
356 | <command> | 363 | <command> | ... | ... |
... | @@ -24,7 +24,7 @@ public interface PacketProcessor { | ... | @@ -24,7 +24,7 @@ public interface PacketProcessor { |
24 | 24 | ||
25 | int ADVISOR_MAX = Integer.MAX_VALUE / 3; | 25 | int ADVISOR_MAX = Integer.MAX_VALUE / 3; |
26 | int DIRECTOR_MAX = (Integer.MAX_VALUE / 3) * 2; | 26 | int DIRECTOR_MAX = (Integer.MAX_VALUE / 3) * 2; |
27 | - static final int OBSERVER_MAX = Integer.MAX_VALUE; | 27 | + int OBSERVER_MAX = Integer.MAX_VALUE; |
28 | 28 | ||
29 | /** | 29 | /** |
30 | * Returns a priority in the ADVISOR range, where processors can take early action and | 30 | * Returns a priority in the ADVISOR range, where processors can take early action and |
... | @@ -38,7 +38,7 @@ public interface PacketProcessor { | ... | @@ -38,7 +38,7 @@ public interface PacketProcessor { |
38 | static int advisor(int priority) { | 38 | static int advisor(int priority) { |
39 | int overallPriority = priority + 1; | 39 | int overallPriority = priority + 1; |
40 | checkArgument(overallPriority > 0 && overallPriority <= ADVISOR_MAX, | 40 | checkArgument(overallPriority > 0 && overallPriority <= ADVISOR_MAX, |
41 | - "Priority not within ADVISOR range"); | 41 | + "Priority not within ADVISOR range"); |
42 | return overallPriority; | 42 | return overallPriority; |
43 | } | 43 | } |
44 | 44 | ||
... | @@ -53,7 +53,7 @@ public interface PacketProcessor { | ... | @@ -53,7 +53,7 @@ public interface PacketProcessor { |
53 | static int director(int priority) { | 53 | static int director(int priority) { |
54 | int overallPriority = ADVISOR_MAX + priority + 1; | 54 | int overallPriority = ADVISOR_MAX + priority + 1; |
55 | checkArgument(overallPriority > ADVISOR_MAX && overallPriority <= DIRECTOR_MAX, | 55 | checkArgument(overallPriority > ADVISOR_MAX && overallPriority <= DIRECTOR_MAX, |
56 | - "Priority not within DIRECTOR range"); | 56 | + "Priority not within DIRECTOR range"); |
57 | return overallPriority; | 57 | return overallPriority; |
58 | } | 58 | } |
59 | 59 | ||
... | @@ -68,8 +68,8 @@ public interface PacketProcessor { | ... | @@ -68,8 +68,8 @@ public interface PacketProcessor { |
68 | */ | 68 | */ |
69 | static int observer(int priority) { | 69 | static int observer(int priority) { |
70 | int overallPriority = DIRECTOR_MAX + priority + 1; | 70 | int overallPriority = DIRECTOR_MAX + priority + 1; |
71 | - checkArgument(overallPriority > DIRECTOR_MAX && overallPriority <= OBSERVER_MAX, | 71 | + checkArgument(overallPriority > DIRECTOR_MAX, |
72 | - "Priority not within OBSERVER range"); | 72 | + "Priority not within OBSERVER range"); |
73 | return overallPriority; | 73 | return overallPriority; |
74 | } | 74 | } |
75 | 75 | ... | ... |
... | @@ -15,9 +15,13 @@ | ... | @@ -15,9 +15,13 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.packet; | 16 | package org.onosproject.net.packet; |
17 | 17 | ||
18 | +import com.google.common.annotations.Beta; | ||
18 | import org.onosproject.core.ApplicationId; | 19 | import org.onosproject.core.ApplicationId; |
19 | import org.onosproject.net.flow.TrafficSelector; | 20 | import org.onosproject.net.flow.TrafficSelector; |
20 | 21 | ||
22 | +import java.util.List; | ||
23 | +import java.util.Map; | ||
24 | + | ||
21 | /** | 25 | /** |
22 | * Service for intercepting data plane packets and for emitting synthetic | 26 | * Service for intercepting data plane packets and for emitting synthetic |
23 | * outbound packets. | 27 | * outbound packets. |
... | @@ -48,6 +52,15 @@ public interface PacketService { | ... | @@ -48,6 +52,15 @@ public interface PacketService { |
48 | void removeProcessor(PacketProcessor processor); | 52 | void removeProcessor(PacketProcessor processor); |
49 | 53 | ||
50 | /** | 54 | /** |
55 | + * Returns priority bindings of all registered packet processors. | ||
56 | + * | ||
57 | + * @return list of existing packet processors | ||
58 | + */ | ||
59 | + @Beta | ||
60 | + // TODO: Consider returning list of PacketProcessorEntry with processor, priority and stats | ||
61 | + Map<Integer, PacketProcessor> getProcessors(); | ||
62 | + | ||
63 | + /** | ||
51 | * Requests that packets matching the given selector are punted from the | 64 | * Requests that packets matching the given selector are punted from the |
52 | * dataplane to the controller. | 65 | * dataplane to the controller. |
53 | * | 66 | * |
... | @@ -70,6 +83,13 @@ public interface PacketService { | ... | @@ -70,6 +83,13 @@ public interface PacketService { |
70 | ApplicationId appId); | 83 | ApplicationId appId); |
71 | 84 | ||
72 | /** | 85 | /** |
86 | + * Returns list of all existing requests ordered by priority. | ||
87 | + * | ||
88 | + * @return list of existing packet requests | ||
89 | + */ | ||
90 | + List<PacketRequest> getRequests(); | ||
91 | + | ||
92 | + /** | ||
73 | * Emits the specified outbound packet onto the network. | 93 | * Emits the specified outbound packet onto the network. |
74 | * | 94 | * |
75 | * @param packet outbound packet | 95 | * @param packet outbound packet | ... | ... |
... | @@ -17,7 +17,7 @@ package org.onosproject.net.packet; | ... | @@ -17,7 +17,7 @@ package org.onosproject.net.packet; |
17 | 17 | ||
18 | import org.onosproject.store.Store; | 18 | import org.onosproject.store.Store; |
19 | 19 | ||
20 | -import java.util.Set; | 20 | +import java.util.List; |
21 | 21 | ||
22 | /** | 22 | /** |
23 | * Manages routing of outbound packets. | 23 | * Manages routing of outbound packets. |
... | @@ -52,8 +52,8 @@ public interface PacketStore extends Store<PacketEvent, PacketStoreDelegate> { | ... | @@ -52,8 +52,8 @@ public interface PacketStore extends Store<PacketEvent, PacketStoreDelegate> { |
52 | /** | 52 | /** |
53 | * Obtains all existing requests in the system. | 53 | * Obtains all existing requests in the system. |
54 | * | 54 | * |
55 | - * @return a set of packet requests | 55 | + * @return list of packet requests in order of priority |
56 | */ | 56 | */ |
57 | - Set<PacketRequest> existingRequests(); | 57 | + List<PacketRequest> existingRequests(); |
58 | 58 | ||
59 | } | 59 | } | ... | ... |
... | @@ -18,6 +18,9 @@ package org.onosproject.net.packet; | ... | @@ -18,6 +18,9 @@ package org.onosproject.net.packet; |
18 | import org.onosproject.core.ApplicationId; | 18 | import org.onosproject.core.ApplicationId; |
19 | import org.onosproject.net.flow.TrafficSelector; | 19 | import org.onosproject.net.flow.TrafficSelector; |
20 | 20 | ||
21 | +import java.util.List; | ||
22 | +import java.util.Map; | ||
23 | + | ||
21 | /** | 24 | /** |
22 | * Test adapter for packet service. | 25 | * Test adapter for packet service. |
23 | */ | 26 | */ |
... | @@ -31,6 +34,16 @@ public class PacketServiceAdapter implements PacketService { | ... | @@ -31,6 +34,16 @@ public class PacketServiceAdapter implements PacketService { |
31 | } | 34 | } |
32 | 35 | ||
33 | @Override | 36 | @Override |
37 | + public Map<Integer, PacketProcessor> getProcessors() { | ||
38 | + return null; | ||
39 | + } | ||
40 | + | ||
41 | + @Override | ||
42 | + public List<PacketRequest> getRequests() { | ||
43 | + return null; | ||
44 | + } | ||
45 | + | ||
46 | + @Override | ||
34 | public void requestPackets(TrafficSelector selector, PacketPriority priority, ApplicationId appId) { | 47 | public void requestPackets(TrafficSelector selector, PacketPriority priority, ApplicationId appId) { |
35 | } | 48 | } |
36 | 49 | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.trivial; | 16 | package org.onosproject.store.trivial; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableList; | ||
18 | import com.google.common.collect.Sets; | 19 | import com.google.common.collect.Sets; |
19 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Service; | 21 | import org.apache.felix.scr.annotations.Service; |
... | @@ -26,8 +27,7 @@ import org.onosproject.net.packet.PacketStore; | ... | @@ -26,8 +27,7 @@ import org.onosproject.net.packet.PacketStore; |
26 | import org.onosproject.net.packet.PacketStoreDelegate; | 27 | import org.onosproject.net.packet.PacketStoreDelegate; |
27 | import org.onosproject.store.AbstractStore; | 28 | import org.onosproject.store.AbstractStore; |
28 | 29 | ||
29 | - | 30 | +import java.util.List; |
30 | -import java.util.Collections; | ||
31 | import java.util.Set; | 31 | import java.util.Set; |
32 | 32 | ||
33 | /** | 33 | /** |
... | @@ -57,8 +57,8 @@ public class SimplePacketStore | ... | @@ -57,8 +57,8 @@ public class SimplePacketStore |
57 | } | 57 | } |
58 | 58 | ||
59 | @Override | 59 | @Override |
60 | - public Set<PacketRequest> existingRequests() { | 60 | + public List<PacketRequest> existingRequests() { |
61 | - return Collections.unmodifiableSet(requests); | 61 | + return ImmutableList.copyOf(requests); |
62 | } | 62 | } |
63 | 63 | ||
64 | } | 64 | } | ... | ... |
... | @@ -15,6 +15,7 @@ | ... | @@ -15,6 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.packet.impl; | 16 | package org.onosproject.net.packet.impl; |
17 | 17 | ||
18 | +import com.google.common.collect.ImmutableMap; | ||
18 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
19 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -53,6 +54,7 @@ import org.onosproject.net.provider.AbstractProviderRegistry; | ... | @@ -53,6 +54,7 @@ import org.onosproject.net.provider.AbstractProviderRegistry; |
53 | import org.onosproject.net.provider.AbstractProviderService; | 54 | import org.onosproject.net.provider.AbstractProviderService; |
54 | import org.slf4j.Logger; | 55 | import org.slf4j.Logger; |
55 | 56 | ||
57 | +import java.util.List; | ||
56 | import java.util.Map; | 58 | import java.util.Map; |
57 | import java.util.concurrent.ConcurrentHashMap; | 59 | import java.util.concurrent.ConcurrentHashMap; |
58 | import java.util.concurrent.ExecutorService; | 60 | import java.util.concurrent.ExecutorService; |
... | @@ -61,8 +63,8 @@ import java.util.concurrent.Executors; | ... | @@ -61,8 +63,8 @@ import java.util.concurrent.Executors; |
61 | import static com.google.common.base.Preconditions.checkNotNull; | 63 | import static com.google.common.base.Preconditions.checkNotNull; |
62 | import static org.onlab.util.Tools.groupedThreads; | 64 | import static org.onlab.util.Tools.groupedThreads; |
63 | import static org.onosproject.security.AppGuard.checkPermission; | 65 | import static org.onosproject.security.AppGuard.checkPermission; |
64 | -import static org.slf4j.LoggerFactory.getLogger; | ||
65 | import static org.onosproject.security.AppPermission.Type.*; | 66 | import static org.onosproject.security.AppPermission.Type.*; |
67 | +import static org.slf4j.LoggerFactory.getLogger; | ||
66 | 68 | ||
67 | /** | 69 | /** |
68 | * Provides a basic implementation of the packet SB & NB APIs. | 70 | * Provides a basic implementation of the packet SB & NB APIs. |
... | @@ -138,6 +140,11 @@ public class PacketManager | ... | @@ -138,6 +140,11 @@ public class PacketManager |
138 | } | 140 | } |
139 | 141 | ||
140 | @Override | 142 | @Override |
143 | + public Map<Integer, PacketProcessor> getProcessors() { | ||
144 | + return ImmutableMap.copyOf(processors); | ||
145 | + } | ||
146 | + | ||
147 | + @Override | ||
141 | public void requestPackets(TrafficSelector selector, PacketPriority priority, | 148 | public void requestPackets(TrafficSelector selector, PacketPriority priority, |
142 | ApplicationId appId) { | 149 | ApplicationId appId) { |
143 | checkPermission(PACKET_READ); | 150 | checkPermission(PACKET_READ); |
... | @@ -163,6 +170,11 @@ public class PacketManager | ... | @@ -163,6 +170,11 @@ public class PacketManager |
163 | } | 170 | } |
164 | } | 171 | } |
165 | 172 | ||
173 | + @Override | ||
174 | + public List<PacketRequest> getRequests() { | ||
175 | + return store.existingRequests(); | ||
176 | + } | ||
177 | + | ||
166 | /** | 178 | /** |
167 | * Pushes a packet request flow rule to all devices. | 179 | * Pushes a packet request flow rule to all devices. |
168 | * | 180 | * | ... | ... |
... | @@ -15,7 +15,7 @@ | ... | @@ -15,7 +15,7 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.packet.impl; | 16 | package org.onosproject.store.packet.impl; |
17 | 17 | ||
18 | -import com.google.common.collect.ImmutableSet; | 18 | +import com.google.common.collect.Lists; |
19 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
20 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
21 | import org.apache.felix.scr.annotations.Deactivate; | 21 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -45,6 +45,7 @@ import org.onosproject.store.service.Versioned; | ... | @@ -45,6 +45,7 @@ import org.onosproject.store.service.Versioned; |
45 | import org.slf4j.Logger; | 45 | import org.slf4j.Logger; |
46 | 46 | ||
47 | import java.util.HashSet; | 47 | import java.util.HashSet; |
48 | +import java.util.List; | ||
48 | import java.util.Set; | 49 | import java.util.Set; |
49 | import java.util.concurrent.ExecutorService; | 50 | import java.util.concurrent.ExecutorService; |
50 | import java.util.concurrent.Executors; | 51 | import java.util.concurrent.Executors; |
... | @@ -152,7 +153,7 @@ public class DistributedPacketStore | ... | @@ -152,7 +153,7 @@ public class DistributedPacketStore |
152 | } | 153 | } |
153 | 154 | ||
154 | @Override | 155 | @Override |
155 | - public Set<PacketRequest> existingRequests() { | 156 | + public List<PacketRequest> existingRequests() { |
156 | return tracker.requests(); | 157 | return tracker.requests(); |
157 | } | 158 | } |
158 | 159 | ||
... | @@ -197,10 +198,11 @@ public class DistributedPacketStore | ... | @@ -197,10 +198,11 @@ public class DistributedPacketStore |
197 | return requests.replace(request.selector(), old.version(), newSet); | 198 | return requests.replace(request.selector(), old.version(), newSet); |
198 | } | 199 | } |
199 | 200 | ||
200 | - public Set<PacketRequest> requests() { | 201 | + public List<PacketRequest> requests() { |
201 | - ImmutableSet.Builder<PacketRequest> builder = ImmutableSet.builder(); | 202 | + List<PacketRequest> list = Lists.newArrayList(); |
202 | - requests.values().forEach(v -> builder.addAll(v.value())); | 203 | + requests.values().forEach(v -> list.addAll(v.value())); |
203 | - return builder.build(); | 204 | + list.sort((o1, o2) -> o1.priority().priorityValue() - o2.priority().priorityValue()); |
205 | + return list; | ||
204 | } | 206 | } |
205 | 207 | ||
206 | } | 208 | } | ... | ... |
-
Please register or login to post a comment