# Binary Exponential Backoff

## Summary

When multiple entities attempt to gain access to a shared resource, only one of them will succeed. Those who fail wait till the resource becomes available and then retry. But if everyone were to retry at the same time, quite possibly none of them will succeed. Moreover, new packets are arriving in addition to those waiting for retries.

**Binary Exponential Backoff (BEB)** is an algorithm to determine how long entities should backoff before they retry. With every unsuccessful attempt, the maximum backoff interval is doubled. BEB prevents congestion and reduces the probability of entities requesting access at the same time, thereby improving system efficiency and capacity utilization.

BEB was initially proposed for computer networking where multiple computers share a single medium or channel. It's most famously used in Ethernet and Wi-Fi networking standards.

## Discussion

### Where is binary exponential backoff useful?

BEB is most useful in distributed systems without centralized control or systems that lack predetermined resource allocation. In such systems, multiple entities attempt to access a shared resource. Because there's no centralized control, whoever manages to grab the resource before anyone else will be allowed to use it. Others have to wait for their turn.

The problem is that when the resource becomes available, everyone else will attempt to grab it. This results in delays. Entities spend time trying to resolve the confusion. Resource utilization is therefore not optimal. The problem gets worse when many entities (dozens or hundreds) are involved.

BEB is an algorithm that mitigates this problem. BEB is therefore useful in probabilistic systems. It's not useful in deterministic systems where the resource is allocated by a controller, each entity knows its turn and will use the resource at specific times and durations as allocated.

### Could you explain how BEB works?

Consider Wi-Fi as an example. Two Wi-Fi stations Sue and Mira want to send data to Arnold. When the stations access the channel at the same time, we say that it's a **collision**. Stations whose packets have just collided will initiate a backoff procedure. Every station maintains a number called **Contention Window (CW)**. The station will choose a random value within this window. This value, which is really the number of idle transmission slots that the station has to wait, is called the **Backoff Period**. During this period, these stations (Sue and Mira) cannot transmit.

The essence of BEB is that the backoff period is randomly selected within the CW. Each station will potentially have a different waiting time. They can't transmit until the backoff period has passed. Moreover, when another station gains access, backoff timer is paused. It's resumed only when the channel becomes idle again as determined by *Distributed Interframe Space (DIFS)*.

With every collision, the station will double its CW. This is why the prefix "binary exponential" is used. It's common to have minimum and maximum values for CW.

### Could you share some facts or details about BEB?

BEB doesn't eliminate collisions. By staggering the channel access due to random backoff, it reduces the *probability of collision*. It's possible that two nodes that collide may backoff the same amount and collide again when they retry. Collision can also happen with nodes that collided long ago and whose backoff just completed.

It may be argued that randomizing the backoff with every retry is enough to lower the collision probability. Why do we need to double the contention window (CW)? This is because new packets are getting generated and need to be transmitted in addition to collided packets. If CW is not increased, we'll have network congestion with more nodes vying for the channel within the same time. However, doubling the CW is not optimal when network load is low.

Often minimum CW is non-zero, so that retrying nodes backoff at least some amount before retrying. Likewise, there's a maximum CW so that nodes are not starved due to long backoff periods.

### What are some well-known applications of BEB?

Medium Access Control (MAC) layer of networking protocols use BEB. For example, both Ethernet and Wi-Fi use Truncated BEB to set the contention window. Actual backoff is selected randomly within the contention window. Due to this randomization, the term *Randomized Exponential Backoff* is sometimes used.

Transmission Control Protocol (TCP) is a protocol that guarantees packet delivery by acknowledging correctly received packets. If acknowledgements are not received, the sender will retransmit the packet. Immediate retransmission can potentially congest the network. Hence, the sender uses BEB before retransmitting.

In a mobile ad hoc network, routes are discovered when required. It's possible for an attacker to flood the network with Route Request (RREQ) packets. One defence against this is BEB. RREQ packets that are seen too soon (not obeying BEB backoffs) are dropped.

In network applications, when a request fails due to contention, BEB with jitter is used for retries. Examples include access to AWS DynamoDB, or Google Cloud Storage.

In general, BEB and its variants are used in wired/wireless networks, transactional memory, lock acquisition, email retransmission, congestion control and many cloud computing scenarios.

### What metrics are useful to measure the performance and stability of BEB?

The following metrics are commonly used:

    + **Throughput**: This is the number of packets per second successfully sent over the channel. Algorithm is considered stable if the throughput does not collapse as the offered load goes to infinity. Offered load can be defined as number of nodes waiting to transmit or total packet arrival rate relative to channel capacity.
    + **Delay**: Nodes that experience a collision, backoff and retry later. Delay increases as the channel experiences more packet collisions. Algorithm is considered stable if the delay is bounded.
    + **Call Count**: This is the average number of retries needed to achieve a successful transmission.Other metrics useful during analysis include probability of collision \(p\_c\) and probability that a node will transmit in an arbitrary time slot \(p\_t\). Sometimes BEB is generalized to *exponential backoff*, with a *backoff factor* \(r\). With BEB, \(r\) is set to 2. It's been shown that the optimum backoff factor that maximizes asymptotic throughput is \(1/(1-e^{-1})\).

### What's the Capture Effect that occurs with BEB?

**Capture Effect** points to a lack of fairness for channel access. Nodes that experience collisions will be in their backoff procedures. New nodes entering the system have a higher chance to capture the channel. These new nodes can therefore transmit long sequences of packets while others are waiting for their backoffs to end. Even if old and new nodes collide, newer nodes will have shorter backoff and will therefore gain access more quickly.

Capture effect has been studied for the Ethernet scenario. It was found that the effect is severe for small number of nodes and improves as more nodes contend for the channel. One proposed solution is to use **Capture Avoidance Binary Exponential Backoff (CABEB)**.

Capture effect is different from **starvation effect**. With starvation, some nodes have little chance to transmit while most are able to transmit. With capture effect, a few nodes occupy the channel most of the time.

### What are some variations of BEB?

By definition, BEB simply doubles the backoff with every collision. So two nodes that collide with their first attempt will most likely collide again since their retries coincide. For this reason, an element of randomness is added to the backoff. This could be termed as *jitter*.

Alternatively, nodes could select a random slot within the contention window as standardized in Ethernet or Wi-Fi. In a modified BEB, each successive slot will be selected with a probability of \(1/2^i\) after \(i\) collisions. This means that next retry can potentially happen after \(2^i\) slots.

With **Truncated BEB**, a maximum backoff time is defined so that nodes that experience lots of collisions don't end up waiting longer and longer. However, there may be limit to the maximum number of retries. In Wi-Fi, CW is in the range [23, 1023].

Other variations include continuously listening to the channel and modifying the backoff; tuning the CW based on slot utilization and collision count; increasing the CW with every alternate collision.

## Milestones

1970

Norman Abramson proposes the use of a shared broadcast channel for the ALOHA system. This system would use radio communications to connect computers of the University of Hawaii spread across the islands of Hawaii. The system comes into operation in June 1971. The design of ALOHA didn't define any backoff since it was assumed that both new and retransmitted packets arrive according to a Poisson process.

1973

Leonard Kleinrock and Simon S. Lam propose the first backoff algorithm for multiple access in slotted ALOHA. A uniform random retransmission delay over K slots is proposed. Channel throughput increases with K but when K goes to infinity channel throughput approaches 1/e. In July, Lam shows that with fixed K backoff, slotted ALOHA is unstable. This suggests that K has to be adaptive.

1975

Simon S. Lam and Leonard Kleinrock propose an adaptive backoff algorithm called **Heuristic RCP (Retransmission Control Procedure)**. The idea is to adapt K based on the number of collisions (m) a packet has experienced. If K increases steeply with respect to m, channel saturation won't happen. Binary exponential backoff is a special case of Heuristic RCP where \(K=2^m\).

2005

IEEE publishes IEEE 802.11e, an amendment to the 802.11 standard. This specifies Quality of Service (QoS) enhancements at the MAC layer. It proposes a feature named **Enhanced Distributed Channel Access (EDCA)**. Traffic is categorized by type into an Access Category (AC). Each AC has its own interframe spacing, and minimum and maximum values for the contention window. This is the way traffic is prioritized towards channel access.

Binary Exponential Backoff


# Data Modelling with MongoDB

## Summary

Though MongoDB is schema-less, there's an implied structure and hence a data model.

When designing a data model, developers should ask what data needs to be stored, what data is likely to be accessed together, how often will a piece of data be accessed, and how fast will data grow and will it be unbounded. Answers to these questions will lead to a data model that's right for each application.

In designing the data model, there's no format process, algorithms or rules. Based on years of experience, MongoDB practitioners have come up with a set of **design patterns** and how they fit into common use cases. These are only guidelines. Ultimately, the developer has to analyze the application and see what fits best.

## Discussion

### Given that MongoDB is schema-less, why do we need data modelling?

By being schema-less, we can easily change the structure in which data is stored. Documents in a collection need not conform to a single rigid structure. The trade-off is that by not having a schema and not validating against that schema, software bugs can creep in. When data is stored in many different ways, application complexity increases. Schema is self-documenting and leads to cleaner code. With sophisticated validations, application code can become simpler.

While MongoDB is schema-less, in reality, data is seldom completely unstructured. Most data has some implied structure, though MongoDB may not validate that structure. Even when data evolves over time, there's some base structure that stays constant. Starting from MongoDB 3.2, document validation is possible.

Here are some specific areas where schema helps:

    + When matching on nested document fields, the order of fields matters.
    + Data with a complicated structure is easier to understand and process given the schema.
    + When using an Object Document Manager (ODM), the ODM can benefit from the schema.
    + Frequent changes to the document structure without a schema can cause performance issues.

### What's the difference between embedded data models and normalized data models?

While MongoDB is document-oriented, it stills allows for relations among collections. This is supported by the `$lookup` and `$graphLookup` pipeline operators. When designing a data model, we have to therefore decide if it makes sense to embed information within a document or to keep it in a separate collection.

**Embedded data model** is applicable when there's a "contains" relationship. Reads are performant when there's a need to access nested documents along with the main document. Document can also be updated in a single atomic operation. To model one-to-many relationship, an array of documents can be nested. However, MongoDB limits a document size to 16MB and at most 100 levels of nesting.

**Normalized data model** uses object references to model relationships between documents. Such a model avoids data duplication: a document can be referenced by many other documents without duplicating its content. Complex many-to-many relationships are easily modelled. Likewise, large hierarchical datasets can be modelled. Data can also be referenced across collections.

### How do I define 1-to-1, 1-to-n and n-to-n relationships in MongoDB?

Consider a User document. The person works for only one company. Company field or document is embedded within the User document. This is an example of 1-to-1 relationship.

A person may have multiple addresses, which is a 1-to-n relationship. This is modelled in MongoDB as an array of documents, that is, an array of addresses is embedded into the User document.

Another 1-to-n example is a Product document that contains many Part documents. There could be dozens of parts. It may be necessary to access each part on its own independent of the product. Hence, we might embed into a Product document an array of ObjectID references to the parts. Parts are stored in a separate collection.

Consider a to-do application that assigns tasks to users. A user can have many tasks and a task can be assigned to many users. This is an example of n-to-n relationship. A User document would embed an array of ObjectID references to tasks. A Task document would embed an array of ObjectID references to users.

### Could you share essential tips towards MongoDB schema design?

Embed documents unless there's a good reason not to. Objects that need to be accessed on their own or high-cardinality arrays are compelling reasons not to embed.

Arrays model 1-to-n relationship. If n is few, embed the documents. If n is in the hundreds, embed ObjectID references, called **child referencing**. If n is in the thousands, embed the `1` ObjectID reference from within `n` documents, called **parent referencing**.

Don't shun application-level joins. If data is correctly indexed and results are minimally projected, they're quite efficient.

Consider the **read-to-write ratio**. A high ratio favours denormalization and improves read performance. A field that's updated often is not a good candidate for denormalization since it has to be updated in multiple places.

Analyze your application and its data access patterns. Structure the data to match the application.

### What schema design patterns are available in MongoDB?

We briefly describe each pattern:

    + **Approximation**: Fewer writes and calculations by saving only approximate values.
    + **Attribute**: On large documents, index and query only on a subset of fields.
    + **Bucket**: For streaming data or IoT applications, bucket values to reduce the number of documents. Pre-aggregation (sum, mean) simplifies data access.
    + **Computed**: Avoids repeated computations on reads by doing them at writes or at regular intervals.
    + **Document Versioning**: Allows different versions of documents to coexist.
    + **Extended Reference**: Avoid lots of joins by embedding only frequently accessed fields.
    + **Outlier**: Data model and queries are designed for typical use cases, and not influenced by outliers.
    + **Pre-Allocation**: Reduce memory reallocation and improve performance when document structure is known in advance.
    + **Polymorphic**: Useful when documents are similar but don't have the same structure.
    + **Schema Versioning**: Useful when schema evolves during the application's lifetime. Avoids downtime and technical debt.
    + **Subset**: Useful when only some data is used by application. Smaller dataset will fit into RAM and improve performance.
    + **Tree**: Suited for hierarchical data. Application needs to manage updates to the graph.

### Could you share an example showing the use of MongoDB schema design patterns?

The example in the figure pertains to an e-commerce application. It shows the use of five design patterns among three collections:

    + **Schema Versioning**: Every collection includes an integer field `schema` to store the schema version.
    + **Subset**: Items and reviews are stored as separate collections but since `top_reviews` are frequently accessed from items, these are embedded into items documents. Other reviews are rarely accessed. Another example is `staff` information embedded into stores collection.
    + **Computed**: Since `sum_reviews` and `num_reviews` are frequently accessed, these are pre-computed and stored in reviews. Another example are fields `tot_rating` and `num_ratings` in items collection.
    + **Bucket**: Rather than store each review as a separate document, reviews are bucketed into a time window (`start_date` and `end_date`).
    + **Extended Reference**: Fields part of other collections, but frequently accessed, are duplicated for higher read performance and avoid joins. Fields `sold_at` in items and `items_in_stock` in stores are two examples.

### What are some schema design anti-patterns in MongoDB?

We could have large arrays stored in documents, some of which are unbounded. Storing lots of a data together leads to bloated documents. Storing numerous collections in a database, some of which are unused, is another anti-pattern.

A collection may have many indexes, some of which could be unnecessary. Remove indexes that are rarely used. Remove indexes already covered by another compound index.

Another anti-pattern is storing information in separate collections although they're often accessed together. The `$lookup` operator is similar to JOIN in relational databases. It's slow and resource intensive. Instead, it's better to denormalize this data.

A case-insensitive query without having a case-insensitive index to cover it is another anti-pattern. We could use `$regex` with the `i` option but this doesn't efficiently utilize case-insensitive indexes. Instead, create a case-insensitive index, that is, index with a collation strength of 1 or 2.

On MongoDB Atlas, Performance Advisor or Data Explorer can spot anti-patterns and warn developers of the same.

## Milestones

Feb
2009

**MongoDB 1.0** is released. By August, this version becomes generally available for production environments.

Dec
2015

MongoDB 3.2 is released. **Schema validation** is now possible during updates and inserts. Validation rules can be specified with the `validator` option via the `db.createCollection()` method and `collMod` command. Validation rules follow the same syntax as query expression. This release also adds `$lookup` pipeline stage to join collections.

Nov
2017

MongoDB 3.6 is released with support for **JSON Schema validation**. The `$jsonSchema` operator within a `validator` expression must be used for this purpose.

Jun
2018

MongoDB 4.0 is released with support for multi-document transactions. However, it's useful to note that due to associated performance costs, developers may benefit from schema redesign, such as a denormalized data model.

Apr
2019

On the MongoDB blog, Coupal and Alger conclude their series of articles titled *Building with Patterns* with a useful summary. Along with a brief description of each data modelling pattern, they note possible use cases of each pattern.

Jul
2021

MongoDB 5.0 is released. When schema validation fails, detailed explanations are shown.

Data Modelling with MongoDB


# Linear Regression

## Summary

Linear regression is a statistical technique used to establish the relationship between variables in a dataset. The equation \(y = mx + c\) describes a linear relationship between dependent variable \(y\) and independent variable \(x\). We may state that \(y\) depends on \(x\). Given sufficient data, linear regression estimates the values of coefficient \(m\) and constant \(c\). In a geometric interpretation, \(m\) is the slope and \(c\) is the intercept. In an alternative notation, these are expressed as \(β\_1\) and \(β\_0\) respectively.

Variable \(y\) is also called response or predicted variable. Variable \(x\) is also called predictor variable. The reason for this that once parameters of the model \(β\_0\) and \(β\_1\) are estimated, we can make predictions of \(y\) given any value of \(x\).

Linear regression is a field of statistics. This article looks at the types, important assumptions and techniques in linear regression.

## Discussion

### Could you explain linear regression with some examples?

Linear regression is frequently used by businesses to understand the link between advertising budget and revenue. In other words, it answers the question "For every advertising dollar I spend, how much will my revenue increase?" This can be modelled as \(Revenue=β\_0+β\_1 \cdot AdSpending\)

\(β\_0\) represents total expected revenue when ad spending is zero. The coefficient \(β\_1\) represents the average increase in total revenue when ad spending is increased by one unit. When \(β\_1<0\), higher ad spending is associated with lower revenue. When \(β\_1=0\) is close to zero, ad spending has little effect on revenue. When \(β\_1>0\) is positive, higher ad spending leads to higher revenue. The model thus aids decision making: a company may decrease or increase its ad spending based on the value of \(β\_1\).

In the figure, the red line is the **best-fit straight line**, \(y=4.187-0.356x\). The values \(β\_0=4.187\) and \(β\_1=-0.356\) are what regression analysis has estimated from available data. Yield falls by 0.356% for every 1% increase in cultivated area. This model can now be used to make predictions; that is, given an area, we can predict the yield.

### What are the main types of linear regression models?

The main types of linear regression models are:

    + **Simple Linear Regression**: This is the most basic type and deals with a single predictor variable. Predicting revenue from ad spending is an example.
    + **Multiple Linear Regression**: Aka *multivariable linear regression*. This is applicable when there are many predictor variables. An example of this is predicting wine prices. This depends on mean growing season temperature, harvest rainfall, winter rainfall, and more.
    + **Hierarchical Linear Model**: Aka *multilevel regression*. Such a model captures the natural hierarchy in predictor variables. Analysis involves a hierarchy of regressions, such as A regressed on B, and B regressed on C. For example, students are nested into classes, classrooms into schools, and schools into districts. So a student's test score can be modelled based on overall performance at different levels.

### What's the mathematical notation of a linear regression model?

We consider the general case of multiple linear regression with \(k\) independent variables. The model therefore has to estimate \(k+1\) parameters: constant \(β\_0\) and coefficients \(β\_j\;for\;1\le j\le k\). The mathematical notation of this model is given in the figure.

In linear algebra, this is expressed as \(Y = X \cdot β + ϵ\), where \(X\) is a \(m\,\times\,k+1\) matrix, \(β\) and \(Y\) are m-dimensional vectors, and \(m\) being the number of observations or data points.

Regression analysis is simply finding \(β\) that minimizes the error term \(ϵ\). This leads us to what's called the **normal equation**: \(β=(X^TX)^{-1} \cdot X^TY\). As is apparent, this equation is in a form that solves for model parameters \(β\).

