summaryrefslogtreecommitdiff
path: root/zebra/zebra_mpls_vty.c
diff options
context:
space:
mode:
authorDon Slice <dslice@cumulusnetworks.com>2016-12-27 07:09:28 -0800
committerDonald Sharp <sharpd@cumulusnetworks.com>2017-04-06 10:28:16 -0400
commitf31e084c7c0e6699926ad72bc4f9a8ca2663f50b (patch)
tree6cc447fac80c5895bcdeaaa1da2ebb3feea9f80e /zebra/zebra_mpls_vty.c
parentbc7268d524eaac8d4a29ed843f01ac1bc5e8d4f2 (diff)
zebra: static label binding
Implement static label binding of a label to a prefix (FEC). Note: Currently, only binding to a prefix is supported, the nexthop and/or other parameters are not considered. This was cherry-picked by hand from an earlier mpls branch. Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Diffstat (limited to 'zebra/zebra_mpls_vty.c')
-rw-r--r--zebra/zebra_mpls_vty.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c
index dd381723c5..90624c12a4 100644
--- a/zebra/zebra_mpls_vty.c
+++ b/zebra/zebra_mpls_vty.c
@@ -209,6 +209,101 @@ DEFUN (no_mpls_transit_lsp_all,
return zebra_mpls_transit_lsp (vty, 0, argv[3]->arg, NULL, NULL, NULL);
}
+static int
+zebra_mpls_bind (struct vty *vty, int add_cmd, const char *prefix,
+ const char *label_str)
+{
+ struct zebra_vrf *zvrf;
+ struct prefix p;
+ u_int32_t label;
+ int ret;
+
+ zvrf = vrf_info_lookup(VRF_DEFAULT);
+ if (!zvrf)
+ {
+ vty_out (vty, "%% Default VRF does not exist%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ memset(&p, 0, sizeof(struct prefix));
+ ret = str2prefix(prefix, &p);
+ if (ret <= 0)
+ {
+ vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (add_cmd)
+ {
+ if (!label_str)
+ {
+ vty_out (vty, "%% No label binding specified%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ if (!strcmp(label_str, "implicit-null"))
+ label = MPLS_IMP_NULL_LABEL;
+ else
+ {
+ label = atoi(label_str);
+ if (!IS_MPLS_UNRESERVED_LABEL(label))
+ {
+ vty_out (vty, "%% Invalid label%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (zebra_mpls_label_already_bound (zvrf, label))
+ {
+ vty_out (vty, "%% Label already bound to a FEC%s",
+ VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ }
+
+ ret = zebra_mpls_static_fec_add (zvrf, &p, label);
+ }
+ else
+ ret = zebra_mpls_static_fec_del (zvrf, &p);
+
+ if (ret)
+ {
+ vty_out (vty, "%% FEC to label binding cannot be %s%s",
+ add_cmd ? "added" : "deleted", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN (mpls_label_bind,
+ mpls_label_bind_cmd,
+ "mpls label bind <A.B.C.D/M|X:X::X:X/M> <(16-1048575)|implicit-null>",
+ MPLS_STR
+ "Label configuration\n"
+ "Establish FEC to label binding\n"
+ "IPv4 prefix\n"
+ "IPv6 prefix\n"
+ "MPLS Label to bind\n"
+ "Use Implicit-Null Label\n")
+{
+ return zebra_mpls_bind (vty, 1, argv[3]->arg, argv[4]->arg);
+}
+
+DEFUN (no_mpls_label_bind,
+ no_mpls_label_bind_cmd,
+ "no mpls label bind <A.B.C.D/M|X:X::X:X/M> [<(16-1048575)|implicit-null>]",
+ NO_STR
+ MPLS_STR
+ "Label configuration\n"
+ "Establish FEC to label binding\n"
+ "IPv4 prefix\n"
+ "IPv6 prefix\n"
+ "MPLS Label to bind\n"
+ "Use Implicit-Null Label\n")
+
+{
+ return zebra_mpls_bind (vty, 0, argv[4]->arg, NULL);
+}
+
/* Static route configuration. */
DEFUN (ip_route_label,
ip_route_label_cmd,
@@ -777,9 +872,44 @@ zebra_mpls_config (struct vty *vty)
return 0;
write += zebra_mpls_write_lsp_config(vty, zvrf);
+ write += zebra_mpls_write_fec_config(vty, zvrf);
return write;
}
+DEFUN (show_mpls_fec,
+ show_mpls_fec_cmd,
+ "show mpls fec [<A.B.C.D/M|X:X::X:X/M>]",
+ SHOW_STR
+ MPLS_STR
+ "MPLS FEC table\n"
+ "FEC to display information about\n"
+ "FEC to display information about\n")
+{
+ struct zebra_vrf *zvrf;
+ struct prefix p;
+ int ret;
+
+ zvrf = vrf_info_lookup(VRF_DEFAULT);
+ if (!zvrf)
+ return 0;
+
+ if (argc == 3)
+ zebra_mpls_print_fec_table(vty, zvrf);
+ else
+ {
+ memset(&p, 0, sizeof(struct prefix));
+ ret = str2prefix(argv[3]->arg, &p);
+ if (ret <= 0)
+ {
+ vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ zebra_mpls_print_fec (vty, zvrf, &p);
+ }
+
+ return CMD_SUCCESS;
+}
+
DEFUN (show_mpls_table,
show_mpls_table_cmd,
"show mpls table [json]",
@@ -876,7 +1006,10 @@ zebra_mpls_vty_init (void)
install_element (CONFIG_NODE, &no_mpls_transit_lsp_cmd);
install_element (CONFIG_NODE, &no_mpls_transit_lsp_out_label_cmd);
install_element (CONFIG_NODE, &no_mpls_transit_lsp_all_cmd);
+ install_element (CONFIG_NODE, &mpls_label_bind_cmd);
+ install_element (CONFIG_NODE, &no_mpls_label_bind_cmd);
install_element (VIEW_NODE, &show_mpls_table_cmd);
install_element (VIEW_NODE, &show_mpls_table_lsp_cmd);
+ install_element (VIEW_NODE, &show_mpls_fec_cmd);
}