Beispiel #1
0
def Test1():
    # Testing graph 1
    '''
    A ----100-----B
    |             |
    50           80
    |             |
    C-----140-----D
    '''
    g1 = graph()
    v1 = graph.vertex('a')
    g1.addvertex(v1)
    v2 = graph.vertex('b')
    v1.addneighbor(v2, 100)
    g1.addvertex(v2)
    v3 = graph.vertex('c')
    v1.addneighbor(v3, 50)
    g1.addvertex(v3)
    v4 = graph.vertex('d')
    v3.addneighbor(v4, 140)
    g1.addvertex(v4)
    v2.addneighbor(v4, 80)
    g1.printgraph()
    #v5 = vertex('e')
    e, nh = g1.dijkstraAB(v1.name,v4.name)
    if e == -1:
        print('One of the vertex doesn\'t belong to this graph')
    else:
        print('Cost of direct path is {0} via {1}'.format(e, nh))
Beispiel #2
0
 def registerRouter(self, name, ip, port, prior):
     v = graph.vertex(name, prior)
     self.managed_routers["nodes"].append({
         "name": name,
         "ip": ip,
         "port": port,
         "interfaces": [],
         "direct_routes": []
     })
     return self.addvertex(v)
Beispiel #3
0
 def __init__(self, name, mgmtIP, port, controllerIP, prio=255):
     if ip_address(controllerIP) not in ip_interface(
             mgmtIP).network.hosts():
         print('Controller IP {0} not in range {1}'.format(
             str(ip_address(controllerIP)),
             str(ip_interface(mgmtIP).network)))
     else:
         self.vertex = graph.vertex(name, prio)
         self.ip = ip_interface(mgmtIP)
         self.port = port
         self.controller = ip_address(controllerIP)
         self.interfaces = {}
         self.localroutes = {}
         params = {
             'name': name,
             'ip': mgmtIP,
             'port': port,
             'priority': prio
         }
         r = rq.get('http://{0}:8089/router'.format(controllerIP),
                    params=params)
         print(r)
Beispiel #4
0
def Test3():
    '''
    A-----100-----B-----50-----E
    |             |            |
    10           80           25
    |             |            |
    C------10-----D-----30-----F
    '''
    g1 = graph()
    v1 = graph.vertex('a', 100)
    v2 = graph.vertex('b')
    v3 = graph.vertex('c')
    v4 = graph.vertex('d', 175)
    v5 = graph.vertex('e')
    v6 = graph.vertex('f', 50)
    v1.addneighbor(v2, 100)
    v1.addneighbor(v3, 10)
    v2.addneighbor(v1, 100)
    v2.addneighbor(v4, 80)
    v2.addneighbor(v5, 50)
    v3.addneighbor(v1, 10)
    v3.addneighbor(v4, 10)
    v4.addneighbor(v2, 80)
    v4.addneighbor(v3, 10)
    v4.addneighbor(v6, 30)
    v5.addneighbor(v2, 50)
    v5.addneighbor(v6, 25)
    v6.addneighbor(v4, 30)
    v6.addneighbor(v5, 25)
    g1.addvertex(v1)
    g1.addvertex(v2)
    g1.addvertex(v3)
    g1.addvertex(v4)
    g1.addvertex(v5)
    g1.addvertex(v6)
    g1.printgraph()
    '''e, nh = g1.dijkstraAB(v1.name,v6.name)
    if e == -1:
        print('One of the vertex doesn\'t belong to this graph')
    else:
        print('Cost of direct path is {0} via {1}'.format(e, nh))'''
    print (g1.fullDijkstra())
    return g1
Beispiel #5
0
-(exit) to exit\n\
:')
    while 1:
        if opt == 'exit':
            break
        elif 'route' in opt:
            if g1.vertexexists(opt.split('+')[1]):
                print(g1.g[opt.split('+')[1]].printroutes())
        elif opt == 'list':
            print(g1.listofvertex())
        elif 'add' in opt:
            if len(opt.split('+')) < 3:
                print('Wrong parameters\n')
            else:
                o, ver, prio = opt.split('+')
                v = graph.vertex(ver, int(prio))
                g1.addvertex(v)
        elif 'edge' in opt:
            if len(opt.split('+')) < 4:
                print('Wrong parameters\n')
            else:
                o, sv, dv, cost = opt.split('+')
                if g1.vertexexists(sv) and g1.vertexexists(dv):
                    g1.addedge(sv, dv, int(cost))
        elif 'remove' in opt:
            if len(opt.split('+')) < 2:
                print('Wrong parameters\n')
            else:
                o, ver = opt.split('+')
                if g1.vertexexists(ver):
                    g1.delvertex(ver)