/* * Copyright 2010 Aalto University, ComNet * Released under GPLv3. See LICENSE.txt for details. */ package interfaces; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import core.CBRConnection; import core.Connection; import core.DTNHost; import core.NetworkInterface; import core.Settings; import core.SimClock; import core.SimScenario; import core.World; /** * A simple Network Interface that provides a constant bit-rate service, where * one transmission can be on at a time. * * These connections are taken from a file */ public class ConnectionsFromFileInterface extends NetworkInterface { /** * Reads the interface settings from the Settings file * */ public ConnectionsFromFileInterface(Settings s) { super(s); } /** * Copy constructor * @param ni the copied network interface object */ public ConnectionsFromFileInterface(ConnectionsFromFileInterface ni) { super(ni); } public NetworkInterface replicate() { return new ConnectionsFromFileInterface(this); } /** * Tries to connect this host to another host. * @param anotherInterface The interface to connect to */ public void connect(NetworkInterface anotherInterface) { } //public List upConnections = new ArrayList(); //public List downConnections = new ArrayList(); public Map> upConnections = new HashMap>(); public Map> downConnections = new HashMap>(); // Returns connections which need to be created for a given time public List getUpPairs(Double time) { List arr = upConnections.get(time); return arr; } /** * Updates the state of current connections (ie tears down connections * that are out of range). */ public void update() { // First create new connections List newConnections = getUpPairs(SimClock.getTime()); if(newConnections != null) { //System.out.println("adding " + newConnections.size() + " Connections for " + this.getHost().getAddress() + " at " + String.format("%.2f",SimClock.getTime())); for(String p : newConnections) { //Collection interfaces = optimizer.getAllInterfaces(); World w = SimScenario.getInstance().getWorld(); DTNHost test = w.getNodeByAddress(Integer.parseInt(p)); Collection interfaces = test.getInterfaces(); for (NetworkInterface i : interfaces) { //System.out.println("Got interfaces for " + test); //System.out.println("adding " + newConnections.size() + " Connections for " + this.getHost().getAddress() + " at " + String.format("%.2f",SimClock.getTime())); createConnection(i); } } } // now break old connections List arr = downConnections.get(SimClock.getTime()); if(arr != null) { // then we have at least one broken connection for this time for (String s : arr) { for (int i=0; i this.transmitSpeed) { conSpeed = this.transmitSpeed; } Connection con = new CBRConnection(this.host, this, anotherInterface.getHost(), anotherInterface, conSpeed); connect(con,anotherInterface); } } /** * Returns a string representation of the object. * @return a string representation of the object. */ public String toString() { return "SimpleBroadcastInterface " + super.toString(); } }