Resource Allocation and Optimal Scheduling of Virtual Network Functions in Software Defined Networks