📄 riprouter.java
字号:
/*
JaNetSim --- Java Network Simulator
-------------------------------------
This software was developed at the Network Research Lab, Faculty of
Computer Science and Information Technology (FCSIT), University of Malaya.
This software may be used and distributed freely. FCSIT assumes no responsibility
whatsoever for its use by other parties, and makes no guarantees, expressed or
implied, about its quality, reliability, or any other characteristic.
We would appreciate acknowledgement if the software is used.
FCSIT ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING
FROM THE USE OF THIS SOFTWARE.
*/
package janetsim.component;
import janetsim.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
public class RIPRouter extends IPRouter implements Serializable {
protected SimParamIP sw_echo_target;
protected SimParamDouble sw_echo_time;
protected Echo sw_echo=null;
//Routing protocols set
protected SimParamBool sw_rip_use=null;
//End routing protocols set
//Routing protocols components
protected RIP sw_rip=null;
//End routing protocols components
//private events (WARNING: MUST NOT use values defined in the superclass)
protected static final int MY_TEST_ECHO = SimProvider.EV_PRIVATE + 4;
public RIPRouter(String aName,String aClass,Sim aSim,int locx,int locy) {
super(aName,aClass,aSim,locx,locy);
sw_create2();
}
protected void neighborAdded(SimComponent comp) {
if(comp.getCompClass().equals("Link")) {
if(sw_rip_use==null) {
//create RIP parameters
sw_rip_use=new SimParamBool("Use RIP",this,theSim.now(),false,true,false);
addParameter(sw_rip_use);
}
}
super.neighborAdded(comp);
}
protected void neighborRemoved(SimComponent comp) {
super.neighborRemoved(comp);
if(comp.getCompClass().equals("Link")) {
if(voports.isEmpty()) {
//remove RIP parameter
removeParameter(sw_rip_use);
sw_rip_use=null;
}
}
}
public void reset() {
super.reset();
sw_echo.reset();
//notify RIP protocol
sw_rip.reset();
}
public void start() {
super.start();
sw_echo.start();
//notify RIP protocol
if(sw_rip_use!=null && sw_rip_use.getValue() == true)
sw_rip.start();
//check whether an echo test is requested
if(sw_echo_time.getValue()>0) {
theSim.enqueue(new SimEvent(MY_TEST_ECHO,this,this,theSim.now()+SimClock.Sec2Tick(sw_echo_time.getValue()),null));
}
}
public void action(SimEvent e) {
super.action(e);
switch(e.getType()) {
case MY_TEST_ECHO:
sw_test_echo();
break;
}
}
////////////////////////// protected methods ////////////////////////////////
protected void sw_create2() {
sw_echo=new Echo(this);
//create new RIP component
sw_rip=new RIP(this);
//Initialize the parameters
sw_echo_target=new SimParamIP("Echo test target",this,theSim.now(),false,true,0);
sw_echo_time=new SimParamDouble("Echo test time (s) (0=off)",this,theSim.now(),false,true,0);
addParameter(sw_echo_target);
addParameter(sw_echo_time);
}
protected void sw_test_echo() {
sw_echo.test(sw_echo_target.getValue());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -