2, the router receives data from the port
Method Name: CentralRout :: ReceiveData
Method parameters: no
Return value: no
The purpose of the method: the router reads data from the router port. If success, the routing is performed.
Possible error: no
// Router receives data from the port
Void CentralRout :: ReceiveData (Void)
{
Dataiter = DataINList.begin ();
IF (DataTer! = DATAINLIST.END ())
{// read a packet
Curripdata.SetaddressFrom (Dataiter-> GetDressFrom ());
Curripdata.Setaddressto (Dataiter-> GetDresSto ());
Curripdata.setnexthop (Dataiter-> getNexthop ());
Curripdata.SetPrehop (Dataiter-> getPrehop ());
Curripdata.id = dataiter-> id;
Curripdata.setipdata (Dataiter-> Getipdata ());
/ / Delete the data package from the port
DataINList.rase (Dataiter);
DataListLength -;
/ / Perform routing calculation
DataroutCompute ();
}
}
3. Raise the current packet for routing
Method Name: Absrout :: DataroutCompute
Method parameters: no
Return value: no
The purpose of the method: the router calculates the current packet to determine which router is to be sent. Then call the router to write data to the port.
Possible error: no
/ / Routing the current packet
Void Absrout :: DatarOutCompute (Void)
{
Curripdata.SetPrehop (Selfaddress);
Unsigned int * addr = routTable.getaddRNexthop (curripdata.getaddressto ());
Curripdata.setnexThop (AddR);
/ / --------------------------------------------------------------------------------------------
/ / Output prompt information to the console
Std :: cout << "/ n / T Calculate success ...";
Std :: cout << "/ n / TNEXT HOP:";
For (int i = 0; i Std :: cout << addr [i]; Std :: cout << std :: endl; / / -------------------------------------------------------------------------------------------- Senddata (); } 4, the router sends data to the port Method Name: Centralrout :: Senddata Method parameters: no Return value: no The purpose of the method: the router writes data to the port. Possible error: no / / The router sends data to the port Void CentralRout :: Senddata (void) { DataOutlist.push_back (curripdata); } 5, network receiving data from the router port Method Name: CentralRout :: NetReadData Method parameters: no Return Value: NetData * The purpose of the method: the network reads the copy of the packet from the router port and returns the packet copy. IPDATA and Message are different processing. This program is more concise, and real-time simulation needs to expand code. Possible error: no // Network receives data from the router port NetData * CentralRout :: NetReadData () { Netdata * _netdata = null; Dataiter = DataOutlist.begin (); IF (Dataiter! = DataOutlist.end ()) { IF (! dataiter-> ismessage ()) { _netdata = new netdata (false); _netdata-> setaddressFrom (dataiter-> getaddressfrom ()); _netdata-> setaddressto (Dataiter-> getaddressto ()); _netdata-> setprehop (Dataiter-> getPrehop ()); _netdata-> setnexthop (dataiter-> getnexthop ()); _netdata-> id = dataiter-> id; _netdata-> setipdata (Dataiter-> getipdata ()); // Semantic, the router should start a batch, // Wait a response message; or some mechanism instead of the timer to do the basis for retransmission. // The code is to be expanded. } else if (dataiter-> ismessage ()) { _netdata = new netdata (TRUE); _netdata-> setaddressFrom (dataiter-> getaddressfrom ()); _netdata-> setaddressto (Dataiter-> getaddressto ()); _netdata-> setprehop (Dataiter-> getPrehop ()); _netdata-> setnexthop (dataiter-> getnexthop ()); _netdata-> id = dataiter-> id; // Answering message does not retransmit DataOutlist.rase (Dataiter); } // End of else IF } // end of if Return_netdata; }