Пример #1
0
def rib_route_remove(dev, channel_id, **kwargs):
    """
    delete already added static routes using execute_prpd_api.
    ** ONLY THE ROUTES ADDED BY A UNIQUE client_id CAN BE REMOVED
    """
    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    if 'table' in kwargs:
        table = kwargs.get('table')

    if 'prefix_len' in kwargs:
        prefix_len = kwargs.get('prefix_len')

    result = []
    for i in dest_prefix_iterator:
        dest_prefix = i

        rtkeys = []

        for index in range(0, len(dest_prefix)):
            #Building the Key for RIB Route Params

            if 'inet6' in table:
                destprefix = prpd.NetworkAddress(inet6=prpd.IpAddress(
                    addr_string=dest_prefix[index]))
            else:
                if 'mpls' in table:
                    destprefix = prpd.NetworkAddress(mpls=prpd.MplsAddress(
                        label=int(dest_prefix[index])))
                else:
                    destprefix = prpd.NetworkAddress(inet=prpd.IpAddress(
                        addr_string=dest_prefix[index]))

            tablename = prpd.RouteTable(name=prpd.RouteTableName(name=table))

            route_match_field = prpd.RouteMatch(dest_prefix=destprefix,
                                                dest_prefix_len=prefix_len,
                                                table=tablename)

            if 'cookie' in kwargs:
                if isinstance(kwargs["cookie"], int):
                    route_match_field.cookie = kwargs.get('cookie')

            rtkeys.append(route_match_field)

        remreq = prpd.RouteDeleteRequest(keys=rtkeys)
        result.append(
            prpd.process_api(dev, channel_id, "RouteDelete",
                             [remreq, "jnx_Rib"], kwargs.get("timeout", None)))

    return result
Пример #2
0
def rib_route_add(dev, channel_id, **kwargs):
    """
    Add static routes
    """

    result = []
    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    for i in dest_prefix_iterator:
        kwargs["dest_prefix"] = i

        updreq = rib_generate_update_req(**kwargs)
        result.append(prpd.process_api(dev, channel_id, "RouteAdd", [updreq, "Rib"], kwargs.get("timeout", None)))

    return  result
Пример #3
0
def rib_route_update(dev, channel_id, **kwargs):
    """
    Update attributes in already added static routes
    add new route if the route is not present already
    """
    result = []
    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    for i in dest_prefix_iterator:
        kwargs["dest_prefix"] = i

        updreq = rib_generate_update_req(**kwargs)

        result.append(prpd.process_api(dev, channel_id, "RouteUpdate", [updreq, "Rib"], kwargs.get("timeout", None)))


    return  result
Пример #4
0
def rib_route_modify(dev, channel_id, **kwargs):
    """
    Modify attributes in already added static routes
    """
    result = []
    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    for i in dest_prefix_iterator:
        kwargs["dest_prefix"] = i

        updreq = rib_generate_update_req(**kwargs)

        result.append(
            prpd.process_api(dev, channel_id, "RouteModify",
                             [updreq, "jnx_Rib"], kwargs.get("timeout", None)))

    return result
Пример #5
0
def bgp_route_get(dev, channel_id, **kwargs):
    """
    Get programmed bgp routes or the routes advertised by any bgp peers
    """

    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    for i in dest_prefix_iterator:

        if isinstance(kwargs["dest_prefix"], dict):
            dpref_attr = copy.deepcopy(kwargs["dest_prefix"])
            dpref_attr.pop('dest_prefix')
            kwargs["dpref_attr"] = copy.deepcopy(dpref_attr)
        kwargs["dest_prefix"] = i

        getreq = bgp_generate_get_req(**kwargs)
        getres = prpd.process_api(dev, channel_id, "RouteGet",
                                  [getreq, "jnx_Bgp"])

    return getres
Пример #6
0
def bgp_route_remove(dev, channel_id, **kwargs):
    """
    Remove already added bgp routes.Routes added by a client can be deleted only by same client.
    """

    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)
    remresult = []
    for i in dest_prefix_iterator:
        if isinstance(kwargs["dest_prefix"], dict):
            dpref_attr = copy.deepcopy(kwargs["dest_prefix"])
            dpref_attr.pop('dest_prefix')
            kwargs["dpref_attr"] = copy.deepcopy(dpref_attr)
        kwargs["dest_prefix"] = i

        remreq = bgp_generate_remove_req(**kwargs)

        remres = prpd.process_api(dev, channel_id, "RouteDelete",
                                  [remreq, "jnx_Bgp"])
        remresult.append(remres)
    return remresult
Пример #7
0
def bgp_route_add(dev, channel_id, **kwargs):
    """
    Add BGP Routes
    """

    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    addresult = []
    for i in dest_prefix_iterator:
        if isinstance(kwargs["dest_prefix"], dict):
            dpref_attr = copy.deepcopy(kwargs["dest_prefix"])
            dpref_attr.pop('dest_prefix')
            kwargs["dpref_attr"] = copy.deepcopy(dpref_attr)

        kwargs["dest_prefix"] = i

        updreq = bgp_generate_update_req(**kwargs)
        addres = prpd.process_api(dev, channel_id, "RouteAdd",
                                  [updreq, "jnx_Bgp"])
        addresult.append(addres)
    return addresult
Пример #8
0
def bgp_route_update(dev, channel_id, **kwargs):
    """
    Update attributes of already added bgp routes.BGP routes added by a client can be updated by same client.
    If route is not present, new route will get added.
    """

    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)
    updresult = []
    for i in dest_prefix_iterator:
        if isinstance(kwargs["dest_prefix"], dict):
            dpref_attr = copy.deepcopy(kwargs["dest_prefix"])
            dpref_attr.pop('dest_prefix')
            kwargs["dpref_attr"] = copy.deepcopy(dpref_attr)

        kwargs["dest_prefix"] = i

        updreq = bgp_generate_update_req(**kwargs)

        updres = prpd.process_api(dev, channel_id, "RouteUpdate",
                                  [updreq, "jnx_Bgp"])
        updresult.append(updres)

    return updresult
Пример #9
0
def bgp_route_modify(dev, channel_id, **kwargs):
    """
    Modify attributes of already added bgp routes.
    BGP routes added by a client can be modified only by same client.
    """

    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)
    modresult = []
    for i in dest_prefix_iterator:
        if isinstance(kwargs["dest_prefix"], dict):
            dpref_attr = copy.deepcopy(kwargs["dest_prefix"])
            dpref_attr.pop('dest_prefix')
            kwargs["dpref_attr"] = copy.deepcopy(dpref_attr)

        kwargs["dest_prefix"] = i

        updreq = bgp_generate_update_req(**kwargs)

        modres = prpd.process_api(dev, channel_id, "RouteModify",
                                  [updreq, "jnx_Bgp"])
        modresult.append(modres)

    return modresult
Пример #10
0
def rib_route_get(dev, channel_id, **kwargs):
    """
    To fetch routes present in the rib
    """

    # To handle same variable name across rib and bgp for destination_prefix,prefix_length
    dest_prefix_iterator = prpd.dest_prefix_limiter(**kwargs)

    if 'table' in kwargs:
        table = kwargs.get('table')

    else:
        raise Exception("Mandatory parameter 'table' absent")


    if 'prefix_len' in kwargs:

        if isinstance(kwargs["prefix_len"], int):
            prefix_len = kwargs.get('prefix_len')
            if 'inet6' in table:
                if prefix_len > 128:
                    raise Exception("Prefix length should be <= 128 for inet6")
            else:
                if prefix_len > 32:
                    raise Exception("Prefix length should be <= 32 for inet")
        else:
            raise Exception("Please enter integer value for prefix_len")

    else:
        raise Exception("Mandatory parameter 'prefix_len' absent")


    count = kwargs.get('route_count', 1000)


    if 'dest_prefix' in kwargs:
        dest_prefix = kwargs.get('dest_prefix')
    else:
        raise Exception("Mandatory parameter 'destination_prefix' absent")

    route_match_type = kwargs.get('route_match_type', prpd.BEST)


    if 'inet6' in table:
        destprefix = prpd.NetworkAddress(inet6=prpd.IpAddress(addr_string=dest_prefix))
    else:
        destprefix = prpd.NetworkAddress(inet=prpd.IpAddress(addr_string=dest_prefix))

    tablename = prpd.RouteTable(rtt_name=prpd.RouteTableName(name=table))

    route_match_field = prpd.RouteMatchFields(dest_prefix=destprefix, dest_prefix_len=prefix_len, table=tablename)


    if 'cookie' in kwargs:
        route_match_field.cookie = kwargs.get('cookie')

    #Defining the RouteGetRequest Structure
    getreq = prpd.RouteGetRequest(key=route_match_field, match_type=route_match_type, route_count=count)

    if 'active_routes' in kwargs:
        if kwargs['active_routes'].upper() == 'TRUE':
            getreq.active_only = True

    if 'tags0' in kwargs or 'tags1' in kwargs:
        rtattr = prpd.RouteExtendedMatchFields()

        if 'tags0' in kwargs:
            rtattr.tags[0].CopyFrom(route_attribute(kwargs.get('tags0')))

        if 'tags1' in kwargs:
            rtattr.tags[1].CopyFrom(route_attribute(kwargs.get('tags1')))

        getreq.extended_match.CopyFrom(rtattr)

    getreply = prpd.process_api(dev, channel_id, "RouteGet", [getreq, "Rib"], kwargs.get("timeout", None))


    return  getreply