Prioritize and Estimate Bandwidth using Intel® Mobile Platform SDK

Submit New Article

Last Modified On :   April 29, 2008 2:47 AM PDT
Rate
 



Abstract

This article shows how to provide applications with the ability to adapt to various network conditions. Use the Intel® Mobile Platform SDK to estimate and prioritize available bandwidth to your Windows* applications. Code samples included.


Introduction

Estimating real-time network bandwidth accurately is a desirable feature for various applications in the wireless as well as wired world. End users typically enjoy having control over the available network bandwidth for their applications. The open source Intel® Mobile Platform Software Development Kit (SDK) 1.2 provides the needed functionality for estimating and prioritizing available bandwidth to adapt applications to varying network conditions. This article covers the APIs and their functionality and provides code samples that simulate and prioritize network bandwidth using Windows* sockets.


Bandwidth Estimation and Prioritization

Typically, applications like to have an estimate of the available bandwidth in order to know how much content they can push to or pull from the Internet. While the information on the theoretical limits on upload and download rates can be found easily, real-time estimation is quite complex since it is dependent on the current network conditions. There may also be multiple sockets within the same application competing for the available bandwidth. In such cases, applications may also want to have a prioritization scheme to give higher priority to a particular socket over others.

The Intel Mobile Platform SDK offers a rich set of functionality for bandwidth estimation and prioritization. Such functionality and its use are demonstrated in the following examples:

  • Quality of Service (QoS) implementation to limit the available bandwidth of competing sockets over VoIP socket to maintain audio rates
  • Automatic adjustment of the rendering content (for example, transitioning from high definition video playback to low definition) when the download rate on the client falls below a certain tolerance
  • Dynamic switching of speech codec in a VoIP application depending on current bandwidth
  • Defined system-wide network policies for enhanced user experience (for example, setting a bandwidth limit on peer-to-peer applications)

 

Let's look at a demonstration application before jumping into the APIs needed to build this functionality into your own applications.


The Intel® Mobile Platform SDK

The Intel Mobile Platform SDK has a set of APIs for bandwidth estimation and control at multiple levels (application, system, process, and connection). A single application can not only control its own process and connection, but also other processes connections. APIs can be used to get the theoretical upload and download rates, current system upload and download rates, and set a limit on the upload and download rates on any given socket. There is also an adaptive option to change the bandwidth limiter accordingly. For example, if the link speed doubles, which can happen with WiFi, the previously set limit will be doubled automatically.

Demonstration

The included sample application demonstrates the bandwidth-related functionality using the Intel Mobile Platform SDK. The code was developed using C++ on a laptop system with Intel® Centrino® Mobile Technology and running the Windows* XP Professional operating system. The sample application simulates network traffic using Windows sockets between the client and a server node. The main functionality demonstrated in the demo includes real-time bandwidth estimation and bandwidth prioritization.


Figure 1: User Interface of Bandwidth Demo

The sample demonstration is run as follows:

  • Run the binary on the server node. Click Server, and then click Run.
    This will initiate the server node and keep it in “listening” mode for client connections.
  • Run the binary on the client node and click Client. Set the options for IP, Port, Buffer-Size and then click Run. If the server is not running on the same system as the client, specify the IP of server node.
  • Click Run on the client node to establish the connection with the server node. This simulates network traffic using Windows sockets.

 

The UploadRate or DownloadRate output provides the real-time upload and download rates estimated using the Intel Mobile Platform SDK. The results can be verified by noting the total time taken to upload and download the data size chosen in the Trial Data Size option.

The following steps demonstrate the Bandwidth Restriction functionality:

  • Start the server node as before in “listening” mode.
  • Start the client binary and select the Restrict Bandwidth check box.
  • Specify the upload and download limits in Kbps.
  • Click Run while in the client node.
    This simulates network traffic as before, but will enforce the upload and download limits set on the socket connection.
  • Clear the Restrict Bandwidth check box while the simulation is running to remove the restriction. For example, in Figure 1, notice that the upload rate went up from 0.11Mbps to 11.99Mbps once the restriction was removed.

 


Implementing Your Own Bandwidth Features

To get started, download and install the Intel Mobile Platform SDK. The distribution includes precompiled binaries, source code and API documentation.

