SR-MPLS: binary API and automated steering

Change-Id: Iacfbaaa91ea8bd92790dec9fce567063bdbc5d64
Signed-off-by: Pablo Camarillo <pcamaril@cisco.com>
diff --git a/src/vnet/srmpls/sr.h b/src/vnet/srmpls/sr.h
deleted file mode 100755
index 0e10669..0000000
--- a/src/vnet/srmpls/sr.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @file
- * @brief Segment Routing MPLS data structures definitions
- *
- */
-
-#ifndef included_vnet_srmpls_h
-#define included_vnet_srmpls_h
-
-#include <vnet/vnet.h>
-#include <vnet/mpls/packet.h>
-#include <vnet/fib/mpls_fib.h>
-#include <vnet/ip/ip.h>
-#include <vnet/ip/lookup.h>
-#include <vnet/dpo/dpo.h>
-#include <vnet/dpo/replicate_dpo.h>
-
-#include <stdlib.h>
-#include <string.h>
-
-/* SR policy types */
-#define SR_POLICY_TYPE_DEFAULT 0
-#define SR_POLICY_TYPE_SPRAY 1
-
-#define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1
-
-#define SR_STEER_IPV4 4
-#define SR_STEER_IPV6 6
-
-/**
- * @brief SR Segment List (SID list)
- */
-typedef struct
-{
-  /**
-    * SIDs (key)
-    */
-  mpls_label_t *segments;
-
-  /**
-    * SID list weight (wECMP / UCMP)
-    */
-  u32 weight;
-
-} mpls_sr_sl_t;
-
-typedef struct
-{
-  u32 *segments_lists;		/**< Pool of SID lists indexes */
-
-  mpls_label_t bsid;		/**< BindingSID (key) */
-
-  u8 type;					/**< Type (default is 0) */
-  /* SR Policy specific DPO                                       */
-  /* IF Type = DEFAULT Then Load Balancer DPO among SID lists     */
-  /* IF Type = SPRAY then Spray DPO with all SID lists            */
-
-} mpls_sr_policy_t;
-
-/**
- * @brief Steering db key
- *
- * L3 is IPv4/IPv6 + mask
- */
-typedef struct
-{
-  ip46_address_t prefix;	/**< IP address of the prefix */
-  u32 mask_width;			/**< Mask width of the prefix */
-  u32 fib_table;			/**< VRF of the prefix */
-  u8 traffic_type;			/**< Traffic type (IPv4, IPv6, L2) */
-  u8 padding[3];
-} sr_mpls_steering_key_t;
-
-typedef struct
-{
-  sr_mpls_steering_key_t classify;		/**< Traffic classification */
-  u32 sr_policy;						/**< SR Policy index */
-} mpls_sr_steering_policy_t;
-
-/**
- * @brief Segment Routing main datastructure
- */
-typedef struct
-{
-  /**
-    * SR SID lists
-    */
-  mpls_sr_sl_t *sid_lists;
-
-  /**
-    * SR MPLS policies
-    */
-  mpls_sr_policy_t *sr_policies;
-
-  /**
-    * Hash table mapping BindingSID to SR MPLS policy
-    */
-  uword *sr_policies_index_hash;
-
-  /**
-    * Pool of SR steer policies instances
-    */
-  mpls_sr_steering_policy_t *steer_policies;
-
-  /**
-    * MHash table mapping steering rules to SR steer instance
-    */
-  mhash_t sr_steer_policies_hash;
-
-  /**
-    * convenience
-    */
-  vlib_main_t *vlib_main;
-  vnet_main_t *vnet_main;
-} mpls_sr_main_t;
-
-extern mpls_sr_main_t sr_mpls_main;
-
-extern int
-sr_mpls_policy_add (mpls_label_t bsid, mpls_label_t * segments,
-		    u8 behavior, u32 weight);
-
-extern int
-sr_mpls_policy_mod (mpls_label_t bsid, u32 index, u8 operation,
-		    mpls_label_t * segments, u32 sl_index, u32 weight);
-
-extern int sr_mpls_policy_del (mpls_label_t bsid, u32 index);
-
-#endif /* included_vnet_sr_mpls_h */
-
-/*
- * fd.io coding-style-patch-verification: ON
- *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
- */
diff --git a/src/vnet/srmpls/sr_doc.md b/src/vnet/srmpls/sr_doc.md
index d60592b..29110ec 100644
--- a/src/vnet/srmpls/sr_doc.md
+++ b/src/vnet/srmpls/sr_doc.md
@@ -64,7 +64,6 @@
 The weight of a SID list can also be modified with:
 
     sr mpls policy mod bsid 40001 mod sl index 1 weight 4
-    sr mpls policy mod index 1    mod sl index 1 weight 4
 
 ### SR Policies: Spray policies
 
@@ -80,8 +79,43 @@
 
 ## Steering packets into a SR Policy
 
-To steer packets in Transit into an SR policy, the user needs to create an 'sr steering policy'.
+Segment Routing supports three methos of steering traffic into an SR policy.
+
+### Local steering
+
+In this variant incoming packets match a routing policy which directs them on a local SR policy.
+
+In order to achieve this behavior the user needs to create an 'sr steering policy via sr policy bsid'.
 
     sr mpls steer l3 2001::/64 via sr policy bsid 40001
     sr mpls steer l3 2001::/64 via sr policy bsid 40001 fib-table 3
     sr mpls steer l3 10.0.0.0/16 via sr policy bsid 40001
+    sr mpls steer l3 10.0.0.0/16 via sr policy bsid 40001 vpn-label 500
+
+### Remote steering
+
+In this variant incoming packets have an active SID matching a local BSID at the head-end.
+
+In order to achieve this behavior the packets should simply arrive with an active SID equal to the Binding SID of a locally instantiated SR policy.
+
+### Automated steering
+
+In this variant incoming packets match a BGP/Service route which recurses on the BSID of a local policy.
+
+In order to achieve this behavior the user first needs to color the SR policies. He can do so by using the CLI:
+
+    sr mpls policy te bsid xxxxx endpoint x.x.x.x color 12341234
+
+Notice that an SR policy can have a single endpoint and a single color. Notice that the *endpoint* value is an IP46 address and the color a u32.
+
+
+Then, for any BGP/Service route the user has to use the API to steer prefixes:
+
+    sr steer l3 2001::/64 via next-hop 2001::1 color 1234 co 2
+    sr steer l3 2001::/64 via next-hop 2001::1 color 1234 co 2 vpn-label 500    
+
+Notice that *co* refers to the CO-bits (values [0|1|2|3]). 
+
+Notice also that a given prefix might be steered over several colors (same next-hop and same co-bit value). In order to add new colors just execute the API several times (or with the del parameter to delete the color).
+
+This variant is meant to be used in conjunction with a control plane agent that uses the underlying binary API bindings of *sr_mpls_steering_policy_add*/*sr_mpls_steering_policy_del* for any BGP service route received.
\ No newline at end of file
diff --git a/src/vnet/srmpls/sr_mpls.api b/src/vnet/srmpls/sr_mpls.api
new file mode 100644
index 0000000..e11dbb7
--- /dev/null
+++ b/src/vnet/srmpls/sr_mpls.api
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2015-2016 Cisco and/or its affiliates. Licensed under the
+ * Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+vl_api_version 1.0 .0
+/** \brief MPLS SR policy add
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param bsid is the bindingSID of the SR Policy. MPLS label (20bit)
+    @param weight is the weight of the sid list. optional.
+    @param type is the type of the SR policy. (0.Default // 1.Spray)
+    @param segments vector of labels (20bit) composing the segment list
+*/
+  autoreply define sr_mpls_policy_add
+{
+  u32 client_index;
+  u32 context;
+  u32 bsid;
+  u32 weight;
+  u8 type;
+  u8 n_segments;
+  u32 segments[n_segments];
+};
+
+/** \brief MPLS SR policy modification
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param bsid is the bindingSID of the SR Policy. MPLS label (20bit)
+    @param sr_policy_index is the index of the SR policy
+    @param fib_table is the VRF where to install the FIB entry for the BSID
+    @param operation is the operation to perform (among the top ones)
+    @param segments is a vector of MPLS labels composing the segment list
+    @param sl_index is the index of the Segment List to modify/delete
+    @param weight is the weight of the sid list. optional.
+    @param is_encap Mode. Encapsulation or SRH insertion.
+*/
+autoreply define sr_mpls_policy_mod
+{
+  u32 client_index;
+  u32 context;
+  u32 bsid;
+  u8 operation;
+  u32 sl_index;
+  u32 weight;
+  u8 n_segments;
+  u32 segments[n_segments];
+};
+
+/** \brief MPLS SR policy deletion
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param bsid is the bindingSID of the SR Policy. MPLS label (20bit)
+*/
+autoreply define sr_mpls_policy_del
+{
+  u32 client_index;
+  u32 context;
+  u32 bsid;
+};
+
+/** \brief MPLS SR steering add/del
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param is_del
+    @param bsid is the bindingSID of the SR Policy (~0 is no bsid)
+    @param table_id is the VRF where to install the FIB entry for the BSID
+    @param prefix is the IPv4/v6 address for L3 traffic type. If IPv4 (first 4B).
+    @param mask_width is the mask for L3 traffic type
+    @param sw_if_index is the incoming interface for L2 traffic
+    @param traffic_type describes the type of traffic
+    @param next_hop describes the next_hop (in case no BSID)
+    @param nh_type describes type of NH (IPv4=4, IPv6=6)
+    @param color describes the color
+    @param co_bits are the CO_bits of the steering policy
+    @param vpn_label is an additonal last VPN label. (~0 is no label)
+*/
+autoreply define sr_mpls_steering_add_del
+{
+  u32 client_index;
+  u32 context;
+  u8 is_del;
+  u32 bsid;
+  u32 table_id;
+  u8 prefix_addr[16];
+  u32 mask_width;
+  u8 traffic_type;
+  u8 next_hop[16];
+  u8 nh_type;
+  u32 color;
+  u8 co_bits;
+  u32 vpn_label;
+};
+
+/** \brief MPLS SR steering add/del
+    @param client_index - opaque cookie to identify the sender
+    @param context - sender context, to match reply w/ request
+    @param bsid is the bindingSID of the SR Policy
+    @param endpoint is the endpoint of the SR policy
+    @param endpoint_type describes type of NH (IPv4=4, IPv6=6)
+    @param color is the color of the sr policy
+*/
+autoreply define sr_mpls_policy_assign_endpoint_color
+{
+  u32 client_index;
+  u32 context;
+  u32 bsid;
+  u8 endpoint[16];
+  u8 endpoint_type;
+  u32 color;
+};
+
+/*
+ * fd.io coding-style-patch-verification: ON Local Variables: eval:
+ * (c-set-style "gnu") End:
+ */
diff --git a/src/vnet/srmpls/sr_mpls.h b/src/vnet/srmpls/sr_mpls.h
new file mode 100755
index 0000000..5b04f76
--- /dev/null
+++ b/src/vnet/srmpls/sr_mpls.h
@@ -0,0 +1,177 @@
+/*
+ * Copyright (c) 2015 Cisco and/or its affiliates. Licensed under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @file
+ * @brief Segment Routing MPLS data structures definitions
+ *
+ */
+
+#ifndef included_vnet_srmpls_h
+#define included_vnet_srmpls_h
+
+#include <vnet/vnet.h>
+#include <vnet/mpls/packet.h>
+#include <vnet/fib/mpls_fib.h>
+#include <vnet/ip/ip.h>
+#include <vnet/ip/lookup.h>
+#include <vnet/dpo/dpo.h>
+#include <vnet/dpo/replicate_dpo.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+/* SR policy types */
+#define SR_POLICY_TYPE_DEFAULT 0
+#define SR_POLICY_TYPE_SPRAY 1
+
+#define SR_SEGMENT_LIST_WEIGHT_DEFAULT 1
+
+#define SR_STEER_IPV4 4
+#define SR_STEER_IPV6 6
+
+#define SR_TE_CO_BITS_00 0
+#define SR_TE_CO_BITS_01 1
+#define SR_TE_CO_BITS_10 2
+#define SR_TE_CO_BITS_11 3
+
+/**
+ * @brief SR Segment List (SID list)
+ */
+typedef struct
+{
+  /* SIDs (key) */
+  mpls_label_t *segments;
+
+  /* SID list weight (wECMP / UCMP) */
+  u32 weight;
+
+} mpls_sr_sl_t;
+
+typedef struct
+{
+  u32 *segments_lists;			/**< Pool of SID lists indexes */
+
+  mpls_label_t bsid;		/**< BindingSID (key) */
+
+  u8 type;			/**< Type (default is 0) */
+  /* SR Policy specific DPO                                       */
+  /* IF Type = DEFAULT Then Load Balancer DPO among SID lists     */
+  /* IF Type = SPRAY then Spray DPO with all SID lists            */
+
+  ip46_address_t endpoint;		/**< Optional NH for SR TE */
+  u8 endpoint_type;
+  u32 color;			/**< Optional color for SR TE */
+} mpls_sr_policy_t;
+
+/**
+ * @brief Steering db key
+ *
+ * L3 is IPv4/IPv6 + mask
+ */
+typedef struct
+{
+  ip46_address_t prefix;	/**< IP address of the prefix */
+  u32 mask_width;			/**< Mask width of the prefix */
+  u32 fib_table;			/**< VRF of the prefix */
+  u8 traffic_type;			/**< Traffic type (IPv4, IPv6, L2) */
+  u8 padding[3];
+} sr_mpls_steering_key_t;
+
+typedef struct
+{
+  sr_mpls_steering_key_t classify;		/**< Traffic classification */
+  mpls_label_t bsid;		/**< SR Policy index */
+  ip46_address_t next_hop;		/**< SR TE NH */
+  char nh_type;
+  u32 *color;			/**< Vector of SR TE colors */
+  char co_bits;			/**< Color-Only bits */
+  mpls_label_t vpn_label;
+} mpls_sr_steering_policy_t;
+
+/**
+ * @brief Segment Routing main datastructure
+ */
+typedef struct
+{
+  /* SR SID lists */
+  mpls_sr_sl_t *sid_lists;
+
+  /* SR MPLS policies */
+  mpls_sr_policy_t *sr_policies;
+
+  /* Hash table mapping BindingSID to SR MPLS policy */
+  uword *sr_policies_index_hash;
+
+  /* Pool of SR steer policies instances */
+  mpls_sr_steering_policy_t *steer_policies;
+
+  /* MHash table mapping steering rules to SR steer instance */
+  mhash_t sr_steer_policies_hash;
+
+  /** SR TE **/
+  /* Hash table mapping (Color->Endpoint->BSID) for SR policies */
+  mhash_t sr_policies_c2e2eclabel_hash;
+  /* SR TE (internal) fib table (Endpoint, Color) */
+  u32 fib_table_EC;
+  /* Pool of (Endpoint, Color) hidden labels */
+  u32 *ec_labels;
+
+  /* convenience */
+  vlib_main_t *vlib_main;
+  vnet_main_t *vnet_main;
+} mpls_sr_main_t;
+
+extern mpls_sr_main_t sr_mpls_main;
+
+extern int
+sr_mpls_policy_add (mpls_label_t bsid, mpls_label_t * segments,
+		    u8 behavior, u32 weight);
+
+extern int
+sr_mpls_policy_mod (mpls_label_t bsid, u8 operation,
+		    mpls_label_t * segments, u32 sl_index, u32 weight);
+
+extern int sr_mpls_policy_del (mpls_label_t bsid);
+
+extern int
+sr_mpls_policy_assign_endpoint_color (mpls_label_t bsid,
+				      ip46_address_t * endpoint,
+				      u8 endpoint_type, u32 color);
+
+extern int
+sr_mpls_steering_policy_add (mpls_label_t bsid, u32 table_id,
+			     ip46_address_t * prefix, u32 mask_width,
+			     u8 traffic_type, ip46_address_t * next_hop,
+			     u8 nh_type, u32 color, char co_bits,
+			     mpls_label_t vpn_label);
+
+extern int
+sr_mpls_steering_policy_del (ip46_address_t * prefix,
+			     u32 mask_width, u8 traffic_type, u32 table_id,
+			     u32 color);
+
+extern u32 find_or_create_internal_label (ip46_address_t endpoint, u32 color);
+
+extern void internal_label_lock (ip46_address_t endpoint, u32 color);
+
+extern void internal_label_unlock (ip46_address_t endpoint, u32 color);
+
+#endif /* included_vnet_sr_mpls_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables: eval: (c-set-style "gnu") End:
+ */
diff --git a/src/vnet/srmpls/sr_mpls_api.c b/src/vnet/srmpls/sr_mpls_api.c
new file mode 100644
index 0000000..a6294e3
--- /dev/null
+++ b/src/vnet/srmpls/sr_mpls_api.c
@@ -0,0 +1,228 @@
+/*
+ * ------------------------------------------------------------------
+ * sr_api.c - ipv6 segment routing api
+ *
+ * Copyright (c) 2016 Cisco and/or its affiliates. Licensed under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ * ------------------------------------------------------------------
+ */
+
+#include <vnet/vnet.h>
+#include <vnet/srmpls/sr_mpls.h>
+#include <vlibmemory/api.h>
+
+#include <vnet/interface.h>
+#include <vnet/api_errno.h>
+#include <vnet/feature/feature.h>
+
+#include <vnet/vnet_msg_enum.h>
+
+#define vl_typedefs		/* define message structures */
+#include <vnet/vnet_all_api_h.h>
+#undef vl_typedefs
+
+#define vl_endianfun		/* define message structures */
+#include <vnet/vnet_all_api_h.h>
+#undef vl_endianfun
+
+/* instantiate all the print functions we know about */
+#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
+#define vl_printfun
+#include <vnet/vnet_all_api_h.h>
+#undef vl_printfun
+
+#include <vlibapi/api_helper_macros.h>
+
+#define foreach_vpe_api_msg                             \
+_(SR_MPLS_POLICY_DEL, sr_mpls_policy_del)                         \
+_(SR_MPLS_STEERING_ADD_DEL, sr_mpls_steering_add_del)             \
+_(SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR, sr_mpls_policy_assign_endpoint_color)
+
+
+static void
+vl_api_sr_mpls_policy_add_t_handler (vl_api_sr_mpls_policy_add_t * mp)
+{
+  vl_api_sr_mpls_policy_add_reply_t *rmp;
+
+  mpls_label_t *segments = 0, *seg;
+  mpls_label_t this_address = 0;
+
+  int i;
+  for (i = 0; i < mp->n_segments; i++)
+    {
+      vec_add2 (segments, seg, 1);
+      this_address = ntohl (mp->segments[i]);
+      clib_memcpy (seg, &this_address, sizeof (this_address));
+    }
+
+  int rv = 0;
+  rv = sr_mpls_policy_add (ntohl (mp->bsid),
+			   segments, mp->type, ntohl (mp->weight));
+
+  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ADD_REPLY);
+}
+
+static void
+vl_api_sr_mpls_policy_mod_t_handler (vl_api_sr_mpls_policy_mod_t * mp)
+{
+  vl_api_sr_mpls_policy_mod_reply_t *rmp;
+
+  mpls_label_t *segments = 0, *seg;
+  mpls_label_t this_address = 0;
+
+  int i;
+  for (i = 0; i < mp->n_segments; i++)
+    {
+      vec_add2 (segments, seg, 1);
+      this_address = ntohl (mp->segments[i]);
+      clib_memcpy (seg, &this_address, sizeof (this_address));
+    }
+
+  int rv = 0;
+  rv = sr_mpls_policy_mod (ntohl (mp->bsid),
+			   mp->operation, segments, ntohl (mp->sl_index),
+			   ntohl (mp->weight));
+
+  REPLY_MACRO (VL_API_SR_MPLS_POLICY_MOD_REPLY);
+}
+
+static void
+vl_api_sr_mpls_policy_del_t_handler (vl_api_sr_mpls_policy_del_t * mp)
+{
+  vl_api_sr_mpls_policy_del_reply_t *rmp;
+  int rv = 0;
+  rv = sr_mpls_policy_del (ntohl (mp->bsid));
+
+  REPLY_MACRO (VL_API_SR_MPLS_POLICY_DEL_REPLY);
+}
+
+static void vl_api_sr_mpls_steering_add_del_t_handler
+  (vl_api_sr_mpls_steering_add_del_t * mp)
+{
+  vl_api_sr_mpls_steering_add_del_reply_t *rmp;
+  ip46_address_t prefix;
+  memset (&prefix, 0, sizeof (ip46_address_t));
+  if (mp->traffic_type == SR_STEER_IPV4)
+    memcpy (&prefix.ip4, mp->prefix_addr, sizeof (prefix.ip4));
+  else
+    memcpy (&prefix, mp->prefix_addr, sizeof (prefix.ip6));
+
+  int rv = 0;
+  if (mp->is_del)
+    rv = sr_mpls_steering_policy_del (&prefix,
+				      ntohl (mp->mask_width),
+				      mp->traffic_type,
+				      ntohl (mp->table_id),
+				      ntohl (mp->color));
+  else
+    rv = sr_mpls_steering_policy_add (ntohl (mp->bsid),
+				      ntohl (mp->table_id),
+				      &prefix,
+				      ntohl (mp->mask_width),
+				      mp->traffic_type,
+				      (ip46_address_t *) & mp->next_hop,
+				      mp->nh_type,
+				      ntohl (mp->color), mp->co_bits,
+				      ntohl (mp->vpn_label));
+
+  REPLY_MACRO (VL_API_SR_MPLS_STEERING_ADD_DEL_REPLY);
+}
+
+static void vl_api_sr_mpls_policy_assign_endpoint_color_t_handler
+  (vl_api_sr_mpls_policy_assign_endpoint_color_t * mp)
+{
+  vl_api_sr_mpls_policy_assign_endpoint_color_reply_t *rmp;
+  int rv = 0;
+
+  ip46_address_t endpoint;
+  memset (&endpoint, 0, sizeof (ip46_address_t));
+  if (mp->endpoint_type == SR_STEER_IPV4)
+    memcpy (&endpoint.ip4, mp->endpoint, sizeof (endpoint.ip4));
+  else
+    memcpy (&endpoint, mp->endpoint, sizeof (endpoint.ip6));
+
+  rv = sr_mpls_policy_assign_endpoint_color (ntohl (mp->bsid),
+					     &endpoint, mp->endpoint_type,
+					     ntohl (mp->color));
+
+  REPLY_MACRO (VL_API_SR_MPLS_POLICY_ASSIGN_ENDPOINT_COLOR_REPLY);
+}
+
+/*
+ * sr_mpls_api_hookup Add vpe's API message handlers to the table. vlib has
+ * alread mapped shared memory and added the client registration handlers.
+ * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
+ */
+#define vl_msg_name_crc_list
+#include <vnet/vnet_all_api_h.h>
+#undef vl_msg_name_crc_list
+
+static void
+setup_message_id_table (api_main_t * am)
+{
+#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
+  foreach_vl_msg_name_crc_sr_mpls;
+#undef _
+}
+
+static clib_error_t *
+sr_mpls_api_hookup (vlib_main_t * vm)
+{
+  api_main_t *am = &api_main;
+
+#define _(N,n)                                                  \
+    vl_msg_api_set_handlers(VL_API_##N, #n,                     \
+                           vl_api_##n##_t_handler,              \
+                           vl_noop_handler,                     \
+                           vl_api_##n##_t_endian,               \
+                           vl_api_##n##_t_print,                \
+                           sizeof(vl_api_##n##_t), 1);
+  foreach_vpe_api_msg;
+#undef _
+
+  /*
+   * Manually register the sr policy add msg, so we trace enough bytes
+   * to capture a typical segment list
+   */
+  vl_msg_api_set_handlers (VL_API_SR_MPLS_POLICY_ADD,
+			   "sr_mpls_policy_add",
+			   vl_api_sr_mpls_policy_add_t_handler,
+			   vl_noop_handler,
+			   vl_api_sr_mpls_policy_add_t_endian,
+			   vl_api_sr_mpls_policy_add_t_print, 256, 1);
+
+  /*
+   * Manually register the sr policy mod msg, so we trace enough bytes
+   * to capture a typical segment list
+   */
+  vl_msg_api_set_handlers (VL_API_SR_MPLS_POLICY_MOD,
+			   "sr_mpls_policy_mod",
+			   vl_api_sr_mpls_policy_mod_t_handler,
+			   vl_noop_handler,
+			   vl_api_sr_mpls_policy_mod_t_endian,
+			   vl_api_sr_mpls_policy_mod_t_print, 256, 1);
+
+  /*
+   * Set up the (msg_name, crc, message-id) table
+   */
+  setup_message_id_table (am);
+
+  return 0;
+}
+
+VLIB_API_INIT_FUNCTION (sr_mpls_api_hookup);
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables: eval: (c-set-style "gnu") End:
+ */
diff --git a/src/vnet/srmpls/sr_mpls_policy.c b/src/vnet/srmpls/sr_mpls_policy.c
index db4ad2a..d75f2d1 100755
--- a/src/vnet/srmpls/sr_mpls_policy.c
+++ b/src/vnet/srmpls/sr_mpls_policy.c
@@ -1,18 +1,17 @@
 /*
  * sr_mpls_policy.c: SR-MPLS policies
  *
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
+ * Copyright (c) 2016 Cisco and/or its affiliates. Licensed under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at:
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
  */
 
 /**
@@ -26,17 +25,19 @@
  * An SR policy has associated a BindingSID.
  * In case any packet arrives with MPLS_label == BindingSID then the SR policy
  * associated to such bindingSID will be applied to such packet.
+ * Also, a BSID can be associated with a (Next-Hop, Color)
  *
  */
 
 #include <vlib/vlib.h>
 #include <vnet/vnet.h>
-#include <vnet/srmpls/sr.h>
+#include <vnet/srmpls/sr_mpls.h>
 #include <vnet/fib/mpls_fib.h>
 #include <vnet/dpo/dpo.h>
 #include <vnet/dpo/replicate_dpo.h>
 #include <vnet/dpo/mpls_label_dpo.h>
 #include <vnet/dpo/lookup_dpo.h>
+#include <vnet/ip/ip.h>
 
 #include <vppinfra/error.h>
 #include <vppinfra/elog.h>
@@ -92,15 +93,15 @@
   mpls_eos_bit_t eos;
   FOR_EACH_MPLS_EOS_BIT (eos)
   {
-    /* *INDENT-OFF* */
-    fib_prefix_t pfx = {
-      .fp_len = 21,
-      .fp_proto = FIB_PROTOCOL_MPLS,
-      .fp_label = sr_policy->bsid,
-      .fp_eos = eos,
-      .fp_payload_proto = DPO_PROTO_MPLS,
-    };
-    /* *INDENT-ON* */
+		/* *INDENT-OFF* */
+		fib_prefix_t	pfx = {
+			.fp_len = 21,
+			.fp_proto = FIB_PROTOCOL_MPLS,
+			.fp_label = sr_policy->bsid,
+			.fp_eos = eos,
+			.fp_payload_proto = DPO_PROTO_MPLS,
+		};
+		/* *INDENT-ON* */
 
     fib_table_entry_path_add2 (0,
 			       &pfx,
@@ -116,11 +117,11 @@
 }
 
 /******************************* SR rewrite API *******************************/
-/* Three functions for handling sr policies:
- *   -> sr_mpls_policy_add
- *   -> sr_mpls_policy_del
- *   -> sr_mpls_policy_mod
- * All of them are API. CLI function on sr_policy_command_fn                  */
+/*
+ * Three functions for handling sr policies: -> sr_mpls_policy_add ->
+ * sr_mpls_policy_del -> sr_mpls_policy_mod All of them are API. CLI function
+ * on sr_policy_command_fn
+ */
 
 /**
  * @brief Create a new SR policy
@@ -141,6 +142,9 @@
   mpls_sr_policy_t *sr_policy = 0;
   uword *p;
 
+  if (!sm->sr_policies_index_hash)
+    sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t));
+
   /* Search for existing keys (BSID) */
   p = hash_get (sm->sr_policies_index_hash, bsid);
   if (p)
@@ -148,12 +152,14 @@
       /* Add SR policy that already exists; complain */
       return -12;
     }
-
   /* Add an SR policy object */
   pool_get (sm->sr_policies, sr_policy);
   memset (sr_policy, 0, sizeof (*sr_policy));
   sr_policy->bsid = bsid;
   sr_policy->type = behavior;
+  sr_policy->endpoint_type = 0;
+  ip6_address_set_zero (&sr_policy->endpoint.ip6);
+  sr_policy->color = (u32) ~ 0;
 
   /* Copy the key */
   hash_set (sm->sr_policies_index_hash, bsid, sr_policy - sm->sr_policies);
@@ -173,7 +179,7 @@
  * @return 0 if correct, else error
  */
 int
-sr_mpls_policy_del (mpls_label_t bsid, u32 index)
+sr_mpls_policy_del (mpls_label_t bsid)
 {
   mpls_sr_main_t *sm = &sr_mpls_main;
   mpls_sr_policy_t *sr_policy = 0;
@@ -182,20 +188,14 @@
   u32 *sl_index;
   uword *p;
 
-  if (bsid)
-    {
-      p = hash_get (sm->sr_policies_index_hash, bsid);
-      if (p)
-	sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
-      else
-	return -1;
-    }
+  if (!sm->sr_policies_index_hash)
+    sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t));
+
+  p = hash_get (sm->sr_policies_index_hash, bsid);
+  if (p)
+    sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
   else
-    {
-      sr_policy = pool_elt_at_index (sm->sr_policies, index);
-      if (!sr_policy)
-	return -1;
-    }
+    return -1;
 
   /* Clean SID Lists */
   vec_foreach (sl_index, sr_policy->segments_lists)
@@ -211,21 +211,24 @@
       .frp_local_label = segment_list->segments[0],
     };
 
