Skip to content
Snippets Groups Projects
Commit 9a0eaec8 authored by Shudong Zhou's avatar Shudong Zhou
Browse files

More removal of OFSwitchImpl references

parent 36c7cffc
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,11 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.locks.Lock;
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
import net.floodlightcontroller.core.internal.Controller;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import org.jboss.netty.channel.Channel;
import org.openflow.protocol.OFFeaturesReply;
......@@ -394,4 +398,20 @@ public interface IOFSwitch {
* @return
*/
public boolean checkFirstPendingRoleRequestCookie(long cookie);
public void setChannel(Channel channel);
public void setFloodlightProvider(Controller controller);
public void setThreadPoolService(IThreadPoolService threadPool);
public void deliverRoleReply(int xid, Role role);
public void deliverRoleRequestNotSupported(int xid);
public Lock getListenerReadLock();
public boolean checkFirstPendingRoleRequestXid(int xid);
public Lock getListenerWriteLock();
}
......@@ -410,7 +410,7 @@ public class Controller implements IFloodlightProviderService,
*/
protected class OFChannelHandler
extends IdleStateAwareChannelUpstreamHandler {
protected OFSwitchImpl sw;
protected IOFSwitch sw;
protected OFChannelState state;
public OFChannelHandler(OFChannelState state) {
......@@ -426,6 +426,7 @@ public class Controller implements IFloodlightProviderService,
log.info("New switch connection from {}",
e.getChannel().getRemoteAddress());
// Use OFSwitchImpl initially
sw = new OFSwitchImpl();
sw.setChannel(e.getChannel());
sw.setFloodlightProvider(Controller.this);
......@@ -1043,14 +1044,15 @@ public class Controller implements IFloodlightProviderService,
state.firstRoleReplyReceived = true;
sw.deliverRoleRequestNotSupported(error.getXid());
synchronized(roleChanger) {
if (sw.role == null && Controller.this.role==Role.SLAVE) {
if (sw.getRole() == null &&
Controller.this.role==Role.SLAVE) {
// the switch doesn't understand role request
// messages and the current controller role is
// slave. We need to disconnect the switch.
// @see RoleChanger for rationale
sw.getChannel().close();
}
else if (sw.role == null) {
else if (sw.getRole() == null) {
// Controller's role is master: add to
// active
// TODO: check if clearing flow table is
......@@ -1397,7 +1399,7 @@ public class Controller implements IFloodlightProviderService,
protected void addSwitch(IOFSwitch sw, boolean shouldClearFlowMods) {
// TODO: is it safe to modify the HashMap without holding
// the old switch's lock?
OFSwitchImpl oldSw = (OFSwitchImpl) this.activeSwitches.put(sw.getId(), sw);
IOFSwitch oldSw = this.activeSwitches.put(sw.getId(), sw);
if (sw == oldSw) {
// Note == for object equality, not .equals for value
log.info("New add switch for pre-existing switch {}", sw);
......
......@@ -129,12 +129,12 @@ public class OFSwitchImpl implements IOFSwitch {
protected long datapathId;
public static IOFSwitchFeatures switchFeatures;
protected static final ThreadLocal<Map<OFSwitchImpl,List<OFMessage>>> local_msg_buffer =
new ThreadLocal<Map<OFSwitchImpl,List<OFMessage>>>() {
@Override
protected Map<OFSwitchImpl,List<OFMessage>> initialValue() {
return new HashMap<OFSwitchImpl,List<OFMessage>>();
}
protected static final ThreadLocal<Map<IOFSwitch,List<OFMessage>>> local_msg_buffer =
new ThreadLocal<Map<IOFSwitch,List<OFMessage>>>() {
@Override
protected Map<IOFSwitch,List<OFMessage>> initialValue() {
return new HashMap<IOFSwitch,List<OFMessage>>();
}
};
// for managing our map sizes
......@@ -214,7 +214,7 @@ public class OFSwitchImpl implements IOFSwitch {
@Override
public void write(OFMessage m, FloodlightContext bc) throws IOException {
Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
Map<IOFSwitch,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
List<OFMessage> msg_buffer = msg_buffer_map.get(this);
if (msg_buffer == null) {
msg_buffer = new ArrayList<OFMessage>();
......@@ -569,7 +569,7 @@ public class OFSwitchImpl implements IOFSwitch {
@Override
public void flush() {
Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
Map<IOFSwitch,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
List<OFMessage> msglist = msg_buffer_map.get(this);
if ((msglist != null) && (msglist.size() > 0)) {
try {
......@@ -583,8 +583,8 @@ public class OFSwitchImpl implements IOFSwitch {
}
public static void flush_all() {
Map<OFSwitchImpl,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
for (OFSwitchImpl sw : msg_buffer_map.keySet()) {
Map<IOFSwitch,List<OFMessage>> msg_buffer_map = local_msg_buffer.get();
for (IOFSwitch sw : msg_buffer_map.keySet()) {
sw.flush();
}
}
......@@ -713,7 +713,7 @@ public class OFSwitchImpl implements IOFSwitch {
explanation="The switch sent an unexpected HA role reply",
recommendation=HA_CHECK_SWITCH)
})
protected void deliverRoleReply(int xid, Role role) {
public void deliverRoleReply(int xid, Role role) {
synchronized(pendingRoleRequests) {
PendingRoleRequestEntry head = pendingRoleRequests.poll();
if (head == null) {
......@@ -755,7 +755,7 @@ public class OFSwitchImpl implements IOFSwitch {
* @param xid
* @return
*/
protected boolean checkFirstPendingRoleRequestXid (int xid) {
public boolean checkFirstPendingRoleRequestXid (int xid) {
synchronized(pendingRoleRequests) {
PendingRoleRequestEntry head = pendingRoleRequests.peek();
if (head == null)
......@@ -788,7 +788,7 @@ public class OFSwitchImpl implements IOFSwitch {
* Otherwise we ignore it.
* @param xid
*/
protected void deliverRoleRequestNotSupported(int xid) {
public void deliverRoleRequestNotSupported(int xid) {
synchronized(pendingRoleRequests) {
PendingRoleRequestEntry head = pendingRoleRequests.poll();
this.role = null;
......@@ -857,4 +857,10 @@ public class OFSwitchImpl implements IOFSwitch {
public byte getTables() {
return tables;
}
@Override
public void setFloodlightProvider(Controller controller) {
floodlightProvider = controller;
}
}
......@@ -934,6 +934,7 @@ public class ControllerTest extends FloodlightTestCase {
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
chdlr.sw.deliverRoleRequestNotSupported(xid);
expect(chdlr.sw.getChannel()).andReturn(ch).anyTimes();
expect(chdlr.sw.getRole()).andReturn(null).anyTimes();
expect(ch.close()).andReturn(null);
replay(ch, chdlr.sw);
......@@ -954,6 +955,7 @@ public class ControllerTest extends FloodlightTestCase {
expect(chdlr.sw.checkFirstPendingRoleRequestXid(xid)).andReturn(true);
chdlr.sw.deliverRoleRequestNotSupported(xid);
expect(chdlr.sw.getChannel()).andReturn(ch).anyTimes();
expect(chdlr.sw.getRole()).andReturn(null).anyTimes();
expect(ch.close()).andReturn(null);
replay(ch, chdlr.sw);
......@@ -974,6 +976,7 @@ public class ControllerTest extends FloodlightTestCase {
chdlr.sw.deliverRoleRequestNotSupported(xid);
setupSwitchForAddSwitch(chdlr.sw, 0L);
chdlr.sw.clearAllFlowMods();
expect(chdlr.sw.getRole()).andReturn(null).anyTimes();
replay(ch, chdlr.sw);
chdlr.processOFMessage(msg);
......
......@@ -8,11 +8,14 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Future;
import java.util.concurrent.locks.Lock;
import net.floodlightcontroller.core.FloodlightContext;
import net.floodlightcontroller.core.IOFMessageListener;
import net.floodlightcontroller.core.IOFSwitch;
import net.floodlightcontroller.core.IFloodlightProviderService.Role;
import net.floodlightcontroller.core.internal.Controller;
import net.floodlightcontroller.threadpool.IThreadPoolService;
import org.jboss.netty.channel.Channel;
import org.openflow.protocol.OFFeaturesReply;
......@@ -358,4 +361,52 @@ public class OFMessageDamperMockSwitch implements IOFSwitch {
return false;
}
@Override
public void setChannel(Channel channel) {
// TODO Auto-generated method stub
}
@Override
public void setFloodlightProvider(Controller controller) {
// TODO Auto-generated method stub
}
@Override
public void setThreadPoolService(IThreadPoolService threadPool) {
// TODO Auto-generated method stub
}
@Override
public void deliverRoleReply(int xid, Role role) {
// TODO Auto-generated method stub
}
@Override
public void deliverRoleRequestNotSupported(int xid) {
// TODO Auto-generated method stub
}
@Override
public Lock getListenerReadLock() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean checkFirstPendingRoleRequestXid(int xid) {
// TODO Auto-generated method stub
return false;
}
@Override
public Lock getListenerWriteLock() {
// TODO Auto-generated method stub
return null;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment