]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_vty.c
Merge pull request #12248 from pguibert6WIND/bgpasdot
[mirror_frr.git] / bgpd / bgp_vty.c
index b858d9c4b49d93ac4ad23e4857688d7b2161e25f..8ef18a34d035d3719cdffb8c7a01b035cd0347c3 100644 (file)
@@ -24,6 +24,7 @@
 #include "queue.h"
 #include "filter.h"
 #include "frrstr.h"
+#include "asn.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_attr_evpn.h"
@@ -579,9 +580,10 @@ static const char *get_bgp_default_af_flag(afi_t afi, safi_t safi)
 }
 
 int bgp_get_vty(struct bgp **bgp, as_t *as, const char *name,
-               enum bgp_instance_type inst_type)
+               enum bgp_instance_type inst_type, const char *as_pretty,
+               enum asnotation_mode asnotation)
 {
-       int ret = bgp_get(bgp, as, name, inst_type);
+       int ret = bgp_get(bgp, as, name, inst_type, as_pretty, asnotation);
 
        if (ret == BGP_CREATED) {
                bgp_timers_set(*bgp, DFLT_BGP_KEEPALIVE, DFLT_BGP_HOLDTIME,
@@ -1222,7 +1224,12 @@ static int bgp_clear(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
 
        /* Clear all neighbors belonging to a specific AS. */
        if (sort == clear_as) {
-               as_t as = strtoul(arg, NULL, 10);
+               as_t as;
+
+               if (!asn_str2asn(arg, &as)) {
+                       vty_out(vty, "%% BGP: No such AS %s\n", arg);
+                       return CMD_WARNING;
+               }
 
                for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
                        if (peer->as != as)
@@ -1460,16 +1467,23 @@ DEFUN (no_auto_summary,
 /* "router bgp" commands. */
 DEFUN_NOSH (router_bgp,
        router_bgp_cmd,
-       "router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
+       "router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
        ROUTER_STR
        BGP_STR
        AS_STR
-       BGP_INSTANCE_HELP_STR)
+       BGP_INSTANCE_HELP_STR
+       "Force the AS notation output\n"
+       "use 'AA.BB' format for AS 4 byte values\n"
+       "use 'AA.BB' format for all AS values\n"
+       "use plain format for all AS values\n")
 {
        int idx_asn = 2;
        int idx_view_vrf = 3;
        int idx_vrf = 4;
        int is_new_bgp = 0;
+       int idx_asnotation = 3;
+       int idx_asnotation_kind = 4;
+       enum asnotation_mode asnotation = ASNOTATION_UNDEFINED;
        int ret;
        as_t as;
        struct bgp *bgp;
@@ -1494,39 +1508,62 @@ DEFUN_NOSH (router_bgp,
 
        // "router bgp X"
        else {
-               as = strtoul(argv[idx_asn]->arg, NULL, 10);
+               if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
+                       vty_out(vty, "%% BGP: No such AS %s\n",
+                               argv[idx_asn]->arg);
+                       return CMD_WARNING_CONFIG_FAILED;
+               }
 
                if (as == BGP_PRIVATE_AS_MAX || as == BGP_AS4_MAX)
                        vty_out(vty, "Reserved AS used (%u|%u); AS is %u\n",
                                BGP_PRIVATE_AS_MAX, BGP_AS4_MAX, as);
 
                inst_type = BGP_INSTANCE_TYPE_DEFAULT;
-               if (argc > 3) {
-                       name = argv[idx_vrf]->arg;
 
-                       if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
-                               if (strmatch(name, VRF_DEFAULT_NAME))
-                                       name = NULL;
-                               else
-                                       inst_type = BGP_INSTANCE_TYPE_VRF;
-                       } else if (!strcmp(argv[idx_view_vrf]->text, "view"))
-                               inst_type = BGP_INSTANCE_TYPE_VIEW;
+               if (argv_find(argv, argc, "VIEWVRFNAME", &idx_vrf)) {
+                       idx_view_vrf = idx_vrf - 1;
+                       if (argv[idx_view_vrf]->text) {
+                               name = argv[idx_vrf]->arg;
+
+                               if (!strcmp(argv[idx_view_vrf]->text, "vrf")) {
+                                       if (strmatch(name, VRF_DEFAULT_NAME))
+                                               name = NULL;
+                                       else
+                                               inst_type =
+                                                       BGP_INSTANCE_TYPE_VRF;
+                               } else if (!strcmp(argv[idx_view_vrf]->text,
+                                                  "view"))
+                                       inst_type = BGP_INSTANCE_TYPE_VIEW;
+                       }
+               }
+               if (argv_find(argv, argc, "as-notation", &idx_asnotation)) {
+                       idx_asnotation_kind = idx_asnotation + 1;
+                       if (strmatch(argv[idx_asnotation_kind]->text, "dot+"))
+                               asnotation = ASNOTATION_DOTPLUS;
+                       else if (strmatch(argv[idx_asnotation_kind]->text,
+                                         "dot"))
+                               asnotation = ASNOTATION_DOT;
+                       else if (strmatch(argv[idx_asnotation_kind]->text,
+                                         "plain"))
+                               asnotation = ASNOTATION_PLAIN;
                }
 
                if (inst_type == BGP_INSTANCE_TYPE_DEFAULT)
                        is_new_bgp = (bgp_lookup(as, name) == NULL);
 
-               ret = bgp_get_vty(&bgp, &as, name, inst_type);
+               ret = bgp_get_vty(&bgp, &as, name, inst_type,
+                                 argv[idx_asn]->arg, asnotation);
                switch (ret) {
                case BGP_ERR_AS_MISMATCH:
-                       vty_out(vty, "BGP is already running; AS is %u\n", as);
+                       vty_out(vty, "BGP is already running; AS is %s\n",
+                               bgp->as_pretty);
                        return CMD_WARNING_CONFIG_FAILED;
                case BGP_ERR_INSTANCE_MISMATCH:
                        vty_out(vty,
                                "BGP instance name and AS number mismatch\n");
                        vty_out(vty,
-                               "BGP instance is already running; AS is %u\n",
-                               as);
+                               "BGP instance is already running; AS is %s\n",
+                               bgp->as_pretty);
                        return CMD_WARNING_CONFIG_FAILED;
                }
 
@@ -1542,6 +1579,19 @@ DEFUN_NOSH (router_bgp,
                        bgp_vpn_leak_export(bgp);
                /* Pending: handle when user tries to change a view to vrf n vv.
                 */
+               /* for pre-existing bgp instance,
+                * - update as_pretty
+                * - update asnotation if explicitly mentioned
+                */
+               if (CHECK_FLAG(bgp->vrf_flags, BGP_VRF_AUTO)) {
+                       XFREE(MTYPE_BGP, bgp->as_pretty);
+                       bgp->as_pretty = XSTRDUP(MTYPE_BGP, argv[idx_asn]->arg);
+                       if (!CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION) &&
+                           asnotation != ASNOTATION_UNDEFINED) {
+                               SET_FLAG(bgp->config, BGP_CONFIG_ASNOTATION);
+                               bgp->asnotation = asnotation;
+                       }
+               }
        }
 
        /* unset the auto created flag as the user config is now present */
@@ -1554,12 +1604,16 @@ DEFUN_NOSH (router_bgp,
 /* "no router bgp" commands. */
 DEFUN (no_router_bgp,
        no_router_bgp_cmd,
-       "no router bgp [(1-4294967295)$instasn [<view|vrf> VIEWVRFNAME]]",
+       "no router bgp [ASNUM$instasn [<view|vrf> VIEWVRFNAME] [as-notation <dot|dot+|plain>]]",
        NO_STR
        ROUTER_STR
        BGP_STR
        AS_STR
-       BGP_INSTANCE_HELP_STR)
+       BGP_INSTANCE_HELP_STR
+       "Force the AS notation output\n"
+       "use 'AA.BB' format for AS 4 byte values\n"
+       "use 'AA.BB' format for all AS values\n"
+       "use plain format for all AS values\n")
 {
        int idx_asn = 3;
        int idx_vrf = 5;
@@ -1588,8 +1642,11 @@ DEFUN (no_router_bgp,
                        return CMD_WARNING_CONFIG_FAILED;
                }
        } else {
-               as = strtoul(argv[idx_asn]->arg, NULL, 10);
-
+               if (!asn_str2asn(argv[idx_asn]->arg, &as)) {
+                       vty_out(vty, "%% BGP: No such AS %s\n",
+                               argv[idx_asn]->arg);
+                       return CMD_WARNING_CONFIG_FAILED;
+               }
                if (argc > 4) {
                        name = argv[idx_vrf]->arg;
                        if (strmatch(argv[idx_vrf - 1]->text, "vrf")
@@ -1821,7 +1878,6 @@ DEFPY (bgp_suppress_fib_pending,
        return CMD_SUCCESS;
 }
 
-
 /* BGP Cluster ID.  */
 DEFUN (bgp_cluster_id,
        bgp_cluster_id_cmd,
@@ -1917,30 +1973,33 @@ DEFPY (no_bgp_send_extra_data,
 
 DEFUN (bgp_confederation_identifier,
        bgp_confederation_identifier_cmd,
-       "bgp confederation identifier (1-4294967295)",
+       "bgp confederation identifier ASNUM",
        BGP_STR
        "AS confederation parameters\n"
-       "AS number\n"
+       AS_STR
        "Set routing domain confederation AS\n")
 {
        VTY_DECLVAR_CONTEXT(bgp, bgp);
        int idx_number = 3;
        as_t as;
 
-       as = strtoul(argv[idx_number]->arg, NULL, 10);
+       if (!asn_str2asn(argv[idx_number]->arg, &as)) {
+               vty_out(vty, "%% BGP: No such AS %s\n", argv[idx_number]->arg);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
 
-       bgp_confederation_id_set(bgp, as);
+       bgp_confederation_id_set(bgp, as, argv[idx_number]->arg);
 
        return CMD_SUCCESS;
 }
 
 DEFUN (no_bgp_confederation_identifier,
        no_bgp_confederation_identifier_cmd,
-       "no bgp confederation identifier [(1-4294967295)]",
+       "no bgp confederation identifier [ASNUM]",
        NO_STR
        BGP_STR
        "AS confederation parameters\n"
-       "AS number\n"
+       AS_STR
        "Set routing domain confederation AS\n")
 {
        VTY_DECLVAR_CONTEXT(bgp, bgp);
@@ -1951,7 +2010,7 @@ DEFUN (no_bgp_confederation_identifier,
 
 DEFUN (bgp_confederation_peers,
        bgp_confederation_peers_cmd,
-       "bgp confederation peers (1-4294967295)...",
+       "bgp confederation peers ASNUM...",
        BGP_STR
        "AS confederation parameters\n"
        "Peer ASs in BGP confederation\n"
@@ -1963,15 +2022,20 @@ DEFUN (bgp_confederation_peers,
        int i;
 
        for (i = idx_asn; i < argc; i++) {
-               as = strtoul(argv[i]->arg, NULL, 10);
-               bgp_confederation_peers_add(bgp, as);
+               if (!asn_str2asn(argv[i]->arg, &as)) {
+                       vty_out(vty, "%% Invalid confed peer AS value: %s\n",
+                               argv[i]->arg);
+                       continue;
+               }
+
+               bgp_confederation_peers_add(bgp, as, argv[i]->arg);
        }
        return CMD_SUCCESS;
 }
 
 DEFUN (no_bgp_confederation_peers,
        no_bgp_confederation_peers_cmd,
-       "no bgp confederation peers (1-4294967295)...",
+       "no bgp confederation peers ASNUM...",
        NO_STR
        BGP_STR
        "AS confederation parameters\n"
@@ -1984,8 +2048,11 @@ DEFUN (no_bgp_confederation_peers,
        int i;
 
        for (i = idx_asn; i < argc; i++) {
-               as = strtoul(argv[i]->arg, NULL, 10);
-
+               if (!asn_str2asn(argv[i]->arg, &as)) {
+                       vty_out(vty, "%% Invalid confed peer AS value: %s\n",
+                               argv[i]->arg);
+                       continue;
+               }
                bgp_confederation_peers_remove(bgp, as);
        }
        return CMD_SUCCESS;
@@ -4489,11 +4556,13 @@ static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
        } else if (as_str[0] == 'e') {
                as = 0;
                as_type = AS_EXTERNAL;
-       } else {
-               /* Get AS number.  */
-               as = strtoul(as_str, NULL, 10);
-       }
+       } else if (!asn_str2asn(as_str, &as))
+               as_type = AS_UNSPECIFIED;
 
+       if (as_type == AS_UNSPECIFIED) {
+               vty_out(vty, "%% Invalid peer AS: %s\n", as_str);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
        /* If peer is peer group or interface peer, call proper function. */
        ret = str2sockunion(peer_str, &su);
        if (ret < 0) {
@@ -4502,11 +4571,12 @@ static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
                /* Check if existing interface peer */
                peer = peer_lookup_by_conf_if(bgp, peer_str);
 
-               ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type);
+               ret = peer_remote_as(bgp, NULL, peer_str, &as, as_type, as_str);
 
                /* if not interface peer, check peer-group settings */
                if (ret < 0 && !peer) {
-                       ret = peer_group_remote_as(bgp, peer_str, &as, as_type);
+                       ret = peer_group_remote_as(bgp, peer_str, &as, as_type,
+                                                  as_str);
                        if (ret < 0) {
                                vty_out(vty,
                                        "%% Create the peer-group or interface first\n");
@@ -4520,7 +4590,7 @@ static int peer_remote_as_vty(struct vty *vty, const char *peer_str,
                                "%% Can not configure the local system as neighbor\n");
                        return CMD_WARNING_CONFIG_FAILED;
                }
-               ret = peer_remote_as(bgp, &su, NULL, &as, as_type);
+               ret = peer_remote_as(bgp, &su, NULL, &as, as_type, as_str);
        }
 
        return bgp_vty_return(vty, ret);
@@ -4591,7 +4661,7 @@ ALIAS(no_bgp_shutdown, no_bgp_shutdown_msg_cmd,
 
 DEFUN (neighbor_remote_as,
        neighbor_remote_as_cmd,
-       "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <(1-4294967295)|internal|external>",
+       "neighbor <A.B.C.D|X:X::X:X|WORD> remote-as <ASNUM|internal|external>",
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a BGP neighbor\n"
@@ -4671,18 +4741,19 @@ static int peer_conf_interface_get(struct vty *vty, const char *conf_if,
                        as_type = AS_EXTERNAL;
                } else {
                        /* Get AS number.  */
-                       as = strtoul(as_str, NULL, 10);
-                       as_type = AS_SPECIFIED;
+                       if (asn_str2asn(as_str, &as))
+                               as_type = AS_SPECIFIED;
                }
        }
 
        peer = peer_lookup_by_conf_if(bgp, conf_if);
        if (peer) {
                if (as_str)
-                       ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type);
+                       ret = peer_remote_as(bgp, NULL, conf_if, &as, as_type,
+                                            as_str);
        } else {
                peer = peer_create(NULL, conf_if, bgp, bgp->as, as, as_type,
-                                  NULL, true);
+                                  NULL, true, as_str);
 
                if (!peer) {
                        vty_out(vty, "%% BGP failed to create peer\n");
@@ -4784,7 +4855,7 @@ DEFUN (neighbor_interface_config_v6only,
 
 DEFUN (neighbor_interface_config_remote_as,
        neighbor_interface_config_remote_as_cmd,
-       "neighbor WORD interface remote-as <(1-4294967295)|internal|external>",
+       "neighbor WORD interface remote-as <ASNUM|internal|external>",
        NEIGHBOR_STR
        "Interface name or neighbor tag\n"
        "Enable BGP on interface\n"
@@ -4801,7 +4872,7 @@ DEFUN (neighbor_interface_config_remote_as,
 
 DEFUN (neighbor_interface_v6only_config_remote_as,
        neighbor_interface_v6only_config_remote_as_cmd,
-       "neighbor WORD interface v6only remote-as <(1-4294967295)|internal|external>",
+       "neighbor WORD interface v6only remote-as <ASNUM|internal|external>",
        NEIGHBOR_STR
        "Interface name or neighbor tag\n"
        "Enable BGP with v6 link-local only\n"
@@ -4970,7 +5041,7 @@ DEFUN (no_neighbor_peer_group,
 
 DEFUN (no_neighbor_interface_peer_group_remote_as,
        no_neighbor_interface_peer_group_remote_as_cmd,
-       "no neighbor WORD remote-as <(1-4294967295)|internal|external>",
+       "no neighbor WORD remote-as <ASNUM|internal|external>",
        NO_STR
        NEIGHBOR_STR
        "Interface name or neighbor tag\n"
@@ -4987,7 +5058,7 @@ DEFUN (no_neighbor_interface_peer_group_remote_as,
        /* look up for neighbor by interface name config. */
        peer = peer_lookup_by_conf_if(bgp, argv[idx_word]->arg);
        if (peer) {
-               peer_as_change(peer, 0, AS_UNSPECIFIED);
+               peer_as_change(peer, 0, AS_UNSPECIFIED, NULL);
                return CMD_SUCCESS;
        }
 
@@ -5003,11 +5074,11 @@ DEFUN (no_neighbor_interface_peer_group_remote_as,
 
 DEFUN (neighbor_local_as,
        neighbor_local_as_cmd,
-       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295)",
+       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM",
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a local-as number\n"
-       "AS number used as local AS\n")
+       "AS number expressed in dotted or plain format used as local AS\n")
 {
        int idx_peer = 1;
        int idx_number = 3;
@@ -5019,18 +5090,23 @@ DEFUN (neighbor_local_as,
        if (!peer)
                return CMD_WARNING_CONFIG_FAILED;
 
-       as = strtoul(argv[idx_number]->arg, NULL, 10);
-       ret = peer_local_as_set(peer, as, 0, 0);
+       if (!asn_str2asn(argv[idx_number]->arg, &as)) {
+               vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
+                       argv[idx_number]->arg);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
+       ret = peer_local_as_set(peer, as, 0, 0, argv[idx_number]->arg);
        return bgp_vty_return(vty, ret);
 }
 
 DEFUN (neighbor_local_as_no_prepend,
        neighbor_local_as_no_prepend_cmd,
-       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend",
+       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend",
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a local-as number\n"
-       "AS number used as local AS\n"
+       "AS number expressed in dotted or plain format used as local AS\n"
        "Do not prepend local-as to updates from ebgp peers\n")
 {
        int idx_peer = 1;
@@ -5043,18 +5119,23 @@ DEFUN (neighbor_local_as_no_prepend,
        if (!peer)
                return CMD_WARNING_CONFIG_FAILED;
 
-       as = strtoul(argv[idx_number]->arg, NULL, 10);
-       ret = peer_local_as_set(peer, as, 1, 0);
+       if (!asn_str2asn(argv[idx_number]->arg, &as)) {
+               vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
+                       argv[idx_number]->arg);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
+       ret = peer_local_as_set(peer, as, 1, 0, argv[idx_number]->arg);
        return bgp_vty_return(vty, ret);
 }
 
 DEFUN (neighbor_local_as_no_prepend_replace_as,
        neighbor_local_as_no_prepend_replace_as_cmd,
-       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as (1-4294967295) no-prepend replace-as",
+       "neighbor <A.B.C.D|X:X::X:X|WORD> local-as ASNUM no-prepend replace-as",
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a local-as number\n"
-       "AS number used as local AS\n"
+       "AS number expressed in dotted or plain format used as local AS\n"
        "Do not prepend local-as to updates from ebgp peers\n"
        "Do not prepend local-as to updates from ibgp peers\n")
 {
@@ -5068,19 +5149,24 @@ DEFUN (neighbor_local_as_no_prepend_replace_as,
        if (!peer)
                return CMD_WARNING_CONFIG_FAILED;
 
-       as = strtoul(argv[idx_number]->arg, NULL, 10);
-       ret = peer_local_as_set(peer, as, 1, 1);
+       if (!asn_str2asn(argv[idx_number]->arg, &as)) {
+               vty_out(vty, "%% Invalid neighbor local-as value: %s\n",
+                       argv[idx_number]->arg);
+               return CMD_WARNING_CONFIG_FAILED;
+       }
+
+       ret = peer_local_as_set(peer, as, 1, 1, argv[idx_number]->arg);
        return bgp_vty_return(vty, ret);
 }
 
 DEFUN (no_neighbor_local_as,
        no_neighbor_local_as_cmd,
-       "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [(1-4294967295) [no-prepend [replace-as]]]",
+       "no neighbor <A.B.C.D|X:X::X:X|WORD> local-as [ASNUM [no-prepend [replace-as]]]",
        NO_STR
        NEIGHBOR_STR
        NEIGHBOR_ADDR_STR2
        "Specify a local-as number\n"
-       "AS number used as local AS\n"
+       "AS number expressed in dotted or plain format used as local AS\n"
        "Do not prepend local-as to updates from ebgp peers\n"
        "Do not prepend local-as to updates from ibgp peers\n")
 {
@@ -9020,10 +9106,13 @@ DEFPY (af_rd_vpn_export,
                           bgp_get_default(), bgp);
 
        if (yes) {
+               bgp->vpn_policy[afi].tovpn_rd_pretty =
+                       XSTRDUP(MTYPE_BGP, rd_str);
                bgp->vpn_policy[afi].tovpn_rd = prd;
                SET_FLAG(bgp->vpn_policy[afi].flags,
                         BGP_VPN_POLICY_TOVPN_RD_SET);
        } else {
+               XFREE(MTYPE_BGP, bgp->vpn_policy[afi].tovpn_rd_pretty);
                UNSET_FLAG(bgp->vpn_policy[afi].flags,
                           BGP_VPN_POLICY_TOVPN_RD_SET);
        }
@@ -9548,7 +9637,8 @@ DEFPY(af_import_vrf_route_map, af_import_vrf_route_map_cmd,
 
                /* Auto-create assuming the same AS */
                ret = bgp_get_vty(&bgp_default, &as, NULL,
-                                 BGP_INSTANCE_TYPE_DEFAULT);
+                                 BGP_INSTANCE_TYPE_DEFAULT, NULL,
+                                 ASNOTATION_UNDEFINED);
 
                if (ret) {
                        vty_out(vty,
@@ -9660,7 +9750,8 @@ DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
        if (!bgp_default) {
                /* Auto-create assuming the same AS */
                ret = bgp_get_vty(&bgp_default, &as, NULL,
-                                 BGP_INSTANCE_TYPE_DEFAULT);
+                                 BGP_INSTANCE_TYPE_DEFAULT, NULL,
+                                 ASNOTATION_UNDEFINED);
 
                if (ret) {
                        vty_out(vty,
@@ -9675,8 +9766,8 @@ DEFPY(bgp_imexport_vrf, bgp_imexport_vrf_cmd,
                        vrf_bgp = bgp_default;
                else
                        /* Auto-create assuming the same AS */
-                       ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type);
-
+                       ret = bgp_get_vty(&vrf_bgp, &as, import_name, bgp_type,
+                                         NULL, ASNOTATION_UNDEFINED);
                if (ret) {
                        vty_out(vty,
                                "VRF %s is not configured as a bgp instance\n",
@@ -10144,7 +10235,7 @@ static int bgp_clear_prefix(struct vty *vty, const char *view_name,
 /* one clear bgp command to rule them all */
 DEFUN (clear_ip_bgp_all,
        clear_ip_bgp_all_cmd,
-       "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|(1-4294967295)|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
+       "clear [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|l2vpn> [<unicast|multicast|vpn|labeled-unicast|flowspec|evpn>]] <*|A.B.C.D$neighbor|X:X::X:X$neighbor|WORD$neighbor|ASNUM|external|peer-group PGNAME> [<soft [<in|out>]|in [prefix-filter]|out|message-stats>]",
        CLEAR_STR
        IP_STR
        BGP_STR
@@ -10157,7 +10248,7 @@ DEFUN (clear_ip_bgp_all,
        "BGP IPv4 neighbor to clear\n"
        "BGP IPv6 neighbor to clear\n"
        "BGP neighbor on interface to clear\n"
-       "Clear peers with the AS number\n"
+       "Clear peers with the AS number in plain or dotted format\n"
        "Clear all external peers\n"
        "Clear all members of peer-group\n"
        "BGP peer-group name\n"
@@ -10198,7 +10289,7 @@ DEFUN (clear_ip_bgp_all,
        if (argv_find_and_parse_afi(argv, argc, &idx, &afi))
                argv_find_and_parse_safi(argv, argc, &idx, &safi);
 
-       /* <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group PGNAME> */
+       /* <*|A.B.C.D|X:X::X:X|WORD|ASNUM|external|peer-group PGNAME> */
        if (argv_find(argv, argc, "*", &idx)) {
                clr_sort = clear_all;
        } else if (argv_find(argv, argc, "A.B.C.D", &idx)) {
@@ -10217,7 +10308,7 @@ DEFUN (clear_ip_bgp_all,
        } else if (argv_find(argv, argc, "WORD", &idx)) {
                clr_sort = clear_peer;
                clr_arg = argv[idx]->arg;
-       } else if (argv_find(argv, argc, "(1-4294967295)", &idx)) {
+       } else if (argv_find(argv, argc, "ASNUM", &idx)) {
                clr_sort = clear_as;
                clr_arg = argv[idx]->arg;
        } else if (argv_find(argv, argc, "external", &idx)) {
@@ -10355,8 +10446,8 @@ DEFUN (show_bgp_views,
                /* Skip VRFs. */
                if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
                        continue;
-               vty_out(vty, "\t%s (AS%u)\n", bgp->name ? bgp->name : "(null)",
-                       bgp->as);
+               vty_out(vty, "\t%s (AS%s)\n", bgp->name ? bgp->name : "(null)",
+                       bgp->as_pretty);
        }
 
        return CMD_SUCCESS;
@@ -11142,7 +11233,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
                                json_object_string_addf(json, "routerId",
                                                        "%pI4",
                                                        &bgp->router_id);
-                               json_object_int_add(json, "as", bgp->as);
+                               asn_asn2json(json, "as", bgp->as,
+                                            bgp->asnotation);
                                json_object_int_add(json, "vrfId", vrf_id_ui);
                                json_object_string_add(
                                        json, "vrfName",
@@ -11152,8 +11244,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
                                                : bgp->name);
                        } else {
                                vty_out(vty,
-                                       "BGP router identifier %pI4, local AS number %u vrf-id %d",
-                                       &bgp->router_id, bgp->as,
+                                       "BGP router identifier %pI4, local AS number %s vrf-id %d",
+                                       &bgp->router_id, bgp->as_pretty,
                                        bgp->vrf_id == VRF_UNKNOWN
                                                ? -1
                                                : (int)bgp->vrf_id);
@@ -11387,12 +11479,13 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
                                        json_object_string_add(json_peer, "domainname",
                                                               peer->domainname);
 
-                               json_object_int_add(json_peer, "remoteAs", peer->as);
-                               json_object_int_add(
-                                       json_peer, "localAs",
-                                       peer->change_local_as
-                                               ? peer->change_local_as
-                                               : peer->local_as);
+                               asn_asn2json(json_peer, "remoteAs", peer->as,
+                                            bgp->asnotation);
+                               asn_asn2json(json_peer, "localAs",
+                                            peer->change_local_as
+                                                    ? peer->change_local_as
+                                                    : peer->local_as,
+                                            bgp->asnotation);
                                json_object_int_add(json_peer, "version", 4);
                                json_object_int_add(json_peer, "msgRcvd",
                                                    PEER_TOTAL_RX(peer));
@@ -11572,14 +11665,19 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
                                        &peer->ibuf->count,
                                        memory_order_relaxed);
 
-                               if (show_wide)
+                               vty_out(vty, "4 ");
+                               vty_out(vty, ASN_FORMAT_SPACE(bgp->asnotation),
+                                       &peer->as);
+                               if (show_wide) {
                                        vty_out(vty,
-                                               "4 %10u %10u %9u %9u %8" PRIu64
-                                               " %4zu %4zu %8s",
-                                               peer->as,
+                                               ASN_FORMAT_SPACE(
+                                                       bgp->asnotation),
                                                peer->change_local_as
-                                                       ? peer->change_local_as
-                                                       : peer->local_as,
+                                                       ? &peer->change_local_as
+                                                       : &peer->local_as);
+                                       vty_out(vty,
+                                               " %9u %9u %8" PRIu64
+                                               " %4zu %4zu %8s",
                                                PEER_TOTAL_RX(peer),
                                                PEER_TOTAL_TX(peer),
                                                peer->version[afi][safi],
@@ -11588,10 +11686,11 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
                                                            timebuf,
                                                            BGP_UPTIME_LEN, 0,
                                                            NULL));
-                               else
-                                       vty_out(vty, "4 %10u %9u %9u %8" PRIu64
-                                                    " %4zu %4zu %8s",
-                                               peer->as, PEER_TOTAL_RX(peer),
+                               } else {
+                                       vty_out(vty,
+                                               " %9u %9u %8" PRIu64
+                                               " %4zu %4zu %8s",
+                                               PEER_TOTAL_RX(peer),
                                                PEER_TOTAL_TX(peer),
                                                peer->version[afi][safi],
                                                inq_count, outq_count,
@@ -11599,7 +11698,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
                                                            timebuf,
                                                            BGP_UPTIME_LEN, 0,
                                                            NULL));
-
+                               }
                                if (peer_established(peer)) {
                                        if (peer->afc_recv[afi][safi]) {
                                                if (CHECK_FLAG(
@@ -11892,7 +11991,7 @@ int bgp_show_summary_vty(struct vty *vty, const char *name, afi_t afi,
 DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
       "show [ip] bgp [<view|vrf> VIEWVRFNAME] [" BGP_AFI_CMD_STR
       " [" BGP_SAFI_WITH_LABEL_CMD_STR
-      "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <(1-4294967295)|internal|external>>] [terse] [wide] [json$uj]",
+      "]] [all$all] summary [established|failed] [<neighbor <A.B.C.D|X:X::X:X|WORD>|remote-as <ASNUM|internal|external>>] [terse] [wide] [json$uj]",
       SHOW_STR IP_STR BGP_STR BGP_INSTANCE_HELP_STR BGP_AFI_HELP_STR
              BGP_SAFI_WITH_LABEL_HELP_STR
       "Display the entries for all address families\n"
@@ -11903,8 +12002,7 @@ DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
       "Neighbor to display information about\n"
       "Neighbor to display information about\n"
       "Neighbor on BGP configured interface\n"
-      "Show only the specified remote AS sessions\n"
-      "AS number\n"
+      "Show only the specified remote AS sessions\n" AS_STR
       "Internal (iBGP) AS sessions\n"
       "External (eBGP) AS sessions\n"
       "Shorten the information on BGP instances\n"
@@ -11946,8 +12044,12 @@ DEFPY(show_ip_bgp_summary, show_ip_bgp_summary_cmd,
                        as_type = AS_INTERNAL;
                else if (argv[idx + 1]->arg[0] == 'e')
                        as_type = AS_EXTERNAL;
-               else
-                       as = (as_t)atoi(argv[idx + 1]->arg);
+               else if (!asn_str2asn(argv[idx + 1]->arg, &as)) {
+                       vty_out(vty,
+                               "%% Invalid neighbor remote-as value: %s\n",
+                               argv[idx + 1]->arg);
+                       return CMD_SUCCESS;
+               }
        }
 
        if (argv_find(argv, argc, "terse", &idx))
@@ -13082,13 +13184,14 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                        json_object_string_addf(json_neigh, "bgpNeighborAddr",
                                                "%pSU", &p->su);
 
-               json_object_int_add(json_neigh, "remoteAs", p->as);
+               asn_asn2json(json_neigh, "remoteAs", p->as, bgp->asnotation);
 
                if (p->change_local_as)
-                       json_object_int_add(json_neigh, "localAs",
-                                           p->change_local_as);
+                       asn_asn2json(json_neigh, "localAs", p->change_local_as,
+                                    bgp->asnotation);
                else
-                       json_object_int_add(json_neigh, "localAs", p->local_as);
+                       asn_asn2json(json_neigh, "localAs", p->local_as,
+                                    bgp->asnotation);
 
                if (CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
                        json_object_boolean_true_add(json_neigh,
@@ -13098,13 +13201,19 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                        json_object_boolean_true_add(json_neigh,
                                                     "localAsReplaceAs");
        } else {
-               if ((p->as_type == AS_SPECIFIED) || (p->as_type == AS_EXTERNAL)
-                   || (p->as_type == AS_INTERNAL))
-                       vty_out(vty, "remote AS %u, ", p->as);
-               else
+               if ((p->as_type == AS_SPECIFIED) ||
+                   (p->as_type == AS_EXTERNAL) ||
+                   (p->as_type == AS_INTERNAL)) {
+                       vty_out(vty, "remote AS ");
+                       vty_out(vty, ASN_FORMAT(bgp->asnotation), &p->as);
+                       vty_out(vty, ", ");
+               } else
                        vty_out(vty, "remote AS Unspecified, ");
-               vty_out(vty, "local AS %u%s%s, ",
-                       p->change_local_as ? p->change_local_as : p->local_as,
+               vty_out(vty, "local AS ");
+               vty_out(vty, ASN_FORMAT(bgp->asnotation),
+                       p->change_local_as ? &p->change_local_as
+                                          : &p->local_as);
+               vty_out(vty, "%s%s, ",
                        CHECK_FLAG(p->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)
                                ? " no-prepend"
                                : "",
@@ -15577,10 +15686,9 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
                                                json_object_new_string(vname));
                        json_object_object_add(json, "exportToVrfs",
                                               json_export_vrfs);
-                       json_object_string_addf(json, "routeDistinguisher",
-                                               "%pRD",
-                                               &bgp->vpn_policy[afi].tovpn_rd);
-
+                       json_object_string_addf(
+                               json, "routeDistinguisher", "%s",
+                               bgp->vpn_policy[afi].tovpn_rd_pretty);
                        dir = BGP_VPN_POLICY_DIR_TOVPN;
                        if (bgp->vpn_policy[afi].rtlist[dir]) {
                                ecom_str = ecommunity_ecom2str(
@@ -15648,8 +15756,10 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,
                                                node, vname))
                                vty_out(vty, "  %s\n", vname);
 
-                       vty_out(vty, "RD: %pRD\n",
+                       vty_out(vty, "RD: ");
+                       vty_out(vty, BGP_RD_AS_FORMAT(bgp->asnotation),
                                &bgp->vpn_policy[afi].tovpn_rd);
+                       vty_out(vty, "\n");
 
                        dir = BGP_VPN_POLICY_DIR_TOVPN;
                        if (bgp->vpn_policy[afi].rtlist[dir]) {
@@ -16014,18 +16124,22 @@ static int bgp_show_one_peer_group(struct vty *vty, struct peer_group *group,
 
        if (conf->as_type == AS_SPECIFIED || conf->as_type == AS_EXTERNAL) {
                if (json)
-                       json_object_int_add(json_peer_group, "remoteAs",
-                                           conf->as);
-               else
-                       vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
-                               group->name, conf->as);
+                       asn_asn2json(json_peer_group, "remoteAs", conf->as,
+                                    bgp_get_asnotation(conf->bgp));
+               else {
+                       vty_out(vty, "\nBGP peer-group %s, remote AS ",
+                               group->name);
+                       vty_out(vty, ASN_FORMAT(bgp_get_asnotation(conf->bgp)),
+                               &conf->as);
+                       vty_out(vty, "\n");
+               }
        } else if (conf->as_type == AS_INTERNAL) {
                if (json)
-                       json_object_int_add(json_peer_group, "remoteAs",
-                                           group->bgp->as);
+                       asn_asn2json(json, "remoteAs", group->bgp->as,
+                                    group->bgp->asnotation);
                else
-                       vty_out(vty, "\nBGP peer-group %s, remote AS %u\n",
-                               group->name, group->bgp->as);
+                       vty_out(vty, "\nBGP peer-group %s, remote AS %s\n",
+                               group->name, group->bgp->as_pretty);
        } else {
                if (!json)
                        vty_out(vty, "\nBGP peer-group %s\n", group->name);
@@ -17148,8 +17262,8 @@ static void bgp_vpn_policy_config_write_afi(struct vty *vty, struct bgp *bgp,
        }
 
        if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET))
-               vty_out(vty, "%*srd vpn export %pRD\n", indent, "",
-                       &bgp->vpn_policy[afi].tovpn_rd);
+               vty_out(vty, "%*srd vpn export %s\n", indent, "",
+                       bgp->vpn_policy[afi].tovpn_rd_pretty);
 
        if (CHECK_FLAG(bgp->vpn_policy[afi].flags,
                       BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
@@ -17319,7 +17433,7 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
                        vty_out(vty, " peer-group %s", peer->group->name);
                        if_pg_printed = true;
                } else if (peer->as_type == AS_SPECIFIED) {
-                       vty_out(vty, " remote-as %u", peer->as);
+                       vty_out(vty, " remote-as %s", peer->as_pretty);
                        if_ras_printed = true;
                } else if (peer->as_type == AS_INTERNAL) {
                        vty_out(vty, " remote-as internal");
@@ -17339,8 +17453,8 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
 
                if (g_peer->as_type == AS_UNSPECIFIED && !if_ras_printed) {
                        if (peer->as_type == AS_SPECIFIED) {
-                               vty_out(vty, " neighbor %s remote-as %u\n",
-                                       addr, peer->as);
+                               vty_out(vty, " neighbor %s remote-as %s\n",
+                                       addr, peer->as_pretty);
                        } else if (peer->as_type == AS_INTERNAL) {
                                vty_out(vty,
                                        " neighbor %s remote-as internal\n",
@@ -17368,8 +17482,8 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
 
                if (!if_ras_printed) {
                        if (peer->as_type == AS_SPECIFIED) {
-                               vty_out(vty, " neighbor %s remote-as %u\n",
-                                       addr, peer->as);
+                               vty_out(vty, " neighbor %s remote-as %s\n",
+                                       addr, peer->as_pretty);
                        } else if (peer->as_type == AS_INTERNAL) {
                                vty_out(vty,
                                        " neighbor %s remote-as internal\n",
@@ -17384,8 +17498,8 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
 
        /* local-as */
        if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS)) {
-               vty_out(vty, " neighbor %s local-as %u", addr,
-                       peer->change_local_as);
+               vty_out(vty, " neighbor %s local-as %s", addr,
+                       peer->change_local_as_pretty);
                if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND))
                        vty_out(vty, " no-prepend");
                if (peergroup_flag_check(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS))
@@ -18066,12 +18180,16 @@ int bgp_config_write(struct vty *vty)
                        continue;
 
                /* Router bgp ASN */
-               vty_out(vty, "router bgp %u", bgp->as);
+               vty_out(vty, "router bgp %s", bgp->as_pretty);
 
                if (bgp->name)
                        vty_out(vty, " %s %s",
                                (bgp->inst_type  == BGP_INSTANCE_TYPE_VIEW)
                                ? "view" : "vrf", bgp->name);
+               if (CHECK_FLAG(bgp->config, BGP_CONFIG_ASNOTATION))
+                       vty_out(vty, " as-notation %s",
+                               asn_mode2str(bgp->asnotation));
+
                vty_out(vty, "\n");
 
                /* BGP fast-external-failover. */
@@ -18189,8 +18307,8 @@ int bgp_config_write(struct vty *vty)
 
                /* Confederation identifier*/
                if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
-                       vty_out(vty, " bgp confederation identifier %u\n",
-                               bgp->confed_id);
+                       vty_out(vty, " bgp confederation identifier %s\n",
+                               bgp->confed_id_pretty);
 
                /* Confederation peer */
                if (bgp->confed_peers_cnt > 0) {
@@ -18199,7 +18317,8 @@ int bgp_config_write(struct vty *vty)
                        vty_out(vty, " bgp confederation peers");
 
                        for (i = 0; i < bgp->confed_peers_cnt; i++)
-                               vty_out(vty, " %u", bgp->confed_peers[i]);
+                               vty_out(vty, " %s",
+                                       bgp->confed_peers[i].as_pretty);
 
                        vty_out(vty, "\n");
                }