/*****************************************************************//**
* \brief Include all ports to default vlan
*
* \param unit   [IN]    unit number
*
* \return OPENNSL_E_XXX     OpenNSL API return code
  ********************************************************************/
int switch_default_vlan_config(int unit)
{
  opennsl_port_config_t pcfg;
  opennsl_pbmp_t upbm;
  int rv;

  OPENNSL_PBMP_CLEAR(upbm);
  /*
   * Create VLAN with id DEFAULT_VLAN and
   * add ethernet ports to the VLAN
   */
  rv = opennsl_port_config_get(unit, &pcfg);
  if (rv != OPENNSL_E_NONE) {
    printf("Failed to get port configuration. Error %s\n", opennsl_errmsg(rv));
    return rv;
  }

  rv = opennsl_vlan_port_add(unit, DEFAULT_VLAN, pcfg.e, upbm);
  if (rv != OPENNSL_E_NONE) {
    printf("Failed to add ports to VLAN. Error %s\n", opennsl_errmsg(rv));
    return rv;
  }

  return 0;
}
Пример #2
0
void BcmPort::enable(const std::shared_ptr<Port>& swPort) {
  if (isEnabled()) {
    // Port is already enabled, don't need to do anything
    return;
  }

  auto pbmp = getPbmp();
  opennsl_pbmp_t emptyPortList;
  OPENNSL_PBMP_CLEAR(emptyPortList);
  int rv;
  for (auto entry : swPort->getVlans()) {
    if (!entry.second.tagged) {
      rv = opennsl_vlan_port_add(unit_, entry.first, pbmp, pbmp);
    } else {
      rv = opennsl_vlan_port_add(unit_, entry.first, pbmp, emptyPortList);
    }
    bcmCheckError(rv, "failed to add enabled port ",
                  swPort->getID(), " to VLAN ", entry.first);
  }

  // Drop packets to/from this port that are tagged with a VLAN that this
  // port isn't a member of.
  rv = opennsl_port_vlan_member_set(unit_, port_,
                                    OPENNSL_PORT_VLAN_MEMBER_INGRESS |
                                    OPENNSL_PORT_VLAN_MEMBER_EGRESS);
  bcmCheckError(rv, "failed to set VLAN filtering on port ",
                swPort->getID());

  // Set the speed and ingress vlan before enabling
  program(swPort);

  // Enable packet and byte counter statistic collection.
  rv = opennsl_port_stat_enable_set(unit_, gport_, true);
  if (rv != OPENNSL_E_EXISTS) {
    // Don't throw an error if counter collection is already enabled
    bcmCheckError(rv, "Unexpected error enabling counter DMA on port ",
                  swPort->getID());
  }

  // Enable linkscan
  rv = opennsl_linkscan_mode_set(unit_, port_, OPENNSL_LINKSCAN_MODE_SW);
  bcmCheckError(rv, "Failed to enable linkscan on port ", swPort->getID());

  rv = opennsl_port_enable_set(unit_, port_, true);
  bcmCheckError(rv, "failed to enable port ", swPort->getID());
}
Пример #3
0
/**************************************************************************//**
 * \brief To add a given set of ports and VLAN to spanning tree instance.
 *
 * \param    unit      [IN] Unit number.
 * \param    *info     [IN] Pointer to a location where STG information
 *                          is stored
 *
 * \return      OPENNSL_E_xxx  OpenNSL API return code
 *****************************************************************************/
int example_stg_create(int unit, stg_info_s *info) {
  int rv;
  opennsl_pbmp_t pbmp;

  /* create VLAN */
  rv = opennsl_vlan_create(DEFAULT_UNIT, info->vlan_1);
  if (rv != OPENNSL_E_NONE) {
    printf("Error, in opennsl_vlan_create, vid=%d, \n", info->vlan_1);
    return rv;
  }

  if(verbose >= 2) {
    printf("VLAN %d is created.\n", info->vlan_1);
  }

  OPENNSL_PBMP_CLEAR(pbmp);
  OPENNSL_PBMP_PORT_ADD(pbmp, info->port_1);
  OPENNSL_PBMP_PORT_ADD(pbmp, info->port_2);

  rv = opennsl_vlan_port_add(unit, info->vlan_1, pbmp, pbmp);
  if (rv != OPENNSL_E_NONE) {
    printf("OPENNSL FAIL %d: %s\n", rv, opennsl_errmsg(rv));
    return rv;
  }

  if(verbose >= 2) {
    printf("Added ports %d, %d to VLAN %d.\n",
           info->port_1, info->port_2, info->vlan_1);
  }

  /* add the vlans to the stg */
  rv = opennsl_stg_vlan_add(unit, info->stg, info->vlan_1);
  if (rv != OPENNSL_E_NONE) {
    printf("Error, in opennsl_stg_vlan_add, vid=%d, \n", info->vlan_1);
    return rv;
  }

  if(verbose >= 2) {
    printf("Attached VLAN %d to Spanning Tree Group %d.\n",
           info->vlan_1, info->stg);
  }

  /* add two ports to the stg and attach stp state for each of them */
  rv = opennsl_stg_stp_set(unit, info->stg, info->port_1, info->stp_state_1);
  if (rv != OPENNSL_E_NONE) {
    printf("Error, in opennsl_stg_stp_set, stg=%d, \n", info->stg);
    return rv;
  }

  if(verbose >= 2) {
    printf("STP state of port %d is set to \"%s\".\n", 
           info->port_1, stp_state_str[info->stp_state_1]);
  }

  rv = opennsl_stg_stp_set(unit, info->stg, info->port_2, info->stp_state_2);
  if (rv != OPENNSL_E_NONE) {
    printf("Error, in opennsl_stg_stp_set, stg=%d, \n", info->stg);
    return rv;
  }
  if(verbose >= 2) {
    printf("STP state of port %d is set to \"%s\".\n",
           info->port_2, stp_state_str[info->stp_state_2]);
  }

  return OPENNSL_E_NONE;
}