An Efficient Data Exchange Algorithm for Chained Network Functions