Cross Layer Design and Optimization in Wireless Sensor Networks