⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topology.h

📁 模拟P2P各种网络环境的,适合新手们的学习,不错的源码.
💻 H
字号:
#ifndef _Topology_h
#define _Topology_h

#define PMAX 0.99
#define PMIN 0.00

#include "Common.h"
#include "Node.h"
#include "Link.h"

class Graph;
class Property;
class Agent;

typedef struct
{
	int id;
	int number;
	int transitNumber;
	
	map<int, int> mapTable;
	map<int, int> reverseMapTable;
	
	set<int> transitTable;

	vector< vector<int> > predecessorMatrix;
	vector< vector<unsigned long> > delayMatrix;
	
}Domain;


class Topology
{
private:
	static Topology *mInstance;
	int mAsNumber; /* number of atonomous system */
	int mNodeNumber;  /* number of nodes */
	int mLinkNumber; /* number of links */
	vector<Node> mNode; /* vector storing all nodes */
	map<string, Link> mLink; /* map storing all links */

	vector<Domain> mDomain;
	
	vector< vector<unsigned long> > mDelayMatrix; /* delay information for any two nodes corresponding to the shortest path between them */
	vector< vector<int> > mPredecessorMatrix; /* used for convenience when compute the links embedded in the shortest path between any two nodes, not in use now, substituted by mDomain */
public:
	Topology();
	static Topology *getInstance();
	void reset();
	
	/* return a non-negative value if success, -1 on error */
	double getDelay(int id1, int id2) const; /*get delay between any two nodes */
	
	/* return a non-negative value if success, -1 on error */
	double getBandwidth(int id1, int id2);

	double getAvailableBandwidth(bool flag, Agent *agent);

	/* non-null pointer if success, null on error */
	Node *getNode(int id);
	
	/* non-null pointer if success, null on error */
	Link *getLinkBetween(int id1, int id2); /* return the link between two adjacent nodes */

	vector<Link *> getVLinkBetween(Agent *agent1, Agent *agent2); /* return the virtual link between agent and node */ 

	/* non-empty vector if success(because the graph we used is always connected and undirected), empty on error */
	vector<Link *> getAllLinkBetweenOld(int id1, int id2); /* (old method)get the links embedded in the shortest path between two nodes, not in use now */
	vector<Link *> getAllLinkBetween(int id1, int id2); /* (new method)get the links embedded in the shortest path between two nodes */
	
	int getNodeNumber();
	int getLinkNumber();
	
	void configNetwork(Graph &graph, Property &property);

	double calculateBandwidth(double mss, double rtt, double p, double c, double band);
	
	void writeData(const char *file);

};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -