Index ports for faster search
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
index fc1c32f..d08da7c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/INetMapTopologyObjects.java
@@ -73,6 +73,14 @@
@Property("number")
public Short getNumber();
+ @JsonIgnore
+ @Property("port_id")
+ public void setPortId(String id);
+
+ @JsonIgnore
+ @Property("port_id")
+ public String getPortId();
+
@Property("number")
public void setNumber(Short n);
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 79a4f76..a4dd528 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -3,6 +3,8 @@
import java.util.Collection;
+import net.floodlightcontroller.core.IOFSwitch;
+
import org.openflow.protocol.OFPhysicalPort;
public interface ISwitchStorage extends INetMapStorage {
@@ -21,7 +23,11 @@
*/
public void addPort(String dpid, OFPhysicalPort port);
/*
- * Get all ports associated on a switch
+ * Add a switch and all its associated ports
+ */
+ public void addSwitch(IOFSwitch sw);
+ /*
+ * Add a switch
*/
public void addSwitch(String dpid);
/*
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 f2b87ce..4bcf9a2 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,5 +1,6 @@
package net.onrc.onos.ofcontroller.core.internal;
+import net.floodlightcontroller.core.IOFSwitch;
import net.onrc.onos.graph.GraphDBConnection;
import net.onrc.onos.graph.GraphDBOperation;
import net.onrc.onos.ofcontroller.core.ISwitchStorage;
@@ -71,23 +72,8 @@
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);
- sw.setState(SwitchState.ACTIVE.toString());
- op.commit();
- } else {
- sw = op.newSwitch(dpid);
-
- if (sw != null) {
- sw.setState(SwitchState.ACTIVE.toString());
- op.commit();
- log.info("SwitchStorage:addSwitch dpid:{} added", dpid);
- } else {
- log.error("switchStorage:addSwitch dpid:{} failed -> newSwitch failed", dpid);
- }
- }
+ newSwitch(dpid);
+ op.commit();
} catch (Exception e) {
e.printStackTrace();
op.rollback();
@@ -95,6 +81,24 @@
}
}
+ private ISwitchObject newSwitch(String dpid) {
+ ISwitchObject sw = op.searchSwitch(dpid);
+ if (sw != null) {
+ //If existing the switch. set The SW state ACTIVE.
+ log.info("SwitchStorage:newSwitch dpid:{} already exists", dpid);
+ sw.setState(SwitchState.ACTIVE.toString());
+ } else {
+ sw = op.newSwitch(dpid);
+ if (sw != null) {
+ sw.setState(SwitchState.ACTIVE.toString());
+ log.info("SwitchStorage:newSwitch dpid:{} added", dpid);
+ } else {
+ log.error("switchStorage:newSwitch dpid:{} failed -> newSwitch failed", dpid);
+ }
+ }
+ return sw;
+ }
+
/***
* This function is for updating the switch into the DB.
* @param dpid The switch dpid you want to update from the DB
@@ -164,7 +168,7 @@
if (p != null) {
log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
} else {
- p = op.newPort(port.getPortNumber());
+ p = op.newPort(dpid, port.getPortNumber());
p.setState("ACTIVE");
p.setPortState(port.getState());
p.setDesc(port.getName());
@@ -207,4 +211,32 @@
log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
}
}
+
+ @Override
+ public void addSwitch(IOFSwitch sw) {
+ // TODO Auto-generated method stub
+ String dpid = sw.getStringId();
+ log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+ try {
+ ISwitchObject switchObject = newSwitch(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());
+ } else {
+ p = op.newPort(dpid, port.getPortNumber());
+ p.setState("ACTIVE");
+ p.setPortState(port.getState());
+ p.setDesc(port.getName());
+ switchObject.addPort(p);
+ }
+ }
+ op.commit();
+ } catch (Exception e) {
+ e.printStackTrace();
+ op.rollback();
+ log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+ }
+
+ }
}
\ 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 5b8e25b..8c83a7c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -153,10 +153,7 @@
public void addedSwitch(IOFSwitch sw) {
if (registryService.hasControl(sw.getId())) {
- swStore.update(sw.getStringId(), SwitchState.ACTIVE, DM_OPERATION.UPDATE);
- for (OFPhysicalPort port: sw.getPorts()) {
- swStore.addPort(sw.getStringId(), port);
- }
+ swStore.addSwitch(sw);
}
}