def running_config_router_interface_details(config, vr_interface, indent=0):
    """
    Display the details for the fields of a router interface which may have
    non-default values.
    """
    if 'vns-connected' in vr_interface and vr_interface['vns-connected'] is not None:
        vns=vr_interface['vns-connected'].split('|')
        vns_name=vns[1]
        config.append(' ' *2*indent + 'interface %s vns %s \n' % (vr_interface['vriname'],vns_name))
    elif 'router-connected' in vr_interface and vr_interface['router-connected'] is not None:
            router=vr_interface['router-connected'].split('|')
            tenant_name=router[0]
            router_name=router[1]
            config.append(' ' *2*indent +'interface %s tenant %s %s \n' % (vr_interface['vriname'],tenant_name, router_name))

    if vr_interface['active'] != mi.field_default_value('virtualrouter-interface', 'active'):
        config.append(' ' *2*(indent+1) + 'no active\n')

    vri_fields = ['origin']

    for field in sorted(vri_fields):
        running_config_include_field(config,
                                     'virtualrouter-interface', field,
                                     vr_interface.get(field,''), indent+1)
    try:
        ip_address_pool = sdnsh.get_table_from_store('interface-address-pool','virtual-router-interface', vr_interface['id'], "exact")
    except Exception:
        ip_address_pool = {}
        pass
    for ip_address in ip_address_pool:
        config.append(' ' *2*(indent+1) + 'ip %s\n' % (utif.ip_and_neg_mask(ip_address['ip-address'],ip_address['subnet-mask'])))
def running_config_router_rule_details(config, vr_route,indent=0):
    """
    Display the details for the fields of a router interface which may have
    non-default values.
    """
    config_str=' ' * 2*indent
    if 'src-tenant' in vr_route and vr_route['src-tenant'] is not None:
        config_str+=('route from tenant %s' % vr_route['src-tenant'])
        if 'src-vns' in vr_route and vr_route['src-vns'] is not None:
            vns=vr_route['src-vns'].split('|')
            vns_name=vns[1]
            config_str+=(' vns %s' % vns_name)
    else:
        if 'src-ip' in vr_route and vr_route['src-ip'] is not None:
            config_str+=('route from %s' % (utif.ip_and_neg_mask(vr_route['src-ip'],vr_route['src-ip-mask'])))
        else:
            config_str+=('route from any')

    config_str+=(' to')

    if 'dst-tenant' in vr_route and vr_route['dst-tenant'] is not None:
        config_str+=(' tenant %s' % vr_route['dst-tenant'])
        if 'dst-vns' in vr_route and vr_route['dst-vns'] is not None:
            vns=vr_route['dst-vns'].split('|')
            vns_name=vns[1]
            config_str+=(' vns %s' % vns_name)
    else:
        if 'dst-ip' in vr_route and vr_route['dst-ip'] is not None:
            config_str+=(' %s' % (utif.ip_and_neg_mask(vr_route['dst-ip'],vr_route['dst-ip-mask'])))
        else:
            config_str+=(' any')

    if 'nh-ip' in vr_route and vr_route['nh-ip'] is not None:
        config_str+=(' %s' % vr_route['nh-ip'])
    if 'gateway-pool' in vr_route and vr_route['gateway-pool'] is not None:
        gwpool= vr_route['gateway-pool'].split('|')
        gwpool_name=gwpool[-1]
        config_str+=(' gw-pool %s' % gwpool_name)
    if 'outgoing-intf' in vr_route and vr_route['outgoing-intf'] is not None:
        intf= vr_route['outgoing-intf'].split('|')
        intf_name=intf[-1]
        config_str+=(' %s' % intf_name)

    config_str+=(' %s\n' % vr_route['action'])
    config.append(config_str)
