chengfan
Committed by Gerrit Code Review

[ONOS-2233] Implement of Tunnel monitoring, measurement and observation

1. add a tunnel statistics interface.
2. add a pcep tunnel statistics interface.
3. add a tunnelStatsCollector to poll statistic request ,The polling interval can be configurable.
4. extend the pcepTunnelProvider to handle tunnel statistic message

Change-Id: I1187d586a1833ca4bee55529a65cd61eff0e612d
...@@ -112,4 +112,11 @@ public interface PcepController { ...@@ -112,4 +112,11 @@ public interface PcepController {
112 */ 112 */
113 Boolean updateTunnelBandwidth(String id, long bandwidth); 113 Boolean updateTunnelBandwidth(String id, long bandwidth);
114 114
115 + /**
116 + * Send statistic request by tunnel id.
117 + *
118 + * @param pcepTunnelId PCEP tunnel id
119 + */
120 + void getTunnelStatistics(String pcepTunnelId);
121 +
115 } 122 }
......
...@@ -28,4 +28,13 @@ public interface PcepTunnelListener { ...@@ -28,4 +28,13 @@ public interface PcepTunnelListener {
28 */ 28 */
29 void handlePCEPTunnel(PcepTunnel tunnel); 29 void handlePCEPTunnel(PcepTunnel tunnel);
30 30
31 + /**
32 + * Notify that get a tunnel statistic data from the network.
33 + *
34 + * @param tunnelStatistics tunnel statistic information.
35 + */
36 + void handlePcepTunnelStatistics(PcepTunnelStatistics tunnelStatistics);
37 +
38 +
39 +
31 } 40 }
......
1 +/*
2 + *
3 + * * Copyright 2015 Open Networking Laboratory
4 + * *
5 + * * Licensed under the Apache License, Version 2.0 (the "License");
6 + * * you may not use this file except in compliance with the License.
7 + * * You may obtain a copy of the License at
8 + * *
9 + * * http://www.apache.org/licenses/LICENSE-2.0
10 + * *
11 + * * Unless required by applicable law or agreed to in writing, software
12 + * * distributed under the License is distributed on an "AS IS" BASIS,
13 + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * * See the License for the specific language governing permissions and
15 + * * limitations under the License.
16 + *
17 + */
18 +
19 +package org.onosproject.pcep.api;
20 +
21 +import java.time.Duration;
22 +import java.util.List;
23 +
24 +/**
25 + * Statistics of a PCEP tunnel.
26 + */
27 +public interface PcepTunnelStatistics {
28 +
29 +
30 + /**
31 + * Returns the id of PCEP tunnel.
32 + *
33 + * @return PCEP tunnel id
34 + */
35 + long id();
36 +
37 +
38 + /**
39 + * Returns the bandwidth utilization of a PCEP tunnel.
40 + *
41 + * @return PCEP bandwidth utilization
42 + */
43 + double bandwidthUtilization();
44 +
45 + /**
46 + * Returns the flow loss rate of a tunnel.
47 + *
48 + * @return tunnel flow loss rate
49 + */
50 + double packetLossRate();
51 +
52 + /**
53 + * Returns the end-to-end traffic flow delay of a tunnel.
54 + *
55 + * @return tunnel traffic flow delay
56 + */
57 + Duration flowDelay();
58 +
59 + /**
60 + * Returns the alarms on a tunnel.
61 + *
62 + * @return tunnel alarms
63 + */
64 + List<String> alarms();
65 +}
1 +/*
2 + *
3 + * * Copyright 2015 Open Networking Laboratory
4 + * *
5 + * * Licensed under the Apache License, Version 2.0 (the "License");
6 + * * you may not use this file except in compliance with the License.
7 + * * You may obtain a copy of the License at
8 + * *
9 + * * http://www.apache.org/licenses/LICENSE-2.0
10 + * *
11 + * * Unless required by applicable law or agreed to in writing, software
12 + * * distributed under the License is distributed on an "AS IS" BASIS,
13 + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * * See the License for the specific language governing permissions and
15 + * * limitations under the License.
16 + *
17 + */
18 +
19 +package org.onosproject.incubator.net.tunnel;
20 +
21 +import java.time.Duration;
22 +import java.util.List;
23 +
24 +/**
25 + * Default implementation of immutable tunnel statistics.
26 + */
27 +public final class DefaultTunnelStatistics implements TunnelStatistics {
28 + private final TunnelId tunnelId;
29 + private final double bwUtilization;
30 + private final double packetLossRatio;
31 + private final Duration flowDelay;
32 + private final List<String> alarms;
33 +
34 + private DefaultTunnelStatistics(TunnelId tunnelId,
35 + double bwUtilization,
36 + double packetLossRatio,
37 + Duration flowDelay,
38 + List<String> alarms) {
39 + this.tunnelId = tunnelId;
40 + this.bwUtilization = bwUtilization;
41 + this.packetLossRatio = packetLossRatio;
42 + this.flowDelay = flowDelay;
43 + this.alarms = alarms;
44 + }
45 +
46 + private DefaultTunnelStatistics() {
47 + this.tunnelId = null;
48 + this.bwUtilization = 0;
49 + this.packetLossRatio = 0;
50 + this.flowDelay = null;
51 + this.alarms = null;
52 + }
53 +
54 +
55 + @Override
56 + public TunnelId id() {
57 + return this.tunnelId;
58 + }
59 +
60 + @Override
61 + public double bandwidthUtilization() {
62 + return this.bwUtilization;
63 + }
64 +
65 + @Override
66 + public double packetLossRate() {
67 + return this.packetLossRatio;
68 + }
69 +
70 + @Override
71 + public Duration flowDelay() {
72 + return this.flowDelay;
73 + }
74 +
75 +
76 + @Override
77 + public List<String> alarms() {
78 + return this.alarms;
79 + }
80 +
81 + /**
82 + * Builder for tunnelStatistics.
83 + */
84 + public static final class Builder {
85 + TunnelId tunnelId;
86 + double bwUtilization;
87 + double packetLossRatio;
88 + Duration flowDelay;
89 + List<String> alarms;
90 +
91 + public Builder() {
92 +
93 + }
94 +
95 + /**
96 + * Set tunnel id.
97 + *
98 + * @param tunnelId tunnel id
99 + * @return builder object
100 + */
101 + public Builder setTunnelId(TunnelId tunnelId) {
102 + this.tunnelId = tunnelId;
103 +
104 + return this;
105 + }
106 +
107 + /**
108 + * set bandwidth utilization.
109 + *
110 + * @param bwUtilization bandwidth utilization
111 + * @return builder object
112 + */
113 + public Builder setBwUtilization(double bwUtilization) {
114 + this.bwUtilization = bwUtilization;
115 +
116 + return this;
117 + }
118 +
119 + /**
120 + * Set packet loss ratio.
121 + *
122 + * @param packetLossRatio packet loss ratio
123 + * @return builder object
124 + */
125 + public Builder setPacketLossRatio(double packetLossRatio) {
126 + this.packetLossRatio = packetLossRatio;
127 +
128 + return this;
129 + }
130 +
131 + /**
132 + * Set flow delay.
133 + *
134 + * @param flowDelay flow delay
135 + * @return builder object
136 + */
137 + public Builder setFlowDelay(Duration flowDelay) {
138 + this.flowDelay = flowDelay;
139 +
140 + return this;
141 + }
142 +
143 + /**
144 + * Set alarms.
145 + *
146 + * @param alarms alarms of a tunnel
147 + * @return builder object
148 + */
149 + public Builder setAlarms(List<String> alarms) {
150 + this.alarms = alarms;
151 +
152 + return this;
153 + }
154 +
155 + /**
156 + * Creates a TunnelStatistics object.
157 + *
158 + * @return DefaultTunnelStatistics
159 + */
160 + public DefaultTunnelStatistics build() {
161 + return new DefaultTunnelStatistics(tunnelId,
162 + bwUtilization,
163 + packetLossRatio,
164 + flowDelay,
165 + alarms);
166 + }
167 + }
168 +}
...@@ -41,7 +41,7 @@ public interface TunnelStatistics { ...@@ -41,7 +41,7 @@ public interface TunnelStatistics {
41 double bandwidthUtilization(); 41 double bandwidthUtilization();
42 42
43 /** 43 /**
44 - * Returns the packet loss rate of a tunnel. 44 + * Returns the packet loss ratio of a tunnel.
45 * 45 *
46 * @return tunnel packet loss ratio 46 * @return tunnel packet loss ratio
47 */ 47 */
......
...@@ -19,5 +19,21 @@ ...@@ -19,5 +19,21 @@
19 <groupId>org.onosproject</groupId> 19 <groupId>org.onosproject</groupId>
20 <artifactId>onos-pcep-controller-api</artifactId> 20 <artifactId>onos-pcep-controller-api</artifactId>
21 </dependency> 21 </dependency>
22 + <dependency>
23 + <groupId>org.osgi</groupId>
24 + <artifactId>org.osgi.compendium</artifactId>
25 + </dependency>
26 + <dependency>
27 + <groupId>org.onosproject</groupId>
28 + <artifactId>onos-api</artifactId>
29 + <classifier>tests</classifier>
30 + <scope>test</scope>
31 + </dependency>
32 + <dependency>
33 + <groupId>org.onosproject</groupId>
34 + <artifactId>onos-incubator-net</artifactId>
35 + <version>${project.version} </version>
36 + <scope>test</scope>
37 + </dependency>
22 </dependencies> 38 </dependencies>
23 </project> 39 </project>
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
16 package org.onosproject.provider.pcep.tunnel.impl; 16 package org.onosproject.provider.pcep.tunnel.impl;
17 17
18 import static com.google.common.base.Preconditions.checkNotNull; 18 import static com.google.common.base.Preconditions.checkNotNull;
19 +import static com.google.common.base.Strings.isNullOrEmpty;
19 import static org.onosproject.net.DefaultAnnotations.EMPTY; 20 import static org.onosproject.net.DefaultAnnotations.EMPTY;
21 +import static org.onlab.util.Tools.get;
20 import static org.onosproject.net.DeviceId.deviceId; 22 import static org.onosproject.net.DeviceId.deviceId;
21 import static org.onosproject.net.PortNumber.portNumber; 23 import static org.onosproject.net.PortNumber.portNumber;
22 import static org.onosproject.pcep.api.PcepDpid.uri; 24 import static org.onosproject.pcep.api.PcepDpid.uri;
...@@ -24,24 +26,29 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -24,24 +26,29 @@ import static org.slf4j.LoggerFactory.getLogger;
24 26
25 import java.util.ArrayList; 27 import java.util.ArrayList;
26 import java.util.Collections; 28 import java.util.Collections;
29 +import java.util.Dictionary;
27 import java.util.HashMap; 30 import java.util.HashMap;
28 import java.util.LinkedList; 31 import java.util.LinkedList;
29 import java.util.List; 32 import java.util.List;
30 import java.util.ListIterator; 33 import java.util.ListIterator;
31 import java.util.Optional; 34 import java.util.Optional;
32 35
36 +import com.google.common.collect.Maps;
33 import org.apache.felix.scr.annotations.Activate; 37 import org.apache.felix.scr.annotations.Activate;
34 import org.apache.felix.scr.annotations.Component; 38 import org.apache.felix.scr.annotations.Component;
35 import org.apache.felix.scr.annotations.Deactivate; 39 import org.apache.felix.scr.annotations.Deactivate;
40 +import org.apache.felix.scr.annotations.Property;
36 import org.apache.felix.scr.annotations.Reference; 41 import org.apache.felix.scr.annotations.Reference;
37 import org.apache.felix.scr.annotations.ReferenceCardinality; 42 import org.apache.felix.scr.annotations.ReferenceCardinality;
38 import org.apache.felix.scr.annotations.Service; 43 import org.apache.felix.scr.annotations.Service;
39 import org.onlab.packet.IpAddress; 44 import org.onlab.packet.IpAddress;
45 +import org.onosproject.cfg.ComponentConfigService;
40 import org.onosproject.core.DefaultGroupId; 46 import org.onosproject.core.DefaultGroupId;
41 import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint; 47 import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint;
42 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 48 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
43 import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; 49 import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription;
44 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; 50 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
51 +import org.onosproject.incubator.net.tunnel.DefaultTunnelStatistics;
45 import org.onosproject.incubator.net.tunnel.OpticalLogicId; 52 import org.onosproject.incubator.net.tunnel.OpticalLogicId;
46 import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; 53 import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint;
47 import org.onosproject.incubator.net.tunnel.Tunnel; 54 import org.onosproject.incubator.net.tunnel.Tunnel;
...@@ -52,6 +59,8 @@ import org.onosproject.incubator.net.tunnel.TunnelName; ...@@ -52,6 +59,8 @@ import org.onosproject.incubator.net.tunnel.TunnelName;
52 import org.onosproject.incubator.net.tunnel.TunnelProvider; 59 import org.onosproject.incubator.net.tunnel.TunnelProvider;
53 import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; 60 import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry;
54 import org.onosproject.incubator.net.tunnel.TunnelProviderService; 61 import org.onosproject.incubator.net.tunnel.TunnelProviderService;
62 +import org.onosproject.incubator.net.tunnel.TunnelService;
63 +import org.onosproject.incubator.net.tunnel.TunnelStatistics;
55 import org.onosproject.net.ConnectPoint; 64 import org.onosproject.net.ConnectPoint;
56 import org.onosproject.net.DefaultAnnotations; 65 import org.onosproject.net.DefaultAnnotations;
57 import org.onosproject.net.DefaultLink; 66 import org.onosproject.net.DefaultLink;
...@@ -73,6 +82,8 @@ import org.onosproject.pcep.api.PcepTunnel; ...@@ -73,6 +82,8 @@ import org.onosproject.pcep.api.PcepTunnel;
73 import org.onosproject.pcep.api.PcepTunnel.PATHTYPE; 82 import org.onosproject.pcep.api.PcepTunnel.PATHTYPE;
74 import org.onosproject.pcep.api.PcepTunnel.PathState; 83 import org.onosproject.pcep.api.PcepTunnel.PathState;
75 import org.onosproject.pcep.api.PcepTunnelListener; 84 import org.onosproject.pcep.api.PcepTunnelListener;
85 +import org.onosproject.pcep.api.PcepTunnelStatistics;
86 +import org.osgi.service.component.annotations.Modified;
76 import org.onosproject.pcep.controller.PccId; 87 import org.onosproject.pcep.controller.PccId;
77 import org.onosproject.pcep.controller.PcepClient; 88 import org.onosproject.pcep.controller.PcepClient;
78 import org.onosproject.pcep.controller.PcepClientController; 89 import org.onosproject.pcep.controller.PcepClientController;
...@@ -99,8 +110,7 @@ import org.onosproject.pcepio.types.PcepValueType; ...@@ -99,8 +110,7 @@ import org.onosproject.pcepio.types.PcepValueType;
99 import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; 110 import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv;
100 import org.onosproject.pcepio.types.SymbolicPathNameTlv; 111 import org.onosproject.pcepio.types.SymbolicPathNameTlv;
101 import org.slf4j.Logger; 112 import org.slf4j.Logger;
102 - 113 +import org.osgi.service.component.ComponentContext;
103 -import static org.onosproject.pcep.api.PcepDpid.*;
104 114
105 /** 115 /**
106 * Provider which uses an PCEP controller to detect, update, create network 116 * Provider which uses an PCEP controller to detect, update, create network
...@@ -116,6 +126,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -116,6 +126,11 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
116 private static final String BANDWIDTH_UINT = "kbps"; 126 private static final String BANDWIDTH_UINT = "kbps";
117 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep"; 127 static final String PROVIDER_ID = "org.onosproject.provider.tunnel.pcep";
118 128
129 + static final int POLL_INTERVAL = 10;
130 + @Property(name = "tunnelStatsPollFrequency", intValue = POLL_INTERVAL,
131 + label = "Frequency (in seconds) for polling tunnel statistics")
132 + private int tunnelStatsPollFrequency = POLL_INTERVAL;
133 +
119 private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied."; 134 private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied.";
120 135
121 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 136 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -126,9 +141,18 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -126,9 +141,18 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
126 141
127 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 142 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
128 protected PcepClientController pcepClientController; 143 protected PcepClientController pcepClientController;
144 +
145 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
146 + protected TunnelService tunnelService;
147 +
148 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
149 + protected ComponentConfigService cfgService;
150 +
129 TunnelProviderService service; 151 TunnelProviderService service;
130 152
131 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); 153 HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>();
154 + HashMap<TunnelId, TunnelStatistics> tunnelStatisticsMap = new HashMap<>();
155 + private HashMap<Long, TunnelStatsCollector> collectors = Maps.newHashMap();
132 156
133 private InnerTunnelProvider listener = new InnerTunnelProvider(); 157 private InnerTunnelProvider listener = new InnerTunnelProvider();
134 158
...@@ -144,10 +168,19 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -144,10 +168,19 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
144 168
145 @Activate 169 @Activate
146 public void activate() { 170 public void activate() {
171 + cfgService.registerProperties(getClass());
147 service = tunnelProviderRegistry.register(this); 172 service = tunnelProviderRegistry.register(this);
148 controller.addTunnelListener(listener); 173 controller.addTunnelListener(listener);
149 pcepClientController.addListener(listener); 174 pcepClientController.addListener(listener);
150 pcepClientController.addEventListener(listener); 175 pcepClientController.addEventListener(listener);
176 + tunnelService.queryAllTunnels().forEach(tunnel -> {
177 + String pcepTunnelId = getPCEPTunnelKey(tunnel.tunnelId());
178 + TunnelStatsCollector tsc = new TunnelStatsCollector(pcepTunnelId, tunnelStatsPollFrequency);
179 + tsc.start();
180 + collectors.put(tunnel.tunnelId().id(), tsc);
181 +
182 + });
183 +
151 log.info("Started"); 184 log.info("Started");
152 } 185 }
153 186
...@@ -155,10 +188,31 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -155,10 +188,31 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
155 public void deactivate() { 188 public void deactivate() {
156 tunnelProviderRegistry.unregister(this); 189 tunnelProviderRegistry.unregister(this);
157 controller.removeTunnelListener(listener); 190 controller.removeTunnelListener(listener);
191 + collectors.values().forEach(TunnelStatsCollector::stop);
158 pcepClientController.removeListener(listener); 192 pcepClientController.removeListener(listener);
159 log.info("Stopped"); 193 log.info("Stopped");
160 } 194 }
161 195
196 + @Modified
197 + public void modified(ComponentContext context) {
198 + Dictionary<?, ?> properties = context.getProperties();
199 + int newTunnelStatsPollFrequency;
200 + try {
201 + String s = get(properties, "tunnelStatsPollFrequency");
202 + newTunnelStatsPollFrequency = isNullOrEmpty(s) ? tunnelStatsPollFrequency : Integer.parseInt(s.trim());
203 +
204 + } catch (NumberFormatException | ClassCastException e) {
205 + newTunnelStatsPollFrequency = tunnelStatsPollFrequency;
206 + }
207 +
208 + if (newTunnelStatsPollFrequency != tunnelStatsPollFrequency) {
209 + tunnelStatsPollFrequency = newTunnelStatsPollFrequency;
210 + collectors.values().forEach(tsc -> tsc.adjustPollInterval(tunnelStatsPollFrequency));
211 + log.info("New setting: tunnelStatsPollFrequency={}", tunnelStatsPollFrequency);
212 + }
213 +
214 + }
215 +
162 @Override 216 @Override
163 public void setupTunnel(Tunnel tunnel, Path path) { 217 public void setupTunnel(Tunnel tunnel, Path path) {
164 if (tunnel.type() != Tunnel.Type.MPLS) { 218 if (tunnel.type() != Tunnel.Type.MPLS) {
...@@ -581,6 +635,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -581,6 +635,21 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
581 } 635 }
582 636
583 /** 637 /**
638 + * Build a DefaultTunnelStatistics from a PcepTunnelStatistics.
639 + *
640 + * @param statistics statistics data from a PCEP tunnel
641 + * @return TunnelStatistics
642 + */
643 + private TunnelStatistics buildTunnelStatistics(PcepTunnelStatistics statistics) {
644 + DefaultTunnelStatistics.Builder builder = new DefaultTunnelStatistics.Builder();
645 + DefaultTunnelStatistics tunnelStatistics = builder.setBwUtilization(statistics.bandwidthUtilization())
646 + .setPacketLossRatio(statistics.packetLossRate())
647 + .setFlowDelay(statistics.flowDelay())
648 + .setAlarms(statistics.alarms())
649 + .build();
650 + return tunnelStatistics;
651 + }
652 + /**
584 * Creates list of hops for ERO object from Path. 653 * Creates list of hops for ERO object from Path.
585 * 654 *
586 * @param path network path 655 * @param path network path
...@@ -844,6 +913,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -844,6 +913,8 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
844 } 913 }
845 } 914 }
846 915
916 +
917 +
847 private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener { 918 private class InnerTunnelProvider implements PcepTunnelListener, PcepEventListener, PcepClientListener {
848 919
849 @Override 920 @Override
...@@ -1141,6 +1212,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid ...@@ -1141,6 +1212,15 @@ public class PcepTunnelProvider extends AbstractProvider implements TunnelProvid
1141 public void clientDisconnected(PccId pccId) { 1212 public void clientDisconnected(PccId pccId) {
1142 // TODO 1213 // TODO
1143 } 1214 }
1215 +
1216 +
1217 +
1218 + @Override
1219 + public void handlePcepTunnelStatistics(PcepTunnelStatistics pcepTunnelStatistics) {
1220 + TunnelId id = getTunnelId(String.valueOf(pcepTunnelStatistics.id()));
1221 + TunnelStatistics tunnelStatistics = buildTunnelStatistics(pcepTunnelStatistics);
1222 + tunnelStatisticsMap.put(id, tunnelStatistics);
1223 + }
1144 } 1224 }
1145 1225
1146 @Override 1226 @Override
......
1 +/*
2 + *
3 + * * Copyright 2014-2015 Open Networking Laboratory
4 + * *
5 + * * Licensed under the Apache License, Version 2.0 (the "License");
6 + * * you may not use this file except in compliance with the License.
7 + * * You may obtain a copy of the License at
8 + * *
9 + * * http://www.apache.org/licenses/LICENSE-2.0
10 + * *
11 + * * Unless required by applicable law or agreed to in writing, software
12 + * * distributed under the License is distributed on an "AS IS" BASIS,
13 + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + * * See the License for the specific language governing permissions and
15 + * * limitations under the License.
16 + *
17 + */
18 +
19 +package org.onosproject.provider.pcep.tunnel.impl;
20 +
21 +
22 +import org.apache.felix.scr.annotations.Reference;
23 +import org.apache.felix.scr.annotations.ReferenceCardinality;
24 +import org.jboss.netty.util.HashedWheelTimer;
25 +import org.jboss.netty.util.Timeout;
26 +import org.jboss.netty.util.TimerTask;
27 +import org.onlab.util.Timer;
28 +import org.onosproject.pcep.api.PcepController;
29 +import org.slf4j.Logger;
30 +import org.slf4j.LoggerFactory;
31 +
32 +import java.util.concurrent.TimeUnit;
33 +
34 +/*
35 + * Sends Stats Request and collect the tunnel statistics with a time interval.
36 + */
37 +public class TunnelStatsCollector implements TimerTask {
38 + private final Logger log = LoggerFactory.getLogger(getClass());
39 +
40 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
41 + protected PcepController controller;
42 +
43 + private int refreshInterval;
44 + private final HashedWheelTimer timer = Timer.getTimer();
45 +
46 + private String pcepTunnelId;
47 + private Timeout timeout;
48 + private volatile boolean stopped;
49 +
50 +
51 + /**
52 + * Greate a tunnel status collector object.
53 + *
54 + * @param id tunnel whose status data will be collected
55 + * @param refreshInterval time interval for collecting statistic
56 + */
57 + public TunnelStatsCollector(String id, int refreshInterval) {
58 + this.pcepTunnelId = id;
59 + this.refreshInterval = refreshInterval;
60 + }
61 +
62 + @Override
63 + public void run(Timeout timeout) throws Exception {
64 + if (stopped || timeout.isCancelled()) {
65 + return;
66 + }
67 + log.trace("Collecting stats for {}", pcepTunnelId);
68 +
69 + sendTunnelStatistic();
70 + if (!stopped && !timeout.isCancelled()) {
71 + log.trace("Scheduling stats collection in {} seconds for {}",
72 + this.refreshInterval, pcepTunnelId);
73 + timeout.getTimer().newTimeout(this, refreshInterval, TimeUnit.SECONDS);
74 + }
75 +
76 + }
77 +
78 + private void sendTunnelStatistic() {
79 + controller.getTunnelStatistics(pcepTunnelId);
80 +
81 + }
82 +
83 + synchronized void adjustPollInterval(int pollInterval) {
84 + this.refreshInterval = pollInterval;
85 + }
86 +
87 + /**
88 + * Starts the collector.
89 + */
90 + public synchronized void start() {
91 + log.info("Starting Tunnel Stats collection thread for {}", pcepTunnelId);
92 + stopped = false;
93 + timeout = timer.newTimeout(this, 1, TimeUnit.SECONDS);
94 + }
95 +
96 + /**
97 + * Stops the collector.
98 + */
99 + public synchronized void stop() {
100 + log.info("Stopping Tunnel Stats collection thread for {}", pcepTunnelId);
101 + stopped = true;
102 + timeout.cancel();
103 + }
104 +}
...@@ -77,4 +77,9 @@ public class PcepControllerAdapter implements PcepController { ...@@ -77,4 +77,9 @@ public class PcepControllerAdapter implements PcepController {
77 public Boolean updateTunnelBandwidth(String id, long bandwidth) { 77 public Boolean updateTunnelBandwidth(String id, long bandwidth) {
78 return null; 78 return null;
79 } 79 }
80 +
81 + @Override
82 + public void getTunnelStatistics(String pcepTunnelId) {
83 +
84 + }
80 } 85 }
......
...@@ -24,6 +24,7 @@ import java.util.List; ...@@ -24,6 +24,7 @@ import java.util.List;
24 import org.junit.After; 24 import org.junit.After;
25 import org.junit.Test; 25 import org.junit.Test;
26 import org.onlab.packet.IpAddress; 26 import org.onlab.packet.IpAddress;
27 +import org.onosproject.cfg.ComponentConfigAdapter;
27 import org.onosproject.core.DefaultGroupId; 28 import org.onosproject.core.DefaultGroupId;
28 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 29 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
29 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; 30 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
...@@ -49,13 +50,16 @@ public class PcepReleaseTunnelProviderTest { ...@@ -49,13 +50,16 @@ public class PcepReleaseTunnelProviderTest {
49 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 50 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
50 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 51 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
51 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); 52 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
53 + private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
52 54
53 @Test 55 @Test
54 public void testCasePcepReleaseTunnel() { 56 public void testCasePcepReleaseTunnel() {
55 tunnelProvider.tunnelProviderRegistry = registry; 57 tunnelProvider.tunnelProviderRegistry = registry;
56 tunnelProvider.pcepClientController = controller; 58 tunnelProvider.pcepClientController = controller;
57 tunnelProvider.controller = ctl; 59 tunnelProvider.controller = ctl;
60 + tunnelProvider.tunnelService = tunnelService;
58 tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper; 61 tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper;
62 + tunnelProvider.cfgService = new ComponentConfigAdapter();
59 tunnelProvider.activate(); 63 tunnelProvider.activate();
60 64
61 Tunnel tunnel; 65 Tunnel tunnel;
......
...@@ -24,6 +24,7 @@ import java.util.List; ...@@ -24,6 +24,7 @@ import java.util.List;
24 import org.junit.After; 24 import org.junit.After;
25 import org.junit.Test; 25 import org.junit.Test;
26 import org.onlab.packet.IpAddress; 26 import org.onlab.packet.IpAddress;
27 +import org.onosproject.cfg.ComponentConfigAdapter;
27 import org.onosproject.core.DefaultGroupId; 28 import org.onosproject.core.DefaultGroupId;
28 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 29 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
29 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; 30 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
...@@ -46,6 +47,7 @@ public class PcepSetupTunnelProviderTest { ...@@ -46,6 +47,7 @@ public class PcepSetupTunnelProviderTest {
46 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); 47 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
47 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 48 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
48 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 49 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
50 + private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
49 51
50 @Test 52 @Test
51 public void testCasePcepSetupTunnel() { 53 public void testCasePcepSetupTunnel() {
...@@ -53,6 +55,8 @@ public class PcepSetupTunnelProviderTest { ...@@ -53,6 +55,8 @@ public class PcepSetupTunnelProviderTest {
53 tunnelProvider.tunnelProviderRegistry = registry; 55 tunnelProvider.tunnelProviderRegistry = registry;
54 tunnelProvider.pcepClientController = controller; 56 tunnelProvider.pcepClientController = controller;
55 tunnelProvider.controller = ctl; 57 tunnelProvider.controller = ctl;
58 + tunnelProvider.cfgService = new ComponentConfigAdapter();
59 + tunnelProvider.tunnelService = tunnelService;
56 tunnelProvider.activate(); 60 tunnelProvider.activate();
57 61
58 62
......
...@@ -38,6 +38,7 @@ import org.onosproject.net.Link; ...@@ -38,6 +38,7 @@ import org.onosproject.net.Link;
38 import org.onosproject.net.Path; 38 import org.onosproject.net.Path;
39 import org.onosproject.net.PortNumber; 39 import org.onosproject.net.PortNumber;
40 import org.onosproject.net.provider.ProviderId; 40 import org.onosproject.net.provider.ProviderId;
41 +import org.onosproject.cfg.ComponentConfigAdapter;
41 42
42 public class PcepTunnelProviderTest { 43 public class PcepTunnelProviderTest {
43 44
...@@ -46,6 +47,7 @@ public class PcepTunnelProviderTest { ...@@ -46,6 +47,7 @@ public class PcepTunnelProviderTest {
46 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter(); 47 private final TunnelProviderRegistryAdapter registry = new TunnelProviderRegistryAdapter();
47 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 48 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
48 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 49 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
50 + private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
49 51
50 @Test 52 @Test
51 public void testCasePcepSetupTunnel() { 53 public void testCasePcepSetupTunnel() {
...@@ -53,6 +55,8 @@ public class PcepTunnelProviderTest { ...@@ -53,6 +55,8 @@ public class PcepTunnelProviderTest {
53 tunnelProvider.tunnelProviderRegistry = registry; 55 tunnelProvider.tunnelProviderRegistry = registry;
54 tunnelProvider.pcepClientController = controller; 56 tunnelProvider.pcepClientController = controller;
55 tunnelProvider.controller = ctl; 57 tunnelProvider.controller = ctl;
58 + tunnelProvider.cfgService = new ComponentConfigAdapter();
59 + tunnelProvider.tunnelService = tunnelService;
56 tunnelProvider.activate(); 60 tunnelProvider.activate();
57 61
58 Tunnel tunnel; 62 Tunnel tunnel;
......
...@@ -24,6 +24,7 @@ import java.util.List; ...@@ -24,6 +24,7 @@ import java.util.List;
24 import org.junit.After; 24 import org.junit.After;
25 import org.junit.Test; 25 import org.junit.Test;
26 import org.onlab.packet.IpAddress; 26 import org.onlab.packet.IpAddress;
27 +import org.onosproject.cfg.ComponentConfigAdapter;
27 import org.onosproject.core.DefaultGroupId; 28 import org.onosproject.core.DefaultGroupId;
28 import org.onosproject.incubator.net.tunnel.DefaultTunnel; 29 import org.onosproject.incubator.net.tunnel.DefaultTunnel;
29 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint; 30 import org.onosproject.incubator.net.tunnel.IpTunnelEndPoint;
...@@ -49,6 +50,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -49,6 +50,8 @@ public class PcepUpdateTunnelProviderTest {
49 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter(); 50 private final PcepClientControllerAdapter controller = new PcepClientControllerAdapter();
50 private final PcepControllerAdapter ctl = new PcepControllerAdapter(); 51 private final PcepControllerAdapter ctl = new PcepControllerAdapter();
51 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper(); 52 private final PcepTunnelApiMapper pcepTunnelAPIMapper = new PcepTunnelApiMapper();
53 + private final TunnelServiceAdapter tunnelService = new TunnelServiceAdapter();
54 +
52 55
53 @Test 56 @Test
54 public void testCasePcepUpdateTunnel() { 57 public void testCasePcepUpdateTunnel() {
...@@ -56,6 +59,8 @@ public class PcepUpdateTunnelProviderTest { ...@@ -56,6 +59,8 @@ public class PcepUpdateTunnelProviderTest {
56 tunnelProvider.pcepClientController = controller; 59 tunnelProvider.pcepClientController = controller;
57 tunnelProvider.controller = ctl; 60 tunnelProvider.controller = ctl;
58 tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper; 61 tunnelProvider.pcepTunnelAPIMapper = pcepTunnelAPIMapper;
62 + tunnelProvider.cfgService = new ComponentConfigAdapter();
63 + tunnelProvider.tunnelService = tunnelService;
59 tunnelProvider.activate(); 64 tunnelProvider.activate();
60 65
61 Tunnel tunnel; 66 Tunnel tunnel;
......
1 +package org.onosproject.provider.pcep.tunnel.impl;
2 +
3 +import org.onosproject.core.ApplicationId;
4 +import org.onosproject.incubator.net.tunnel.Tunnel;
5 +import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
6 +import org.onosproject.incubator.net.tunnel.TunnelId;
7 +import org.onosproject.incubator.net.tunnel.TunnelListener;
8 +import org.onosproject.incubator.net.tunnel.TunnelName;
9 +import org.onosproject.incubator.net.tunnel.TunnelService;
10 +import org.onosproject.incubator.net.tunnel.TunnelSubscription;
11 +import org.onosproject.net.Annotations;
12 +import org.onosproject.net.DeviceId;
13 +
14 +import java.util.Collection;
15 +import java.util.Collections;
16 +
17 +public class TunnelServiceAdapter implements TunnelService {
18 + @Override
19 + public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId, Annotations... annotations) {
20 + return null;
21 + }
22 +
23 + @Override
24 + public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelName tunnelName,
25 + Annotations... annotations) {
26 + return null;
27 + }
28 +
29 + @Override
30 + public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst,
31 + Annotations... annotations) {
32 + return null;
33 + }
34 +
35 + @Override
36 + public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst,
37 + Tunnel.Type type, Annotations... annotations) {
38 + return null;
39 + }
40 +
41 + @Override
42 + public boolean returnTunnel(ApplicationId consumerId, TunnelId tunnelId, Annotations... annotations) {
43 + return false;
44 + }
45 +
46 + @Override
47 + public boolean returnTunnel(ApplicationId consumerId, TunnelName tunnelName, Annotations... annotations) {
48 + return false;
49 + }
50 +
51 + @Override
52 + public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst,
53 + Tunnel.Type type, Annotations... annotations) {
54 + return false;
55 + }
56 +
57 + @Override
58 + public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, TunnelEndPoint dst,
59 + Annotations... annotations) {
60 + return false;
61 + }
62 +
63 + @Override
64 + public Tunnel queryTunnel(TunnelId tunnelId) {
65 + return null;
66 + }
67 +
68 + @Override
69 + public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) {
70 + return null;
71 + }
72 +
73 + @Override
74 + public Collection<Tunnel> queryTunnel(Tunnel.Type type) {
75 + return null;
76 + }
77 +
78 + @Override
79 + public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
80 + return null;
81 + }
82 +
83 + @Override
84 + public Collection<Tunnel> queryAllTunnels() {
85 + return Collections.emptyList();
86 + }
87 +
88 + @Override
89 + public int tunnelCount() {
90 + return 0;
91 + }
92 +
93 + @Override
94 + public Iterable<Tunnel> getTunnels(DeviceId deviceId) {
95 + return null;
96 + }
97 +
98 + @Override
99 + public void addListener(TunnelListener listener) {
100 +
101 + }
102 +
103 + @Override
104 + public void removeListener(TunnelListener listener) {
105 +
106 + }
107 +}