예제 #1
0
 def get_ipport(hop, rt, uc):
     '''
     input: a list of ip string at this hop (step)
     output: a list of L3 port object at this hop (step)
     '''
     if len(hop) > 1:
         return [get_ipport([ip_str], self.unisrt, meta_obj.currentclient) for ip_str in hop]
     
     hop = hop[0]
         
     if hop == '*':
         return None
     elif hop in self.unisrt.ipports['existing']:
         return self.unisrt.ipports['existing'][hop]
     else:
         # not been posted to unis yet, still in ['new'], no selfRef, L2 port node info etc.
         l3 = ipport({
                      'address': {
                                  'type': 'ipv4',
                                  'address': hop
                                  }
                      },
                     rt,
                     uc,
                     True)
         return l3
예제 #2
0
def buildIPresolver(unisrt, tree):
    '''
    return a dictionary that maps an IP to an L2 port
    '''
    ip_resolver = {}
    for node, ports in tree.iteritems():
        for port, port_conf in ports.iteritems():
            if "unit" not in port_conf:
                continue
            for unit_conf in port_conf["unit"].itervalues():
                try:
                    for ip in unit_conf["family"]["inet"]["address"].iterkeys():
                        ip_resolver[ip[:-3]] = node
                        # don't upload ipport at this moment (even though I don't do it, unisencoder+esnetrspec already done it)
                        # these rules to compose UNIS refs are so artificial
                        # don't use 'ip' list of ports, because they may not exist in the topo
                        models.ipport({'address': {
                                        'address': ip[:-3],
                                        'type': 'ipv4'
                                   },
                                   'relations': {
                                        'over': [{'href': unisrt.unis_url + '/ports/' + node + '_port_' + port.replace('/', '_')}]
                                   },
                                   'node': unisrt.unis_url + '/nodes/' + node
                                   }, unisrt, False)
                except (KeyError, TypeError):
                    continue
                    
    # Okay, now let's build ip_resolver for ESnet. Really should just use ipport dictionary...
    tmp = {}
    for k, v in unisrt.ipports['existing'].iteritems():
        if k in ip_resolver:
            continue
        try:
            tmp[k] = v.node.id
        except:
            tmp[k] = v.node
    ip_resolver.update(tmp)
        
    return ip_resolver