Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 1 | ## -*- 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 | |
| 20 | import ns.core |
| 21 | import ns.ndnSIM |
| 22 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 23 | class 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 Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 28 | |
| 29 | def connect (self): |
| 30 | pass |
| 31 | |
| 32 | def disconnect (self): |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 33 | self.Shutdown () |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 34 | |
| 35 | def defer_verification (self, deferVerification = True): |
| 36 | pass |
| 37 | |
| 38 | def expressInterestSimple (self, name, onData, onTimeout, template = None): |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 39 | if template: |
| 40 | interest = ns.ndnSIM.ndn.Interest (template) |
| 41 | else: |
| 42 | interest = ns.ndnSIM.ndn.Interest () |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 44 | interest.SetName (name) |
| 45 | self.ExpressInterest (interest, onData, onTimeout) |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 46 | |
| 47 | def setInterestFilterSimple (self, name, onInterest, flags = None): |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 48 | self.SetInterestFilter (name, onInterest) |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 49 | |
| 50 | def clearInterestFilter(self, name): |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 51 | self.ClearInterestFilter (name) |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 53 | def get(self, name, template = None, timeoutms = 3000): |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 54 | raise ("NS-3 simulation cannot have syncrhonous operations") |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 55 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 56 | def put(self, data): |
| 57 | self.Put (data) |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 58 | |
| 59 | @staticmethod |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 60 | def getDefaultKey (): |
| 61 | return None |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 62 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 63 | class EventLoop(object): |
| 64 | def execute (self, event): |
| 65 | ns.core.Simulator.ScheduleNow (event) |
Alexander Afanasyev | 5ba9036 | 2013-07-15 19:58:38 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | 76b1157 | 2013-07-16 21:49:50 -0700 | [diff] [blame^] | 67 | def run (self, timeoutMs): |
| 68 | ns.core.Simulator.Stop (ns.core.MilliSeconds (timeoutMs)) |
| 69 | ns.core.Simulator.Run () |
| 70 | ns.core.Simulator.Destroy () |