In this section, we propose a mathematical model of the dynamic vswitch resource allocation problem and the packet scheduling problem in CIoV. It optimizes the time expenditure of resource allocation on vswitches and packet scheduling for each network connection. Besides, we apply Lyapunov Optimization Framework [16,17,18] to transform the joint optimization problem into a discrete-time queuing system. It converts the model constraints to virtual queues and defines the Lyapunov Function to represent the stabilization of the system. To solve the optimization problem and to stabilize the queue system, we minimize the drift of the Lyapunov Function and derive the optimization policies from the function. In addition, we deduce the performance tradeoff of the policies from the theoretical analysis, and it shows that the time-average expectation of vswitch resource allocation and queue backlogs conform to [*O*(1/*V*), *O*(*V*)] tradeoff.

### 3.1 Network model

We provide an instance of the dynamic vswitch resource allocation problem and the packet scheduling problem in CIoV in Fig. 3. All cognitive services are deployed in virtual machines with virtualized servers, and service requests and responses can be considered as network connections in this model. The data center operator manages the system in slotted time. ❶ The vswitch in the server \(s_1\) creates a vswitch virtual port *u* for the virtual machine VM1 and binds NICs as vswitch physical ports. The vswitch in server \(s_2\) also creates a vswitch virtual port *v* for the virtual machine VM2 and binds NICs as vswitch physical ports. ❷ Each vswitch port *p* enqueues received packets to a Receive Queue (Rx-Queue), and a packet classifier dequeues packets at the rate of \(f(r_p(t))\). The vswitch resource allocation decision variable \(r_p(t)\) represents that the cloud operator allocates resource \(r_p(t)\) to vswitch port *p* on slot *t*. The performance function \(f(\cdot )\) describes the relationship between resource allocation and packet processing rate, which can be measured on servers. The cache miss and the data bus bandwidth limit the forwarding performance of vswitch [29,30,31], which conduct \(f(\cdot )\) to a nondecrease concave function [32]. The cloud operator allocates CPU resource to port *u* by setting the vswitch resource allocation variables \(r_u(t)\) to port *u* for forwarding packets on the server \(s_1\).

In the time slot *t*, ❹ VM1 creates a connection *m* to VM2 that requires networks bandwidth \(A_m(t)\). The required bandwidth \(A_m(t)\) is a stochastic variable and i.i.d over slots. The cloud operator should not only allocate the resource to vswitches but also decide packet scheduling decisions on this slot. For the packet scheduling decisions, the cloud operator needs to choose a forwarding path that connects \(s_1\) to \(s_2\) for the connection *m*. In this example, the cloud operator selects the forwarding path \(y^{ij}_m(t)\), which connects the port *i* in \(s_1\) to port *j* in \(s_2\). The connection occupies the bandwidth \(A_m(t)\) on the forwarding path (*i*, *j*). The capacity of the forwarding path is \(\beta _{ij}\). ❺ The vswitch in server \(s_2\) handles the connection *m* on port *j* and enqueues packets in the queue \(Q_j(t)\). ❻ The cloud operator also needs to allocate the resource \(r_j(t)\) to port *j* for forwarding packets. ❼ VM2 receives packets of the connection *m* from vswitch port *v*, and handles the cognition service request. The cognition service response also can be presented as a similar process. Without loss of generality, we model all bidirectional service requests and responses as two connections (Table 1).

The packets in connection *m* transverse through port *u* and are enqueued in Rx-Queue \(Q_u(t)\). The classifier dequeues packets in Rx-Queue \(Q_u(t)\) and forwards packets to port *i*. The packets are forwarded through the path (*i*, *j*) in DCN. After being received by port *j*, the packets are enqueued in Rx-Queue \(Q_j(t)\) and forwarded to port *v*. We define the vswitch virtual port backlog update Eq. (1) and the vswitch physical port backlog update Eq. (2), which describe the backlog of vswitch queues in each slot.

$$\begin{aligned} Q_{u} (t + 1)&= \max \left( Q_{u}(t) - f(r_{u}(t)) + \sum \limits _{m \in M} A_m(t) z^{u}_m(t), 0\right) , \forall u \in P_{\text {VM}} \end{aligned}$$

(1)

$$\begin{aligned} Q_{j} (t + 1)&= \max \left( Q_{j}(t) - f(r_{j}(t)) + \sum \limits _{m \in M} \sum \limits _{i \in P_{ \text {NIC} }} \sum \limits _{u \in P_{ \text {VM} }} \sum \limits _{v \in P_{ \text {VM} }} A_m(t) z^u_m(t)z^v_m(t) y^{ij}_m(t), 0\right) \\ &\qquad \forall j \in P_{\text {NIC}} \end{aligned}$$

(2)

To optimize the dynamic vswitch resource allocation problem and the packet scheduling problem on time average, we define the optimization problem (3–12). The object of the optimization (3) is to minimize the time-average expectation of resource allocation on vswitches, when the resource capacity constraint (4), the network path capacity constraint (5), the flow conservation constraint (6), the single path constraint (7, 8) and the queue stable constraint (9) hold. The resource allocation constraint (4) restricts that the resource allocation for all ports of a vswitch is not greater than the capacity of the server. The forwarding path capacity constraint (5) guarantees that the traffic on each forwarding path does not exceed the bandwidth of the path. The flow conservation constraint (6) ensures that the incoming traffic is equal to the outgoing network traffic for each forwarding path. The single path constraint (7–8) indicates that the network does not support multi-path. The queue stable constraint (9) states that the queue backlog will not increase to infinite. Queue mean rate stable can be defined as \(\lim \limits _{t \rightarrow \infty } \frac{\mathbb {E}\{|Q(t)|\} }{t} = 0\). We assume the requirement of each connection and the resource allocation in each server are bounded (10–11). The binary variables \(z^u_m(t), z^v_m(t)\) represent that the connection *m* traverses through the vswitch virtual ports *u* and *v*. The binary decision variable \(y^{ij}_m(t)\) indicates that the connection *m* is scheduled to traverse through the forwarding path (*i*, *j*). Define the time average of a stochastic variable as \({\overline{x}} = \lim \limits _{t \rightarrow \infty } \frac{1}{t} \sum \limits _{\tau = 0} ^ {t - 1}x(\tau )\).

$$\begin{aligned}&\min \quad \sum \limits _{p \in P_{\text {NIC}} \cup P_{\text {VM}}}\overline{r_p} \end{aligned}$$

(3)

$$\begin{aligned}&\text {s.t.} \quad \sum \limits _{ u \in P^s_{\text {VM}} } \overline{r_{u}} + \sum \limits _{ j \in P^s_{\text {NIC}} } \overline{r_{j}} \le R_s,\quad \forall s \in S \end{aligned}$$

(4)

$$\begin{aligned}&\sum \limits _{m \in M} \sum \limits _{ u \in P_{\text {VM}} } \sum \limits _{v \in P_{\text {VM}} } \overline{ A_m z^{u}_m z^{v}_m y^{{ij}}_m } \le \beta _{i j},\quad \forall i,j \in P_{\text {NIC}} \end{aligned}$$

(5)

$$\begin{aligned}&\sum \limits _{m \in M} \sum \limits _{u \in P_{\text {VM}}} \overline{A_m z^u_m y^{ij}_m} = \sum \limits _{m \in M} \sum \limits _{v \in P_{\text {VM}}} \overline{A_m z^v_m y^{ij}_m },\quad \forall i, j \in P_{\text {NIC}} \end{aligned}$$

(6)

$$\begin{aligned}&\sum \limits _{i \in P_{\text {NIC}}}\sum \limits _{j \in P_{\text {NIC}}} \overline{y^{ij}_m} \le 1,\quad \forall m \in M \end{aligned}$$

(7)

$$\begin{aligned}&\forall s \in S,\quad \text {if}\quad i, j \in P^s_{\text {NIC}},\quad y^{ij}_m(t) = 0 \end{aligned}$$

(8)

$$\begin{aligned}&\text {Queue}\,Q_p(t)\,\text {is mean rate stable},\quad \forall p \in P_{\text {NIC}} \cup P_{\text {VM}} \end{aligned}$$

(9)

$$\begin{aligned}&0 \le A_m(t) \le A_m^{\text {max}} \end{aligned}$$

(10)

$$\begin{aligned}&0 \le r_{p}(t) \le R_s,\quad p \in P^s_{\text {NIC}} \cup P^s_\text {VM} \end{aligned}$$

(11)

$$\begin{aligned}&z^u_m(t),\quad z^v_m(t),\quad y^{ij}_m(t) \in \{0,1\} \end{aligned}$$

(12)

### 3.2 Transformed problem

The constraints of the above optimization can also be transformed as queue backlog update equations, which have similar forms as the queue update equation of vswitch ports. We transform the constraints (4–7) to *virtual queues* (13–16). And if a virtual queue is mean rate stable, it denotes that the corresponding constraint holds in the optimization problem.

$$\begin{aligned} H_s(t + 1)&= \max \left( H_s(t) + \sum \limits _{ u \in P^s_{\text {VM}} } {r_{u}(t)} + \sum \limits _{ j \in P^s_{\text {NIC}} } {r_{j}(t)} - R_s, 0\right) ,\quad \forall s \in S \end{aligned}$$

(13)

$$\begin{aligned} G_{ij}(t + 1)&= \max \left( G_{ij}(t) + \sum \limits _{m \in M} \sum \limits _{u \in P_{\text {VM}}} \sum \limits _{v \in P_{\text {VM}}} A_m(t) z^u_m(t) z^v_m(t) y^{ij}_m(t) - \beta _{ij}, 0 \right) , \\ &\quad \forall i,j \in P_{\text {NIC}} \end{aligned}$$

(14)

$$\begin{aligned} N_{ij}(t + 1)&= N_{ij}(t) + \sum \limits _{m \in M}\sum \limits _{u \in P_{M}} A_m(t)z^u_m(t)y^{ij}_m(t) \\ &\quad - \sum \limits _{m \in M}\sum \limits _{v \in P_{\text {VM}}} A_m(t)z^v_m(t)y^{ij}_m(t),\quad \forall i,j \in P_{\text {NIC}} \end{aligned}$$

(15)

$$\begin{aligned} K_m(t + 1)&= \max \left( K_m(t) + \sum \limits _{i \in P_{\text {NIC}}} \sum \limits _{j \in P_{\text {NIC}}} y^{ij}_m(t) - 1, 0\right) \end{aligned}$$

(16)

We define a vector (17) which includes all vswitches queues and virtual queues. We can define the Lyapunov function (18) and the Lyapunov drift (19) from the vector. The Lyapunov function is the sum of the squares of all vswitches queue backlogs and virtual queue backlogs, which are always nonnegative. If the Lyapunov function is a large number, it denotes that at least one queue in the vector \({\varvec{\Theta }}(t)\) is large. It represents that too many resources are allocated to the virtual switches, or some constraints are not satisfied in the optimization problem. We define the Lyapunov drift as the difference of the Lyapunov function with the previous time slot.

$$\begin{aligned} {\varvec{\Theta }}(t)&\triangleq [Q_{u}(t), Q_{j}(t), H_{s}(t),G_{ij}(t),N_{ij}(t),K_m(t)] \end{aligned}$$

(17)

$$\begin{aligned} L({\varvec{\Theta }} (t))&= \frac{1}{2} \left( \sum \limits _{u \in P_{\text {VM}}} Q_{u}(t)^2 + \sum \limits _{j \in P_{\text {NIC}}} Q_{j}(t)^2 + \sum \limits _{s \in S}H_s(t)^2 \right. \\ &\left. \quad + \sum \limits _{i \in P_{\text {NIC}}} \sum \limits _{j \in P_{\text {NIC}}} G_{ij}(t)^2 + \sum \limits _{i \in P_{\text {NIC}}} \sum \limits _{j \in P_{\text {NIC}}} N_{ij} (t)^2 + \sum \limits _{m \in M} K_m(t)^2 \right) \end{aligned}$$

(18)

To reduce the expenditure of resource allocation and to stabilize the system, we apply Lyapunov Optimization Framework [16,17,18,19] which minimizes the drift-plus-penalty (20) on each slot. The drift-plus-penalty is defined as the weighted sum of the Lyapunov drift and the object of the optimization problem. The factor *V* is a positive penalty factor, which indicates the relation between the system stability and the object of the problem. Applying the fact that if \(a = max(b, 0)\), then \(a^2 \le b^2\) to the definition of queues (1–2, 13–16), we obtain the inequation (21) which is the bound of the drift-plus-penalty. Because these stochastic variables are bounded (10–11), *B* is a constant independent from the factor *V*, which contains the remaining square terms of the inequation (21).

$$\begin{aligned}&\Delta ( {\varvec{\Theta }} (t) ) \triangleq \mathbb {E}[L({\varvec{\Theta }}(t + 1)) - L({\varvec{\Theta }}(t)) \vert {\varvec{\Theta }} (t)] \end{aligned}$$

(19)

$$\begin{aligned}&\Delta ({\varvec{\Theta }}(t)) + V \sum \limits _{p \in P_{\text {NIC}} \cup P_{\text {VM}}} r_p(t) \end{aligned}$$

(20)

To minimize the drift-plus-penalty, we minimize the right side of the inequation (21) on each slot, which could deduce the vswitch resource allocation problem (22–23) and packet scheduling problem (24).

According to the above analysis, we can design distributed resource allocation policies for the dynamic vswitch resource allocation problem and the packet scheduling problem. On each slot, the vswitch on each server can solve the optimization problems (22–23) independently to allocate resources for each vswitch virtual port and vswitch physical port. The cloud operator solves the optimization problem (24) to select the physical path for each connection. In addition, the resource allocation and packet scheduling only depend on vswitches queue backlogs and virtual queue backlogs on the current slots that will not require prior information about the distribution of the traffic.

$$\begin{aligned}&\Delta (\Theta (t)) + V \sum \limits _{p \in P_{\text {NIC}} \cup P_{\text {VM}}} r_p(t) \le B + V \sum \limits _{u \in P_{\text {NIC}}} r_u(t) + V \sum \limits _{j \in P_{\text {VM}}} r_j(t) \\ &\quad + \sum \limits _{j \in P_{\text {NIC}}} Q_{j}(t) \left( \sum \limits _{m \in M} \sum \limits _{i \in P_{ \text {NIC} }} \sum \limits _{u \in P_{ \text {VM} }} \sum \limits _{v \in P_{ \text {VM} }} A_m(t) z^u_m(t) z^v_m(t) y^{ij}_m(t) - f(r_{j}(t))\right) \\ &\quad - \sum \limits _{u \in P_{\text {VM}}} Q_u(t) \left( f(r_{u}(t)) + \sum \limits _{s \in S} H_s(t) \left( \sum \limits _{ u \in P^s_{\text {VM}} } {r_{u}(t)} + \sum \limits _{ j \in P^s_{\text {NIC}} } {r_{j}(t)}\right) \right. \\ &\left. \quad + \sum \limits _{i \in P_{\text {NIC}}} \sum \limits _{j \in P_{\text {NIC}}} G_{ij}(t) \left( \sum \limits _{m \in M} \sum \limits _{u,v \in P_{\text {VM}}} A_m(t) z^u_m(t) z^v_m(t) y^{ij}_m(t)\right) \right) \\ &\quad + \sum \limits _{i \in P_{\text {NIC}}}\sum \limits _{j \in P_{\text {NIC}}} N_{ij}(t) \left( \sum \limits _{m \in M}\sum \limits _{u \in P_{\text {VM}}} A_m(t)z^u_m(t)y^{ij}_m(t) \right. \\ &\left. \quad - \sum \limits _{m \in M}\sum \limits _{v \in P_{\text {VM}}} A_m(t)z^v_m(t)y^{ij}_m(t)\right) + \sum \limits _{m \in M}\sum \limits _{i \in P_{\text {NIC}}} \sum \limits _{j \in P_{\text {NIC}}} K_m(t) y^{ij}_m(t) \end{aligned}$$

(21)

$$\begin{aligned}&\min \ (H_s(t) + V) {r_{u}(t)} - Q_{u}(t) f(r_{u}(t)),\quad \forall u \in P^s_{\text {VM}},\quad \forall s \in S \end{aligned}$$

(22)

$$\begin{aligned}&\min \ (H_s(t) + V) {r_{j}(t)} - Q_{j}(t) f(r_{j}(t)),\quad \forall j \in P^s_{\text {NIC}},\quad \forall s \in S \end{aligned}$$

(23)

$$\begin{aligned}&\min \left( (Q_{j}(t) + G_{ij}(t)) \sum \limits _{m \in M} \sum \limits _{u,v \in P_{ \text {VM} }} A_m(t) z^u_m(t) z^v_m(t) + N_{ij}(t) \left( \sum \limits _{m \in M} K_m(t) \right. \right. \\ &\left. \left. \quad + \sum \limits _{m \in M}\sum \limits _{u \in P_{VM}} A_m(t) z^u_m(t) - \sum \limits _{m \in M} \sum \limits _{v \in P_{VM}} A_m(t) z^v_m(t)\right) \right) y^{ij}_m(t) \end{aligned}$$

(24)

### 3.3 Performance analysis

Based on the above transformation and optimization policies, we provide a theorem that reveals the tradeoff [*O*(1/*V*), *O*(*V*)] between the time-average expectation of resource allocation and queue backlogs. We can evaluate the system’s stability with the optimization object by tuning the factor *V*, which balances the vswitch resource allocation and the satisfaction of optimization constraints.

###
**Theorem 1**

*Assume the optimization problem* (3–8) *is feasible, the bounded restraints hold* (10–11), *the initial queue backlogs are finite* (\(\mathbb {E}[ L(0)] \le \infty\)), *and the Slater’s condition holds*.

$$\begin{aligned}&\sum \limits _{p \in P} r_p(t) = \omega (\eta ),\quad 0 \le \omega (\eta ) \le \sum \limits _{p \in P} r_p^{\text {max}} \\&\mathbb {E}[{H_s(t)}] \le 0,\quad \forall s \in S \\&\mathbb {E}[{G_{ij}(t)}] \le 0,\quad \forall i,j \in P_{\text {NIC}} \\&\mathbb {E}[{N_{ij}(t)}] \le 0,\quad \forall i,j \in P_{\text {VM}} \\&\mathbb {E}[{K_{m}(t)}] \le 0,\quad \forall m \in M \\&\mathbb {E}[{Q_{p}(t)}] \le \eta ,\quad \forall p \in P \text { and } \eta > 0 \end{aligned}$$

*If a* *C*-*additive algorithm applies on every slot to minimize the right side of inequality* (21) *and gets the optimal solution* \(\sum _{p \in P} r_p^{\text {opt}}\), *then(a) the time-average expectation of resource allocation satisfies* (25) *and (b) the time-average expectation of queue backlogs meets* (26).

$$\begin{aligned}&\limsup _{t \rightarrow \infty } \frac{1}{t} \sum \limits _{\tau = 0}^{t - 1} \sum \limits _{p \in P} \mathbb {E}[r_p(\tau )] \le \sum \limits _{p \in P} r_p^{\text {opt}} + \frac{(B + C)}{V} \end{aligned}$$

(25)

$$\begin{aligned}&\limsup _{t \rightarrow \infty } \frac{1}{t} \sum \limits _{\tau = 0}^{t - 1} \sum \limits _{p \in P} \mathbb {E}[ Q_p(\tau ) ] \le \frac{1}{\eta } \left( B + C + V \left( \sum \limits _{p \in P} r_p^{\text {opt}} - \omega (\eta )\right) \right) \end{aligned}$$

(26)

### Proof 1

We insert the Slater’s condition on the right side of (21) and apply the *C*-additive algorithm on each slot to get the optimal solution, which yields (27). We get (28) from taking expectation of (27) with the law of total expectation, and applying the law of telescoping sum from slot 0 to \(t-1\). Then, we rearrange the inequation (28)–(29), divide (29) by *Vt* and take limits \(t\rightarrow \infty\) to prove (25). Similarly, we rearrange the inequation (28)–(30), divide \(\eta t\) into (30) and take limits \(t \rightarrow \infty\) to prove (26).

$$\begin{aligned}&\Delta ({\varvec{\Theta }} (t) ) + V \mathbb {E}\left[ \sum \limits _{p \in P} r_p(t) \vert {\varvec{\Theta }} (t) \right] \le B + C + V \sum \limits _{p \in P} r_p^{\text {opt}} - \eta \sum \limits _{p \in P} Q_p(t) \end{aligned}$$

(27)

$$\begin{aligned}&\mathbb {E}(L({\varvec{\Theta }} (t))) - \mathbb {E}(L({\varvec{\Theta }} (0))) + V \sum \limits _{\tau =0}^{t-1} \mathbb {E}\left[ \sum \limits _{p \in P} r_p(\tau )\right] \\ &\quad \le Bt + Ct + Vt \sum \limits _{p \in P} r_p^{\text {opt}} - \eta \sum \limits _{\tau = 0}^{t - 1} \sum \limits _{p \in P} \mathbb {E}(Q_p(\tau )) \end{aligned}$$

(28)

$$\begin{aligned}&V \sum \limits _{\tau =0}^{t-1} \mathbb {E}\left[ \sum \limits _{p \in P} r_p(\tau )\right] \le Bt + Ct + Vt \sum \limits _{p \in P} r_p^{\text {opt}} + \mathbb {E}(L({\varvec{\Theta }} (0))) \\ &\quad - \eta \sum \limits _{\tau = 0}^{t - 1} \sum \limits _{p \in P}\mathbb {E}(Q_p(\tau )) - \mathbb {E}(L({\varvec{\Theta }} (t))) \end{aligned}$$

(29)

$$\begin{aligned}&\eta \sum \limits _{\tau = 0}^{t - 1} \sum \limits _{p \in P} \mathbb {E}[Q_p(\tau )] \le Bt + Ct + Vt \sum \limits _{p \in P} r_p^{\text {opt}} + \mathbb {E}(L({\varvec{\Theta }} (0))) \\ &\quad - V\sum \limits _{\tau =0}^{t-1} \mathbb {E}\left[ \sum \limits _{p \in P} r_p(\tau )\right] - \mathbb {E}(L({\varvec{\Theta }} (t))) \end{aligned}$$

(30)