In Machine Learning (ML), it's common to use \(θ\) instead of \(β\) for the model parameters.

### What are some estimation methods in linear regression?

Methods commonly used for estimating the model parameters (also called estimates) are:

    + **Ordinary Least Squares (OLS)**: This looks at the sum of the square of the difference between actual observed value and its prediction via the model. The method attempts to minimize this sum.
    + **Method of Moments (MoM)**: This uses moments, which are the expectation of the powers of a random variable. Number of moments to be calculated is equal to the number of unknown parameters. The resulting system of equations is then solved.
    + **Maximum Likelihood Estimate (MLE)**: This seeks to maximize the likelihood function. In other words, we determine the estimates that make the observed values most probable. MLE method is applicable when the probability distribution of the error terms is known.Related to OLS are more sophisticated methods including Weighted Least Squares (WLS) and Generalized Least Squares (GLS). Less common ones are Least Median Squares and Least Trimmed Squares. In fact, the minimization need not be of the squares. We could minimize on Least Absolute Deviations, Huber, Bisquare, etc.

### How do I evaluate the performance of a linear regression model?

Models are rarely perfect and there's a need to measure how good a model really is. The differences between predicted values and actual values are called **residuals**. Model evaluation and validating the assumptions can be performed from residuals and this field of study is called **Residual Analysis**.

**Mean Absolute Error (MAE)** and **Mean Squared Error (MSE)** are two ways to quantify the residuals. MAE looks at absolute differences. MSE looks at the square of the differences. Another measure is **Root Mean Squared Error (RMSE)** that's the square root of MSE. RMSE has the same unit as the output variable, making it easier to interpret.

Perhaps the most widely used statistical measure is **R-Squared (R2)**. It quantifies the proportion of the variation explained by the model. Closer it is to 1, better the model explains the data. R2 is also called the **Coefficient of Determination**.

### What are the main assumptions when constructing a linear regression model?

In linear regression, we usually make the following assumptions:

    + **Linearity**: The dependent variable Y is related to the independent variables X in a linear way.
    + **Independence**: Observations are independent of one another. We could also say that the residuals are independent of Y. In time-series data, observations are not correlated. When data doesn't meet this assumption, we have a problem called *autocorrelation*.
    + **Normality**: Residuals are normally distributed. Equivalently, at a fixed observation X, the dependent variable Y is normally distributed.
    + **Homoscedasticity**: The residuals have the same variance at all predicted or fitted points Y. When data doesn't meet this assumption, we have a problem called *heteroscedasticity*.If one or more of these assumptions is violated, what the model predicts may be incorrect or even deceptive.

### How can I determine if linear regression is appropriate for a particular set of data?

Scatterplot can help us validate the linearity assumption. For multiple linear regression, 2-D pairwise scatter plots, rotating plots, and dynamic graphs can help.

To validate the independence assumption, a scatterplot of residuals versus fitted values shouldn't show any pattern.

To validate the normality assumption, a normal probability plot, a residual histogram or a quantile-quantile plot can be used.

To validate the homoscedasticity assumption, do a scatterplot of residuals against the fitted values. A cone-shaped pattern implies that the residuals vary more for some predicted values than others, thus invalidating the assumption. There are also lots of statistical tests to check for homoscedasticity: Bartlett's Test, Box's Test, Brown-Forsythe Test, Hartley's Fmax Test, Levene's Test, and Breusch-Pagan Test.

We also expect predictor variables to be independent of one another. A scatterplot of one independent variable with another can validate this. We can also calculate the correlation coefficients pairwise for all independent variables. Correlation coefficients close to ±1 imply high correlation. Low model coefficients or high Variance Inflation Factor (VIF) indicate correlated variables.

### How do autocorrelation, multicollinearity, and heteroscedasticity affect linear regression estimates?

**Autocorrelation** exists when multiple observations of a predictor variable are not independent. This is common in time-series data but could occur in other scenarios such as samples drawn from a cluster or geographic area. Autocorrelation can be detected with the Durbin-Watson test. Due to autocorrelation, OLS estimators will be inefficient. Estimated variance of regression coefficients will be biased and inconsistent. Hypothesis testing will be invalid. R2 will be overestimated.

A correlation between two or more predictor variables is referred to as **multicollinearity**. Though the overall model fit is not affected, multicollinearity can increase the variance of estimates and make them sensitive to model changes. Model becomes harder to interpret. It's harder to determine the precise effect of each predictor.

Heteroscedasticity means unequal spread of the residuals. It's a problem because OLS regression assumes constant spread. Though this doesn't introduce bias to the estimates, it does make them less precise. It produces smaller p-values because OLS regression doesn't detect the increase in the variance of the estimates. Thus, we may wrong conclude that an estimate is statistically significant.

### How do we model the interaction of independent variables?

When one independent variable has a distinct effect on the outcome based on the values of another independent variable, we call this an **interaction**.

Assume that a cholesterol-lowering medication is being evaluated in a clinical trial. Drug effect is dependent on both dose administered and the patient's sex. Without interaction between dose and sex, effect increases at a fixed slope with respect to the dose regardless of the sex.

With interaction, we can no longer ask what's the drug's effect since for every unit dose the incremental effect depends on the sex. Dose affects males differently from females and this what interaction is about. We can see in the figure that the slope is steeper for males than for females. We could use two separate linear models, one for each sex. But it's easier to enhance a single model to handle the interaction. Such as model can be written as, \(Y = β\_0 + β\_1 \cdot dose + β\_2 \cdot sex + β\_3 \cdot dose \cdot sex\). If there's no interaction, \(β\_3\) is zero.

### What are random effects, fixed effects and mixed effects models?

When model parameters \(β\) are random variables, it's called a random effects model. Otherwise, we have a fixed effects model. A model that considers both fixed and random effects is called a mixed effects model.

Mathematically, a mixed effects model is written as, \(Y = X \cdot β + Z \cdot u + ϵ\) where the first term models the fixed effects and the second term models the random effects.

Let's assume a study involving 10 people. Repeated measurements are collected from each person. However, these individuals are only "random" samples from a larger population. This sampling is accounted for by the random effects term of the model.

The random effects term also models a hierarchy of distinct populations (hence it relates to multilevel regression). An example hierarchy is students, schools, and districts. Random effects term models the variations at school and district levels. Perhaps a good definition that clarifies this is,

> Fixed-effect parameters describe the relationships of the covariates to the dependent variable for an entire population, random effects are specific to clusters of subjects within a population.

### What software packages are useful for solving linear regression problems?

In Python, **scikit-learn** is perhaps the most helpful Python for linear regression. In particular, `sklearn.linear_model.LinearRegression` and `sklearn.metrics` are relevant.

In R, there are many packages with functions to perform linear regression. Package `stats` is most useful. Package `car` can help with ANOVA analysis, residual analysis and testing the assumptions. Package `MASS` enables Generalized Least Squares (GLS) and robust fitting of linear models. Package `caret` streamlines the model training process and includes ML algorithms. Package `glmnet` enables many types of linear regression. `BLR` supports Bayesian linear regression, which is a subset of linear regression. `Lars` supports Lasso regression efficiently.

## Milestones

1875

Sir Francis Galton and Karl Pearson reveal that Galton's research on the genetic traits of sweet peas is probably the first example of linear regression.

1894

Sir Francis Galton proposes the notion of linear regression for the first time.

1896

Pearson's first rigorous discussion of **correlation** and **regression** is published in the *Philosophical Transactions of the Royal Society of London*. Pearson credits Bravais (1846) with discovering the first mathematical formulas for correlation.

1922

Pearson's theory explains how the **regression slope** is discovered.

1938

Pearson develops a theory for **multiple regression**. He also makes novel advances in other areas of statistics such as chi-square.

1981

Ghiselli explains a simpler proof for the product-moment approach than Pearson's.

1990

Computations to a complete linear regression is formed.

Linear Regression


# Naive Bayes Classifier

## Summary

Naive Bayes is a **probabilistic classifier** that returns the probability of a test point belonging to a class rather than the label of the test point. It's among the most basic Bayesian network models, but when combined with kernel density estimation, it may attain greater levels of accuracy. . This algorithm is applicable for Classification tasks only, unlike many other ML algorithms which can typically perform Regression as well as Classification tasks.

Naive Bayes algorithm is considered naive because the assumptions the algorithm makes are virtually impossible to find in real-life data. It uses conditional probability to calculate a product of individual probabilities of components. This means that the algorithm assumes the presence or absence of a specific feature of a class which is not related to the presence or absence of any other feature (absolute independence of features), given the class variable.

## Discussion

### Could you explain the Naive Bayes classifier with examples?

Consider two groups of insects, grasshoppers and katydids. By studying the antenna lengths from many insect samples, we can discern some patterns and computed probabilities. For examples, given an antenna length of 3 cm, the insect is more likely to be a grasshopper than a katydid. Naive Bayes classifier is a technique to perform such a classification. Antenna length is a feature that's used to classify an insect into one of two classes.

Suppose the antenna length is 5 cm. Probabilities computed from observed samples inform that both classes are equally likely. In this case, classification can be improved by considering more features such as abdomen length. NB classifier assumes that features are independent of one another.

Consider the statement "Officer Drew arrested me." Is Drew male or female? We can answer this by gathering data on the officer: height, eye colour and long/short hair. Then we lookup a police database of all officers and apply NB classifier. This problem uses three independent features and two classes (male or female).

### What is Bayes' Theorem and how is it relevant to the NB classifier?

**Bayes theorem** (aka Bayes rule) works on conditional probability. In conditional probability, the occurrence of a particular outcome is conditioned on the outcome of another event occurring. Given two events A and B, Bayes theorem states that,

