blob: ebfeb5d480ee5d9aec9c198a8685b880d000a8fe [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
Alexander Afanasyev76b11572013-07-16 21:49:50 -070023class Face (ns.ndnSIM.ndn.ApiFace):
24 def __init__(self):
25 self.nodeId = ns.core.Simulator.GetContext ()
26 self.node = ns.core.NodeList.GetNode (self.nodeId)
27 super(Face, self).__init__ (self.node)
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070028
29 def connect (self):
30 pass
31
32 def disconnect (self):
Alexander Afanasyev76b11572013-07-16 21:49:50 -070033 self.Shutdown ()
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070034
35 def defer_verification (self, deferVerification = True):
36 pass
37
38 def expressInterestSimple (self, name, onData, onTimeout, template = None):
Alexander Afanasyev76b11572013-07-16 21:49:50 -070039 if template:
40 interest = ns.ndnSIM.ndn.Interest (template)
41 else:
42 interest = ns.ndnSIM.ndn.Interest ()
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070043
Alexander Afanasyev76b11572013-07-16 21:49:50 -070044 interest.SetName (name)
45 self.ExpressInterest (interest, onData, onTimeout)
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070046
47 def setInterestFilterSimple (self, name, onInterest, flags = None):
Alexander Afanasyev76b11572013-07-16 21:49:50 -070048 self.SetInterestFilter (name, onInterest)
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070049
50 def clearInterestFilter(self, name):
Alexander Afanasyev76b11572013-07-16 21:49:50 -070051 self.ClearInterestFilter (name)
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070052
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070053 def get(self, name, template = None, timeoutms = 3000):
Alexander Afanasyev76b11572013-07-16 21:49:50 -070054 raise ("NS-3 simulation cannot have syncrhonous operations")
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070055
Alexander Afanasyev76b11572013-07-16 21:49:50 -070056 def put(self, data):
57 self.Put (data)
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070058
59 @staticmethod
Alexander Afanasyev76b11572013-07-16 21:49:50 -070060 def getDefaultKey ():
61 return None
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070062
Alexander Afanasyev76b11572013-07-16 21:49:50 -070063class EventLoop(object):
64 def execute (self, event):
65 ns.core.Simulator.ScheduleNow (event)
Alexander Afanasyev5ba90362013-07-15 19:58:38 -070066
Alexander Afanasyev76b11572013-07-16 21:49:50 -070067 def run (self, timeoutMs):
68 ns.core.Simulator.Stop (ns.core.MilliSeconds (timeoutMs))
69 ns.core.Simulator.Run ()
70 ns.core.Simulator.Destroy ()