Fix merge error
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
index 6130218..f469911 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/DeviceStorageImpl.java
@@ -7,7 +7,6 @@
import net.floodlightcontroller.devicemanager.IDevice;
import net.floodlightcontroller.devicemanager.SwitchPort;
-import net.floodlightcontroller.packet.IPv4;
import net.onrc.onos.graph.DBOperation;
import net.onrc.onos.graph.GraphDBManager;
import net.onrc.onos.ofcontroller.core.IDeviceStorage;
@@ -30,15 +29,13 @@
* @author Pankaj
*/
public class DeviceStorageImpl implements IDeviceStorage {
+ protected final static Logger log = LoggerFactory.getLogger(DeviceStorageImpl.class);
private DBOperation ope;
- protected final static Logger log = LoggerFactory.getLogger(SwitchStorageImpl.class);
- /**
- * *
- * Initialize function. Before you use this class, please call this method
- *
- * @param conf configuration file for Cassandra DB
- */
+ /***
+ * Initialize function. Before you use this class, please call this method
+ * @param conf configuration file for Cassandra DB
+ */
@Override
public void init(final String dbStore, final String conf) {
try {
@@ -49,34 +46,29 @@
}
}
- /**
- * *
- * Finalize/close function. After you use this class, please call this
- * method. It will close the DB connection.
- */
+ /***
+ * Finalize/close function. After you use this class, please call this method.
+ * It will close the DB connection.
+ */
@Override
public void close() {
ope.close();
}
- /**
- * *
- * Finalize/close function. After you use this class, please call this
- * method. It will close the DB connection. This is for Java garbage
- * collection.
- */
+ /***
+ * Finalize/close function. After you use this class, please call this method.
+ * It will close the DB connection. This is for Java garbage collection.
+ */
@Override
public void finalize() {
close();
}
- /**
- * *
- * This function is for adding the device into the DB.
- *
- * @param device The device you want to add into the DB.
- * @return IDeviceObject which was added in the DB.
- */
+ /***
+ * This function is for adding the device into the DB.
+ * @param device The device you want to add into the DB.
+ * @return IDeviceObject which was added in the DB.
+ */
@Override
public IDeviceObject addDevice(IDevice device) {
IDeviceObject obj = null;
@@ -91,20 +83,20 @@
obj = ope.newDevice();
log.debug("Adding device {}: creating new device", device.getMACAddressString());
}
-
+
if (obj == null) {
return null;
}
-
+
changeDeviceAttachments(device, obj);
-
+
changeDeviceIpv4Addresses(device, obj);
-
+
obj.setMACAddress(device.getMACAddressString());
obj.setType("device");
obj.setState("ACTIVE");
ope.commit();
-
+
break;
//log.debug("Adding device {}",device.getMACAddressString());
} catch (TitanException e) {
@@ -113,16 +105,14 @@
obj = null;
}
}
-
- return obj;
+
+ return obj;
}
- /**
- * *
- * This function is for updating the Device properties.
- *
- * @param device The device you want to add into the DB.
- * @return IDeviceObject which was added in the DB.
- */
+ /***
+ * This function is for updating the Device properties.
+ * @param device The device you want to add into the DB.
+ * @return IDeviceObject which was added in the DB.
+ */
@Override
public IDeviceObject updateDevice(IDevice device) {
return addDevice(device);
@@ -135,12 +125,13 @@
@Override
public void removeDevice(IDevice device) {
IDeviceObject dev;
-
+
if ((dev = ope.searchDevice(device.getMACAddressString())) != null) {
removeDevice(dev);
}
}
-
+
+ @Override
public void removeDevice(IDeviceObject deviceObject) {
String deviceMac = deviceObject.getMACAddress();
@@ -154,26 +145,23 @@
log.error("DeviceStorage:removeDevice mac:{} failed", deviceMac);
}
}
-
+
public void removeDeviceImpl(IDeviceObject deviceObject) {
for (IIpv4Address ipv4AddressVertex : deviceObject.getIpv4Addresses()) {
ope.removeIpv4Address(ipv4AddressVertex);
}
-
+
ope.removeDevice(deviceObject);
}
- /**
- * *
- * This function is for getting the Device from the DB by Mac address of the
- * device.
- *
- * @param mac The device mac address you want to get from the DB.
- * @return IDeviceObject you want to get.
- */
- @Override
- public IDeviceObject getDeviceByMac(String mac) {
- return ope.searchDevice(mac);
- }
+ /***
+ * This function is for getting the Device from the DB by Mac address of the device.
+ * @param mac The device mac address you want to get from the DB.
+ * @return IDeviceObject you want to get.
+ */
+ @Override
+ public IDeviceObject getDeviceByMac(String mac) {
+ return ope.searchDevice(mac);
+ }
/***
* This function is for getting the Device from the DB by IP address of the device.
@@ -195,12 +183,10 @@
}
}
- /**
- * *
- * This function is for changing the Device attachment point.
- *
- * @param device The device you want change the attachment point
- */
+ /***
+ * This function is for changing the Device attachment point.
+ * @param device The device you want change the attachment point
+ */
@Override
public void changeDeviceAttachments(IDevice device) {
IDeviceObject obj = null;
@@ -218,7 +204,7 @@
log.error(":addDevice mac:{} failed", device.getMACAddressString());
}
}
-
+
/***
* This function is for changing the Device attachment point.
* @param device The new device you want change the attachment point
@@ -232,7 +218,7 @@
//Check if there is the port
IPortObject port = ope.searchPort(HexString.toHexString(ap.getSwitchDPID()),
(short) ap.getPort());
- log.debug("New Switch Port is {},{}",
+ log.debug("New Switch Port is {},{}",
HexString.toHexString(ap.getSwitchDPID()), (short) ap.getPort());
if (port != null){
@@ -242,18 +228,18 @@
attachedPorts.remove(port);
} else {
log.debug("Adding device {}: attaching to port", device.getMACAddressString());
- port.setDevice(obj);
+ port.setDevice(obj);
}
log.debug("port number is {}", port.getNumber());
log.debug("port desc is {}", port.getDesc());
}
- }
+ }
for (IPortObject port: attachedPorts) {
log.debug("Detaching the device {}: detaching from port", device.getMACAddressString());
port.removeDevice(obj);
-
+
if (!obj.getAttachedPorts().iterator().hasNext()) {
// XXX If there are no more ports attached to the device,
// delete it. Otherwise we have a situation where the
@@ -285,7 +271,7 @@
log.error(":changeDeviceIPv4Address mac:{} failed due to exception {}", device.getMACAddressString(), e);
}
}
-
+
private void changeDeviceIpv4Addresses(IDevice device, IDeviceObject deviceObject) {
List<String> dbIpv4Addresses = new ArrayList<String>();
List<Integer> intDbIpv4Addresses = new ArrayList<Integer>();
@@ -293,33 +279,33 @@
dbIpv4Addresses.add(InetAddresses.fromInteger(ipv4Vertex.getIpv4Address()).getHostAddress());
intDbIpv4Addresses.add(ipv4Vertex.getIpv4Address());
}
-
+
List<String> memIpv4Addresses = new ArrayList<String>();
for (int addr : device.getIPv4Addresses()) {
memIpv4Addresses.add(InetAddresses.fromInteger(addr).getHostAddress());
}
-
+
log.debug("Device IP addresses {}, database IP addresses {}",
memIpv4Addresses, dbIpv4Addresses);
-
+
for (int ipv4Address : device.getIPv4Addresses()) {
//if (deviceObject.getIpv4Address(ipv4Address) == null) {
if (!intDbIpv4Addresses.contains(ipv4Address)) {
IIpv4Address dbIpv4Address = ope.ensureIpv4Address(ipv4Address);
-
+
/*
IDeviceObject oldDevice = dbIpv4Address.getDevice();
if (oldDevice != null) {
oldDevice.removeIpv4Address(dbIpv4Address);
}
*/
-
- log.debug("Adding IP address {}",
+
+ log.debug("Adding IP address {}",
InetAddresses.fromInteger(ipv4Address).getHostAddress());
deviceObject.addIpv4Address(dbIpv4Address);
}
}
-
+
List<Integer> deviceIpv4Addresses = Arrays.asList(device.getIPv4Addresses());
for (IIpv4Address dbIpv4Address : deviceObject.getIpv4Addresses()) {
if (!deviceIpv4Addresses.contains(dbIpv4Address.getIpv4Address())) {
@@ -330,17 +316,17 @@
}
}
}
-
+
/**
* Takes an {@link OnosDevice} and adds it into the database. There is no
- * checking of the database data and removing old data - an
+ * checking of the database data and removing old data - an
* {@link OnosDevice} basically corresponds to a packet we've just seen,
* and we need to add that information into the database.
*/
@Override
public void addOnosDevice(OnosDevice onosDevice) {
String macAddress = HexString.toHexString(onosDevice.getMacAddress().toBytes());
-
+
//if the switch port we try to attach a new device already has a link, then stop adding device
IPortObject portObject1 = ope.searchPort(HexString.toHexString(
onosDevice.getSwitchDPID()), onosDevice.getSwitchPort());
@@ -352,19 +338,19 @@
}
return;
}
-
+
log.debug("addOnosDevice: {}", onosDevice);
try {
IDeviceObject device = ope.searchDevice(macAddress);
-
+
if (device == null) {
device = ope.newDevice();
device.setType("device");
device.setState("ACTIVE");
device.setMACAddress(macAddress);
}
-
+
// Check if the device has the IP address, add it if it doesn't
if (onosDevice.getIpv4Address() != null) {
boolean hasIpAddress = false;
@@ -374,7 +360,7 @@
break;
}
}
-
+
if (!hasIpAddress) {
IIpv4Address ipv4Address = ope.ensureIpv4Address(onosDevice.getIpv4Address().intValue());
IDeviceObject oldDevice = ipv4Address.getDevice();
@@ -384,7 +370,7 @@
device.addIpv4Address(ipv4Address);
}
}
-
+
// Check if the device has the attachment point, add it if not
// TODO single attachment point for now, extend to multiple later
String switchDpid = HexString.toHexString(onosDevice.getSwitchDPID());
@@ -403,7 +389,7 @@
}
}
}
-
+
/*
for (IPortObject portObject : device.getAttachedPorts()) {
ISwitchObject switchObject = portObject.getSwitch();
@@ -414,14 +400,14 @@
}
}
*/
-
+
if (!hasAttachmentPoint) {
IPortObject portObject = ope.searchPort(switchDpid, onosDevice.getSwitchPort());
if (portObject != null) {
portObject.setDevice(device);
}
}
-
+
ope.commit();
}
catch (TitanException e) {