Ejemplo n.º 1
0
    def __init__(self, *args, **kwargs):
        """Constructor.

        :param addr: Address for parent network interface [default=None].
        :param args: Additional arguments passed to `RouteTable` constructor.
        :param kwargs: Additional keywords passed to `RouteTable` constructor.
        """
        RouteTable.__init__(self, *args, **kwargs)
        # set default parameters
        if self.timeout is None:
            self.timeout = self.DefaultTimeout
Ejemplo n.º 2
0
 def hasroute(self, dest, path="ignore"):
     """Overloaded to allow checking for a specific path."""
     r = RouteTable.hasroute(self, dest)
     if r and (path!="ignore"):
         nhlist = [h for (c,t,h) in self.data[dest]['list']]
         r = (path in nhlist)
     return r
Ejemplo n.º 3
0
 def addroute(self, dest, nexthop=None, cost=None):
     """Cache intermediate destinations."""
     rval = RouteTable.addroute(self, dest, nexthop, cost)
     if DSR_CACHE_ALL_HOPS and nexthop:
         # check if nexthop is valid source route
         isiter = True
         try:    x = iter(nexthop)
         except: isiter = False
         isiter &= not isinstance(nexthop, str)
         errmsg = "[ROUTECACHE]: Invalid source route (%s)"%(nexthop)
         assert (isiter), errmsg
         # cache intermediate hops
         for k in range(len(nexthop)):
             dst = nexthop[k]    # intermediate node
             path = nexthop[:k]  # truncated path to intermediate node
             if not path: path = None
             RouteTable.addroute(self, dst, path, None)
     return rval