+    vec_add (path.frp_label_stack, segment_list + 1,
+	     vec_len (segment_list) - 1);
+
     fib_route_path_t *paths = NULL;
     vec_add1 (paths, path);
 
     /* remove each of the MPLS routes */
     FOR_EACH_MPLS_EOS_BIT (eos)
     {
-      /* *INDENT-OFF* */
-      fib_prefix_t pfx = {
-        .fp_len = 21,
-        .fp_proto = FIB_PROTOCOL_MPLS,
-        .fp_label = sr_policy->bsid,
-        .fp_eos = eos,
-        .fp_payload_proto = DPO_PROTO_MPLS,
-      };
-      /* *INDENT-ON* */
+			/* *INDENT-OFF* */
+			fib_prefix_t	pfx = {
+				.fp_len = 21,
+				.fp_proto = FIB_PROTOCOL_MPLS,
+				.fp_label = sr_policy->bsid,
+				.fp_eos = eos,
+				.fp_payload_proto = DPO_PROTO_MPLS,
+			};
+			/* *INDENT-ON* */
 
       fib_table_entry_path_remove2 (0, &pfx, FIB_SOURCE_SR, paths);
     }
@@ -234,6 +237,12 @@
     pool_put_index (sm->sid_lists, *sl_index);
   }
 
+  /* If there is still traces of TE, make sure locks are released */
+  if (sr_policy->endpoint_type != 0 && sr_policy->color != (u32) ~ 0)
+    {
+      sr_mpls_policy_assign_endpoint_color (bsid, NULL, 0, (u32) ~ 0);
+    }
+
   /* Remove SR policy entry */
   hash_unset (sm->sr_policies_index_hash, sr_policy->bsid);
   pool_put (sm->sr_policies, sr_policy);
@@ -249,17 +258,16 @@
  * Segment List from the SR Policy.
  *
  * @param bsid is the bindingSID of the SR Policy
- * @param index is the index of the SR policy
  * @param fib_table is the VRF where to install the FIB entry for the BSID
  * @param operation is the operation to perform (among the top ones)
  * @param segments is a vector of IPv6 address composing the segment list
  * @param sl_index is the index of the Segment List to modify/delete
  * @param weight is the weight of the sid list. optional.
  *
- * @return 0 if correct, else error
+ * @return 0 ok, >0 index of SL, <0 error
  */
 int
-sr_mpls_policy_mod (mpls_label_t bsid, u32 index, u8 operation,
+sr_mpls_policy_mod (mpls_label_t bsid, u8 operation,
 		    mpls_label_t * segments, u32 sl_index, u32 weight)
 {
   mpls_sr_main_t *sm = &sr_mpls_main;
@@ -268,34 +276,32 @@
   u32 *sl_index_iterate;
   uword *p;
 
-  if (bsid)
-    {
-      p = hash_get (sm->sr_policies_index_hash, bsid);
-      if (p)
-	sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
-      else
-	return -1;
-    }
-  else
-    {
-      sr_policy = pool_elt_at_index (sm->sr_policies, index);
-      if (!sr_policy)
-	return -1;
-    }
+  if (!sm->sr_policies_index_hash)
+    sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t));
 
