Monday, August 5, 2013

Starbucks API Explorer view
This post will deviate from the earlier posts on networking. Here I want to describe the UI and implementation for trying out REST based APIs. Here I will address questions such as what should the UI look like ? Should it be server side implementation or client side implementation. Should it be implemented in a browser or should it be a mobile device application ?
For now we will refer to our implementation as an app.
Next, Let's look at a few use cases.
The most common use case for the UI is to target the REST APIs from a single provider. This means its targetting a known endpoint and port. In fact, the URI is structured in a way that users are scoped down to the most variable part towards the end of the URI. Thus the app should only ask for the resource qualifier and retain the value from the previous usage.
Another thing is that the the method such as GET or POST should be easily selected. On Mobile devices, auto complete works better than drop down but there is no preference between the two.
Also additional methods to auto populate query parameters should be made available such as to get tokens
The query string itself can be constructed with a name value parameters where the names are populated before hand. Each API supports a pre-canned set of query parameters and request body.Therefore name value parameters should be added on user wish to specify more. Initially this list could be a collapsible pane hiding the complexity of additional parameters unless the user wants more and more fields to populate. Typing on mobile devices is hard so reliance on user session and auto-complete feature could come useful.
The choice of method should additionally define the Request Header and Request Body.
The request header can also be thought of comprising name value pairs so the treatment given to query parameters can be the same for request header fields.
The choice of return type such as JSON or XML need not be specified in the Request header. These are very frequently used fields and hence they are candidates for independent controls by themselves.
Next, the Response can be rendered either as plain text, or with markups. If the JSON is being rendered, separating out the name value pairs on separate lines may be helpful. Similarly XML may have each element on a new line. Indentations can help in both cases.
Long strings are common in several fields of the above mentioned form, therefore splitting it and displaying it in a vertical format will help visually. Even for URLs, we could consider keeping endpoints and resource locator apart. The strings are difficult to scroll in the limited breadth of a portfolio styled screen. 
Having described the page for the composer of the HTTP request, it is important to note that endpoints are usable only when they are documented. Hence the Explorer view must provide a link to the corresponding documentation of each API. There could be a separate view to list the endpoints. This is helpful to browse all that is available. 
Also, when we talk about the overview of the pages seen when the user opens the application, we list these pages such as an API browser to show all endpoints, a Composer to make requests, a capture to show the requests and responses capture and to browse the responses in detail. 
An app to explore Starbucks API :

This is along the same lines as Fiddler or Facebook Graph API explorer. In fact mobile applications don't have a handy app to test REST URIs like we can do from desktop. This application can be made available on IPhone or Windows phone as well. 

Sunday, August 4, 2013

DiffServ continued...

Forwarding techniques in Differentiated Services (DiffServ) model:
Expedited Forwarding (EF):
This is a technique that assigns different priorities to incoming traffic flows. The flows don't interfere with each other because there is no queuing delay. Flows are admitted based on their peak rate. The network does not let the rate fall below a limit. If the flow varies beyond expected rates, then the packets are either dropped or the flow is shaped. We will discuss traffic shaping shortly. Since the rate is reserved along the route for the packets, this forwarding technique can be thought of as a virtual circuit.
The example here is that of a virtual leased line service where the line is admitted if the sum of all lines does not exceed the link bandwidth.
Assured Forwarding (AF):
Assured Forwarding (AF) is a technique that maintains one or more bands of service such as gold, silver etc. Each service has a reservation for bandwidth and allocation for buffers. Within each class, there are three priorities that determine which packets get dropped when there is a congestion. Unlike expedited forwarding, the flow that does not conform is reclassified. It could end up in the unregulated best effort band.
AF and EF continue to be developed. Notice that it is the core routers where these forwarding takes place. For simple forwarding schemes, this is alright. For complex forwarding schemes, an entity such as a bandwidth broker is required that can manage the bandwidth across the core network. There are several ways to design such broker with stateless management of bandwidths across core routers.
But there are other problems as well. For example, the core routers may not all be DiffServ based. Besides flows may traverse networks with different forwarding behaviors. Packets may be handled differently by different routers along the path. A repository for listing the routers in the network such as we get with SNMP is required. This poses challenges to determining end to end service.

QoS continued

Differentiated services
This continues from the previous post on IntServ. DiffServ tries to address the difficulties with IntServ. For example, if the routers all keep track of the per flow reservations, then they don't scale when the number of flows is high such as in the case of high speed networks. Also, Diffserv is able to provide bands of service because the network as a whole makes the decisions. The edge routers decide what service model can be met. This simpler service description is signaled through the network with a method simpler than the RSVP. The packets are labeled with a priority stamp. With these labels, the core of the network finds it easy to forward packets instead of the per flow states that was being maintained. Therefore the network provides expedited services instead of best effort an d is an incremental improvement over the existing networks.
Moreover, the service providers can define and implement any forwarding behavior on top of this architecture. So service providers can differentiate their services. The architecture supports QoS by aggregating flows and yet allows service providers to implement per-flow Scalability and differentiated services are the two important advantages of this design.
Diffserv
The edge router performs the admission control functions such as classification, metering, marking and conditioning. Classification determines the labels based on rules. Metering checks whether the traffic can be accomodated. Marking marks packets with their labels. Conditioning regulates the traffic even discarding if forwarding is not possible.
The markings are based on Type of Service in IPv4 and traffic class in IPv6.
The core routers perform only forwarding according to "Per-Hop-Behaviour"  depending only on the labels. Thus the core routers are stateless. The Per-hop-Behaviour is what service providers can dictate.