All the capabilities for a given system are grouped into the ContextClass category in the Intel Mobile Platform SDK. For example, Connectivity/Bandwidth/Power falls into the ContextClass category. All bandwidth-related methods are invoked with the BandwidthInstance class. The following code shows an example of how to get the instance object for bandwidth and invoke some of the bandwidth related methods.

Creating an Instance Object for Bandwidth
ContextClass MyContextClass;
BandwidthInstance*
pMyBandwidthInstance;
pMyBandwidthInstance=reinterpret_cast<BandwidthInstance*>
(MyContextClass.GetInstance(L"Bandwidth") );

 

You'll probably do something exactly the same as this in your own application. Once you have the BandwidthInstance object you can start interrogating the instance about the current bandwidth. Here is some code that shows off some of the bandwidth estimation functionality:

//Bandwidth APIs report in Kbps. Convert if necessary
//p is pointer to BandwidthInstance Object
float factor = (format==MEGABYTESPERSEC)
? (float)1./(float)(8.*1024.):(float)1.;
//socket upload rate limit
float LimitTx = p->GetSessionLimitTx(sock)*factor;
//socket download rate limit
float LimitRx = p->GetSessionLimitRx(sock)*factor;
//socket current upload rate
float RateTx = p->GetSessionRateTx(sock)*factor;
//socket current download rate
float RateRx = p->GetSessionRateRx(sock)*factor;
//is upload rate restricted?
int LimitedTx = p->GetSessionLimitedTx(sock);
//is download rate restricted?
int LimitedRx = p->GetSessionLimitedRx(sock);

 

In this code, we have set a factor that is used to calculate the transmit data by different measurement. You’ll see a few calls to the API too. For example, GetSessionLimitTx() returns the maximum kilobits per second the given socket can transmit over network devices, and getSessionRateTx() returns the measured transfer rate the connection has transmitted over network devices.

If you’re going to be restricting the bandwidth you’ll want to use the setSessionLimitXXX() set of methods. The SetSessionLimitedRx() method enables or disables enforcement of a connection limit for receiving data and SetSessionLimitedTx() enables or disables enforcement of a connection limit for sending data. Here’s some code that enforces the upload/download limits on sockets.

//active_socket is the socket descriptor 
//upload/download input is in Kbps
//set socket download limit
pMyBandwidthInstance->SetSessionLimitRx(active_socket,download);
//set socket upload limit
pMyBandwidthInstance->SetSessionLimitTx(active_socket,upload);
//note that the limits set above are not enforced yet!
//enforce the upload/download limits on sockets below
pMyBandwidthInstance->SetSessionLimitedRx(active_socket,true);
pMyBandwidthInstance->SetSessionLimitedTx(active_socket,true);

 

As you can see, interrogating and limiting the bandwidth is really easy with the MPSDK. A question remains open though: how do you know when to limit and when to extend the bandwidth? Ideally, what you need is a way for your application to be notified when changes occur to the network connectivity. The MPSDK has just this functionality in the form of events. Essentially, you can register the application to listen in on network change events, and then take the appropriate action when they occur. The article, Intel® Mobile Platform SDK: Monitor Connectivity Status, demonstrates this functionality.


Sample Code Download

Click here to download the sample code for this article. The zip file contains Powbat.sln and readme,txt files. Please read readme.txt before you open the solution files.


Conclusion

Bandwidth estimation and prioritization are desirable features that can enhance the end-user experience. This article demonstrates how to use the Intel Mobile Platform SDK for bandwidth estimation prioritization. For more information on the Intel Mobile Platform SDK, visit http://ossmpsdk.intel.com/


References

Intel Mobile Platform SDK 1.2 Open Source Project


About Authors

Karthik Krishnan is a software engineer with the Software Solutions Group at Intel. He holds a Masters degree in Mathematics from the Indian Institute of Technology. His current focus is on power and performance optimization of software applications on dual-core platforms.

Joe Zhao is a Software Technical Consulting Engineer working for Intel Corporation's Software and Solutions Group in Shanghai, China. He worked for nearly 2 years in Intel. He was the engineer in supporting Mobile Platform SDK, and now he is in charge of the maintenance of MPSDK Open Source project website. He got Master degree from the University of East Anglia in England.