-  if (operation == 1)		/* Add SR List to an existing SR policy */
-    {
+  p = hash_get (sm->sr_policies_index_hash, bsid);
+  if (p)
+    sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
+  else
+    return -1;
+
+  if (operation == 1)
+    {				/* Add SR List to an existing SR policy */
       /* Create the new SL */
       segment_list = create_sl (sr_policy, segments, weight);
-
+      return segment_list - sm->sid_lists;
     }
-  else if (operation == 2)	/* Delete SR List from an existing SR policy */
-    {
+  else if (operation == 2)
+    {				/* Delete SR List from an existing SR
+				 * policy */
       /* Check that currently there are more than one SID list */
       if (vec_len (sr_policy->segments_lists) == 1)
 	return -21;
 
-      /* Check that the SR list does exist and is assigned to the sr policy */
+      /*
+       * Check that the SR list does exist and is assigned to the
+       * sr policy
+       */
       vec_foreach (sl_index_iterate, sr_policy->segments_lists)
 	if (*sl_index_iterate == sl_index)
 	break;
@@ -316,20 +322,23 @@
 	.frp_local_label = segment_list->segments[0],
       };
 
+      vec_add (path.frp_label_stack, segment_list + 1,
+	       vec_len (segment_list) - 1);
+
       fib_route_path_t *paths = NULL;
       vec_add1 (paths, path);
 
       FOR_EACH_MPLS_EOS_BIT (eos)
       {
-	/* *INDENT-OFF* */
-        fib_prefix_t pfx = {
-          .fp_len = 21,
-          .fp_proto = FIB_PROTOCOL_MPLS,
-          .fp_label = sr_policy->bsid,
-          .fp_eos = eos,
-          .fp_payload_proto = DPO_PROTO_MPLS,
-        };
-	/* *INDENT-ON* */
+			/* *INDENT-OFF* */
+			fib_prefix_t	pfx = {
+				.fp_len = 21,
+				.fp_proto = FIB_PROTOCOL_MPLS,
+				.fp_label = sr_policy->bsid,
+				.fp_eos = eos,
+				.fp_payload_proto = DPO_PROTO_MPLS,
+			};
+			/* *INDENT-ON* */
 
 	fib_table_entry_path_remove2 (0, &pfx, FIB_SOURCE_SR, paths);
       }
@@ -340,8 +349,9 @@
       vec_del1 (sr_policy->segments_lists,
 		sl_index_iterate - sr_policy->segments_lists);
     }
-  else if (operation == 3)	/* Modify the weight of an existing SR List */
-    {
+  else if (operation == 3)
+    {				/* Modify the weight of an existing
+				 * SR List */
       /* Find the corresponding SL */
       vec_foreach (sl_index_iterate, sr_policy->segments_lists)
 	if (*sl_index_iterate == sl_index)
@@ -352,10 +362,67 @@
 
       /* Change the weight */
       segment_list = pool_elt_at_index (sm->sid_lists, sl_index);
-      segment_list->weight = weight;
 
       /* Update LB */
-      //FIXME
+      mpls_eos_bit_t eos;
+      fib_route_path_t path = {
+	.frp_proto = DPO_PROTO_MPLS,
+	.frp_sw_if_index = ~0,
+	.frp_fib_index = 0,
+	.frp_weight = segment_list->weight,
+	.frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
+	.frp_local_label = segment_list->segments[0],
+      };
+
+      vec_add (path.frp_label_stack, segment_list + 1,
+	       vec_len (segment_list) - 1);
+
+      fib_route_path_t *paths = NULL;
+      vec_add1 (paths, path);
+
+      FOR_EACH_MPLS_EOS_BIT (eos)
+      {
+			/* *INDENT-OFF* */
+			fib_prefix_t	pfx = {
+				.fp_len = 21,
+				.fp_proto = FIB_PROTOCOL_MPLS,
+				.fp_label = sr_policy->bsid,
+				.fp_eos = eos,
+				.fp_payload_proto = DPO_PROTO_MPLS,
+			};
+			/* *INDENT-ON* */
+
+	fib_table_entry_path_remove2 (0, &pfx, FIB_SOURCE_SR, paths);
+      }
+
+      segment_list->weight = weight;
+
+      path.frp_weight = segment_list->weight;
+
+      vec_free (paths);
+      paths = NULL;
+      vec_add1 (paths, path);
+
+      FOR_EACH_MPLS_EOS_BIT (eos)
+      {
+			/* *INDENT-OFF* */
+			fib_prefix_t	pfx = {
+				.fp_len = 21,
+				.fp_proto = FIB_PROTOCOL_MPLS,
+				.fp_label = sr_policy->bsid,
+				.fp_eos = eos,
+				.fp_payload_proto = DPO_PROTO_MPLS,
+			};
+			/* *INDENT-ON* */
+
+	fib_table_entry_path_add2 (0,
+				   &pfx,
+				   FIB_SOURCE_SR,
+				   (sr_policy->type ==
+				    SR_POLICY_TYPE_DEFAULT ?
+				    FIB_ENTRY_FLAG_NONE :
+				    FIB_ENTRY_FLAG_MULTICAST), paths);
+      }
     }
   return 0;
 }
@@ -371,7 +438,7 @@
   char is_del = 0, is_add = 0, is_mod = 0;
   char policy_set = 0;
   mpls_label_t bsid, next_label;
-  u32 sr_policy_index = (u32) ~ 0, sl_index = (u32) ~ 0;
+  u32 sl_index = (u32) ~ 0;
   u32 weight = (u32) ~ 0;
   mpls_label_t *segments = 0;
   u8 operation = 0;
@@ -389,13 +456,9 @@
 	       && unformat (input, "bsid %U", unformat_mpls_unicast_label,
 			    &bsid))
 	policy_set = 1;
-      else if (!is_add && !policy_set
-	       && unformat (input, "index %d", &sr_policy_index))
-	policy_set = 1;
       else if (unformat (input, "weight %d", &weight));
-      else
-	if (unformat
-	    (input, "next %U", unformat_mpls_unicast_label, &next_label))
+      else if (unformat
+	       (input, "next %U", unformat_mpls_unicast_label, &next_label))
 	{
 	  vec_add (segments, &next_label, 1);
 	}
@@ -427,9 +490,7 @@
 				SR_POLICY_TYPE_DEFAULT), weight);
     }
   else if (is_del)
-    rv =
-      sr_mpls_policy_del ((sr_policy_index != (u32) ~ 0 ? (u32) ~ 0 : bsid),
-			  sr_policy_index);
+    rv = sr_mpls_policy_del (bsid);
   else if (is_mod)
     {
       if (!operation)
@@ -440,12 +501,8 @@
 	return clib_error_return (0, "No Segment List specified");
       if (operation == 3 && weight == (u32) ~ 0)
 	return clib_error_return (0, "No new weight for the SL specified");
-      rv =
-	sr_mpls_policy_mod ((sr_policy_index != (u32) ~ 0 ? (u32) ~ 0 : bsid),
-			    sr_policy_index, operation, segments,
-			    sl_index, weight);
+      rv = sr_mpls_policy_mod (bsid, operation, segments, sl_index, weight);
     }
-
   switch (rv)
     {
     case 0:
@@ -464,6 +521,10 @@
       return clib_error_return (0,
 				"Could not delete the segment list. "
 				"It is not associated with that SR policy.");
+    case -23:
+      return clib_error_return (0,
+				"Could not delete the segment list. "
+				"It is not associated with that SR policy.");
     case -32:
       return clib_error_return (0,
 				"Could not modify the segment list. "
@@ -475,12 +536,13 @@
 }
 
 /* *INDENT-OFF* */
-VLIB_CLI_COMMAND (sr_mpls_policy_command, static) = {
-  .path = "sr mpls policy",
-  .short_help = "sr mpls policy [add||del||mod] bsid 2999 "
-  "next 10 next 20 next 30 (weight 1) (spray)",
-  .long_help = "TBD.\n",
-  .function = sr_mpls_policy_command_fn,
+VLIB_CLI_COMMAND(sr_mpls_policy_command, static)=
+{
+	.path = "sr mpls policy",
+		.short_help = "sr mpls policy [add||del||mod] bsid 2999 "
+		"next 10 next 20 next 30 (weight 1) (spray)",
+		.long_help = "TBD.\n",
+		.function = sr_mpls_policy_command_fn,
 };
 /* *INDENT-ON* */
 
@@ -502,9 +564,11 @@
 
   vlib_cli_output (vm, "SR MPLS policies:");
 
-  /* *INDENT-OFF* */
-		pool_foreach  (sr_policy, sm->sr_policies, {vec_add1 (vec_policies, sr_policy); } );
-  /* *INDENT-ON* */
+	/* *INDENT-OFF* */
+	pool_foreach(sr_policy, sm->sr_policies, {
+		vec_add1(vec_policies, sr_policy);
+	});
+	/* *INDENT-ON* */
 
   vec_foreach_index (i, vec_policies)
   {
@@ -512,6 +576,21 @@
     vlib_cli_output (vm, "[%u].-\tBSID: %U",
 		     (u32) (sr_policy - sm->sr_policies),
 		     format_mpls_unicast_label, sr_policy->bsid);
+    switch (sr_policy->endpoint_type)
+      {
+      case SR_STEER_IPV6:
+	vlib_cli_output (vm, "\tEndpoint: %U", format_ip6_address,
+			 &sr_policy->endpoint.ip6);
+	vlib_cli_output (vm, "\tColor: %u", sr_policy->color);
+	break;
+      case SR_STEER_IPV4:
+	vlib_cli_output (vm, "\tEndpoint: %U", format_ip4_address,
+			 &sr_policy->endpoint.ip4);
+	vlib_cli_output (vm, "\tColor: %u", sr_policy->color);
+	break;
+      default:
+	vlib_cli_output (vm, "\tTE disabled");
+      }
     vlib_cli_output (vm, "\tType: %s",
 		     (sr_policy->type ==
 		      SR_POLICY_TYPE_DEFAULT ? "Default" : "Spray"));
@@ -536,10 +615,244 @@
 }
 
 /* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_sr_mpls_policies_command, static) = {
-  .path = "show sr mpls policies",
-  .short_help = "show sr mpls policies",
-  .function = show_sr_mpls_policies_command_fn,
+VLIB_CLI_COMMAND(show_sr_mpls_policies_command, static)=
+{
+	.path = "show sr mpls policies",
+		.short_help = "show sr mpls policies",
+		.function = show_sr_mpls_policies_command_fn,
+};
+/* *INDENT-ON* */
+
+/**
+ * @brief Update the Endpoint,Color tuple of an SR policy
+ *
+ * @param bsid is the bindingSID of the SR Policy
+ * @param endpoint represents the IP46 of the endpoint
+ * @param color represents the color (u32)
+ *
+ * To reset to NULL use ~0 as parameters.
+ *
+ * @return 0 if correct, else error
+ */
+int
+sr_mpls_policy_assign_endpoint_color (mpls_label_t bsid,
+				      ip46_address_t * endpoint,
+				      u8 endpoint_type, u32 color)
+{
+  mpls_sr_main_t *sm = &sr_mpls_main;
+  mpls_sr_policy_t *sr_policy = 0;
+  uword *endpoint_table, *p, *old_value;
+
+  ip46_address_t any;
+  any.as_u64[0] = any.as_u64[1] = (u64) ~ 0;
+
+  if (!sm->sr_policies_index_hash)
+    sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t));
+
+  p = hash_get (sm->sr_policies_index_hash, bsid);
+  if (p)
+    sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
+  else
+    return -1;
+
+  /* If previous Endpoint, color existed, remove (NH,C) and (ANY,C) */
+  if (sr_policy->endpoint_type)
+    {
+      endpoint_table =
+	mhash_get (&sm->sr_policies_c2e2eclabel_hash, &sr_policy->color);
+      if (!endpoint_table)
+	return -2;
+      old_value =
+	mhash_get ((mhash_t *) endpoint_table, &sr_policy->endpoint);
+
+      fib_prefix_t pfx = { 0 };
+      pfx.fp_proto = FIB_PROTOCOL_MPLS;
+      pfx.fp_len = 21;
+      pfx.fp_label = (u32) * old_value;
+
+      mpls_eos_bit_t eos;
+      FOR_EACH_MPLS_EOS_BIT (eos)
+      {
+	pfx.fp_eos = eos;
+	fib_table_entry_path_remove (sm->fib_table_EC,
+				     &pfx,
+				     FIB_SOURCE_SR,
+				     DPO_PROTO_MPLS,
+				     NULL,
+				     ~0, 0, 1, FIB_ROUTE_PATH_FLAG_NONE);
+      }
+
+      old_value = mhash_get ((mhash_t *) endpoint_table, &any);
+      pfx.fp_label = (u32) * old_value;
+
+      FOR_EACH_MPLS_EOS_BIT (eos)
+      {
+	pfx.fp_eos = eos;
+	fib_table_entry_path_remove (sm->fib_table_EC,
+				     &pfx,
+				     FIB_SOURCE_SR,
+				     DPO_PROTO_MPLS,
+				     NULL,
+				     ~0, 0, 1, FIB_ROUTE_PATH_FLAG_NONE);
+      }
+
+      /* Release the lock on (NH, Color) and (ANY, Color) */
+      internal_label_unlock (sr_policy->endpoint, sr_policy->color);
+      internal_label_unlock (any, sr_policy->color);
+
+      /* Reset the values on the SR policy */
+      sr_policy->endpoint_type = 0;
+      sr_policy->endpoint.as_u64[0] = sr_policy->endpoint.as_u64[1] =
+	(u64) ~ 0;
+      sr_policy->color = (u32) ~ 0;
+    }
+
+  if (endpoint_type)
+    {
+      sr_policy->endpoint_type = endpoint_type;
+      sr_policy->endpoint.as_u64[0] = endpoint->as_u64[0];
+      sr_policy->endpoint.as_u64[1] = endpoint->as_u64[1];
+      sr_policy->color = color;
+
+      u32 label = find_or_create_internal_label (*endpoint, color);
+      internal_label_lock (*endpoint, sr_policy->color);
+
+      /* If FIB doesnt exist, create them */
+      if (sm->fib_table_EC == (u32) ~ 0)
+	{
+	  sm->fib_table_EC = fib_table_create_and_lock (FIB_PROTOCOL_MPLS,
+							FIB_SOURCE_SR,
+							"SR-MPLS Traffic Engineering (NextHop,Color)");
+
+	  fib_table_flush (sm->fib_table_EC, FIB_PROTOCOL_MPLS,
+			   FIB_SOURCE_SPECIAL);
+	}
+
+      fib_prefix_t pfx = { 0 };
+      pfx.fp_proto = FIB_PROTOCOL_MPLS;
+      pfx.fp_len = 21;
+
+      fib_route_path_t path = {
+	.frp_proto = DPO_PROTO_MPLS,
+	.frp_sw_if_index = ~0,
+	.frp_fib_index = 0,
+	.frp_weight = 1,
+	.frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
+	.frp_label_stack = 0
+      };
+      path.frp_local_label = sr_policy->bsid;
+
+      //Add the entry to ANY,Color
+      u32 any_label = find_or_create_internal_label (any, color);
+      internal_label_lock (any, sr_policy->color);
+
+      pfx.fp_eos = MPLS_EOS;
+      path.frp_eos = MPLS_EOS;
+
+      fib_route_path_t *paths = NULL;
+      vec_add1 (paths, path);
+
+      pfx.fp_label = label;
+      fib_table_entry_update (sm->fib_table_EC,
+			      &pfx,
+			      FIB_SOURCE_SR,
+			      FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+
+      pfx.fp_label = any_label;
+      fib_table_entry_update (sm->fib_table_EC,
+			      &pfx,
+			      FIB_SOURCE_SR,
+			      FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+
+      vec_add1 (path.frp_label_stack, MPLS_IETF_IMPLICIT_NULL_LABEL);
+      pfx.fp_eos = MPLS_NON_EOS;
+      path.frp_eos = MPLS_NON_EOS;
+
+      paths = NULL;
+      vec_add1 (paths, path);
+
+      pfx.fp_label = label;
+      fib_table_entry_update (sm->fib_table_EC,
+			      &pfx,
+			      FIB_SOURCE_SR,
+			      FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+
+      pfx.fp_label = any_label;
+      fib_table_entry_update (sm->fib_table_EC,
+			      &pfx,
+			      FIB_SOURCE_SR,
+			      FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+    }
+  return 0;
+}
+
+/**
+ * @brief CLI to modify the Endpoint,Color of an SR policy
+ */
+static clib_error_t *
+cli_sr_mpls_policy_ec_command_fn (vlib_main_t * vm, unformat_input_t * input,
+				  vlib_cli_command_t * cmd)
+{
+  ip46_address_t endpoint;
+  u32 color = (u32) ~ 0;
+  mpls_label_t bsid;
+  u8 endpoint_type = 0;
+  char clear = 0, color_set = 0, bsid_set = 0;
+
+  memset (&endpoint, 0, sizeof (ip46_address_t));
+
+  int rv;
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (!endpoint_type
+	  && unformat (input, "endpoint %U", unformat_ip6_address,
+		       &endpoint.ip6))
+	endpoint_type = SR_STEER_IPV6;
+      else if (!endpoint_type
+	       && unformat (input, "endpoint %U", unformat_ip4_address,
+			    &endpoint.ip4))
+	endpoint_type = SR_STEER_IPV4;
+      else if (!color_set && unformat (input, "color %u", &color))
+	color_set = 1;
+      else if (!bsid_set
+	       && unformat (input, "bsid %U", unformat_mpls_unicast_label,
+			    &bsid))
+	bsid_set = 1;
+      else if (!clear && unformat (input, "clear"))
+	clear = 1;
+      else
+	break;
+    }
+
+  if (!bsid_set)
+    return clib_error_return (0, "No BSID specified");
+  if (!endpoint_type && !clear)
+    return clib_error_return (0, "No Endpoint specified");
+  if (!color_set && !clear)
+    return clib_error_return (0, "No Color set");
+
+  /* In case its a cleanup */
+  if (clear)
+    {
+      ip6_address_set_zero (&endpoint.ip6);
+      color = (u32) ~ 0;
+    }
+  rv =
+    sr_mpls_policy_assign_endpoint_color (bsid, &endpoint, endpoint_type,
+					  color);
+
+  if (rv)
+    clib_error_return (0, "Error on Endpoint,Color");
+
+  return 0;
+}
+
+/* *INDENT-OFF* */
+VLIB_CLI_COMMAND(cli_sr_mpls_policy_ec_command, static)=
+{
+	.path = "sr mpls policy te",
+		.short_help = "sr mpls policy te bsid xxxxx endpoint x.x.x.x color 12341234",
+		.function = cli_sr_mpls_policy_ec_command_fn,
 };
 /* *INDENT-ON* */
 
@@ -553,17 +866,15 @@
   mpls_sr_main_t *sm = &sr_mpls_main;
 
   /* Init memory for sr policy keys (bsid <-> ip6_address_t) */
-  sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t));
-
+  sm->sr_policies_index_hash = NULL;
+  sm->sr_policies_c2e2eclabel_hash.hash = NULL;
   return 0;
 }
 
 VLIB_INIT_FUNCTION (sr_mpls_policy_rewrite_init);
 
 /*
-* fd.io coding-style-patch-verification: ON
-*
-* Local Variables:
-* eval: (c-set-style "gnu")
-* End:
-*/
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables: eval: (c-set-style "gnu") End:
+ */
diff --git a/src/vnet/srmpls/sr_mpls_steering.c b/src/vnet/srmpls/sr_mpls_steering.c
index 3a9aea2..0bd3466 100755
--- a/src/vnet/srmpls/sr_mpls_steering.c
+++ b/src/vnet/srmpls/sr_mpls_steering.c
@@ -1,18 +1,17 @@
 /*
  * sr_steering.c: ipv6 segment routing steering into SR policy
  *
- * Copyright (c) 2016 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
+ * Copyright (c) 2016 Cisco and/or its affiliates. Licensed under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at:
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
  */
 
 /**
@@ -25,13 +24,14 @@
  * sr_policy_rewrite.c
  *
  * Supports:
- *  - Steering of IPv6 traffic Destination Address based
- *  - Steering of IPv4 traffic Destination Address based
+ *  - Steering of IPv6 traffic Destination Address based through BSID
+ *  - Steering of IPv4 traffic Destination Address based through BSID
+ *  - Steering of IPv4 and IPv6 traffic through N,C (SR CP)
  */
 
 #include <vlib/vlib.h>
 #include <vnet/vnet.h>
