Middleboxes have become a vital part of modern networks by providing services such as load balancing, optimization of network traffic, and content filtering. A sequence of middleboxes comprising a logical service is called a Service Function Chain (SFC). In this context, the main issues are to maintain an acceptable level of network path survivability and a fair allocation of the resource between different demands in the event of faults or failures. In this paper, we focus on the problems of traffic engineering, failure recovery, fault prevention, and SFC with reliability and energy consumption constraints in Software Defined Networks (SDN). These types of deployments use Fog computing as an emerging paradigm to manage the distributed small-size traffic flows passing through the SDN-enabled switches (possibly Fog Nodes). The main aim of this integration is to support service delivery in real-time failure recovery in an SFC context. First, we present an architecture for Failure Recovery called FRFP; this is a multi-tier structure in which the real-time traffic flows pass through SDN-enabled switches to jointly decrease the network side-effects of flow rerouting and energy consumption of the Fog Nodes. We then mathematically formulate an optimization problem called the Optimal Fast Failure Recovery algorithm (OFFR) and propose a near-optimal heuristic called Heuristic HFFR to solve the corresponding problem in polynomial time. In this way, the reliability of the selected paths are optimized, while the network congestion is minimized. KEYWORDS failure recovery, fog computing (FC), network function virtualization (NFV), resource reallocation, service function chaining (SFC), software defined network (SDN) 1 INTRODUCTION Network Function Virtualization (NFV) paradigm decouples network functions (NFs) from dedicated hardware equipment and provides more flexibility to the owner of an IT infrastructure. NFV consists in a set of different services running on generic hardware (eg, IDS, proxy, deep packet inspection, and firewall) that are chained using the so called Service Function Chaining (SFC) concept. This concept can be applied to industrial environments; in particular, NFV is used in industrial network design in order to reduce exposure to risks, reduce CAPEX/OPEX costs, and minimize future performance issues by basing the infrastructure upon commodity servers and switches. 1 NFV and SFCs offer a great flexibility in the chaining and placement of NFs. The European Telecommunications Standards Institute (ETSI) is driving the standardization of NFV. Software Defined Networking (SDN) complements NFV and is concerned with the decoupling of control plane functionality from packet forwarding devices, allowing a controller to flexibly configure the networking operations in the infrastructure. NFV and SDN require attention to avoid cascading threats as well ascontroller protections, especially for the software applications across the SDN switches that interoperate with the server virtualization and virtual machines (VMs). 2...