<commit_before>/*
 *  Copyright (c) 2004-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */
#include "fboss/agent/hw/bcm/BcmPortGroup.h"
#include "fboss/agent/hw/bcm/BcmSwitch.h"
#include "fboss/agent/hw/bcm/BcmPortTable.h"
#include "fboss/agent/hw/bcm/BcmPort.h"
#include "fboss/agent/hw/bcm/BcmError.h"

#include "fboss/agent/state/Port.h"

extern "C" {
#include <opennsl/port.h>
}

namespace {
using facebook::fboss::BcmPortGroup;
using facebook::fboss::cfg::PortSpeed;
using facebook::fboss::FbossError;
BcmPortGroup::LaneMode neededLaneModeForSpeed(
    PortSpeed speed, PortSpeed maxLaneSpeed) {
  if (speed == PortSpeed::DEFAULT) {
    throw FbossError("Speed cannot be DEFAULT");
  }
  auto neededLanes =
    static_cast<uint32_t>(speed) / static_cast<uint32_t>(maxLaneSpeed);
  if (neededLanes <= 1) {
    return BcmPortGroup::LaneMode::QUAD;
  } else if (neededLanes == 2) {
    return BcmPortGroup::LaneMode::DUAL;
  } else if (neededLanes > 2 && neededLanes <= 4) {
    return BcmPortGroup::LaneMode::SINGLE;
  } else {
    throw FbossError("Cannot support speed ", speed);
  }
}

}

namespace facebook { namespace fboss {

BcmPortGroup::BcmPortGroup(BcmSwitch* hw,
                           BcmPort* controllingPort,
                           std::vector<BcmPort*> allPorts)
    : hw_(hw),
      controllingPort_(controllingPort),
      allPorts_(std::move(allPorts)) {

  if (allPorts_.size() != 4) {
    throw FbossError("Port groups must have exactly four members");
  }

  for (int i = 0; i < allPorts_.size(); ++i) {
    if (getLane(allPorts_[i]) != i) {
      throw FbossError("Ports passed in are not ordered by lane");
    }
  }

  // get the number of active lanes
  auto activeLanes = retrieveActiveLanes();<commit_msg>port group fixes for 6.4.10<commit_after>/*
 *  Copyright (c) 2004-present, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 */
#include "fboss/agent/hw/bcm/BcmPortGroup.h"
#include "fboss/agent/hw/bcm/BcmSwitch.h"
#include "fboss/agent/hw/bcm/BcmPortTable.h"
#include "fboss/agent/hw/bcm/BcmPort.h"
#include "fboss/agent/hw/bcm/BcmError.h"

#include "fboss/agent/state/Port.h"

extern "C" {
#include <opennsl/port.h>
}

namespace {
using facebook::fboss::BcmPortGroup;
using facebook::fboss::cfg::PortSpeed;
using facebook::fboss::FbossError;
BcmPortGroup::LaneMode neededLaneModeForSpeed(
    PortSpeed speed, PortSpeed maxLaneSpeed) {
  if (speed == PortSpeed::DEFAULT) {
    throw FbossError("Speed cannot be DEFAULT");
  }
  auto neededLanes =
    static_cast<uint32_t>(speed) / static_cast<uint32_t>(maxLaneSpeed);
  if (neededLanes <= 1) {
    return BcmPortGroup::LaneMode::QUAD;
  } else if (neededLanes == 2) {
    return BcmPortGroup::LaneMode::DUAL;
  } else if (neededLanes > 2 && neededLanes <= 4) {
    return BcmPortGroup::LaneMode::SINGLE;
  } else {
    throw FbossError("Cannot support speed ", speed);
  }
}

}

namespace facebook { namespace fboss {

BcmPortGroup::BcmPortGroup(BcmSwitch* hw,
                           BcmPort* controllingPort,
                           std::vector<BcmPort*> allPorts)
    : hw_(hw),
      controllingPort_(controllingPort),
      allPorts_(std::move(allPorts)) {

  if (allPorts_.size() != 4) {
    throw FbossError("Port groups must have exactly four members. Found ",
                     allPorts_.size());
  }

  for (int i = 0; i < allPorts_.size(); ++i) {
    if (getLane(allPorts_[i]) != i) {
      throw FbossError("Ports passed in are not ordered by lane");
    }
  }

  // get the number of active lanes
  auto activeLanes = retrieveActiveLanes();
{'fraction_non_alphanumeric': 0.12639682145517755, 'fraction_numerical': 0.007946362056121183, 'mean_word_length': 3.5720771850170263, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5090039', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1374, 'n_words': 339}