Exemplo n.º 3
0
def realtime_flow_brief(i, data=None):
    brief = []
    wildcard = data['wildcards']
    # wild = print_mask_enum_string_and_int(wildcards, wildcard)
    try:
        i = int(wildcard)
    except:
        return ''

    if not wildcard & 0x1:
        brief.append('rx=%s' % decode_openflow_port(data['inputPort'], data))
    if (not wildcard & 0x2) and (data['dataLayerVirtualLan'] != -1):
        brief.append('vlan:%s' % data['dataLayerVirtualLan'])
    if (not wildcard & 0x4) and (data['dataLayerVirtualLanPriorityCodePoint']
                                 != '*'):
        brief.append('pri:%s' % data['dataLayerVirtualLanPriorityCodePoint'])
    if (not wildcard & 0x8) and (data['dataLayerType'] != '*'):
        brief.append('eth:%s' % data['dataLayerType'])
    if not wildcard & 0x10:
        brief.append('tos:%s' % data['networkTypeOfService'])
    if not wildcard & 0x20:
        brief.append('ip:%s' % data['networkProtocol'])
    if data['networkSourceMaskLen']:
        brief.append('src:%s' % utif.ip_and_neg_mask(
            data['networkSource'], data['networkSourceMaskLen']))
    if not wildcard & 0x40:
        brief.append('sport:%s' % data['transportSource'])
    if data['networkSourceMaskLen']:
        brief.append('src:%s' % utif.ip_and_neg_mask(
            data['networkSource'], data['networkSourceMaskLen']))
    if not wildcard & 0x80:
        brief.append('dport:%s' % data['transportDestination'])
    # mpls not in OF1.0
    #if not wildcard & 0x100:
    #brief.append('mpls: ?')
    #if not wildcard & 0x200:
    #brief.append('mpls-tc: ?')

    return ', '.join(brief)
Exemplo n.º 4
0
def realtime_flow_brief(i, data=None):
    brief = []
    wildcard = data['wildcards']
    # wild = print_mask_enum_string_and_int(wildcards, wildcard)
    try:
        i = int(wildcard)
    except:
        return ''

    if not wildcard & 0x1:
        brief.append('rx=%s' % decode_openflow_port(data['inputPort'], data))
    if (not wildcard & 0x2) and (data['dataLayerVirtualLan'] != -1):
        brief.append('vlan:%s' % data['dataLayerVirtualLan'])
    if (not wildcard & 0x4) and (data['dataLayerVirtualLanPriorityCodePoint'] != '*'):
        brief.append('pri:%s' % data['dataLayerVirtualLanPriorityCodePoint'])
    if (not wildcard & 0x8) and (data['dataLayerType'] != '*') :
        brief.append('eth:%s' % data['dataLayerType'])
    if not wildcard & 0x10:
        brief.append('tos:%s' % data['networkTypeOfService'])
    if not wildcard & 0x20:
        brief.append('ip:%s' % data['networkProtocol'])
    if data['networkSourceMaskLen']:
        brief.append('src:%s' % utif.ip_and_neg_mask(data['networkSource'],
                                                  data['networkSourceMaskLen']))
    if not wildcard & 0x40:
        brief.append('sport:%s' % data['transportSource'])
    if data['networkSourceMaskLen']:
        brief.append('src:%s' % utif.ip_and_neg_mask(data['networkSource'],
                                                  data['networkSourceMaskLen']))
    if not wildcard & 0x80:
        brief.append('dport:%s' % data['transportDestination'])
    # mpls not in OF1.0
    #if not wildcard & 0x100:
        #brief.append('mpls: ?')
    #if not wildcard & 0x200:
        #brief.append('mpls-tc: ?')

    return ', '.join(brief)
