使用NumPy进行离散网络请求事件模拟器?

时间:2014-06-02 22:49:09

标签: python networking numpy simpy

我需要模拟路由器网络正在处理的请求和响应,并通过创建服务器类来开始:

class NBServer:
"""Name based content server"""

def __init__(self, _id):
    self.id = _id
    self.requests = deque('x')
    self.responses = deque('x')
    self.req_load = 0 
    self.res_load = 0
    self.color = ''
    self.forwarding_table = {}
    self.content_store = {}
    self.pending_table = {}

def __str__(self):
    return 'current load: ' + str(req_load + req_load)


def request(self, content_name, requester_id):
    self.requests.append((content_name, requester_ids))
self.req_load += 1

def response(self, content_name, content_url):
    self.responses.append((content_url, destination_ids))
    return ((content_url, destination_ids))


def process(self):
    for req in self.requests:
        # Case 1: content in cache
  if content_name in self.content_store:
    return self.content_name[content_name]

  # Case 2: duplicate request exists
  elif content_name in self.pending_table:
    self.pending_table[content_name].append(requester_id)

  # Case 3: add to PT, forward to next router
  else: 
    self.pending_table[content_name] = [requester_id]

response = response.popleft()
if response:
    for dest_id in self.pending_table[content_name]:
        nodes[dest_id].response(content_name, content_url)
    del self.pending_table[content_name]

但是,现在我对如何表示路由器之间的通信感到困惑:

有关如何使用NumPy执行此操作的任何建议吗?

非常感谢任何帮助!

0 个答案:

没有答案