Showing
5 changed files
with
119 additions
and
7 deletions
1 | +/* | ||
2 | + * Licensed to the Apache Software Foundation (ASF) under one | ||
3 | + * or more contributor license agreements. See the NOTICE file | ||
4 | + * distributed with this work for additional information | ||
5 | + * regarding copyright ownership. The ASF licenses this file | ||
6 | + * to you under the Apache License, Version 2.0 (the | ||
7 | + * "License"); you may not use this file except in compliance | ||
8 | + * with the License. You may obtain a copy of the License at | ||
9 | + * | ||
10 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
11 | + * | ||
12 | + * Unless required by applicable law or agreed to in writing, | ||
13 | + * software distributed under the License is distributed on an | ||
14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
15 | + * KIND, either express or implied. See the License for the | ||
16 | + * specific language governing permissions and limitations | ||
17 | + * under the License. | ||
18 | + */ | ||
19 | +package org.onlab.onos.cli.net; | ||
20 | + | ||
21 | +import org.apache.karaf.shell.commands.Argument; | ||
22 | +import org.apache.karaf.shell.commands.Command; | ||
23 | +import org.onlab.onos.cli.AbstractShellCommand; | ||
24 | +import org.onlab.onos.net.ConnectPoint; | ||
25 | +import org.onlab.onos.net.DeviceId; | ||
26 | +import org.onlab.onos.net.PortNumber; | ||
27 | + | ||
28 | +import org.onlab.onos.net.statistic.Load; | ||
29 | +import org.onlab.onos.net.statistic.StatisticService; | ||
30 | + | ||
31 | + | ||
32 | +import static org.onlab.onos.net.DeviceId.deviceId; | ||
33 | +import static org.onlab.onos.net.PortNumber.portNumber; | ||
34 | + | ||
35 | +/** | ||
36 | + * Fetches statistics. | ||
37 | + */ | ||
38 | +@Command(scope = "onos", name = "get-stats", | ||
39 | + description = "Fetches stats for a connection point") | ||
40 | +public class GetStatistics extends AbstractShellCommand { | ||
41 | + | ||
42 | + @Argument(index = 0, name = "connectPoint", | ||
43 | + description = "Device/Port Description", | ||
44 | + required = true, multiValued = false) | ||
45 | + String connectPoint = null; | ||
46 | + | ||
47 | + | ||
48 | + @Override | ||
49 | + protected void execute() { | ||
50 | + StatisticService service = get(StatisticService.class); | ||
51 | + | ||
52 | + DeviceId ingressDeviceId = deviceId(getDeviceId(connectPoint)); | ||
53 | + PortNumber ingressPortNumber = portNumber(getPortNumber(connectPoint)); | ||
54 | + ConnectPoint cp = new ConnectPoint(ingressDeviceId, ingressPortNumber); | ||
55 | + | ||
56 | + Load load = service.load(cp); | ||
57 | + | ||
58 | + print("Load on %s -> %s", cp, load); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Extracts the port number portion of the ConnectPoint. | ||
63 | + * | ||
64 | + * @param deviceString string representing the device/port | ||
65 | + * @return port number as a string, empty string if the port is not found | ||
66 | + */ | ||
67 | + private String getPortNumber(String deviceString) { | ||
68 | + int slash = deviceString.indexOf('/'); | ||
69 | + if (slash <= 0) { | ||
70 | + return ""; | ||
71 | + } | ||
72 | + return deviceString.substring(slash + 1, deviceString.length()); | ||
73 | + } | ||
74 | + | ||
75 | + /** | ||
76 | + * Extracts the device ID portion of the ConnectPoint. | ||
77 | + * | ||
78 | + * @param deviceString string representing the device/port | ||
79 | + * @return device ID string | ||
80 | + */ | ||
81 | + private String getDeviceId(String deviceString) { | ||
82 | + int slash = deviceString.indexOf('/'); | ||
83 | + if (slash <= 0) { | ||
84 | + return ""; | ||
85 | + } | ||
86 | + return deviceString.substring(0, slash); | ||
87 | + } | ||
88 | +} |
... | @@ -119,6 +119,12 @@ | ... | @@ -119,6 +119,12 @@ |
119 | </optional-completers> | 119 | </optional-completers> |
120 | </command> | 120 | </command> |
121 | <command> | 121 | <command> |
122 | + <action class="org.onlab.onos.cli.net.GetStatistics"/> | ||
123 | + <completers> | ||
124 | + <ref component-id="connectPointCompleter"/> | ||
125 | + </completers> | ||
126 | + </command> | ||
127 | + <command> | ||
122 | <action class="org.onlab.onos.cli.net.AddMultiPointToSinglePointIntentCommand"/> | 128 | <action class="org.onlab.onos.cli.net.AddMultiPointToSinglePointIntentCommand"/> |
123 | <completers> | 129 | <completers> |
124 | <ref component-id="connectPointCompleter"/> | 130 | <ref component-id="connectPointCompleter"/> | ... | ... |
1 | package org.onlab.onos.net.statistic; | 1 | package org.onlab.onos.net.statistic; |
2 | 2 | ||
3 | +import com.google.common.base.MoreObjects; | ||
3 | import org.onlab.onos.net.flow.FlowRuleProvider; | 4 | import org.onlab.onos.net.flow.FlowRuleProvider; |
4 | 5 | ||
5 | /** | 6 | /** |
... | @@ -53,4 +54,11 @@ public class DefaultLoad implements Load { | ... | @@ -53,4 +54,11 @@ public class DefaultLoad implements Load { |
53 | public long time() { | 54 | public long time() { |
54 | return time; | 55 | return time; |
55 | } | 56 | } |
57 | + | ||
58 | + @Override | ||
59 | + public String toString() { | ||
60 | + return MoreObjects.toStringHelper("Load").add("rate", rate()) | ||
61 | + .add("latest", latest()).toString(); | ||
62 | + | ||
63 | + } | ||
56 | } | 64 | } | ... | ... |
... | @@ -3,8 +3,7 @@ package org.onlab.onos.store.statistic.impl; | ... | @@ -3,8 +3,7 @@ package org.onlab.onos.store.statistic.impl; |
3 | import static org.onlab.onos.store.statistic.impl.StatisticStoreMessageSubjects.*; | 3 | import static org.onlab.onos.store.statistic.impl.StatisticStoreMessageSubjects.*; |
4 | import static org.slf4j.LoggerFactory.getLogger; | 4 | import static org.slf4j.LoggerFactory.getLogger; |
5 | 5 | ||
6 | -import com.google.common.collect.ImmutableSet; | 6 | +import com.google.common.collect.Sets; |
7 | - | ||
8 | import org.apache.felix.scr.annotations.Activate; | 7 | import org.apache.felix.scr.annotations.Activate; |
9 | import org.apache.felix.scr.annotations.Component; | 8 | import org.apache.felix.scr.annotations.Component; |
10 | import org.apache.felix.scr.annotations.Deactivate; | 9 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -130,7 +129,7 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -130,7 +129,7 @@ public class DistributedStatisticStore implements StatisticStore { |
130 | } | 129 | } |
131 | 130 | ||
132 | @Override | 131 | @Override |
133 | - public void removeFromStatistics(FlowRule rule) { | 132 | + public synchronized void removeFromStatistics(FlowRule rule) { |
134 | ConnectPoint cp = buildConnectPoint(rule); | 133 | ConnectPoint cp = buildConnectPoint(rule); |
135 | if (cp == null) { | 134 | if (cp == null) { |
136 | return; | 135 | return; |
... | @@ -139,6 +138,15 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -139,6 +138,15 @@ public class DistributedStatisticStore implements StatisticStore { |
139 | if (rep != null) { | 138 | if (rep != null) { |
140 | rep.remove(rule); | 139 | rep.remove(rule); |
141 | } | 140 | } |
141 | + Set<FlowEntry> values = current.get(cp); | ||
142 | + if (values != null) { | ||
143 | + values.remove(rule); | ||
144 | + } | ||
145 | + values = previous.get(cp); | ||
146 | + if (values != null) { | ||
147 | + values.remove(rule); | ||
148 | + } | ||
149 | + | ||
142 | } | 150 | } |
143 | 151 | ||
144 | @Override | 152 | @Override |
... | @@ -181,7 +189,7 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -181,7 +189,7 @@ public class DistributedStatisticStore implements StatisticStore { |
181 | return SERIALIZER.decode(response.get(STATISTIC_STORE_TIMEOUT_MILLIS, | 189 | return SERIALIZER.decode(response.get(STATISTIC_STORE_TIMEOUT_MILLIS, |
182 | TimeUnit.MILLISECONDS)); | 190 | TimeUnit.MILLISECONDS)); |
183 | } catch (IOException | TimeoutException e) { | 191 | } catch (IOException | TimeoutException e) { |
184 | - // FIXME: throw a FlowStoreException | 192 | + // FIXME: throw a StatsStoreException |
185 | throw new RuntimeException(e); | 193 | throw new RuntimeException(e); |
186 | } | 194 | } |
187 | } | 195 | } |
... | @@ -200,7 +208,7 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -200,7 +208,7 @@ public class DistributedStatisticStore implements StatisticStore { |
200 | } else { | 208 | } else { |
201 | ClusterMessage message = new ClusterMessage( | 209 | ClusterMessage message = new ClusterMessage( |
202 | clusterService.getLocalNode().id(), | 210 | clusterService.getLocalNode().id(), |
203 | - GET_CURRENT, | 211 | + GET_PREVIOUS, |
204 | SERIALIZER.encode(connectPoint)); | 212 | SERIALIZER.encode(connectPoint)); |
205 | 213 | ||
206 | try { | 214 | try { |
... | @@ -209,7 +217,7 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -209,7 +217,7 @@ public class DistributedStatisticStore implements StatisticStore { |
209 | return SERIALIZER.decode(response.get(STATISTIC_STORE_TIMEOUT_MILLIS, | 217 | return SERIALIZER.decode(response.get(STATISTIC_STORE_TIMEOUT_MILLIS, |
210 | TimeUnit.MILLISECONDS)); | 218 | TimeUnit.MILLISECONDS)); |
211 | } catch (IOException | TimeoutException e) { | 219 | } catch (IOException | TimeoutException e) { |
212 | - // FIXME: throw a FlowStoreException | 220 | + // FIXME: throw a StatsStoreException |
213 | throw new RuntimeException(e); | 221 | throw new RuntimeException(e); |
214 | } | 222 | } |
215 | } | 223 | } |
... | @@ -283,7 +291,7 @@ public class DistributedStatisticStore implements StatisticStore { | ... | @@ -283,7 +291,7 @@ public class DistributedStatisticStore implements StatisticStore { |
283 | 291 | ||
284 | public synchronized Set<FlowEntry> get() { | 292 | public synchronized Set<FlowEntry> get() { |
285 | counter.set(rules.size()); | 293 | counter.set(rules.size()); |
286 | - return ImmutableSet.copyOf(rules); | 294 | + return Sets.newHashSet(rules); |
287 | } | 295 | } |
288 | 296 | ||
289 | 297 | ... | ... |
... | @@ -31,6 +31,7 @@ import org.onlab.onos.net.flow.DefaultFlowEntry; | ... | @@ -31,6 +31,7 @@ import org.onlab.onos.net.flow.DefaultFlowEntry; |
31 | import org.onlab.onos.net.flow.DefaultFlowRule; | 31 | import org.onlab.onos.net.flow.DefaultFlowRule; |
32 | import org.onlab.onos.net.flow.DefaultTrafficSelector; | 32 | import org.onlab.onos.net.flow.DefaultTrafficSelector; |
33 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; | 33 | import org.onlab.onos.net.flow.DefaultTrafficTreatment; |
34 | +import org.onlab.onos.net.flow.FlowEntry; | ||
34 | import org.onlab.onos.net.flow.FlowId; | 35 | import org.onlab.onos.net.flow.FlowId; |
35 | import org.onlab.onos.net.flow.criteria.Criteria; | 36 | import org.onlab.onos.net.flow.criteria.Criteria; |
36 | import org.onlab.onos.net.flow.criteria.Criterion; | 37 | import org.onlab.onos.net.flow.criteria.Criterion; |
... | @@ -98,6 +99,7 @@ public final class KryoNamespaces { | ... | @@ -98,6 +99,7 @@ public final class KryoNamespaces { |
98 | DefaultHostDescription.class, | 99 | DefaultHostDescription.class, |
99 | DefaultFlowRule.class, | 100 | DefaultFlowRule.class, |
100 | DefaultFlowEntry.class, | 101 | DefaultFlowEntry.class, |
102 | + FlowEntry.FlowEntryState.class, | ||
101 | FlowId.class, | 103 | FlowId.class, |
102 | DefaultTrafficSelector.class, | 104 | DefaultTrafficSelector.class, |
103 | Criteria.PortCriterion.class, | 105 | Criteria.PortCriterion.class, | ... | ... |
-
Please register or login to post a comment