Random Topology Generation

731 views
Skip to first unread message

Bob Thomas

unread,
Oct 20, 2010, 3:06:55 PM10/20/10
to ns-3-users
HI,

Does anyone know how I could generate random topologies for use in
ns3?
I am looking for the simplest way of doing this, I don't want to get
bogged down too much by it.
Thanks.

Rafael Roque

unread,
Oct 20, 2010, 7:48:35 PM10/20/10
to ns-3-...@googlegroups.com
Why dont you try two ranges, say A from x to y, and B from r to t, then use an ns3 provided uniform variable to generate initial nodes positions?


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Rafael Roque Aschoff

PhD student at the City University London - http://www.soi.city.ac.uk/
Researcher at Network and Telecommunication Research Group - www.gprt.ufpe.br
MSc in Computer Science / UFPE - www.cin.ufpe.br

Mobile Contact: 07848873464



Bob Thomas

unread,
Oct 21, 2010, 12:32:12 PM10/21/10
to ns-3-users
I'm not sure that I am following what you mean, could you build off of
that a little?

Thanks for the reply.

Bob Thomas

unread,
Oct 21, 2010, 12:58:18 PM10/21/10
to ns-3-users
Oh by the way, this will be for use in a global routing script, so
wired links.

Rafael Roque

unread,
Oct 21, 2010, 4:38:45 PM10/21/10
to ns-3-...@googlegroups.com
For example, you could use:

UniformVariable a(0,100);
UniformVariable b(0,200);

for(i=0; i < numNodes; i++){
 Ptr<Node> temp = nodeContainer.Get(i); 
 Vector pos;
 pos.x = a.GetValue();
 pos.y = b.GetValue();
 Ptr<MobilityModel> mobility = node->GetObject<MobilityModel> ();
 mobility->SetPosition (v);
}

Well, this is a very simple example.

On Thu, Oct 21, 2010 at 5:58 PM, Bob Thomas <redv...@gmail.com> wrote:
Oh by the way, this will be for use in a global routing script, so
wired links.
--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Bob Thomas

unread,
Oct 21, 2010, 11:13:03 PM10/21/10
to ns-3-users
Ahh, ok thanks for the reply.

I'm actually not using the mobilitymodel at the moment. I'm using
global routing, wired links. So I guess a random topology would
consist of a random links between the nodes that I create, maybe a
random number of nodes, or a set number..either way. I'm not familiar
with mobility. So I guess I need to create random links and random
link weights. Any thoughts?

Thank you.

Rafael Roque

unread,
Oct 22, 2010, 4:47:00 AM10/22/10
to ns-3-...@googlegroups.com
Hmmm, thats more interesting...

I have an idea. It is just a first idea and I do not even try it on a compiler, but I think it will be useful for something.
The bellow algorithm creates an enclosed topology and does not care about weight, however, my intention was just to create something that helped to create a random topology somehow.

There should be some mistakes, but i hope the idea is clear.

--------------------------------------------------
uint_32 numNodes = 50;

bool linkMatrix[50][50];
bzero (linkMatrix, sizeof(bool)*50*50); //initialize it to false


UniformVariable encT; //Used to create an enclosed topology

//tryes to create an simple enclosed topology
//by incrementaly choosing previous nodes (probabilistically) to be connected with.
for(uint_32 i = 1, i < numNodes; i++){
    uint_32 instaledNode = encT.GetInteger(0, i-1);
    linkMatrix[i, instaledNode] = true;
    linkMatrix[instaledNode, i] = true;
    cout << "There is a path between node " << i << " and node " << instaledNode << endl;           
}

//now lets try to construct other paths


double linkProbability = 30.0;
UniformVariable link(0,100);


for(uint_32 i = 0, i < numNodes; i++){ 
    for(uint_32 j = i+1, j < numNodes; j++){
        bool addPath = (!linkMatrix[i][j]) && (linkP.GetVAlue() <= linkProbability);
        if(addPath){
            linkMatrix[i, j] = true;
            linkMatrix[j, i] = true;
            cout << "There is a path between node " << i << " and node " << j << endl;
        }      
      
    }
}


for(uint_32 i = 0, i < numNodes; i++){
    cout << "Link for node " << j << endl;     
    for(uint_32 j = 0, j < numNodes; j++){
        cout << "" << j " - "; 
    }
    cout << endl;
}

--------------------------------------------------


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Bob Thomas

unread,
Oct 22, 2010, 2:12:55 PM10/22/10
to ns-3-users
Thank you so much for the reply :)
Your code will be useful, I just want to clear some things up.

My first thoughts on how to create this random topology were as
follows..

1) Generate random # of nodes (or I could use a fixed number)
2) Create these nodes in ns3 script
3) Generate a random adjacency matrix (or cost incidence matrix)
For example, something like this

0 1 2 3
0 -1 2 5 3
1 0 -1 1 5
2 9 8 -1 3
3 -1 2 -1 -1

something like that...with "-1" representing the fact that their is no
link between those nodes.

for ( int i = 0; i < nodes.GetN() ; i++) {
for ( int j = 0 ; j< nodes.GetN() ; j++){
if ( i ==j || j == i ) { mylinkweights[i][j] = -1;} //avoid
loops
else { mylinkweights[i][j] = UniformVariable::GetSingleValue(-1,
100);}
}
}

4) Create the channels in ns3 from this matrix

NetDeviceContainer n[i]n[j] =
p2phelper.Install(nodes.Get(i),nodes.Get(j));

5) Assign the IP addresses to these channels
Ipv4AddressHelper ipv4;
ipv4.SetBase("10.1.1.0", "255.255.255.0");

I don't have my code on my atm, so I can't go further then this.
And i'm not sure if this is all possible in ns3..mainly confused about
step 4 and 5.

Any ideas?
Thanks so much

Egemen Cetinkaya

unread,
Oct 22, 2010, 4:36:06 PM10/22/10
to ns-3-...@googlegroups.com
A matrix-topology.cc example is merged to ns-3-dev tree, under the
examples directory... As long as you provide the adjacency matrix and
node coordinates, it setups the network for you. It doesn't deal with
the link weights however. How you generate the random topology, it is
up to you. I would suggest to have a look at that one for your
problem.

Thanks,

Egemen

Rafael Roque

unread,
Oct 23, 2010, 3:34:47 PM10/23/10
to ns-3-...@googlegroups.com
I think it could be a good idea to check the code matrix-topology.cc as already suggested.
Moreover, your code mylinkweights[i][j] = UniformVariable::GetSingleValue(-1,
100); will let your matrix (at a high probability) with every nodes connected to every nodes.

This is why in my code I introduced two step. One for ensure that topology is enclosed, and another to setup additional links.
You could change it to decide the weights instead of yes or no.


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.

Bob Thomas

unread,
Oct 25, 2010, 2:19:45 PM10/25/10
to ns-3-users
Thanks for all of the help so far :)

I have a quick question about the matrix-topolog.cc

NS_LOG_INFO ("Assign Addresses to Nodes.");
Ipv4AddressHelper ipv4_n;
ipv4_n.SetBase ("10.0.0.0", "255.255.255.252");

This sets all of the nodes addresses to "10.0.0.0" correct? I would
like my topology to have the addresses to go like this. 10.1.1.0,
10.1.2.0, 10.1.3.0, 10.1.4.0, 10.1.5.0, etc. How could this be made
possible?

Thanks

Egemen Cetinkaya

unread,
Oct 25, 2010, 4:52:32 PM10/25/10
to ns-3-...@googlegroups.com
No, the below sets the IP addresses as : 10.0.0.4, 1.0.0.8, ... since
the network mask was set to /30 (255.255.255.252) in the
matrix-topology.cc, with each interface having a separate IP address.

Have a look at the network masking subject for your question.
10.1.0.0 /16 should allocate you the whole block.

Thanks,

Egemen

Bob Thomas

unread,
Oct 27, 2010, 11:45:21 AM10/27/10
to ns-3-users
Thanks for the reply.

Ok...So I'm using still confused on how the network masks work.

I was actually mistaken on my addressing in the above post.
For my topology I want my links to have addresses: 10.1.1.0, 10.1.2.0,
10.1.3.0, 10.1.4.0, 10.1.5.0...etc
and I want my nodes to have addresses: 10.1.1.1, 10.1.1.2, 10.1.2.1,
10.1.2.2, 10.1.3.1, 10.1.3.2...etc

My idea is that "255.255.0.0" means that only bits 3 and 4 can change?

Therefore I tried this.

ipv4_n.SetBase("10.1.1.0", "255.255.0,0");

Any help?

Leandro Melo de Sales

unread,
Oct 27, 2010, 12:10:30 PM10/27/10
to ns-3-users

Was the last comma just a mistake in the above SetBase? you wrote 255.255.0,0, instead of 255.255.0.0

Leandro.
 

Any help?


--
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To post to this group, send email to ns-3-...@googlegroups.com.
To unsubscribe from this group, send email to ns-3-users+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ns-3-users?hl=en.




--
Leandro Melo de Sales
Assistant Professor
Institute of Computing at Federal University of Alagoas, Brazil

PhD candidate in Computer Science
Pervasive and Embedded Computing Laboratory, UFCG

"The warrior is strong in loyalty, intensity, determination, initiative, persistence, courage and willpower. The warrior is light in the soul, self-trust and compassion. The warrior is often called to take the front when other cowardly make a step backwards. There are warriors on the battlefields and in everyday life."

Bob Thomas

unread,
Oct 27, 2010, 1:48:33 PM10/27/10
to ns-3-users
Yep that was a mistake, sorry about that.

Should be:
ipv4_n.SetBase("10.1.1.0", "255.255.0.0");

Bob Thomas

unread,
Oct 27, 2010, 1:54:02 PM10/27/10
to ns-3-users
But that mistake was only on the list, not in my code. So any help?
Reply all
Reply to author
Forward
0 new messages