$$P(A|B) = \frac{P(A⋂B)}{P(B)} = \frac{P(A) \cdot P(B|A)}{P(B)}$$

where \(P(A)\) and \(P(B)\), called marginal probability or prior probability, are the probabilities of events A and B event occurring; where \(P(A|B)\), called posterior probability, is the probability of event A occurring given that event B has occurred; where \(P(B|A)\), called likelihood probability, is the probability of event B occurring given that event A has occurred; \(P(A⋂B)\) is the joint probability of both events occurring. \(P(A|B)\) and \(P(B|A)\) are also called conditional probabilities.

Suppose you have drawn a red card from a deck of playing cards. What's the probability that it's a four? We apply conditional probability. There are 26 possible red cards and two of the are fours. Thus, \(P(four|red)=2/26=1/13\). Bayes Theorem allows us to reformulate the problem as follows:

$$P(four|red) = P(four) \cdot P(red|four) / P(red)\\= (4/52 \cdot 2/4) / (26/52)\\= 1/13$$

### What are the types of the NB classifier?

scikit-learn implements three naive Bayes variants based on the same number of different probabilistic distributions: Bernoulli, multinomial, and Gaussian.

**Bernoulli Naive Bayes**

The predictors in this case are boolean variables. So your only options are 'True' and 'False' (you might also have 'Yes' or 'No'). When the data has a multivariate Bernoulli distribution, we use it.

**Multinomial Naive Bayes**

The frequency with which particular events were created by a multinomial distribution are represented by feature vectors. This is the event model that is most commonly used for document classification.This algorithm is used to tackle document classification difficulties. For example, if you want to know whether a document is in the 'Legal' or 'Human Resources' category, you'd use this technique to figure it out. It makes advantage of the frequency of the current words as a feature.

**Gaussian Naive Bayes**

It is used for numerical / continuous features. The distribution of continues values are "assumed" to be Gaussian. And therefore the likelihood probabilities are computed based on Gaussian distribution.

### How would you use Naive Bayes classifier for categorical features?

For a discrete variable with more than two possible outcomes, such as the roll of a dice, the categorical distribution is an extension of the Bernoulli distribution. In contrast, the categorical distribution provides a probability of different outcomes for one drawing rather than multiple drawings as is the multinomial distribution.

The properties should be encoded using label encoding techniques, and each category should be assigned a unique number.

It is given by:

\(p(x\_i = t | y = c; α) = N\_???+α /N\_c+α n\_i\)

\(?\_???\) = Number of times category t appears in the samples ??, which belong to class ?

\(?\_?\) = Total number of samples with class c

\(?\) = Laplace smoothing parameter used to handle zero frequency problem

\(?\_?\) = Number of available categories of feature

### What is Laplace smoothing in the context of the NB classifier?

Laplace smoothing is a smoothing technique used in Naive Bayes to solve the problem of zero probability. Consider text categorization, where the aim is to determine if a review is good or negative. Based on the training data, we create a likelihood table. We use the Likelihood table values when querying a review, but what if a word in a review was not present in the training dataset?. For example, a test query has form, Query review= x1x2x’

Let, a test sample have three words, where we assume x1 and x2 are present in the training data but not x’. Laplace smoothing comes into picture.

\(P(x’/positive)= (number of reviews with x’ and target\_outcome=positive + α) / (N+ α\*k)\)

K denotes the number of dimensions (features) in the data.

N is the number of reviews with the target outcome=positive.

α represents the smoothing parameter.

### Can we use the NB classifier when features are not independent?

The process of evaluating features depending on how successful they are in predicting the target variable is known as feature importance.The naive bayes classifiers do not provide an intrinsic technique for determining the relevance of features. Naive Bayes algorithms forecast the class with the highest probability by computing the conditional and unconditional probabilities associated with the features.As a result, no coefficients have been generated or connected with the characteristics used to train the model.However, there are ways for analysing the model after it has been trained that can be used post-hoc. One of these strategies is the Permutation Importance, which has been neatly implemented in scikit-learn.

When the data is tabular, **permutation feature importance** is a model inspection technique that can be utilised for any fitted estimator. For a given dataset, the permutation importance function computes the feature importance of estimators. The **n\_ repeats** option specifies how many times a feature is randomly shuffled before returning a sample of feature importances.

### What are some applications of the NB classifier?

**Text classification/ Spam Filtering/ Sentiment Analysis**: Naive Bayes classifiers, which are commonly employed in text classification (owing to better results in multi-class problems and the independence criterion), have a greater success rate than other techniques. As a result, it is commonly utilised in spam filtering (determining spam e-mail) and sentiment analysis (in social media analysis, to identify positive and negative customer sentiments)

**Recommendation System**: The Naive Bayes Classifier and Collaborative Filtering work together to create a Recommendation System that employs machine learning and data mining techniques to filter unseen data and forecast whether a user would enjoy a given resource or not.

**Multi-class Prediction**: This algorithm is also well-known for its multi-class prediction capability. We can anticipate the likelihood of various target variable classes here.

**Real-time Prediction**: Naive Bayes is a quick learning classifier that is eager to learn. As a result, it might be utilised to make real-time forecasts.

### How is the NB classifier related to logistic regression?

Given input features \(X\), both NB classifier and logistic regression predict an output class, that is, output \(Y\) is categorical. Logistic regression directly estimates \(P(Y|X)\) whereas NB classifier applies the Bayes theorem and estimates \(P(Y)\) and \(P(X|Y)\). As such, we call logistic regression a **discriminative classifier** and NB a **generative classifier**.

It's been observed that on small training datasets, NB classifier does better than logistic regression. If more training samples are available, logistic regression does better. While logistic regression has a lower asymptotic error, NB classifier may converge faster to its higher asymptotic error.

It's known that the Gaussian Naive Bayes (GNB) classifier is closely related to logistic regression. Parameters of one model can be expressed in terms of the other. Moreover, asymptotically both converge to the same classifier when GNB assumptions hold. When the assumptions don't hold, such as dependence among features, logistic regression does better because it adjusts its parameters to give a better fit.

### What are some disadvantages and advantages of the NB classifier?

**Advantages**: Naive bayes is Simple to put into action. The conditional probabilities are simple to compute. The probabilities can be determined immediately, there is no need for iterations. As a result, this strategy is useful in situations when training speed is critical. If the conditional Independence assumption is true, the consequences could be spectacular. This algorithm predicts classes faster than many other classification algorithms.

**Disadvantages**:The premise of independent predictors is the main imitation of Naive Bayes. Naive Bayes implicitly assumes that all attributes are independent of one another. In practise, it is very hard to obtain a set of predictors that are totally independent. If a categorical variable in the test data set has a category that was not observed in the training data set, the model will assign a 0 (zero) probability and will be unable to predict. This is commonly referred to as Zero Frequency. you can utilise the smoothing approach to remedy this. Laplace estimation is one of the most basic smoothing techniques.

## Milestones

1763

The Royal Society publishes a paper on probability by Thomas Bayes after his death in 1761. It's titled *Essay Towards Solving a Problem in the Doctrine of Chances* and details what would later become famous as the **Bayes inference**. The basic idea is to revise predictions based on new evidence. Decades later (early 19th century), Pierre-Simon Laplace develops and popularizes Bayesian probability.

1940

Bayesian approach is applied during the Second World War. It sees a revival in the years after the war. Earlier, Bayesian approach had been criticized. The frequentist approach developed by R.A. Fisher had been favoured since the mid-1920s.

1960

Maron and Kuhns apply Bayes' Theorem to the task of **Information Retrieval (IR)**. The probability of retrieving a relevant document given a query can be computed from the prior probability of document relevance and conditional probability of user making a particular query given the relevant document. Over the next forty years, Naive Bayes is the main technique in IR until machine learning techniques become popular.

1968

Hughes considers a **two-class pattern recognition problem**. The model considers \(n\) discrete values that can be measured and \(m\) sample patterns. He shows that for a given \(m\), there's an optimal \(n\) that minimizes the pattern recognition error. This is shown in the figure (right) for the case of equal class probabilities. The figure (left) also shows an example of \(n=5\) in which values 1-3 imply class \(c\_1\) and values 4-5 imply class \(c\_2\).

1973

Duda and Hart use the Naive Bayes classifier in **pattern recognition**.

1992

Langley et al. present an **analysis** of Bayesian classifiers considering noisy classes and noise-free attributes. They find that the Naive Bayes classifier gives comparable results to the C4 algorithm that induces decision trees. They conclude that despite its simplicity, the Naive Bayes classifier deserves more research attention.

1997

Domingos and Pazzani show that even when **attributes are not independent**, the Bayesian classifier does well. It can be optimal under zero-one loss (misclassification rate). It's optimal under squared error loss only when the independence assumption holds.

1998

Kasif et al. propose a probabilistic framework for memory-based reasoning (MBR). Such a framework can be used for classification tasks. They note that a **probabilistic graphical model** is really another way of looking at the Naive Bayes classifier.

Naive Bayes Classifier


# 5G Service-Based Architecture

## Summary

Cellular core networks till LTE used specialized telecom protocols running on specialized telecom hardware. With LTE vEPC, the first efforts were made towards virtualization. Service-Based Architecture (SBA) is an evolution of this approach and it's been adopted by 5G System.

In SBA, a set of Network Functions (NFs) provide services to other authorized NFs. These NFs are nothing more than software implementations running on commercial off-the-shelf hardware, possibly in the cloud. A NF can offer one or more services. NFs are interfaced via well-defined APIs and a client-server model. Traditional telecom signalling messages are replaced with API calls on a logically shared service bus.

SBA utilizes the maturity of web and cloud technologies. Modularity, scalability, reliability, cost-effective operation, easy deployments, and faster innovation are some of the benefits of moving to SBA.

## Discussion