-#include <vnet/srmpls/sr.h>
+#include <vnet/srmpls/sr_mpls.h>
 #include <vnet/ip/ip4_packet.h>
 #include <vnet/ip/ip6_packet.h>
 #include <vnet/fib/mpls_fib.h>
@@ -39,6 +39,323 @@
 #include <vppinfra/error.h>
 #include <vppinfra/elog.h>
 
+#define SRMPLS_TE_OFFSET 50
+
+/**
+ * @brief function to sort the colors in descending order
+ */
+int
+sort_color_descent (const u32 * x, u32 * y)
+{
+  return *y - *x;
+}
+
+/********************* Internal (NH, C) labels *******************************/
+/**
+ * @brief find the corresponding label for (endpoint, color) and lock it
+ * endpoint might be NULL or ANY
+ * NULL = 0, ANY=~0
+ */
+u32
+find_or_create_internal_label (ip46_address_t endpoint, u32 color)
+{
+  mpls_sr_main_t *sm = &sr_mpls_main;
+  uword *color_table, *result_label;
+
+  if (!sm->sr_policies_c2e2eclabel_hash.hash)
+    mhash_init (&sm->sr_policies_c2e2eclabel_hash, sizeof (mhash_t),
+		sizeof (u32));
+
+  color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color);
+  if (!color_table)
+    {
+      mhash_t color_t;
+      memset (&color_t, 0, sizeof (mhash_t));
+      mhash_init (&color_t, sizeof (u32), sizeof (ip46_address_t));
+      mhash_set_mem (&sm->sr_policies_c2e2eclabel_hash, &color,
+		     (uword *) & color_t, NULL);
+      color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color);
+    }
+
+  result_label = mhash_get ((mhash_t *) color_table, &endpoint);
+
+  if (result_label)
+    return (u32) * result_label;
+
+  /* Create and set a new internal label */
+  u32 *new_internal_label = 0;
+  pool_get (sm->ec_labels, new_internal_label);
+  *new_internal_label = 0;
+  mhash_set ((mhash_t *) color_table, &endpoint,
+	     (new_internal_label - sm->ec_labels) + SRMPLS_TE_OFFSET, NULL);
+
+  return (new_internal_label - sm->ec_labels) + SRMPLS_TE_OFFSET;
+}
+
+always_inline void
+internal_label_lock_co (ip46_address_t endpoint, u32 color, char co_bits)
+{
+  ip46_address_t zero, any;
+  ip46_address_reset (&zero);
+  any.as_u64[0] = any.as_u64[1] = (u64) ~ 0;
+  switch (co_bits)
+    {
+    case SR_TE_CO_BITS_10:
+      internal_label_lock (endpoint, color);
+      internal_label_lock (zero, color);
+      internal_label_lock (any, color);
+      break;
+    case SR_TE_CO_BITS_01:
+      internal_label_lock (endpoint, color);
+      internal_label_lock (zero, color);
+      break;
+    case SR_TE_CO_BITS_00:
+    case SR_TE_CO_BITS_11:
+      internal_label_lock (endpoint, color);
+      break;
+    }
+}
+
+/**
+ * @brief lock the label for (NH, C)
+ * endpoint might be NULL or ANY
+ * NULL = 0, ANY=~0
+ */
+void
+internal_label_lock (ip46_address_t endpoint, u32 color)
+{
+  mpls_sr_main_t *sm = &sr_mpls_main;
+  uword *color_table, *result_label;
+
+  if (!sm->sr_policies_c2e2eclabel_hash.hash)
+    return;
+
+  color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color);
+  if (!color_table)
+    return;
+
+  result_label = mhash_get ((mhash_t *) color_table, &endpoint);
+
+  if (!result_label)
+    return;
+
+  /* Lock it */
+  u32 *label_lock =
+    pool_elt_at_index (sm->ec_labels, *result_label - SRMPLS_TE_OFFSET);
+  (*label_lock)++;
+}
+
+
+always_inline void
+internal_label_unlock_co (ip46_address_t endpoint, u32 color, char co_bits)
+{
+  ip46_address_t zero, any;
+  ip46_address_reset (&zero);
+  any.as_u64[0] = any.as_u64[1] = (u64) ~ 0;
+  switch (co_bits)
+    {
+    case SR_TE_CO_BITS_10:
+      internal_label_unlock (endpoint, color);
+      internal_label_unlock (zero, color);
+      internal_label_unlock (any, color);
+      break;
+    case SR_TE_CO_BITS_01:
+      internal_label_unlock (endpoint, color);
+      internal_label_unlock (zero, color);
+      break;
+    case SR_TE_CO_BITS_00:
+    case SR_TE_CO_BITS_11:
+      internal_label_unlock (endpoint, color);
+      break;
+    }
+}
+
+/**
+ * @brief Release lock on label for (endpoint, color)
+ * endpoint might be NULL or ANY
+ * NULL = 0, ANY=~0
+ */
+void
+internal_label_unlock (ip46_address_t endpoint, u32 color)
+{
+  mpls_sr_main_t *sm = &sr_mpls_main;
+  uword *color_table, *result_label;
+
+  if (!sm->sr_policies_c2e2eclabel_hash.hash)
+    return;
+
+  color_table = mhash_get (&sm->sr_policies_c2e2eclabel_hash, &color);
+  if (!color_table)
+    return;
+
+  result_label = mhash_get ((mhash_t *) color_table, &endpoint);
+
+  if (!result_label)
+    return;
+
+  u32 *label_lock =
+    pool_elt_at_index (sm->ec_labels, *result_label - SRMPLS_TE_OFFSET);
+  (*label_lock)--;
+
+  if (*label_lock == 0)
+    {
+      pool_put (sm->ec_labels, label_lock);
+      mhash_unset ((mhash_t *) color_table, &endpoint, NULL);
+      if (mhash_elts ((mhash_t *) color_table) == 0)
+	{
+	  mhash_free ((mhash_t *) color_table);
+	  mhash_unset (&sm->sr_policies_c2e2eclabel_hash, &color, NULL);
+	  if (mhash_elts (&sm->sr_policies_c2e2eclabel_hash) == 0)
+	    {
+	      mhash_free (&sm->sr_policies_c2e2eclabel_hash);
+	      sm->sr_policies_c2e2eclabel_hash.hash = NULL;
+	      fib_table_unlock (sm->fib_table_EC, FIB_PROTOCOL_MPLS,
+				FIB_SOURCE_SR);
+	      sm->fib_table_EC = (u32) ~ 0;
+	    }
+	}
+    }
+}
+
+/********************* steering computation  *********************************/
+/**
+ * @brief function to update the FIB
+ */
+void
+compute_sr_te_automated_steering_fib_entry (mpls_sr_steering_policy_t *
+					    steer_pl)
+{
+  mpls_sr_main_t *sm = &sr_mpls_main;
+  fib_prefix_t pfx = { 0 };
+
+  u32 *internal_labels = 0;
+  ip46_address_t zero, any;
+  ip46_address_reset (&zero);
+  any.as_u64[0] = any.as_u64[1] = (u64) ~ 0;
+
+  u32 *color_i = NULL;
+  vec_foreach (color_i, steer_pl->color)
+  {
+    switch (steer_pl->co_bits)
+      {
+      case SR_TE_CO_BITS_10:
+	vec_add1 (internal_labels,
+		  find_or_create_internal_label (steer_pl->next_hop,
+						 *color_i));
+	vec_add1 (internal_labels,
+		  find_or_create_internal_label (zero, *color_i));
+	vec_add1 (internal_labels,
+		  find_or_create_internal_label (any, *color_i));
+	break;
+      case SR_TE_CO_BITS_01:
+	vec_add1 (internal_labels,
+		  find_or_create_internal_label (steer_pl->next_hop,
+						 *color_i));
+	vec_add1 (internal_labels,
+		  find_or_create_internal_label (zero, *color_i));
+	break;
+      case SR_TE_CO_BITS_00:
+      case SR_TE_CO_BITS_11:
+	vec_add1 (internal_labels,
+		  find_or_create_internal_label (steer_pl->next_hop,
+						 *color_i));
+	break;
+      }
+  }
+
+  /* Does hidden FIB already exist? */
+  if (sm->fib_table_EC == (u32) ~ 0)
+    {
+      sm->fib_table_EC = fib_table_create_and_lock (FIB_PROTOCOL_MPLS,
+						    FIB_SOURCE_SR,
+						    "SR-MPLS Traffic Engineering (NextHop,Color)");
+
+      fib_table_flush (sm->fib_table_EC, FIB_PROTOCOL_MPLS,
+		       FIB_SOURCE_SPECIAL);
+    }
+
+  /* Add the corresponding FIB entries */
+  fib_route_path_t path = {
+    .frp_proto = DPO_PROTO_MPLS,
+    .frp_eos = MPLS_EOS,
+    .frp_sw_if_index = ~0,
+    .frp_fib_index = sm->fib_table_EC,
+    .frp_weight = 1,
+    .frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
+    .frp_label_stack = 0
+  };
+  fib_route_path_t *paths = NULL;
+
+  if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
+    {
+      pfx.fp_proto = FIB_PROTOCOL_IP6;
+      pfx.fp_len = steer_pl->classify.mask_width;
+      pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
+    }
+  else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
+    {
+      pfx.fp_proto = FIB_PROTOCOL_IP4;
+      pfx.fp_len = steer_pl->classify.mask_width;
+      pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
+    }
+
+  if (steer_pl->vpn_label != (u32) ~ 0)
+    {
+      vec_add1 (path.frp_label_stack, steer_pl->vpn_label);
+      path.frp_eos = MPLS_NON_EOS;
+    }
+
+  u32 label_i;
+  vec_foreach_index (label_i, internal_labels)
+  {
+    path.frp_local_label = internal_labels[label_i];
+    path.frp_preference = label_i;
+    vec_add1 (paths, path);
+  }
+
+  /* Finally we must add to FIB IGP to N */
+  clib_memcpy (&path.frp_addr, &steer_pl->next_hop,
+	       sizeof (steer_pl->next_hop));
+  path.frp_preference = vec_len (internal_labels);
+  path.frp_label_stack = NULL;
+
+  if (steer_pl->nh_type == SR_STEER_IPV6)
+    {
+      path.frp_proto = DPO_PROTO_IP6;
+      path.frp_fib_index =
+	fib_table_find (FIB_PROTOCOL_IP6,
+			(steer_pl->classify.fib_table !=
+			 (u32) ~ 0 ? steer_pl->classify.fib_table : 0));
+    }
+  else if (steer_pl->nh_type == SR_STEER_IPV4)
+    {
+      path.frp_proto = DPO_PROTO_IP4;
+      path.frp_fib_index =
+	fib_table_find (FIB_PROTOCOL_IP4,
+			(steer_pl->classify.fib_table !=
+			 (u32) ~ 0 ? steer_pl->classify.fib_table : 0));
+    }
+
+  vec_add1 (paths, path);
+  if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
+    fib_table_entry_update (fib_table_find
+			    (FIB_PROTOCOL_IP6,
+			     (steer_pl->classify.fib_table !=
+			      (u32) ~ 0 ? steer_pl->classify.fib_table : 0)),
+			    &pfx, FIB_SOURCE_SR,
+			    FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+  else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
+    fib_table_entry_update (fib_table_find
+			    (FIB_PROTOCOL_IP4,
+			     (steer_pl->classify.fib_table !=
+			      (u32) ~ 0 ? steer_pl->classify.fib_table : 0)),
+			    &pfx, FIB_SOURCE_SR,
+			    FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+
+  vec_free (paths);
+  paths = NULL;
+}
+
 /**
  * @brief Steer traffic L3 traffic through a given SR-MPLS policy
  *
@@ -49,13 +366,19 @@
  * @param prefix is the IPv4/v6 address for L3 traffic type
  * @param mask_width is the mask for L3 traffic type
  * @param traffic_type describes the type of traffic
+ * @param next_hop SR TE Next-Hop
+ * @param nh_type is the AF of Next-Hop
+ * @param color SR TE color
+ * @param co_bits SR TE color-only bits
  *
  * @return 0 if correct, else error
  */
 int
-sr_mpls_steering_policy (int is_del, mpls_label_t bsid, u32 sr_policy_index,
-			 u32 table_id, ip46_address_t * prefix,
-			 u32 mask_width, u8 traffic_type)
+sr_mpls_steering_policy_add (mpls_label_t bsid, u32 table_id,
+			     ip46_address_t * prefix, u32 mask_width,
+			     u8 traffic_type, ip46_address_t * next_hop,
+			     u8 nh_type, u32 color, char co_bits,
+			     mpls_label_t vpn_label)
 {
   mpls_sr_main_t *sm = &sr_mpls_main;
   sr_mpls_steering_key_t key;
@@ -80,192 +403,254 @@
 
   key.traffic_type = traffic_type;
 
-  /* Search for the item */
-  p = mhash_get (&sm->sr_steer_policies_hash, &key);
+  if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6)
+    return -1;
 
+  /*
+   * Search for steering policy. If already exists we are adding a new
+   * color.
+   */
+  if (!sm->sr_steer_policies_hash.hash)
+    mhash_init (&sm->sr_steer_policies_hash, sizeof (uword),
+		sizeof (sr_mpls_steering_key_t));
+
+  p = mhash_get (&sm->sr_steer_policies_hash, &key);
   if (p)
     {
-      /* Retrieve Steer Policy function */
       steer_pl = pool_elt_at_index (sm->steer_policies, p[0]);
+      if (steer_pl->bsid != (u32) ~ 0)
+	return -1;		//Means we are rewritting the steering. Not allowed.
 
-      if (is_del)
-	{
-	  if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
-	    {
-	      /* Remove FIB entry */
-	      pfx.fp_proto = FIB_PROTOCOL_IP6;
-	      pfx.fp_len = steer_pl->classify.mask_width;
-	      pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
-
-	      fib_table_entry_delete (fib_table_find
-				      (FIB_PROTOCOL_MPLS,
-				       steer_pl->classify.fib_table), &pfx,
-				      FIB_SOURCE_SR);
-	    }
-	  else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
-	    {
-	      /* Remove FIB entry */
-	      pfx.fp_proto = FIB_PROTOCOL_IP4;
-	      pfx.fp_len = steer_pl->classify.mask_width;
-	      pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
-
-	      fib_table_entry_delete (fib_table_find
-				      (FIB_PROTOCOL_MPLS,
-				       steer_pl->classify.fib_table), &pfx,
-				      FIB_SOURCE_SR);
-	    }
-
-	  /* Delete SR steering policy entry */
-	  pool_put (sm->steer_policies, steer_pl);
-	  mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
-
-	  return 1;
-	}
-      else			/* It means user requested to update an existing SR steering policy */
-	{
-	  /* Retrieve SR steering policy */
-	  if (bsid)		//TODO FIXME
-	    {
-	      p = hash_get (sm->sr_policies_index_hash, bsid);
-	      if (p)
-		sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
-	      else
-		return -2;
-	    }
-	  else
-	    sr_policy = pool_elt_at_index (sm->sr_policies, sr_policy_index);
-
-	  if (!sr_policy)
-	    return -2;
-
-	  steer_pl->sr_policy = sr_policy - sm->sr_policies;
-
-	  /* Remove old FIB/hw redirection and create a new one */
-	  if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
-	    {
-	      /* Remove FIB entry */
-	      pfx.fp_proto = FIB_PROTOCOL_IP6;
-	      pfx.fp_len = steer_pl->classify.mask_width;
-	      pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
-
-	      fib_table_entry_delete (fib_table_find
-				      (FIB_PROTOCOL_IP6,
-				       steer_pl->classify.fib_table), &pfx,
-				      FIB_SOURCE_SR);
-
-	      /* Create a new one */
-	      goto update_fib;
-	    }
-	  else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
-	    {
-	      /* Remove FIB entry */
-	      pfx.fp_proto = FIB_PROTOCOL_IP4;
-	      pfx.fp_len = steer_pl->classify.mask_width;
-	      pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
-
-	      fib_table_entry_delete (fib_table_find
-				      (FIB_PROTOCOL_IP4,
-				       steer_pl->classify.fib_table), &pfx,
-				      FIB_SOURCE_SR);
-
-	      /* Create a new one */
-	      goto update_fib;
-	    }
-	}
-    }
-  else
-    /* delete; steering policy does not exist; complain */
-  if (is_del)
-    return -4;
-
-  /* Retrieve SR policy */
-  if (bsid)			//FIX
-    {
-      p = hash_get (sm->sr_policies_index_hash, bsid);
-      if (p)
-	sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
-      else
+      /* Means we are adding a color. Check that NH match. */
+      if (ip46_address_cmp (&steer_pl->next_hop, next_hop))
 	return -2;
+      if (vec_search (steer_pl->color, color) != ~0)
+	return -3;
+      if (steer_pl->co_bits != co_bits)
+	return -4;		/* CO colors should be the same */
+      if (steer_pl->vpn_label != vpn_label)
+	return -5;		/* VPN label should be the same */
+
+      /* Remove the steering and ReDo it */
+      vec_add1 (steer_pl->color, color);
+      vec_sort_with_function (steer_pl->color, sort_color_descent);
+      compute_sr_te_automated_steering_fib_entry (steer_pl);
+      internal_label_lock_co (steer_pl->next_hop, color, steer_pl->co_bits);
+      return 0;
     }
-  else
-    sr_policy = pool_elt_at_index (sm->sr_policies, sr_policy_index);
 
   /* Create a new steering policy */
   pool_get (sm->steer_policies, steer_pl);
   memset (steer_pl, 0, sizeof (*steer_pl));
-
-  if (traffic_type == SR_STEER_IPV4 || traffic_type == SR_STEER_IPV6)
-    {
-      clib_memcpy (&steer_pl->classify.prefix, prefix,
-		   sizeof (ip46_address_t));
-      steer_pl->classify.mask_width = mask_width;
-      steer_pl->classify.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
-      steer_pl->classify.traffic_type = traffic_type;
-    }
-  else
-    {
-      /* Incorrect API usage. Should never get here */
-      pool_put (sm->steer_policies, steer_pl);
-      mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
-      return -1;
-    }
-  steer_pl->sr_policy = sr_policy - sm->sr_policies;
+  clib_memcpy (&steer_pl->classify.prefix, prefix, sizeof (ip46_address_t));
+  clib_memcpy (&steer_pl->next_hop, next_hop, sizeof (ip46_address_t));
+  steer_pl->nh_type = nh_type;
+  steer_pl->co_bits = co_bits;
+  steer_pl->classify.mask_width = mask_width;
+  steer_pl->classify.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
+  steer_pl->classify.traffic_type = traffic_type;
+  steer_pl->color = NULL;
+  steer_pl->vpn_label = vpn_label;
 
   /* Create and store key */
   mhash_set (&sm->sr_steer_policies_hash, &key, steer_pl - sm->steer_policies,
 	     NULL);
 
-update_fib:;
-
-  fib_route_path_t path = {
-    .frp_proto = DPO_PROTO_MPLS,
-    .frp_local_label = sr_policy->bsid,
-    .frp_eos = MPLS_EOS,
-    .frp_sw_if_index = ~0,
-    .frp_fib_index = 0,
-    .frp_weight = 1,
-    .frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
-    .frp_label_stack = NULL
-  };
-
-  fib_route_path_t *paths = NULL;
-
-  /* FIB API calls - Recursive route through the BindingSID */
-  if (traffic_type == SR_STEER_IPV6)
+  /* Local steering */
+  if (bsid != (u32) ~ 0)
     {
-      pfx.fp_proto = FIB_PROTOCOL_IP6;
-      pfx.fp_len = steer_pl->classify.mask_width;
-      pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
-      path.frp_fib_index = 0;
+      if (!sm->sr_policies_index_hash)
+	sm->sr_policies_index_hash = hash_create (0, sizeof (mpls_label_t));
+      steer_pl->bsid = bsid;
+      p = hash_get (sm->sr_policies_index_hash, bsid);
+      if (!p)
+	return -1;
+      sr_policy = pool_elt_at_index (sm->sr_policies, p[0]);
 
-      vec_add1 (paths, path);
+      fib_route_path_t path = {
+	.frp_proto = DPO_PROTO_MPLS,
+	.frp_local_label = sr_policy->bsid,
+	.frp_eos = MPLS_EOS,
+	.frp_sw_if_index = ~0,
+	.frp_fib_index = 0,
+	.frp_weight = 1,
+	.frp_flags = FIB_ROUTE_PATH_FLAG_NONE,
+	.frp_label_stack = 0
+      };
+      fib_route_path_t *paths = NULL;
 
-      fib_table_entry_path_add2 (fib_table_find
-				 (FIB_PROTOCOL_IP6,
-				  (table_id != (u32) ~ 0 ? table_id : 0)),
-				 &pfx, FIB_SOURCE_SR,
-				 FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+      if (steer_pl->vpn_label != (u32) ~ 0)
+	vec_add1 (path.frp_label_stack, steer_pl->vpn_label);
 
-      vec_free (paths);
+      /* FIB API calls - Recursive route through the BindingSID */
+      if (traffic_type == SR_STEER_IPV6)
+	{
+	  pfx.fp_proto = FIB_PROTOCOL_IP6;
+	  pfx.fp_len = steer_pl->classify.mask_width;
+	  pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
+	  path.frp_fib_index = 0;
+	  path.frp_preference = 0;
+	  vec_add1 (paths, path);
+	  fib_table_entry_path_add2 (fib_table_find
+				     (FIB_PROTOCOL_IP6,
+				      (table_id != (u32) ~ 0 ? table_id : 0)),
+				     &pfx, FIB_SOURCE_SR,
+				     FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+	  vec_free (paths);
+	}
+      else if (traffic_type == SR_STEER_IPV4)
+	{
+	  pfx.fp_proto = FIB_PROTOCOL_IP4;
+	  pfx.fp_len = steer_pl->classify.mask_width;
+	  pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
+	  path.frp_fib_index = 0;
+	  path.frp_preference = 0;
+	  vec_add1 (paths, path);
+	  fib_table_entry_path_add2 (fib_table_find
+				     (FIB_PROTOCOL_IP4,
+				      (table_id != (u32) ~ 0 ? table_id : 0)),
+				     &pfx, FIB_SOURCE_SR,
+				     FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
+	  vec_free (paths);
+	}
     }
-  else if (traffic_type == SR_STEER_IPV4)
+  /* Automated steering */
+  else
     {
-      pfx.fp_proto = FIB_PROTOCOL_IP4;
-      pfx.fp_len = steer_pl->classify.mask_width;
-      pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
-      path.frp_fib_index = 0;
-
-      vec_add1 (paths, path);
-
-      fib_table_entry_path_add2 (fib_table_find
-				 (FIB_PROTOCOL_IP4,
-				  (table_id != (u32) ~ 0 ? table_id : 0)),
-				 &pfx, FIB_SOURCE_SR,
-				 FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT, paths);
-
-      vec_free (paths);
+      steer_pl->bsid = (u32) ~ 0;
+      vec_add1 (steer_pl->color, color);
+      compute_sr_te_automated_steering_fib_entry (steer_pl);
+      internal_label_lock_co (steer_pl->next_hop, color, steer_pl->co_bits);
     }
+  return 0;
+}
 
+/**
+ * @brief Delete steering rule for an SR-MPLS policy
+ *
+ * @param is_del
+ * @param bsid is the bindingSID of the SR Policy (alt to sr_policy_index)
+ * @param sr_policy is the index of the SR Policy (alt to bsid)
+ * @param table_id is the VRF where to install the FIB entry for the BSID
+ * @param prefix is the IPv4/v6 address for L3 traffic type
+ * @param mask_width is the mask for L3 traffic type
+ * @param traffic_type describes the type of traffic
+ * @param next_hop SR TE Next-HOP
+ * @param nh_type is the AF of Next-Hop
+ * @param color SR TE color
+ *
+ * @return 0 if correct, else error
+ */
+int
+sr_mpls_steering_policy_del (ip46_address_t * prefix, u32 mask_width,
+			     u8 traffic_type, u32 table_id, u32 color)
+{
+  mpls_sr_main_t *sm = &sr_mpls_main;
+  sr_mpls_steering_key_t key;
+  mpls_sr_steering_policy_t *steer_pl;
+  fib_prefix_t pfx = { 0 };
+  uword *p = 0;
+
+  memset (&key, 0, sizeof (sr_mpls_steering_key_t));
+
+  /* Compute the steer policy key */
+  if (traffic_type != SR_STEER_IPV4 && traffic_type != SR_STEER_IPV6)
+    return -1;
+
+  key.prefix.as_u64[0] = prefix->as_u64[0];
+  key.prefix.as_u64[1] = prefix->as_u64[1];
+  key.mask_width = mask_width;
+  key.fib_table = (table_id != (u32) ~ 0 ? table_id : 0);
+  key.traffic_type = traffic_type;
+
+  if (!sm->sr_steer_policies_hash.hash)
+    mhash_init (&sm->sr_steer_policies_hash, sizeof (uword),
+		sizeof (sr_mpls_steering_key_t));
+
+  /* Search for the item */
+  p = mhash_get (&sm->sr_steer_policies_hash, &key);
+
+  if (!p)
+    return -1;
+
+  /* Retrieve Steer Policy function */
+  steer_pl = pool_elt_at_index (sm->steer_policies, p[0]);
+
+  if (steer_pl->bsid == (u32) ~ 0)
+    {
+      /* Remove the color from the color vector */
+      vec_del1 (steer_pl->color, vec_search (steer_pl->color, color));
+
+      if (vec_len (steer_pl->color))
+	{
+	  /* Reorder Colors */
+	  vec_sort_with_function (steer_pl->color, sort_color_descent);
+	  compute_sr_te_automated_steering_fib_entry (steer_pl);
+	  /* Remove all the locks for this ones... */
+	  internal_label_unlock_co (steer_pl->next_hop, color,
+				    steer_pl->co_bits);
+	  return 0;
+	}
+      else
+	{
+	  vec_free (steer_pl->color);
+	  /* Remove FIB entry */
+	  if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
+	    {
+	      pfx.fp_proto = FIB_PROTOCOL_IP6;
+	      pfx.fp_len = steer_pl->classify.mask_width;
+	      pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
+	      fib_table_entry_delete (fib_table_find
+				      (FIB_PROTOCOL_IP6,
+				       steer_pl->classify.fib_table), &pfx,
+				      FIB_SOURCE_SR);
+	    }
+	  else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
+	    {
+	      pfx.fp_proto = FIB_PROTOCOL_IP4;
+	      pfx.fp_len = steer_pl->classify.mask_width;
+	      pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
+	      fib_table_entry_delete (fib_table_find
+				      (FIB_PROTOCOL_IP4,
+				       steer_pl->classify.fib_table), &pfx,
+				      FIB_SOURCE_SR);
+	    }
+	  /* Remove all the locks for this ones... */
+	  internal_label_unlock_co (steer_pl->next_hop, color,
+				    steer_pl->co_bits);
+	}
+    }
+  else				//Remove by BSID
+    {
+      if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
+	{
+	  pfx.fp_proto = FIB_PROTOCOL_IP6;
+	  pfx.fp_len = steer_pl->classify.mask_width;
+	  pfx.fp_addr.ip6 = steer_pl->classify.prefix.ip6;
+	  fib_table_entry_delete (fib_table_find
+				  (FIB_PROTOCOL_IP6,
+				   steer_pl->classify.fib_table), &pfx,
+				  FIB_SOURCE_SR);
+	}
+      else if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
+	{
+	  pfx.fp_proto = FIB_PROTOCOL_IP4;
+	  pfx.fp_len = steer_pl->classify.mask_width;
+	  pfx.fp_addr.ip4 = steer_pl->classify.prefix.ip4;
+	  fib_table_entry_delete (fib_table_find
+				  (FIB_PROTOCOL_IP4,
+				   steer_pl->classify.fib_table), &pfx,
+				  FIB_SOURCE_SR);
+	}
+    }
+  /* Delete SR steering policy entry */
+  pool_put (sm->steer_policies, steer_pl);
+  mhash_unset (&sm->sr_steer_policies_hash, &key, NULL);
+  if (mhash_elts (&sm->sr_steer_policies_hash) == 0)
+    {
+      mhash_free (&sm->sr_steer_policies_hash);
+      sm->sr_steer_policies_hash.hash = NULL;
+    }
   return 0;
 }
 
@@ -275,17 +660,19 @@
 {
   int is_del = 0;
 
-  ip46_address_t prefix;
+  ip46_address_t prefix, nh;
   u32 dst_mask_width = 0;
   u8 traffic_type = 0;
-  u32 fib_table = (u32) ~ 0;
+  u8 nh_type = 0;
+  u32 fib_table = (u32) ~ 0, color = (u32) ~ 0;
+  u32 co_bits = 0;
 
-  mpls_label_t bsid;
-  u32 sr_policy_index = (u32) ~ 0;
+  mpls_label_t bsid, vpn_label = (u32) ~ 0;
 
   u8 sr_policy_set = 0;
 
   memset (&prefix, 0, sizeof (ip46_address_t));
+  memset (&nh, 0, sizeof (ip46_address_t));
 
   int rv;
   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
@@ -301,15 +688,27 @@
 			    &prefix.ip4, &dst_mask_width))
 	traffic_type = SR_STEER_IPV4;
       else if (!sr_policy_set
-	       && unformat (input, "via sr policy index %d",
-			    &sr_policy_index))
-	sr_policy_set = 1;
-      else if (!sr_policy_set
 	       && unformat (input, "via sr policy bsid %U",
 			    unformat_mpls_unicast_label, &bsid))
 	sr_policy_set = 1;
+      else if (!sr_policy_set
+	       && unformat (input, "via next-hop %U color %d co %d",
+			    unformat_ip4_address, &nh.ip4, &color, &co_bits))
+	{
+	  sr_policy_set = 1;
+	  nh_type = SR_STEER_IPV4;
+	}
+      else if (!sr_policy_set
+	       && unformat (input, "via next-hop %U color %d co %d",
+			    unformat_ip6_address, &nh.ip6, &color, &co_bits))
+	{
+	  sr_policy_set = 1;
+	  nh_type = SR_STEER_IPV6;
+	}
       else if (fib_table == (u32) ~ 0
 	       && unformat (input, "fib-table %d", &fib_table));
+      else if (unformat (input, "vpn-label %U",
+			 unformat_mpls_unicast_label, &vpn_label));
       else
 	break;
     }
@@ -333,10 +732,19 @@
       ip6_address_mask (&prefix.ip6, &mask);
     }
 
-  rv =
-    sr_mpls_steering_policy (is_del, bsid,
-			     sr_policy_index, fib_table, &prefix,
-			     dst_mask_width, traffic_type);
+  if (nh_type)
+    bsid = (u32) ~ 0;
+
+  if (is_del)
+    rv =
+      sr_mpls_steering_policy_del (&prefix, dst_mask_width,
+				   traffic_type, fib_table, color);
+
+  else
+    rv =
+      sr_mpls_steering_policy_add (bsid, fib_table, &prefix, dst_mask_width,
+				   traffic_type, &nh, nh_type, color, co_bits,
+				   vpn_label);
 
   switch (rv)
     {
@@ -347,17 +755,13 @@
     case -1:
       return clib_error_return (0, "Incorrect API usage.");
     case -2:
-      return clib_error_return (0,
-				"The requested SR policy could not be located. Review the BSID/index.");
+      return clib_error_return (0, "The Next-Hop does not match.");
     case -3:
-      return clib_error_return (0,
-				"Unable to do SW redirect. Incorrect interface.");
+      return clib_error_return (0, "The color already exists.");
     case -4:
-      return clib_error_return (0,
-				"The requested SR steering policy could not be deleted.");
+      return clib_error_return (0, "The co-bits do not match.");
     case -5:
-      return clib_error_return (0,
-				"The SR policy is not an encapsulation one.");
+      return clib_error_return (0, "The VPN-labels do not match.");
     default:
       return clib_error_return (0, "BUG: sr steer policy returns %d", rv);
     }
@@ -365,17 +769,19 @@
 }
 
 /* *INDENT-OFF* */
