def create_vnf_processes(self): ''' Create a process for each assigned VNF :return: processes dict ''' for v in self.attached_vnfs: p = self.processes[v.id] = Process(v, self) env.process(p.process())
def main(): ''' The main control flow to run the simulation :return: None ''' TOTAL_SERVICE_CHAIN_NUM = 4 TOTAL_SIM_TIME = 1000 random.seed(4) # step1: create network topology t = Topology() t.load_network_graph(path='./topology/topology.txt') t.create_network_topology() for link in t.links.values(): env.process(link.run()) paths = cal_shortest_path(t.topology, t.links) # step2: initialize servers servers = Server.init_servers(t.get_nodes(), t.get_links()) # step3: create service chains service_chains = [ ServiceChain.random_gen() for _ in range(TOTAL_SERVICE_CHAIN_NUM) ] # step4: place service chains. single instance... multiple instance... for chain in service_chains: best_fit(servers, chain) # launch server processes for server in servers.values(): server.run() # step5: generate a packet pool packet_pool = Packet.gen_packet_pool(servers, paths, service_chains) # step6 create a packet from the packet pool and simulate routing process. # env.process(flow_generator(packet_pool, servers, t.links)) # single packet test # packet = random.choice(packet_pool) # print(packet.routing_path) # print(packet.vnf_server_addr) # packet.forward() # generating traffic flow env.process(flow_generator(packet_pool)) env.run(TOTAL_SIM_TIME)
def flow_generator(packet_pool): ''' randomly generate a packet from the packet pool, and make it go through the placed service chain. :param packet_pool: :param servers: :param links: :return: None ''' # todo: consider to find a Poisson distribution for the packet generation or to use the wiki traffic trace. while True: yield env.timeout(1) packet = Packet.random_gen(packet_pool) packet.create_time = env.now env.process(packet.forward())
def run(self): while True: with self.forwarder.request() as req: packet = yield self.buffer.get() yield req # forwarding the packet. KB / MB forward_time = packet.get_size() / self.bandwidth / 1000 yield env.timeout(forward_time) # print('link from {} to {} forwards the packet {} at time {}'.format(self.from_node.id, self.to_node.id, # packet.id, env.now)) env.process(packet.forward(self.propagation_latency))
def run(self): env.process(self.in_packet_proc()) env.process(self.out_packet_proc()) self.create_vnf_processes()