### Why does the 5G Core need a service-based architecture?

5G is not just about new devices, new use cases and higher speeds. The core network needs to be modernized to be able to support demanding performance requirements. eMBB, mMTC and URLLC are all different use cases that can't be satisfied by a monolithic architecture. We're expecting a massive increase in high-bandwidth content, low-latency applications and huge volumes of small data packets from IoT sensors.

5G Core needs to be flexible, agile and scalable. User plane and control plane need to be scaled independently. Traffic handling must be optimized. Network operators must be able to quickly launch new services. This calls for virtualization, a software-driven approach and adopting web protocols and cloud technologies. The network must be composed of loosely coupled network functions that can be managed independently but interfaced efficiently via mature and scalable technologies.

To reduce both CAPEX and OPEX, there's a need to use off-the-shelf hardware running multi-vendor software exposing open interfaces. Operators must have the flexibility to use private or public clouds. Compute and storage should be distributed. There's a need to support edge computing.

### What are the benefits of moving to 5G SBA?

Since NFs are loosely coupled and interfaced with APIs, each NF can be evolved and deployed independently. SBA signifies a move from monolithic to **modular architecture**. New NFs can be rolled out without impacting existing ones. Via NEF, external applications can interwork with 5G Core. Across the 5G ecosystem, this enables **faster innovation**.

SBA brings **scalability and resilience**. Rather than add physical nodes that may take weeks, new instances of NFs can be created/destroyed dynamically in minutes. If an instance or a physical node fails, monitoring systems can detect this and quickly spin up new instances.

SBA's modular design enables **network slicing**. Multiple logical networks can run on a single physical network, thus catering to multiple industry verticals.

In terms of true business value, Oracle has noted that,

> SBAs provide a set of loosely coupled services that empower communications service providers (CSPs) to be more agile and enable rapid service delivery.

### What web technologies are enabling 5G SBA?

Telecom protocols common in earlier generations have been replaced in 5G Core with web technologies. SCCP, TCAP, SCTP and Diameter are some examples that have been replaced with TCP/IP for networking, HTTP/2 at the web application layer and JSON as the data serialization format. For security, TLS is used above TCP layer.

Network functions in SBA are exposed via well-defined Service-Based Interfaces (SBIs). The bottom-up layering of L2, IP, TCP, TLS, HTTP/2 and application layers is formally called the **SBI protocol stack**.

The interfaces themselves are defined with an Interface Definition Language (IDL) called **OpenAPI Specification**.

Interfaces are exposed as **RESTful APIs**. 5G SBA has adopted the web's client-server model but a client is called **Service Consumer** and a server is called **Service Provider**.

Many cloud native tools and technologies are enabling 5G SBA: Docker for containerization, Kubernetes for container orchestration, Istio for service mesh, Prometheus for monitoring, Grafana for visualization, and many more.

### Could you describe the architecture of 5G SBA?

5G SBA is described by a **reference point representation** that names the points by which each NF connects to other NFs. In practice, the reference points are implemented by corresponding NF **Service-Based Interfaces (SBIs)**. Instead of point-to-point connections, NFs interconnect on a logically shared infrastructure or service bus. For instance, AMF and SMF are connected via the N11 reference point for which the corresponding SBIs are Namf and Nsmf.

SBIs are defined only for the control plane. Thus, the reference point between SMF and UPF is N4. It has no equivalent SBI. Likewise, SBIs are defined for 5G Core functionality. Thus, reference points N1, N2 and N3 that involve the UE or RAN don't have SBIs.

### Which are the main functions in 5G SBA?

5G Core has about two dozen **network functions**: Access and Mobility Management Function (AMF), Application Function (AF), Authentication Server Function (AUSF), Binding Support Function (BSF), CHarging Function (CHF), Network Data Analytics Function (NWDAF), Network Exposure Function (NEF), Network Repository Function (NRF), Network Slice Selection Function (NSSF), Network Slice Specific Authentication and Authorization Function (NSSAAF), Policy Control Function (PCF), Session Management Function (SMF), UE radio Capability Management Function (UCMF) and Unstructured Data Storage Function (UDSF), Unified Data Repository (UDR), User Plane Function (UPF) and Unified Data Management (UDM).

Among the network **entities** are Service Communication Proxy (SCP) and Security Edge Protection Proxy (SEPP).

For **interworking** with non-3GPP access networks, we have Non-3GPP InterWorking Function (N3IWF), Trusted Non-3GPP Gateway Function (TNGF), Wireline Access Gateway Function (W-AGF) and Trusted WLAN Interworking Function (TWIF).

For **location services**, NFs include Location Management Function (LMF), Location Retrieval Function (LRF) and Gateway Mobile Location Centre (GMLC).

### Could you describe some of the network functions in 5G SBA?

We note a few of Release 15 NFs:

    + **AMF**: Registration, access control and mobility management.
    + **SMF**: Creates, updates and removes PDU sessions. Manages session context with UPF. UE IP address allocation and DHCP role.
    + **UPF**: User plane packet forwarding and routing. Anchor point for mobility.
    + **NRF**: Maintains updated records of services provided by other NFs.
    + **NEF**: Securely opens up the network to third-party applications.
    + **AUSF**: Authentication for 3GPP access and untrusted non-3GPP access.
    + **PCF**: Unified policy framework to govern network behaviour. Provides policy rules for control plane.
    + **NSSF**: Selects network slice instances for the UE. Determines AMF set to serve the UE.
    + **UDM**: Generates AKA authentication credentials. Authorizes access based on subscription data.
    + **AF**: Interfaces with 3GPP core network for traffic routing preferences, NEF access, policy framework interactions and IMS interactions.
    + **BSF**: Binds an AF request to the relevant PCF.

### Could you describe an example how services communicate in 5G SBA?

A service producer will register itself with the Network Repository Function (NRF). A service consumer will consult the NRF to discover available NF instances. Thus, the process involves **Service Registration** and **Service Discovery**.

Once so discovered, the service consumer can **directly consume** authorized APIs exposed by the service producer. These API calls are RESTful: client-server model, stateless calls, unique URIs, and use of HTTP verbs GET/POST/PUT/PATCH/DELETE.

**Indirect communication** is also possible via Service Communication Proxy (SCP). Service registration and discovery still happen with the NRF but this may be delegated to the SCP. Consumers send their requests through the SCP. The SCP itself doesn't expose any network function.

Finally, it's possible to configure consumers with NF profiles of producers. This bypasses service registration and discovery. In fact, the specification identifies this as Model A. Model B is direct communication. Model C and Model D are indirect communications.

All NF services are detailed in TS 23.502 specification. Services within an NF can call one another but their interactions are not specified in Release 16.

### What are the challenges with 5G SBA?

**Security** is one the big challenges with many possible vulnerabilities. JSON is an exact opposite of telecom world's ASN.1. JSON specification is less rigorous and has versioning problems. Implementing and deploying OAuth 2.0 is going to be complex. The web's practice of rapid changes and CI/CD pipelines can make telecom systems less secure. REST APIs have many known vulnerabilities. There are also problems with TLS.

Architecture, frameworks, libraries and tools need greater **maturity**. Cloud-native architecture was developed for enterprise clouds, not for telecom systems that need low downtime of few minutes per year. Kubernetes lacks networking features such as ECMP, GTP tunnelling, SCTP and LACP. In a distributed environment involving hundreds of nodes, deploying and operating OpenStack and Kubernetes for NFVI and MANO are not trivial. Complexity increases when extensions such as DPDK are included. Traditional network visibility tools must evolve to monitor at the container level.

With NFs being developed by many vendors, integration and **interoperability** may become an issue. LTE EPC and 5G Core need to interoperate as well and shouldn't be managed in silos. Legacy OAM tools for 4G that can't handle 5G Core may lead to inefficient operations.

## Milestones

1990

This is the decade when **Service-Oriented Architecture (SOA)** starts to gain wider adoption. Applications are not monoliths but composed of isolated and independent services. Services are loosely bound together by a standard communications framework.

2000

In this decade, **Web Services**, a web-based implementation of SOA, becomes popular over proprietary methods such as CORBA or DCOM.

2010

Many web and cloud technologies develop and become popular through the 2010s: the term **microservices** is coined (2011); **REST** and **JSON** become the de facto standard to consume backend data (2012); **Docker** for containerization gets open sourced (2013); and Google open sources **Kubernetes**, a container orchestration system. These developments soon enable the birth of 5G's service-based architecture.

Feb
2013

At Mobile World Congress, **Virtual Evolved Packet Core (vEPC)** solutions are showcased by NEC, Cisco and Intel. In October, NEC claims to be the world's first to offer a vEPC solution on commercial off-the-shelf (COTS) hardware based on Intel architecture. Deployment of vEPC solutions gathers pace and adoption through 2014. By 2015, operators see the value in virtualization of the core network.

Jul
2016

At the ÜberConf 2016 conference, Ford and Richards deliver presentations on **service-based architecture**. SOA breaks applications by layers but microservices breaks them by domain. They note that moving a monolithic application to microservices is not a trivial exercise. SBA offers a middle ground with dozens of services rather than hundreds of microservices. Services in SBA may even share a common data storage.

Jan
2017

3GPP publishes version 0.0.0 of *TS 23.501: System architecture for the 5G System*. In future, this is the main document that would detail 5G Core's service-based architecture. This evolves to version 1.0.0 by June.

Dec
2017

3GPP publishes **Release 15** "early drop". In TS 23.501, this release includes network functions and entities AUSF, AMF, UDSF, NEF, NRF, NSSF, PCF, SMF, UDM, UDR, UPF, AF, 5G-EIR and SEPP. BSF is also included in this release.

Jan
2018

