Routing simulation - implementation of design options (3)

zhaozj2021-02-16  51

3, create a network

Method Name: Net :: RECREATE

Method parameters: no

Return value: no

The purpose of the method: Recreate the network (including first creation). If the network information changes, the memory resource is released, and the network information is re-obtained, and the network data structure PnodeArray is built. At the same time, this method is in the network information, and fill in an important intermediate table: the router label and the address map. The implementation of this scenario is still a simple manner, and complex networks, PNODEARRAY needs to be built as completed adjacent tables. Implementation code is omitted.

Possible error: File operation failed: The system exits.

// Create a network

Void Net :: Rereate (Void)

{

IF (iSChanged ())

{

Absrout * prout = NULL;

Absline * pline = NULL;

Std :: fstream file;

Std :: fstream indexfile;

Char * filename = "routaddress.txt";

Char * indexfilename = "indexaddr.txt";

Unsigned int Addr [ip_address_length];

// Empty resources

Clear ();

// Get network structure information

GetNetinFor ();

PnodeArray = new NetNode [routnum];

/ / Open the Storage "Router Address Form" file

File.open (filename, std :: os_base :: in | std :: os_base :: out); if (file.fail ()) {std :: cout << "/ n / n file (" << FileName < <") Open failed ./n/n"; char ch; std :: cin >> CH; exit (-1);} // Open Storage "Route and Address Correspondence" file

Indexfile.open (IndexFileName, std :: ios_base :: in | std :: os_base :: out);

IF (indexfile.fail ()) {std :: cout << "/ n / n file (" << indexfilename << ") opens failed ./n/n"; char ch; std :: cin >> CH; exit (-1);

For (int i = 0; i

{// Initialization

Indexfile << i << '/ t';

For (int J = 0; j

{

File >> Addr [J];

Indexfile << Addr [J] << '';

}

Indexfile << '/ n';

PROUT = New Centralrout ();

PROUT-> SetSelfadDress (add);

(PnodeArray I) -> PROUT = prout;

PLINE = New fiber ();

(PnodeArray I) -> PLINE = PLINE;

} // End of for

File.Close ();

Indexfile.close ();

}

/ * Comment content is the implementation of network neighboring tables, and the adjacent table can represent any complex network.

But here is omitted, and the information of the network is still relying on matrix and saved. To be created

When any complicated network, you can modify and expand the code.

(This part of the code is slightly ...) * /

}

Third, the establishment of routing calculation and routing table

This part is the comparison core content. The establishment of routing calculations is separated from the implementation of routing. Routing Calculation Realization We have another document separately. When the routing calculation is integrated with its realization, the routing table can be completed by the router.

1. Set the routing method

Method Name: Absrout :: SetComputeMethods

Method parameters: void _RoutCompute (int **, int **, int ** &, int, int)

Return value: no

The purpose of the method: the implementation of the routing calculation (parameter _ routCompute) is connected to the router within the router.

Possible error: no

// Set the routing method

Void Absrout :: SetComputeMethods (void _RoutCompute (int **, int **, int ** &, int, int))

{

RoutCompute = _ROUTCompute;

}

2, the establishment of routing calculation

Method Name: Net :: RoutComputeBuilder

Method parameters: no

Return value: no

The purpose of the method: the complete establishment of routing calculations. Including settings to achieve routing calculations, flooding to send network information to the router, call the routing table fill in the method.

Possible error: no

// Runputing creation

Void Net :: RoutComputeBuilder (Void)

{

IF (PnodeArray! = NULL)

{

For (int i = 0; i

{

(PnodeArray i) -> PROUT-> setComputeMethods (ComputeMethods);

(PnodeArray i) -> PROT-> SetNetinFor (NetArray, Valarray, Routnum);

} //

For (int i = 0; i

(PnodeArray I) -> PROUT-> setttable ();

} //

}

Note: The function computeMethod is implemented by the DLL file, which is the topic section of the routing algorithm.

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

New Post(0)