Refactor the logic on collecting OpenFlow message statistics
Change-Id: I34c209c0ca90cb094ed5f82c96a8a43d3519b807
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java
index 8900d9d..20e2aed 100644
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java
+++ b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java
@@ -52,10 +52,6 @@
}
@Override
- public void monitorAllEvents(boolean monitor) {
- }
-
- @Override
public void addListener(OpenFlowSwitchListener listener) {
}
@@ -64,6 +60,16 @@
}
@Override
+ public void addMessageListener(OpenFlowMessageListener listener) {
+
+ }
+
+ @Override
+ public void removeMessageListener(OpenFlowMessageListener listener) {
+
+ }
+
+ @Override
public void addPacketListener(int priority, PacketListener listener) {
}
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitchTest.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitchTest.java
deleted file mode 100644
index f726e50..0000000
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitchTest.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.openflow.controller.driver;
-
-import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelConfig;
-import org.jboss.netty.channel.ChannelFactory;
-import org.jboss.netty.channel.ChannelFuture;
-import org.jboss.netty.channel.ChannelPipeline;
-import org.junit.Before;
-import org.junit.Test;
-import org.onosproject.openflow.controller.Dpid;
-import org.onosproject.openflow.controller.OpenFlowEventListener;
-import org.onosproject.openflow.controller.RoleState;
-import org.projectfloodlight.openflow.protocol.OFMessage;
-
-import java.net.SocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
-
-/**
- * Tests for packet processing in the abstract openflow switch class.
- */
-public class AbstractOpenFlowSwitchTest {
-
- OpenFlowSwitchImpl ofSwitch;
- TestExecutorService executorService;
-
- /**
- * Mock executor service that tracks submits.
- */
- static class TestExecutorService extends ExecutorServiceAdapter {
- private List<OFMessage> submittedMessages = new ArrayList<>();
-
- List<OFMessage> submittedMessages() {
- return submittedMessages;
- }
-
- @Override
- public void execute(Runnable task) {
- AbstractOpenFlowSwitch.OFMessageHandler handler =
- (AbstractOpenFlowSwitch.OFMessageHandler) task;
- submittedMessages.add(handler.msg);
- }
- }
-
- /**
- * Sets up switches to use as data.
- */
- @Before
- public void setUp() {
- ofSwitch = new OpenFlowSwitchImpl();
-
- executorService = new TestExecutorService();
- ofSwitch.executorMsgs = executorService;
- Channel channel = new MockChannel();
- ofSwitch.setChannel(channel);
- ofSwitch.role = RoleState.MASTER;
- ofSwitch.addEventListener(new OpenFlowEventListenerAdapter());
- }
-
- /**
- * Tests a packet out operation.
- */
- @Test
- public void testPacketOut() {
- OFMessage ofPacketOut = new MockOfPacketOut();
- ofSwitch.sendMsg(ofPacketOut);
- assertThat(executorService.submittedMessages(), hasSize(1));
- assertThat(executorService.submittedMessages().get(0), is(ofPacketOut));
- }
-
- /**
- * Tests a flow mod operation.
- */
- @Test
- public void testFlowMod() {
- OFMessage ofFlowMod = new MockOfFlowMod();
- ofSwitch.sendMsg(ofFlowMod);
- assertThat(executorService.submittedMessages(), hasSize(1));
- assertThat(executorService.submittedMessages().get(0), is(ofFlowMod));
- }
-
- /**
- * Tests a stats request operation.
- */
- @Test
- public void testStatsRequest() {
- OFMessage ofStatsRequest = new MockOfStatsRequest();
- ofSwitch.sendMsg(ofStatsRequest);
- assertThat(executorService.submittedMessages(), hasSize(1));
- assertThat(executorService.submittedMessages().get(0), is(ofStatsRequest));
- }
-
- protected class OpenFlowSwitchImpl extends AbstractOpenFlowSwitch {
-
- @Override
- public Boolean supportNxRole() {
- return null;
- }
-
- @Override
- public void startDriverHandshake() {
- }
-
- @Override
- public boolean isDriverHandshakeComplete() {
- return false;
- }
-
- @Override
- public void processDriverHandshakeMessage(OFMessage m) {
- }
- }
-
- private class OpenFlowEventListenerAdapter implements OpenFlowEventListener {
-
- @Override
- public void handleMessage(Dpid dpid, OFMessage msg) {
- }
- }
-
- private class MockChannel implements Channel {
-
- @Override
- public Integer getId() {
- return null;
- }
-
- @Override
- public ChannelFactory getFactory() {
- return null;
- }
-
- @Override
- public Channel getParent() {
- return null;
- }
-
- @Override
- public ChannelConfig getConfig() {
- return null;
- }
-
- @Override
- public ChannelPipeline getPipeline() {
- return null;
- }
-
- @Override
- public boolean isOpen() {
- return false;
- }
-
- @Override
- public boolean isBound() {
- return false;
- }
-
- @Override
- public boolean isConnected() {
- // we assume that the channel is connected
- return true;
- }
-
- @Override
- public SocketAddress getLocalAddress() {
- return null;
- }
-
- @Override
- public SocketAddress getRemoteAddress() {
- return null;
- }
-
- @Override
- public ChannelFuture write(Object message) {
- return null;
- }
-
- @Override
- public ChannelFuture write(Object message, SocketAddress remoteAddress) {
- return null;
- }
-
- @Override
- public ChannelFuture bind(SocketAddress localAddress) {
- return null;
- }
-
- @Override
- public ChannelFuture connect(SocketAddress remoteAddress) {
- return null;
- }
-
- @Override
- public ChannelFuture disconnect() {
- return null;
- }
-
- @Override
- public ChannelFuture unbind() {
- return null;
- }
-
- @Override
- public ChannelFuture close() {
- return null;
- }
-
- @Override
- public ChannelFuture getCloseFuture() {
- return null;
- }
-
- @Override
- public int getInterestOps() {
- return 0;
- }
-
- @Override
- public boolean isReadable() {
- return false;
- }
-
- @Override
- public boolean isWritable() {
- return false;
- }
-
- @Override
- public ChannelFuture setInterestOps(int interestOps) {
- return null;
- }
-
- @Override
- public ChannelFuture setReadable(boolean readable) {
- return null;
- }
-
- @Override
- public boolean getUserDefinedWritability(int index) {
- return false;
- }
-
- @Override
- public void setUserDefinedWritability(int index, boolean isWritable) {
-
- }
-
- @Override
- public Object getAttachment() {
- return null;
- }
-
- @Override
- public void setAttachment(Object attachment) {
-
- }
-
- @Override
- public int compareTo(Channel o) {
- return 0;
- }
- }
-}
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/ExecutorServiceAdapter.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/ExecutorServiceAdapter.java
deleted file mode 100644
index a50db99..0000000
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/ExecutorServiceAdapter.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.openflow.controller.driver;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * Test harness adapter for the ExecutorService.
- */
-public class ExecutorServiceAdapter implements ExecutorService {
- @Override
- public void shutdown() {
-
- }
-
- @Override
- public List<Runnable> shutdownNow() {
- return null;
- }
-
- @Override
- public boolean isShutdown() {
- return false;
- }
-
- @Override
- public boolean isTerminated() {
- return false;
- }
-
- @Override
- public boolean awaitTermination(long timeout, TimeUnit unit)
- throws InterruptedException {
- return false;
- }
-
- @Override
- public <T> Future<T> submit(Callable<T> task) {
- return null;
- }
-
- @Override
- public <T> Future<T> submit(Runnable task, T result) {
- return null;
- }
-
- @Override
- public Future<?> submit(Runnable task) {
- return null;
- }
-
- @Override
- public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
- throws InterruptedException {
- return null;
- }
-
- @Override
- public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
- throws InterruptedException {
- return null;
- }
-
- @Override
- public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
- return null;
- }
-
- @Override
- public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
- throws InterruptedException, ExecutionException, TimeoutException {
- return null;
- }
-
- @Override
- public void execute(Runnable command) {
-
- }
-}
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfFlowMod.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfFlowMod.java
deleted file mode 100644
index 27b356f..0000000
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfFlowMod.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.openflow.controller.driver;
-
-
-import org.projectfloodlight.openflow.protocol.OFFlowMod;
-import org.projectfloodlight.openflow.protocol.OFFlowModCommand;
-import org.projectfloodlight.openflow.protocol.OFType;
-import org.projectfloodlight.openflow.protocol.OFFlowModFlags;
-import org.projectfloodlight.openflow.protocol.action.OFAction;
-import org.projectfloodlight.openflow.protocol.instruction.OFInstruction;
-import org.projectfloodlight.openflow.protocol.match.Match;
-import org.projectfloodlight.openflow.types.OFBufferId;
-import org.projectfloodlight.openflow.types.OFPort;
-import org.projectfloodlight.openflow.types.TableId;
-import org.projectfloodlight.openflow.types.U64;
-import org.projectfloodlight.openflow.types.OFGroup;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * Mock of the Open Flow flow mod message.
- */
-public class MockOfFlowMod extends OfMessageAdapter implements OFFlowMod {
-
- public MockOfFlowMod() {
- super(OFType.FLOW_MOD);
- }
-
- @Override
- public U64 getCookie() {
- return null;
- }
-
- @Override
- public U64 getCookieMask() throws UnsupportedOperationException {
- return null;
- }
-
- @Override
- public TableId getTableId() throws UnsupportedOperationException {
- return null;
- }
-
- @Override
- public OFFlowModCommand getCommand() {
- return null;
- }
-
- @Override
- public int getIdleTimeout() {
- return 0;
- }
-
- @Override
- public int getHardTimeout() {
- return 0;
- }
-
- @Override
- public int getPriority() {
- return 0;
- }
-
- @Override
- public OFBufferId getBufferId() {
- return null;
- }
-
- @Override
- public OFPort getOutPort() {
- return null;
- }
-
- @Override
- public OFGroup getOutGroup() throws UnsupportedOperationException {
- return null;
- }
-
- @Override
- public Set<OFFlowModFlags> getFlags() {
- return null;
- }
-
- @Override
- public Match getMatch() {
- return null;
- }
-
- @Override
- public List<OFInstruction> getInstructions() throws UnsupportedOperationException {
- return null;
- }
-
- @Override
- public List<OFAction> getActions() throws UnsupportedOperationException {
- return null;
- }
-
- @Override
- public OFFlowMod.Builder createBuilder() {
- return null;
- }
-}
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfPacketOut.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfPacketOut.java
deleted file mode 100644
index a945950..0000000
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfPacketOut.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.openflow.controller.driver;
-
-import org.projectfloodlight.openflow.protocol.OFPacketOut;
-import org.projectfloodlight.openflow.protocol.OFType;
-import org.projectfloodlight.openflow.protocol.action.OFAction;
-import org.projectfloodlight.openflow.types.OFBufferId;
-import org.projectfloodlight.openflow.types.OFPort;
-
-import java.util.List;
-
-/**
- * Mock of the Open Flow packet out message.
- */
-public class MockOfPacketOut extends OfMessageAdapter implements OFPacketOut {
-
- public MockOfPacketOut() {
- super(OFType.PACKET_OUT);
- }
-
- @Override
- public OFBufferId getBufferId() {
- return null;
- }
-
- @Override
- public OFPort getInPort() {
- return null;
- }
-
- @Override
- public List<OFAction> getActions() {
- return null;
- }
-
- @Override
- public byte[] getData() {
- return new byte[0];
- }
-
- @Override
- public OFPacketOut.Builder createBuilder() {
- return null;
- }
-}
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfStatsRequest.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfStatsRequest.java
deleted file mode 100644
index 2eafec8..0000000
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/MockOfStatsRequest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.openflow.controller.driver;
-
-
-
-import org.projectfloodlight.openflow.protocol.OFStatsRequest;
-import org.projectfloodlight.openflow.protocol.OFStatsType;
-import org.projectfloodlight.openflow.protocol.OFType;
-import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags;
-
-import java.util.Set;
-
-/**
- * Mock of the Open Flow stats request message.
- */
-public class MockOfStatsRequest extends OfMessageAdapter implements OFStatsRequest {
-
- public MockOfStatsRequest() {
- super(OFType.STATS_REQUEST);
- }
-
- @Override
- public OFStatsType getStatsType() {
- return null;
- }
-
- @Override
- public Set<OFStatsReplyFlags> getFlags() {
- return null;
- }
-
- @Override
- public OFStatsRequest.Builder createBuilder() {
- return null;
- }
-}
diff --git a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/OfMessageAdapter.java b/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/OfMessageAdapter.java
deleted file mode 100644
index df6d855..0000000
--- a/protocols/openflow/api/src/test/java/org/onosproject/openflow/controller/driver/OfMessageAdapter.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2015-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.openflow.controller.driver;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.projectfloodlight.openflow.protocol.OFMessage;
-import org.projectfloodlight.openflow.protocol.OFType;
-import org.projectfloodlight.openflow.protocol.OFVersion;
-
-import com.google.common.hash.PrimitiveSink;
-
-/**
- * Adapter for testing against an OpenFlow message.
- */
-public class OfMessageAdapter implements OFMessage {
- OFType type;
-
- private OfMessageAdapter() {}
-
- public OfMessageAdapter(OFType type) {
- this.type = type;
- }
-
- @Override
- public OFType getType() {
- return type;
- }
-
- @Override
- public OFVersion getVersion() {
- return null;
- }
-
- @Override
- public long getXid() {
- return 0;
- }
-
- @Override
- public void writeTo(ChannelBuffer channelBuffer) { }
-
- @Override
- public Builder createBuilder() {
- return null;
- }
-
- @Override
- public void putTo(PrimitiveSink sink) { }
-}