In an interview, we come to learn that 3GPP Core Networks and Terminals (CT) Working Groups are interfacing with IETF on how to adopt **QUIC**. As a replacement to the TCP/IP stack in the 5G Core, QUIC may be considered. As of Release 16 (July 2020), QUIC isn't part of 5G Core.

Jun
2020

Towards supporting **Location Services (LCS)**, relevant network functions are defined in TS 23.273, version 16.0.0. These include Gateway Mobile Location Centre (GMLC), Location Retrieval Function (LRF) and Location Management Function (LMF).

Jul
2020

3GPP publishes **Release 16** specifications. New capabilities are NEF-based infrequent small data transfer via NAS, which will benefit MTC use cases and IoT applications; indirect communication between network services via Service Communication Proxy (SCP) and implicit discovery; support of trusted non-3GPP access; NF Set and NF Service Set; and more. New NFs include UCMF, NWDAF, CHF, N3IWF, TNGF, W-AGF.

Jul
2020

A study involving service providers who operator 30% of the world's commercial 5G networks shows that **Unified Data Management (UDM)** is the most tested and deployed network function. This comes from the realization that data is the new gold. Operators wish to control and monetize it.

5G Service-Based Architecture


# Byte Ordering

## Summary

A byte (of 8 bits) has a limited range of 256 values. When a value is beyond this range, it has to be stored in multiple bytes. A number such as 753 in hexadecimal format is 0x02F1. It requires at least two bytes of storage. The order in which these two bytes are stored in memory can be different. Byte 0x02 can be stored in lower memory address followed by 0xF1; or vice versa.

Programs must conform to the byte ordering as supported by the processor. If not, 0x02F1 might be wrongly interpreted as 0xF102, which is the number 61698 in decimal system. Byte ordering is also important when data is transferred across a network or between systems using different ordering.

Byte ordering is an attribute of the processor, not the operating system running on it.

## Discussion

### Which are the different byte orderings present in computing systems?

Two common ordering systems include,

    + **Little-Endian**: Low-order byte is stored at a lower address. This is also called *Intel order* since Intel's x86 family of CPUs popularized this ordering. Intel, AMD, PDP-11 and VAX are little-endian systems.
    + **Big-Endian**: High-order byte is stored at a lower address. This is also called *Motorola order* since Motorola's PowerPC architecture used this ordering. Motorola 68K and IBM mainframes are big-endian systems.Some processors support both ordering and are therefore called **Bi-Endian**. PowerPC and Itanium are bi-endian. Bi-Endian processers can switch between the two orderings. Most RISC architectures (SPARC, PowerPC, MIPS) were originally big-endian but are now configurable. While ARM processors are bi-endian, the default is to run them as little-endian systems, as seen in the Raspberry Pi.

Due to the popular adoption of x86-based systems (Intel, AMD, etc.) and ARM, little-endian systems have come to dominate the market.

### Could you compare host-byte vs network-byte ordering?

Since computers using different byte ordering, and exchanging data, have to operate correctly on data, the convention is to always send data on the network in big-endian format. We call this **network-byte ordering**. The ordering used on a computer is called **host-byte ordering**.

A host system may be little-endian but when sending data into the network, it must convert data into big-endian format. Likewise, a little-endian machine must first convert network data into little-endian before processing it.

Four common functions to do these conversions are (for 32-bit long and 16-bit short) `htonl`, `ntohl`, `htons` and `ntohs`.

Even if your code doesn't do networking, data may be stored in a different ordering. For example, file data is stored in big-endian while your machine is big-endian. In some cases, CPU instructions may be available for conversion. Intel's 64-bit instruction set has `BSWAP` to swap byte ordering. Since ARMv6, `REV` swaps byte order and `SETEND` to set the endianness.

### Aren't conversions redundant for big-endian machines since it already conforms to network-byte ordering?

It's good programming practice to invoke these conversions since this makes your code *portable*. The same codebase can be compiled for a little-endian machine and it will work. Calling the conversion functions on a big-endian machine has no effect.

While a little-endian system sending data to another little-endian system need not do any conversion, it's good to convert. This makes the code more portable across systems.

### Are there situations where byte ordering doesn't matter?

When data is stored and processed as a sequence of single bytes (not shorts or longs), then byte ordering doesn't matter. No conversions are required when receiving or sending such data into the network.

ASCII strings are stored as a sequence of single bytes. Byte ordering doesn't matter. Byte ordering for Unicode strings depends on the type of encoding used. If encoding is UTF-8, ordering doesn't matter since encoding is a sequence of single bytes. If encoding is UTF-16, then byte ordering matters.

When storing TIFF images, byte ordering matters since pixels are stored as words. GIF and JPEG images don't care about byte ordering since storage is not word oriented.

### What's the purpose of Byte Order Mark (BOM)?

An alternative to using host-to-network and network-to-host conversions is to send the data along with an indication of the ordering that's being used. This ordering is indicated with additional two bytes, known as **Byte Order Mark (BOM)**.

The BOM could have any agreed upon value but 0xFEFF is common. If a machine reads this as 0xFFFE, it implies that ordering is different from the machine's ordering and conversion is required before processing the data further.

BOM adds overhead. For example, sending two bytes of data incurs an overhead of additional two bytes. Problems can also arise if a program forgets to add the BOM or data payload starts with the BOM by coincidence.

BOM is not required for single-byte UTF-8 encoding. However, some editors such as Notepad on Windows may include BOM (three bytes, EFBBBF) to indicate UTF-8 encoding.

### What are the pros and cons of little-endian and big-endian systems?

In little-endian systems, just reading the lowest byte is enough to know if the number is odd or even. This may be an advantage for low-level processing. Big-endian systems have a similar advantage: lowest byte can tell us if a signed integer is positive or negative.

Typecasting (say from `int16_t` to `int8_t`) is easier in little-endian systems. Because of the simple relationship between address offset and byte number, little-endian can be easier for writing math routines.

During low-level debugging, programmers can see bytes stored from low address to high address, in left-to-right ordering. Big-endian systems store in the same left-to-right order and this makes debugging easier. For the same reason, binary to decimal routines are easier.

For most part, programmers have to deal with both systems. Each system evolved separately and therefore it's hard to complain about not having a single system.

### Is the concept of endianness applicable for instructions?

Endianness is applicable for multi-byte numeric values. Instructions are not numeric values and therefore endianness is not relevant. However, an instruction may contain 16-bit integers, addresses or other values. The byte ordering of these parts is important.

For example, 8051 has a `LCALL` instruction that stores the address of the next instruction on the stack. Address is pushed to stack in little-endian format. However, `LJMP` and `LCALL` instructions contain 16-bit addresses that are in big-endian format.

### How can I check the endianness of my system?

On Linux and Mac, the command `lscpu` can be used to find endianness.

Developers can also write a simple program to determine the endianness of the host machine. In a C program, for example, store two bytes in memory. Then use a `short *ptr` to point to the lower address. Dereference this pointer to obtain a short value, which will tell us if the machine is little-endian or big-endian.

### Do systems differ in the ordering of bits within a byte?

Bits within a byte are commonly numbered as Bit0 for the least significant bit and Bit7 for the most significant bit. Thus, bit numbering in a 32-bit integer will be left-to-right order in big-endian, and right-to-left in little-endian. However, some systems such as the OpenXC vehicle interface use the opposite numbering in which the least significant bit is Bit7. Note that in either case, the content remains the same, only the numbering is different.

Danny Cohen in his classic paper on the subject of endianness notes some examples where bit numbering was inconsistent in early computer systems. For example, M68000 was big-endian but the bit numbering resembled little-endian.

In digital interfaces, bit ordering matters. In Serial Peripheral Interface (SPI), this can be configured based on what both devices support. In I2C, most significant bit is sent first. In UART, either ordering is fine and must be configured correctly at both ends. If not, sending least significant bit first is usually assumed.

## Milestones

1970

PDP-11 released by DEC is probably the first computer to adopt little-endian ordering.

1980

The terms big-endian and little-endian are used for the first time in the context of byte ordering. The terms are inspired by Jonathan Swift's novel titled *Gulliver's Travels*.

1983

Byte order conversion functions `htonl`, `ntohl`, `htons` and `ntohs` are introduced in BSD 4.2 release.

1992

First samples of an ARM processor came out in 1985. It's only in 1992 with the release of ARM6 that the processor becomes bi-endian. Legacy big-endian is supported for both instructions and data. Otherwise, instructions are little-endian. Data is little-endian or big-endian as configured. While byte ordering can be configured in software for some ARM processors, for others such as ARM-Cortex M3, the order is determined by a configuration pin that's sampled at reset.

Byte Ordering


# RISC-V Architecture

## Summary

When computers "compute", they're in fact executing instructions that are defined by what's known as **Instruction Set Architecture (ISA)**. Each computer hardware will support a particular ISA. RISC-V is a free, open ISA that can be extended or customized for a variety of hardware or application requirements.

Apart from defining the instructions themselves, to be a success, any ISA requires broad industry support from chip manufacturers, hardware designers, tool vendors, compiler writers, software engineers, and more. While RISC-V is still new, progress has been made in building a healthy ecosystem and first RISC-V chips have been released.

It's been said that,

> The real value of RISC-V is enabling the software and tools community to develop around a single common hardware specification.

## Discussion

### What's the motivation for creating RISC-V?

Many of the world's PCs and laptops are based Intel's x86 architecture. Many of the world's smartphones and embedded devices are based on ARM architecture. Both are proprietary and any use of these architectures involve licensing cost and may involve royalty fees. Moreover, companies may lack full competency to design their proprietary ISA. Another problem is long-time support. For example, when DEC died, there was no one to support their proprietary ISAs Alpha or VAX.

One researcher claimed that security flaws such as Meltdown and Spectre are down to flaws in Intel's instruction sets. This is less likely when ISAs are open to inspection by a wide engineering community.

