Community networks are evolving rapidly to include heterogeneous physical access (both wired and wireless) and a large number of smart devices that generate different types of traffic. In addition, a variety of applications (VoIP, messaging, video, etc.) with different requirements is putting more constraints in community networks such as delay, packet loss, and bandwidth. Due to its particular architecture, which is very dense and very dynamic, the traditional one-pair-node shortest path solution, which is currently used in metro or WAN networks, is no longer efficient in community networks. This paper presents an analytical framework for dynamically optimizing data flows in community network using Software-defined networking (SDN). We formulate a QoS-based routing optimization problem as a constrained shortest path problem, and then propose an optimized solution to determine minimal cost between all pairs of nodes in the network taking into account the different types of physical accesses and the network utilization patterns. Our experiments show the proposed solution improves resource utilization up to 90%, and outperforms the traditional shortest cost based algorithm with a gain that reaches 13% for the majority of criteria, with 83% for distance, 77% for bandwidth and 51% for packet loss.