openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

l3.c (10773B)


      1 
      2 /*
      3  * 
      4  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      5  * 
      6  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      7  *
      8  * File:    l3.c
      9  * Purpose: Common L3 API
     10  */
     11 
     12 #include <soc/defs.h>
     13 
     14 #include <sal/core/libc.h>
     15 
     16 #include <soc/drv.h>
     17 #include <soc/mem.h>
     18 #include <soc/util.h>
     19 #include <soc/debug.h>
     20 
     21 #include <bcm/l2.h>
     22 #include <bcm/l3.h>
     23 #include <bcm/tunnel.h>
     24 #include <bcm/port.h>
     25 #include <bcm/error.h>
     26 #include <bcm/vlan.h>
     27 #include <bcm/rate.h>
     28 #include <bcm/ipmc.h>
     29 #include <bcm/stack.h>
     30 #include <bcm/topo.h>
     31 #include <bcm/debug.h>
     32 #include <bcm/types.h>
     33 #include <bcm/stat.h>
     34 
     35 #ifdef BCM_ESW_SUPPORT
     36 #include <bcm_int/esw/l3.h>
     37 #endif
     38 /*
     39  * Function:
     40  *      bcm_ip6_mask_create
     41  * Purpose:
     42  *      Create IPv6 network address from prefix length
     43  * Parameters:
     44  *      ip6 - (OUT) IPv6 address holder
     45  *      len - the prefix/mask length
     46  * Returns:
     47  *      none
     48  */
     49 
     50 int
     51 bcm_ip6_mask_create(bcm_ip6_t ip6, int len)
     52 {
     53     return _shr_ip6_mask_create(ip6, len);
     54 }
     55 
     56 /*
     57  * Function:
     58  *      bcm_ip6_mask_length
     59  * Purpose:
     60  *      Return the mask length from IPv6 network address
     61  * Parameters: 
     62  *      mask - IPv6 address
     63  * Returns:
     64  *      The prefix/mask length
     65  */
     66 
     67 int
     68 bcm_ip6_mask_length(bcm_ip6_t mask)
     69 {
     70     return _shr_ip6_mask_length(mask);
     71 }
     72 
     73 
     74 /*
     75  * Function:
     76  *      bcm_ip_mask_create
     77  * Purpose:
     78  *      Create IPv4 network address from prefix length
     79  * Parameters:
     80  *      len - the prefix/mask length
     81  * Returns:
     82  *      The IPv4 mask
     83  */
     84 
     85 bcm_ip_t
     86 bcm_ip_mask_create(int len)
     87 {
     88     return _shr_ip_mask_create(len);
     89 }
     90 
     91 /*
     92  * Function:
     93  *      bcm_ip_mask_length
     94  * Purpose:
     95  *      Return the mask length from IPv4 network address
     96  * Parameters:
     97  *      mask - The IPv4 mask as IP address
     98  * Returns:
     99  *      The IPv4 mask length
    100  */
    101 
    102 int
    103 bcm_ip_mask_length(bcm_ip_t mask)
    104 {
    105     return _shr_ip_mask_length(mask);
    106 }
    107 
    108 #ifdef INCLUDE_L3
    109 /*
    110  * Function:
    111  *      bcm_l3_intf_t_init
    112  * Purpose:
    113  *      Initialize a L3 interface struct
    114  * Parameters:
    115  *      intf - pointer to the L3 interface struct
    116  * Returns:
    117  *      NONE
    118  */
    119 
    120 void
    121 bcm_l3_intf_t_init(bcm_l3_intf_t *intf)
    122 {
    123     if (NULL != intf) {
    124         sal_memset(intf, 0, sizeof (*intf));
    125         intf->l3a_vrf = BCM_L3_VRF_DEFAULT;
    126     }
    127     return;
    128 }
    129 
    130 /*
    131  * Function:
    132  *      bcm_l3_intf_qos_t_init
    133  * Purpose:
    134  *      Initialize a bcm_l3_intf_qos_t structure
    135  * Parameters:
    136  *      intf_qos - pointer to the bcm_l3_intf_qos_t struct
    137  * Returns:
    138  *      NONE
    139  */
    140 
    141 void
    142 bcm_l3_intf_qos_t_init(bcm_l3_intf_qos_t *intf_qos)
    143 {
    144     if (NULL != intf_qos) {
    145         sal_memset(intf_qos, 0, sizeof (*intf_qos));
    146     }
    147     return;
    148 }
    149 
    150 /*
    151  * Function:
    152  *      bcm_l3_host_t_init
    153  * Purpose:
    154  *      Initialize a L3 IP struct
    155  * Parameters:
    156  *      ip - pointer to the L3 IP struct
    157  * Returns:
    158  *      NONE
    159  */
    160 
    161 void
    162 bcm_l3_host_t_init(bcm_l3_host_t *ip)
    163 {
    164     if (NULL != ip) {
    165         sal_memset(ip, 0, sizeof (*ip));
    166         ip->l3a_vrf = BCM_L3_VRF_DEFAULT;
    167     }
    168     return;
    169 }
    170 
    171 /* 
    172  * Function:
    173  *      bcm_l3_route_t_init
    174  * Purpose:
    175  *      Initialize a L3 route struct
    176  * Parameters: 
    177  *      route - pointer to the L3 route struct
    178  * Returns:
    179  *      NONE
    180  */
    181 
    182 void
    183 bcm_l3_route_t_init(bcm_l3_route_t *route)
    184 {
    185     if (NULL != route) {
    186         sal_memset(route, 0, sizeof (*route));
    187         route->l3a_vrf = BCM_L3_VRF_DEFAULT;
    188         route->l3a_rp = BCM_IPMC_RP_ID_INVALID;
    189     }
    190     return;
    191 }
    192 
    193 /* 
    194  * Function:
    195  *      bcm_l3_egress_t_init
    196  * Purpose:
    197  *      Initialize a L3 egress object  struct.
    198  * Parameters: 
    199  *      egr - pointer to the L3 egress object struct.
    200  * Returns:
    201  *      NONE
    202  */
    203 void
    204 bcm_l3_egress_t_init(bcm_l3_egress_t *egr)
    205 {
    206     if (NULL != egr) {
    207         sal_memset(egr, 0, sizeof (*egr));
    208         egr->mpls_label = BCM_MPLS_LABEL_INVALID;
    209         egr->dynamic_scaling_factor =
    210             BCM_L3_ECMP_DYNAMIC_SCALING_FACTOR_INVALID;
    211         egr->dynamic_load_weight =
    212             BCM_L3_ECMP_DYNAMIC_LOAD_WEIGHT_INVALID;
    213         egr->dynamic_queue_size_weight =
    214             BCM_L3_ECMP_DYNAMIC_QUEUE_SIZE_WEIGHT_INVALID;
    215         egr->counting_profile = BCM_STAT_LIF_COUNTING_PROFILE_NONE;
    216         egr->vlan_port_id = BCM_GPORT_INVALID;
    217     }
    218     return;
    219 }
    220 
    221 /* 
    222  * Function:
    223  *      bcm_l3_ingress_t_init
    224  * Purpose:
    225  *      Initialize a L3 egress object  struct.
    226  * Parameters: 
    227  *      egr - pointer to the L3 egress object struct.
    228  * Returns:
    229  *      NONE
    230  */
    231 void
    232 bcm_l3_ingress_t_init(bcm_l3_ingress_t *ing_intf)
    233 {
    234     if (NULL != ing_intf) {
    235         sal_memset(ing_intf, 0, sizeof (*ing_intf));
    236     }
    237     return;
    238 }
    239 
    240 /*
    241  * Function:
    242  *      bcm_l3_ecmp_dlb_mon_t_init
    243  * Purpose:
    244  *      Initialize DLB flow monitoring configuration struct
    245  * Parameters:
    246  *      dlb_mon_cfg - pointer to DLB flow monitoring configuration struct
    247  * Returns:
    248  *      NONE
    249  */
    250 
    251 void
    252 bcm_l3_ecmp_dlb_mon_cfg_t_init(bcm_l3_ecmp_dlb_mon_cfg_t *dlb_mon_cfg)
    253 {
    254     if (NULL != dlb_mon_cfg) {
    255         sal_memset(dlb_mon_cfg, 0, sizeof (*dlb_mon_cfg));
    256     }
    257     return;
    258 }
    259 
    260 /*
    261  * Function:
    262  *      bcm_tunnel_initiator_t_init
    263  * Purpose:
    264  *      Initialize a tunnel initiator object struct.
    265  * Parameters:
    266  *      tunnel - pointer to the tunnel initiator object struct.
    267  * Returns:
    268  *      NONE
    269  */
    270 void
    271 bcm_tunnel_initiator_t_init(bcm_tunnel_initiator_t *tunnel_init)
    272 {
    273     if (tunnel_init != NULL) {
    274         sal_memset(tunnel_init, 0, sizeof (*tunnel_init));
    275         tunnel_init->outlif_counting_profile = BCM_STAT_LIF_COUNTING_PROFILE_NONE;
    276         tunnel_init->egress_qos_model.egress_qos = bcmQosEgressModelPipeNextNameSpace;
    277         tunnel_init->egress_qos_model.egress_ttl = bcmQosEgressModelPipeMyNameSpace;
    278     }
    279     return;
    280 }
    281 
    282 /*
    283  * Function:
    284  *      bcm_tunnel_terminator_t_init
    285  * Purpose:
    286  *      Initialize a tunnel terminator object struct.
    287  * Parameters:
    288  *      tunnel - pointer to the tunnel terminator object struct.
    289  * Returns:
    290  *      NONE
    291  */
    292 void
    293 bcm_tunnel_terminator_t_init(bcm_tunnel_terminator_t *tunnel_term)
    294 {
    295     if (tunnel_term != NULL) {
    296         sal_memset(tunnel_term, 0, sizeof (*tunnel_term));
    297         tunnel_term->vrf = BCM_L3_VRF_DEFAULT;
    298         tunnel_term->tunnel_if = BCM_IF_INVALID;
    299         tunnel_term->inlif_counting_profile = BCM_STAT_LIF_COUNTING_PROFILE_NONE;
    300     }
    301     return;
    302 }
    303 
    304 /*
    305  * Function:
    306  *      bcm_tunnel_config_t_init
    307  * Purpose:
    308  *      Initialize a tunnel config object struct.
    309  * Parameters:
    310  *      tunnel - pointer to the tunnel config object struct.
    311  * Returns:
    312  *      NONE
    313  */
    314 void
    315 bcm_tunnel_config_t_init(bcm_tunnel_config_t *tconfig)
    316 {
    317     if (tconfig != NULL) {
    318         sal_memset(tconfig, 0, sizeof (*tconfig));
    319     }
    320     return;
    321 }
    322 
    323 /*
    324  * Function:
    325  *      bcm_l3_key_t_init
    326  * Purpose:
    327  *      Initialize a L3 key object struct.
    328  * Parameters:
    329  *      key - pointer to the L3 key object struct.
    330  * Returns:
    331  *      NONE
    332  */
    333 void
    334 bcm_l3_key_t_init(bcm_l3_key_t *key)
    335 {
    336     if (key != NULL) {
    337         sal_memset(key, 0, sizeof (*key));
    338         key->l3k_vrf = BCM_L3_VRF_DEFAULT;
    339     }
    340     return;
    341 }
    342 
    343 /*
    344  * Function:
    345  *      bcm_tunnel_dscp_map_t_init
    346  * Purpose:
    347  *      Initialize a dscp map object struct.
    348  * Parameters:
    349  *      dscp_info - pointer to the dscp map object struct.
    350  * Returns:
    351  *      NONE
    352  */
    353 void
    354 bcm_tunnel_dscp_map_t_init(bcm_tunnel_dscp_map_t *dscp_info)
    355 {
    356     if (dscp_info != NULL) {
    357         sal_memset(dscp_info, 0, sizeof (*dscp_info));
    358     }
    359     return;
    360 }
    361 
    362 /*
    363  * Function:
    364  *      bcm_l3_info_t_init
    365  * Purpose:
    366  *      Initialize a L3 info object struct.
    367  * Parameters:
    368  *      info - pointer to the L3 info object struct.
    369  * Returns:
    370  *      NONE
    371  */
    372 void
    373 bcm_l3_info_t_init(bcm_l3_info_t *info)
    374 {
    375     if (info != NULL) {
    376         sal_memset(info, 0, sizeof (*info));
    377     }
    378     return;
    379 }
    380 
    381 /*
    382  * Function:
    383  *      bcm_l3_source_bind_t_init
    384  * Purpose:
    385  *      Initialize a bcm_l3_source_bind_t structure.
    386  * Parameters:
    387  *      info - (IN/OUT) L3 source binding information
    388  * Returns:
    389  *      BCM_E_XXX
    390  * Notes:
    391  */
    392 void 
    393 bcm_l3_source_bind_t_init(bcm_l3_source_bind_t *info)
    394 {
    395     if (info != NULL) {
    396         sal_memset(info, 0, sizeof (*info));
    397         info->port = BCM_GPORT_INVALID; /* Wildcard port by default */
    398     }
    399     return;
    400 }
    401 
    402 /* 
    403  * Function:
    404  *      bcm_l3_egress_ecmp_t_init
    405  * Purpose:
    406  *      Initialize a L3 egress ecmp object struct.
    407  * Parameters: 
    408  *      ecmp - pointer to the L3 egress ecmp object struct.
    409  * Returns:
    410  *      NONE
    411  */
    412 void
    413 bcm_l3_egress_ecmp_t_init(bcm_l3_egress_ecmp_t *ecmp)
    414 {
    415     if (NULL != ecmp) {
    416         sal_memset(ecmp, 0, sizeof (*ecmp));
    417     }
    418     return;
    419 }
    420 
    421 /* 
    422  * Function:
    423  *      bcm_l3_ecmp_member_t_init
    424  * Purpose:
    425  *      Initialize a L3 ecmp member struct.
    426  * Parameters: 
    427  *      ecmp_member - pointer to the L3 egress ecmp member's struct.
    428  * Returns:
    429  *      NONE
    430  */
    431 void
    432 bcm_l3_ecmp_member_t_init(bcm_l3_ecmp_member_t *ecmp_member)
    433 {
    434     if (NULL != ecmp_member) {
    435         sal_memset(ecmp_member, 0, sizeof (*ecmp_member));
    436     }
    437     return;
    438 }
    439 
    440 /*
    441  * Function:
    442  *      bcm_l3_egress_multi_info_t_init
    443  * Purpose:
    444  *      Initialize L3 Egress multi group struct.
    445  * Parameters:
    446  *      ecmp_member - pointer to l3 egress multi struct.
    447  * Returns:
    448  *      NONE
    449  */
    450 void
    451 bcm_l3_egress_multi_info_t_init(bcm_l3_egress_multi_info_t *egress_multi_info)
    452 {
    453     if (NULL != egress_multi_info) {
    454         sal_memset(egress_multi_info, 0, sizeof (*egress_multi_info));
    455     }
    456     return;
    457 }
    458 
    459 /*
    460  * Function:
    461  *      bcm_tunnel_terminator_config_key_t_init
    462  * Purpose:
    463  *      Initialize a tunnel L3 tunnel bcm_tunnel_terminator_config_key_t structure.
    464  * Parameters:
    465  *      config_key - pointer to l3 tunnel terminator config key struct.
    466  * Returns:
    467  *      NONE
    468  */
    469 void 
    470 bcm_tunnel_terminator_config_key_t_init(bcm_tunnel_terminator_config_key_t *config_key) {
    471     if (NULL != config_key) {
    472         sal_memset(config_key, 0, sizeof (*config_key));
    473     }
    474     return;
    475 }
    476 
    477 /*
    478  * Function:
    479  *      tunnel_terminator_config_action_t_init
    480  * Purpose:
    481  *      Initialize a tunnel L3 tunnel tunnel_terminator_config_action_t structure.
    482  * Parameters:
    483  *      ecmp_member - pointer to l3 tunnel terminator config action struct.
    484  * Returns:
    485  *      NONE
    486  */
    487 void 
    488 bcm_tunnel_terminator_config_action_t_init(bcm_tunnel_terminator_config_action_t *config_action) {
    489     if (NULL != config_action) {
    490         sal_memset(config_action, 0, sizeof (*config_action));
    491     }
    492     return;
    493 }
    494 
    495 /*
    496  * Function:
    497  *      bcm_l3_vpbr_entry_t_init
    498  * Purpose:
    499  *      Initialize a bcm_l3_vpbr_entry_t structure.
    500  * Parameters:
    501  *      vpbr_info
    502  * Returns:
    503  *      NONE
    504  */
    505 void 
    506 bcm_l3_vpbr_entry_t_init(bcm_l3_vpbr_entry_t *vpbr_info) 
    507 {
    508     if (NULL != vpbr_info) {
    509         sal_memset(vpbr_info, 0, sizeof (*vpbr_info));
    510     }
    511     return;
    512 }
    513 
    514 #endif   /* INCLUDE_L3 */