⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edge.java

📁 source code for fishnet
💻 JAVA
字号:
/** * <pre>    * Edge stores the specifics about each edge in the topology.  * Edges can be temporarily disabled and they record when the next packet can be sent along the edge * </pre>    */public class Edge {    private int a;    private int b;    private boolean live;    private long[] nextPktSendTime;  // When can the next packet be put onto the wire (in microseconds)    private EdgeOptions options;    /**     * Create a live edge between nodes a and b     * @param a Int specifying a node     * @param b Int specifying a node     * @param options The edge options. That is, the delay, the loss rate and the bandwidth     */    public Edge(int a, int b, EdgeOptions options) {	this.a = a;	this.b = b;	this.live = true;	this.nextPktSendTime = new long[2];	this.insertSendTime(a, 0);	this.insertSendTime(b, 0);		this.options = options;    }    /**     * Figure out when, in microseconds, a packet will arrive at the destination, given a link's      * bandwidth propogation delay characteristics.     * @param src The src node that wants to send the packet     * @param size The size of the packet in bytes     * @param now The current time in microseconds     * @return The time (in microseconds) when the next packet will arrive at the destination. Returns -1 if the packet is dropped     * @throws IllegalArgumentException Thrown if size is greater than Packet.MAX_PACKET_SIZE     */    public long schedulePkt(int src, int size, long now) throws IllegalArgumentException {	if (size > Packet.MAX_PACKET_SIZE) {	    throw new IllegalArgumentException("Packet size must be less than Packet.MAX_PACKET_SIZE. Size = " + 					       String.valueOf(size));	}		if (src != this.a && src != this.b) {	    throw new IllegalArgumentException("Src specified is not part of this edge. This edge has a: " + 					       String.valueOf(this.a) + " and b: " + String.valueOf(this.b) + 					       ". Src specified is: " + String.valueOf(src));	}	long result = Math.max(now, this.getSendTime(src));	this.insertSendTime(src, result + size * 1000 / this.options.getBW());	if(!this.live || Math.random() < this.options.getLossRate()) {	    return -1; // pkt was dropped	}	return this.getSendTime(src) + (this.options.getDelay() * 1000);    }    /**     * @param a Int specifying a node     * @param b Int specifying a node     * @return Returns true if this is an edge between a and b     */    public boolean isEdge(int a, int b) {	return ((this.a == a && this.b == b) || (this.a == b && this.b == a));    }    /**     * Returns node a      * @return The address of node a     */    public int getNodeA() {	return this.a;    }    /**     * Returns node b      * @return The address of node b     */    public int getNodeB() {	return this.b;    }    /**     * Sets the state of the edge, either live or not live     * @param state The state of the edge. True means live     */    public void setState(boolean state) {	this.live = state;    }    /**     * @return True if edge is live     */    public boolean isLive() {	return this.live;    }    /**     * @return The options of the edge. That is, the loss rate, delay and bandwidth     */    public EdgeOptions getOptions() {	return this.options;    }    /**     * Sets the options for the edge     * @param options The edge options     */    public void setOptions(EdgeOptions options) {	this.options = options;    }            private void insertSendTime(int node, long time) {	this.nextPktSendTime[getIndex(node)] = time;    }    private long getSendTime(int node) {	return this.nextPktSendTime[getIndex(node)];    }    private int getIndex(int node) {	if (node == this.a) {	    return 0;	}	return 1;		       }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -