Designing a network in Python

varun7rs at gmail.com varun7rs at gmail.com
Wed Apr 30 05:30:04 EDT 2014


Hello Friends

I would like to design a network given the topology and the source I use is 
http://sndlib.zib.de/home.action

I have managed to read most of the important data in the xml onto lists. Now, I have two lists, Source and Destination and I'd like to create bi-directional links between them. My code is as below. And moreover, I'd like to assign some kind of a bandwidth capacity to the links and similarly, storage and processing capacity to the nodes. So, I generated some random integers for them. I don't know how to proceed further to design the topology. I'd prefer to do the topology design in another .py file probably. I'd be glad if you guys could lend me a helping hand.

import sys
import xml.dom.minidom as dom 
import string
#from xml.dom.minidom import getDOMimplementation
from xml.dom import minidom
from xml.dom.minidom import parse
import os
import random



class PHY_NODES:
    def __init__(self, nodeID, x, y, capacity_proc, capacity_stor, capacity_switch):
        self.nodeID = nodeID
        self.x = x
        self.y = y
        self.linklist = []
        self.capacity_proc = capacity_proc
        self.capacity_stor = capacity_stor
        self.capacity_switch = capacity_switch
        
class PHY_LINKS:
    def __init__(self, linkID, source, destination, capacity_bdw):
        self.linkID = linkID
        self.source = source
        self.destination = destination
        self.capacity_bdw = capacity_bdw
        
# Reading Nodes

Read_Data = minidom.parse("germany50.xml")
nodelist = Read_Data.getElementsByTagName("node")
corenodes = []
for node in nodelist :
	corenodes.append(node.getAttribute("id"))
	nodeid = node.getAttribute("id")
	xCoordinates = node.getElementsByTagName("x") [0]
	yCoordinates = node.getElementsByTagName("y") [0]
	proc = random.randint(20, 40)
	stor = random.randint(40, 80)
	switch = random.randint(60, 90)
	nodeobj = PHY_NODES(nodeid, xCoordinates, yCoordinates, proc, stor, switch)



# Reading Links 

linklist = Read_Data.getElementsByTagName("link")

links = []
sources = []
destinations = []
capacity_link = []
for link in linklist :
	linkid = link.getAttribute("id")
	Source = link.getElementsByTagName("source") [0]
	Destination = link.getElementsByTagName("target") [0]
	Capacity = link.getElementsByTagName("capacity") [0]
	linkobj = PHY_LINKS(linkid, Source, Destination, Capacity)
	sources.append(Source.firstChild.data)
	destinations.append(Destination.firstChild.data)
	capacity_link.append(Capacity.firstChild.data)



More information about the Python-list mailing list