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

📄 datalinklayer.java

📁 total是最后的版本。包括的全是最新的物理层和数据链路层。另外还有pro1和pro2的打包程序和调用它们形成的各自的界面程序
💻 JAVA
字号:
/*DataLink_Layer definition based on the packaged Physical_Layer
 *it provides cheng some quan basic parameter setting and operations 
 *that can be used commonly in all of these 6 prptocols designed
 *from simplicity to complexity.*/
package chq;

import javax.swing.*;
import java.net.*;
import chq.PhyLayer;

public class DatalinkLayer
{
	public String event,r;
	
	public PhyLayer phy = new PhyLayer();
	
	/* Wait for an event to happen; return its type in event. */
	public String waitfor_Event(String event)
	{
		r=phy.waitForPackets();
		event=pick_Event(r);
		
		return event;
	}

	/* Fetch a packet from the network layer for transmission on the channel. */
	public String from_NetworkLayer()
	{
		String pfn=JOptionPane.showInputDialog(
			"input the message handed down from NetworkLayer");
		return pfn;	
	}
	/* Deliver information from an inbound frame to the network layer. */
	public void to_NetworkLayer(String ptn){
		JOptionPane.showMessageDialog(null,ptn,
			"The message handed up to NetworkLayer",
			JOptionPane.INFORMATION_MESSAGE);
	}

	/* Go get an inbound frame from the physical layer and copy it to r. */
	public String from_PhysicalLayer(){
		return r;
	}

	/* Pass the frame to the physical layer for transmission. */
	public void to_PhysicalLayer(String aimaddress,int aimport,String fs){
		phy.from_DatalinkLayer(aimaddress,aimport,fs);
	}
	
	/* Macro inc is expanded in-line: Increment k circularly. */
	public int inc(int k,int MAX_SEQ){
		if (k < MAX_SEQ) k = k + 1; 
		else k = 0;
		return k;
	}

	/* Start the clock running and enable the timeout event. */
	public String start_timer(String event){
		r=phy.waitForTime(); //if time out,return timeout; 
							//if not timeout,return received frame from phy
		event=pick_Event(r);
		return event;
	}

	/* Stop the clock and disable the timeout event. */
	public void stop_timer(int k){}

	/* Start an auxiliary timer and enable the ack_timeout event. */
	public void start_ack_timer(){}

	/* Stop the auxiliary timer and disable the ack_timeout event. */
	public void stop_ack_timer(){}

	/* Allow the network layer to cause a network_layer_ready event. */
	public void enable_network_layer(){}

	/* Forbid the network layer from causing a network_layer_ready event. */
	public void disable_network_layer(){}

	//datatype event:frame_arrival==1; 
	public String pick_Event(String s){
		if(s.equals("timeout"))	event="timeout";
		else event="frame_arrival";
		return event;
	}
	
	public String getLocalAddress(){
		return phy.getLocalAddress();
	}
	
	public int getLocalPort(){
		return phy.getLocalPort();		
	}
}  

⌨️ 快捷键说明

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