-VLIB_CLI_COMMAND (sr_mpls_steer_policy_command, static) = {
+VLIB_CLI_COMMAND(sr_mpls_steer_policy_command, static)=
+{
   .path = "sr mpls steer",
-  .short_help = "sr mpls steer (del) l3 <ip_addr/mask>"
-    "via sr policy bsid <mpls_label> (fib-table <fib_table_index>)",
-  .long_help =
+    .short_help = "sr mpls steer (del) l3 <ip_addr/mask> "
+    "via [sr policy bsid <mpls_label> || next-hop <ip46_addr> color <u32> co <0|1|2|3> ](fib-table <fib_table_index>)(vpn-label 500)",
+    .long_help =
     "\tSteer L3 traffic through an existing SR policy.\n"
     "\tExamples:\n"
-    "\t\tsr steer l3 2001::/64 via sr_policy index 5\n"
     "\t\tsr steer l3 2001::/64 via sr_policy bsid 29999\n"
-    "\t\tsr steer del l3 2001::/64 via sr_policy index 5\n",
-  .function = sr_mpls_steer_policy_command_fn,
+    "\t\tsr steer del l3 2001::/64 via sr_policy bsid 29999\n"
+    "\t\tsr steer l3 2001::/64 via next-hop 1.1.1.1 color 1234 co 0\n"
+    "\t\tsr steer l3 2001::/64 via next-hop 2001::1 color 1234 co 2 vpn-label 500\n",
+    .function = sr_mpls_steer_policy_command_fn,
 };
 /* *INDENT-ON* */
 
@@ -388,43 +794,87 @@
   mpls_sr_steering_policy_t **steer_policies = 0;
   mpls_sr_steering_policy_t *steer_pl;
 
-  mpls_sr_policy_t *pl = 0;
   int i;
 
   vlib_cli_output (vm, "SR MPLS steering policies:");
   /* *INDENT-OFF* */
-  pool_foreach (steer_pl, sm->steer_policies, ({vec_add1(steer_policies, steer_pl);}));
+  pool_foreach(steer_pl, sm->steer_policies, ({
+    vec_add1(steer_policies, steer_pl);
+  }));
   /* *INDENT-ON* */
-  vlib_cli_output (vm, "Traffic\t\tSR policy BSID");
   for (i = 0; i < vec_len (steer_policies); i++)
     {
+      vlib_cli_output (vm, "==========================");
       steer_pl = steer_policies[i];
-      pl = pool_elt_at_index (sm->sr_policies, steer_pl->sr_policy);
       if (steer_pl->classify.traffic_type == SR_STEER_IPV4)
 	{
-	  vlib_cli_output (vm, "L3 %U/%d\t%U",
+	  vlib_cli_output (vm, "Prefix: %U/%d via:",
 			   format_ip4_address,
 			   &steer_pl->classify.prefix.ip4,
-			   steer_pl->classify.mask_width,
-			   format_mpls_unicast_label, pl->bsid);
+			   steer_pl->classify.mask_width);
 	}
       else if (steer_pl->classify.traffic_type == SR_STEER_IPV6)
 	{
-	  vlib_cli_output (vm, "L3 %U/%d\t%U",
+	  vlib_cli_output (vm, "Prefix: %U/%d via:",
 			   format_ip6_address,
 			   &steer_pl->classify.prefix.ip6,
-			   steer_pl->classify.mask_width,
-			   format_mpls_unicast_label, pl->bsid);
+			   steer_pl->classify.mask_width);
+	}
+
+      if (steer_pl->bsid != (u32) ~ 0)
+	{
+	  vlib_cli_output (vm, "· BSID %U",
+			   format_mpls_unicast_label, steer_pl->bsid);
+	}
+      else
+	{
+	  if (steer_pl->nh_type == SR_STEER_IPV4)
+	    {
+	      vlib_cli_output (vm, "· Next-hop %U",
+			       format_ip4_address, &steer_pl->next_hop.ip4);
+	    }
+	  else if (steer_pl->nh_type == SR_STEER_IPV6)
+	    {
+	      vlib_cli_output (vm, "· Next-hop %U",
+			       format_ip6_address, &steer_pl->next_hop.ip6);
+	    }
+
+	  u32 *color_i = 0;
+	  u8 *s = NULL;
+	  s = format (s, "[ ");
+	  vec_foreach (color_i, steer_pl->color)
+	  {
+	    s = format (s, "%d, ", *color_i);
+	  }
+	  s = format (s, "\b\b ]");
+	  vlib_cli_output (vm, "· Color %s", s);
+
+	  switch (steer_pl->co_bits)
+	    {
+	    case SR_TE_CO_BITS_00:
+	      vlib_cli_output (vm, "· CO-bits: 00");
+	      break;
+	    case SR_TE_CO_BITS_01:
+	      vlib_cli_output (vm, "· CO-bits: 01");
+	      break;
+	    case SR_TE_CO_BITS_10:
+	      vlib_cli_output (vm, "· CO-bits: 10");
+	      break;
+	    case SR_TE_CO_BITS_11:
+	      vlib_cli_output (vm, "· CO-bits: 11");
+	      break;
+	    }
 	}
     }
   return 0;
 }
 
 /* *INDENT-OFF* */
