Cooperative Inter-Node and Inter-Layer Optimization of Network Protocols