  Based on software-defined principles, we propose a holistic architecture for
Cyberphysical Systems (CPS) and Internet of Things (IoT) applications, and
highlight the merits pertaining to scalability, flexibility, robustness,
interoperability, and cyber security. Our design especially capitalizes on the
computational units possessed by smart agents, which may be utilized for
decentralized control and in-network data processing. We characterize the data
flow, communication flow, and control flow that assimilate a set of components
such as sensors, actuators, controllers, and coordinators in a systemic
programmable fashion. We specifically aim for distributed and decentralized
decision-making by spreading the control over several hierarchical layers. In
addition, we propose a middleware layer to encapsulate units and services for
time-critical operations in highly dynamic environments. We further enlist a
multitude of vulnerabilities to cyberattacks, and integrate software-defined
solutions for enabling resilience, detection, and recovery. In this purview,
several controllers cooperate to identify and respond to security threats and
abnormal situations in a self-adjusting manner. Last, we illustrate numerical
simulations in support of the virtues of a software-defined design for CPS and
IoT.