-VLIB_CLI_COMMAND (show_sr_mpls_steering_policies_command, static) = {
+VLIB_CLI_COMMAND(show_sr_mpls_steering_policies_command, static)=
+{
   .path = "show sr mpls steering policies",
-  .short_help = "show sr mpls steering policies",
-  .function = show_sr_mpls_steering_policies_command_fn,
+    .short_help = "show sr mpls steering policies",
+    .function = show_sr_mpls_steering_policies_command_fn,
 };
 /* *INDENT-ON* */
 
@@ -434,20 +884,20 @@
   mpls_sr_main_t *sm = &sr_mpls_main;
 
   /* Init memory for function keys */
-  mhash_init (&sm->sr_steer_policies_hash, sizeof (uword),
-	      sizeof (sr_mpls_steering_key_t));
+  sm->sr_steer_policies_hash.hash = NULL;
+
+  sm->fib_table_EC = (u32) ~ 0;
+  sm->ec_labels = 0;
 
   return 0;
 }
 
 /* *INDENT-OFF* */
-VLIB_INIT_FUNCTION (sr_mpls_steering_init);
+VLIB_INIT_FUNCTION(sr_mpls_steering_init);
 /* *INDENT-ON* */
 
 /*
-* fd.io coding-style-patch-verification: ON
-*
-* Local Variables:
-* eval: (c-set-style "gnu")
-* End:
-*/
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables: eval: (c-set-style "gnu") End:
+ */
diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h
index ccd464f..4ff34a3 100644
--- a/src/vnet/vnet_all_api_h.h
+++ b/src/vnet/vnet_all_api_h.h
@@ -1,28 +1,28 @@
 /*
- *------------------------------------------------------------------
+ * ------------------------------------------------------------------
  * vl_memory_api_h.h - memory API headers, in a specific order.
  *
- * Copyright (c) 2009-2010 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
+ * Copyright (c) 2009-2010 Cisco and/or its affiliates. Licensed under the
+ * Apache License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of the
+ * License at:
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *------------------------------------------------------------------
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ * ------------------------------------------------------------------
  */
 
 /*
- * Add to the bottom of the #include list, or elves will steal your
- * keyboard in the middle of the night!
+ * Add to the bottom of the #include list, or elves will steal your keyboard
+ * in the middle of the night!
  *
- * Include current layer (2) last, or an artistic disagreement
- * about message numbering will occur
+ * Include current layer (2) last, or an artistic disagreement about message
+ * numbering will occur
  */
 
 #ifndef included_from_layer_3
@@ -54,6 +54,7 @@
 #include <vnet/session/session.api.h>
 #include <vnet/mpls/mpls.api.h>
 #include <vnet/srv6/sr.api.h>
+#include <vnet/srmpls/sr_mpls.api.h>
 #include <vnet/classify/classify.api.h>
 #include <vnet/flow/flow.api.h>
 #include <vnet/dhcp/dhcp.api.h>
@@ -71,7 +72,5 @@
 /*
  * fd.io coding-style-patch-verification: ON
  *
- * Local Variables:
- * eval: (c-set-style "gnu")
- * End:
+ * Local Variables: eval: (c-set-style "gnu") End:
  */