Design one, global name space
All the global variables and functions in the routing simulation system are implemented in a name space.
Name space: Netsource
Name Space variables:
#define NULL 0
Network Device Type Table
Enum Netelementtype{fiber=1,centralrout};
Route IP Address length
const int IP_ADDRESS_LENGTH=32;
Maximum routing table length
const int max_rout_table_size=100;
Router Port Maximum packet capacity
const int MAX_DATA_QUEUE_LENGTH=20;
function in name space:
Determine whether two IP addresses are equal
BOOL Addrequal (const unsigned int * addr1,const unsigned int * addr2);
Second, class design
The class of routing simulation system is designed according to the former document class diagram. The constructors of all classes and the interface of the destructor are described slightly.
1, network elements
Class Name: Netelement
Nature of Class: pure virtual base class
Parent class: None
Main properties of the class:
Types of network devices
< protected > Netelementtype netelementtype;
The main interface of the class:
Get the type of network device
< public > virtual Netelementtype GetType (void) = 0;
2, Network Line
Class Name: Absline
Nature of Class: pure virtual base class
Parent class: Public inheritance Netelement
Main properties of the class:
Inheritance property slightly;
Length of network Line
< protected > int length;
The main interface of the class:
< public > virtual void setlength (int _length) = 0;
< public > virtual int getlength (void) = 0;
3, Optical fiber
Class Name: Fiber
The nature of a class: an instantiated subclass
Parent class: Public inheritance Absline
Main properties of the class:
Inheritance property slightly;
The main interface of the class:
Get the type of network device
< public > Netelementtype GetType (void);
Set the line physical length
< public > virtual void setlength (int _length);
Get the line physical length
< public > virtual int getlength (void);
4, router
Class Name: Absrout
Nature of Class: pure virtual base class
Parent class: Public inheritance Netelement
Main properties of the class:
Inheritance property slightly;
Router's own address
< protected > int selfaddress[ip_address_length];
routing table
< protected > Table routtable;
Current IP packet
< protected > Netdata currtpdata;
Data port
< protected > Std::list <NetData> datainlist;
< protected > Std::list <NetData> dataoutlist;
< protected > Std::list <netdata>::iterator dataiter;
Current Data port Data volume
< protected > int datalistlength;
The main interface of the class:
Routers send data to ports
< protected > virtual void senddata (void) = 0;
Routers receive data from ports
< protected > virtual void receivedata (void) = 0;
Network writes data to router port
< public > virtual bool Netwritedata (Netdata & _netdata) = 0;
The network receives data from the router port
< public > virtual Netdata * netreaddata () = 0;
Setting up the routing table
< public > virtual void setrouttable (void);
Routing Calculations: function pointers
< protected > void (*routcompute) (int **_netarray,int **_valarray,
int **&result,int Routnum,int index);
Route calculation for current packet
< protected > void Dataroutcompute (void);
Set Routing calculation method
< public > void setcomputemethods void _routcompute (int **,int * *,
int **&,int,int));
Set your own address
< public > virtual void setselfaddress (
unsigned int addr[ip_address_length]);
Get your own address
< public > virtual unsigned int * getselfaddress (void);
Empty
< public > virtual void setnetinfor (int * * _netarray, int * * * Valarray,
int _routnum);
Generate Data
< public > void Makedata (Netdata & Netdata);
5, center router
Class Name: Centralrout
The nature of a class: an instantiated subclass
Parent class: Public inheritance Absrout
Main properties of the class:
Inheritance property slightly;
Network Information
< private > int **netarray,**valarray;
Send Packet Tracker
< private > Double ID;
The main interface of the class:
Get device Type
< public > virtual Netelementtype GetType (void);
Network sends data to port
< public > virtual bool Netwritedata (Netdata & _netdata);
The network receives data from the router port
< public > virtual Netdata * netreaddata ();
Setting up the routing table
< public > virtual void setrouttable (void);
Flood process obtains network information
< public > virtual void setnetinfor (int * * _netarray, int * * * _valarray,int _routnum);
Routers send data to ports
< protected > virtual void senddata (void);
Routers receive data from ports
< protected > virtual void receivedata (void);
6. Network Node
Class Name: Netnode
The nature of a class: an instantiated class
Parent class: None
Main properties of the class:
Router
< public > Absrout *prout;
Network Line
< public > Absline *pline;
< public > Netnode *pnextnode;
The main interface of the class:
No
7, Network
Class Name: Net
The nature of a class: an instantiated class
Parent class: None
Main properties of the class:
Number of routers in the network
< private > int routnum;
Number of network lines in network
< private > int linenum;
Data structure of the network: adjacency table
< private > Netnode *pnodearray;
Adjacent matrix and dissipation matrix of networks
< private > int * * NETARRAY;
< private > int * * VALARRAY;
The type vector of the router
< private > Netelementtype * routtypes;
Type vectors for network lines
< private > Netelementtype * linetypes;
Network first built
< private > static bool I;
The main interface of the class:
Create an empty network
< public > void Create (int _routnum);
Creating a backbone network
< public > void Create (int * * * _netarray, int * * _valarray, int _routnum);
Create any type of network
< public > void Create (int * * * _netarray, int * * _valarray, int _routnum,int _linenum, Netelementtype * R, Netelement Type * L);
Get Network Information
< private > void getnetinfor (void);
Determine if the network has changed
< private > bool ischanged (void);
Releasing resources
< private > void clear (void);
Create a network
< public > void recreate (void);
According to the address to obtain the router sequence subscript
< public > int getroutid (unsigned int addr[ip_address_length]);
Get Pnodearray
< public > Netnode *& getpnodearray ();
Data packets that generate network transmissions
< public > int makedata (void);
Data packets that generate network transmissions
< public > int makedata (netdata &_ipdata);
The establishment of routing calculation
< public > void Routcomputebuilder (void);
8. Routing Table node
Class Name: Tablenode
The nature of a class: an instantiated class
Parent class: None
Main properties of the class:
Destination Address
< public > unsigned int addressto[ip_address_length];
Next Relay Routing Address
< public > unsigned int addressnexthop[ip_address_length];
The main interface of the class:
Set Destination Address
< public > void Setaddressto (unsigned int _addressto[ip_address_length]);
Set Next relay Routing address
< public > void setaddressnexthop (unsigned int
_addressnexthop[ip_address_length]);
9, routing Table
Class Name: Table
The nature of a class: an instantiated class
Parent class: None
Main properties of the class:
Number of routers
< private > int routnum;
routing table
< private > Tablenode table[max_rout_table_size];
The main interface of the class:
Set the number of routers
< public > void setroutnum (int _routnum);
Setting up the routing table
< public > void settable (Tablenode _table[max_rout_table_size]);
Get Next Relay Routing address
< public > int * getaddrnexthop (int addrto[ip_address_length]);
Get number of routers
< public > int getroutnum (void);
10, network data packet
Class Name: Netdata
The nature of a class: an instantiated class
Parent class: None
Main properties of the class:
The source address of the network packet
< private > unsigned int addressfrom[ip_address_length];
Destination Address of network packet
< private > unsigned int addressto[ip_address_length];
Relay address before network packet
< private > unsigned int prehop[ip_address_length];
Relay address after network packet
< private > unsigned int nexthop[ip_address_length];
Whether it's a message
< private > bool bmessage;
Packet Tracking counter: message and IP packet a pair of images
< public > Double ID;
Data information of network packet
< private > int ipdata[ip_address_length];
The main interface of the class:
Determine if the answer message is
< public > bool Ismessage (void);
Determine if network packets are the same
< public > BOOL operator = = (Netdata &netdata);
Set network packet Source address
< public > void setaddressfrom (unsigned int addrfrom[ip_address_length]);
Set network packet Destination address
< public > void Setaddressto (unsigned int addrto[ip_address_length]);
Get network packet Source address
< public > Unsigned int * getaddressfrom (void);
Get network packet Destination address
< public > Unsigned int * getaddressto (void);
Relay addresses before setting up network packets
< public > void Setprehop (const unsigned int _prehop[ip_address_length]);
Relay address after setting up network packets
< public > void Setnexthop (const unsigned int _nexthop[ip_address_length]);
Relay address before obtaining network packet
< public > Unsigned int * getprehop (void);
Relay address after obtaining network packet
< public > Unsigned int * getnexthop (void);
Set IP packet data content
< public > void setipdata (const int _ipdata[ip_address_length]);
Get the data content of IP packets
< public > int * getipdata (void);
11, communication
Class Name: Communication
The nature of a class: an instantiated class
Parent class: None
Main properties of the class:
Network simulation
< private > Net &net;
References to network data structures
< private > Netnode *& pnodearray;
The main interface of the class:
Single Packet routing
< public > void singledatarout (void);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.