Saturday, August 3, 2013

QoS Discussion continued

IntServ is an IETF standard that provides per-flow QoS. Support specific applications such as video streaming because each flow is controlled based on equations. A service model describes what the network can guarantee for the flow. An application uses an interface to describe the guarantees it needs. And the network meets the guarantees by scheduling the packets. The guarantees are established at the time the applications are admitted.
Each stream or flow can have a different QoS - for example, best effort, predictive or differentiated services, and strong guarantees on the level of service (real-time).The set of services that is supported on a specific network can be viewed as a service model. Services can be selected based on performance or cost tradeoffs. Service models can be say guaranteed service, controlled load, or best effort. Guaranteed service is the best offering where bandwidth, delay and jitter are controlled and applications can expect real time performance. Controlled load targets applications that can adapt to network conditions for short durations and can specify traffic characteristics and bandwidth. Best effort has no quality of service. Both Guaranteed service and controlled load require that applications be denied admission if their QoS cannot be met. Once admitted, the QoS is maintained.
Flows are setup by sessions. Sessions define the QoS being requested by the receiver. This is usually defined by rate r  and is called the R-spec. The traffic characteristics is defined in terms of rate r and the buffer size b and is called the T-spec. Traffic characteristics are best described by a leaky bucket. The rate and the bucket size determine the flow. RSVP is the signaling protocol that is used to pass around the R-spec and T-spec to the routers where the reservation is required.
Guaranteed service uses token bucket filter to characterize traffic and weighted fair queuing at the routers.  A bit about this in detail shortly. Routers will admit calls based on their R-spec and T-spec and based on their current resource allocated at the routers to other calls.
Now back to weighted fair queuing which is a scheduling technique. This assigns different priorities to data flows that share the same communication link. Think of the link as being broken down into a number of communication channels each having varying bit rates. The sharing adapts to the instantaneous traffic demands of the data streams that are transferred over each channel. It uses statistical techniques.  With a link data rate of R and N simultaneous data flows, the average data rate is R/N. The weights are assigned to the data flows to denote the priorities. Therefore, the data flow number i will have an average data flow rate of Rwi/ (w1 + w2 + w3 ... + wn). Notice that if the weights are fractional and they add up to one, the average rate translates to probability distribution. And one flow does not affect the others if it sends packets more than its rate. As an example of weighted fair queuing, consider the CDMA spread spectrum networking. Here the weights may be the cost for the required energy
This is different from fixed sharing of links either via time division multiplexing or frequency division multiplexing. The improvement in the link utilization is referred to as the statistical multiplexing gain.
Courtesy : Lecture notes CMU and wikipedia.

IL code on .Net platform to Objective-C gcc 4.6 instruction set on MacOS conversion.


Dual Mode operation

Dual mode operation is common in computing. Take edge routers for instance. As opposed to core routers, Edge routers additionally perform admission control. To provide more context to routers and admission control, lets' review quality of service.
Internet has been serving a single class of service called the Best Effort service. There is no assurances about delivery. Such assurances based on rate and throughput are defined as quality of service. In the absence of quality of service (QoS), applications have to tolerate losses and delays and adapt to congestion. Should we modify the applications to be more adaptive or should we modify the internet to support QoS.
Applications that adapt to the performance of network are called "tolerant real-time" and those that demand hard limits on performance are called "intolerant  real-time".
 Quality of Service guarantees are based on sharing and congestion studies. In order to study congestion, packets are marked for router to distinguish between different classes and new router policies to treat packets differently.  QoS guarantees provide isolation for one class from other classes When allocating different bandwidths to each application flow, bandwidth may not be efficiently used. Therefore another tenet of Qos guarantees is that while providing isolation to different classes, it is preferred to utilize the resources as efficiently as possible. Since most networks have a link capacity that cannot be exceeded. there is a need to control admission. Applications can declare their requirements, and network can block if it cannot provide the resources.
Therefore Quality of Service are provided using packet classification, Isolation: scheduling and policy, high resource utilization  and call admission
IntServ and DiffServ are models of providing quality of Service. IntServ stands for Integrated services and DiffServ stands for Differentiated Services. In the IntServ model, QoS is applied on a per flow basis and addresses concerns such as business model and charging. Even in mobile phone networks, this is evident when certain billing options are desirable but not possible. In Differentiated services, the emphasis is on scalability, flexible service model, and simpler signaling. Scalability here means we don't track resources for each of the possibly large number of flows. Service model means we provide bands of service such as platinum, gold and silver.
Courtesy: lecture notes CMU