blob: 54803dbc61a66f2c0b9163c3fdbfe9aed97dbfdf [file] [log] [blame]
Alexander Afanasyev5ba90362013-07-15 19:58:38 -07001## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2#
3# Copyright (c) 2011-2013, Regents of the University of California
4# Alexander Afanasyev
5#
6# GNU 3.0 license, See the LICENSE file for more information
7#
8# Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
9#
10
11#
12# Based on PyCCN code, copyrighted and licensed as follows
13#
14# Copyright (c) 2011-2013, Regents of the University of California
15# BSD license, See the COPYING file for more information
16# Written by: Derek Kulinski <takeda@takeda.tk>
17# Jeff Burke <jburke@ucla.edu>
18#
19
20import ns.core
21import ns.ndnSIM
22
23# from ns3.ndnSIM import ApiFace, Interest, Name
24
25class Face (object):
26 def __init__(self, node):
27 self._face = ns.ndnSIM.ndn.ApiFace (node)
28
29 def connect (self):
30 pass
31
32 def disconnect (self):
33 pass
34
35 def defer_verification (self, deferVerification = True):
36 pass
37
38 def expressInterestSimple (self, name, onData, onTimeout, template = None):
39
40 pass
41 # class TrivialExpressClosure (Closure.Closure):
42 # __slots__ = ["_baseName", "_onData", "_onTimeout"];
43
44 # def __init__ (self, baseName, onData, onTimeout):
45 # self._baseName = baseName
46 # self._onData = onData
47 # self._onTimeout = onTimeout
48
49 # def upcall(self, kind, upcallInfo):
50 # if (kind == Closure.UPCALL_CONTENT or
51 # kind == Closure.UPCALL_CONTENT_UNVERIFIED or
52 # kind == Closure.UPCALL_CONTENT_UNVERIFIED or
53 # kind == Closure.UPCALL_CONTENT_KEYMISSING or
54 # kind == Closure.UPCALL_CONTENT_RAW):
55 # return self._onData (self._baseName, upcallInfo.Interest, upcallInfo.ContentObject, kind)
56 # elif (kind == Closure.UPCALL_INTEREST_TIMED_OUT):
57 # return self._onTimeout (self._baseName, upcallInfo.Interest)
58 # return Closure.RESULT_OK
59
60 # trivial_closure = TrivialExpressClosure (name, onData, onTimeout)
61 # self.expressInterest (name, trivial_closure, template)
62
63 def setInterestFilterSimple (self, name, onInterest, flags = None):
64 pass
65 # class TrivialFilterClosure (Closure.Closure):
66 # # __slots__ = ["_baseName", "_onInterest"];
67
68 # def __init__ (self, baseName, onInterest):
69 # self._baseName = baseName
70 # self._onInterest = onInterest
71
72 # def upcall(self, kind, upcallInfo):
73 # if (kind == Closure.UPCALL_INTEREST):
74 # return self._onInterest (self._baseName, upcallInfo.Interest)
75 # return Closure.RESULT_OK
76
77 # trivial_closure = TrivialFilterClosure (name, onInterest)
78 # self.setInterestFilter (name, trivial_closure, flags)
79
80 def clearInterestFilter(self, name):
81 pass
82
83 # Blocking!
84 def get(self, name, template = None, timeoutms = 3000):
85 # self._acquire_lock("get")
86 # try:
87 # return _ndn.get(self, name, template, timeoutms)
88 # finally:
89 # self._release_lock("get")
90
91 # def put(self, contentObject):
92 # self._acquire_lock("put")
93 # try:
94 # return _ndn.put(self, contentObject)
95 # finally:
96 # self._release_lock("put")
97
98 @staticmethod
99 def getDefaultKey():
100 pass
101 # return _ndn.get_default_key()
102
103# class EventLoop(object):
104# def __init__(self, *handles):
105# self.running = False
106# self.fds = {}
107# for handle in handles:
108# self.fds[handle.fileno()] = handle
109# self.eventLock = threading.Lock ()
110# self.events = []
111
112# def execute (self, event):
113# self.eventLock.acquire ()
114# self.events.append (event)
115# self.eventLock.release ()
116
117# def run_scheduled(self):
118# wait = {}
119# for fd, handle in zip(self.fds.keys(), self.fds.values()):
120# wait[fd] = handle.process_scheduled()
121# return wait[sorted(wait, key=wait.get)[0]] / 1000.0
122
123# def run_once(self):
124# fd_read = self.fds.values()
125# fd_write = []
126# for handle in self.fds.values():
127# if handle.output_is_pending():
128# fd_write.append(handle)
129
130# timeout = min(self.run_scheduled(), 1.000)
131
132# res = select.select(fd_read, fd_write, [], timeout)
133
134# handles = set(res[0]).union(res[1])
135# for handle in handles:
136# handle.run(0)
137
138# def run(self):
139# self.running = True
140# while self.running:
141# try:
142# self.eventLock.acquire ()
143# for event in self.events:
144# event ()
145# self.events = []
146# self.eventLock.release ()
147
148# self.run_once()
149# except select.error, e:
150# if e[0] == 4:
151# continue
152# else:
153# raise
154# self.running = False
155
156# def stop(self):
157# self.running = False
158# for fd, handle in zip(self.fds.keys(), self.fds.values()):
159# handle.disconnect ()