Designing a network in Python

Discussion in 'Python' started by varun7rs@gmail.com, Apr 30, 2014.

  1. Guest

    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, storageand processing capacity to the nodes. So, I generated some random integersfor 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)
     
    , Apr 30, 2014
    #1
    1. Advertising

  2. > 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.


    > And moreover, I'd like to assign some kind of a bandwidth capacity to thelinks and
    > similarly, storage and processing capacity to the nodes.


    I don't know anything about your use case or data really, but from the above I
    already know I would shove this all into a database, adding tables with relations
    and mining data based on relations becomes trivial. More importantly, it also then
    becomes easily extensible without refactoring as your requirements change.

    Just my opinion,
    jlc
     
    Joseph L. Casale, Apr 30, 2014
    #2
    1. Advertising

  3. Guest

    I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the xml file like the node-name, source, destination and the capacity. Since, I am done with that part, I now want to have a link between source and destination and assign capacity to it.

    eg., [a,b,c,d,e] [l,m,n,o,p] [5,2,3,4,5]

    I need something like a - l: 5, b - m: 2,....I don't know how to describe this exactly but I hope this would give you a rough idea. After this, I put the stuff back into an xml but this time only there are more parameters andlooks more detailed....

    Like nodeID = Aachen...stor_capacity = 100, proc_capacity = 200, switch_capacity = 190...etc
     
    , Apr 30, 2014
    #3
  4. On 4/30/14 9:57 AM, wrote:
    > I don't know how to do that stuff in python.


    Always a good time to learn.


    Let the database do the work for you; try not to re-invent the
    relational database wheel. Access the database via python-sql:

    https://pypi.python.org/pypi/python-sql/


    marcus
     
    Mark H Harris, Apr 30, 2014
    #4
  5. > I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the
    > xml file like the node-name, source, destination and the capacity. Since,I am done with that
    > part, I now want to have a link between source and destination and assigncapacity to it.


    I dont mind writing you an SQLite schema and accessor class, can you defineyour data in a tabular
    format and mail it to me offline, we add relationships etc as we go.

    Hopefully it inspires you to adopt this approach in the future as it often proves powerful.

    jlc
     
    Joseph L. Casale, Apr 30, 2014
    #5
  6. Guest

    On Wednesday, 30 April 2014 20:38:07 UTC+2, Joseph L. Casale wrote:
    > > I don't know how to do that stuff in python. Basically, I'm trying to pull certain data from the
    > > xml file like the node-name, source, destination and the capacity. Since, I am done with that
    > > part, I now want to have a link between source and destination and assign capacity to it.

    >
    > I dont mind writing you an SQLite schema and accessor class, can you define your data in a tabular
    > format and mail it to me offline, we add relationships etc as we go.
    >
    > Hopefully it inspires you to adopt this approach in the future as it often proves powerful.
    >
    > jlc


    Thanks a lot for your help. But, how do I mail you? I can't find your mail id here
     
    , May 2, 2014
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kal
    Replies:
    1
    Views:
    9,532
    Kevin Spencer
    Jun 21, 2004
  2. Jane Davis

    Network Service account over network

    Jane Davis, Jun 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    453
    Kevin Spencer
    Jun 22, 2005
  3. Bill Volk
    Replies:
    1
    Views:
    3,155
    Bill Volk
    Jul 2, 2003
  4. kin
    Replies:
    0
    Views:
    919
  5. king
    Replies:
    1
    Views:
    285
Loading...

Share This Page