Jian Li
Committed by Gerrit Code Review

Refactor the logic on collecting OpenFlow message statistics

Change-Id: I34c209c0ca90cb094ed5f82c96a8a43d3519b807
Showing 21 changed files with 157 additions and 1032 deletions
...@@ -65,13 +65,6 @@ public interface OpenFlowController { ...@@ -65,13 +65,6 @@ public interface OpenFlowController {
65 OpenFlowSwitch getEqualSwitch(Dpid dpid); 65 OpenFlowSwitch getEqualSwitch(Dpid dpid);
66 66
67 /** 67 /**
68 - * If this set to be true, all incoming events are monitored.
69 - * Other wise, only stats related incoming events are monitored
70 - * @param monitor monitoring flag
71 - */
72 - void monitorAllEvents(boolean monitor);
73 -
74 - /**
75 * Register a listener for meta events that occur to OF 68 * Register a listener for meta events that occur to OF
76 * devices. 69 * devices.
77 * @param listener the listener to notify 70 * @param listener the listener to notify
...@@ -86,6 +79,20 @@ public interface OpenFlowController { ...@@ -86,6 +79,20 @@ public interface OpenFlowController {
86 void removeListener(OpenFlowSwitchListener listener); 79 void removeListener(OpenFlowSwitchListener listener);
87 80
88 /** 81 /**
82 + * Register a listener for all OF msg types.
83 + *
84 + * @param listener the listener to notify
85 + */
86 + void addMessageListener(OpenFlowMessageListener listener);
87 +
88 + /**
89 + * Unregister a listener for all OF msg types.
90 + *
91 + * @param listener the listener to notify
92 + */
93 + void removeMessageListener(OpenFlowMessageListener listener);
94 +
95 + /**
89 * Register a listener for packet events. 96 * Register a listener for packet events.
90 * @param priority the importance of this listener, lower values are more important 97 * @param priority the importance of this listener, lower values are more important
91 * @param listener the listener to notify 98 * @param listener the listener to notify
......
1 +/*
2 + * Copyright 2016-present 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.openflow.controller;
17 +
18 +import org.projectfloodlight.openflow.protocol.OFMessage;
19 +
20 +import java.util.List;
21 +
22 +/**
23 + * Notifies providers about all OpenFlow messages.
24 + */
25 +public interface OpenFlowMessageListener {
26 +
27 + /**
28 + * Handles all incoming OpenFlow messages.
29 + *
30 + * @param dpid the switch where the message generated
31 + * @param msg raw OpenFlow message
32 + */
33 + void handleIncomingMessage(Dpid dpid, OFMessage msg);
34 +
35 + /**
36 + * Handles all outgoing OpenFlow messages.
37 + *
38 + * @param dpid the switch where the message to be sent
39 + * @param msgs a collection of raw OpenFlow message
40 + */
41 + void handleOutgoingMessage(Dpid dpid, List<OFMessage> msgs);
42 +}
...@@ -157,18 +157,4 @@ public interface OpenFlowSwitch { ...@@ -157,18 +157,4 @@ public interface OpenFlowSwitch {
157 * @return string representation of the connection to the device 157 * @return string representation of the connection to the device
158 */ 158 */
159 String channelId(); 159 String channelId();
160 -
161 - /**
162 - * Registers a listener for OF msg events.
163 - *
164 - * @param listener the listener to notify
165 - */
166 - void addEventListener(OpenFlowEventListener listener);
167 -
168 - /**
169 - * Unregisters a listener.
170 - *
171 - * @param listener the listener to unregister
172 - */
173 - void removeEventListener(OpenFlowEventListener listener);
174 } 160 }
......
...@@ -22,7 +22,6 @@ import org.onlab.packet.IpAddress; ...@@ -22,7 +22,6 @@ import org.onlab.packet.IpAddress;
22 import org.onosproject.net.Device; 22 import org.onosproject.net.Device;
23 import org.onosproject.net.driver.AbstractHandlerBehaviour; 23 import org.onosproject.net.driver.AbstractHandlerBehaviour;
24 import org.onosproject.openflow.controller.Dpid; 24 import org.onosproject.openflow.controller.Dpid;
25 -import org.onosproject.openflow.controller.OpenFlowEventListener;
26 import org.onosproject.openflow.controller.RoleState; 25 import org.onosproject.openflow.controller.RoleState;
27 import org.projectfloodlight.openflow.protocol.OFDescStatsReply; 26 import org.projectfloodlight.openflow.protocol.OFDescStatsReply;
28 import org.projectfloodlight.openflow.protocol.OFErrorMsg; 27 import org.projectfloodlight.openflow.protocol.OFErrorMsg;
...@@ -37,7 +36,6 @@ import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; ...@@ -37,7 +36,6 @@ import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
37 import org.projectfloodlight.openflow.protocol.OFPortStatus; 36 import org.projectfloodlight.openflow.protocol.OFPortStatus;
38 import org.projectfloodlight.openflow.protocol.OFRoleReply; 37 import org.projectfloodlight.openflow.protocol.OFRoleReply;
39 import org.projectfloodlight.openflow.protocol.OFRoleRequest; 38 import org.projectfloodlight.openflow.protocol.OFRoleRequest;
40 -import org.projectfloodlight.openflow.protocol.OFType;
41 import org.projectfloodlight.openflow.protocol.OFVersion; 39 import org.projectfloodlight.openflow.protocol.OFVersion;
42 import org.slf4j.Logger; 40 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory; 41 import org.slf4j.LoggerFactory;
...@@ -48,16 +46,10 @@ import java.net.SocketAddress; ...@@ -48,16 +46,10 @@ import java.net.SocketAddress;
48 import java.util.ArrayList; 46 import java.util.ArrayList;
49 import java.util.Collections; 47 import java.util.Collections;
50 import java.util.List; 48 import java.util.List;
51 -import java.util.Set;
52 -import java.util.concurrent.CopyOnWriteArraySet;
53 -import java.util.concurrent.ExecutorService;
54 -import java.util.concurrent.Executors;
55 import java.util.concurrent.atomic.AtomicInteger; 49 import java.util.concurrent.atomic.AtomicInteger;
56 import java.util.concurrent.atomic.AtomicReference; 50 import java.util.concurrent.atomic.AtomicReference;
57 import java.util.stream.Collectors; 51 import java.util.stream.Collectors;
58 52
59 -import static org.onlab.util.Tools.groupedThreads;
60 -
61 /** 53 /**
62 * An abstract representation of an OpenFlow switch. Can be extended by others 54 * An abstract representation of an OpenFlow switch. Can be extended by others
63 * to serve as a base for their vendor specific representation of a switch. 55 * to serve as a base for their vendor specific representation of a switch.
...@@ -90,11 +82,6 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -90,11 +82,6 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
90 protected OFFeaturesReply features; 82 protected OFFeaturesReply features;
91 protected OFDescStatsReply desc; 83 protected OFDescStatsReply desc;
92 84
93 - protected Set<OpenFlowEventListener> ofOutgoingMsgListener = new CopyOnWriteArraySet<>();
94 -
95 - protected ExecutorService executorMsgs =
96 - Executors.newCachedThreadPool(groupedThreads("onos/of", "event-outgoing-msg-stats-%d", log));
97 -
98 // messagesPendingMastership is used as synchronization variable for 85 // messagesPendingMastership is used as synchronization variable for
99 // all mastership related changes. In this block, mastership (including 86 // all mastership related changes. In this block, mastership (including
100 // role update) will have either occurred or not. 87 // role update) will have either occurred or not.
...@@ -133,9 +120,9 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -133,9 +120,9 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
133 a synchronization primitive, because the message would have just been 120 a synchronization primitive, because the message would have just been
134 dropped anyway. 121 dropped anyway.
135 */ 122 */
123 +
136 if (role == RoleState.MASTER) { 124 if (role == RoleState.MASTER) {
137 // fast path send when we are master 125 // fast path send when we are master
138 -
139 sendMsgsOnChannel(msgs); 126 sendMsgsOnChannel(msgs);
140 return; 127 return;
141 } 128 }
...@@ -166,23 +153,10 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -166,23 +153,10 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
166 } 153 }
167 } 154 }
168 155
169 - private void countOutgoingMsg(List<OFMessage> msgs) {
170 - // listen to outgoing control messages only if listeners are registered
171 - if (ofOutgoingMsgListener.size() != 0) {
172 - msgs.forEach(m -> {
173 - if (m.getType() == OFType.PACKET_OUT ||
174 - m.getType() == OFType.FLOW_MOD ||
175 - m.getType() == OFType.STATS_REQUEST) {
176 - executorMsgs.execute(new OFMessageHandler(dpid, m));
177 - }
178 - });
179 - }
180 - }
181 -
182 private void sendMsgsOnChannel(List<OFMessage> msgs) { 156 private void sendMsgsOnChannel(List<OFMessage> msgs) {
183 if (channel.isConnected()) { 157 if (channel.isConnected()) {
184 channel.write(msgs); 158 channel.write(msgs);
185 - countOutgoingMsg(msgs); 159 + agent.processDownstreamMessage(dpid, msgs);
186 } else { 160 } else {
187 log.warn("Dropping messages for switch {} because channel is not connected: {}", 161 log.warn("Dropping messages for switch {} because channel is not connected: {}",
188 dpid, msgs); 162 dpid, msgs);
...@@ -335,16 +309,6 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -335,16 +309,6 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
335 } 309 }
336 310
337 @Override 311 @Override
338 - public void addEventListener(OpenFlowEventListener listener) {
339 - ofOutgoingMsgListener.add(listener);
340 - }
341 -
342 - @Override
343 - public void removeEventListener(OpenFlowEventListener listener) {
344 - ofOutgoingMsgListener.remove(listener);
345 - }
346 -
347 - @Override
348 public OFFactory factory() { 312 public OFFactory factory() {
349 return OFFactories.getFactory(ofVersion); 313 return OFFactories.getFactory(ofVersion);
350 } 314 }
...@@ -535,25 +499,4 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour ...@@ -535,25 +499,4 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour
535 ? channel.getRemoteAddress() : "?") 499 ? channel.getRemoteAddress() : "?")
536 + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; 500 + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]";
537 } 501 }
538 -
539 - /**
540 - * OpenFlow message handler for outgoing control messages.
541 - */
542 - protected final class OFMessageHandler implements Runnable {
543 -
544 - protected final OFMessage msg;
545 - protected final Dpid dpid;
546 -
547 - public OFMessageHandler(Dpid dpid, OFMessage msg) {
548 - this.msg = msg;
549 - this.dpid = dpid;
550 - }
551 -
552 - @Override
553 - public void run() {
554 - for (OpenFlowEventListener listener : ofOutgoingMsgListener) {
555 - listener.handleMessage(dpid, msg);
556 - }
557 - }
558 - }
559 } 502 }
......
...@@ -20,6 +20,8 @@ import org.onosproject.openflow.controller.OpenFlowSwitch; ...@@ -20,6 +20,8 @@ import org.onosproject.openflow.controller.OpenFlowSwitch;
20 import org.onosproject.openflow.controller.RoleState; 20 import org.onosproject.openflow.controller.RoleState;
21 import org.projectfloodlight.openflow.protocol.OFMessage; 21 import org.projectfloodlight.openflow.protocol.OFMessage;
22 22
23 +import java.util.List;
24 +
23 /** 25 /**
24 * Responsible for keeping track of the current set of switches 26 * Responsible for keeping track of the current set of switches
25 * connected to the system. As well as whether they are in Master 27 * connected to the system. As well as whether they are in Master
...@@ -84,6 +86,14 @@ public interface OpenFlowAgent { ...@@ -84,6 +86,14 @@ public interface OpenFlowAgent {
84 void removeConnectedSwitch(Dpid dpid); 86 void removeConnectedSwitch(Dpid dpid);
85 87
86 /** 88 /**
89 + * Notify OpenFlow message listeners on all outgoing message event.
90 + *
91 + * @param dpid the dpid the message sent to
92 + * @param m the collection of messages to sent out
93 + */
94 + void processDownstreamMessage(Dpid dpid, List<OFMessage> m);
95 +
96 + /**
87 * Process a message coming from a switch. 97 * Process a message coming from a switch.
88 * 98 *
89 * @param dpid the dpid the message came on. 99 * @param dpid the dpid the message came on.
......
...@@ -52,15 +52,21 @@ public class OpenflowControllerAdapter implements OpenFlowController { ...@@ -52,15 +52,21 @@ public class OpenflowControllerAdapter implements OpenFlowController {
52 } 52 }
53 53
54 @Override 54 @Override
55 - public void monitorAllEvents(boolean monitor) { 55 + public void addListener(OpenFlowSwitchListener listener) {
56 } 56 }
57 57
58 @Override 58 @Override
59 - public void addListener(OpenFlowSwitchListener listener) { 59 + public void removeListener(OpenFlowSwitchListener listener) {
60 } 60 }
61 61
62 @Override 62 @Override
63 - public void removeListener(OpenFlowSwitchListener listener) { 63 + public void addMessageListener(OpenFlowMessageListener listener) {
64 +
65 + }
66 +
67 + @Override
68 + public void removeMessageListener(OpenFlowMessageListener listener) {
69 +
64 } 70 }
65 71
66 @Override 72 @Override
......
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.driver;
17 -
18 -import org.jboss.netty.channel.Channel;
19 -import org.jboss.netty.channel.ChannelConfig;
20 -import org.jboss.netty.channel.ChannelFactory;
21 -import org.jboss.netty.channel.ChannelFuture;
22 -import org.jboss.netty.channel.ChannelPipeline;
23 -import org.junit.Before;
24 -import org.junit.Test;
25 -import org.onosproject.openflow.controller.Dpid;
26 -import org.onosproject.openflow.controller.OpenFlowEventListener;
27 -import org.onosproject.openflow.controller.RoleState;
28 -import org.projectfloodlight.openflow.protocol.OFMessage;
29 -
30 -import java.net.SocketAddress;
31 -import java.util.ArrayList;
32 -import java.util.List;
33 -
34 -import static org.hamcrest.MatcherAssert.assertThat;
35 -import static org.hamcrest.Matchers.hasSize;
36 -import static org.hamcrest.Matchers.is;
37 -
38 -/**
39 - * Tests for packet processing in the abstract openflow switch class.
40 - */
41 -public class AbstractOpenFlowSwitchTest {
42 -
43 - OpenFlowSwitchImpl ofSwitch;
44 - TestExecutorService executorService;
45 -
46 - /**
47 - * Mock executor service that tracks submits.
48 - */
49 - static class TestExecutorService extends ExecutorServiceAdapter {
50 - private List<OFMessage> submittedMessages = new ArrayList<>();
51 -
52 - List<OFMessage> submittedMessages() {
53 - return submittedMessages;
54 - }
55 -
56 - @Override
57 - public void execute(Runnable task) {
58 - AbstractOpenFlowSwitch.OFMessageHandler handler =
59 - (AbstractOpenFlowSwitch.OFMessageHandler) task;
60 - submittedMessages.add(handler.msg);
61 - }
62 - }
63 -
64 - /**
65 - * Sets up switches to use as data.
66 - */
67 - @Before
68 - public void setUp() {
69 - ofSwitch = new OpenFlowSwitchImpl();
70 -
71 - executorService = new TestExecutorService();
72 - ofSwitch.executorMsgs = executorService;
73 - Channel channel = new MockChannel();
74 - ofSwitch.setChannel(channel);
75 - ofSwitch.role = RoleState.MASTER;
76 - ofSwitch.addEventListener(new OpenFlowEventListenerAdapter());
77 - }
78 -
79 - /**
80 - * Tests a packet out operation.
81 - */
82 - @Test
83 - public void testPacketOut() {
84 - OFMessage ofPacketOut = new MockOfPacketOut();
85 - ofSwitch.sendMsg(ofPacketOut);
86 - assertThat(executorService.submittedMessages(), hasSize(1));
87 - assertThat(executorService.submittedMessages().get(0), is(ofPacketOut));
88 - }
89 -
90 - /**
91 - * Tests a flow mod operation.
92 - */
93 - @Test
94 - public void testFlowMod() {
95 - OFMessage ofFlowMod = new MockOfFlowMod();
96 - ofSwitch.sendMsg(ofFlowMod);
97 - assertThat(executorService.submittedMessages(), hasSize(1));
98 - assertThat(executorService.submittedMessages().get(0), is(ofFlowMod));
99 - }
100 -
101 - /**
102 - * Tests a stats request operation.
103 - */
104 - @Test
105 - public void testStatsRequest() {
106 - OFMessage ofStatsRequest = new MockOfStatsRequest();
107 - ofSwitch.sendMsg(ofStatsRequest);
108 - assertThat(executorService.submittedMessages(), hasSize(1));
109 - assertThat(executorService.submittedMessages().get(0), is(ofStatsRequest));
110 - }
111 -
112 - protected class OpenFlowSwitchImpl extends AbstractOpenFlowSwitch {
113 -
114 - @Override
115 - public Boolean supportNxRole() {
116 - return null;
117 - }
118 -
119 - @Override
120 - public void startDriverHandshake() {
121 - }
122 -
123 - @Override
124 - public boolean isDriverHandshakeComplete() {
125 - return false;
126 - }
127 -
128 - @Override
129 - public void processDriverHandshakeMessage(OFMessage m) {
130 - }
131 - }
132 -
133 - private class OpenFlowEventListenerAdapter implements OpenFlowEventListener {
134 -
135 - @Override
136 - public void handleMessage(Dpid dpid, OFMessage msg) {
137 - }
138 - }
139 -
140 - private class MockChannel implements Channel {
141 -
142 - @Override
143 - public Integer getId() {
144 - return null;
145 - }
146 -
147 - @Override
148 - public ChannelFactory getFactory() {
149 - return null;
150 - }
151 -
152 - @Override
153 - public Channel getParent() {
154 - return null;
155 - }
156 -
157 - @Override
158 - public ChannelConfig getConfig() {
159 - return null;
160 - }
161 -
162 - @Override
163 - public ChannelPipeline getPipeline() {
164 - return null;
165 - }
166 -
167 - @Override
168 - public boolean isOpen() {
169 - return false;
170 - }
171 -
172 - @Override
173 - public boolean isBound() {
174 - return false;
175 - }
176 -
177 - @Override
178 - public boolean isConnected() {
179 - // we assume that the channel is connected
180 - return true;
181 - }
182 -
183 - @Override
184 - public SocketAddress getLocalAddress() {
185 - return null;
186 - }
187 -
188 - @Override
189 - public SocketAddress getRemoteAddress() {
190 - return null;
191 - }
192 -
193 - @Override
194 - public ChannelFuture write(Object message) {
195 - return null;
196 - }
197 -
198 - @Override
199 - public ChannelFuture write(Object message, SocketAddress remoteAddress) {
200 - return null;
201 - }
202 -
203 - @Override
204 - public ChannelFuture bind(SocketAddress localAddress) {
205 - return null;
206 - }
207 -
208 - @Override
209 - public ChannelFuture connect(SocketAddress remoteAddress) {
210 - return null;
211 - }
212 -
213 - @Override
214 - public ChannelFuture disconnect() {
215 - return null;
216 - }
217 -
218 - @Override
219 - public ChannelFuture unbind() {
220 - return null;
221 - }
222 -
223 - @Override
224 - public ChannelFuture close() {
225 - return null;
226 - }
227 -
228 - @Override
229 - public ChannelFuture getCloseFuture() {
230 - return null;
231 - }
232 -
233 - @Override
234 - public int getInterestOps() {
235 - return 0;
236 - }
237 -
238 - @Override
239 - public boolean isReadable() {
240 - return false;
241 - }
242 -
243 - @Override
244 - public boolean isWritable() {
245 - return false;
246 - }
247 -
248 - @Override
249 - public ChannelFuture setInterestOps(int interestOps) {
250 - return null;
251 - }
252 -
253 - @Override
254 - public ChannelFuture setReadable(boolean readable) {
255 - return null;
256 - }
257 -
258 - @Override
259 - public boolean getUserDefinedWritability(int index) {
260 - return false;
261 - }
262 -
263 - @Override
264 - public void setUserDefinedWritability(int index, boolean isWritable) {
265 -
266 - }
267 -
268 - @Override
269 - public Object getAttachment() {
270 - return null;
271 - }
272 -
273 - @Override
274 - public void setAttachment(Object attachment) {
275 -
276 - }
277 -
278 - @Override
279 - public int compareTo(Channel o) {
280 - return 0;
281 - }
282 - }
283 -}
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.driver;
17 -
18 -import java.util.Collection;
19 -import java.util.List;
20 -import java.util.concurrent.Callable;
21 -import java.util.concurrent.ExecutionException;
22 -import java.util.concurrent.ExecutorService;
23 -import java.util.concurrent.Future;
24 -import java.util.concurrent.TimeUnit;
25 -import java.util.concurrent.TimeoutException;
26 -
27 -/**
28 - * Test harness adapter for the ExecutorService.
29 - */
30 -public class ExecutorServiceAdapter implements ExecutorService {
31 - @Override
32 - public void shutdown() {
33 -
34 - }
35 -
36 - @Override
37 - public List<Runnable> shutdownNow() {
38 - return null;
39 - }
40 -
41 - @Override
42 - public boolean isShutdown() {
43 - return false;
44 - }
45 -
46 - @Override
47 - public boolean isTerminated() {
48 - return false;
49 - }
50 -
51 - @Override
52 - public boolean awaitTermination(long timeout, TimeUnit unit)
53 - throws InterruptedException {
54 - return false;
55 - }
56 -
57 - @Override
58 - public <T> Future<T> submit(Callable<T> task) {
59 - return null;
60 - }
61 -
62 - @Override
63 - public <T> Future<T> submit(Runnable task, T result) {
64 - return null;
65 - }
66 -
67 - @Override
68 - public Future<?> submit(Runnable task) {
69 - return null;
70 - }
71 -
72 - @Override
73 - public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
74 - throws InterruptedException {
75 - return null;
76 - }
77 -
78 - @Override
79 - public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
80 - throws InterruptedException {
81 - return null;
82 - }
83 -
84 - @Override
85 - public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
86 - return null;
87 - }
88 -
89 - @Override
90 - public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
91 - throws InterruptedException, ExecutionException, TimeoutException {
92 - return null;
93 - }
94 -
95 - @Override
96 - public void execute(Runnable command) {
97 -
98 - }
99 -}
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.driver;
17 -
18 -
19 -import org.projectfloodlight.openflow.protocol.OFFlowMod;
20 -import org.projectfloodlight.openflow.protocol.OFFlowModCommand;
21 -import org.projectfloodlight.openflow.protocol.OFType;
22 -import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
23 -import org.projectfloodlight.openflow.protocol.action.OFAction;
24 -import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
25 -import org.projectfloodlight.openflow.protocol.match.Match;
26 -import org.projectfloodlight.openflow.types.OFBufferId;
27 -import org.projectfloodlight.openflow.types.OFPort;
28 -import org.projectfloodlight.openflow.types.TableId;
29 -import org.projectfloodlight.openflow.types.U64;
30 -import org.projectfloodlight.openflow.types.OFGroup;
31 -
32 -import java.util.List;
33 -import java.util.Set;
34 -
35 -/**
36 - * Mock of the Open Flow flow mod message.
37 - */
38 -public class MockOfFlowMod extends OfMessageAdapter implements OFFlowMod {
39 -
40 - public MockOfFlowMod() {
41 - super(OFType.FLOW_MOD);
42 - }
43 -
44 - @Override
45 - public U64 getCookie() {
46 - return null;
47 - }
48 -
49 - @Override
50 - public U64 getCookieMask() throws UnsupportedOperationException {
51 - return null;
52 - }
53 -
54 - @Override
55 - public TableId getTableId() throws UnsupportedOperationException {
56 - return null;
57 - }
58 -
59 - @Override
60 - public OFFlowModCommand getCommand() {
61 - return null;
62 - }
63 -
64 - @Override
65 - public int getIdleTimeout() {
66 - return 0;
67 - }
68 -
69 - @Override
70 - public int getHardTimeout() {
71 - return 0;
72 - }
73 -
74 - @Override
75 - public int getPriority() {
76 - return 0;
77 - }
78 -
79 - @Override
80 - public OFBufferId getBufferId() {
81 - return null;
82 - }
83 -
84 - @Override
85 - public OFPort getOutPort() {
86 - return null;
87 - }
88 -
89 - @Override
90 - public OFGroup getOutGroup() throws UnsupportedOperationException {
91 - return null;
92 - }
93 -
94 - @Override
95 - public Set<OFFlowModFlags> getFlags() {
96 - return null;
97 - }
98 -
99 - @Override
100 - public Match getMatch() {
101 - return null;
102 - }
103 -
104 - @Override
105 - public List<OFInstruction> getInstructions() throws UnsupportedOperationException {
106 - return null;
107 - }
108 -
109 - @Override
110 - public List<OFAction> getActions() throws UnsupportedOperationException {
111 - return null;
112 - }
113 -
114 - @Override
115 - public OFFlowMod.Builder createBuilder() {
116 - return null;
117 - }
118 -}
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.driver;
17 -
18 -import org.projectfloodlight.openflow.protocol.OFPacketOut;
19 -import org.projectfloodlight.openflow.protocol.OFType;
20 -import org.projectfloodlight.openflow.protocol.action.OFAction;
21 -import org.projectfloodlight.openflow.types.OFBufferId;
22 -import org.projectfloodlight.openflow.types.OFPort;
23 -
24 -import java.util.List;
25 -
26 -/**
27 - * Mock of the Open Flow packet out message.
28 - */
29 -public class MockOfPacketOut extends OfMessageAdapter implements OFPacketOut {
30 -
31 - public MockOfPacketOut() {
32 - super(OFType.PACKET_OUT);
33 - }
34 -
35 - @Override
36 - public OFBufferId getBufferId() {
37 - return null;
38 - }
39 -
40 - @Override
41 - public OFPort getInPort() {
42 - return null;
43 - }
44 -
45 - @Override
46 - public List<OFAction> getActions() {
47 - return null;
48 - }
49 -
50 - @Override
51 - public byte[] getData() {
52 - return new byte[0];
53 - }
54 -
55 - @Override
56 - public OFPacketOut.Builder createBuilder() {
57 - return null;
58 - }
59 -}
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.driver;
17 -
18 -
19 -
20 -import org.projectfloodlight.openflow.protocol.OFStatsRequest;
21 -import org.projectfloodlight.openflow.protocol.OFStatsType;
22 -import org.projectfloodlight.openflow.protocol.OFType;
23 -import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
24 -
25 -import java.util.Set;
26 -
27 -/**
28 - * Mock of the Open Flow stats request message.
29 - */
30 -public class MockOfStatsRequest extends OfMessageAdapter implements OFStatsRequest {
31 -
32 - public MockOfStatsRequest() {
33 - super(OFType.STATS_REQUEST);
34 - }
35 -
36 - @Override
37 - public OFStatsType getStatsType() {
38 - return null;
39 - }
40 -
41 - @Override
42 - public Set<OFStatsReplyFlags> getFlags() {
43 - return null;
44 - }
45 -
46 - @Override
47 - public OFStatsRequest.Builder createBuilder() {
48 - return null;
49 - }
50 -}
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.driver;
17 -
18 -import org.jboss.netty.buffer.ChannelBuffer;
19 -import org.projectfloodlight.openflow.protocol.OFMessage;
20 -import org.projectfloodlight.openflow.protocol.OFType;
21 -import org.projectfloodlight.openflow.protocol.OFVersion;
22 -
23 -import com.google.common.hash.PrimitiveSink;
24 -
25 -/**
26 - * Adapter for testing against an OpenFlow message.
27 - */
28 -public class OfMessageAdapter implements OFMessage {
29 - OFType type;
30 -
31 - private OfMessageAdapter() {}
32 -
33 - public OfMessageAdapter(OFType type) {
34 - this.type = type;
35 - }
36 -
37 - @Override
38 - public OFType getType() {
39 - return type;
40 - }
41 -
42 - @Override
43 - public OFVersion getVersion() {
44 - return null;
45 - }
46 -
47 - @Override
48 - public long getXid() {
49 - return 0;
50 - }
51 -
52 - @Override
53 - public void writeTo(ChannelBuffer channelBuffer) { }
54 -
55 - @Override
56 - public Builder createBuilder() {
57 - return null;
58 - }
59 -
60 - @Override
61 - public void putTo(PrimitiveSink sink) { }
62 -}
...@@ -34,6 +34,7 @@ import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; ...@@ -34,6 +34,7 @@ import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext;
34 import org.onosproject.openflow.controller.Dpid; 34 import org.onosproject.openflow.controller.Dpid;
35 import org.onosproject.openflow.controller.OpenFlowController; 35 import org.onosproject.openflow.controller.OpenFlowController;
36 import org.onosproject.openflow.controller.OpenFlowEventListener; 36 import org.onosproject.openflow.controller.OpenFlowEventListener;
37 +import org.onosproject.openflow.controller.OpenFlowMessageListener;
37 import org.onosproject.openflow.controller.OpenFlowPacketContext; 38 import org.onosproject.openflow.controller.OpenFlowPacketContext;
38 import org.onosproject.openflow.controller.OpenFlowSwitch; 39 import org.onosproject.openflow.controller.OpenFlowSwitch;
39 import org.onosproject.openflow.controller.OpenFlowSwitchListener; 40 import org.onosproject.openflow.controller.OpenFlowSwitchListener;
...@@ -134,7 +135,7 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -134,7 +135,7 @@ public class OpenFlowControllerImpl implements OpenFlowController {
134 135
135 protected Set<OpenFlowEventListener> ofEventListener = new CopyOnWriteArraySet<>(); 136 protected Set<OpenFlowEventListener> ofEventListener = new CopyOnWriteArraySet<>();
136 137
137 - protected boolean monitorAllEvents = false; 138 + protected Set<OpenFlowMessageListener> ofMessageListener = new CopyOnWriteArraySet<>();
138 139
139 protected Multimap<Dpid, OFFlowStatsEntry> fullFlowStats = 140 protected Multimap<Dpid, OFFlowStatsEntry> fullFlowStats =
140 ArrayListMultimap.create(); 141 ArrayListMultimap.create();
...@@ -217,11 +218,6 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -217,11 +218,6 @@ public class OpenFlowControllerImpl implements OpenFlowController {
217 } 218 }
218 219
219 @Override 220 @Override
220 - public void monitorAllEvents(boolean monitor) {
221 - this.monitorAllEvents = monitor;
222 - }
223 -
224 - @Override
225 public void addListener(OpenFlowSwitchListener listener) { 221 public void addListener(OpenFlowSwitchListener listener) {
226 if (!ofSwitchListener.contains(listener)) { 222 if (!ofSwitchListener.contains(listener)) {
227 this.ofSwitchListener.add(listener); 223 this.ofSwitchListener.add(listener);
...@@ -234,6 +230,16 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -234,6 +230,16 @@ public class OpenFlowControllerImpl implements OpenFlowController {
234 } 230 }
235 231
236 @Override 232 @Override
233 + public void addMessageListener(OpenFlowMessageListener listener) {
234 + ofMessageListener.add(listener);
235 + }
236 +
237 + @Override
238 + public void removeMessageListener(OpenFlowMessageListener listener) {
239 + ofMessageListener.remove(listener);
240 + }
241 +
242 + @Override
237 public void addPacketListener(int priority, PacketListener listener) { 243 public void addPacketListener(int priority, PacketListener listener) {
238 ofPacketListener.put(priority, listener); 244 ofPacketListener.put(priority, listener);
239 } 245 }
...@@ -625,8 +631,20 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -625,8 +631,20 @@ public class OpenFlowControllerImpl implements OpenFlowController {
625 } 631 }
626 632
627 @Override 633 @Override
634 + public void processDownstreamMessage(Dpid dpid, List<OFMessage> m) {
635 + for (OpenFlowMessageListener listener : ofMessageListener) {
636 + listener.handleOutgoingMessage(dpid, m);
637 + }
638 + }
639 +
640 +
641 + @Override
628 public void processMessage(Dpid dpid, OFMessage m) { 642 public void processMessage(Dpid dpid, OFMessage m) {
629 processPacket(dpid, m); 643 processPacket(dpid, m);
644 +
645 + for (OpenFlowMessageListener listener : ofMessageListener) {
646 + listener.handleIncomingMessage(dpid, m);
647 + }
630 } 648 }
631 649
632 @Override 650 @Override
......
1 -/*
2 - * Copyright 2015-present 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.openflow;
17 -
18 -import org.projectfloodlight.openflow.protocol.OFPacketIn;
19 -import org.projectfloodlight.openflow.protocol.OFPacketInReason;
20 -import org.projectfloodlight.openflow.protocol.OFType;
21 -import org.projectfloodlight.openflow.protocol.match.Match;
22 -import org.projectfloodlight.openflow.types.OFBufferId;
23 -import org.projectfloodlight.openflow.types.OFPort;
24 -import org.projectfloodlight.openflow.types.TableId;
25 -import org.projectfloodlight.openflow.types.U64;
26 -
27 -/**
28 - * Mock of the Open Flow packet in message.
29 - */
30 -public class MockOfPacketIn extends OfMessageAdapter implements OFPacketIn {
31 - public MockOfPacketIn() {
32 - super(OFType.PACKET_IN);
33 - }
34 -
35 - @Override
36 - public OFBufferId getBufferId() {
37 - return null;
38 - }
39 -
40 - @Override
41 - public int getTotalLen() {
42 - return 0;
43 - }
44 -
45 - @Override
46 - public OFPacketInReason getReason() {
47 - return null;
48 - }
49 -
50 - @Override
51 - public TableId getTableId() {
52 - return null;
53 - }
54 -
55 - @Override
56 - public Match getMatch() {
57 - return null;
58 - }
59 -
60 - @Override
61 - public byte[] getData() {
62 - return new byte[0];
63 - }
64 -
65 - @Override
66 - public OFPort getInPort() {
67 - return null;
68 - }
69 -
70 - @Override
71 - public OFPort getInPhyPort() {
72 - return null;
73 - }
74 -
75 - @Override
76 - public U64 getCookie() {
77 - return null;
78 - }
79 -
80 - @Override
81 - public OFPacketIn.Builder createBuilder() {
82 - return null;
83 - }
84 -}
...@@ -15,14 +15,11 @@ ...@@ -15,14 +15,11 @@
15 */ 15 */
16 package org.onosproject.openflow; 16 package org.onosproject.openflow;
17 17
18 -import java.util.List;
19 -
20 import org.jboss.netty.channel.Channel; 18 import org.jboss.netty.channel.Channel;
21 import org.onosproject.net.Device; 19 import org.onosproject.net.Device;
22 import org.onosproject.net.driver.DriverData; 20 import org.onosproject.net.driver.DriverData;
23 import org.onosproject.net.driver.DriverHandler; 21 import org.onosproject.net.driver.DriverHandler;
24 import org.onosproject.openflow.controller.Dpid; 22 import org.onosproject.openflow.controller.Dpid;
25 -import org.onosproject.openflow.controller.OpenFlowEventListener;
26 import org.onosproject.openflow.controller.RoleState; 23 import org.onosproject.openflow.controller.RoleState;
27 import org.onosproject.openflow.controller.driver.OpenFlowAgent; 24 import org.onosproject.openflow.controller.driver.OpenFlowAgent;
28 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; 25 import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver;
...@@ -38,6 +35,8 @@ import org.projectfloodlight.openflow.protocol.OFPortDesc; ...@@ -38,6 +35,8 @@ import org.projectfloodlight.openflow.protocol.OFPortDesc;
38 import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; 35 import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply;
39 import org.projectfloodlight.openflow.protocol.OFVersion; 36 import org.projectfloodlight.openflow.protocol.OFVersion;
40 37
38 +import java.util.List;
39 +
41 /** 40 /**
42 * Testing adapter for the OpenFlow switch driver class. 41 * Testing adapter for the OpenFlow switch driver class.
43 */ 42 */
...@@ -300,12 +299,4 @@ public class OpenflowSwitchDriverAdapter implements OpenFlowSwitchDriver { ...@@ -300,12 +299,4 @@ public class OpenflowSwitchDriverAdapter implements OpenFlowSwitchDriver {
300 public String channelId() { 299 public String channelId() {
301 return null; 300 return null;
302 } 301 }
303 -
304 - @Override
305 - public void addEventListener(OpenFlowEventListener listener) {
306 - }
307 -
308 - @Override
309 - public void removeEventListener(OpenFlowEventListener listener) {
310 - }
311 } 302 }
......
1 -/*
2 - * Copyright 2015-present 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.openflow.controller.impl;
17 -
18 -import org.onosproject.openflow.OfMessageAdapter;
19 -import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
20 -import org.projectfloodlight.openflow.protocol.OFType;
21 -import org.projectfloodlight.openflow.protocol.match.Match;
22 -import org.projectfloodlight.openflow.types.TableId;
23 -import org.projectfloodlight.openflow.types.U64;
24 -
25 -/**
26 - * Mock of the Open Flow packet removed message.
27 - */
28 -public class MockOfFlowRemoved extends OfMessageAdapter implements OFFlowRemoved {
29 -
30 - public MockOfFlowRemoved() {
31 - super(OFType.FLOW_REMOVED);
32 - }
33 -
34 - @Override
35 - public U64 getCookie() {
36 - return null;
37 - }
38 -
39 - @Override
40 - public int getPriority() {
41 - return 0;
42 - }
43 -
44 - @Override
45 - public short getReason() {
46 - return 0;
47 - }
48 -
49 - @Override
50 - public TableId getTableId() throws UnsupportedOperationException {
51 - return null;
52 - }
53 -
54 - @Override
55 - public long getDurationSec() {
56 - return 0;
57 - }
58 -
59 - @Override
60 - public long getDurationNsec() {
61 - return 0;
62 - }
63 -
64 - @Override
65 - public int getIdleTimeout() {
66 - return 0;
67 - }
68 -
69 - @Override
70 - public int getHardTimeout() throws UnsupportedOperationException {
71 - return 0;
72 - }
73 -
74 - @Override
75 - public U64 getPacketCount() {
76 - return null;
77 - }
78 -
79 - @Override
80 - public U64 getByteCount() {
81 - return null;
82 - }
83 -
84 - @Override
85 - public Match getMatch() {
86 - return null;
87 - }
88 -
89 - @Override
90 - public OFFlowRemoved.Builder createBuilder() {
91 - return null;
92 - }
93 -}
...@@ -104,7 +104,6 @@ public class OpenFlowControllerImplPacketsTest { ...@@ -104,7 +104,6 @@ public class OpenFlowControllerImplPacketsTest {
104 agent = controller.agent; 104 agent = controller.agent;
105 switchListener = new OpenFlowSwitchListenerAdapter(); 105 switchListener = new OpenFlowSwitchListenerAdapter();
106 controller.addListener(switchListener); 106 controller.addListener(switchListener);
107 - controller.monitorAllEvents(true);
108 107
109 packetListener = new TestPacketListener(); 108 packetListener = new TestPacketListener();
110 controller.addPacketListener(100, packetListener); 109 controller.addPacketListener(100, packetListener);
......
...@@ -38,6 +38,7 @@ import org.onosproject.net.provider.ProviderId; ...@@ -38,6 +38,7 @@ import org.onosproject.net.provider.ProviderId;
38 import org.onosproject.openflow.controller.Dpid; 38 import org.onosproject.openflow.controller.Dpid;
39 import org.onosproject.openflow.controller.OpenFlowController; 39 import org.onosproject.openflow.controller.OpenFlowController;
40 import org.onosproject.openflow.controller.OpenFlowEventListener; 40 import org.onosproject.openflow.controller.OpenFlowEventListener;
41 +import org.onosproject.openflow.controller.OpenFlowMessageListener;
41 import org.onosproject.openflow.controller.OpenFlowSwitch; 42 import org.onosproject.openflow.controller.OpenFlowSwitch;
42 import org.onosproject.openflow.controller.OpenFlowSwitchListener; 43 import org.onosproject.openflow.controller.OpenFlowSwitchListener;
43 import org.onosproject.openflow.controller.PacketListener; 44 import org.onosproject.openflow.controller.PacketListener;
...@@ -275,10 +276,6 @@ public class OpenFlowDeviceProviderTest { ...@@ -275,10 +276,6 @@ public class OpenFlowDeviceProviderTest {
275 } 276 }
276 277
277 @Override 278 @Override
278 - public void monitorAllEvents(boolean monitor) {
279 - }
280 -
281 - @Override
282 public void addListener(OpenFlowSwitchListener listener) { 279 public void addListener(OpenFlowSwitchListener listener) {
283 this.listener = listener; 280 this.listener = listener;
284 } 281 }
...@@ -289,6 +286,16 @@ public class OpenFlowDeviceProviderTest { ...@@ -289,6 +286,16 @@ public class OpenFlowDeviceProviderTest {
289 } 286 }
290 287
291 @Override 288 @Override
289 + public void addMessageListener(OpenFlowMessageListener listener) {
290 +
291 + }
292 +
293 + @Override
294 + public void removeMessageListener(OpenFlowMessageListener listener) {
295 +
296 + }
297 +
298 + @Override
292 public void addPacketListener(int priority, PacketListener listener) { 299 public void addPacketListener(int priority, PacketListener listener) {
293 } 300 }
294 301
...@@ -416,14 +423,6 @@ public class OpenFlowDeviceProviderTest { ...@@ -416,14 +423,6 @@ public class OpenFlowDeviceProviderTest {
416 return "1.2.3.4:1"; 423 return "1.2.3.4:1";
417 } 424 }
418 425
419 - @Override
420 - public void addEventListener(OpenFlowEventListener listener) {
421 - }
422 -
423 - @Override
424 - public void removeEventListener(OpenFlowEventListener listener) {
425 - }
426 -
427 } 426 }
428 427
429 } 428 }
......
...@@ -41,6 +41,7 @@ import org.onosproject.net.provider.ProviderId; ...@@ -41,6 +41,7 @@ import org.onosproject.net.provider.ProviderId;
41 import org.onosproject.openflow.controller.Dpid; 41 import org.onosproject.openflow.controller.Dpid;
42 import org.onosproject.openflow.controller.OpenFlowController; 42 import org.onosproject.openflow.controller.OpenFlowController;
43 import org.onosproject.openflow.controller.OpenFlowEventListener; 43 import org.onosproject.openflow.controller.OpenFlowEventListener;
44 +import org.onosproject.openflow.controller.OpenFlowMessageListener;
44 import org.onosproject.openflow.controller.OpenFlowSwitch; 45 import org.onosproject.openflow.controller.OpenFlowSwitch;
45 import org.onosproject.openflow.controller.OpenFlowSwitchListener; 46 import org.onosproject.openflow.controller.OpenFlowSwitchListener;
46 import org.onosproject.openflow.controller.PacketListener; 47 import org.onosproject.openflow.controller.PacketListener;
...@@ -225,6 +226,16 @@ public class OpenFlowGroupProviderTest { ...@@ -225,6 +226,16 @@ public class OpenFlowGroupProviderTest {
225 } 226 }
226 227
227 @Override 228 @Override
229 + public void addMessageListener(OpenFlowMessageListener listener) {
230 +
231 + }
232 +
233 + @Override
234 + public void removeMessageListener(OpenFlowMessageListener listener) {
235 +
236 + }
237 +
238 + @Override
228 public void addPacketListener(int priority, PacketListener listener) { 239 public void addPacketListener(int priority, PacketListener listener) {
229 240
230 } 241 }
...@@ -288,11 +299,6 @@ public class OpenFlowGroupProviderTest { ...@@ -288,11 +299,6 @@ public class OpenFlowGroupProviderTest {
288 public OpenFlowSwitch getEqualSwitch(Dpid dpid) { 299 public OpenFlowSwitch getEqualSwitch(Dpid dpid) {
289 return null; 300 return null;
290 } 301 }
291 -
292 - @Override
293 - public void monitorAllEvents(boolean monitor) {
294 - }
295 -
296 } 302 }
297 303
298 private class TestGroupProviderRegistry implements GroupProviderRegistry { 304 private class TestGroupProviderRegistry implements GroupProviderRegistry {
...@@ -411,14 +417,5 @@ public class OpenFlowGroupProviderTest { ...@@ -411,14 +417,5 @@ public class OpenFlowGroupProviderTest {
411 public String channelId() { 417 public String channelId() {
412 return null; 418 return null;
413 } 419 }
414 -
415 - @Override
416 - public void addEventListener(OpenFlowEventListener listener) {
417 - }
418 -
419 - @Override
420 - public void removeEventListener(OpenFlowEventListener listener) {
421 - }
422 -
423 } 420 }
424 } 421 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -32,7 +32,7 @@ import org.onosproject.net.provider.AbstractProvider; ...@@ -32,7 +32,7 @@ import org.onosproject.net.provider.AbstractProvider;
32 import org.onosproject.net.provider.ProviderId; 32 import org.onosproject.net.provider.ProviderId;
33 import org.onosproject.openflow.controller.Dpid; 33 import org.onosproject.openflow.controller.Dpid;
34 import org.onosproject.openflow.controller.OpenFlowController; 34 import org.onosproject.openflow.controller.OpenFlowController;
35 -import org.onosproject.openflow.controller.OpenFlowEventListener; 35 +import org.onosproject.openflow.controller.OpenFlowMessageListener;
36 import org.onosproject.openflow.controller.OpenFlowSwitch; 36 import org.onosproject.openflow.controller.OpenFlowSwitch;
37 import org.onosproject.openflow.controller.OpenFlowSwitchListener; 37 import org.onosproject.openflow.controller.OpenFlowSwitchListener;
38 import org.onosproject.openflow.controller.RoleState; 38 import org.onosproject.openflow.controller.RoleState;
...@@ -42,6 +42,7 @@ import org.projectfloodlight.openflow.protocol.OFType; ...@@ -42,6 +42,7 @@ import org.projectfloodlight.openflow.protocol.OFType;
42 import org.slf4j.Logger; 42 import org.slf4j.Logger;
43 43
44 import java.util.HashMap; 44 import java.util.HashMap;
45 +import java.util.List;
45 import java.util.concurrent.ScheduledFuture; 46 import java.util.concurrent.ScheduledFuture;
46 import java.util.concurrent.TimeUnit; 47 import java.util.concurrent.TimeUnit;
47 48
...@@ -71,11 +72,8 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -71,11 +72,8 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
71 72
72 private final InternalDeviceProvider listener = new InternalDeviceProvider(); 73 private final InternalDeviceProvider listener = new InternalDeviceProvider();
73 74
74 - private final InternalIncomingMessageProvider inMsgListener = 75 + private final InternalControlMessageListener messageListener =
75 - new InternalIncomingMessageProvider(); 76 + new InternalControlMessageListener();
76 -
77 - private final InternalOutgoingMessageProvider outMsgListener =
78 - new InternalOutgoingMessageProvider();
79 77
80 private HashMap<Dpid, OpenFlowControlMessageAggregator> aggregators = Maps.newHashMap(); 78 private HashMap<Dpid, OpenFlowControlMessageAggregator> aggregators = Maps.newHashMap();
81 private SharedScheduledExecutorService executor; 79 private SharedScheduledExecutorService executor;
...@@ -98,12 +96,8 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -98,12 +96,8 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
98 // listens all OpenFlow device related events 96 // listens all OpenFlow device related events
99 controller.addListener(listener); 97 controller.addListener(listener);
100 98
101 - // listens all OpenFlow incoming message events 99 + // listens all OpenFlow control message
102 - controller.addEventListener(inMsgListener); 100 + controller.addMessageListener(messageListener);
103 - controller.monitorAllEvents(true);
104 -
105 - // listens all OpenFlow outgoing message events
106 - controller.getSwitches().forEach(sw -> sw.addEventListener(outMsgListener));
107 101
108 executor = SharedScheduledExecutors.getSingleThreadExecutor(); 102 executor = SharedScheduledExecutors.getSingleThreadExecutor();
109 103
...@@ -117,12 +111,8 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -117,12 +111,8 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
117 providerRegistry.unregister(this); 111 providerRegistry.unregister(this);
118 providerService = null; 112 providerService = null;
119 113
120 - // stops listening all OpenFlow incoming message events 114 + // stops listening all OpenFlow control message events
121 - controller.monitorAllEvents(false); 115 + controller.removeMessageListener(messageListener);
122 - controller.removeEventListener(inMsgListener);
123 -
124 - // stops listening all OpenFlow outgoing message events
125 - controller.getSwitches().forEach(sw -> sw.removeEventListener(outMsgListener));
126 116
127 log.info("Stopped"); 117 log.info("Stopped");
128 } 118 }
...@@ -149,12 +139,6 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -149,12 +139,6 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
149 return; 139 return;
150 } 140 }
151 141
152 - OpenFlowSwitch sw = controller.getSwitch(dpid);
153 - if (sw != null) {
154 - // start to monitor the outgoing control messages
155 - sw.addEventListener(outMsgListener);
156 - }
157 -
158 DeviceId deviceId = deviceId(uri(dpid)); 142 DeviceId deviceId = deviceId(uri(dpid));
159 OpenFlowControlMessageAggregator ofcma = 143 OpenFlowControlMessageAggregator ofcma =
160 new OpenFlowControlMessageAggregator(metricsService, 144 new OpenFlowControlMessageAggregator(metricsService,
...@@ -171,12 +155,6 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -171,12 +155,6 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
171 return; 155 return;
172 } 156 }
173 157
174 - OpenFlowSwitch sw = controller.getSwitch(dpid);
175 - if (sw != null) {
176 - // stop monitoring the outgoing control messages
177 - sw.removeEventListener(outMsgListener);
178 - }
179 -
180 // removes the aggregator when switch is removed 158 // removes the aggregator when switch is removed
181 // this also stops the aggregator from running 159 // this also stops the aggregator from running
182 OpenFlowControlMessageAggregator aggregator = aggregators.remove(dpid); 160 OpenFlowControlMessageAggregator aggregator = aggregators.remove(dpid);
...@@ -200,12 +178,12 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -200,12 +178,12 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
200 } 178 }
201 179
202 /** 180 /**
203 - * A listener for incoming OpenFlow messages. 181 + * A listener for all OpenFlow control messages.
204 */ 182 */
205 - private class InternalIncomingMessageProvider implements OpenFlowEventListener { 183 + private class InternalControlMessageListener implements OpenFlowMessageListener {
206 184
207 @Override 185 @Override
208 - public void handleMessage(Dpid dpid, OFMessage msg) { 186 + public void handleIncomingMessage(Dpid dpid, OFMessage msg) {
209 if (msg.getType() == OFType.PACKET_IN || 187 if (msg.getType() == OFType.PACKET_IN ||
210 msg.getType() == OFType.FLOW_MOD || 188 msg.getType() == OFType.FLOW_MOD ||
211 msg.getType() == OFType.STATS_REPLY) { 189 msg.getType() == OFType.STATS_REPLY) {
...@@ -215,19 +193,19 @@ public class OpenFlowControlMessageProvider extends AbstractProvider ...@@ -215,19 +193,19 @@ public class OpenFlowControlMessageProvider extends AbstractProvider
215 }); 193 });
216 } 194 }
217 } 195 }
218 - }
219 -
220 - /**
221 - * A listener for outgoing OpenFlow messages.
222 - */
223 - private class InternalOutgoingMessageProvider implements OpenFlowEventListener {
224 196
225 @Override 197 @Override
226 - public void handleMessage(Dpid dpid, OFMessage msg) { 198 + public void handleOutgoingMessage(Dpid dpid, List<OFMessage> msgs) {
227 - aggregators.computeIfPresent(dpid, (k, v) -> { 199 + for (OFMessage msg : msgs) {
228 - v.increment(msg); 200 + if (msg.getType() == OFType.PACKET_OUT ||
229 - return v; 201 + msg.getType() == OFType.FLOW_MOD ||
230 - }); 202 + msg.getType() == OFType.STATS_REQUEST) {
203 + aggregators.computeIfPresent(dpid, (k, v) -> {
204 + v.increment(msg);
205 + return v;
206 + });
207 + }
208 + }
231 } 209 }
232 } 210 }
233 } 211 }
......
...@@ -40,6 +40,7 @@ import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; ...@@ -40,6 +40,7 @@ import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext;
40 import org.onosproject.openflow.controller.Dpid; 40 import org.onosproject.openflow.controller.Dpid;
41 import org.onosproject.openflow.controller.OpenFlowController; 41 import org.onosproject.openflow.controller.OpenFlowController;
42 import org.onosproject.openflow.controller.OpenFlowEventListener; 42 import org.onosproject.openflow.controller.OpenFlowEventListener;
43 +import org.onosproject.openflow.controller.OpenFlowMessageListener;
43 import org.onosproject.openflow.controller.OpenFlowPacketContext; 44 import org.onosproject.openflow.controller.OpenFlowPacketContext;
44 import org.onosproject.openflow.controller.OpenFlowSwitch; 45 import org.onosproject.openflow.controller.OpenFlowSwitch;
45 import org.onosproject.openflow.controller.OpenFlowSwitchListener; 46 import org.onosproject.openflow.controller.OpenFlowSwitchListener;
...@@ -287,15 +288,21 @@ public class OpenFlowPacketProviderTest { ...@@ -287,15 +288,21 @@ public class OpenFlowPacketProviderTest {
287 } 288 }
288 289
289 @Override 290 @Override
290 - public void monitorAllEvents(boolean monitor) { 291 + public void addListener(OpenFlowSwitchListener listener) {
291 } 292 }
292 293
293 @Override 294 @Override
294 - public void addListener(OpenFlowSwitchListener listener) { 295 + public void removeListener(OpenFlowSwitchListener listener) {
295 } 296 }
296 297
297 @Override 298 @Override
298 - public void removeListener(OpenFlowSwitchListener listener) { 299 + public void addMessageListener(OpenFlowMessageListener listener) {
300 +
301 + }
302 +
303 + @Override
304 + public void removeMessageListener(OpenFlowMessageListener listener) {
305 +
299 } 306 }
300 307
301 @Override 308 @Override
...@@ -428,16 +435,6 @@ public class OpenFlowPacketProviderTest { ...@@ -428,16 +435,6 @@ public class OpenFlowPacketProviderTest {
428 public String channelId() { 435 public String channelId() {
429 return "1.2.3.4:1"; 436 return "1.2.3.4:1";
430 } 437 }
431 -
432 - @Override
433 - public void addEventListener(OpenFlowEventListener listener) {
434 - }
435 -
436 - @Override
437 - public void removeEventListener(OpenFlowEventListener listener) {
438 - }
439 -
440 -
441 } 438 }
442 439
443 } 440 }
......