Пример #1
0
def getgriport(hwswitch,core,griport):
    """
    In the following logical topology <Host> - <HwSwitch> - <Core Router>, the OSCARS circuits ends onto the
    port on the core router connected to the HwSwitch. This function returns the port on the HwSwitch that
    is connected to the the core router when the OSCARS circuit terminates.
    """
    hwswitchname = hwswitch.name
    corename = core.name
    links = getlinks(corename, hwswitchname)
    if links == None or len(links) == 0:
        print "No links from",corename,"to",hwswitchname
        return False
    corelink = None
    for link in links:
        (node,port) = linkednode (link, hwswitchname)
        if port != None and port == griport:
            # found the link between HwSwith and Core that ends to the OSCARS circuit.
            corelink = link
            break
    (node,hwport_tocore) = linkednode (corelink,corename)
    return hwport_tocore
Пример #2
0
def connect (localpop,
             remotepop,
             host,
             remotehost,
             gri,
             hostvlan,
             remotehostvlan,
             meter=3,
             host_rewitemac = None):
    hostname = host['name']
    remotehostname = remotehost['name']
    core = localpop.props['coreRouter']
    corename = core.name
    (corename,coredom,coreport,corevlan) = getgrinode(gri,corename)
    remotecore = remotepop.props['coreRouter']
    remotecorename = remotecore.name
    (remotecorename,remotecoredom,remotecoreport,remotecorevlan) = getgrinode(gri,remotecorename)
    datapath = getdatapaths(host)[0] # Assumes the first datapath
    hostport = datapath['name']
    remotedatapath = getdatapaths(remotehost)[0] # Assumes the first datapath
    remotehostport = remotedatapath['name']
    hwswitch = localpop.props['hwSwitch']
    hwswitchname = hwswitch.name
    remotehwswitch = remotepop.props['hwSwitch']
    remotehwswitchname = remotehwswitch.name
    remotelinks = getlinks(remotecorename, remotehwswitchname)
    # Find hwswith/port - core/port
    hwport_tocore = getgriport(hwswitch,core,coreport)
    # Find remotehwswith/port - remotecore/port
    remotehwport_tocore = getgriport(remotehwswitch,remotecore,remotecoreport)

    # Find the port on the HwSwitch that is connected to the host's port
    links = getlinks(hostname, hwswitchname)
    if links == None or len(links) == 0:
        print "No links from",hostname,"to",hwswitchname
        return False
    hostlink = None
    for link in links:
        (node,port) = linkednode (link, hwswitchname)
        if port != None and port == hostport:
            # found the link
            hostlink = link
            break
    (node,hwport_tohost) = linkednode ( hostlink,hostname)

    connectdataplane(hwswitch,
                     host,
                     hostport,
                     hostvlan,
                     hwswitch,
                     hwport_tohost,
                     hwport_tocore,
                     corevlan,
                     gri,
                     meter,
                     host_rewitemac = host_rewitemac)

    # Find the port on the remote HwSwitch that is connected to the remote host's port
    links = getlinks(remotehostname, remotehwswitchname)
    if links == None or len(links) == 0:
        print "No links from",remotehostname,"to",remotehwswitchname
        return False
    hostlink = None
    for link in links:
        (node,port) = linkednode (link, remotehwswitchname)
        if port != None and port == remotehostport:
            # found the link
            hostlink = link
            break

    (node,remotehwport_tohost) = linkednode ( hostlink,remotehostname)

    connectremoteplane(switch = remotehwswitch,
                       host = host,
                       hostvlan = hostvlan,
                       remotehost_port = remotehwport_tohost,
                       remotehost = remotehost,
                       remotehost_vlan = remotehostvlan,
                       remotehwport_tocore =remotehwport_tocore,
                       corevlan = corevlan,
                       gri = gri,
                       meter = meter,
                       host_rewitemac = host_rewitemac)

    return True