{'fraction_non_alphanumeric': 0.04253097451756059, 'fraction_numerical': 0.007992128355991085, 'mean_word_length': 4.453948088927828, 'pattern_counts': {'":': 0, '<': 1, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
WNetKAT: A Weighted SDN Programming and Verification Language

Programmability and verifiability lie at the heart of the software-defined networking paradigm. While OpenFlow and its match-action concept provide primitive operations to manipulate hardware configurations, over the last years, several more expressive network programming languages have been developed. This paper presents WNetKAT, the first network programming language accounting for the fact that networks are inherently weighted, and communications subject to capacity constraints (e.g., in terms of bandwidth) and costs (e.g., latency or monetary costs). WNetKAT is based on a syntactic and semantic extension of the NetKAT algebra. We demonstrate several relevant applications for WNetKAT, including cost- and capacity-aware reachability, as well as quality-of-service and fairness aspects. These applications do not only apply to classic, splittable and unsplittable (s; t)-flows, but also generalize to more complex network functions and service chains. For example, WNetKAT allows to model flows which need to traverse certain waypoint functions, which may change the traffic rate. This paper also shows the relation between the equivalence problem of WNetKAT and the equivalence problem of the weighted finite automata, which implies undecidability of the former. However, this paper also succeeds to prove the decidability of another useful problem, which is sufficient in many practical scnearios: whether an expression equals to 0. Moreover, we initiate the discussion of decidable subsets of the whole language.


Introduction
Managing and operating traditional computer networks is known to be a challenging, manual and error-prone process. Given the critical role computer networks play today, not only in the context of the wide-area Internet but also of enterprise and data center networks, this is worrisome. Software-Defined Networks (SDNs) in general and the OpenFlow standard in particular, promise to overcome these problems by enabling automation, formal reasoning and verification, as well as by defining open standards for vendors. Indeed, there is also a wide consensus that formal verifiability is one of the key advantages of SDN over past attempts to innovate computer networks, e.g., in the context of active networking [38]. Accordingly, SDN/OpenFlow is seen as a promising paradigm toward more dependable computer networks.
At the core of the software-defined networking paradigm lies the desire to program the network. In a nutshell, in an SDN, a general-purpose computer manages a set of programmable switches, by installing rules (e.g., for forwarding) and reacting to events (e.g., newly arriving flows or link failures). In particular, OpenFlow follows a match-action paradigm: the controller installs rules which define, using a match pattern (expressed over the packet header fields, and defining a flow), which packets (of a flow) are subject to which actions (e.g., forwarding to a certain port).
While the OpenFlow API is simple and allows to manipulate hardware configurations in flexible ways, it is very low level and not well-suited as a language for human programmers. Accordingly, over the last years, several more high-level and expressive domain-specific SDN languages have been developed, especially within the Frenetic project [13]. These languages can also be used to express fundamental network queries, for example related to reachability: They help administrators answer questions such as "Can a given host A reach host B?" or "Is traffic between hosts A and B isolated from traffic between hosts C and D?".
What is missing today however is a domain-specific language which allows to describe the important weighted aspects of networking. E.g., real networks naturally come with capacity constraints, and especially in the Wide-Area Network (WAN) as well as in data centers, bandwidth is a precious resource. Similarly, networks come with latency and/or monetary costs: transmitting a packet over a wide-area link, or over a highly utilized link, may entail a non-trivial latency, and inter-ISP links may also be attributed with monetary costs.
Weights may not be limited to links only, but also nodes (switches or routers) have capacities and costs e.g., related to the packet rate. What is more, today's computer networks provide a wide spectrum of in-network functions related to security (e.g., firewalls) and performance (e.g., caches, WAN optimizers). To give an example, today, the number of so-called middleboxes in enterprise networks can be in the same order of magnitude as the number of routers [34]. A domain specific language for SDNs should be expressive enough to account for middleboxes which can change (e.g., compress or increase) the rate of the traffic passing through them. Moreover, a network language should be able to define that traffic must pass through these middleboxes in the first place, i.e., that routing policies fulfill waypointing invariants [40]. With the advent of more virtualized middleboxes, and the Network Function Virtualization paradigm, short NFV, (virtualized) middleboxes may also be composed to form more complex network services. For example, SDN traffic engineering flexibilities can be used to steer traffic through a series of middleboxes, concatenating the individual functions into so-called service chains [18,25]. For instance, a network operator might want to ensure that all traffic from s to t should first be routed through a firewall FW, and then through a WAN optimizer WO, before eventually reaching t: the operator can do so by defining a service chain (s, FW, WO, t). A Motivating Example. Let us consider a more detailed example, see the network in Figure 1: The network hosts two types of (virtualized) functions F 1 and F 2 : possible network functions may include, e.g., a firewall, a NAT, a proxy, a tunnel endpoint, a WAN optimizer (and its counterpart), a header decompressor, etc. In this example, function F 2 is instantiated at two locations. Functions F 1 and F 2 may not be flow-preserving, but may decrease the traffic rate (e.g., in case of a proxy, WAN optimizer, etc.) or increase it: e.g., a tunnel entry-point may add an extra header, a security box may add a watermark to the packet, the counterpart of the WAN optimizer may decompress the packet, etc. Links come with a certain cost (say latency) and a certain capacity (in terms of bandwidth). Accordingly, we may annotate links with two weights: the tuple (2, 3) denotes that the link cost is 2 and the link capacity 3. We would like to be able to ask questions such as: Can source s emit traffic into the service chain at rate x without overloading the network? or Can we embed a service chain of cost (e.g., end-to-end latency) at most x?. Contributions. This paper initiates the study of weighted network languages for programming and reasoning about SDN networks, which go beyond topological aspects but account for actual resource availabilities, capacities, or costs. In particular, we present WNetKAT, an extension of the NetKAT [5] algebra.
For example, WNetKAT supports a natural generalization of the reachibility concepts used in classic network programming languages, such as cost-aware or capacity-aware reachability. In particular, WNetKAT allows to answer questions of the form: Can host A reach host B at cost/bandwidth/latency x?
We demonstrate applications of WNetKAT for a number of practical use cases related to performance, qualityof-service, fairness, and costs. These applications are not only useful in the context of both splittable and unsplittable routing models, where flows need to travel from a source s to a destination t, but also in the context of more complex models with waypointing requirements (e.g., service chains).
The weighted extension of NetKAT is non-trivial, as capacity constraints introduce dependencies between flows, and arithmetic operations such as addition (e.g., in case of latency) or minimum (e.g., in case of bandwidth to compute the end-to-end delay) have to be supported along the paths. Therefore, we extend the syntax of NetKAT toward weighted packet-and switch-variables, as well as queues, and provide a semantics accordingly. In particular, one contribution of our work is to show for which weighted aspects and use cases which language extensions are required.
We also show the relation between WNetKAT expressions and weighted finite automata [10] -an important operational model for weighted programs. This leads to the undeciability of WNetKAT equivalence problem.
However, leveraging this relation we also succeed to prove the decidability of whether an expression equals to 0: for many practical scenarios a sufficient and relevant solution. Moreover, this paper initiates the discussion of identifying decidable subsets of the whole language. Related Work. Most modern domain-specific SDN languages enable automated tools for verifying network properties [12,13,28,43,44]. Especially reachability properties, which are also the focus in our paper, have been studied intensively in the literature [19,20]. Indeed, the formal verifiability of the OpenFlow match-action interface [19,20,29,47] constitutes a key advantage of the paradigm over previous innovation efforts [6]. Existing expressive languages use SAT formulas [26], graph-based representations [19,20], or higher-order logic [45] to describe network topologies and policies.
Our work builds upon NetKAT, a new framework based on Kleene algebra with tests for specifying, programming, and reasoning about networks and policies. NetKAT respresents a more principled approach compared to prior work, and is also motivated by the observation that end-to-end functionality is determined not only by the behavior of the switches and but also by the structure of the network topology. NetKAT in turn is based on earlier efforts performed in the context of NetCore [27], Pyretic [28] and Frenetic [13]. It has recently been extended to a probabilistic setting [14]. The Kleene algebra with tests was developed by Kozen [24].
However, to the best of our knowledge, there is prior work on weighted versions of NetKAT. Organization. The rest of this paper is organized as follows. Section 2 provides the necessary background on SDN and NetKAT. Section 3 introduces WNetKAT, our weighted version of NetKAT. Section 4 demonstrates the usefulness of our extensions in a number of applications. Section 5 and Section 6 discuss complexity and implementation aspects. Section 7 concludes our contribution.

Background
We first provide a more detailed introduction to OpenFlow, and then describe the programming language NetKAT, which compiles to OpenFlow. SDN and OpenFlow. A Software-Defined Network (SDN) outsources and consolidates the control over data plane elements to a logically centralized control plane implemented in software. Arguably, software-defined networking in general, and its de facto standard, OpenFlow, are about programmability, verifiability and generality [11]: A software-defined network allows programmers to write network applications (for example for traffic engineering) in software. The behavior of an OpenFlow switch is defined by its configuration: a list of prioritized (flow) rules stored in the switch flow table, which are used to classify, filter, and modify packets based on their header fields. In particular, OpenFlow follows a simple match-action paradigm: the match parts of the flow rules (expressed over the header fields) specify which packets belong to a certain flow (e.g., depending on the IP destination address), and the action parts define how these packets should be processed (e.g., forward to a certain port). OpenFlow supports a rather general packet processing: it allows to match and process packets based on their Layer-2 (e.g., MAC addresses), Layer-3 (e.g., IP addresses), and Layer-4 header fields (e.g., TCP ports), or even in a protocolindependent manner, using arbitrary bitmasking [4]. For example, an OpenFlow router may forward packets destined to http ports differently from traffic destined to ftp ports. In other words, an OpenFlow switch blurs the difference between switches and routers (the two terms are used interchangeably in this paper), and even supports some basic middlebox functionality.
OpenFlow also readily supports quantitative aspects, e.g., the selection of queues annotated with different round robin weights (the standard approach to implement quality-of-service guarantees in networks today), or meters (measuring the bandwidth of a flow). Moreover, we currently witness a trend toward more flexible and stateful programmable switches and packet processors, featuring group tables, counters, and beyond [31,4,1,3,39,37,2]. NetKAT. The formal framework developed in this paper is based on NetKAT [5]. Here we briefly review the main concepts underlying NetKAT, and discuss how they relate to OpenFlow.
NetKAT is a high-level algebra for reasoning about network programs. It is based on Kleene Algebra with Tests (KAT), and uses an equational theory combining the axioms of KAT and network-specific axioms that describe transformations on packets (as performed by OpenFlow switch rules). These axioms facilitate reasoning about local switch processing functionality (needed during compilation and for optimization) as well as global network behavior (needed to check reachability and traffic isolation properties). Basically, an atomic NetKAT policy (a function from packet headers to sets of packet headers: essentially the per-switch OpenFlow rules discussed above) can be used to filter or modify packets. Policy combinators (+) allow to build larger policies out of smaller policies. There is also a sequential composition combinator to apply functions consecutively.
Besides the policy, modeling the per-switch OpenFlow rules, a network programming language needs to be able to describe the network topology. NetKAT models the network topology as a directed graph: nodes (hosts, routers, switches) are connected via edges (links) using (switch) ports. NetKAT simply describes the topology as the union of smaller policies that encode the behavior of each link. To model the effect of sending a packet across a link, NetKAT employs the sequential composition of a filter that retains packets located at one end of the link, and a modification that updates the switch and port fields to the location at the other end of the link. Note that the NetKAT topology and the NetKAT policy are hence to be seen as two independent concepts. Succinctly: A Kleene algebra (KA) is any structure (K, +, ·, * , 0, 1), where K is a set, + and · are binary operations on K, * is a unary operation on K, and 0 and 1 are constants, satisfying the following axioms, where we define p ≤ q iff p + q = q. p is a two-sorted structure (K, B, +, ·, * , , 0, 1), where B ⊆ K and • (K, +, ·, * , 0, 1) is a Kleene algebra; • (B, +, ·, , 0, 1) is a Boolean algebra; • (B, +, ·, 0, 1) is a subalgebra of (K, +, ·, 0, 1).
The elements of B are called tests. The axioms of Boolean algebra are: NetKAT is a version of KAT in which the atoms (elements in K) are defined over header fields f (variables) and values ω: ("test the value of a header field") • dup ("duplicate the packet") The set of all possible values of f is denoted Ω. For readability, we use skip and drop to denote 1 and 0, respectively.
The NetKAT axioms consist of the following equations, in addition to the KAT axioms on the commutativity and redundancy of different actions and tests, and enforcing that the field has exactly one value: In terms of semantics, NetKAT uses packet histories to record the state of each packet on its path from switch to switch through the network. The notation pk 1 , . . . , pk n is used to describe a history with elements pk 1 , . . . , pk n being packets; pk :: is used to denote a history with one element and pk :: h to denote the history constructed by prepending pk on to h. By convention, the first element of a history is the current packet (the "head"). A NetKAT expression denotes a function : H → 2 H , where H is the set of packet histories. Histories are only needed for reasoning: Policies only inspect or modify the first (current) packet in the history. Succinctly: Consider the network in Figure 1. NetKAT can be used to specify the topology as follows, where the field sw stores the current location (switch) of the packet: 2 ; sw ← t The first line of the above NetKAT expression specifies that if the packet is at s, then it will be sent to F 1 or v. Analogously for the other cases. In OpenFlow, this policy can be implemented using OpenFlow rules, whose match part applies to packets arriving at s, and whose action part assigns the packets to the respective forwarding ports.
However, one can observe that with NetKAT it is not possible to specify or reason about the important quantitative aspects in Figure 1, e.g., the cost and capacity along the links or the function of F 2 which changes the rate of the flow. To do these, a weighted extension of NetKAT is needed.

WNetKAT
On a high level, a computer network can be described as a set of nodes (hosts or routers) which are interconnected by a set of links, hence defining the network topology. While this high-level view is sufficient for many purposes, for example for reasoning about reachability, in practice, the situation is often more complex: both nodes and links come with capacity constraints (e.g., in terms of buffers, CPU, and bandwidth) and may be attributed with costs (e.g., monetary or in terms of performance). In order to reason about performance, cost, and fairness aspects, it is therefore important to take these dimensions into account.
The challenge of extending NetKAT to weighted scenarios lies in the fact that in a weighted network, traffic flows can no longer be considered independently, but they may interfere: their packets compete for the shared resource. Moreover, packets of a given flow may not necessarily be propagated along a unique path, but may be split and distributed among multiple paths (in the so-called multi-path routing or splittable flow variant). Accordingly, a weighted extension of NetKAT must be able to deal with "inter-packet states".
We in this paper will think of the network as a weighted (directed) graph G = (V, E, w). Here, V denotes the set of switches (or equivalently routers, and henceforth often simply called nodes), E is the set of links (connected to the switches by ports), and w is a weight function. The weight function w applies to both nodes V as well as links E. Moreover, a node and a link may be characterized by a vector of weights and also combine multiple resources: for example, a list of capacities (e.g., CPU and memory on nodes, or bandwidth on links) and a list of costs (e.g., performance, energy, or monetary costs).
In order to specify the quantitative aspects, we propose in this paper a weighted extension of NetKAT: WNetKAT. In addition to NetKAT: • WNetKAT includes a set of quantitative packet-variables to specify the quantitative information carried in the packet, in addition to the regular (non-quantitative) packet-variables of NetKAT (called fields in NetKAT): e.g., regular variables are used to describe locations, such as switch and port, or priorities, while quantitative variables are used to specify latency or energy. The set of all packet-variables is denoted by V p .
x ← ω (ρ, pk :: h) where r ′ = Σ y p ∈V ′ ∩V p pk(y p ) + Σ y s ∈V ′ ∩V q ρ(v, y s ) + r Table 1: Semantics of WNetKAT • WNetKAT also includes a set of switch-variables, denoted by V s , to specify the configurations at the switch.
Switch variables can either be quantitative (e.g., counters, meters, meta-rules [4,32]) or non-quantitative (e.g., location related), as it is the case of the packet-variables.
Remarks: The set of quantitative (packet-and switch-) variables is denoted by V q and these variables range over the natural numbers N (e.g., normalized rational numbers). The set of non-quantitative (packet-and switch-) variables is denoted V n and the set of the possible values is denoted Ω.
In addition to introducing quantitative variables, we also need to extend the atomic actions and tests of NetKAT. Concretely, WNetKAT first supports non-quantitative assignments and non-quantitative tests on the nonquantitative switch-variables, similar to those on the packet-variables in NetKAT. Moreover, WNetKAT also allows for quantitative assignments and quantitative tests, defined as follows, where x ∈ V q , V ′ ⊆ V q , δ ∈ N, ⊲⊳∈ {>, < , ≤, ≥, =}: Read the current values of the variables in V ′ and add them to δ, then assign this result to x.
Read the current value of the variables in V ′ and add them to δ, then compare this result to the current value of x.
Remarks: 1. In the quantitative assignment and test, only addition is allowed. However, an extension to other arithmetic operations (e.g., linear combinations) is straightfoward. Moreover, calculating minimum or maximum may be useful in practice: e.g., the throughput of a flow often depends on the weakest link (of minimal bandwidth) along a path. Note that these operations can actually be implemented with quantitative assignments and tests, i.e., by comparing every variable to another and determining the smallest. E.g., for x ∈ V q and y, z ∈ V q or N, In quantitative assignment and test, x might be in V ′ . 3. We use + to denote the arithmetic operation over numbers. Therefore, we will use "&" in WNetKAT to denote the "+" operator of Kleene Algebra, which is also used in [14].
Given the set of switches V, a switch-variable valuation is a partial function ρ : V ×V s ֒→ N∪Ω. It associates, for each switch and each switch-variable, a integer or a value from Ω. We emphasize that ρ is a partial function, as some variables may not be defined at some switches.
A WNetKATexpression denotes a function : ρ × H → 2 H , where H is the set of packet histories. The semantics of WNetKAT is defined in Table 1, where x ∈ V n , y ∈ V q , δ ∈ N and ω ∈ Ω. Remarks: • Equations (1) and (3) update the corresponding header field if x is a packet-variable, or they update the corresponding switch information of the current switch if x is a switch-variable. Equation (1) updates the non-quantitative variables and Equation (3) the quantitative ones. • Equations (2) and (4) test the non-quantitative and quantitative variables respectively, using the current packet-and switch-variables. Figure 1. The topology of the network can be characterized with the following WNetKAT formula t, where sw specifies the current location (switch) of the packet, co specifies the cost, and ca specifies the capacity along the links.

Example 2. Consider again the network in
The variable co accumulates the costs along the path, and the variable ca records the smallest capacity along the path. Notice that ca is just a packet-variable used to record the capacity of the path; it does not represent the capacity used by this packet (the latter is assumed to be negligible).
Assume that function F 1 is flow conserving (e.g., a NAT), while F 2 increases the flow rate by an additive constant γ ∈ N (e.g., a security related function, adding a watermark or an IPSec header).
The policy of F 2 can be specified as: p F 2 ::= (sw = F (1) 2 & sw = F (2) 2 ); ca ← ca + γ Remarks: Note that this simple example required only (non-quantitative and quantitative) packet-variables. However, as we will see in Section 4, to model more complex aspects of networking, such as splittable flows, additonal concepts of WNetKAT will be needed.

Applications
The weighted extensions introduced by WNetKAT come with a number of interesting applications. In this section, we show that the notions of reachability frequently discussed in prior work, find natural extensions in the world of weighted networks, and discuss applications in the context of service chains, fairness, and quality-of-service. In the Appendix, additional details are provided for some of these use cases.

Cost Reachability
Especially data center networks but also wide-area networks, and to some extent enterprise networks, feature a certain path diversity [42]: there exist multiple routes between two endpoints (e.g., hosts). This path diversity is not only a prerequisite for fault-tolerance, but also introduces traffic engineering flexibilities. In particular, different paths or routes depend on different links, whose cost can vary. For example, links may be attributed with monetary costs: a peering link may be free of charge, while an up-or down-link is not. Links cost can also be performance related, and may for example vary in terms of latency, for example due to the use of different technologies [36], or simply because of different physical distances. The monetary and performance costs are often related: for example, in the context of stock markets, lower latency links come at a higher price [33]. It is therefore natural to ask questions such as: "Can A reach B at cost at most c?". We will refer to this type of questions as cost reachability questions. Figure 2. The topology roughly describes the North American data centers interconnected by Google B4, according to [17].

Example 3. Consider the network in
In order to reason about network latencies, we not only need information about the switch at which the packet is currently located (as in our earlier examples), but also the port of the switch needs to be specified. We introduce the packet-variable pt. We can then specify this network topology in WNetKAT. The link from dc 1 to dc 2 (latency 4 units) represented by the port 1 at dc 1 and the port 4 at dc 2 is specified as follows, where we use packet-variable sw to denote the current switch, pt to specify the current port, and l to specify the latency of the path the packet traverses, sw = dc 1 ; pt = 1; sw ← dc 2 ; pt ← 4; l ← l + 4 Analogously, the entire network topology can be modeled with WNetKAT, henceforth denoted by t. The policy of the network determines the functionality of each switch (the OpenFlow rules), e.g., in dc 2 , packets from dc 1 to  Remarks: For ease of presentation, in the above example, we considered only one weight. However, WNetKAT readily supports multiple weights: we can simply use multiple variables accordingly. Moreover, while the computational problem complexity can increase with the number of considered weights [23], the multi-constrained path selection does not affect the general asymptotic complexity of WNetKAT.

Capacitated Reachability
Especially in the wide-area network, but also in data centers, link capacities are a scarce resource: indeed, widearea traffic is one of the fastest growing traffic aggregates [17]. However, also the routers themselves come with capacity constraints, both in terms of memory (size of TCAM) as well as CPU: for example, the CPU utilization has been shown to depend on the packet rate [30]. Accordingly, a natural question to ask is: Can A communicate at rate at least r to B? We will refer to this type of questions as capacitated reachability questions.
There are two problem variants: • Unsplittable flows: The capacity needs to be computed along a single path (e.g., an MPLS tunnel).
• Splittable flows: The capacity needs to be computed along multiple paths (e.g., MPTCP, ECMP). We will assume links of higher capacity are chosen first.
For both variants, to find out the capacity of paths between two nodes, a single test packet will be sent to explore the network and record the bandwidth/capacity with a packet-variable in the packet. We assume that the bandwidth consumed by this packet is negligibile. Also, only once the packet has traversed and determined the bandwidth, e.g., the actual (large) flows are allocated accordingly (by the SDN controller). Figure 2 again, but assume that the labels are the capacities rather than latency. Unsplittable flow scenario: The switch policies are exactly the same as in Example 3, while the topology will be specified similarly using packet-variable c to record the capacity of the link. E.g., the link between dc 1 and dc 2 can be specified as: Another (possibly) more efficient approach is not to update c while the bandwidth is smaller than r (meaning that a flow of size r cannot go through this link). In this case, one can specify the topology as follows, where c is not used to record the capacity along the path anymore, but rather to test whether this link is wide enough: sw = dc 1 ; pt = 1; sw ← dc 2 ; pt ← 4; c ≤ 4 The above WNetKAT expression only tests whether c is less than or equal to 4. It makes sure that the value of c (which is r) does not exceed the capacity of the following link. If it exceeds the capacity of the link, then a flow of rate r cannot use this link. Therefore, the test packet is dropped already. The capacitated reachability question can then be answered by checking whether the following expression is equal to drop: scr ← A; dst ← B; c ← r; sw ← A; pt(pt) * ; sw = B If the above formula does not equal drop, then A can communicate at rate at least r to B. Splittable flow scenario: For the splittable scenario, the situation is far more complicated. For example, in dc 2 , packets arriving at port 4 are sent out through port 1 or port 2, and port 2 prioritizes port 1. That is, if the incoming traffic has rate 4, then a share of 3 units will be sent out through port 2, and a 1 share through port 1.

Example 4. Consider the network in
Note that also here, still only one single test packet will be sent to collect the capacity information. This information will be stored in the packet-variable c as well. However, when the test packet arrives at a switch where a flow can be split, copies of the packet are sent (after updating the c according to the bandwidth of each path) to all possible paths, to record the capacity along all other paths. This exploits the fact that WNetKAT (NetKAT) treats the & operator as conjunction in the sense that both operations are performed, rather than disjunction, where one of the two operations would be chosen non-deterministically (according to the usual Kleene interpretation). Again, we emphasize that we will refer to c stored in one single test packet, and not the actual real data flow. Now the topology will update c as in the unsplittable case. However, the policy needs to not only decide which ports the packets go to, but also update c according to the split policy. E.g.,, at dc 2 , the data flow from dc 1 to dc 5 at rate 4 is sent out through port 1 at rate 3, and the port 3 at 1. And if the rate is smaller than or equal to 3, e.g., 2, then the whole flow of rate 2 will be sent out through port 1. The following WNetKAT formula specifies this behavior: The test c ≤ 5 ensures that the flow does not exceed the capacity of both paths. Notice that even when the size of the flow is small enough for one path, a copy of the test packet with c = 0 will still be sent to the other. This ensures that sufficient information is available at the switch where flows merge. That is, the switch collects the weights the packets carry (c in our example). The switch will only push packets to the right out-ports after all expected packets have arrived. This will happen before the switch sends the packet to the right out-ports. For example, at dc 4 , the flow from dc 1 to dc 5 might arrive in from ports 1 and 2 and will be sent out through port 3. In order to record the capacity of both links, switch-variables C and X are introduced, for each possible merge. For example, the following When a packet from dc 1 to dc 5 arrives at port 1 or 2 of dc 4 , first the switch collects the value of c and adds it to the switch-variable C, then decrements X to record that one packet arrived. Afterwards, we test whether all expected packets arrived (X = 0). If not, the current one is dropped; if yes, we send the current packet out to port 3. The reason that we can drop all packets except for the last, is that all those packets carry exactly the same values. Therefore, we eventually only need to include the merged capacity (C) in the last packet, and propagate it.
Combining the split and merge cases, the policy of the switch can be defined. For example, the second line of the merging rule table can be specified as follows, by first merging from port 3 and 4, and then splitting to port 1 and 2:

Service Chaining
The virtualization and programmability trend is not limited to the network, but is currently also discussed intensively for network functions in the context of the Network Function Virtualization (NFV) paradigm. SDN and NFV nicely complement each other, enabling innovative new network services such as service chains [18]: network functions which are traversed in a particular order (e.g., first firewall, then cache, then wide-area network optimizer). Our language allows to reason about questions such as Are sequences of network functions traversed in a particular order, without violating node and link capacities? WNetKAT can easily be used to describe weighted aspects also in the context of service chains. In particular, network functions may both increase (e.g., due to addition of an encapsulation header, or a watermark) or decrease (e.g., a WAN optimizer, or a cache) the traffic rate, both additively (e.g., adding a header) or multiplicatively (e.g., WAN optimizer). Figure 1, and consider a service chain of the form (s, F 1 , F 2 , t): traffic from s to t should first traverse a function F 1 and then a function F 2 , before reaching t. For example, F 1 may be a firewall or proxy and F 2 is a WAN optimizer. The virtualized functions F 1 and F 2 may be allocated redundantly and may change the traffic volume. Using WNetKAT, we can ask questions such as: What is the maximal rate at which s can transmit traffic into the service chain? or Can we realize a service chain of cost (e.g., latency) at most x?. Let us consider the following example: The question "Can s reach t at cost/latency at most ℓ and/or at rate/bandwidth at least r, via the service chain functions F 1 and F 2 ?", can be formulated by combining the reachability problems above and the waypointing technique in [5]. For example, in case of cost reachability, we can ask if the following WNetKAT formula equals drop. src ← s; dst ← t; co ← 0; sw ← s; pt(pt) * ; sw = F 1 ; p F 1 ; tpt(pt) * ; sw = F 2 ; p F 2 ; tpt(pt) * ; sw = t; co ≤ ℓ; ca ≥ r Note that in this example, we considered an unsplittable scenario. For the splittable scenario, we can extend the splittable capacitated reachability use case above analogously.

Fairness
Related to quality-of-service is the question of fairness. For example, a natural question to ask is: "Does the current flow allocation satisfy network neutrality requirements?" [46], or more specifically, "Is the network maxmin fair?" [16] For example, consider the network in Figure 3. The numbers on the links specify the bandwidth capacity. Suppose that there are three flows: s 1 → d 1 , s 1 → d 2 , s 2 → d 2 embedded in this network. Suppose the rates of these three flows are 2, 3, 1, respectively. In a max-min fair allocation, we aim to maximize the minimal flow allocated to any of these three flows, subject to capacity constraints. For example, the minimum flow s 2 → d 2 receives a fair share here: the flow is naturally limited by the first link of capacity 1. However, the next smallest rate, s 1 → d 1 , may be increased to 2.5, by reducing the flow s 1 → d 2 accordingly.  Figure 3. In order to specify whether the given rates for the flows are max-min fair, we send three test packets along the three flows respectively. The topology of this network can be specified in WNetKAT as before, which only takes care of forwarding packets. E.g., the link between s 1 and r 1 is specified as follows, where c specifies the capacity: sw = s 1 ; pt = 1; sw ← r 1 ; pt ← 1 The switches not only put incoming packets to the right outgoing ports, but also assign the bandwidth of the out-going links to different flows. This will be recorded in the test packets as a packet-variable, denoted by a. Moreover, three packet-variables x 1 , x 2 , x 3 are used to represent the rates of the flows that are supposed to be checked for max-min fairness.
E.g., the policy of r 1 can be specified as follows.
The first line specifies that the packets arriving at port 1 or 2 will be sent out through port 3. The following lines update a of the test packets, according the rates of the flows that share the link. In order to test max-min fairness, we first order the given rates increasingly. For example, to check whether the following flow rates are max-min fair, Then, we check them one-by-one, by verifying whether the following WNetKAT expressions are equal to drop or not.
x 2 = a While checking whether x 3 is max-min fair, one does not need to consider x 1 , x 2 (can be modified if not fair), because x 3 is the minimum; therefore, x 1 , x 2 are set to 0. While checking x 1 , it is already known that x 3 is fair. Therefore the value of x 3 cannot be changed even if x 1 is not fair; this is why x 3 is set to 1, and x 2 is 0 in f 1 .
Similarly for x 2 .
If all of the above formulas are not equal to drop, then the given rates are max-min fair. E.g., the above rates x 1 = 2, x 2 = 3, x 1 = 1 are not max-min fair because f 1 equals drop. This matches our discussion above.
Moreover, the results of the above tests can also help develop more fair rates. E.g., f 1 is the first list entry to equal drop, this means that x 1 is not fairly allocated. However, x 3 must be fair as f 3 does not equal drop. Therefore, to ensure max-min fairness in this network, one should keep the rate of the flow s 2 → d 2 , and adjust the rate of s 1 → d 1 and that of s 1 → d 2 .

Quality-of-Service
We have already shown how to specify and reason about a number of relevant use cases for weighted networks. An additional important motivation for weighted models concerns the ability to express and verify quality-of-service guarantees. For example, in a computer network (providing limited resources), it can be useful to prioritize a certain flow (e.g., a VoIP call) over another (e.g., a Dropbox synchronization). Figure 4.  It has two incoming ports 1, 2 and one outgoing port 3. Suppose there are two types of traffic flows going through this switch: skype calls and web surfing traffic. This switch should respect that the skype calls have higher priority, but at the same time not completely disallow the web surfing. Suppose we want to give skype calls 80% of the bandwidth and to web surfing only 20%. This policy can be easily specified with the following WNetKATexpression, where x is a packet-variable specifying the priority of the packet (e.g., skype has high priority high and http low low) and C h , C l are two switch-variables for counting the number of packets with the two priorities respectively. EQ Q (ρ, pk ::

Example 7. Consider the switch in
{ρ, pk :: h} if HEAD(Q) = pk :: h then DQ(Q) 1 * (ρ, pk :: h) otherwise (6) The second line deals with high priority packets: if the amount of the packets with this priority is less than 8, then it will be sent out through port 3. Similar for the low priority packets. The last line resets C h , C l to 0 when both reach the upper limit, triggering a new round of counting.

Further Extensions
While, using switch-variables (e.g., as counters), WNetKAT supports a basic form of prioritization, allowing to provide one flow with a larger share of the bandwidth than another, this solution is still naive. For example, when a skype packet arrives at switch r and C h is already 8, then this packet will be dropped, which might lower the quality of the skype call. In a even worse situation, in the absence of web traffic packets, the switch will still wait and drop all the incoming skype packets. To overcome these problems and improved notion of qualityof-service, we could introduce a notion of queue. Indeed, queues, e.g., annotated with different round robin weights, are an essential component in any computer network today, and are also the predominant mechanism to implement service differentiation. However, while OpenFlow actions can readily be used to enqueue a packet in a certain queue, it is the responsibility of the management plane (and not the SDN control plane) to actually allocate these queues and scheduling policies. While we currently witness first attempts to combine control and management planes [35], today, there does not exist any standard. Nevertheless, we in the following start exploring how WNetKAT could be extended with a notion of queues.
Concretely, we can extend WNetKAT by a set of queues, henceforth denoted by Q, which are used for buffering packets which currently cannot be forwarded due to limited resources. We will assume that all queues are FIFO with normal queue related functions, e.g., enqueue (EQ( )), dequeue (DQ( )), head of queue (HEAD( )), etc.
For specifying the queue operations, we extend WNetKAT to allow enqueue and dequeue, where Q ∈ Q: • Enqueue EQ Q: Put the current packet into the queue Q. The packet remains in the queue until being processed by the switch.
• Dequeue DQ Q: Dequeue the first packet from the queue Q and delete it from the queue.
The semantics are defined in Table 2, for Q ∈ Q. Remarks: Equations (5) and (6) deal with the queues at the switches, by taking care of the detailed queue processing. Notice that each switch can only manage its own queues.   However, there are two queues at the switch for high priority packets (e.g., skype packets) and low priority (e.g., http packets) packets respectively. Different from Example 7, when a packet arrives at the switch r, it will be put into the right queue first. This can be specified using the following, where x is the packet-variable representing the priority. sw = r; x = low; EQ Q l & sw = r; x = high; EQ Q h Moreover, the switch also makes sure that the high priority queue is processed 80% of the time and the low priority queue 20% of the time. The following expression shows the case of high priority packets.
The second line specifies that when x h is less than 8, we take the first packet of the high priority queue and send it through port 3. This is similar to non-queue case. The third line specifies the situation when x h already reached its upper limit, meaning that the high priority packets already used up the bandwidth assigned for them. However, the low priority queue is empty, i.e., there is no low priority packet that needs to use the link. Therefore, in this case, the high priority packets can use the low priority packets' share. The fourth line specifies the case that the high priority packets already used up their share and need to wait for the low packets to go first. The last line tests whether the counters both reach their upper limit and if yes, reset both of them.
Related to the quality-of-service discussion above is also the question of how to model entire flows competing for a set of shared resources (e.g., along paths). While so far, all our use cases have been described in terms of packet and switch variables only, these concepts are insufficient to model contention across multiple resources.
In principle, it is simple to extend WNetKAT with a notion of global variables which allows to account for such more global aspects. In practice however, supporting global variables can be inefficient: such variables cannot be maintained by the switch, but require interactions with the controller. The latter introduces network loads and latencies, which can be undesirable, especially in wide-area network where the controller can be located remotely.

(Un)Decidability
In this section we shed light on the fundamental decidability of weighted SDN programming languages like WNetKAT. Given today's trend toward more quantitative networking, we believe that this is an important yet hardly explored dimension. In particular, we will establish an equivalence between WNetKAT and weighted automata.
In the following, we will restrict ourselves to settings where quantitative variables of the same type behave similarly in the entire network: For example, the cost variables (e.g., quantifying latencies) in the network are always added up along a given path, while capacity variables require minimum operations along different paths. This is a reasonable for real-world networks.
The definition of the weighted automata used here is slightly different from those usually studied, e.g., [7,10]. However, it is easy to see that they are equivalent.
Let Ω be the set of complete quantitative tests and ∆ be the set of complete quantitative assignments.
A weighted NetKAT automata is a finite state weighted automaton A = (S , s, F, λ, µ) over a structure K and alphabet Σ. The inputs to the automaton are so called reduced strings introduced in [5,15], which belong to the set U = At · Ω · P · ∆ · (dup · P · ∆) * , i.e., the strings belonging to U are of the form: αωp 0 δ 0 dup p 1 δ 1 dup · · · dup p n δ n for some n ≥ 0. Intuitively, µ attempts to consume αωp 0 δ 0 dup from the front of the input string and move to a new state with a weight and the new state has the residual input string α 0 ω 0 p 1 δ 1 dup · · · dup p n δ n .
From WNetKAT to WFA Let e be a weighted automata expression, then following [5,15], we can define a set of reduced strings R which are semantically equivalent to e. We define a weighted NetKAT automata A = (S , s, F, λ, µ) over a structure K and alphabet Σ, where s = R and Σ = At × At. µ : Σ → K S ×S is defined as: µ(α, β)(u 1 , We have the following theorem. From this relationship, we have the following theorem about the (un)decidability of WNetKAT expression equivalence.

Theorem 10. Deciding equivalence of two WNetKAT expressions is equal to deciding the equivalence of the two corresponding weighted WNetKAT automata.
For all the semiring and bimonoid we encountered in this paper, the WFA equivalence is undecidable. Therefore, the equivalence is also undeciable.
This negative result highlights the inherent challenges involved in complex network languages which are powerful enough to deal with weighted aspects.
However, we also observe that in many practical scenarios, the above undecidability result is too general and does not apply. For example, most of the use cases presented in in Section 4 can actually be reduced to test emptiness: we often want to test whether a given WNetKAT expression e equals 0, i.e., whether the corresponding weighted NetKAT automaton is empty. Indeed, there seems to exist an intriguing relationship between emptiness and reachability. Theorem 11. Deciding whether a WNetKAT expression is equal to 0 is equal to deciding the emptiness of the corresponding weighted automaton.
Interestingly, as shown in [8,9,21,22], the emptiness problem is decidable for several semirings/bimonoids, e.g., the tropical semiring and the tropical bimonoid used in this paper. This leads to the decidability of the WNetKAT equivalence over these structures.
Another interesting domain with many decidability results are unambiguous regular grammars and unambiguous finite automata [41]. Accordingly, in our future work, we aim to extend these concepts to the weighted world and explore the unambiguous subsets of WNetKAT which might enable decidability for equivalence.

Compilation and Practical Considerations
We conclude with some remarks on compilation and compatibility to OpenFlow. In general, OpenFlow today does not accommodate stateful packet operations, and thus, per-connection or per-packet logic require involvement of the controller. Moreover, OpenFlow switches do not per se support arithmetic computations, such as addition of packet field values.
However, we currently witness a strong trend toward computationally more advanced and stateful packetprocessing functionality. For example, the advent of programming protocol-independent packet processors like P4 [4], programming platform-independent stateful OpenFlow applications inside the switch like OpenState [3], but also systems like SNAP [1], POF [39], or Domino [37] introduce features which render these platforms potentially interesting compilation targets for WNetKAT. To give another example, Open vSwitch allows running on-hypervisor local controllers in addition to a remote, primary controller, to introduce a more stateful packet processing.
Nevertheless, we observe that several features of today's OpenFlow versions can be exploited for the compilation of WNetKAT expressions. For example, in order to implement arithmetic operations (see e.g., Equations (3) and (4)), we can simply use lookup tables realized as OpenFlow rules, see the technique in [31]. Thus, cost reachability queries can be compiled to flow tables similarly as in NetKAT.
Interestingly, however, also a simple form of switch state can readily be implemented in OpenFlow today. Indeed, OpenFlow switches provide stateful features such as group tables, packet counters, bandwidth meters, etc. For example, a simple yet inefficient solution to compile WNetKAT switch variables is to use either the meta-rule approach taken by Schiff et al. [32] (introducing additional flow rules), or to leverage round robin groups [31]. Finally, we note that while OpenFlow actions can be used to forward packets to specific queues, the scheduling regime for the queues is defined via the management plane [35].

Conclusion
In our future research, we aim to chart a more comprehensive landscape of the decidability and decision complexity of WNetKAT. In the longer term, we also aim to extend WNetKAT to support probabilistic aspects of networking.