|
@@ -104,7 +104,7 @@ public class NetworkController {
|
|
//Skip ports that are not connected
|
|
//Skip ports that are not connected
|
|
if(p.getConnection()==null)
|
|
if(p.getConnection()==null)
|
|
continue;
|
|
continue;
|
|
- removeDeviceFromConnection(p, p.getConnection());
|
|
|
|
|
|
+ removeDeviceFromConnectionAndProtocol(p, p.getConnection());
|
|
}
|
|
}
|
|
|
|
|
|
// Remove from Links
|
|
// Remove from Links
|
|
@@ -160,7 +160,7 @@ public class NetworkController {
|
|
* @param link link to add
|
|
* @param link link to add
|
|
*/
|
|
*/
|
|
public void addLink(Link link){
|
|
public void addLink(Link link){
|
|
- if(link!=null)
|
|
|
|
|
|
+ if(link!=null && !model.getConnectionNetworks().contains(link))
|
|
model.addConnectionNetwork(link);
|
|
model.addConnectionNetwork(link);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -185,7 +185,7 @@ public class NetworkController {
|
|
* @param connection connection to be added
|
|
* @param connection connection to be added
|
|
*/
|
|
*/
|
|
public void addConnection(Connection connection){
|
|
public void addConnection(Connection connection){
|
|
- if(connection!=null)
|
|
|
|
|
|
+ if(connection!=null && !getConnections().contains(connection))
|
|
model.addConnection(connection);
|
|
model.addConnection(connection);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -251,7 +251,7 @@ public class NetworkController {
|
|
public boolean changeRoleOfDevice(Protocol protocol, Connection con, Port device, int newRole){
|
|
public boolean changeRoleOfDevice(Protocol protocol, Connection con, Port device, int newRole){
|
|
if(newRole < 0 || newRole >= protocol.getNumberOfRoles()){
|
|
if(newRole < 0 || newRole >= protocol.getNumberOfRoles()){
|
|
protocol.removeDevice(device);
|
|
protocol.removeDevice(device);
|
|
- removeDeviceFromConnection(device, con);
|
|
|
|
|
|
+ removeDeviceFromConnectionAndProtocol(device, con);
|
|
return false;
|
|
return false;
|
|
} else if(protocol.getDevicesWithRole(newRole).contains(device)){
|
|
} else if(protocol.getDevicesWithRole(newRole).contains(device)){
|
|
if(!con.getParticipants().contains(device))
|
|
if(!con.getParticipants().contains(device))
|
|
@@ -280,11 +280,11 @@ public class NetworkController {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Removes Device p from the Connection
|
|
|
|
|
|
+ * Removes Device p from the Connection & Protocol
|
|
* @param p Port/Device to remove
|
|
* @param p Port/Device to remove
|
|
* @param connection connection, which should remove the device
|
|
* @param connection connection, which should remove the device
|
|
*/
|
|
*/
|
|
- public void removeDeviceFromConnection(Port p, Connection connection){
|
|
|
|
|
|
+ public void removeDeviceFromConnectionAndProtocol(Port p, Connection connection){
|
|
if(connection != null){
|
|
if(connection != null){
|
|
connection.removeSmartDevice(p);
|
|
connection.removeSmartDevice(p);
|
|
connection.getProtocol().removeDevice(p);
|
|
connection.getProtocol().removeDevice(p);
|
|
@@ -297,6 +297,22 @@ public class NetworkController {
|
|
if(p!=null)
|
|
if(p!=null)
|
|
p.setConnection(null);
|
|
p.setConnection(null);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Removes Device p from the Connection & Protocol
|
|
|
|
+ * @param p Port/Device to remove
|
|
|
|
+ * @param connection connection, which should remove the device
|
|
|
|
+ */
|
|
|
|
+ public void removeDeviceFromConnection(Port p, Connection connection){
|
|
|
|
+ if(connection != null){
|
|
|
|
+ connection.removeSmartDevice(p);
|
|
|
|
+ p.setConnection(null);
|
|
|
|
+ if(connection.getParticipants().isEmpty())
|
|
|
|
+ deleteConnection(connection);
|
|
|
|
+ }
|
|
|
|
+ if(p != connection)
|
|
|
|
+ p.setConnection(null);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Adds Device p to the connection with the specified role
|
|
* Adds Device p to the connection with the specified role
|
|
@@ -305,7 +321,7 @@ public class NetworkController {
|
|
* @param role new role of the device (See {@link Protocol} Roles)
|
|
* @param role new role of the device (See {@link Protocol} Roles)
|
|
* @return true, if the device was added
|
|
* @return true, if the device was added
|
|
*/
|
|
*/
|
|
- public boolean addDeviceToConnection(Port p, Connection connection, int role){
|
|
|
|
|
|
+ public boolean addDeviceToConnectionAndProtocol(Port p, Connection connection, int role){
|
|
if(connection.getProtocol().getDevicesWithRole(role).contains(p) || connection.getProtocol().addDeviceOfRole(p, role)){
|
|
if(connection.getProtocol().getDevicesWithRole(role).contains(p) || connection.getProtocol().addDeviceOfRole(p, role)){
|
|
//If port already has the role, or it could be assigned - just check the fields
|
|
//If port already has the role, or it could be assigned - just check the fields
|
|
if(!connection.getParticipants().contains(p))
|
|
if(!connection.getParticipants().contains(p))
|
|
@@ -324,6 +340,19 @@ public class NetworkController {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Adds Device p to the connection
|
|
|
|
+ * @param p Port/Device to be added
|
|
|
|
+ * @param connection Connection
|
|
|
|
+ */
|
|
|
|
+ public void addDeviceToConnection(Port p, Connection connection){
|
|
|
|
+ if(p==null || connection == null)
|
|
|
|
+ return;
|
|
|
|
+ if(!connection.getParticipants().contains(p))
|
|
|
|
+ connection.addSmartDevice(p);
|
|
|
|
+ p.setConnection(connection);
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* Changes the link of the given connection to the new link. Returns true if it was successfully changed, false if it could not be changed.
|
|
* Changes the link of the given connection to the new link. Returns true if it was successfully changed, false if it could not be changed.
|
|
@@ -356,7 +385,8 @@ public class NetworkController {
|
|
* Add Connection to new Link
|
|
* Add Connection to new Link
|
|
*/
|
|
*/
|
|
connection.setLink(link);
|
|
connection.setLink(link);
|
|
- link.addConnection(connection);
|
|
|
|
|
|
+ if(!link.getConnections().contains(connection))
|
|
|
|
+ link.addConnection(connection);
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
@@ -379,15 +409,14 @@ public class NetworkController {
|
|
try{
|
|
try{
|
|
newCon = newConnectionClass.newInstance();
|
|
newCon = newConnectionClass.newInstance();
|
|
newCon.setProtocol(connection.getProtocol());
|
|
newCon.setProtocol(connection.getProtocol());
|
|
- newCon.setLink(connection.getLink());
|
|
|
|
- connection.getLink().addConnection(newCon);
|
|
|
|
|
|
+ addConnectionToLink(newCon, connection.getLink());
|
|
newCon.setStatus(connection.getStatus());
|
|
newCon.setStatus(connection.getStatus());
|
|
newCon.setPacketLossProbability(connection.getPacketLossProbability());
|
|
newCon.setPacketLossProbability(connection.getPacketLossProbability());
|
|
newCon.setName(connection.getName());
|
|
newCon.setName(connection.getName());
|
|
for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
|
|
for (Iterator<Port> p = connection.getParticipants().iterator(); p.hasNext();) {
|
|
Port type = (Port) p.next();
|
|
Port type = (Port) p.next();
|
|
- newCon.addSmartDevice(type);
|
|
|
|
- type.setConnection(newCon);
|
|
|
|
|
|
+ removeDeviceFromConnection(type, connection);
|
|
|
|
+ addDeviceToConnection(type, connection);
|
|
|
|
|
|
}
|
|
}
|
|
}catch(Exception e){
|
|
}catch(Exception e){
|
|
@@ -471,7 +500,7 @@ public class NetworkController {
|
|
if(c == null)return;
|
|
if(c == null)return;
|
|
LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
|
|
LinkedList<Port> ports = new LinkedList<Port>(c.getParticipants());
|
|
for(Port p:ports)
|
|
for(Port p:ports)
|
|
- removeDeviceFromConnection(p, c);
|
|
|
|
|
|
+ removeDeviceFromConnectionAndProtocol(p, c);
|
|
ports.clear();
|
|
ports.clear();
|
|
removeConnectionFromLink(c, c.getLink());
|
|
removeConnectionFromLink(c, c.getLink());
|
|
c.setStatus(Connection.TERMINATED);
|
|
c.setStatus(Connection.TERMINATED);
|
|
@@ -519,6 +548,8 @@ public class NetworkController {
|
|
public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
|
|
public Link changeLinkType(Link oldLink, Class<? extends Link> newType) {
|
|
if(newType == null)
|
|
if(newType == null)
|
|
return null;
|
|
return null;
|
|
|
|
+ System.out.println("Change Link:");
|
|
|
|
+ printLinkHelp(oldLink);
|
|
/**
|
|
/**
|
|
* New Link which was created
|
|
* New Link which was created
|
|
*/
|
|
*/
|
|
@@ -533,10 +564,10 @@ public class NetworkController {
|
|
}else {
|
|
}else {
|
|
// Set old Name
|
|
// Set old Name
|
|
newLink.setName(oldLink.getName());
|
|
newLink.setName(oldLink.getName());
|
|
- // Add to Mode
|
|
|
|
- if(getLinks().contains(oldLink)){
|
|
|
|
- removeLink(oldLink);
|
|
|
|
- addLink(newLink);
|
|
|
|
|
|
+
|
|
|
|
+ //Connection to the new Link
|
|
|
|
+ for(Connection c: new LinkedList<Connection>(oldLink.getConnections())){
|
|
|
|
+ addConnectionToLink(c, newLink);
|
|
}
|
|
}
|
|
// Add devices to the new Link
|
|
// Add devices to the new Link
|
|
LinkedList<SmartDevice> devices= new LinkedList<>(oldLink.getDevices());
|
|
LinkedList<SmartDevice> devices= new LinkedList<>(oldLink.getDevices());
|
|
@@ -544,12 +575,29 @@ public class NetworkController {
|
|
removeLinkFromDevice(oldLink, device);
|
|
removeLinkFromDevice(oldLink, device);
|
|
addLinkToDevice(newLink, device);
|
|
addLinkToDevice(newLink, device);
|
|
}
|
|
}
|
|
- //Connection to the new Link
|
|
|
|
- for(Connection c: new LinkedList<Connection>(oldLink.getConnections())){
|
|
|
|
- removeConnectionFromLink(c, oldLink);
|
|
|
|
- addConnectionToLink(c, newLink);
|
|
|
|
|
|
+
|
|
|
|
+ System.out.println("oldLink:");
|
|
|
|
+ printLinkHelp(oldLink);
|
|
|
|
+ System.out.println("new Link:");
|
|
|
|
+ printLinkHelp(newLink);
|
|
|
|
+
|
|
|
|
+ // Add to Mode
|
|
|
|
+ if(getLinks().contains(oldLink)){
|
|
|
|
+ removeLink(oldLink);
|
|
|
|
+ addLink(newLink);
|
|
}
|
|
}
|
|
- return newLink;
|
|
|
|
|
|
+ return newLink;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void printLinkHelp(Link l){
|
|
|
|
+ System.out.println("Link: "+l.getName());
|
|
|
|
+ for(SmartDevice d:l.getDevices()){
|
|
|
|
+ System.out.println(d.getName());
|
|
|
|
+ }
|
|
|
|
+ System.out.println("Connections:");
|
|
|
|
+ for(Connection c:l.getConnections()){
|
|
|
|
+ System.out.println(c.getName());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|