Committed by
Gerrit Code Review
Bugfix: count outgoing control messages if CPMan is activated
Previous implementation omits all outgoing messages when the role is configured as Master. With the revised version, the controller would more precisely count the number of outgoing control messages. Change-Id: I90c06097cb297535bce37e4a0ed5734cf01871bf
Showing
2 changed files
with
156 additions
and
3 deletions
1 | /* | 1 | /* |
2 | - * Copyright 2014-2015 Open Networking Laboratory | 2 | + * Copyright 2014-2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -164,7 +164,9 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour | ... | @@ -164,7 +164,9 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour |
164 | dpid, role, channel.isConnected(), msgs); | 164 | dpid, role, channel.isConnected(), msgs); |
165 | } | 165 | } |
166 | } | 166 | } |
167 | + } | ||
167 | 168 | ||
169 | + private void countOutgoingMsg(List<OFMessage> msgs) { | ||
168 | // listen to outgoing control messages only if listeners are registered | 170 | // listen to outgoing control messages only if listeners are registered |
169 | if (ofOutgoingMsgListener.size() != 0) { | 171 | if (ofOutgoingMsgListener.size() != 0) { |
170 | msgs.forEach(m -> { | 172 | msgs.forEach(m -> { |
... | @@ -180,6 +182,7 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour | ... | @@ -180,6 +182,7 @@ public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour |
180 | private void sendMsgsOnChannel(List<OFMessage> msgs) { | 182 | private void sendMsgsOnChannel(List<OFMessage> msgs) { |
181 | if (channel.isConnected()) { | 183 | if (channel.isConnected()) { |
182 | channel.write(msgs); | 184 | channel.write(msgs); |
185 | + countOutgoingMsg(msgs); | ||
183 | } else { | 186 | } else { |
184 | log.warn("Dropping messages for switch {} because channel is not connected: {}", | 187 | log.warn("Dropping messages for switch {} because channel is not connected: {}", |
185 | dpid, msgs); | 188 | dpid, msgs); | ... | ... |
... | @@ -16,13 +16,18 @@ | ... | @@ -16,13 +16,18 @@ |
16 | package org.onosproject.openflow.controller.driver; | 16 | package org.onosproject.openflow.controller.driver; |
17 | 17 | ||
18 | import org.jboss.netty.channel.Channel; | 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; | ||
19 | import org.junit.Before; | 23 | import org.junit.Before; |
20 | import org.junit.Test; | 24 | import org.junit.Test; |
21 | -import org.onosproject.core.netty.ChannelAdapter; | ||
22 | import org.onosproject.openflow.controller.Dpid; | 25 | import org.onosproject.openflow.controller.Dpid; |
23 | import org.onosproject.openflow.controller.OpenFlowEventListener; | 26 | import org.onosproject.openflow.controller.OpenFlowEventListener; |
27 | +import org.onosproject.openflow.controller.RoleState; | ||
24 | import org.projectfloodlight.openflow.protocol.OFMessage; | 28 | import org.projectfloodlight.openflow.protocol.OFMessage; |
25 | 29 | ||
30 | +import java.net.SocketAddress; | ||
26 | import java.util.ArrayList; | 31 | import java.util.ArrayList; |
27 | import java.util.List; | 32 | import java.util.List; |
28 | 33 | ||
... | @@ -65,8 +70,9 @@ public class AbstractOpenFlowSwitchTest { | ... | @@ -65,8 +70,9 @@ public class AbstractOpenFlowSwitchTest { |
65 | 70 | ||
66 | executorService = new TestExecutorService(); | 71 | executorService = new TestExecutorService(); |
67 | ofSwitch.executorMsgs = executorService; | 72 | ofSwitch.executorMsgs = executorService; |
68 | - Channel channel = new ChannelAdapter(); | 73 | + Channel channel = new MockChannel(); |
69 | ofSwitch.setChannel(channel); | 74 | ofSwitch.setChannel(channel); |
75 | + ofSwitch.role = RoleState.MASTER; | ||
70 | ofSwitch.addEventListener(new OpenFlowEventListenerAdapter()); | 76 | ofSwitch.addEventListener(new OpenFlowEventListenerAdapter()); |
71 | } | 77 | } |
72 | 78 | ||
... | @@ -130,4 +136,148 @@ public class AbstractOpenFlowSwitchTest { | ... | @@ -130,4 +136,148 @@ public class AbstractOpenFlowSwitchTest { |
130 | public void handleMessage(Dpid dpid, OFMessage msg) { | 136 | public void handleMessage(Dpid dpid, OFMessage msg) { |
131 | } | 137 | } |
132 | } | 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 | + } | ||
133 | } | 283 | } | ... | ... |
-
Please register or login to post a comment