def vns_acl_entry_to_text(acl):
    """
    Return a short string for a specific acl entry.  Used for both short acl display
    formats (vns-access-list-entry within a vns subconfig mode), and for show running config
    """
    if acl['type'] in ['tcp', 'udp']:
        if not acl.get('src-ip') or not acl.get('src-ip-mask'):
            return '[broken src ip or mask (a) ]'
        if not acl.get('dst-ip') or not acl.get('dst-ip-mask'):
            return '[broken src ip or mask (b) ]'
        return "%s%s%s%s" % (utif.ip_and_neg_mask(acl['src-ip'],
                                                  acl['src-ip-mask']),
                             port_ntoa(acl.get('src-tp-port-op', ''),
                                       acl.get('src-tp-port', '')),
                             utif.ip_and_neg_mask(acl['dst-ip'],
                                                  acl['dst-ip-mask']),
                             port_ntoa(acl.get('dst-tp-port-op', ''),
                                       acl.get('dst-tp-port', '')))
    elif acl['type'] == 'ip' or DIGITS_RE.match(acl['type']):
        if not acl.get('src-ip') or not acl.get('src-ip-mask'):
            return '[broken src ip or mask (c)]'
        if not acl.get('dst-ip') or not acl.get('dst-ip-mask'):
            return '[broken src ip or mask (d)]'
        return "%s%s" % (utif.ip_and_neg_mask(acl['src-ip'],
                                              acl['src-ip-mask']),
                         utif.ip_and_neg_mask(acl['dst-ip'],
                                              acl['dst-ip-mask']))
    elif acl['type'] == 'icmp':
        if not acl.get('src-ip') or not acl.get('src-ip-mask'):
            return '[broken src ip or mask (e)]'
        if not acl.get('dst-ip') or not acl.get('dst-ip-mask'):
            return '[broken src ip or mask (f)]'
        return "%s%s%s" % (utif.ip_and_neg_mask(acl['src-ip'],
                                                acl['src-ip-mask']),
                           utif.ip_and_neg_mask(acl['dst-ip'],
                                                acl['dst-ip-mask']),
                                                 acl.get('icmp-type', ""))
    elif acl['type'] == 'mac':
        if 'vlan' in acl and acl['vlan'] != None and acl['vlan'] != '':
            if 'ether-type' in acl and\
               acl['ether-type'] != None and acl['ether-type'] != '':
                return "%s %s %s vlan %s" % (acl.get('src-mac', 'any'),
                                             acl.get('dst-mac', 'any'),
                                             acl.get('ether-type'),
                                             acl['vlan'])
            else:
                return "%s %s vlan %s" % (acl.get('src-mac', 'any'),
                                          acl.get('dst-mac', 'any'),
                                          acl['vlan'])
        else:
            return "%s %s %s" % (acl.get('src-mac', 'any'),
                                 acl.get('dst-mac', 'any'),
                                 acl.get('ether-type', ''))
    else:
        return '[unrecognized acl format]'
Exemplo n.º 6
0
def vns_acl_entry_to_text(acl):
    """
    Return a short string for a specific acl entry.  Used for both short acl display
    formats (vns-access-list-entry within a vns subconfig mode), and for show running config
    """
    if acl['type'] in ['tcp', 'udp']:
        if not acl.get('src-ip') or not acl.get('src-ip-mask'):
            return '[broken src ip or mask (a) ]'
        if not acl.get('dst-ip') or not acl.get('dst-ip-mask'):
            return '[broken src ip or mask (b) ]'
        return "%s%s%s%s" % (
            utif.ip_and_neg_mask(acl['src-ip'], acl['src-ip-mask']),
            port_ntoa(acl.get('src-tp-port-op', ''), acl.get(
                'src-tp-port',
                '')), utif.ip_and_neg_mask(acl['dst-ip'], acl['dst-ip-mask']),
            port_ntoa(acl.get('dst-tp-port-op', ''), acl.get(
                'dst-tp-port', '')))
    elif acl['type'] == 'ip' or DIGITS_RE.match(acl['type']):
        if not acl.get('src-ip') or not acl.get('src-ip-mask'):
            return '[broken src ip or mask (c)]'
        if not acl.get('dst-ip') or not acl.get('dst-ip-mask'):
            return '[broken src ip or mask (d)]'
        return "%s%s" % (
            utif.ip_and_neg_mask(acl['src-ip'], acl['src-ip-mask']),
            utif.ip_and_neg_mask(acl['dst-ip'], acl['dst-ip-mask']))
    elif acl['type'] == 'icmp':
        if not acl.get('src-ip') or not acl.get('src-ip-mask'):
            return '[broken src ip or mask (e)]'
        if not acl.get('dst-ip') or not acl.get('dst-ip-mask'):
            return '[broken src ip or mask (f)]'
        return "%s%s%s" % (
            utif.ip_and_neg_mask(acl['src-ip'], acl['src-ip-mask']),
            utif.ip_and_neg_mask(acl['dst-ip'],
                                 acl['dst-ip-mask']), acl.get('icmp-type', ""))
    elif acl['type'] == 'mac':
        if 'vlan' in acl and acl['vlan'] != None and acl['vlan'] != '':
            if 'ether-type' in acl and\
               acl['ether-type'] != None and acl['ether-type'] != '':
                return "%s %s %s vlan %s" % (acl.get(
                    'src-mac', 'any'), acl.get(
                        'dst-mac', 'any'), acl.get('ether-type'), acl['vlan'])
            else:
                return "%s %s vlan %s" % (acl.get(
                    'src-mac', 'any'), acl.get('dst-mac', 'any'), acl['vlan'])
        else:
            return "%s %s %s" % (acl.get(
                'src-mac', 'any'), acl.get('dst-mac',
                                           'any'), acl.get('ether-type', ''))
    else:
        return '[unrecognized acl format]'