RISC-V is an open ISA. It uses **BSD Open Source License**. This license does not restrict even commercial use of the ISA. Anyone implementing RISC-V are not required to release the source code of their RISC-V cores. The license only requires that authors of RISC-V must be acknowledged. An open ISA will permit software reuse, greater innovation and reduced cost.

### Do we need RISC-V when there are other open ISAs?

Creators of RISC-V considered and dismissed other open ISAs. OpenRISC has technical shortcomings and little industry adoption. OpenSPARC is suitable for servers but not for embedded devices and smartphones. OpenSPARC is also licensed under GPLv2, which may not attract support from commercial players.

RISC-V benefits from the mistakes of the past. It has no burden to support legacy instructions. It adopts RISC for its simplicity. By leaving out delayed branches, RISC-V is kept simple and clean. Other open ISAs are not modular. RISC-V is modular so that the right balance of cost and efficiency can be attained for a particular application. In particular, it can be customized for constrained IoT devices, smartphones/tablets or servers.

One claim states that LatticeMico32 is an open source RISC processor that's some are already using and questions the need for RISC-V. They also state that the ecosystem is more important than having a perfect ISA.

### What are some possible benefits of using RISC-V?

Beyond saving on licensing or royalty fees, RISC-V has many benefits:

    + **Universal**: As one of its goals, RISC-V should suit all sizes of processors, all types of implementations (FPGA/ASIC/SoC), various software stacks, and various programming languages.
    + **Modular**: The ISA has a base specification plus optional extensions. This means designers can leave out stuff they don't need for their application.
    + **Extensible**: Designers can add custom instructions for specialized functions such as machine learning or security. This is particularly important when Moore's Law is ending.
    + **Freedom**: Designers have the freedom to work on their own optimized implementations and retain the choice to make their IP open.
    + **Frozen**: By freezing the ISA specifications, we can be certain that today's software and tools will work on RISC-V systems many decades from now.
    + **Adoption & Reuse**: By being open, RISC-V will encourage wider adoption because of compatibility. This enables reuse.

### Could you compare RISC-V with alternative architectures?

In terms of code sizes, one study found RISC-V compressed ISA (RV32C) is similar to Thumb-2, while RV64C has better code density than its alternatives.

In terms of performance (speed and power), there's no reason to believe that RISC-V processors will fare worse than ARM or x86 processors. It will be dependent on implementation: microarchitectural design, circuit design and processing technology.

### Could you name some processors based on RISC-V?

Because RISC-V is open, anyone can design and develop their own processors without licensing fees. However, design and engineering costs can run into millions of dollars plus a delayed time to market. It therefore makes sense to use IP cores or processors developed by others.

Some offer RISC-V **IP cores** that chip makers can license. Among them are Andes Technology, Codasip, Bluespec, Cortus, and SiFive. There are others who offer **soft cores** that can run in FPGAs: Microsemi, Rumble Development, and VectorBlox.

SiFive has two families of licensable cores: E Series and U Series. They also offer these in silicon plus their development boards. Freedom E310 (FE310) is the first member of the Freedom Everywhere family.

India's Shakti is a RISC-V chip developed at IIT Madras.

lowRISC is a fully open-sourced, Linux-capable, RISC-V-based SoC currently being developed. Their Rocket core currently runs on an FPGA.

RISC-V Foundation maintains a list of RISC-V cores and SoCs.

### What tools are available for developers who wish to work on RISC-V?

Basic tools include compiler, assembler, disassembler, profiler, debugger, and linker. Beyond these are IDEs, SDKs, simulators, and many more.

Tools are being developed and maintained by the team at UC Berkeley plus the wider community outside. RISC-V supports GNU/GCC, GNU/GDB and LLVM. Instruction Set Simulators (ISS) are available from Antmicro and QEMU. Full IDEs are available from Imperas, Microsemi and SiFive. SiFive's Eclipse-based IDE is called Freedom Studio. Tools are available to design your own RISC-V subsystem for FPGAs.

RISC-V Foundation maintains the state of the current RISC-V software ecosystem.

### Which operating systems have been ported to run on RISC-V?

Different flavours of Linux have been ported to RISC-V, including Yocto. In January 2018, kernel version 4.6 was being used. Researchers at the University of Cambridge have ported FreeBSD. As on August 2018, 80% of Debian software library has been compiled for RISC-V. Fedora/RISC-V project aims to bring the Fedora experience on RV64GC architecture.

Among the RTOS, Zephyr is planning a port as of August 2018. A port of FreeRTOS is also available.

## Milestones

2010

Researchers at the University of California, Berkeley conceive RISC-V (pronounced "risk five") as an ISA for research and education at Berkeley. Previously, they used SPARC ISA and a modified MIPS ISA but want a unified ISA for future projects. This is the fifth generation, following in the steps of four earlier generations in the 1980s.

May
2011

Version 1.0 of the RISC-V base user-level ISA is published as volume 1. This version is not frozen. Volume 2 is for supervisor-level ISA. About this time, Raven-1 testchip is taped out using ST 28nm FDSOI process node.

May
2014

Version 2.0 of the user-level ISA is published. This is a final frozen version.

2015

In January, the 1st RISC-V Workshop is organized in Monterey, CA. To drive the future development and adoption of RISC-V, **RISC-V Foundation** is established. With more than 100 member organizations, this is an open collaborative community including both hardware and software innovators.

Dec
2016

SiFive releases Freedom E310 32-bit microcontroller at 320 MHz. This is the first commercial RISC-V chip. The CPU core is SiFive E31 and its ISA is RV32IMAC.

Oct
2017

SiFive releases U54-MC Coreplex, the first RISC-V-based chip that supports Linux, Unix, and FreeBSD. It has 5 CPU cores: 4xU54 + 1xE51. This enables RISC-V processors to compete against ARM cores. In February 2018, SiFive releases a development board named HiFive Unleashed for this chip.

Jan
2018

It's reported that commercial players including Western Digital and Nvdia plan to use RISC-V ISA for their next generation of products.

Jul
2018

India's Shakti RISC-V processor at 400 MHz boots up Linux. The processor is based on Intel's 22nm FinFET process node.

RISC-V Architecture


# 5G Quality of Service

## Summary

5G Quality of Service (QoS) model is based on **QoS Flows**. Each QoS flow has a unique identifier called QoS Flow Identifier (QFI). There are two types of flows: Guaranteed Bit Rate (GBR) QoS Flows and Non-GBR QoS Flows. The QoS Flow is the finest granularity of QoS differentiation in the PDU Session. User Plane (UP) traffic with the same QFI receive the same forwarding treatment.

At the Non-Access Stratum (NAS), packet filters in UE and 5GC map UL and DL packets respectively to QoS flows. At the Access Stratum (AS), rules in UE and Access Network (AN) map QoS flows to Data Radio Bearers (DRBs).

Every QoS flow has a QoS profile that includes QoS parameters and QoS characteristics. Applicable parameters depend on GBR or non-GBR flow type. QoS characteristics are standardized or dynamically configured.

## Discussion

### Could you explain 5G QoS with an example?

Consider multiple PDU sessions, each of which could be generating packets of different QoS requirements. For example, packets from the Internet may be due to user browsing a website, streaming a video or downloading a large file from an FTP server. Delay and jitter are important for video but less important for FTP download.

Between the User Equipment (UE) and the Data Network (DN), PDU sessions and Service Data Flows (SDFs) are set up. Each application gets its own SDF. In our example, we may say that Internet, Netflix and IMS are PDU sessions. The Internet PDU session has four SDFs and the IMS PDU session has two SDFs.

Multiple IP flows can be mapped to the same QoS flow. QoS flow 2 is an example that carries both WhatsApp video and Skype video. On the radio interface, QoS flows are mapped to data radio bearers (DRBs) that are configured to deliver that QoS. Multiple QoS flows can be mapped to a single DRB. DRB2 is an example and it carries QoS flows 2 and 3.

### How does the QoS model differ between LTE and 5G networks?

In 4G/LTE, QoS is applied at the level of Evolved Packet Service (EPS) bearer. There's a one-to-one mapping, which really means that for an EPS bearer there's a corresponding EPS Radio Access Bearer (RAB), an S1 bearer and a Radio Bearer (RB).

5G provides a more flexible QoS model with **QoS Flow** being the finest granularity at which QoS is applied. The abstraction of QoS flow allows us to decouple the roles of 5G Core and NG-RAN. SMF in the 5G Core configures how packets ought to be mapped to QoS flows.

AN independently decides how to map QoS flows to radio bearers. This is a flexible design since gNB can choose to map multiple QoS flows to a single RB if such an RB can be configured to fulfil the requirements of those QoS flows. The figure shows an example in which QoS flow 1 goes on DRB1; QoS flows 2 and 3 go on DRB2.

To summarize, 4G QoS is at the EPS bearer level and 5G QoS is at the QoS flow level.

### Could you describe end-to-end QoS for a PDU session?

Application packets are classified or mapped to suitable QoS flows by the UPF in DL and UE in UL. UPF uses Packet Detection Rules (PDRs). UE uses QoS rules. Because multiple PDRs and rules can exist, these are evaluated in precedence order, from lowest to highest values. If no match is found, packet is discarded.

On the N3 interface between UPF and AN, packets are marked with QFI in an encapsulation header. Due to this marking, AN knows which packets belong to which QoS flow. SDAP sublayer in the AN maps the flows to suitable DRBs. At the receiving end, UE's SDAP sublayer does the reverse mapping from DRBs to QoS flows.

A similar flow happens for UL packets. UE marks the packet with QFI in SDAP header. AN does QFI marking in an encapsulation header on N3. UPF verifies if a received QFI is aligned with configured QoS rules or Reflective QoS.

