Squashed commit of the following:
commit e9604083c5374bf5eac889e82cf54bb0b22ef763
Author: Naoki Shiota <n-shiota@onlab.us>
Date: Wed Oct 23 11:51:00 2013 -0700
Refactored NetworkGraphPublisher and related modules to be ready for implementing event notification.
diff --git a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
index bebcdd2..56a54f2 100644
--- a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
@@ -7,6 +7,7 @@
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.diskstorage.StorageException;
import com.tinkerpop.blueprints.TransactionalGraph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
@@ -133,15 +134,17 @@
/**
* Commit changes for the graph operations.
+ * @throws Exception
*/
@Override
public void commit() {
- try {
+// // Should not catch exception here!
+// try {
graph.commit();
- }
- catch (Exception e) {
- log.error("{}", e.toString());
- }
+// }
+// catch (Exception e) {
+// log.error("{}", e.toString());
+// }
}
/**
@@ -149,12 +152,13 @@
*/
@Override
public void rollback() {
- try {
+ // Should not catch exception here!
+// try {
graph.rollback();
- }
- catch (Exception e) {
- log.error("{}", e.toString());
- }
+// }
+// catch (Exception e) {
+// log.error("{}", e.toString());
+// }
}
/**
@@ -162,6 +166,10 @@
*/
@Override
public void close() {
- commit();
+ try {
+ commit();
+ } catch (Exception e) {
+ log.error("{}", e.toString());
+ }
}
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
index ce2379b..483fbda 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
@@ -15,26 +15,27 @@
/*
* Generic operation method
*/
- public void update(Link link, LinkInfo linkinfo, DM_OPERATION op);
+ public boolean update(Link link, LinkInfo linkinfo, DM_OPERATION op);
/*
* Link creation
*/
- public void addLink(Link link);
- public void addLinks(List<Link> links);
+ public boolean addLink(Link link);
+ public boolean addLink(Link link, LinkInfo linfo);
+ public boolean addLinks(List<Link> links);
/*
* Link deletion
*/
- public void deleteLink(Link link);
- public void deleteLinks(List<Link> links);
+ public boolean deleteLink(Link link);
+ public boolean deleteLinks(List<Link> links);
/*
* Utility method to delete links associated with dpid and port
* If only dpid is used, All links associated for switch are removed
* Useful for port up/down and also switch join/remove events
*/
- public void deleteLinksOnPort(Long dpid, short port);
+ public boolean deleteLinksOnPort(Long dpid, short port);
/*
* Get Links from Storage
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 bc50049..b7825f9 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -18,27 +18,29 @@
/*
* Update the switch details
*/
- public void update(String dpid,SwitchState state, DM_OPERATION op);
- /*
- * Associate a port on switch
- */
- public void addPort(String dpid, OFPhysicalPort port);
- /*
- * Delete a port on a switch by num
- */
- public void deletePort(String dpid, short port);
+ public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION op);
/*
* Add a switch and all its associated ports
*/
- public void addSwitch(IOFSwitch sw);
+ public boolean addSwitch(IOFSwitch sw);
/*
* Add a switch
*/
- public void addSwitch(String dpid);
+ public boolean addSwitch(String dpid);
/*
* Delete switch and associated ports
*/
- public void deleteSwitch(String dpid);
-
-
+ public boolean deleteSwitch(String dpid);
+ /*
+ * Update the port details
+ */
+ public boolean updatePort(String dpid, short port, int state, String desc);
+ /*
+ * Associate a port on switch
+ */
+ public boolean addPort(String dpid, OFPhysicalPort port);
+ /*
+ * Delete a port on a switch by num
+ */
+ public boolean deletePort(String dpid, short port);
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
index 753563e..da34c22 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
@@ -14,7 +14,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.thinkaurelius.titan.core.TitanException;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.pipes.PipeFunction;
import com.tinkerpop.pipes.transform.PathPipe;
@@ -25,7 +24,7 @@
public class LinkStorageImpl implements ILinkStorage {
protected static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
- protected GraphDBOperation dbop;
+ protected GraphDBOperation op;
/**
@@ -34,37 +33,105 @@
*/
@Override
public void init(String conf) {
- this.dbop = new GraphDBOperation(conf);
+ this.op = new GraphDBOperation(conf);
}
+ // Method designing policy:
+ // op.commit() and op.rollback() MUST called in public (first-class) methods.
+ // A first-class method MUST NOT call other first-class method.
+ // Routine process should be implemented in private method.
+ // A private method MUST NOT call commit or rollback.
+
+
/**
- * Update a record in the LinkStorage in a way provided by op.
+ * Update a record in the LinkStorage in a way provided by dmop.
* @param link Record of a link to be updated.
- * @param op Operation to be done.
+ * @param linkinfo Meta-information of a link to be updated.
+ * @param dmop Operation to be done.
*/
@Override
- public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) {
- switch (op) {
+ public boolean update(Link link, LinkInfo linkinfo, DM_OPERATION dmop) {
+ boolean success = false;
+
+ switch (dmop) {
case CREATE:
case INSERT:
- addLinkImpl(link,op);
+ if (link != null) {
+ try {
+ if (addLinkImpl(link)) {
+ op.commit();
+ success = true;
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("LinkStorageImpl:update {} link:{} failed", dmop, link);
+ }
+ }
break;
case UPDATE:
- if (linkinfo != null) {
- setLinkInfo(link, linkinfo);
- } else {
- deleteLinkInfo(link);
+ if (link != null && linkinfo != null) {
+ try {
+ if (setLinkInfoImpl(link, linkinfo)) {
+ op.commit();
+ success = true;
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("LinkStorageImpl:update {} link:{} failed", dmop, link);
+ }
}
break;
case DELETE:
- deleteLink(link);
+ if (link != null) {
+ try {
+ if (deleteLinkImpl(link)) {
+ op.commit();
+ success = true;
+ log.debug("LinkStorageImpl:update {} link:{} succeeded", dmop, link);
+ } else {
+ op.rollback();
+ log.debug("LinkStorageImpl:update {} link:{} failed", dmop, link);
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("LinkStorageImpl:update {} link:{} failed", dmop, link);
+ }
+ }
break;
}
+
+ return success;
}
@Override
- public void addLink(Link link) {
- addLinkImpl(link, DM_OPERATION.INSERT);
+ public boolean addLink(Link link) {
+ return addLink(link, null);
+ }
+
+ @Override
+ public boolean addLink(Link link, LinkInfo linfo) {
+ boolean success = false;
+
+ try {
+ if (addLinkImpl(link)) {
+ // Set LinkInfo only if linfo is non-null.
+ if (linfo != null && (! setLinkInfoImpl(link, linfo))) {
+ op.rollback();
+ }
+ op.commit();
+ success = true;
+ } else {
+ op.rollback();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ log.error("LinkStorageImpl:addLink link:{} linfo:{} failed", link, linfo);
+ }
+
+ return success;
}
/**
@@ -73,143 +140,82 @@
* @param op Operation to be done.
*/
@Override
- public void addLinks(List<Link> links) {
+ public boolean addLinks(List<Link> links) {
+ boolean success = false;
+
for (Link lt: links) {
- addLinkImpl(lt, DM_OPERATION.INSERT);
+ if (! addLinkImpl(lt)) {
+ return false;
+ }
}
+
+ try {
+ op.commit();
+ success = true;
+ } catch (Exception e) {
+ e.printStackTrace();
+ log.error("LinkStorageImpl:addLinks link:s{} failed", links);
+ }
+
+ return success;
}
/**
- * Delete a record in the LinkStorage.
- * @param lt Record to be deleted.
- */
- @Override
- public void deleteLink(Link lt) {
- IPortObject vportSrc = null, vportDst = null;
-
- log.debug("deleteLink(): {}", lt);
-
- try {
- // get source port vertex
- String dpid = HexString.toHexString(lt.getSrc());
- short port = lt.getSrcPort();
- vportSrc = dbop.searchPort(dpid, port);
-
- // get dst port vertex
- dpid = HexString.toHexString(lt.getDst());
- port = lt.getDstPort();
- vportDst = dbop.searchPort(dpid, port);
- // FIXME: This needs to remove all edges
-
- if (vportSrc != null && vportDst != null) {
- vportSrc.removeLink(vportDst);
- dbop.commit();
- log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
- lt, vportSrc, vportDst});
-
- // TODO publish DELETE_LINK event here
- } else {
- log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
- dbop.rollback();
- }
-
- } catch (TitanException e) {
- /*
- * retry till we succeed?
- */
- log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
- dbop.rollback();
- e.printStackTrace();
- }
- }
+ * Delete a record in the LinkStorage.
+ * @param lt Record to be deleted.
+ */
+ @Override
+ public boolean deleteLink(Link lt) {
+ boolean success = false;
+
+ log.debug("LinkStorageImpl:deleteLink(): {}", lt);
+
+ try {
+ if (deleteLinkImpl(lt)) {
+ op.commit();
+ success = true;
+ log.debug("LinkStorageImpl:deleteLink(): deleted edges {}", lt);
+ } else {
+ op.rollback();
+ log.error("LinkStorageImpl:deleteLink(): failed invalid vertices {}", lt);
+ }
+ } catch (Exception e) {
+ op.rollback();
+ log.error("LinkStorageImpl:deleteLink(): failed {} {}",
+ new Object[]{lt, e.toString()});
+ e.printStackTrace();
+ }
+
+ return success;
+ }
/**
* Delete multiple records in LinkStorage.
* @param links List of records to be deleted.
*/
@Override
- public void deleteLinks(List<Link> links) {
- for (Link lt : links) {
- deleteLink(lt);
+ public boolean deleteLinks(List<Link> links) {
+ boolean success = false;
+
+ try {
+ for (Link lt : links) {
+ if (! deleteLinkImpl(lt)) {
+ op.rollback();
+ return false;
+ }
+ }
+ op.commit();
+ success = true;
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("LinkStorageImpl:deleteLinks failed invalid vertices {}", links);
}
- }
-
- /**
- * Update a record of link with meta-information in the LinkStorage in a way provided by op.
- * @param link Record of a link to update.
- * @param linkinfo Meta-information of a link to be updated.
- * @param op Operation to be done.
- */
- private void setLinkInfo(Link link, LinkInfo linkinfo) {
- // TODO implement this
- // TODO publish UPDATE_LINK event here
- }
-
- private void deleteLinkInfo(Link link) {
- // TODO implement this
-
- // TODO publish UPDATE_LINK event here
+ return success;
}
/**
- * Perform INSERT/CREATE/UPDATE operation to update the LinkStorage.
- * @param lt Record of a link to be updated.
- * @param linkinfo Meta-information of a link to be updated.
- * @param op Operation to be done. (only INSERT/CREATE/UPDATE is acceptable)
- */
- private void addLinkImpl(Link lt, DM_OPERATION op) {
- IPortObject vportSrc = null, vportDst = null;
-
- log.trace("updateLink(): op {} {}", new Object[]{op, lt});
-
- try {
- // get source port vertex
- String dpid = HexString.toHexString(lt.getSrc());
- short port = lt.getSrcPort();
- vportSrc = dbop.searchPort(dpid, port);
-
- // get dest port vertex
- dpid = HexString.toHexString(lt.getDst());
- port = lt.getDstPort();
- vportDst = dbop.searchPort(dpid, port);
-
- if (vportSrc != null && vportDst != null) {
- // check if the link exists
-
- Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts();
- List<IPortObject> currLinks = new ArrayList<IPortObject>();
- for (IPortObject V : currPorts) {
- currLinks.add(V);
- }
-
- if (currLinks.contains(vportDst)) {
- if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) {
- log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}",
- new Object[]{op, lt, vportSrc, vportDst});
- }
- } else {
- vportSrc.setLinkPort(vportDst);
-
- dbop.commit();
- log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
-
- // TODO publish ADD_LINK event here
- }
- } else {
- log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
- dbop.rollback();
- }
- } catch (TitanException e) {
- /*
- * retry till we succeed?
- */
- e.printStackTrace();
- log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()});
- }
- }
-
- /**
* Get list of all links connected to the port specified by given DPID and port number.
* @param dpid DPID of desired port.
* @param port Port number of desired port.
@@ -219,7 +225,7 @@
public List<Link> getLinks(Long dpid, short port) {
List<Link> links = new ArrayList<Link>();
- IPortObject srcPort = dbop.searchPort(HexString.toHexString(dpid), port);
+ IPortObject srcPort = op.searchPort(HexString.toHexString(dpid), port);
ISwitchObject srcSw = srcPort.getSwitch();
if(srcSw != null && srcPort != null) {
@@ -243,12 +249,27 @@
* @param port Port number of desired port.
*/
@Override
- public void deleteLinksOnPort(Long dpid, short port) {
- List<Link> linksToDelete = getLinks(dpid, port);
+ public boolean deleteLinksOnPort(Long dpid, short port) {
+ boolean success = false;
- for(Link l : linksToDelete) {
- deleteLink(l);
+ List<Link> linksToDelete = getLinks(dpid, port);
+ try {
+ for(Link l : linksToDelete) {
+ if (! deleteLinkImpl(l)) {
+ op.rollback();
+ log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port);
+ return false;
+ }
+ }
+ op.commit();
+ success = true;
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port);
}
+
+ return success;
}
/**
@@ -260,7 +281,7 @@
public List<Link> getLinks(String dpid) {
List<Link> links = new ArrayList<Link>();
- ISwitchObject srcSw = dbop.searchSwitch(dpid);
+ ISwitchObject srcSw = op.searchSwitch(dpid);
if(srcSw != null) {
for(IPortObject srcPort : srcSw.getPorts()) {
@@ -285,7 +306,7 @@
* @return List of active links. Empty list if no port was found.
*/
public List<Link> getActiveLinks() {
- Iterable<ISwitchObject> switches = dbop.getActiveSwitches();
+ Iterable<ISwitchObject> switches = op.getActiveSwitches();
List<Link> links = new ArrayList<Link>();
@@ -329,6 +350,79 @@
// graph.shutdown();
}
+ /**
+ * Update a record of link with meta-information in the LinkStorage.
+ * @param link Record of a link to update.
+ * @param linkinfo Meta-information of a link to be updated.
+ */
+ private boolean setLinkInfoImpl(Link link, LinkInfo linkinfo) {
+ // TODO implement this
+
+ return false;
+ }
+
+ private boolean addLinkImpl(Link lt) {
+ boolean success = false;
+
+ IPortObject vportSrc = null, vportDst = null;
+
+ // get source port vertex
+ String dpid = HexString.toHexString(lt.getSrc());
+ short port = lt.getSrcPort();
+ vportSrc = op.searchPort(dpid, port);
+
+ // get dest port vertex
+ dpid = HexString.toHexString(lt.getDst());
+ port = lt.getDstPort();
+ vportDst = op.searchPort(dpid, port);
+
+ if (vportSrc != null && vportDst != null) {
+ IPortObject portExist = null;
+ // check if the link exists
+ for (IPortObject V : vportSrc.getLinkedPorts()) {
+ if (V.equals(vportDst)) {
+ portExist = V;
+ break;
+ }
+ }
+
+ if (portExist == null) {
+ vportSrc.setLinkPort(vportDst);
+ success = true;
+ } else {
+ log.debug("LinkStorageImpl:addLinkImpl failed link exists {} {} src {} dst {}",
+ new Object[]{op, lt, vportSrc, vportDst});
+ }
+ }
+
+ return success;
+ }
+
+ private boolean deleteLinkImpl(Link lt) {
+ boolean success = false;
+ IPortObject vportSrc = null, vportDst = null;
+
+ // get source port vertex
+ String dpid = HexString.toHexString(lt.getSrc());
+ short port = lt.getSrcPort();
+ vportSrc = op.searchPort(dpid, port);
+
+ // get dst port vertex
+ dpid = HexString.toHexString(lt.getDst());
+ port = lt.getDstPort();
+ vportDst = op.searchPort(dpid, port);
+
+ // FIXME: This needs to remove all edges
+ if (vportSrc != null && vportDst != null) {
+ vportSrc.removeLink(vportDst);
+ log.debug("deleteLinkImpl(): deleted edges src {} dst {}", new Object[]{
+ lt, vportSrc, vportDst});
+ success = true;
+ }
+
+ return success;
+ }
+
// TODO should be moved to TopoLinkServiceImpl (never used in this class)
static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
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 d9f24e0..8399d6f 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
@@ -1,8 +1,5 @@
package net.onrc.onos.ofcontroller.core.internal;
-import java.util.ArrayList;
-import java.util.List;
-
import net.floodlightcontroller.core.IOFSwitch;
import net.onrc.onos.graph.GraphDBConnection;
import net.onrc.onos.graph.GraphDBOperation;
@@ -17,7 +14,7 @@
import org.slf4j.LoggerFactory;
/**
- * This is the class for storing the information of switches into CassandraDB
+ * This is the class for storing the information of switches into GraphDB
*/
public class SwitchStorageImpl implements ISwitchStorage {
protected GraphDBOperation op;
@@ -50,23 +47,12 @@
op.close();
}
- private void setStatus(String dpid, SwitchState state) {
- ISwitchObject sw = op.searchSwitch(dpid);
-
- try {
- if (sw != null) {
- sw.setState(state.toString());
- op.commit();
- log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
- // TODO publish UPDATE_SWITCH event here
- }
- } catch(Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);
- }
- }
-
+ // Method designing policy:
+ // op.commit() and op.rollback() MUST called in public (first-class) methods.
+ // A first-class method MUST NOT call other first-class method.
+ // Routine process should be implemented in private method.
+ // A private method MUST NOT call commit or rollback.
+
/***
* This function is for updating the switch into the DB.
* @param dpid The switch dpid you want to update from the DB
@@ -74,71 +60,221 @@
* @param dmope The DM_OPERATION of the switch
*/
@Override
- public void update(String dpid, SwitchState state, DM_OPERATION dmope) {
- log.info("SwitchStorage:update dpid:{} state: {} ", dpid, state);
+ public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION dmope) {
+ boolean success = false;
+ ISwitchObject sw = null;
+
+ log.info("SwitchStorage:update {} dpid:{}", dmope, dpid);
switch(dmope) {
case UPDATE:
+ try {
+ sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ setSwitchStateImpl(sw, state);
+ op.commit();
+ success = true;
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid);
+ }
+ break;
case INSERT:
case CREATE:
- addSwitch(dpid);
- if (state != SwitchState.ACTIVE) {
- setStatus(dpid, state);
- }
+ try {
+ sw = addSwitchImpl(dpid);
+ if (sw != null) {
+ if (state != SwitchState.ACTIVE) {
+ setSwitchStateImpl(sw, state);
+ }
+ op.commit();
+ success = true;
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid);
+ }
break;
case DELETE:
- deleteSwitch(dpid);
+ try {
+ sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ deleteSwitchImpl(sw);
+ op.commit();
+ success = true;
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid);
+ }
break;
default:
}
+
+ return success;
+ }
+
+ @Override
+ public boolean addSwitch(IOFSwitch sw) {
+ boolean success = false;
+
+ String dpid = sw.getStringId();
+ log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+
+ try {
+ ISwitchObject curr = op.searchSwitch(dpid);
+ if (curr != null) {
+ //If existing the switch. set The SW state ACTIVE.
+ log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+ setSwitchStateImpl(curr, SwitchState.ACTIVE);
+ } else {
+ curr = addSwitchImpl(dpid);
+ }
+
+ for (OFPhysicalPort port: sw.getPorts()) {
+ IPortObject p = op.searchPort(dpid, port.getPortNumber());
+ if (p != null) {
+ log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
+ setPortStateImpl(p, port.getState(), port.getName());
+ p.setState("ACTIVE");
+ } else {
+ p = addPortImpl(curr, port.getPortNumber());
+ setPortStateImpl(p, port.getState(), port.getName());
+ }
+ }
+ op.commit();
+ success = true;
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ }
+
+ return success;
+ }
+
+ /***
+ * This function is for adding the switch into the DB.
+ * @param dpid The switch dpid you want to add into the DB.
+ */
+ @Override
+ public boolean addSwitch(String dpid) {
+ boolean success = false;
+
+ log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+ try {
+ ISwitchObject sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ //If existing the switch. set The SW state ACTIVE.
+ log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+ setSwitchStateImpl(sw, SwitchState.ACTIVE);
+ } else {
+ addSwitchImpl(dpid);
+ }
+ op.commit();
+ success = true;
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ }
+
+ return success;
+ }
+
+ /***
+ * This function is for deleting the switch into the DB.
+ * @param dpid The switch dpid you want to delete from the DB.
+ */
+ @Override
+ public boolean deleteSwitch(String dpid) {
+ boolean success = false;
+
+ try {
+ ISwitchObject sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ deleteSwitchImpl(sw);
+ op.commit();
+ }
+ success = true;
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("SwitchStorage:deleteSwitch {} failed", dpid);
+ }
+
+ return success;
+ }
+
+ public boolean updatePort(String dpid, short portNum, int state, String desc) {
+ boolean success = false;
+
+ try {
+ ISwitchObject sw = op.searchSwitch(dpid);
+
+ if (sw != null) {
+ IPortObject p = sw.getPort(portNum);
+ log.info("SwitchStorage:updatePort dpid:{} port:{}", dpid, portNum);
+ if (p != null) {
+ setPortStateImpl(p, state, desc);
+ }
+ op.commit();
+ success = true;
+ } else {
+ log.error("SwitchStorage:updatePort dpid:{} port:{} : failed switch does not exist", dpid, portNum);
+ }
+ } catch (Exception e) {
+ op.rollback();
+ e.printStackTrace();
+ log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, portNum);
+ }
+
+ return success;
}
/***
* This function is for adding the switch port into the DB.
* @param dpid The switch dpid that has the port.
- * @param port The port you want to add the switch.
+ * @param phport The port you want to add the switch.
*/
@Override
- public void addPort(String dpid, OFPhysicalPort port) {
+ public boolean addPort(String dpid, OFPhysicalPort phport) {
+ boolean success = false;
- if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
- ((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
- deletePort(dpid, port.getPortNumber());
- return;
- }
+ if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & phport.getConfig()) > 0) ||
+ ((OFPortState.OFPPS_LINK_DOWN.getValue() & phport.getState()) > 0)) {
+ // just dispatch to deletePort()
+ return deletePort(dpid, phport.getPortNumber());
+ }
try {
ISwitchObject sw = op.searchSwitch(dpid);
if (sw != null) {
- IPortObject p = op.searchPort(dpid, port.getPortNumber());
- log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, port.getPortNumber());
+ IPortObject p = sw.getPort(phport.getPortNumber());
+ log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, phport.getPortNumber());
if (p != null) {
- log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- op.commit();
-
- // TODO publish UPDATE_PORT event here
+ setPortStateImpl(p, phport.getState(), phport.getName());
+ log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, phport.getPortNumber());
} else {
- p = op.newPort(dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- sw.addPort(p);
- op.commit();
-
- // TODO publish ADD_PORT event here
+ addPortImpl(sw, phport.getPortNumber());
+ setPortStateImpl(p, phport.getState(), phport.getName());
}
+ op.commit();
+ success = true;
} else {
- log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
+ log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, phport.getPortNumber());
}
} catch (Exception e) {
- e.printStackTrace();
op.rollback();
- log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
+ e.printStackTrace();
+ log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, phport.getPortNumber());
}
-
+
+ return success;
}
/***
@@ -147,111 +283,36 @@
* @param port The port you want to delete the switch.
*/
@Override
- public void deletePort(String dpid, short port) {
+ public boolean deletePort(String dpid, short port) {
+ boolean success = false;
+
try {
ISwitchObject sw = op.searchSwitch(dpid);
if (sw != null) {
- IPortObject p = op.searchPort(dpid, port);
+ IPortObject p = sw.getPort(port);
if (p != null) {
log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port);
- p.setState("INACTIVE");
+ deletePortImpl(p);
op.commit();
- // TODO publish DELETE_PORT event here
}
}
} catch (Exception e) {
- e.printStackTrace();
op.rollback();
+ e.printStackTrace();
log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
- }
- }
-
- @Override
- public void addSwitch(IOFSwitch sw) {
- String dpid = sw.getStringId();
- log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
-
- ISwitchObject curr = op.searchSwitch(dpid);
- if (curr != null) {
- //If existing the switch. set The SW state ACTIVE.
- log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
- setSwitchStateImpl(curr, SwitchState.ACTIVE);
- } else {
- curr = addSwitchImpl(dpid);
}
- try {
- List<IPortObject> added_ports = new ArrayList<IPortObject>();
- List<IPortObject> updated_ports = new ArrayList<IPortObject>();
- for (OFPhysicalPort port: sw.getPorts()) {
- IPortObject p = op.searchPort(dpid, port.getPortNumber());
- if (p != null) {
- log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
-
- added_ports.add(p);
- } else {
- p = op.newPort(dpid, port.getPortNumber());
- p.setState("ACTIVE");
- p.setPortState(port.getState());
- p.setDesc(port.getName());
- curr.addPort(p);
-
- updated_ports.add(p);
- }
- }
-
- op.commit();
-
- // TODO publish ADD_PORT event here
- // TODO publish UPDATE_PORT event here
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
- }
+ return success;
}
- /***
- * This function is for adding the switch into the DB.
- * @param dpid The switch dpid you want to add into the DB.
- */
- @Override
- public void addSwitch(String dpid) {
- log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
-
- ISwitchObject sw = op.searchSwitch(dpid);
- if (sw != null) {
- //If existing the switch. set The SW state ACTIVE.
- log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
- setSwitchStateImpl(sw, SwitchState.ACTIVE);
- } else {
- addSwitchImpl(dpid);
- }
- }
-
private ISwitchObject addSwitchImpl(String dpid) {
- try {
+ if (dpid != null) {
ISwitchObject sw = op.newSwitch(dpid);
- if (sw != null) {
- sw.setState(SwitchState.ACTIVE.toString());
- log.info("SwitchStorage:addSwitchImpl dpid:{} added", dpid);
- } else {
- log.error("switchStorage:addSwitchImpl dpid:{} failed", dpid);
- throw new RuntimeException();
- }
-
- op.commit();
-
- // TODO publish ADD_SWITCH event here
- return sw;
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.info("SwitchStorage:addSwitchImpl dpid:{} failed", dpid);
+ sw.setState(SwitchState.ACTIVE.toString());
+ log.info("SwitchStorage:addSwitchImpl dpid:{} added", dpid);
+ return sw;
+ } else {
return null;
}
}
@@ -259,33 +320,48 @@
private void setSwitchStateImpl(ISwitchObject sw, SwitchState state) {
if (sw != null && state != null) {
sw.setState(state.toString());
- op.commit();
-
- // TODO publish UPDATE_SWITCH event here
+ log.info("SwitchStorage:setSwitchStateImpl dpid:{} updated {}",
+ sw.getDPID(), state.toString());
}
}
-
- /***
- * This function is for deleting the switch into the DB.
- * @param dpid The switch dpid you want to delete from the DB.
- */
- @Override
- public void deleteSwitch(String dpid) {
- try {
- ISwitchObject sw = op.searchSwitch(dpid);
- if (sw != null) {
- op.removeSwitch(sw);
- op.commit();
- log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
-
- // TODO publish DELETE_SWITCH event here
- }
- } catch (Exception e) {
- e.printStackTrace();
- op.rollback();
- log.error("SwitchStorage:deleteSwitch {} failed", dpid);
- }
-
- }
+ private void deleteSwitchImpl(ISwitchObject sw) {
+ if (sw != null) {
+ op.removeSwitch(sw);
+ log.info("SwitchStorage:DeleteSwitchImpl dpid:{} done",
+ sw.getDPID());
+ }
+ }
+
+ private IPortObject addPortImpl(ISwitchObject sw, short portNum) {
+ IPortObject p = op.newPort(sw.getDPID(), portNum);
+ p.setState("ACTIVE");
+ sw.addPort(p);
+ log.info("SwitchStorage:addPortImpl dpid:{} port:{} done",
+ sw.getDPID(), portNum);
+
+ return p;
+ }
+
+ private void setPortStateImpl(IPortObject port, Integer state, String desc) {
+ if (port != null) {
+ if (state != null) {
+ port.setPortState(state);
+ }
+ if (desc != null) {
+ port.setDesc(desc);
+ }
+
+ log.info("SwitchStorage:setPortStateImpl port:{} state:{} desc:{} done",
+ new Object[] {port.getPortId(), state, desc});
+ }
+ }
+
+ private void deletePortImpl(IPortObject port) {
+ if (port != null) {
+ op.removePort(port);
+ log.info("SwitchStorage:deletePortImpl port:{} done",
+ port.getPortId());
+ }
+ }
}
\ No newline at end of file
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 852cbb8..23c0e78 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -91,12 +91,17 @@
@Override
public void controlChanged(long dpid, boolean hasControl) {
- // TODO Auto-generated method stub
-
if (hasControl) {
log.debug("got control to set inactive sw {}", HexString.toHexString(dpid));
- swStore.update(HexString.toHexString(dpid),SwitchState.INACTIVE, DM_OPERATION.UPDATE);
- registryService.releaseControl(dpid);
+ try {
+ if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
+ registryService.releaseControl(dpid);
+
+ // TODO publish UPDATE_SWITCH event here
+ }
+ } catch (Exception e) {
+ log.error("Error in SwitchCleanup:controlChanged ", e);
+ }
}
}
}
@@ -119,12 +124,12 @@
// log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
}
} catch (NumberFormatException e) {
- // TODO Auto-generated catch block
+ log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
e.printStackTrace();
} catch (RegistryException e) {
log.debug("Caught RegistryException trying to requestControl in cleanup thread");
e.printStackTrace();
- }
+ }
}
op.close();
}
@@ -138,22 +143,27 @@
switch (update.getOperation()) {
case LINK_REMOVED:
log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
- linkStore.deleteLink(lt);
- // TODO: Move network map link removal here
- // reconcile paths here
-// IPortObject srcPort = conn.utils().searchPort(conn, HexString.toHexString(update.getSrc()), update.getSrcPort());
+
+ if (linkStore.deleteLink(lt)) {
+ // TODO publish DELETE_LINK event here
+ }
break;
case LINK_UPDATED:
log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
+
LinkInfo linfo = linkStore.getLinkInfo(lt);
// TODO update "linfo" using portState derived using "update"
- linkStore.update(lt, linfo, DM_OPERATION.UPDATE);
+ if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
+ // TODO publish UPDATE_LINK event here
+ }
break;
case LINK_ADDED:
log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
- linkStore.addLink(lt);
+
+ if (linkStore.addLink(lt)) {
+ // TODO publish ADD_LINK event here
+ }
break;
-
default:
break;
}
@@ -162,36 +172,41 @@
@Override
public void addedSwitch(IOFSwitch sw) {
-
if (registryService.hasControl(sw.getId())) {
- swStore.addSwitch(sw);
+ if (swStore.addSwitch(sw)) {
+ // TODO publish ADD_SWITCH event here
+ }
}
-
}
@Override
public void removedSwitch(IOFSwitch sw) {
- // TODO Auto-generated method stub
-
+ if (registryService.hasControl(sw.getId())) {
+ if (swStore.deleteSwitch(sw.getStringId())) {
+ // TODO publish DELETE_SWITCH event here
+ }
+ }
}
@Override
public void switchPortChanged(Long switchId) {
// TODO Auto-generated method stub
-
+ // NOTE: Event not needed here. This callback always coincide with add/remove callback.
}
@Override
public void switchPortAdded(Long switchId, OFPhysicalPort port) {
- // TODO Auto-generated method stub
- swStore.addPort(HexString.toHexString(switchId), port);
+ if (swStore.addPort(HexString.toHexString(switchId), port)) {
+ // TODO publish ADD_PORT event here
+ }
}
@Override
public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
- // TODO Auto-generated method stub
- swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber());
+ if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
+ // TODO publish DELETE_PORT event here
+ }
}
@Override
@@ -201,7 +216,6 @@
@Override
public void deviceAdded(IDevice device) {
- // TODO Auto-generated method stub
log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
devStore.addDevice(device);
}
@@ -214,16 +228,12 @@
@Override
public void deviceMoved(IDevice device) {
- // TODO Auto-generated method stub
devStore.changeDeviceAttachments(device);
-
}
@Override
public void deviceIPV4AddrChanged(IDevice device) {
- // TODO Auto-generated method stub
devStore.changeDeviceIPv4Address(device);
-
}
@Override
@@ -263,7 +273,6 @@
@Override
public void init(FloodlightModuleContext context)
throws FloodlightModuleException {
- // TODO Auto-generated method stub
Map<String, String> configMap = context.getConfigParams(this);
String conf = configMap.get(DBConfigFile);
op = new GraphDBOperation(conf);
@@ -291,7 +300,6 @@
@Override
public void startUp(FloodlightModuleContext context) {
- // TODO Auto-generated method stub
Map<String, String> configMap = context.getConfigParams(this);
String cleanupNeeded = configMap.get(CleanupEnabled);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
index 24c17f4..53a5b12 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
@@ -115,6 +115,7 @@
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(state);
mockISw.setState(state);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -204,21 +205,18 @@
//Mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
- mockISw.setState("ACTIVE");
mockISw.setState(stateINACTIVE.toString());
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
- expect(mockOpe.searchSwitch(dpid)).andReturn(null);
- expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
- mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
mockOpe.close();
replay(mockOpe);
swSt.init(conf);
- swSt.update(dpid, stateINACTIVE, opUPDATE);
+ swSt.updateSwitch(dpid, stateINACTIVE, opUPDATE);
}
/**
@@ -241,19 +239,17 @@
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState("ACTIVE");
mockISw.setState(stateINACTIVE.toString());
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
- expect(mockOpe.searchSwitch(dpid)).andReturn(null);
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
- expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- mockOpe.commit();
mockOpe.close();
replay(mockOpe);
swSt.init(conf);
- swSt.update(dpid, stateINACTIVE, opCREATE);
+ swSt.updateSwitch(dpid, stateINACTIVE, opCREATE);
}
/**
@@ -276,19 +272,17 @@
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState("ACTIVE");
mockISw.setState(stateINACTIVE.toString());
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
- expect(mockOpe.searchSwitch(dpid)).andReturn(null);
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
- expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- mockOpe.commit();
mockOpe.close();
replay(mockOpe);
swSt.init(conf);
- swSt.update(dpid, stateINACTIVE, opINSERT);
+ swSt.updateSwitch(dpid, stateINACTIVE, opINSERT);
}
/**
@@ -310,6 +304,7 @@
//Mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(stateACTIVE.toString());
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -324,7 +319,7 @@
swSt.init(conf);
swSt.addSwitch(dpid);
- swSt.update(dpid, stateACTIVE, opDELETE);
+ swSt.updateSwitch(dpid, stateACTIVE, opDELETE);
}
/**
@@ -344,6 +339,7 @@
//Mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(state);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -380,6 +376,7 @@
//Mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(state);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -432,6 +429,8 @@
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(state);
mockISw.addPort(mockIPort);
+ expect(mockISw.getPort(anyShort())).andReturn(null);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -439,7 +438,7 @@
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
mockOpe.close();
@@ -464,7 +463,8 @@
String dpid = "00:00:00:00:00:00:0a:01";
short portNumber = 5;
String swState = "ACTIVE";
- String portState = "INACTIVE";
+// String portState = "INACTIVE";
+ String portId = "5";
String name = "port 5 at SEA switch";
OFPhysicalPort portToAdd = new OFPhysicalPort();
@@ -475,24 +475,27 @@
//Expectation of mock Port
IPortObject mockIPort = createMock(IPortObject.class);
- mockIPort.setState(portState);
- mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
- mockIPort.setDesc(name);
+ expect(mockIPort.getPortId()).andReturn(portId);
+// mockIPort.setState(portState);
+// mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+// mockIPort.setDesc(name);
replay(mockIPort);
//Expectation of mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(swState);
// mockISw.removePort(mockIPort);
+ expect(mockISw.getPort(anyShort())).andReturn(mockIPort);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
expect(mockOpe.searchSwitch(dpid)).andReturn(null);
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
- mockOpe.commit();
+ mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
-// mockOpe.removePort(mockIPort);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+ mockOpe.removePort(mockIPort);
mockOpe.commit();
mockOpe.close();
replay(mockOpe);
@@ -528,6 +531,7 @@
//Expectation of mock Switch
ISwitchObject mockISw = createStrictMock(ISwitchObject.class);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -572,6 +576,8 @@
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(state);
mockISw.addPort(mockIPort);
+ expect(mockISw.getPort(portNumber)).andReturn(null);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -579,7 +585,7 @@
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
expect(mockOpe.newPort(dpid, portNumber)).andReturn(null);
mockOpe.rollback();
mockOpe.close();
@@ -623,6 +629,8 @@
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(state);
mockISw.addPort(mockIPort);
+ expect(mockISw.getPort(portNumber)).andReturn(null);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -630,7 +638,7 @@
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
expectLastCall().andThrow(new RuntimeException());
@@ -658,6 +666,7 @@
short portNumber = 5;
String portState = "INACTIVE";
String swState = "ACTIVE";
+ String portId = "5";
String name = "port 5 at SEA switch";
OFPhysicalPort portToAdd = new OFPhysicalPort();
@@ -669,31 +678,33 @@
//Expectation of mock Port
IPortObject mockIPort = createMock(IPortObject.class);
mockIPort.setState(swState);
- mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+// mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
mockIPort.setDesc(name);
mockIPort.setState(portState);
+ expect(mockIPort.getPortId()).andReturn(portId);
replay(mockIPort);
//Expectation of mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(swState);
- mockISw.addPort(mockIPort);
// mockISw.removePort(mockIPort);
+ expect(mockISw.getPort(portNumber)).andReturn(null);
+ mockISw.addPort(mockIPort);
+ expect(mockISw.getPort(portNumber)).andReturn(mockIPort);
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
-
-
//Expectation of mock operation.
expect(mockOpe.searchSwitch(dpid)).andReturn(null);
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
-// mockOpe.removePort(mockIPort);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+ mockOpe.removePort(mockIPort);
mockOpe.commit();
mockOpe.close();
replay(mockOpe);
@@ -719,6 +730,7 @@
short portNumber = 5;
String swState = "ACTIVE";
String portState = "INACTIVE";
+ String portId = "5";
String name = "port 5 at SEA switch";
OFPhysicalPort portToAdd = new OFPhysicalPort();
@@ -733,13 +745,18 @@
mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
mockIPort.setDesc(name);
mockIPort.setState(portState);
+ expect(mockIPort.getPortId()).andReturn(portId);
replay(mockIPort);
//Expectation of mock Switch
ISwitchObject mockISw = createMock(ISwitchObject.class);
mockISw.setState(swState);
mockISw.addPort(mockIPort);
+ expect(mockISw.getPort(portNumber)).andReturn(null);
+ expect(mockISw.getPort(portNumber)).andReturn(mockIPort).anyTimes();
// mockISw.removePort(mockIPort);
+
+ expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
replay(mockISw);
//Expectation of mock operation.
@@ -747,15 +764,15 @@
expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);
mockOpe.commit();
expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
- expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
- mockOpe.commit(); // Cannot generate exception..need to revisit this test
-// mockOpe.removePort(mockIPort);
-// expectLastCall().andThrow(new RuntimeException());
-// mockOpe.rollback();
+// expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+// mockOpe.commit(); // Cannot generate exception..need to revisit this test
+ mockOpe.removePort(mockIPort);
+ expectLastCall().andThrow(new RuntimeException());
+ mockOpe.rollback();
mockOpe.close();
replay(mockOpe);
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
index 19ac709..585a8fd 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
@@ -106,7 +106,7 @@
public void testAddSwitchExisting() {
String dpid = "00:00:00:00:00:00:0a:06";
- swSt.update(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
+ swSt.updateSwitch(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
ISwitchObject sw = ope.searchSwitch(dpid);
assertTrue(sw != null);
assertEquals(sw.getState(), SwitchState.INACTIVE.toString());
@@ -136,7 +136,7 @@
ISwitchObject sw = ope.searchSwitch(dpid);
assertTrue(sw == null);
- swSt.update(dpid, state, dmope);
+ swSt.updateSwitch(dpid, state, dmope);
ISwitchObject sw2 = ope.searchSwitch(dpid);
assertTrue(sw2 != null);
assertEquals(sw2.getState(), state.toString());
@@ -161,7 +161,7 @@
ISwitchObject sw = ope.searchSwitch(dpid);
assertTrue(sw != null);
- swSt.update(dpid, state, dmope);
+ swSt.updateSwitch(dpid, state, dmope);
ISwitchObject sw2 = ope.searchSwitch(dpid);
assertTrue(sw2 == null);
}