Routing Simulation - Implementation of Design Scheme (2)

zhaozj2021-02-16  51

Second, the establishment of the network

The establishment of the network is targeted for the central router, any complex network can be expanded. In addition, part of the code is written for separate debugging, running, and rewrites part of the code when integrating with the communication simulation system.

1, get network information

Method Name: Net :: GetNetinfor

Method parameters: no

Return value: no

The purpose of the method: obtain information of the network, including the topology information of the network, dissipation information, and router type vectors that may include network line type vector. This implementation is a simple case, read this information from a file. If integrated with the communication simulation system, the interface provided by the communication simulation system is called to obtain this information, and the code can be rewritten.

Possible error: File operation failed: The system exits.

// Get network information

Void Net :: GetNetinfor (Void)

{

INT _ROUTNUM = -1;

INT _LINENUM = -1;

Std :: fstream file;

Char * filename = "netinfor.txt";

File.open (filename, std :: os_base :: in | std :: ios_base :: out);

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

/ / Here is the network information from the file, which can be obtained directly from the communication simulation system.

// can be implemented separately. Current code only considers information about the backbone network. Complex networks can be expanded.

File >> _ routnum;

File >> _ lineenum;

Routnum = _ROUTNUM;

LINENUM = _LineNum;

// Apply for memory resources

NetArray = new int * [routnum];

For (int i = 0; i

NetArray [i] = new int [routnum];

Valarray = new int * [routnum];

For (int i = 0; i

Valarray [i] = new int [routnum];

ROUTTYPES = New NetlementType [routnum];

LINETYPES = New NetlementType [LINENUM];

// Read the file to get network information: only includes topology information and dissipation information

For (int i = 0; i

For (int J = 0; j

File >> NetArray [i] [j];

For (int i = 0; i

For (int J = 0; j

File >> Valarray [i] [j];

File.Close ();

}

2. Judging whether the network changes

Method Name: Net :: ischancted

Method parameters: no

Return value: BOOL type, the network information changes, otherwise it will not change. The purpose of the method: determines whether the network information changes to decide whether to re-establish the network. Network information has changed when the network is initiated. The implementation of this scenario still needs to overwrite some code when integrating, complex networks or integration with communication simulation systems.

Possible error: File operation failed: The system exits.

/ / Judgment Whether the network changes

Bool Net :: ischanged (void)

{

IF (first) {// network initial construction

FigSt = false;

Return True;

}

/ * The code for the comment is the way to obtain network information directly from the communication system.

IF (routnum! = ... || LINENUM! = ...)

Return True;

For (int i = 0; i

For (int J = 0; j

IF (NetArray [i] [j]! = ... || Valarray [i] [j]! = ...)

Return True;

* /

INT _ROUTNUM = -1;

INT _LINENUM = -1;

Std :: fstream file;

Char * filename = "netinfor.txt";

File.open (filename, std :: os_base :: in | std :: ios_base :: out);

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

File >> _ routnum;

File >> _ lineenum;

IF (routnum! = _ routnum || LINENUM! = _ lineenum)

{// Judgment the number of routers and the number of lines

File.Close ();

Return True;

}

// Deconstimate whether the matrix and dissipation matrix have changed in network information

Int value;

For (int i = 0; i

For (int J = 0; j

{

File >> Value;

IF (NetArray [i] [j]! = value)

{

File.Close ();

Return True;

}

}

For (int i = 0; i

For (int J = 0; j

{

File >> Value;

IF (Valarray [i] [j]! = value)

{

File.Close ();

Return True;

}

}

// Network information has not changed

File.Close ();

Return False;

}

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

New Post(0)