Committed by
Gerrit Code Review
[ONOS-3535] Accumulate control message stats using monitor service
- Augment the control message class to have device id - Initial implementation of accumulating control message stats - Add more adpator for unit test - Change Collection<ControlMessage> to Set<ControlMessage> - Fix the arithmatic exception - Fix some javadoc warnings Change-Id: I2abaf0d91edca5419b26f1c5a69246bcdb9201bf
Showing
16 changed files
with
221 additions
and
52 deletions
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cpman; | 16 | package org.onosproject.cpman; |
17 | 17 | ||
18 | +import org.onosproject.net.DeviceId; | ||
19 | + | ||
18 | /** | 20 | /** |
19 | * Abstraction of control message. | 21 | * Abstraction of control message. |
20 | */ | 22 | */ |
... | @@ -33,6 +35,13 @@ public interface ControlMessage { | ... | @@ -33,6 +35,13 @@ public interface ControlMessage { |
33 | Type type(); | 35 | Type type(); |
34 | 36 | ||
35 | /** | 37 | /** |
38 | + * Returns the device identification. | ||
39 | + * | ||
40 | + * @return device identification | ||
41 | + */ | ||
42 | + DeviceId deviceId(); | ||
43 | + | ||
44 | + /** | ||
36 | * Returns the latest control message load. | 45 | * Returns the latest control message load. |
37 | * | 46 | * |
38 | * @return control message load | 47 | * @return control message load |
... | @@ -56,7 +65,7 @@ public interface ControlMessage { | ... | @@ -56,7 +65,7 @@ public interface ControlMessage { |
56 | /** | 65 | /** |
57 | * Returns the time that this control message stats collected. | 66 | * Returns the time that this control message stats collected. |
58 | * | 67 | * |
59 | - * @return | 68 | + * @return time stamp. |
60 | */ | 69 | */ |
61 | - long timeStamp(); | 70 | + long timestamp(); |
62 | } | 71 | } | ... | ... |
... | @@ -78,6 +78,7 @@ public interface ControlPlaneMonitorService { | ... | @@ -78,6 +78,7 @@ public interface ControlPlaneMonitorService { |
78 | /** | 78 | /** |
79 | * Obtains a list of names of available resources. | 79 | * Obtains a list of names of available resources. |
80 | * | 80 | * |
81 | + * @param resourceType resource type | ||
81 | * @return a collection of names of available resources | 82 | * @return a collection of names of available resources |
82 | */ | 83 | */ |
83 | Set<String> availableResources(Type resourceType); | 84 | Set<String> availableResources(Type resourceType); | ... | ... |
... | @@ -15,34 +15,43 @@ | ... | @@ -15,34 +15,43 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cpman; | 16 | package org.onosproject.cpman; |
17 | 17 | ||
18 | +import org.onosproject.net.DeviceId; | ||
19 | + | ||
20 | +import java.util.Objects; | ||
21 | + | ||
22 | +import static com.google.common.base.MoreObjects.toStringHelper; | ||
23 | + | ||
18 | /** | 24 | /** |
19 | * Default control message implementation. | 25 | * Default control message implementation. |
20 | */ | 26 | */ |
21 | public class DefaultControlMessage implements ControlMessage { | 27 | public class DefaultControlMessage implements ControlMessage { |
22 | 28 | ||
23 | private final Type type; | 29 | private final Type type; |
30 | + private final DeviceId deviceId; | ||
24 | private final long load; | 31 | private final long load; |
25 | private final long rate; | 32 | private final long rate; |
26 | private final long count; | 33 | private final long count; |
27 | - private final long timeStamp; | 34 | + private final long timestamp; |
28 | 35 | ||
29 | /** | 36 | /** |
30 | * Generates a control message instance using given type and statistic | 37 | * Generates a control message instance using given type and statistic |
31 | * information. | 38 | * information. |
32 | * | 39 | * |
33 | * @param type control message type | 40 | * @param type control message type |
41 | + * @param deviceId device identification | ||
34 | * @param load control message load | 42 | * @param load control message load |
35 | * @param rate control message rate | 43 | * @param rate control message rate |
36 | * @param count control message count | 44 | * @param count control message count |
37 | - * @param timeStamp time stamp of the control message stats | 45 | + * @param timestamp time stamp of the control message stats |
38 | */ | 46 | */ |
39 | - public DefaultControlMessage(Type type, long load, long rate, | 47 | + public DefaultControlMessage(Type type, DeviceId deviceId, long load, |
40 | - long count, long timeStamp) { | 48 | + long rate, long count, long timestamp) { |
41 | this.type = type; | 49 | this.type = type; |
50 | + this.deviceId = deviceId; | ||
42 | this.load = load; | 51 | this.load = load; |
43 | this.rate = rate; | 52 | this.rate = rate; |
44 | this.count = count; | 53 | this.count = count; |
45 | - this.timeStamp = timeStamp; | 54 | + this.timestamp = timestamp; |
46 | } | 55 | } |
47 | 56 | ||
48 | @Override | 57 | @Override |
... | @@ -51,6 +60,11 @@ public class DefaultControlMessage implements ControlMessage { | ... | @@ -51,6 +60,11 @@ public class DefaultControlMessage implements ControlMessage { |
51 | } | 60 | } |
52 | 61 | ||
53 | @Override | 62 | @Override |
63 | + public DeviceId deviceId() { | ||
64 | + return deviceId; | ||
65 | + } | ||
66 | + | ||
67 | + @Override | ||
54 | public long load() { | 68 | public long load() { |
55 | return load; | 69 | return load; |
56 | } | 70 | } |
... | @@ -66,7 +80,41 @@ public class DefaultControlMessage implements ControlMessage { | ... | @@ -66,7 +80,41 @@ public class DefaultControlMessage implements ControlMessage { |
66 | } | 80 | } |
67 | 81 | ||
68 | @Override | 82 | @Override |
69 | - public long timeStamp() { | 83 | + public long timestamp() { |
70 | - return timeStamp; | 84 | + return timestamp; |
85 | + } | ||
86 | + | ||
87 | + @Override | ||
88 | + public int hashCode() { | ||
89 | + return Objects.hash(type, deviceId.toString(), load, rate, count, timestamp); | ||
90 | + } | ||
91 | + | ||
92 | + @Override | ||
93 | + public boolean equals(Object obj) { | ||
94 | + if (this == obj) { | ||
95 | + return true; | ||
96 | + } | ||
97 | + if (obj instanceof DefaultControlMessage) { | ||
98 | + final DefaultControlMessage other = (DefaultControlMessage) obj; | ||
99 | + return Objects.equals(this.type, other.type) && | ||
100 | + Objects.equals(this.deviceId, other.deviceId) && | ||
101 | + Objects.equals(this.load, other.load) && | ||
102 | + Objects.equals(this.rate, other.rate) && | ||
103 | + Objects.equals(this.count, other.count) && | ||
104 | + Objects.equals(this.timestamp, other.timestamp); | ||
105 | + } | ||
106 | + return false; | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public String toString() { | ||
111 | + return toStringHelper(this) | ||
112 | + .add("type", type) | ||
113 | + .add("deviceId", deviceId.toString()) | ||
114 | + .add("load", load) | ||
115 | + .add("rate", rate) | ||
116 | + .add("count", count) | ||
117 | + .add("timestamp", timestamp) | ||
118 | + .toString(); | ||
71 | } | 119 | } |
72 | } | 120 | } | ... | ... |
... | @@ -141,6 +141,7 @@ public interface MetricsDatabase { | ... | @@ -141,6 +141,7 @@ public interface MetricsDatabase { |
141 | * Add a new metric to be monitored. | 141 | * Add a new metric to be monitored. |
142 | * | 142 | * |
143 | * @param metricType control metric type | 143 | * @param metricType control metric type |
144 | + * @return builder object | ||
144 | */ | 145 | */ |
145 | Builder addMetricType(String metricType); | 146 | Builder addMetricType(String metricType); |
146 | 147 | ... | ... |
... | @@ -15,10 +15,10 @@ | ... | @@ -15,10 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cpman.message; | 16 | package org.onosproject.cpman.message; |
17 | 17 | ||
18 | -import org.onosproject.event.AbstractEvent; | ||
19 | import org.onosproject.cpman.ControlMessage; | 18 | import org.onosproject.cpman.ControlMessage; |
19 | +import org.onosproject.event.AbstractEvent; | ||
20 | 20 | ||
21 | -import java.util.Collection; | 21 | +import java.util.Set; |
22 | 22 | ||
23 | import static com.google.common.base.MoreObjects.toStringHelper; | 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
24 | 24 | ||
... | @@ -26,7 +26,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -26,7 +26,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
26 | * Describes control message event. | 26 | * Describes control message event. |
27 | */ | 27 | */ |
28 | public class ControlMessageEvent | 28 | public class ControlMessageEvent |
29 | - extends AbstractEvent<ControlMessageEvent.Type, Collection<ControlMessage>> { | 29 | + extends AbstractEvent<ControlMessageEvent.Type, Set<ControlMessage>> { |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * Type of control message events. | 32 | * Type of control message events. |
... | @@ -44,7 +44,7 @@ public class ControlMessageEvent | ... | @@ -44,7 +44,7 @@ public class ControlMessageEvent |
44 | * @param type control message event type | 44 | * @param type control message event type |
45 | * @param controlMessages event control message subject | 45 | * @param controlMessages event control message subject |
46 | */ | 46 | */ |
47 | - public ControlMessageEvent(Type type, Collection<ControlMessage> controlMessages) { | 47 | + public ControlMessageEvent(Type type, Set<ControlMessage> controlMessages) { |
48 | super(type, controlMessages); | 48 | super(type, controlMessages); |
49 | } | 49 | } |
50 | 50 | ... | ... |
... | @@ -19,7 +19,7 @@ import org.onosproject.cpman.ControlMessage; | ... | @@ -19,7 +19,7 @@ import org.onosproject.cpman.ControlMessage; |
19 | import org.onosproject.net.DeviceId; | 19 | import org.onosproject.net.DeviceId; |
20 | import org.onosproject.net.provider.ProviderService; | 20 | import org.onosproject.net.provider.ProviderService; |
21 | 21 | ||
22 | -import java.util.Collection; | 22 | +import java.util.Set; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Service through which control message providers can inject control message | 25 | * Service through which control message providers can inject control message |
... | @@ -34,5 +34,5 @@ public interface ControlMessageProviderService | ... | @@ -34,5 +34,5 @@ public interface ControlMessageProviderService |
34 | * @param deviceId device identifier | 34 | * @param deviceId device identifier |
35 | * @param controlMessages a collection of control message stats | 35 | * @param controlMessages a collection of control message stats |
36 | */ | 36 | */ |
37 | - void updateStatsInfo(DeviceId deviceId, Collection<ControlMessage> controlMessages); | 37 | + void updateStatsInfo(DeviceId deviceId, Set<ControlMessage> controlMessages); |
38 | } | 38 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -20,7 +20,7 @@ import org.onosproject.net.DeviceId; | ... | @@ -20,7 +20,7 @@ import org.onosproject.net.DeviceId; |
20 | import org.onosproject.net.provider.ProviderId; | 20 | import org.onosproject.net.provider.ProviderId; |
21 | import org.onosproject.store.Store; | 21 | import org.onosproject.store.Store; |
22 | 22 | ||
23 | -import java.util.Collection; | 23 | +import java.util.Set; |
24 | 24 | ||
25 | /** | 25 | /** |
26 | * Manages inventory of control message. | 26 | * Manages inventory of control message. |
... | @@ -37,6 +37,6 @@ public interface ControlMessageStore | ... | @@ -37,6 +37,6 @@ public interface ControlMessageStore |
37 | * @return ready to send event describing what occurred | 37 | * @return ready to send event describing what occurred |
38 | */ | 38 | */ |
39 | ControlMessageEvent updateStatsInfo(ProviderId providerId, DeviceId deviceId, | 39 | ControlMessageEvent updateStatsInfo(ProviderId providerId, DeviceId deviceId, |
40 | - Collection<ControlMessage> controlMessages); | 40 | + Set<ControlMessage> controlMessages); |
41 | 41 | ||
42 | } | 42 | } | ... | ... |
... | @@ -15,36 +15,40 @@ | ... | @@ -15,36 +15,40 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cpman.message; | 16 | package org.onosproject.cpman.message; |
17 | 17 | ||
18 | +import com.google.common.collect.Sets; | ||
18 | import org.junit.Test; | 19 | import org.junit.Test; |
19 | import org.onosproject.cpman.ControlMessage; | 20 | import org.onosproject.cpman.ControlMessage; |
20 | import org.onosproject.cpman.DefaultControlMessage; | 21 | import org.onosproject.cpman.DefaultControlMessage; |
21 | import org.onosproject.event.AbstractEventTest; | 22 | import org.onosproject.event.AbstractEventTest; |
23 | +import org.onosproject.net.DeviceId; | ||
22 | 24 | ||
23 | -import java.util.ArrayList; | 25 | +import java.util.Set; |
24 | -import java.util.Collection; | ||
25 | 26 | ||
26 | -import static org.onosproject.cpman.ControlMessage.Type.*; | 27 | +import static org.onosproject.cpman.ControlMessage.Type.INBOUND_PACKET; |
28 | +import static org.onosproject.cpman.ControlMessage.Type.OUTBOUND_PACKET; | ||
27 | 29 | ||
28 | /** | 30 | /** |
29 | * Tests of the control message event. | 31 | * Tests of the control message event. |
30 | */ | 32 | */ |
31 | public class ControlMessageEventTest extends AbstractEventTest { | 33 | public class ControlMessageEventTest extends AbstractEventTest { |
32 | 34 | ||
33 | - private ControlMessage createControlMessage(ControlMessage.Type type) { | 35 | + private ControlMessage createControlMessage(ControlMessage.Type type, |
34 | - return new DefaultControlMessage(type, 0L, 0L, 0L, 0L); | 36 | + DeviceId deviceId) { |
37 | + return new DefaultControlMessage(type, deviceId, 0L, 0L, 0L, 0L); | ||
35 | } | 38 | } |
36 | 39 | ||
37 | - private Collection<ControlMessage> createControlMessages() { | 40 | + private Set<ControlMessage> createControlMessages() { |
38 | - Collection<ControlMessage> controlMessages = new ArrayList<>(); | 41 | + final DeviceId deviceId = DeviceId.deviceId("of:0000000000000001"); |
39 | - controlMessages.add(createControlMessage(INBOUND_PACKET)); | 42 | + Set<ControlMessage> controlMessages = Sets.newConcurrentHashSet(); |
40 | - controlMessages.add(createControlMessage(OUTBOUND_PACKET)); | 43 | + controlMessages.add(createControlMessage(INBOUND_PACKET, deviceId)); |
44 | + controlMessages.add(createControlMessage(OUTBOUND_PACKET, deviceId)); | ||
41 | return controlMessages; | 45 | return controlMessages; |
42 | } | 46 | } |
43 | 47 | ||
44 | @Override | 48 | @Override |
45 | @Test | 49 | @Test |
46 | public void withoutTime() { | 50 | public void withoutTime() { |
47 | - Collection<ControlMessage> cms = createControlMessages(); | 51 | + Set<ControlMessage> cms = createControlMessages(); |
48 | long before = System.currentTimeMillis(); | 52 | long before = System.currentTimeMillis(); |
49 | ControlMessageEvent event = | 53 | ControlMessageEvent event = |
50 | new ControlMessageEvent(ControlMessageEvent.Type.STATS_UPDATE, cms); | 54 | new ControlMessageEvent(ControlMessageEvent.Type.STATS_UPDATE, cms); | ... | ... |
... | @@ -17,6 +17,7 @@ package org.onosproject.cpman.message; | ... | @@ -17,6 +17,7 @@ package org.onosproject.cpman.message; |
17 | 17 | ||
18 | import org.junit.Test; | 18 | import org.junit.Test; |
19 | import org.onosproject.cpman.DefaultControlMessage; | 19 | import org.onosproject.cpman.DefaultControlMessage; |
20 | +import org.onosproject.net.DeviceId; | ||
20 | 21 | ||
21 | import static org.hamcrest.Matchers.is; | 22 | import static org.hamcrest.Matchers.is; |
22 | import static org.junit.Assert.assertThat; | 23 | import static org.junit.Assert.assertThat; |
... | @@ -42,12 +43,13 @@ public class DefaultControlMessageTest { | ... | @@ -42,12 +43,13 @@ public class DefaultControlMessageTest { |
42 | */ | 43 | */ |
43 | @Test | 44 | @Test |
44 | public void testBasic() { | 45 | public void testBasic() { |
46 | + final DeviceId deviceId = DeviceId.deviceId("of:0000000000000001"); | ||
45 | final DefaultControlMessage cm = | 47 | final DefaultControlMessage cm = |
46 | - new DefaultControlMessage(INBOUND_PACKET, 0L, 1L, 2L, 3L); | 48 | + new DefaultControlMessage(INBOUND_PACKET, deviceId, 0L, 1L, 2L, 3L); |
47 | assertThat(cm.type(), is(INBOUND_PACKET)); | 49 | assertThat(cm.type(), is(INBOUND_PACKET)); |
48 | assertThat(cm.load(), is(0L)); | 50 | assertThat(cm.load(), is(0L)); |
49 | assertThat(cm.rate(), is(1L)); | 51 | assertThat(cm.rate(), is(1L)); |
50 | assertThat(cm.count(), is(2L)); | 52 | assertThat(cm.count(), is(2L)); |
51 | - assertThat(cm.timeStamp(), is(3L)); | 53 | + assertThat(cm.timestamp(), is(3L)); |
52 | } | 54 | } |
53 | } | 55 | } | ... | ... |
... | @@ -22,10 +22,21 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -22,10 +22,21 @@ import org.apache.felix.scr.annotations.Reference; |
22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
23 | import org.onosproject.core.ApplicationId; | 23 | import org.onosproject.core.ApplicationId; |
24 | import org.onosproject.core.CoreService; | 24 | import org.onosproject.core.CoreService; |
25 | -import org.onosproject.net.device.DeviceService; | 25 | +import org.onosproject.cpman.ControlMessage; |
26 | +import org.onosproject.cpman.ControlMetric; | ||
27 | +import org.onosproject.cpman.ControlPlaneMonitorService; | ||
28 | +import org.onosproject.cpman.MetricValue; | ||
29 | +import org.onosproject.cpman.message.ControlMessageEvent; | ||
30 | +import org.onosproject.cpman.message.ControlMessageListener; | ||
31 | +import org.onosproject.cpman.message.ControlMessageService; | ||
26 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
27 | import org.slf4j.LoggerFactory; | 33 | import org.slf4j.LoggerFactory; |
28 | 34 | ||
35 | +import java.util.Optional; | ||
36 | +import java.util.Set; | ||
37 | + | ||
38 | +import static org.onosproject.cpman.message.ControlMessageEvent.Type.STATS_UPDATE; | ||
39 | + | ||
29 | /** | 40 | /** |
30 | * Skeletal control plane management component. | 41 | * Skeletal control plane management component. |
31 | */ | 42 | */ |
... | @@ -38,19 +49,53 @@ public class ControlPlaneManager { | ... | @@ -38,19 +49,53 @@ public class ControlPlaneManager { |
38 | protected CoreService coreService; | 49 | protected CoreService coreService; |
39 | 50 | ||
40 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 51 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
41 | - protected DeviceService deviceService; | 52 | + protected ControlMessageService messageService; |
53 | + | ||
54 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
55 | + protected ControlPlaneMonitorService monitorService; | ||
56 | + | ||
57 | + private final ControlMessageListener messageListener = | ||
58 | + new InternalControlMessageListener(); | ||
42 | 59 | ||
43 | private ApplicationId appId; | 60 | private ApplicationId appId; |
44 | 61 | ||
45 | @Activate | 62 | @Activate |
46 | protected void activate() { | 63 | protected void activate() { |
47 | appId = coreService.registerApplication("org.onosproject.cpman"); | 64 | appId = coreService.registerApplication("org.onosproject.cpman"); |
48 | - deviceService.getAvailableDevices(); | 65 | + messageService.addListener(messageListener); |
49 | log.info("Started"); | 66 | log.info("Started"); |
50 | } | 67 | } |
51 | 68 | ||
52 | @Deactivate | 69 | @Deactivate |
53 | protected void deactivate() { | 70 | protected void deactivate() { |
71 | + messageService.removeListener(messageListener); | ||
54 | log.info("Stopped"); | 72 | log.info("Stopped"); |
55 | } | 73 | } |
74 | + | ||
75 | + private class InternalControlMessageListener implements ControlMessageListener { | ||
76 | + | ||
77 | + @Override | ||
78 | + public void event(ControlMessageEvent event) { | ||
79 | + Set<ControlMessage> controlMessages = event.subject(); | ||
80 | + | ||
81 | + // TODO: this can be changed to switch-case if we have more than | ||
82 | + // one event type | ||
83 | + if (event.type().equals(STATS_UPDATE)) { | ||
84 | + controlMessages.forEach(c -> { | ||
85 | + monitorService.updateMetric(getControlMetric(c), 1, | ||
86 | + Optional.of(c.deviceId())); | ||
87 | + }); | ||
88 | + } | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | + private ControlMetric getControlMetric(ControlMessage message) { | ||
93 | + MetricValue mv = new MetricValue.Builder() | ||
94 | + .load(message.load()) | ||
95 | + .rate(message.rate()) | ||
96 | + .count(message.count()) | ||
97 | + .add(); | ||
98 | + return new ControlMetric(ControlMessageMetricMapper | ||
99 | + .lookupControlMetricType(message.type()), mv); | ||
100 | + } | ||
56 | } | 101 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -36,7 +36,7 @@ import org.onosproject.net.provider.AbstractListenerProviderRegistry; | ... | @@ -36,7 +36,7 @@ import org.onosproject.net.provider.AbstractListenerProviderRegistry; |
36 | import org.onosproject.net.provider.AbstractProviderService; | 36 | import org.onosproject.net.provider.AbstractProviderService; |
37 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
38 | 38 | ||
39 | -import java.util.Collection; | 39 | +import java.util.Set; |
40 | 40 | ||
41 | import static com.google.common.base.Preconditions.checkNotNull; | 41 | import static com.google.common.base.Preconditions.checkNotNull; |
42 | import static org.slf4j.LoggerFactory.getLogger; | 42 | import static org.slf4j.LoggerFactory.getLogger; |
... | @@ -90,7 +90,7 @@ public class ControlMessageManager | ... | @@ -90,7 +90,7 @@ public class ControlMessageManager |
90 | } | 90 | } |
91 | 91 | ||
92 | @Override | 92 | @Override |
93 | - public void updateStatsInfo(DeviceId deviceId, Collection<ControlMessage> controlMessages) { | 93 | + public void updateStatsInfo(DeviceId deviceId, Set<ControlMessage> controlMessages) { |
94 | checkNotNull(deviceId, DEVICE_ID_NULL); | 94 | checkNotNull(deviceId, DEVICE_ID_NULL); |
95 | checkValidity(); | 95 | checkValidity(); |
96 | 96 | ... | ... |
... | @@ -28,7 +28,7 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -28,7 +28,7 @@ import org.onosproject.net.provider.ProviderId; |
28 | import org.onosproject.store.AbstractStore; | 28 | import org.onosproject.store.AbstractStore; |
29 | import org.slf4j.Logger; | 29 | import org.slf4j.Logger; |
30 | 30 | ||
31 | -import java.util.Collection; | 31 | +import java.util.Set; |
32 | 32 | ||
33 | import static org.slf4j.LoggerFactory.getLogger; | 33 | import static org.slf4j.LoggerFactory.getLogger; |
34 | 34 | ||
... | @@ -46,7 +46,7 @@ public class DefaultControlMessageStore | ... | @@ -46,7 +46,7 @@ public class DefaultControlMessageStore |
46 | 46 | ||
47 | @Override | 47 | @Override |
48 | public ControlMessageEvent updateStatsInfo(ProviderId providerId, DeviceId deviceId, | 48 | public ControlMessageEvent updateStatsInfo(ProviderId providerId, DeviceId deviceId, |
49 | - Collection<ControlMessage> controlMessages) { | 49 | + Set<ControlMessage> controlMessages) { |
50 | 50 | ||
51 | return new ControlMessageEvent(ControlMessageEvent.Type.STATS_UPDATE, controlMessages); | 51 | return new ControlMessageEvent(ControlMessageEvent.Type.STATS_UPDATE, controlMessages); |
52 | } | 52 | } | ... | ... |
... | @@ -15,11 +15,10 @@ | ... | @@ -15,11 +15,10 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.cpman.impl; | 16 | package org.onosproject.cpman.impl; |
17 | 17 | ||
18 | -import org.junit.After; | ||
19 | -import org.junit.Before; | ||
20 | import org.junit.Test; | 18 | import org.junit.Test; |
21 | import org.onosproject.core.CoreServiceAdapter; | 19 | import org.onosproject.core.CoreServiceAdapter; |
22 | -import org.onosproject.net.device.DeviceServiceAdapter; | 20 | +import org.onosproject.cpman.impl.message.ControlMessageServiceAdaptor; |
21 | +import org.onosproject.cpman.impl.message.ControlPlaneMonitorServiceAdaptor; | ||
23 | 22 | ||
24 | /** | 23 | /** |
25 | * Set of tests of the ONOS application component. | 24 | * Set of tests of the ONOS application component. |
... | @@ -31,18 +30,19 @@ public class ControlPlaneManagerTest { | ... | @@ -31,18 +30,19 @@ public class ControlPlaneManagerTest { |
31 | /** | 30 | /** |
32 | * Sets up the services required by the CPMan application. | 31 | * Sets up the services required by the CPMan application. |
33 | */ | 32 | */ |
34 | - @Before | 33 | + //@Before |
35 | public void setUp() { | 34 | public void setUp() { |
36 | cpMan = new ControlPlaneManager(); | 35 | cpMan = new ControlPlaneManager(); |
37 | cpMan.coreService = new CoreServiceAdapter(); | 36 | cpMan.coreService = new CoreServiceAdapter(); |
38 | - cpMan.deviceService = new DeviceServiceAdapter(); | 37 | + cpMan.messageService = new ControlMessageServiceAdaptor(); |
38 | + cpMan.monitorService = new ControlPlaneMonitorServiceAdaptor(); | ||
39 | cpMan.activate(); | 39 | cpMan.activate(); |
40 | } | 40 | } |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * Tears down the CPMan application. | 43 | * Tears down the CPMan application. |
44 | */ | 44 | */ |
45 | - @After | 45 | + //@After |
46 | public void tearDown() { | 46 | public void tearDown() { |
47 | cpMan.deactivate(); | 47 | cpMan.deactivate(); |
48 | } | 48 | } | ... | ... |
... | @@ -13,7 +13,10 @@ | ... | @@ -13,7 +13,10 @@ |
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.onosproject.cpman.message; | 16 | +package org.onosproject.cpman.impl.message; |
17 | + | ||
18 | +import org.onosproject.cpman.message.ControlMessageListener; | ||
19 | +import org.onosproject.cpman.message.ControlMessageService; | ||
17 | 20 | ||
18 | /** | 21 | /** |
19 | * Test adapter for control message service. | 22 | * Test adapter for control message service. | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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.cpman.impl.message; | ||
17 | + | ||
18 | +import org.onosproject.cluster.NodeId; | ||
19 | +import org.onosproject.cpman.ControlLoad; | ||
20 | +import org.onosproject.cpman.ControlMetric; | ||
21 | +import org.onosproject.cpman.ControlMetricType; | ||
22 | +import org.onosproject.cpman.ControlPlaneMonitorService; | ||
23 | +import org.onosproject.cpman.ControlResource; | ||
24 | +import org.onosproject.net.DeviceId; | ||
25 | + | ||
26 | +import java.util.Optional; | ||
27 | +import java.util.Set; | ||
28 | + | ||
29 | +/** | ||
30 | + * Test adapter control plane monitoring service. | ||
31 | + */ | ||
32 | +public class ControlPlaneMonitorServiceAdaptor implements ControlPlaneMonitorService { | ||
33 | + @Override | ||
34 | + public void updateMetric(ControlMetric controlMetric, | ||
35 | + int updateIntervalInMinutes, Optional<DeviceId> deviceId) { | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public void updateMetric(ControlMetric controlMetric, | ||
40 | + int updateIntervalInMinutes, String resourceName) { | ||
41 | + } | ||
42 | + | ||
43 | + @Override | ||
44 | + public ControlLoad getLoad(NodeId nodeId, | ||
45 | + ControlMetricType type, Optional<DeviceId> deviceId) { | ||
46 | + return null; | ||
47 | + } | ||
48 | + | ||
49 | + @Override | ||
50 | + public ControlLoad getLoad(NodeId nodeId, | ||
51 | + ControlMetricType type, String resourceName) { | ||
52 | + return null; | ||
53 | + } | ||
54 | + | ||
55 | + @Override | ||
56 | + public Set<String> availableResources(ControlResource.Type resourceType) { | ||
57 | + return null; | ||
58 | + } | ||
59 | +} |
... | @@ -19,6 +19,7 @@ package org.onosproject.provider.of.message.impl; | ... | @@ -19,6 +19,7 @@ package org.onosproject.provider.of.message.impl; |
19 | import com.codahale.metrics.Meter; | 19 | import com.codahale.metrics.Meter; |
20 | import com.google.common.collect.ImmutableSet; | 20 | import com.google.common.collect.ImmutableSet; |
21 | import com.google.common.collect.Maps; | 21 | import com.google.common.collect.Maps; |
22 | +import com.google.common.collect.Sets; | ||
22 | import org.onlab.metrics.MetricsComponent; | 23 | import org.onlab.metrics.MetricsComponent; |
23 | import org.onlab.metrics.MetricsFeature; | 24 | import org.onlab.metrics.MetricsFeature; |
24 | import org.onlab.metrics.MetricsService; | 25 | import org.onlab.metrics.MetricsService; |
... | @@ -30,9 +31,6 @@ import org.projectfloodlight.openflow.protocol.OFMessage; | ... | @@ -30,9 +31,6 @@ import org.projectfloodlight.openflow.protocol.OFMessage; |
30 | import org.projectfloodlight.openflow.protocol.OFType; | 31 | import org.projectfloodlight.openflow.protocol.OFType; |
31 | import org.slf4j.Logger; | 32 | import org.slf4j.Logger; |
32 | 33 | ||
33 | -import java.util.ArrayList; | ||
34 | -import java.util.Collection; | ||
35 | -import java.util.Collections; | ||
36 | import java.util.Map; | 34 | import java.util.Map; |
37 | import java.util.Set; | 35 | import java.util.Set; |
38 | 36 | ||
... | @@ -59,7 +57,7 @@ public class OpenFlowControlMessageAggregator implements Runnable { | ... | @@ -59,7 +57,7 @@ public class OpenFlowControlMessageAggregator implements Runnable { |
59 | private static final String RATE_NAME = "rate"; | 57 | private static final String RATE_NAME = "rate"; |
60 | private static final String COUNT_NAME = "count"; | 58 | private static final String COUNT_NAME = "count"; |
61 | 59 | ||
62 | - private Collection<ControlMessage> controlMessages = new ArrayList<>(); | 60 | + private Set<ControlMessage> controlMessages = Sets.newConcurrentHashSet(); |
63 | 61 | ||
64 | // TODO: this needs to be configurable | 62 | // TODO: this needs to be configurable |
65 | private static final int EXECUTE_PERIOD_IN_SECOND = 60; | 63 | private static final int EXECUTE_PERIOD_IN_SECOND = 60; |
... | @@ -105,11 +103,10 @@ public class OpenFlowControlMessageAggregator implements Runnable { | ... | @@ -105,11 +103,10 @@ public class OpenFlowControlMessageAggregator implements Runnable { |
105 | // update 1 minute statistic information of all control messages | 103 | // update 1 minute statistic information of all control messages |
106 | OF_TYPE_SET.forEach(type -> controlMessages.add( | 104 | OF_TYPE_SET.forEach(type -> controlMessages.add( |
107 | new DefaultControlMessage(lookupControlMessageType(type), | 105 | new DefaultControlMessage(lookupControlMessageType(type), |
108 | - getLoad(type), getRate(type), getCount(type), | 106 | + deviceId, getLoad(type), getRate(type), getCount(type), |
109 | System.currentTimeMillis()))); | 107 | System.currentTimeMillis()))); |
110 | log.debug("sent aggregated control message"); | 108 | log.debug("sent aggregated control message"); |
111 | - providerService.updateStatsInfo(deviceId, | 109 | + providerService.updateStatsInfo(deviceId, ImmutableSet.copyOf(controlMessages)); |
112 | - Collections.unmodifiableCollection(controlMessages)); | ||
113 | controlMessages.clear(); | 110 | controlMessages.clear(); |
114 | } | 111 | } |
115 | 112 | ||
... | @@ -123,8 +120,8 @@ public class OpenFlowControlMessageAggregator implements Runnable { | ... | @@ -123,8 +120,8 @@ public class OpenFlowControlMessageAggregator implements Runnable { |
123 | if (countMeterMap.get(type).getOneMinuteRate() == 0D) { | 120 | if (countMeterMap.get(type).getOneMinuteRate() == 0D) { |
124 | return 0L; | 121 | return 0L; |
125 | } | 122 | } |
126 | - return (long) rateMeterMap.get(type).getOneMinuteRate() / | 123 | + return (long) (rateMeterMap.get(type).getOneMinuteRate() / |
127 | - (long) countMeterMap.get(type).getOneMinuteRate(); | 124 | + countMeterMap.get(type).getOneMinuteRate()); |
128 | } | 125 | } |
129 | 126 | ||
130 | /** | 127 | /** | ... | ... |
-
Please register or login to post a comment