### What's the basis for classifying packets into QoS flows?

In the downlink, UPF uses Packet Detection Rules (PDRs). In the uplink, UE uses QoS rules. Both these make use of Packet Filter Set that has one or more packet filters.

An **IP Packet Filter Set** is based on a combination of fields: Source/destination IP address or IPv6 prefix; Source/destination port number (could be a port range); Protocol ID of the protocol above IP/Next header type; Type of Service (TOS) (IPv4) or Traffic class (IPv6) and Mask; Flow Label (IPv6); Security parameter index; and Packet Filter direction.

An **Ethernet Packet Filter Set** is based on a combination of fields: Source/destination MAC address (may be a range); Ethertype as defined in IEEE 802.3; Customer-VLAN tag (C-TAG) and/or Service-VLAN tag (S-TAG) VID fields as defined in IEEE Std 802.1Q; Customer-VLAN tag (C-TAG) and/or Service-VLAN tag (S-TAG) PCP/DEI fields as defined in IEEE Std 802.1Q; IP Packet Filter Set, in the case that Ethertype indicates IPv4/IPv6 payload; and Packet Filter direction.

### What are the defaults used in the 5G QoS model?

The specification defines a **default QoS rule**. Every PDU session is required to have a QoS flow associated with such a default. This flow remains active for the lifetime of the PDU session. This is a Non-GBR QoS Flow to facilitate EPS interworking.

For IP and Ethernet sessions, the default QoS rule is the only rule with a Packet Filter Set that allows all UL packets, and it has the highest precedence. Note that QoS rules and PDRs are evaluated in increasing order of precedence values.

Reflective QoS is not applied and RQA is not sent for a QoS flow that's using default QoS flow.

**QoS parameters** too have defaults. On a per-session basis, SMF obtains from the UDM subscribed Session-AMBR, and subscribed defaults for Non-GBR 5QI, ARP and optionally 5QI Priority Level. Based on interaction with PCF, SMF may change subscribed values.

### What's the role of SMF within the QoS model?

QoS flows are controlled by SMF. They're preconfigured or created/updated via PDU Session Establishment or Modification procedures.

SMF interacts with UDM and PCF to obtain subscribed and authorized QoS parameters for each QoS flow. PCF responds with Policy Charging and Control (PCC) Rules that includes Packet Filter Set. SMF extracts QoS Flow Binding Parameters (5QI, ARP, Priority, MDBV, Notification Control) and creates a new QoS flow if one doesn't exist for this combination. The binding of PCC rules to QoS Flows is an essential role of SMF.

SMF associates a QoS flow with QoS profile, QoS rules and PDRs. PDRs are derived from the PCC rule and inherit the precedence value. PDRs are part of SDF Template passed to UPF. SMF sends QoS profile to AN via AMF over N2, QoS rules to the UE via AMF over N1, and PDRs to the UPF over N4.

SMF assigns a QFI for each QoS flow and an identifier to each QoS rule. Both identifiers are unique within the PDU session.

### What is meant by Reflective QoS?

For UL packet classification, SMF provides QoS rules to the UE. Or the UE implicitly derives the rules from downlink packets. This latter case is called **Reflective QoS**.

Both reflective and non-reflective QoS can coexist within the same PDU session. Reflective QoS applies to IP PDU session and Ethernet PDU session. UE indicates to SMF if it supports Reflective QoS during PDU Session Establishment. UE may change its support and indicate this via PDU Session Modification. UE-derived QoS rule would include UL packet filter, QFI and precedence value.

Reflective QoS is controlled per packet. SMF signals the use of **Reflective QoS Indication (RQI)** marking to UPF. SMF signals **Reflective QoS Attribute (RQA)** to the AN via N2 interface. Subsequently, UPF includes RQI for every DL packet of an SDF that's using Reflective QoS. AN indicates the RQI to the UE.

When UE receives a DL packet with RQI, it creates or updates the QoS rule for UL traffic. It also starts the **Reflective QoS Timer**. There's one timer per UE-derived rule. The timer is restarted when a matching DL packet is received. Rule is discarded when timer expires.

### Which are the 5G QoS parameters?

We note the following:

    + **5G QoS Identifier (5QI)**: An identifier for QoS characteristics that influence scheduling weights, admission thresholds, queue management thresholds, link layer protocol configuration, etc.
    + **Allocation and Retention Priority (ARP)**: Information about priority level, pre-emption capability (can pre-empt resources assigned to other QoS flows) and the pre-emption vulnerability (can be pre-empted by other QoS flows).
    + **Reflective QoS Attribute (RQA)**: Optional parameter. Certain traffic on this flow may use reflective QoS.
    + **Guaranteed Flow Bit Rate (GFBR)**: Measured over the Averaging Time Window. Recommended to be the lowest bitrate at which the service will survive.
    + **Maximum Flow Bit Rate (MFBR)**: Limits bitrate to the highest expected by this QoS flow.
    + **Aggregate Maximum Bit Rate (AMBR)**: *Session-AMBR* is per PDU session across all its QoS flows. *UE-AMBR* is for each UE.
    + **QoS Notification Control (QNC)**: Configures NG-RAN to notify SMF if GFBR can't be met. Useful if application can adapt to changing conditions. If alternative QoS profiles are configured, NG-RAN indicates if one of these matches currently fulfilled performance metrics.
    + **Maximum Packet Loss Rate**: In Release 16, this is limited to voice media.

### Could you describe some standardized 5QI values and their QoS characteristics?

Specification TS 23.501 defines some 5QI values that translate to QoS characteristics commonly used. This leads to optimized signalling, that is, specifying the 5QI value is sufficient, though default values can be modified. For non-standard 5QI values, QoS characteristics need to be signalled as part of the QoS profile.

SMF signals QoS profiles to NG-RAN via AMF. QoS characteristics in these profiles are in fact guidelines to the NG-RAN to configure suitable RBs to carry QoS flows.

There are about two dozen standard 5QI values, grouped into three resource types: Guaranteed Bit Rate (GBR), Non-GBR, Delay-critical GBR. **QoS characteristics** include resource type, priority level (lower number implies higher priority), Packet Delay Budget (PDB), Packet Error Rate (PER), averaging window (for GBR and delay-critical GBR only), and Maximum Data Burst Volume (MDBV) (for delay-critical GBR only).

Conversational voice (5QI=1) has 100ms PDB and 0.01 PER. Real-time gaming (5QI=3) has 50ms PDB and a lower priority. IMS signalling (5QI=5) has stringent PER of 0.000001. Discrete automation (5QI=82) has stringent PDB of 10ms.

### Does meeting 5G QoS requirements imply high QoE?

QoS is based on objective metrics whereas Quality of Experience (QoE) is more subjective and based on actual user experience. Thus, it's quite possible to optimize the network to yield better KPIs for QoS without users actually noticing any difference.

Delay, jitter and packet loss are some metrics used to determine QoS. QoE has different concerns: service accessibility, wait times, are users leaving because of poor features, response time, seamless interactivity, etc. QoE depends on user expectations, which can change with evolving technology and applications.

A 5% packet loss could have little impact for a cloud service but even a 0.5% packet loss could result in huge throughput reduction for another application. It's therefore clear that QoE should consider user and application perspectives, and not just network performance metrics. For example, on the same network with high bitrates an AR application might experience low QoE but a file download has high QoE even when latency or transport continuity are relatively poor. Even within AR, we can discern a variety of applications, each with its own QoE characteristics.

### What are the relevant specifications that detail 5G QoS?

An overview of 5G QoS model and architecture is given in **TS 38.300**, section 12. A more detailed and complete description of QoS is in **TS 23.501**, section 5.7. These two documents are good starting points for beginners.

From the perspective of 5G System (5GS) procedures, QoS details are covered in **TS 23.502**. QoS flow binding and parameter mapping are covered in **TS 29.513**. QoS Information Elements (IEs) are detailed in **TS 38.413**.

The mapping of QoS flows to Radio Bearers (RBs) is done at Service Data Adaptation Protocol (SDAP) sublayer, which is covered in **TS 37.324**.

## Milestones

Dec
2017

3GPP approves the first specifications for 5G, called "early drop" of **Release 15**. The focus of this release is Non-Standalone (NSA) mode of operation using Dual Connectivity (DC) between LTE and 5G NR. At this time, SDAP specification TS 37.324 is at v1.2.0 and not yet approved for Release 15.

Jun
2018

**SDAP specification TS 37.324**, v15.0.0 is approved for Release 15. This date coincides with "main drop" of Release 15 specifications. This release enables Standalone (SA) mode of operation based on 5G Core. SDAP sublayer in gNB and UE maps QoS flows to DRBs.

Oct
2018

Modern application traffic, particularly concerning mobile devices, often pass through enterprise networks, the Internet and cellular mobile networks. Whereas 3GPP uses QoS Class Identifiers (QCIs) and 5G QoS Identifiers (5QIs), IETF uses Differentiated Services Code Point (DSCP) markings. Henry and Szigeti therefore publish an IETF Internet-Draft titled *Diffserv to QCI Mapping*. Version 04 of this draft is published in April 2020 but it expires in October 2020, without any further continuity.

Mar
2019

Specification **TS 23.501** is updated for Release 16. Among QoS-specific changes are Deterministic QoS for Time-Sensitive Communication (TSC); QoS support for Multi-Access PDU Session; and New 5QIs for Enhanced Framework for Uplink Streaming.

Apr
2020

As an example from an implementation perspective, we note Cisco's publication of document titled *Ultra Cloud Core 5G Session Management Function, Release 2020.02 - Configuration and Administration Guide*. This guide details the 5G QoS model and how it's managed by SMF. It explains default bearer QoS handling for 4G, 5G and Wi-Fi sessions.

5G Quality of Service