alshabib

api and manager for statistic service

Change-Id: If00b8b43a2bd780ae3c05321697896290fb0f415
1 +package org.onlab.onos.net.statistic;
2 +
3 +/**
4 + * Simple data repository for link load information.
5 + */
6 +public interface Load {
7 +
8 + /**
9 + * Obtain the current observed rate on a link.
10 + * @return long value
11 + */
12 + long rate();
13 +
14 + /**
15 + * Obtain the latest counter viewed on that link.
16 + * @return long value
17 + */
18 + long latest();
19 +
20 +}
1 +package org.onlab.onos.net.statistic;
2 +
3 +import org.onlab.onos.net.ConnectPoint;
4 +import org.onlab.onos.net.Link;
5 +import org.onlab.onos.net.Path;
6 +import org.onlab.onos.net.flow.FlowRule;
7 +
8 +/**
9 + * Service for obtaining statistic information about link in the system.
10 + * Statistics are obtained from the FlowRuleService in order to minimize the
11 + * amount of hammering occuring at the dataplane.
12 + */
13 +public interface StatisticService {
14 +
15 + /**
16 + * Obtain the load for a the ingress to the given link.
17 + * @param link the link to query.
18 + * @return a {@link org.onlab.onos.net.statistic.Load Load}
19 + */
20 + Load load(Link link);
21 +
22 + /**
23 + * Obtain the load for the given port.
24 + * @param connectPoint the port to query
25 + * @return a {@link org.onlab.onos.net.statistic.Load}
26 + */
27 + Load load(ConnectPoint connectPoint);
28 +
29 + /**
30 + * Find the most loaded link along a path.
31 + * @param path the path to search in
32 + * @return the most loaded {@link org.onlab.onos.net.Link}.
33 + */
34 + Link max(Path path);
35 +
36 + /**
37 + * Find the least loaded link along a path.
38 + * @param path the path to search in
39 + * @return the least loaded {@link org.onlab.onos.net.Link}.
40 + */
41 + Link min(Path path);
42 +
43 + /**
44 + * Returns the highest hitter (a flow rule) of for a given port, ie. the
45 + * flow rule which is generating the most load.
46 + * @param connectPoint the port
47 + * @return the flow rule
48 + */
49 + FlowRule highestHitter(ConnectPoint connectPoint);
50 +
51 +}
1 +package org.onlab.onos.net.statistic;
2 +
3 +import org.onlab.onos.net.ConnectPoint;
4 +import org.onlab.onos.net.flow.FlowEntry;
5 +import org.onlab.onos.net.flow.FlowRule;
6 +
7 +import java.util.Set;
8 +
9 +/**
10 + * Store to house the computed statistics.
11 + */
12 +public interface StatisticStore {
13 +
14 + /**
15 + * Lay the foundation for receiving flow stats for this rule.
16 + * @param rule a {@link org.onlab.onos.net.flow.FlowRule}
17 + */
18 + void prepareForStatistics(FlowRule rule);
19 +
20 + /**
21 + * Remove entries associated with this rule.
22 + a @param rule {@link org.onlab.onos.net.flow.FlowRule}
23 + */
24 + void removeFromStatistics(FlowRule rule);
25 +
26 + /**
27 + * Adds a stats observation for a flow rule.
28 + * @param rule a {@link org.onlab.onos.net.flow.FlowEntry}
29 + */
30 + void addOrUpdateStatistic(FlowEntry rule);
31 +
32 + /**
33 + * Fetches the current observed stats values.
34 + * @param connectPoint the port to fetch information for
35 + * @return set of current flow rules
36 + */
37 + Set<FlowEntry> getCurrentStatistic(ConnectPoint connectPoint);
38 +
39 + /**
40 + * Fetches the current observed stats values.
41 + * @param connectPoint the port to fetch information for
42 + * @return set of current values
43 + */
44 + Set<FlowEntry> getPreviousStatistic(ConnectPoint connectPoint);
45 +}
1 +/**
2 + * Service for looking up statistics on links.
3 + */
4 +package org.onlab.onos.net.statistic;
...\ No newline at end of file ...\ No newline at end of file
1 +package org.onlab.onos.net.statistic.impl;
2 +
3 +import org.apache.felix.scr.annotations.Activate;
4 +import org.apache.felix.scr.annotations.Component;
5 +import org.apache.felix.scr.annotations.Deactivate;
6 +import org.apache.felix.scr.annotations.Reference;
7 +import org.apache.felix.scr.annotations.ReferenceCardinality;
8 +import org.apache.felix.scr.annotations.Service;
9 +import org.onlab.onos.net.ConnectPoint;
10 +import org.onlab.onos.net.Link;
11 +import org.onlab.onos.net.Path;
12 +import org.onlab.onos.net.flow.FlowRule;
13 +import org.onlab.onos.net.flow.FlowRuleEvent;
14 +import org.onlab.onos.net.flow.FlowRuleListener;
15 +import org.onlab.onos.net.flow.FlowRuleService;
16 +import org.onlab.onos.net.statistic.Load;
17 +import org.onlab.onos.net.statistic.StatisticService;
18 +import org.onlab.onos.net.statistic.StatisticStore;
19 +import org.slf4j.Logger;
20 +
21 +import static org.slf4j.LoggerFactory.getLogger;
22 +
23 +/**
24 + * Provides an implementation of the Statistic Service.
25 + */
26 +@Component(immediate = true)
27 +@Service
28 +public class StatisticManager implements StatisticService {
29 +
30 + private final Logger log = getLogger(getClass());
31 +
32 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
33 + protected FlowRuleService flowRuleService;
34 +
35 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
36 + protected StatisticStore statisticStore;
37 +
38 + private final InternalFlowRuleListener listener = new InternalFlowRuleListener();
39 +
40 + @Activate
41 + public void activate() {
42 + flowRuleService.addListener(listener);
43 + log.info("Started");
44 + }
45 +
46 + @Deactivate
47 + public void deactivate() {
48 + flowRuleService.removeListener(listener);
49 + log.info("Stopped");
50 + }
51 +
52 + @Override
53 + public Load load(Link link) {
54 + return null;
55 + }
56 +
57 + @Override
58 + public Load load(ConnectPoint connectPoint) {
59 + return null;
60 + }
61 +
62 + @Override
63 + public Link max(Path path) {
64 + return null;
65 + }
66 +
67 + @Override
68 + public Link min(Path path) {
69 + return null;
70 + }
71 +
72 + @Override
73 + public FlowRule highestHitter(ConnectPoint connectPoint) {
74 + return null;
75 + }
76 +
77 + /**
78 + * Internal flow rule event listener.
79 + */
80 + private class InternalFlowRuleListener implements FlowRuleListener {
81 +
82 + @Override
83 + public void event(FlowRuleEvent event) {
84 +
85 + }
86 + }
87 +
88 +
89 +}
1 +/**
2 + * Core subsystem for responding to statistical inquiries.
3 + */
4 +package org.onlab.onos.net.statistic.impl;
...\ No newline at end of file ...\ No newline at end of file