文件位置nesting/ieee8021q/queue/transmissionSelectionAlgorithms
主要对CreditBasedShaper中C++代码做了注释
.h头文件
#ifndef __MAIN_CREDITBASEDSHAPER_H_
#define __MAIN_CREDITBASEDSHAPER_H_
#include <omnetpp.h>
#include "inet/common/ModuleAccess.h"
#include "inet/common/packet/Packet.h"
#include "TSAlgorithm.h"
#include "../../Ieee8021q.h"
using namespace omnetpp;
namespace nesting {
/**
* See the NED file for a detailed description.
*/
class CreditBasedShaper: public TSAlgorithm {
protected:
/**
* Enumeration to represent the internal state of the credit-based-shaper transmission selection algorithm. The state can be (1) earning credits, (2)spending credits or (3) staying idle.
* 枚举来表示基于信用的整形器传输选择算法的内部状态。状态可以(1)获得信用值,(2)消耗信用值或(3)保持闲置状态
*/
enum State {
kEarnCredit, kSpendCredit, kIdle //赚取信用(kEarnCredit)、花费信用(kSpendCredit)或保持空闲(kIdle)
};
protected:
/**
* The rate of change of credit as factor of the transmission rate of the Mac module.
* 信用值变化率率作为Mac模块传输速率的因子
*/
double idleSlopeFactor;
/**
* Credit balance.信用值
*/
double credit;
/**
* Internal state.间隔状态
*/
State state;
/**
* Time-stamp when the last state change was performed. This value is used to calculate e.g. earned credits.
* 上次状态更改"执行的时间戳。此值用于计算已获得的信用等信息
*/
simtime_t lastEventTimestamp;
/**
* Self message used to signal the end of a credit spending period.自消息用于信用消耗周期的结束
*/
cMessage endSpendingCreditMessage = cMessage("endSpendingCredit");//这行代码定义了一个名为 “endSpendingCreditMessage” 的变量,类型为 cMessage,
//,它被赋值为一个新创建的 cMessage 对象,这个对象的名称为 “endSpendingCredit结束消耗信用值"
//这个变量被用来发送一个自我消息,以通知模块 credit spend period 的结束。
/**
* Self message used to signal that zero credits are reached. This is necessary because reaching a positive amount of credits can trigger a packet-enqueued event subsequent queuing components.
这是用于向自己发送信号的消息,表示当前的信用已经降低到0。这是必要的,因为达到一定的信用数量可能会触发后续排队组件中的数据包进入排队事件。*/
cMessage reachedZeroCreditMessage = cMessage("reachedZeroCredit");
protected:
/** @copydoc cSimpleModule::initialize() */
virtual void initialize() override;//初始化的功能
/** @copydoc cSimpleModule::handleMessage(cMessage*) */
virtual void handleMessage(cMessage* msg) override;//处理消息
/** @copydoc cSimpleModule::refreshDisplay() const */
virtual void refreshDisplay() const override;//显示收发包的数量
/** This method calculates the idleSlope value in credits per second. 此方法以每秒积分为单位计算累积斜率值*/
virtual double getIdleSlope();
/** This method calculates the sendSlope value in credits per second. 此方法以每秒积分为单位计算减少斜率值*/
virtual double getSendSlope();
/**
* This method returns the associated Mac port transmit rate in bits per second此方法以每秒比特为单位返回关联的Mac端口传输速率.
*/
virtual double getPortTransmitRate();
/**
* For a given credit rate per second and a given time interval, this method calculates the associated amount of credits.
* 对于给定的信用率和给定的时间间隔,此方法计算相关的信用值。
* @param creditPerSecond The rate of earned/spend credit in credits per second. This value must be greater than zero.每秒计算的增加/消耗信贷比率。此值必须大于零。
* @param time The time interval to calculate the earned/spend credits for. This value must be greater or equal than zero.计算增加/消耗信用值的时间间隔。此值必须大于或等于零
* @return The amount of credit earned/generated.
*/
virtual double creditsForTime(doub