Routing simulation - implementation of design options (1)

zhaozj2021-02-16  47

Routing Simulation System Design Scheme (2)

Implementation

2004-4-10

Explanation: This implementation only introduces the realization of major interfaces.

First, the generation of network packets

The network packet can be generated by the router, here is generated by the NET class, and transmitted to the corresponding router as the starting point. Due to the original intention of this system, the interface of all processes is console. If the implementation is implemented as the form interface, you can overload or override this part of the code.

1, generate network transmission packets

Method Name: Net :: Makedata

Method parameters: no

Return Value: int type, starting the point router number for the packet.

The purpose of the method: the correct start router number and the target router number are entered by the console to generate the correct packet. Among them, the router number and router address are one-one.

Possible error: The network is not built: an error is wrong and the system exits.

Console router number input is incorrect: an error and re-enter.

// Generate a data package for network transmission

INT NET :: Makedata (Void)

{

IF (routnum == 0 || pnodeArray == null)

{

The std :: cout << "/ n network is an empty network, currently unable to generate packets ... / n / n";

EXIT (-1);

} //

INT i = 0, j = 0;

Std :: cout << "/ n network router label and address: / n"

<< "" Number: / T address "<< std :: end1;

For (int K = 0; k

{// Print router number and address correspondence table

Std :: cout << k << ": / t";

For (int m = 0; M

Std :: cout << * ((PNodeArray K) -> PROUT-> getselfaddress () m);

Std :: cout << std :: endl;

}

LOOP:

Std :: cout << "/ n Please enter the label of the source router of the packet:";

Std :: cin >> i;

Std :: cout << "/ n Please enter the label of the target router for the packet:";

Std :: cin >> J;

IF ((i <0) || (i> routnum-1) || (j <0) || (j> routnum-1)))

{

Std :: cout << "The reference source router of the source router or the label of the target router has an error, please check ... / n / n";

Goto loop;

}

/ / Generate a network-transmitted data package: ipdata packet

NetData ipdata (false);

ipdata.setaddressFrom ((PNodeArray i) -> PROUT-> getselfaddress ());

ipdata.setaddressto ((PNodeArray J) -> PROUT-> GetSelfaddress ());

Ipdata.setnexthop ((PnodeArray i) -> PROUT-> getselfaddress ());

ipdata.setprehop ((pnodeaRray i) -> prout-> getselfaddress ()); // Give the starting router

(PnodeArray i) -> PROUT-> Makedata (IPDATA);

Return I;

}

2, router generate data

Method Name: Absrout :: Makedata

Method parameters: NetData & NetData

Return value: no

The purpose of the method: copy the parameter NetData to the current packet of the router, and call the route calculation.

Possible error: no

// Generate data

Void Absrout :: Makedata (NetData & NetData)

{

Curripdata.SetaddressFrom (NetData.GetaddressFrom ());

Curripdata.SetAddressto (NetData.GetaddResSto ());

Curripdata.setipdata (NetData.Getipdata ());

Curripdata.setnexThop (NetData.getNexthop ());

Curripdata.setprehop (NetData.GetPrehop ());

Curripdata.id = NetData.id;

/ / ---------------------------------------------

Std :: cout << "/ n generated packet: / n";

For (int i = 0; i

Std :: cout << * (NetData.GetaddressFrom () i);

Std :: cout << "->;

For (int i = 0; i

Std :: cout << * (NetData.GetaddResSto () i);

Std :: cout << "/ n / nat rout: / t";

For (int i = 0; i

Std :: cout << SelfadDress [i];

Std :: cout << std :: endl;

// -----------------------------------------------

IF (curripdata.getaddressto (), selfddress)) Return;

DataroutCompute ();

}

转载请注明原文地址:https://www.9cbs.com/read-25385.html

New Post(0)