  Segment routing (SR) combines the advantages of source routing supported by
centralized software-defined networking (SDN) paradigm and hop-by-hop routing
applied in distributed IP network infrastructure. However, because of the
computation inefficiency, it is nearly impossible to evaluate whether various
types of networks will benefit from the SR with multiple segments using
conventional approaches. In this paper, we propose a flexible $Q$-SR model as
well as its formulation in order to fully explore the potential of SR from an
algorithmic perspective. The model leads to a highly extensible framework to
design and evaluate algorithms that can be adapted to various network
topologies and traffic matrices. For the offline setting, we develop a fully
polynomial time approximation scheme (FPTAS) which can finds a
$(1+\omega)$-approximation solution for any specified $\omega>0$ in time that
is a polynomial function of the network size. To the best of our knowledge, the
proposed FPTAS is the first algorithm that can compute arbitrarily accurate
solution. For the online setting, we develop an online primal-dual algorithm
that proves $O(1)$-competitive and violates link capacities by a factor of
$O(\log n)$, where $n$ is the node number. We also prove performance bounds for
the proposed algorithms. We conduct simulations on realistic topologies to
validate SR parameters and algorithmic parameters in both offline and online
scenarios.
