Fixed switches and ports being deleted from the database
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
index 1c243c0..2cfab3f 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -34,6 +34,10 @@
*/
public boolean deleteSwitch(String dpid);
/*
+ * Deactivate the switch and associated ports
+ */
+ public boolean deactivateSwitch(String dpid);
+ /*
* Update the port details
*/
public boolean updatePort(String dpid, short port, int state, String desc);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index 7f0c259..6377605 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -62,6 +62,14 @@
* @param state The state of the switch like ACTIVE, INACTIVE
* @param dmope The DM_OPERATION of the switch
*/
+ /*
+ * Jono, 11/8/2013
+ * We don't need this update method that demultiplexes DM_OPERATIONS,
+ * we can have clients just call the required methods directly.
+ * We especially don't need this update method to re-implement
+ * the functions of other methods.
+ */
+ @Deprecated
@Override
public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION dmope) {
boolean success = false;
@@ -191,7 +199,7 @@
} catch (Exception e) {
op.rollback();
e.printStackTrace();
- log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ log.error("SwitchStorage:addSwitch dpid:{} failed", dpid, e);
}
return success;
@@ -220,6 +228,32 @@
return success;
}
+
+ public boolean deactivateSwitch(String dpid) {
+ boolean success = false;
+
+ try {
+ ISwitchObject switchObject = op.searchSwitch(dpid);
+ if (switchObject != null) {
+ setSwitchStateImpl(switchObject, SwitchState.INACTIVE);
+
+ for (IPortObject portObject : switchObject.getPorts()) {
+ portObject.setState("INACTIVE");
+ }
+ op.commit();
+ success = true;
+ }
+ else {
+ log.warn("Switch {} not found when trying to deactivate", dpid);
+ }
+ } catch (Exception e) {
+ // TODO what type of exception is thrown when we can't commit?
+ op.rollback();
+ log.error("SwitchStorage:deactivateSwitch {} failed", dpid, e);
+ }
+
+ return success;
+ }
public boolean updatePort(String dpid, short portNum, int state, String desc) {
boolean success = false;
@@ -259,6 +293,8 @@
if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & phport.getConfig()) > 0) ||
((OFPortState.OFPPS_LINK_DOWN.getValue() & phport.getState()) > 0)) {
// just dispatch to deletePort()
+ // TODO This is wrong. We need to make sure the port is in the
+ // DB with the correct info and port state.
return deletePort(dpid, phport.getPortNumber());
}
@@ -305,7 +341,8 @@
IPortObject p = sw.getPort(port);
if (p != null) {
log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port);
- deletePortImpl(p);
+ //deletePortImpl(p);
+ p.setState("INACTIVE");
op.commit();
}
}
@@ -313,7 +350,7 @@
} catch (Exception e) {
op.rollback();
e.printStackTrace();
- log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
+ log.error("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
}
return success;
diff --git a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
index 648f6f1..6364a2f 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -108,7 +108,8 @@
List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(dpid));
links.addAll(reverseLinks);
- if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
+ //if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
+ if (swStore.deactivateSwitch(HexString.toHexString(dpid))) {
registryService.releaseControl(dpid);
// TODO publish UPDATE_SWITCH event here
@@ -268,6 +269,7 @@
@Override
public void removedSwitch(IOFSwitch sw) {
+ /*
if (registryService.hasControl(sw.getId())) {
// Get the affected ports
List<Short> ports = swStore.getPorts(HexString.toHexString(sw.getId()));
@@ -300,6 +302,7 @@
}
}
}
+ */
}
@Override