# Fog over Virtualized IoT: New Opportunity for Context-Aware Networked Applications and a Case Study
## 4 A Case Study: StreamVehicularFog
### Energy Models  
Let \(\mathcal{E}_{c}^{idle}(s)[J]\) and \(\mathcal{E}_{c}^{max}(s)[J]\)\(1\leq s\leq\mathcal{S}_{T}\) be the energies wasted by the \(s\)-th physical server in the idle (inactive) state and we have \(\mathcal{E}_{c}^{idle}(s)\leq\mathcal{E}_{c}^{max}(s)\) and the TCP/IP intra-connection inside the FDC can be considered under Fast/Giga Ethernet with the practical ranges of values for \(\Omega_{s,v}^{c}\) as the bandwidth power coefficient of \([J/(IU)^{\gamma}]\), and \(R_{max}\) as the end-to-end band-width rate in \(([IU/sec])\) as follows:  
\(\bullet\)\(\quad\)Fast Ethernet: \(1.1\times 10^{-3}\leq\Omega_{s,v}^{c}\leq 1.8\times 10^{-3}\), \(R_{max}=100\)  
\(\bullet\)\(\quad\)Giga Ethernet: \(1.8\times 10^{-3}\leq\Omega_{s,v}^{c}\leq 2.5\times 10^{-2}\), \(R_{max}=1000\). The corresponding communication energy \(\mathcal{E}_{s,v}^{LAN}[J]\) wasted by the \(s\)-virtual link is: \(\mathcal{E}_{s,v}^{LAN}\equiv\mathcal{E}_{s,v}^{LAN}(\mathcal{L}_{s,v})=\Omega_{ s,v}^{c}(\mathcal{L}_{s,v})^{\gamma}[J]\), \(1\leq v\leq\mathcal{VM}_{max}(s)\); \(s=1,\ldots,\mathcal{S}_{T}\). When the VMs hosted per physical server are perfectly isolated, the resulting model for the overall wasted computing energy simplifies to the following formula:\[\mathcal{E}_{T}(t)=\mathcal{E}_{C}(t)+\mathcal{E}_{S}(t)+\mathcal{E}_{N}(t)\;[J]\]  
where \(\mathcal{E}_{C}(t)\) is the SVF computing energy; \(\mathcal{E}_{S}(t)\) is the SVF energy switching; and, \(\mathcal{E}_{N}(t)\) is the SVF TCP/IP communication energy. Therefore, the \(\mathcal{E}_{T}\) for slot \(t\) is defined as  
\[ \begin{split}\mathcal{E}_{T}(t)=\sum\limits_{s=1}^{\mathcal{S}_{T }}\left\{\left[\mathcal{E}_{c}^{idle}(s)\left(\sum\limits_{v=1}^{\mathcal{V} \mathcal{M}_{max}(s)}f_{s,v}(t)\right)\right.\right.+\left.\left(\frac{ \mathcal{E}_{c,v}^{max}(s)-\mathcal{E}_{c,v}^{idle}(s)}{\mathcal{V}\mathcal{M }_{max}(s)}\right)\left(\sum\limits_{v=1}^{\mathcal{V}\mathcal{M}_{max}(s)} \left(\frac{f_{s,v}(t)}{f_{s,v}^{max}}\right)^{w}\right)\right]+\\ k_{e}\left(\sum\limits_{v=1}^{\mathcal{V}\mathcal{M}_{max}(s)}(f _{s,v}(t)-f_{s,v}(t-1))^{2}\right)+\left.\left(\sum\limits_{v=1}^{\mathcal{V} \mathcal{M}_{max}(s)}\Omega_{s,v}^{\mathcal{E}}(\mathcal{L}_{s,v})^{\gamma}(t )\right)\right\},\end{split}  \tag{1}\]  
where \(t\in T\), \(t\geq 1\); \(\gamma\) is the powered model for the energy held in the per-transport layer connections per energy instant \(t\); \(\Omega-\) is the common energy consumptions of all LAN (TCP/IP) connections measured \([J/(IU)^{\gamma}]\); and \(w\geq 2\) is strictly convex in \(f_{s,v}(t)\). Therefore, the general optimization problem can be simplified as  
\[\min\{\mathcal{E}_{T}(t)\}, \tag{2}\]  
subjected to:  
\[\mathcal{L}_{T}(t)-\left(\sum\limits_{s=1}^{\mathcal{S}_{T}}\sum \limits_{v=1}^{\mathcal{V}\mathcal{M}_{max}(s)}\mathcal{L}_{s,v}(t)\right)=0, \tag{3}\] \[\mathcal{L}_{s,v}(t)-t_{slot}f_{s,v}^{max}\leq 0,\qquad\forall s,v \in\mathcal{V}\mathcal{M}(s;v),\] (4) \[f_{s,v}(t)-f_{s,v}^{max}\leq 0,\qquad\forall s,v\in\mathcal{V} \mathcal{M}(s;v), \tag{5}\]  
where \(t_{slot}\) is the hard deadline considered to process each slot; in fact, it can be considered as the service level agreement for the mobile application requested from VFC. The workload processed should not be more than the input workload in each time slot \((t)\) (see Equation (3)), and the frequency of each VM should not be more than the maximum frequency (see Equations (4) and (5)). In order to resolve the problem, we can consider the problem as a _bin packing penalty-aware_ problem. Algorithm 1 presents the pseudocode of the proposed solution. Indeed, in turn, for each incoming workload \(\mathcal{L}_{T}(t)\), we calculate how many VMs can be allocated for the \(t\)-th slot. After that, we consider servers as bins and VMs as packs that must be distributed based on their time limitations and frequency limitations.